de.sciss.gui
Class SpringPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by de.sciss.gui.SpringPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
AudioFileFormatPane, PathField

public class SpringPanel
extends javax.swing.JPanel

A subclass of JPanel that is linked to a SpringLayout. Components must be added using one of the gridAdd methods which define the component's space in terms of a virtual grid. When all components have been added, the actual layout contraints are calculated by calling either makeGrid (for equal cell size grid) or makeCompactGrid. Just like GridBagLayout, the grid positions need not be "compact", i.e. you may omit complete columns or rows and start at an arbitrary offset.

Version:
0.33, 19-Feb-06
Author:
Hanns Holger Rutz
See Also:
Serialized Form
Todo:
the elastic/nonelastic choice isn't working yet

Nested Class Summary
static class SpringPanel.ComponentHeightRatioSpring
           
static class SpringPanel.ComponentWidthRatioSpring
           
static class SpringPanel.RatioSpring
           
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SpringPanel()
          Creates a new panel with zero padding and offset
SpringPanel(int initialX, int initialY, int xPad, int yPad)
          Creates a new panel with given padding and offset (in pixels).
 
Method Summary
 void gridAdd(javax.swing.JComponent c, int x, int y)
          Add a component to the panel and store its placement information for use in makeGrid.
 void gridAdd(javax.swing.JComponent c, int x, int y, int width, int height)
          Add a component to the panel and store its placement information for use in makeGrid.
 void gridAdd(javax.swing.JComponent c, java.awt.Rectangle r)
          Add a component to the panel and store its placement information for use in makeGrid.
 void makeCompactGrid()
          Aligns all the gadgets in a compact grid whose virtual cells are as small as possible (calculated from the maximum width of a column and maximum height of a row).
 void makeCompactGrid(boolean hElastic, boolean vElastic)
          Aligns all the gadgets in a compact grid whose virtual cells are as small as possible (calculated from the maximum width of a column and maximum height of a row).
 void makeGrid(boolean elastic)
          Aligns all the gadgets in a regular grid whose virtual cells are all of the same size (calculated from the maximum dimensions of all cells).
 void setInitialX(int x)
          Changes the horizontal offset.
 void setInitialY(int y)
          Changes the vertical offset.
 void setPadding(int initialX, int initialY, int xPad, int yPad)
          Changes the padding and offset for the panel.
 void setTitle(java.lang.String title)
          Adds a titled border to the panel.
 void setXPad(int x)
          Changes the horizontal padding.
 void setYPad(int y)
          Changes the vertical padding.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpringPanel

public SpringPanel()
Creates a new panel with zero padding and offset


SpringPanel

public SpringPanel(int initialX,
                   int initialY,
                   int xPad,
                   int yPad)
Creates a new panel with given padding and offset (in pixels).

Parameters:
initialX - the spacing for gadgets from the left border of the panel
initialY - the spacing for gadgets from the top border of the panel
xPad - the spacing between a gadget and its horizontal neighbour
yPad - the spacing between a gadget and its vertical neighbour
Method Detail

setInitialX

public void setInitialX(int x)
Changes the horizontal offset. This takes effect, next time makeGrid is called.

Parameters:
x - the spacing for gadgets from the left border of the panel

setInitialY

public void setInitialY(int y)
Changes the vertical offset. This takes effect, next time makeGrid is called.

Parameters:
y - the spacing for gadgets from the top border of the panel

setXPad

public void setXPad(int x)
Changes the horizontal padding. This takes effect, next time makeGrid is called.

Parameters:
x - the spacing between a gadget and its horizontal neighbour

setYPad

public void setYPad(int y)
Changes the vertical padding. This takes effect, next time makeGrid is called.

Parameters:
y - the spacing between a gadget and its vertical neighbour

setPadding

public void setPadding(int initialX,
                       int initialY,
                       int xPad,
                       int yPad)
Changes the padding and offset for the panel. These take effect, next time makeGrid is called.

Parameters:
initialX - the spacing for gadgets from the left border of the panel
initialY - the spacing for gadgets from the top border of the panel
xPad - the spacing between a gadget and its horizontal neighbour
yPad - the spacing between a gadget and its vertical neighbour

gridAdd

public void gridAdd(javax.swing.JComponent c,
                    int x,
                    int y)
Add a component to the panel and store its placement information for use in makeGrid. The component is assumed to occupy a grid dimension of 1 x 1 cell.

Parameters:
c - the component
x - the horizontal grid position
y - the vertical grid position

gridAdd

public void gridAdd(javax.swing.JComponent c,
                    int x,
                    int y,
                    int width,
                    int height)
Add a component to the panel and store its placement information for use in makeGrid.

Parameters:
c - the component
x - the horizontal grid position
y - the vertical grid position
width - the number of columns to occupy (a negative width means the width is not elastic)
height - the number of rows to occupy (a negative height means the height is not elastic)

gridAdd

public void gridAdd(javax.swing.JComponent c,
                    java.awt.Rectangle r)
Add a component to the panel and store its placement information for use in makeGrid.

Parameters:
c - the component
r - the grid location and extent. (a negative width or height means the width or height is not elastic)

setTitle

public void setTitle(java.lang.String title)
Adds a titled border to the panel.

Parameters:
title - the text to display in the titled border

makeGrid

public void makeGrid(boolean elastic)
Aligns all the gadgets in a regular grid whose virtual cells are all of the same size (calculated from the maximum dimensions of all cells).

Parameters:
elastic - not yet fully working, has to be false for now(?)
Todo:
this method is not yet fully working

makeCompactGrid

public void makeCompactGrid()
Aligns all the gadgets in a compact grid whose virtual cells are as small as possible (calculated from the maximum width of a column and maximum height of a row). The layout is automatically stretched when the panel is resized.


makeCompactGrid

public void makeCompactGrid(boolean hElastic,
                            boolean vElastic)
Aligns all the gadgets in a compact grid whose virtual cells are as small as possible (calculated from the maximum width of a column and maximum height of a row).

Parameters:
hElastic - whether the layout should be horizontally stretched as to use additional space when the panel is horizontally resized
vElastic - whether the layout should be vertically stretched as to use additional space when the panel is vertically resized
Todo:
the elastic flags should be set to true for now