jmri.util
Class JmriJFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by jmri.util.JmriJFrame
All Implemented Interfaces:
ComponentListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, ModifiedFlag
Direct Known Subclasses:
AbstractAudioFrame, AbstractMonFrame, AbstractPacketGenFrame, AcelaPacketGenFrame, AddSensorJFrame, AddSignalMastJFrame, AlignTableFrame, AlmBrowserFrame, AnalogClockFrame, AutomatTableFrame, AutoTrainsFrame, BeanTableFrame, BlockBossFrame, CanSendFrame, CbusConsoleFrame, CbusEventFilterFrame, CbusEventTableFrame, ConfigToolFrame, ConsistToolFrame, ControllerFilterFrame, CoordinateEdit, DataSource, DebuggerFrame, DiagnosticFrame, DispatcherFrame, DualDecoderSelectFrame, EasyDccPacketGenFrame, EditCircuitFrame, EditCircuitPaths, Editor, Editor.JFrameItem, EditorFrame, EditPortalFrame, FollowerFrame, HexFileFrame, ImageIndexEditor, ItemPalette, JmriServerFrame, JmriSRCPServerFrame, LcdClockFrame, LearnThrottleFrame, LI101Frame, ListFrame, ListFrame, LIUSBConfigFrame, LoaderFrame, LogFrame, LV102Frame, LZ100Frame, LZV100Frame, MdiMainFrame, MiniServerPrefsFrame, MultiPaneWindow, MultiSensorIconFrame, NetworkPortFrame, NixieClockFrame, NodeConfigFrame, NodeConfigFrame, NodeConfigFrame, NodeConfigFrame, NodeConfigFrame, NodeConfigFrame, NodeConfigToolFrame, NodeTableFrame, OpenLcbCanSendFrame, OperationsFrame, OsIndicatorFrame, PacketGenFrame, PacketGenFrame, PacketGenFrame, PacketGenFrame, PacketGenFrame, PacketTableFrame, PaneProgFrame, PickFrame, PollTableFrame, PowerPanelFrame, PowerPanelFrame, PreferencesFrame, RenumberFrame, ReportFrame, RosterGroupTableFrame, RpsTrackingFrame, SendPacketFrame, SensorGroupFrame, SensorTextEdit, SerialPacketGenFrame, SerialPacketGenFrame, SerialPacketGenFrame, SerialPacketGenFrame, SerialPacketGenFrame, SerialPacketGenFrame, SerialPacketGenFrame, SerialPortFrame, ServerFrame, SignallingFrame, SignallingSourceFrame, SimpleClockFrame, SimpleLightCtrlFrame, SimpleProgFrame, SimpleServerFrame, SimpleTurnoutCtrlFrame, SlipTurnoutTextEdit, SoundSetFrame, SpeedoConsoleFrame, SpeedometerFrame, SplashWindow, SprogHexFile, SprogPacketGenFrame, SprogSlotMonFrame, SprogUpdateFrame, StackMonFrame, StatusFrame, StatusFrame, SymbolicProgFrame, SystemInfoFrame, TabbedPreferencesFrame, TableFrames, ThreePaneTLRWindow, ThrottleWindow, TieToolFrame, TreeFrame, TwoPaneTBWindow, UserInterface, WarrantFrame, WiThrottlePrefsFrame, XpaConfigureFrame, XpaPacketGenFrame, ZimoPacketGenFrame

public class JmriJFrame
extends JFrame
implements WindowListener, ModifiedFlag, ComponentListener

JFrame extended for common JMRI use.

We needed a place to refactor common JFrame additions in JMRI code, so this class was created.

Features:

Window Closing

Normally, a JMRI window wants to be disposed when it closes. This is what's needed when each invocation of the corresponding action can create a new copy of the window. To do this, you don't have to do anything in your subclass. This class has


 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE)

If you want this behavior, but need to do something when the window is closing, override the windowClosing(java.awt.event.WindowEvent) method to do what you want. Also, if you override dispose(), make sure to call super.dispose().

If you want the window to just do nothing or just hide, rather than be disposed, when closed, set the DefaultCloseOperation to DO_NOTHING_ON_CLOSE or HIDE_ON_CLOSE depending on what you're looking for.

Author:
Bob Jacobsen Copyright 2003, 2008
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  boolean reuseFrameSavedPosition
           
protected  boolean reuseFrameSavedSized
           
 
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 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
JmriJFrame()
           
JmriJFrame(boolean saveSize, boolean savePosition)
          Creates a JFrame
JmriJFrame(String name)
           
JmriJFrame(String name, boolean saveSize, boolean savePosition)
          Creates a JMRI JFrame
 
Method Summary
 void addHelpMenu(String ref, boolean direct)
          Add a standard help menu, including window specific help item.
 void addNotify()
           
 void componentHidden(ComponentEvent e)
           
 void componentMoved(ComponentEvent e)
           
 void componentResized(ComponentEvent e)
           
 void componentShown(ComponentEvent e)
           
 void dispose()
          When window is finally destroyed, remove it from the list of windows.
 void generateWindowRef()
          Regenerates the window frame ref that is used for saving and setting frame size and position against.
static JmriJFrame getFrame(String name)
          Get a JmriJFrame of a particular name.
static List<JmriJFrame> getFrameList()
          Get a List of the currently-existing JmriJFrame objects.
 Dimension getMaximumSize()
          Provide a maximum frame size that is limited to what can fit on the screen after toolbars, etc are deducted.
 boolean getModifiedFlag()
          Get the balue of the modified flag.
 Dimension getPreferredSize()
          The preferred size must fit on the physical screen, so calculate the lesser of either the preferred size from the layout or the screen size.
 boolean getSavePosition()
          Returns if the frame Position is saved or not
 boolean getSaveSize()
          Returns if the frame Size is saved or not
protected  String getWindowFrameRef()
           
protected  void handleModified()
          Handle closing a window or quiting the program while the modified bit was set.
 void initComponents()
          By default, Swing components should be created an installed in this method, rather than in the ctor itself.
 void markWindowModified(boolean yes)
           
 void pack()
           
 void setModifiedFlag(boolean flag)
          A frame is considered "modified" if it has changes that have not been stored.
 void setSavePosition(boolean save)
          Set whether the frame Position is saved or not after it has been created.
 void setSaveSize(boolean save)
          Set whether the frame Size is saved or not after it has been created
protected  void setShutDownTask()
           
protected  void storeValues()
           
 void windowActivated(WindowEvent e)
           
 void windowClosed(WindowEvent e)
           
 void windowClosing(WindowEvent e)
           
 void windowDeactivated(WindowEvent e)
           
 void windowDeiconified(WindowEvent e)
           
 void windowIconified(WindowEvent e)
           
 void windowOpened(WindowEvent e)
           
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, 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, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

reuseFrameSavedPosition

protected boolean reuseFrameSavedPosition

reuseFrameSavedSized

protected boolean reuseFrameSavedSized
Constructor Detail

JmriJFrame

public JmriJFrame(boolean saveSize,
                  boolean savePosition)
Creates a JFrame

Parameters:
saveSize - - Set true to save the last known size
savePosition - - Set true to save the last known location

JmriJFrame

public JmriJFrame()

JmriJFrame

public JmriJFrame(String name)

JmriJFrame

public JmriJFrame(String name,
                  boolean saveSize,
                  boolean savePosition)
Creates a JMRI JFrame

Parameters:
name - - Title of the JFrame
saveSize - - Set true to save the last knowm size
savePosition - - Set true to save the last known location
Method Detail

generateWindowRef

public void generateWindowRef()
Regenerates the window frame ref that is used for saving and setting frame size and position against.


pack

public void pack()
Overrides:
pack in class Window

getWindowFrameRef

protected String getWindowFrameRef()

initComponents

public void initComponents()
                    throws Exception
By default, Swing components should be created an installed in this method, rather than in the ctor itself.

Throws:
Exception

addHelpMenu

public void addHelpMenu(String ref,
                        boolean direct)
Add a standard help menu, including window specific help item.

Parameters:
ref - JHelp reference for the desired window-specific help page
direct - true if the help menu goes directly to the help system, e.g. there are no items in the help menu

getMaximumSize

public Dimension getMaximumSize()
Provide a maximum frame size that is limited to what can fit on the screen after toolbars, etc are deducted.

Some of the methods used here return null pointers on some Java implementations, however, so this will return the superclasses's maximum size if the algorithm used here fails.

Overrides:
getMaximumSize in class Container

getPreferredSize

public Dimension getPreferredSize()
The preferred size must fit on the physical screen, so calculate the lesser of either the preferred size from the layout or the screen size.

Overrides:
getPreferredSize in class Container

getFrameList

public static List<JmriJFrame> getFrameList()
Get a List of the currently-existing JmriJFrame objects. The returned list is a copy made at the time of the call, so it can be manipulated as needed by the caller.


getFrame

public static JmriJFrame getFrame(String name)
Get a JmriJFrame of a particular name. If more than one exists, there's no guarantee as to which is returned.


addNotify

public void addNotify()
Overrides:
addNotify in class Frame

setSavePosition

public void setSavePosition(boolean save)
Set whether the frame Position is saved or not after it has been created.


setSaveSize

public void setSaveSize(boolean save)
Set whether the frame Size is saved or not after it has been created


getSavePosition

public boolean getSavePosition()
Returns if the frame Position is saved or not


getSaveSize

public boolean getSaveSize()
Returns if the frame Size is saved or not


setModifiedFlag

public void setModifiedFlag(boolean flag)
A frame is considered "modified" if it has changes that have not been stored.

Specified by:
setModifiedFlag in interface ModifiedFlag
Parameters:
flag - true if the object has been modified

getModifiedFlag

public boolean getModifiedFlag()
Get the balue of the modified flag.

Not a bound parameter

Specified by:
getModifiedFlag in interface ModifiedFlag
Returns:
true if the object has been modified and needs to be stored

handleModified

protected void handleModified()
Handle closing a window or quiting the program while the modified bit was set.


storeValues

protected void storeValues()

markWindowModified

public void markWindowModified(boolean yes)

windowOpened

public void windowOpened(WindowEvent e)
Specified by:
windowOpened in interface WindowListener

windowClosed

public void windowClosed(WindowEvent e)
Specified by:
windowClosed in interface WindowListener

windowActivated

public void windowActivated(WindowEvent e)
Specified by:
windowActivated in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent e)
Specified by:
windowDeactivated in interface WindowListener

windowIconified

public void windowIconified(WindowEvent e)
Specified by:
windowIconified in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent e)
Specified by:
windowDeiconified in interface WindowListener

windowClosing

public void windowClosing(WindowEvent e)
Specified by:
windowClosing in interface WindowListener

componentHidden

public void componentHidden(ComponentEvent e)
Specified by:
componentHidden in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Specified by:
componentMoved in interface ComponentListener

componentResized

public void componentResized(ComponentEvent e)
Specified by:
componentResized in interface ComponentListener

componentShown

public void componentShown(ComponentEvent e)
Specified by:
componentShown in interface ComponentListener

setShutDownTask

protected void setShutDownTask()

dispose

public void dispose()
When window is finally destroyed, remove it from the list of windows.

Subclasses that over-ride this method must invoke this implementation with super.dispose()

Overrides:
dispose in class Window


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads