org.proteinshader.gui.components
Class SpringLoadedJFrame

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 org.proteinshader.gui.components.SpringLoadedJFrame
All Implemented Interfaces:
ComponentListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class SpringLoadedJFrame
extends JFrame
implements ComponentListener, WindowListener

Provides a spring-loaded (retractable) JFrame that will adjust its size and position relative to a parent JFrame.

The JFrame that is given as an argument to this frame's constructor is considered the parent frame (parent in a graph sense), and this frame will always calculate its position and size relative to its parent frame. Tracking the parent frame's size, position, and iconfication status is accomplished by having this frame register itself as a ComponentListener and WindowListener for its parent frame.

The setVisible(boolean b) of JFrame is overloaded with setVisible(boolean visiblity, boolean animate) so that it will open on a Timer that first hides the spring-loaded frame behind its parent frame and then slides it out to create the appearance of a retractable panel. Conversely, closing the spring-loaded frame with animation will slide it behind the parent frame before setting it invisible.

The frame close box still has the default behavior of immediately closing the frame, but this can be easily changed to close with animation by using frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ) and then adding a WindowListener (or WindowAdaptor) in which the windowClosing() method calls on frame.setVisible(false, true).

If the two-argument constructor is given a position argument of LEFT or RIGHT, then the spring-loaded frame will have dimensions:

width = parent frame width * DEFAULT_SHORT_FACTOR
height = parent frame height * DEFAULT_LONG_FACTOR


On the other hand, if the position is set to TOP or BOTTOM, then the factors are switched to give dimensions:

width = parent frame width * DEFAULT_LONG_FACTOR
height = parent frame height * DEFAULT_SHORT_FACTOR


For most purposes, a DEFAULT_SHORT_FACTOR of 0.25 and a DEFAULT_LONG_FACTOR of 0.90 seem reasonable.

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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static double DEFAULT_LONG_FACTOR
          Default height for LEFT or RIGHT spring-loaded frame, but default width for TOP or BOTTOM spring-loaded frame.
static double DEFAULT_SHORT_FACTOR
          0.25 is the default width for LEFT or RIGHT spring-loaded frame, but the default height for TOP or BOTTOM spring-loaded frame.
static int DELAY
          Sets the delay for the timer circuit used to open the spring-loaded frame.
static double INCREMENT
          Sets the increment for the timer circuit used to open the spring-loaded frame.
static double MAX_HEIGHT_FACTOR
          The height factor will not be allowed to be more than 0.90.
static double MAX_WIDTH_FACTOR
          The width factor will not be allowed to be more than 0.90.
static double MIN_HEIGHT_FACTOR
          The height factor will not be allowed to be less than 0.10.
static double MIN_WIDTH_FACTOR
          The width factor will not be allowed to be less than 0.10.
 
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
SpringLoadedJFrame(JFrame parent, OrientationEnum position)
          Constructs a SpringLoadedJFrame using default width and height factors based on whether the spring-loaded frame is attached to its parent frame at the TOP, BOTTOM, LEFT, or RIGHT (see comments for DEFAULT_SHORT_FACTOR and DEFAULT_LONG_FACTOR).
SpringLoadedJFrame(JFrame parent, OrientationEnum position, double widthFactor, double heightFactor)
          Constructs a SpringLoadedJFrame.
 
Method Summary
 void clearTimer()
          Stops the timer (if it is running) and sets it to null.
 void componentHidden(ComponentEvent e)
          This method is called automatically when the parent frame is made invisible, so it will hide this frame if it is visible.
 void componentMoved(ComponentEvent e)
          This method is called automatically when the parent frame's position changes, and it will recalculate this frame's bounds.
 void componentResized(ComponentEvent e)
          This method is called automatically when the parent frame's size changes, and it will recalculate this frame's bounds.
 void componentShown(ComponentEvent e)
          This method is called automatically when the parent frame has been made visible, so it will set this frame visible if it had been hidden with the parent.
 void setHeightFactor(double heightFactor)
          Sets the height factor.
 void setVisible(boolean visibility, boolean animate)
          If animate is true, a timer is used to gradually open or close the frame.
 void setWidthFactor(double widthFactor)
          Sets the width factor.
 void windowActivated(WindowEvent e)
          NOT USED: This method is called when the parent frame is set to be the active window.
 void windowClosed(WindowEvent e)
          NOT USED: This method is called when the parent frame has been closed as the result of calling dispose on the window.
 void windowClosing(WindowEvent e)
          NOT USED: This method is called when the user attempts to close the parent frame from its system menu.
 void windowDeactivated(WindowEvent e)
          NOT USED: This method is called when the parent frame is no longer the active window.
 void windowDeiconified(WindowEvent e)
          This method is called automatically when the parent frame is deiconified, and if this frame was hidden when the parent had been iconified, then this frame will be made visible again.
 void windowIconified(WindowEvent e)
          This method is called automatically when the parent frame is iconified, and if this frame is visible, it will be hidden.
 void windowOpened(WindowEvent e)
          NOT USED: This method is called when the parent frame is made visible for the first time.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, 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, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, 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, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, 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, 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, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

DELAY

public static final int DELAY
Sets the delay for the timer circuit used to open the spring-loaded frame.

See Also:
Constant Field Values

INCREMENT

public static final double INCREMENT
Sets the increment for the timer circuit used to open the spring-loaded frame.

See Also:
Constant Field Values

MIN_WIDTH_FACTOR

public static final double MIN_WIDTH_FACTOR
The width factor will not be allowed to be less than 0.10.

See Also:
Constant Field Values

MAX_WIDTH_FACTOR

public static final double MAX_WIDTH_FACTOR
The width factor will not be allowed to be more than 0.90.

See Also:
Constant Field Values

MIN_HEIGHT_FACTOR

public static final double MIN_HEIGHT_FACTOR
The height factor will not be allowed to be less than 0.10.

See Also:
Constant Field Values

MAX_HEIGHT_FACTOR

public static final double MAX_HEIGHT_FACTOR
The height factor will not be allowed to be more than 0.90.

See Also:
Constant Field Values

DEFAULT_SHORT_FACTOR

public static final double DEFAULT_SHORT_FACTOR
0.25 is the default width for LEFT or RIGHT spring-loaded frame, but the default height for TOP or BOTTOM spring-loaded frame.

See Also:
Constant Field Values

DEFAULT_LONG_FACTOR

public static final double DEFAULT_LONG_FACTOR
Default height for LEFT or RIGHT spring-loaded frame, but default width for TOP or BOTTOM spring-loaded frame.

See Also:
Constant Field Values
Constructor Detail

SpringLoadedJFrame

public SpringLoadedJFrame(JFrame parent,
                          OrientationEnum position)
Constructs a SpringLoadedJFrame using default width and height factors based on whether the spring-loaded frame is attached to its parent frame at the TOP, BOTTOM, LEFT, or RIGHT (see comments for DEFAULT_SHORT_FACTOR and DEFAULT_LONG_FACTOR).

The OrientationEnum given as an argument will determine whether this spring-loaded frame will attach itself to the TOP, BOTTOM, LEFT, or RIGHT of the parent frame.

Parameters:
parent - the frame that this frame should attach itself to.
position - where this frame should attach to its parent.
Throws:
NullPointerException - if parent or position is null.

SpringLoadedJFrame

public SpringLoadedJFrame(JFrame parent,
                          OrientationEnum position,
                          double widthFactor,
                          double heightFactor)
Constructs a SpringLoadedJFrame.

The OrientationEnum given as an argument will determine whether this spring-loaded frame will attach itself to the TOP, BOTTOM, LEFT, or RIGHT of the parent frame.

This frame will calculate its width and height by multiplying its parent frame's width and height by the widthFactor and heightFactor, respectively. If a widthFactor is less than MIN_WIDTH_FACTOR or more than MAX_WIDTH_FACTOR, it will be reset to the min or max, respectively. The heightFactor will also only be allowed to range from MIN_HEIGHT_FACTOR to MAX_HEIGHT_FACTOR.

Parameters:
parent - the frame that this frame should attach itself to.
position - where this frame should attach to its parent.
widthFactor - for calculating this frame's width.
heightFactor - for calculating this frame's height.
Throws:
NullPointerException - if parent or position is null.
Method Detail

setWidthFactor

public void setWidthFactor(double widthFactor)
Sets the width factor. The width of this frame will be calculated by multiplying the width of the parent frame by the width factor. The width factor will be tested (and reset if necessary) to make sure that it is between MIN_WIDTH_FACTOR and MAX_WIDTH_FACTOR.

Parameters:
widthFactor - for calculating this frame's width.

setHeightFactor

public void setHeightFactor(double heightFactor)
Sets the height factor. The height of this frame will be calculated by multiplying the height of the parent frame by the height factor. The height factor will be tested (and reset if necessary) to make sure that it is between MIN_HEIGHT_FACTOR and MAX_HEIGHT_FACTOR.

Parameters:
heightFactor - for calculating this frame's height.

setVisible

public void setVisible(boolean visibility,
                       boolean animate)
If animate is true, a timer is used to gradually open or close the frame. Note that calling setVisible(true, false) is slightly different than calling setVisible(true) of JFrame in that setVisible(true, false) will adjust the size and location of this frame (based on the parent frame's size and location) before setting it visible, whereas setVisible(true) will simply set the frame visible with whatever its current location and size happen to be.

Parameters:
visibility - determines if frame should be set visible.
animate - determines if frame should be gradually opened or closed.

componentMoved

public void componentMoved(ComponentEvent e)
This method is called automatically when the parent frame's position changes, and it will recalculate this frame's bounds.

Specified by:
componentMoved in interface ComponentListener

componentResized

public void componentResized(ComponentEvent e)
This method is called automatically when the parent frame's size changes, and it will recalculate this frame's bounds.

Specified by:
componentResized in interface ComponentListener

componentHidden

public void componentHidden(ComponentEvent e)
This method is called automatically when the parent frame is made invisible, so it will hide this frame if it is visible.

Specified by:
componentHidden in interface ComponentListener

componentShown

public void componentShown(ComponentEvent e)
This method is called automatically when the parent frame has been made visible, so it will set this frame visible if it had been hidden with the parent.

Specified by:
componentShown in interface ComponentListener

windowIconified

public void windowIconified(WindowEvent e)
This method is called automatically when the parent frame is iconified, and if this frame is visible, it will be hidden.

Specified by:
windowIconified in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowDeiconified

public void windowDeiconified(WindowEvent e)
This method is called automatically when the parent frame is deiconified, and if this frame was hidden when the parent had been iconified, then this frame will be made visible again.

Specified by:
windowDeiconified in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowActivated

public void windowActivated(WindowEvent e)
NOT USED: This method is called when the parent frame is set to be the active window.

Specified by:
windowActivated in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowDeactivated

public void windowDeactivated(WindowEvent e)
NOT USED: This method is called when the parent frame is no longer the active window.

Specified by:
windowDeactivated in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowOpened

public void windowOpened(WindowEvent e)
NOT USED: This method is called when the parent frame is made visible for the first time.

Specified by:
windowOpened in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowClosed

public void windowClosed(WindowEvent e)
NOT USED: This method is called when the parent frame has been closed as the result of calling dispose on the window.

Specified by:
windowClosed in interface WindowListener
Parameters:
e - the window event for the parent frame.

windowClosing

public void windowClosing(WindowEvent e)
NOT USED: This method is called when the user attempts to close the parent frame from its system menu.

Specified by:
windowClosing in interface WindowListener
Parameters:
e - the window event for the parent frame.

clearTimer

public void clearTimer()
Stops the timer (if it is running) and sets it to null.



Copyright © 2007-2008