org.opensourcephysics.display
Class OSPFrame

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byorg.opensourcephysics.display.OSPFrame
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants
Direct Known Subclasses:
ControlFrame, DatasetTool, DataTableFrame, DrawingFrame, DrawingFrame3D, EncryptionTool, GridTableFrame, TranslatorTool

public class OSPFrame
extends javax.swing.JFrame
implements java.awt.print.Printable

OSPFrame is the base class for Open Source Physics JFrames such as DrawingFrame and DataTableFrame. Copyright: Copyright (c) 2002

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  boolean animated
          Set to true if a simulation should automatically render this frame after every animation step.
static javax.swing.JApplet applet
          Field myApplet provides a static reference to an applet context so that the document base and the code base can be obtained in applet mode.
static boolean appletMode
          Set true if the program is an applet.
protected static boolean authorMode
          Set true if a program should allows users to author internal parameters such as Locale strings.
protected  boolean autoclear
          Set to true if a simulation should automatically clear the data when it is initialized.
protected  javax.swing.JPanel buttonPanel
           
static java.lang.String chooserDir
          File Chooser starting directory.
 java.lang.ThreadGroup constructorThreadGroup
          The thread group that created this object.
protected  java.util.ArrayList customButtons
           
static boolean DEFAULT_LOOK_AND_FEEL
          Look and feel property for the graphical user interface.
protected static java.util.Locale[] defaultLocales
           
protected  boolean keepHidden
           
protected static boolean launcherMode
          Set true if a program is being run within Launcher.
static java.lang.String osp_icon_file
          Location of OSP icon.
protected  java.awt.image.BufferStrategy strategy
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
OSPFrame()
          OSPFrame constructor.
OSPFrame(java.awt.Container contentPane)
          OSPFrame constructor with a new content pane.
OSPFrame(java.lang.String title)
          OSPFrame constructor with a title.
 
Method Summary
 javax.swing.JButton addButton(java.lang.String methodName, java.lang.String text, java.lang.String toolTipText, java.lang.Object target)
          Adds a custom button to the control's frame.
 void bufferStrategyShow()
          Shows (repaints) the frame useing the current BufferStrategy.
 void clearData()
          Clears data from drawing objects within this frame.
 void clearDataAndRepaint()
          Clears data and repaints the drawing panel within this frame.
 void createBufferStrategy()
          Creates a BufferStrategy based on the capabilites of the hardware.
 void dispose()
           
static javax.swing.JFileChooser getChooser()
          Gets a file chooser.
 java.lang.ThreadGroup getConstructorThreadGroup()
          Gets the ThreadGroup that constructed this frame.
static java.util.Locale[] getDefaultLocales()
          Gets Locales for langauges that have properties files in the core library.
 javax.swing.JMenu getMenu(java.lang.String menuName)
          Gets a menu with the given name from the menu bar.
 void invalidateImage()
          Invalidates image buffers if a drawing panel is buffered.
 boolean isAnimated()
          Reads the animated property.
static boolean isAuthorMode()
          Gets the authorMode property.
 boolean isAutoclear()
          Reads the animated property.
 boolean isIconified()
          Gets the ICONIFIED flag for this frame.
 boolean isKeepHidden()
          Reads the keepHidden flag.
static boolean isLauncherMode()
          Gets the launcherMode property.
protected  javax.swing.JMenu loadDisplayMenu()
          Adds a Display menu to the menu bar.
protected  javax.swing.JMenu loadToolsMenu()
          Adds a Tools menu to the menu bar.
 void parseXMLMenu(java.lang.String xmlMenu)
          Creates a menu in the menu bar from the given XML document.
 void parseXMLMenu(java.lang.String xmlMenu, java.lang.Class type)
          Creates a menu in the menu bar from the given XML document.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
          Draws the panel into a graphics object suitable for printing.
protected  void refreshGUI()
          Refreshes the user interface in response to display changes such as Language.
 javax.swing.JMenu removeMenu(java.lang.String menuName)
          Removes a menu with the given name from the menu bar and returns the removed item.
 javax.swing.JMenuItem removeMenuItem(java.lang.String menuName, java.lang.String itemName)
          Removes a menu item with the given name from the menu bar and returns the removed item.
 void render()
          Renders the frame.
 void setAnimated(boolean animated)
          Sets the animated property.
static void setAuthorMode(boolean b)
          Sets the authorMode property.
 void setAutoclear(boolean autoclear)
          Sets the autoclear property.
 void setDefaultCloseOperation(int operation)
          Overrides JFrame method.
protected  void setFontLevel(int level)
          Sets the font level.
 void setKeepHidden(boolean _keepHidden)
          Sets the keepHidden flag.
static void setLauncherMode(boolean b)
          Sets the launcherMode property.
 void setSize(int width, int height)
           
 void setTitle(java.lang.String title)
          Sets the title for this frame to the specified string after converting TeX math symbols to characters.
 void setVisible(boolean b)
          Shows or hides this component depending on the value of parameter b and the keepHidden flag.
 void show()
          Deprecated.  
 boolean wishesToExit()
          Returns true if this frame wishes to exit.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

DEFAULT_LOOK_AND_FEEL

public static boolean DEFAULT_LOOK_AND_FEEL
Look and feel property for the graphical user interface.


osp_icon_file

public static final java.lang.String osp_icon_file
Location of OSP icon.

See Also:
Constant Field Values

chooserDir

public static java.lang.String chooserDir
File Chooser starting directory.


customButtons

protected java.util.ArrayList customButtons

defaultLocales

protected static java.util.Locale[] defaultLocales

animated

protected boolean animated
Set to true if a simulation should automatically render this frame after every animation step.


autoclear

protected boolean autoclear
Set to true if a simulation should automatically clear the data when it is initialized.


appletMode

public static boolean appletMode
Set true if the program is an applet.


launcherMode

protected static boolean launcherMode
Set true if a program is being run within Launcher.


authorMode

protected static boolean authorMode
Set true if a program should allows users to author internal parameters such as Locale strings.


applet

public static javax.swing.JApplet applet
Field myApplet provides a static reference to an applet context so that the document base and the code base can be obtained in applet mode.


constructorThreadGroup

public java.lang.ThreadGroup constructorThreadGroup
The thread group that created this object.


keepHidden

protected boolean keepHidden

strategy

protected java.awt.image.BufferStrategy strategy

buttonPanel

protected javax.swing.JPanel buttonPanel
Constructor Detail

OSPFrame

public OSPFrame(java.lang.String title)
OSPFrame constructor with a title.


OSPFrame

public OSPFrame()
OSPFrame constructor.


OSPFrame

public OSPFrame(java.awt.Container contentPane)
OSPFrame constructor with a new content pane.

Method Detail

getDefaultLocales

public static java.util.Locale[] getDefaultLocales()
Gets Locales for langauges that have properties files in the core library.

Returns:
Locale[]

setAuthorMode

public static void setAuthorMode(boolean b)
Sets the authorMode property. AuthorMode allows users to author internal parameters such as Locale strings.

Parameters:
b - boolean

isAuthorMode

public static boolean isAuthorMode()
Gets the authorMode property. AuthorMode allows users to author internal parameters such as Locale strings.

Returns:
boolean

setLauncherMode

public static void setLauncherMode(boolean b)
Sets the launcherMode property. LauncherMode disables access to propertes, such as Locale, that affect the VM.

Parameters:
b - boolean

isLauncherMode

public static boolean isLauncherMode()
Gets the launcherMode property. LauncherMode disables access to propertes, such as Locale, that affect the VM.

Returns:
boolean

setTitle

public void setTitle(java.lang.String title)
Sets the title for this frame to the specified string after converting TeX math symbols to characters.

Parameters:
title - the title to be displayed in the frame's border. A null value is treated as an empty string, "".
See Also:
Frame.getTitle()

isIconified

public boolean isIconified()
Gets the ICONIFIED flag for this frame.

Returns:
boolean true if frame is iconified; false otherwise

invalidateImage

public void invalidateImage()
Invalidates image buffers if a drawing panel is buffered.


setFontLevel

protected void setFontLevel(int level)
Sets the font level.

Parameters:
level - the level

isAnimated

public boolean isAnimated()
Reads the animated property.

Returns:
boolean

setAnimated

public void setAnimated(boolean animated)
Sets the animated property.

Parameters:
animated -

isAutoclear

public boolean isAutoclear()
Reads the animated property.

Returns:
boolean

setAutoclear

public void setAutoclear(boolean autoclear)
Sets the autoclear property.

Parameters:
autoclear -

loadDisplayMenu

protected javax.swing.JMenu loadDisplayMenu()
Adds a Display menu to the menu bar. The default method does nothing. Override this method to create a menu item that is appropriate for the frame.


loadToolsMenu

protected javax.swing.JMenu loadToolsMenu()
Adds a Tools menu to the menu bar. The default method does nothing. Override this method to create a menu item that is appropriate for the frame.


clearData

public void clearData()
Clears data from drawing objects within this frame. The default method does nothing. Override this method to select the object(s) and the data to be cleared.


clearDataAndRepaint

public void clearDataAndRepaint()
Clears data and repaints the drawing panel within this frame. The default method does nothing. Override this method to clear and repaint objects that have data.


setSize

public void setSize(int width,
                    int height)

show

public void show()
Deprecated.  

Shows the frame on the screen if the keep hidden flag is false.


dispose

public void dispose()

setVisible

public void setVisible(boolean b)
Shows or hides this component depending on the value of parameter b and the keepHidden flag. OSP Applets often keep windows hidden.

Parameters:
b -

setKeepHidden

public void setKeepHidden(boolean _keepHidden)
Sets the keepHidden flag.

Parameters:
_keepHidden -

isKeepHidden

public boolean isKeepHidden()
Reads the keepHidden flag.


getConstructorThreadGroup

public java.lang.ThreadGroup getConstructorThreadGroup()
Gets the ThreadGroup that constructed this frame.

Returns:
the ThreadGroup

createBufferStrategy

public void createBufferStrategy()
Creates a BufferStrategy based on the capabilites of the hardware.


bufferStrategyShow

public void bufferStrategyShow()
Shows (repaints) the frame useing the current BufferStrategy.


render

public void render()
Renders the frame. Subclass this method to render the contents of this frame in the calling thread.


getMenu

public javax.swing.JMenu getMenu(java.lang.String menuName)
Gets a menu with the given name from the menu bar. Returns null if menu item does not exist.

Parameters:
menuName - String
Returns:
JMenu

removeMenu

public javax.swing.JMenu removeMenu(java.lang.String menuName)
Removes a menu with the given name from the menu bar and returns the removed item. Returns null if menu item does not exist.

Parameters:
menuName - String
Returns:
JMenu

removeMenuItem

public javax.swing.JMenuItem removeMenuItem(java.lang.String menuName,
                                            java.lang.String itemName)
Removes a menu item with the given name from the menu bar and returns the removed item. Returns null if menu item does not exist.

Parameters:
menuName - String
Returns:
JMenu

parseXMLMenu

public void parseXMLMenu(java.lang.String xmlMenu)
Creates a menu in the menu bar from the given XML document.

Parameters:
xmlMenu - name of the xml file with menu data

parseXMLMenu

public void parseXMLMenu(java.lang.String xmlMenu,
                         java.lang.Class type)
Creates a menu in the menu bar from the given XML document.

Parameters:
xmlMenu - name of the xml file with menu data
type - the class to load the menu, may be null

getChooser

public static javax.swing.JFileChooser getChooser()
Gets a file chooser. The choose is static and will therefore be the same for all OSPFrames.

Returns:
the chooser

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Draws the panel into a graphics object suitable for printing.

Specified by:
print in interface java.awt.print.Printable
Parameters:
g -
pageFormat -
pageIndex -
Returns:
status code
Throws:
java.awt.print.PrinterException

refreshGUI

protected void refreshGUI()
Refreshes the user interface in response to display changes such as Language.


addButton

public javax.swing.JButton addButton(java.lang.String methodName,
                                     java.lang.String text,
                                     java.lang.String toolTipText,
                                     java.lang.Object target)
Adds a custom button to the control's frame.

Parameters:
methodName - the name of the method; the method has no parameters
text - the button's text label
toolTipText - the button's tool tip text
target - the target for the method
Returns:
the custom button

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)
Overrides JFrame method. This converts EXIT_ON_CLOSE to DISPOSE_ON_CLOSE and sets the wishesToExit flag.

Parameters:
operation - the operation

wishesToExit

public boolean wishesToExit()
Returns true if this frame wishes to exit. Launcher uses this to identify control frames.

Returns:
true if this frame wishes to exit