edu.neu.ccs.jpf
Class JPF

java.lang.Object
  extended byedu.neu.ccs.jpf.JPF
All Implemented Interfaces:
ConsoleAware, JPTConstants, SwingConstants

public class JPF
extends Object
implements JPTConstants, ConsoleAware

The Java Power Framework class JPF provides the foundation for creating an automatic Java GUI application with access to the JPT console and a graphics window and to automatically created action buttons. Specifically, the automatic objects available are:

The automatic action buttons are created from the public methods in the class (or chain of classes) derived from JPF that satisfy the following conditions.

The arguments and return types of the public methods may be chosen from the following types:

In addition, the return types of the public methods may also be chosen from the following types:

For each public method that satisfies the above conditions, there is an action button created that executes the method. Method names may be overloaded. The tooltip that is shown when the mouse hovers over an action button will give the full method signature. For a method that has non-trivial arguments or a non-void return type, the click of the action button will bring up an auxiliary GUI so the arguments may be provided and the return value may be shown.

The creation of the automatic Java GUI application is accomplished by a combination of Java reflection and the use of the rest of the Java Power Tools. Since these techniques are encapsulated, a beginner may use the Java Power Framework without any specific knowledge of the JPT.

To use the Java Power Framework class JPF, simply define a class that extends JPF, directly or indirectly, and execute a constructor on that new class. The constructor may implicitly call the default JPF constructor or may call one of the non-default JPF constructors using super.

For example, if a class named Methods extends the class JPF, directly or indirectly, then all public methods that satisfy the above constraints and are defined either in the class Methods itself or in some intermediate class between Methods and JPF will give rise to action buttons in the automatically generated GUI application. These action buttons will execute the methods used to define them.

The structure of a typical Methods class that directly extends JPF will therefore look as follows:

    public class Methods extends JPF {

        public static void main(String[] args) { new Methods(); }

        // enter here any member or static data declarations as desired

        // enter here the public methods to be made into action buttons

        // enter here any non-public helper methods as desired
    }

The Java Power Framework may be used to create action buttons in an automatically generated application for any of the following purposes:

To illustrate how to define a method to launch a separate Java application that we will name, for convenience, Foo, here is the code:

    public void LaunchFoo() { Foo.main(null); }

Placing this code in the Methods class will cause a button to be created in the automatic GUI that is labeled "LaunchFoo" and that launches the application Foo when clicked.

It is also possible to pass arguments to the main method of a class Foo. As on a typical command line, the arguments will be typed in by the user as a String which will then be converted to a String[] as required by main.

    public void LaunchFoo(String arguments) {
        Foo.main(Strings.tokenize(arguments, " \t\n", false));
    }

Notice that the above code parses the arguments parameter using blank, tab, and newline. This actually enables multiline arguments should that be convenient.

It is sometimes desirable to set the look-and-feel via the tools in the class LookAndFeelTools. Calls to such methods should be made in main prior to any constructor invocation for class Methods.

In 2.4.0, added the methods normalConsole, iconifyConsole, maximizeConsole, and toggleConsole.

In 2.6.0, added the member data sequence to access the paintable sequence associated with the graphics window.

In 2.7.0, the class JPFBase was removed as a base class for class JPF. This was a consequence of the decision to create the class JPFApplet which allows JPF-like code to be demonstrated in an applet. Since an applet class must derive from Applet, it was not possible to derive JPFApplet from JPFBase. To keep JPF and JPFApplet as parallel as possible, we made the decision to remove the little used class JPFBase altogether.

In 2.7.0, new constructors are provided that permit the caller to determine if the console should be visible initially and if an additional filter should be used to prune the methods that will instantiated as buttons.

The 2.7.0 default constructor does not show the console initially but does show the graphics window. The console may still be opened via the “Toggle Console” button. This is a change to the default behavior from prior versions of JPF.

In 2.7.0, the console is no longer set to the color text scheme by default. This compensates for a Macintosh Java bug.

Since:
2.2.0
Version:
2.7.0

Field Summary
protected  Action exitAction
          Default application closing action.
 PaintableSequence sequence
          The paintable sequence of the graphics buffered panel window.
protected  JPTFrame theFrame
          The application frame.
protected  JPFPane thePane
          The JPF pane.
protected  Action toggleConsoleAction
          Toggle console action.
protected  Action toggleGraphicsAction
          Toggle graphics action.
 BufferedPanel window
          The graphics buffered panel window.
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface edu.neu.ccs.console.ConsoleAware
console
 
Constructor Summary
JPF()
          Construct the JPF application using as the given initializer the derived class that uses this default constructor.
JPF(boolean showConsole)
          Construct the JPF application using as the given initializer the derived class that uses this special constructor.
JPF(boolean showConsole, MethodFilter filter)
          Construct the JPF application using as the given initializer the derived class that uses this special constructor.
 
Method Summary
protected  void addToggleButtons()
          Adds the two toggle buttons to the pane GUI.
 void clearGraphics()
          Clears the graphics window.
 void exitFramework()
          Exits the framework by calling exitFramework() on the underlying JPFPane pane object.
static JPTFrame frame(Object object)
          Frame the given object in a JPTFrame and open the frame; return the frame constructed.
static JPTFrame frame(Object object, int location)
          Frame the given object in a JPTFrame and open the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; return the frame constructed.
static JPTFrame frame(Object object, String title)
          Frame the given object in a JPTFrame and open the frame; use the given title for the frame; return the frame constructed.
static JPTFrame frame(Object object, String title, Insets insets)
          Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given insets to inset the frame in the screen; return the frame constructed.
static JPTFrame frame(Object object, String title, int location)
          Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; return the frame constructed.
static JPTFrame frame(Object object, String title, int location, Insets insets)
          Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; use the given insets to inset the frame in the screen; return the frame constructed.
static GeneralDialog generalDialog(Object object, Object[][] actionData)
          Place the given object in a modal general dialog and open the dialog; use the action data to define the dialog buttons; return the dialog constructed.
static GeneralDialog generalDialog(Object object, Object[][] actionData, Object defaultAction)
          Place the given object in a modal general dialog and open the dialog; use the action data to define the dialog buttons; use the default action object to define the default button; return the dialog constructed.
static GeneralDialog generalDialog(Object object, String title, Object[][] actionData)
          Place the given object in a modal general dialog and open the dialog; use the given title for the dialog; use the action data to define the dialog buttons; return the dialog constructed.
static GeneralDialog generalDialog(Object object, String title, Object[][] actionData, Object defaultAction)
          Place the given object in a modal general dialog and open the dialog; use the given title for the dialog; use the action data to define the dialog buttons; use the default action object to define the default button; return the dialog constructed.
 JPTFrame getFrame()
          Returns the JPTFrame used to enclose this JPF application.
 JPFPane getPane()
          Returns the JPFPane used to construct this JPF application.
 void iconifyConsole()
          If the console is not activated then activates it; sets the state of the console to iconify.
 boolean isConsoleActivated()
          Returns whether or not the console is activated.
 boolean isGraphicsVisible()
          Returns whether or not the graphics window is visible.
 void makeShapshot()
          Makes a shapshot of the graphics window and shows this snapshot in a separate frame.
 void maximizeConsole()
          If the console is not activated then activates it; sets the state of the console to maximize.
 void normalConsole()
          If the console is not activated then activates it; sets the state of the console to normal.
static GeneralDialog OKCancelDialog(Object object)
          Place the given object in a modal OK-Cancel dialog and open the dialog; return the dialog constructed.
static GeneralDialog OKCancelDialog(Object object, String title)
          Place the given object in a modal OK-Cancel dialog and open the dialog; use the given title for the dialog; return the dialog constructed.
static GeneralDialog OKDialog(Object object)
          Place the given object in a modal OK dialog and open the dialog; return the dialog constructed.
static GeneralDialog OKDialog(Object object, String title)
          Place the given object in a modal OK dialog and open the dialog; use the given title for the dialog; return the dialog constructed.
 void setConsoleActivated(boolean activate)
          Sets the activation of the console.
 void setGraphicsVisible(boolean visible)
          Sets the visibility of the graphics window.
 void showConsole()
          Shows the console.
 void toggleConsole()
          If the console is not activated then activates it; otherwise toggles the state of the console between normal and iconified.
 void toggleGraphics()
          Toggles the visibility of the graphics window.
static GeneralDialog YesNoCancelDialog(Object object)
          Place the given object in a modal Yes-No-Cancel dialog and open the dialog; return the dialog constructed.
static GeneralDialog YesNoCancelDialog(Object object, String title)
          Place the given object in a modal Yes-No-Cancel dialog and open the dialog; use the given title for the dialog; return the dialog constructed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

window

public BufferedPanel window
The graphics buffered panel window.


sequence

public PaintableSequence sequence
The paintable sequence of the graphics buffered panel window.


thePane

protected JPFPane thePane
The JPF pane.


theFrame

protected JPTFrame theFrame
The application frame.


toggleGraphicsAction

protected Action toggleGraphicsAction
Toggle graphics action.


toggleConsoleAction

protected Action toggleConsoleAction
Toggle console action.


exitAction

protected Action exitAction

Default application closing action. Calls:

    setConsoleActivated(false);
    System.exit(0);

Constructor Detail

JPF

public JPF()

Construct the JPF application using as the given initializer the derived class that uses this default constructor.

This constructor shows the graphics window initially but does not show the console.


JPF

public JPF(boolean showConsole)

Construct the JPF application using as the given initializer the derived class that uses this special constructor.

This constructor shows the graphics window initially and shows the console if the given boolean parameter is true.

Parameters:
showConsole - whether or not to initially show the console

JPF

public JPF(boolean showConsole,
           MethodFilter filter)

Construct the JPF application using as the given initializer the derived class that uses this special constructor.

This constructor shows the graphics window initially and shows the console if the given boolean parameter is true; uses the given filter to filter the methods used for buttons.

Parameters:
showConsole - whether or not to initially show the console
filter - an optional method filter to filter the methods used for buttons
Method Detail

getPane

public final JPFPane getPane()

Returns the JPFPane used to construct this JPF application.


getFrame

public final JPTFrame getFrame()

Returns the JPTFrame used to enclose this JPF application.


showConsole

public final void showConsole()

Shows the console.

No longer sets the console to the color text scheme by default. This compensates for a Macintosh Java bug.


isConsoleActivated

public final boolean isConsoleActivated()
Returns whether or not the console is activated.


setConsoleActivated

public final void setConsoleActivated(boolean activate)

Sets the activation of the console.

Does nothing if activation will not change.

Parameters:
activate - the desired activation setting

normalConsole

public final void normalConsole()
If the console is not activated then activates it; sets the state of the console to normal.


iconifyConsole

public final void iconifyConsole()
If the console is not activated then activates it; sets the state of the console to iconify.


maximizeConsole

public final void maximizeConsole()
If the console is not activated then activates it; sets the state of the console to maximize.


toggleConsole

public final void toggleConsole()
If the console is not activated then activates it; otherwise toggles the state of the console between normal and iconified.


clearGraphics

public final void clearGraphics()
Clears the graphics window.


isGraphicsVisible

public final boolean isGraphicsVisible()
Returns whether or not the graphics window is visible.


setGraphicsVisible

public final void setGraphicsVisible(boolean visible)

Sets the visibility of the graphics window.

Does nothing if visibility will not change.

Parameters:
visible - the desired visibility setting

toggleGraphics

public final void toggleGraphics()
Toggles the visibility of the graphics window.


makeShapshot

public final void makeShapshot()

Makes a shapshot of the graphics window and shows this snapshot in a separate frame.

This facility is provided to make it easy for users to create a snapshot of the graphics window that may then be saved by utilities that can capture a frame.

This method works whether or not the graphics window is currently visible on screen.

The programmer may make the following call to capture the graphics window to a BufferedImage in order to save the data in a specific format or to do further manipulation.

    BufferedImage snapshot = window.makeSnapshot();


exitFramework

public final void exitFramework()

Exits the framework by calling exitFramework() on the underlying JPFPane pane object. In turn, this method invokes the doClick method on the exit button. This procedure guarantees that the exit behavior will be identical to the action attached to the exit button.


addToggleButtons

protected final void addToggleButtons()
Adds the two toggle buttons to the pane GUI.


frame

public static JPTFrame frame(Object object)

Frame the given object in a JPTFrame and open the frame; return the frame constructed.

Parameters:
object - the object to frame
Returns:
the frame constructed
Since:
2.3.4

frame

public static JPTFrame frame(Object object,
                             int location)

Frame the given object in a JPTFrame and open the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; return the frame constructed.

Parameters:
object - the object to frame
location - the constant representing the frame location
Returns:
the frame constructed
Since:
2.3.4

frame

public static JPTFrame frame(Object object,
                             String title)

Frame the given object in a JPTFrame and open the frame; use the given title for the frame; return the frame constructed.

Parameters:
object - the object to frame
title - the title for the frame
Returns:
the frame constructed
Since:
2.3.4

frame

public static JPTFrame frame(Object object,
                             String title,
                             int location)

Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; return the frame constructed.

Parameters:
object - the object to frame
title - the title for the frame
location - the constant representing the frame location
Returns:
the frame constructed
Since:
2.3.4

frame

public static JPTFrame frame(Object object,
                             String title,
                             Insets insets)

Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given insets to inset the frame in the screen; return the frame constructed.

Parameters:
object - the object to frame
title - the title for the frame
insets - the screen insets to use to adjust the location
Returns:
the frame constructed
Since:
2.3.4

frame

public static JPTFrame frame(Object object,
                             String title,
                             int location,
                             Insets insets)

Frame the given object in a JPTFrame and open the frame; use the given title for the frame; use the given location which should be either CENTER or one of the standard constants for one of the eight compass directions; use the given insets to inset the frame in the screen; return the frame constructed.

Parameters:
object - the object to frame
title - the title for the frame
location - the constant representing the frame location
insets - the screen insets to use to adjust the location
Returns:
the frame constructed
Since:
2.3.4

OKDialog

public static GeneralDialog OKDialog(Object object)

Place the given object in a modal OK dialog and open the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
Returns:
the dialog constructed
Since:
2.3.4

OKDialog

public static GeneralDialog OKDialog(Object object,
                                     String title)

Place the given object in a modal OK dialog and open the dialog; use the given title for the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
title - the title for the dialog
Returns:
the dialog constructed
Since:
2.3.4

OKCancelDialog

public static GeneralDialog OKCancelDialog(Object object)

Place the given object in a modal OK-Cancel dialog and open the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
Returns:
the dialog constructed
Since:
2.3.4

OKCancelDialog

public static GeneralDialog OKCancelDialog(Object object,
                                           String title)

Place the given object in a modal OK-Cancel dialog and open the dialog; use the given title for the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
title - the title for the dialog
Returns:
the dialog constructed
Since:
2.3.4

YesNoCancelDialog

public static GeneralDialog YesNoCancelDialog(Object object)

Place the given object in a modal Yes-No-Cancel dialog and open the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
Returns:
the dialog constructed
Since:
2.3.4

YesNoCancelDialog

public static GeneralDialog YesNoCancelDialog(Object object,
                                              String title)

Place the given object in a modal Yes-No-Cancel dialog and open the dialog; use the given title for the dialog; return the dialog constructed.

Parameters:
object - the object to place in the dialog
title - the title for the dialog
Returns:
the dialog constructed
Since:
2.3.4

generalDialog

public static GeneralDialog generalDialog(Object object,
                                          Object[][] actionData)

Place the given object in a modal general dialog and open the dialog; use the action data to define the dialog buttons; return the dialog constructed.

The parameter actionData is an Object[][] array that specifies each dialog Action in one of the following ways:

If the option parameter is specified, it must be one of the following values that will determine what is done to the dialog when the action is finished:

If the option parameter is not specified, it is taken to be DialogAction.AUTO_CLOSE.

Parameters:
object - the object to place in the dialog
actionData - the action data
Returns:
the dialog constructed
Since:
2.3.4

generalDialog

public static GeneralDialog generalDialog(Object object,
                                          Object[][] actionData,
                                          Object defaultAction)

Place the given object in a modal general dialog and open the dialog; use the action data to define the dialog buttons; use the default action object to define the default button; return the dialog constructed.

The parameter actionData is an Object[][] array that specifies each dialog Action in one of the following ways:

If the option parameter is specified, it must be one of the following values that will determine what is done to the dialog when the action is finished:

If the option parameter is not specified, it is taken to be DialogAction.AUTO_CLOSE.

The Object supplied for the default action must either be an Action or a name that is supplied in the action data. If the parameter is null, no default action is set.

Parameters:
object - the object to place in the dialog
actionData - the action data
defaultAction - the default action
Returns:
the dialog constructed
Since:
2.3.4

generalDialog

public static GeneralDialog generalDialog(Object object,
                                          String title,
                                          Object[][] actionData)

Place the given object in a modal general dialog and open the dialog; use the given title for the dialog; use the action data to define the dialog buttons; return the dialog constructed.

The parameter actionData is an Object[][] array that specifies each dialog Action in one of the following ways:

If the option parameter is specified, it must be one of the following values that will determine what is done to the dialog when the action is finished:

If the option parameter is not specified, it is taken to be DialogAction.AUTO_CLOSE.

Parameters:
object - the object to place in the dialog
title - the title for the dialog
actionData - the action data
Returns:
the dialog constructed
Since:
2.3.4

generalDialog

public static GeneralDialog generalDialog(Object object,
                                          String title,
                                          Object[][] actionData,
                                          Object defaultAction)

Place the given object in a modal general dialog and open the dialog; use the given title for the dialog; use the action data to define the dialog buttons; use the default action object to define the default button; return the dialog constructed.

The parameter actionData is an Object[][] array that specifies each dialog Action in one of the following ways:

If the option parameter is specified, it must be one of the following values that will determine what is done to the dialog when the action is finished:

If the option parameter is not specified, it is taken to be DialogAction.AUTO_CLOSE.

The Object supplied for the default action must either be an Action or a name that is supplied in the action data. If the parameter is null, no default action is set.

Parameters:
object - the object to place in the dialog
title - the title for the dialog
actionData - the action data
defaultAction - the default action
Returns:
the dialog constructed
Since:
2.3.4