JET

edu.utep.cs.jet.gui
Class Util

java.lang.Object
  extended by edu.utep.cs.jet.gui.Util
All Implemented Interfaces:
Constants

public abstract class Util
extends Object
implements Constants

A utility class that provides various static utility methods.

Author:
Yoonsik Cheon

Field Summary
 
Fields inherited from interface edu.utep.cs.jet.gui.Constants
CLASS_EXTENSION, COLOR_EXPLORER, COLOR_OUTPUT, COPYRIGHT, DEBUG, DIVIDER_SIZE, EDIT_MENU_NAME, EXPLORER_DIR, EXPLORER_ROOT, FILE_MENU_NAME, HELP_MENU_NAME, ICON_ABOUT, ICON_ABSTRACT_CLASS, ICON_BROWSER, ICON_CLASS, ICON_CLASS_DISABLED, ICON_DELETE, ICON_ERROR, ICON_FILE, ICON_FOLDER, ICON_GEN_APP, ICON_HOME, ICON_INFORM, ICON_INTERFACE, ICON_JAVA_FILE, ICON_JML_LOGO, ICON_METHOD, ICON_METHOD_GREEN, ICON_METHOD_ORANGE, ICON_METHOD_RED, ICON_MINER, ICON_NEW, ICON_NEWTESTSUITE, ICON_NOTE, ICON_OPEN, ICON_OUTPUT, ICON_PREFERENCES, ICON_QUESTION, ICON_REDO, ICON_SAVE_AS, ICON_TEST_FILE, ICON_UNDO, ICON_UNKOWN, ICON_WARN, JAVA, JAVA_EXTENSION, JAVAC, JUNIT_SWINGGUI_TESTRUNNER, NEWLINE, OPTION_MENU_NAME, TEST_MENU_NAME, TITLE, TOOL_MENU_NAME, VERSION, WEB_PAGE_LOCATION, WEB_PAGE_NAME, WINDOW_HEIGHT, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH, WINDOW_WIDTH
 
Method Summary
static void addHidePopupMenu(JComponent comp, String title, AbstractAction action)
          Adds a popup menu to the given component.
static void addPopupMenu(JComponent comp, JPopupMenu menu)
          Adds the given popup menu to the given component.
static void centerWindow(Component window)
          Centers the given window within the screen.
static Border createBorder(String title, JComponent comp, int gap)
          Creates a compound boder consisting of a titled border and an empty border.
static ComponentListener createComponentListener(int w, int h)
          Returns a component listener that prohibits the component c from being resized smaller than the width w and the height h.
static Box createRow(JComponent... comps)
          Creates a horizontal box consisting of the given components.
static JScrollPane createScrollPane(Component comp)
          Creates a scroll pane for the given component.
static void debug(String msg)
          Prints the given message on stdout if the debug flag Constants.DEBUG is true; otherwise, do nothing.
static String getBaseName(File file)
          Returns the base name of the give file.
static ImageIcon getIcon(String name)
          Returns an image icon whose image is read from the file named name.
static void invokeAndWait(Runnable job)
          Runs the given job in a thread-safe way.
static void invokeLater(Runnable job)
          Runs the given job in a thread-safe way.
static boolean isClassFile(File file)
          Returns true if the given file is a Java class file.
static boolean isClassFile(String name)
          Returns true if the given name ends with .class.
static boolean isJavaFile(File file)
          Returns true if the given file is a Java source file.
static boolean isJavaFile(String name)
          Returns true if the argument names a Java source file.
static JScrollPane makeScrollable(JComponent comp)
          Adds to the given component horizontal and vertical scroll bars.
static void run(Runnable job)
          Runs the given job in a new thread.
static void setSize(JComponent c, int width, int height)
          Sets the minimum, maximum, and preferred size of the given component.
static boolean synthesized(String name)
          Returns true if the given name is synthesized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addPopupMenu

public static void addPopupMenu(JComponent comp,
                                JPopupMenu menu)
Adds the given popup menu to the given component.


addHidePopupMenu

public static void addHidePopupMenu(JComponent comp,
                                    String title,
                                    AbstractAction action)
Adds a popup menu to the given component. The popup menu will have the given tile and consists of a single menu item of the given action.


createScrollPane

public static JScrollPane createScrollPane(Component comp)
Creates a scroll pane for the given component.


invokeAndWait

public static void invokeAndWait(Runnable job)
Runs the given job in a thread-safe way.


invokeLater

public static void invokeLater(Runnable job)
Runs the given job in a thread-safe way.


run

public static void run(Runnable job)
Runs the given job in a new thread.


centerWindow

public static void centerWindow(Component window)
Centers the given window within the screen.

Parameters:
window - The window to center.

    requires window != null;
 

getIcon

public static ImageIcon getIcon(String name)
Returns an image icon whose image is read from the file named name. A null is returned if reading the file fails.


debug

public static void debug(String msg)
Prints the given message on stdout if the debug flag Constants.DEBUG is true; otherwise, do nothing.


isJavaFile

public static boolean isJavaFile(String name)
Returns true if the argument names a Java source file. I.e., it ends with the Java extension (.java). If the argument is null, false is returned.


isJavaFile

public static boolean isJavaFile(File file)
Returns true if the given file is a Java source file. I.e., it ends with the Java extension (.java).


isClassFile

public static boolean isClassFile(File file)
Returns true if the given file is a Java class file. I.e., it ends with the Java extension (.class).


isClassFile

public static boolean isClassFile(String name)
Returns true if the given name ends with .class.


getBaseName

public static String getBaseName(File file)
Returns the base name of the give file.


synthesized

public static boolean synthesized(String name)
Returns true if the given name is synthesized. A name is synthesized if it contains a '$'.


setSize

public static void setSize(JComponent c,
                           int width,
                           int height)
Sets the minimum, maximum, and preferred size of the given component.


createComponentListener

public static ComponentListener createComponentListener(int w,
                                                        int h)
Returns a component listener that prohibits the component c from being resized smaller than the width w and the height h.


makeScrollable

public static JScrollPane makeScrollable(JComponent comp)
Adds to the given component horizontal and vertical scroll bars.


createBorder

public static Border createBorder(String title,
                                  JComponent comp,
                                  int gap)
Creates a compound boder consisting of a titled border and an empty border. The gap specifies the width of the four sides of the empty border.


createRow

public static Box createRow(JComponent... comps)
Creates a horizontal box consisting of the given components. If an argument is null, a horizontal glue object is added at that position.


JET

JET is Copyright (C) 2005-2008 by The University of Texas at El Paso and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.