|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Window java.awt.Frame javax.swing.JFrame org.proteinshader.gui.components.SpringLoadedJFrame
public class SpringLoadedJFrame
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.
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 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.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Field Detail |
---|
public static final int DELAY
public static final double INCREMENT
public static final double MIN_WIDTH_FACTOR
public static final double MAX_WIDTH_FACTOR
public static final double MIN_HEIGHT_FACTOR
public static final double MAX_HEIGHT_FACTOR
public static final double DEFAULT_SHORT_FACTOR
public static final double DEFAULT_LONG_FACTOR
Constructor Detail |
---|
public SpringLoadedJFrame(JFrame parent, OrientationEnum position)
parent
- the frame that this frame should attach itself to.position
- where this frame should attach to its parent.
NullPointerException
- if parent or position is null.public SpringLoadedJFrame(JFrame parent, OrientationEnum position, double widthFactor, double heightFactor)
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.
NullPointerException
- if parent or position is null.Method Detail |
---|
public void setWidthFactor(double widthFactor)
widthFactor
- for calculating this frame's width.public void setHeightFactor(double heightFactor)
heightFactor
- for calculating this frame's height.public void setVisible(boolean visibility, boolean animate)
visibility
- determines if frame should be set visible.animate
- determines if frame should be gradually opened or
closed.public void componentMoved(ComponentEvent e)
componentMoved
in interface ComponentListener
public void componentResized(ComponentEvent e)
componentResized
in interface ComponentListener
public void componentHidden(ComponentEvent e)
componentHidden
in interface ComponentListener
public void componentShown(ComponentEvent e)
componentShown
in interface ComponentListener
public void windowIconified(WindowEvent e)
windowIconified
in interface WindowListener
e
- the window event for the parent frame.public void windowDeiconified(WindowEvent e)
windowDeiconified
in interface WindowListener
e
- the window event for the parent frame.public void windowActivated(WindowEvent e)
windowActivated
in interface WindowListener
e
- the window event for the parent frame.public void windowDeactivated(WindowEvent e)
windowDeactivated
in interface WindowListener
e
- the window event for the parent frame.public void windowOpened(WindowEvent e)
windowOpened
in interface WindowListener
e
- the window event for the parent frame.public void windowClosed(WindowEvent e)
windowClosed
in interface WindowListener
e
- the window event for the parent frame.public void windowClosing(WindowEvent e)
windowClosing
in interface WindowListener
e
- the window event for the parent frame.public void clearTimer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |