com.pegacat.vcf
Class GridPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.pegacat.vcf.GridPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GridPanel
extends java.awt.Panel

Java layout managers are frustrating, badly written pieces of garbage that are difficult to use, erratic, throw strange errors, and are generally junk. The only one worth spitting on is GridBagLayout, but it's clumsy and inconvenient to use.

This class wraps up a Panel with an intrinsic GridBagLayout and constraints object, and provides a bunch of new add() ftns to make stuff faster and easier. For me, anyway :-).

This works nicely for adding single height objects of different widths, using ftns such as add(), addline(), newline(), or addwide(). High objects can be placed explicitly using add(x,y,width,height).

The concept of a 'cursor' position is used, with cells being added to the next 'cursor' position, and the cursor being adjusted with 'newline()', or a fixed positional placement.

    e.g.

    add(a); add(b); add(c); newLine();
    addLine(d);
    add(e); addLine(f);
    addWide(g,2); addLine(h);
    addBig(i,2);
    add(j,1,2,3,8)

    should produce something like:

    [ a ] [ b ] [ c ]
    [       d       ]
    [ e ] [    f    ]
    [    g    ] [ h ]
    [               ]
    [       i       ]
    ...    ...   ...
    ...    [   j    ]

        (YMMV :-) )
    
- Chris

See Also:
Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
GridPanel()
          Constructor calls the JPanel superclass constructor, and initialises the GridBagLayout and GridBagConstraints objects.
GridPanel(java.awt.Image background)
           
 
Method Summary
 java.awt.Component add(java.awt.Component comp)
          Add the next component in a straight line, automatically incrementing the X position 'cursor'.
 java.awt.Component add(java.awt.Component comp, int x, int y)
          Add a unit cell object to a specific x and y position.
 java.awt.Component add(java.awt.Component comp, int x, int y, int width, int height)
          Adds a component to the specified x,y cell position, with a size spanning (width, height) cells.
 void addLine(java.awt.Component comp)
          Adds a component taking up the remainder of the line (using GridBagConstraints.REMAINDER), and increments the cursor to the next line.
 void addLines(java.awt.Component comp, int height)
          Adds a large multi - line component at the next cursor position, increments the cursor to the start of the next line immediately below the object.
 void addln(java.awt.Component comp)
          Adds a component taking up the remainder of the line (using GridBagConstraints.REMAINDER), and increments the cursor to the next line.
 void addWide(java.awt.Component comp, int width)
          Adds a wider-than-usual component, updating the cursor as appropriate.
 void makeHeavy()
          Makes all components added after this call expand to fill all available space.
 void makeLight()
           
 void makeWide()
          Makes all components added after this call expand to fill all available width (but not height).
 void newLine()
          Adjusts the cursor to the next line down.
 void paint(java.awt.Graphics g)
           
 void setBackground(java.awt.Image background)
           
 java.lang.String toString()
          for debugging...
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridPanel

public GridPanel()
Constructor calls the JPanel superclass constructor, and initialises the GridBagLayout and GridBagConstraints objects.

GridPanel

public GridPanel(java.awt.Image background)
Method Detail

setBackground

public void setBackground(java.awt.Image background)

makeHeavy

public void makeHeavy()
Makes all components added after this call expand to fill all available space.

makeWide

public void makeWide()
Makes all components added after this call expand to fill all available width (but not height).

makeLight

public void makeLight()

add

public java.awt.Component add(java.awt.Component comp)
Add the next component in a straight line, automatically incrementing the X position 'cursor'.
Overrides:
add in class java.awt.Container
Parameters:
comp - the component to add

add

public java.awt.Component add(java.awt.Component comp,
                              int x,
                              int y)
Add a unit cell object to a specific x and y position. The 'cursor' is set to the adjacent x position.
Parameters:
comp - the component to add

add

public java.awt.Component add(java.awt.Component comp,
                              int x,
                              int y,
                              int width,
                              int height)
Adds a component to the specified x,y cell position, with a size spanning (width, height) cells. Cursor resets to the lowest y position (i.e. height), and the adjacent x position (i.e. x+width);
Parameters:
comp - the component to add

newLine

public void newLine()
Adjusts the cursor to the next line down. (i.e. set the x cursor to zero, and increments the y cursor).

addLine

public void addLine(java.awt.Component comp)
Adds a component taking up the remainder of the line (using GridBagConstraints.REMAINDER), and increments the cursor to the next line.
Parameters:
comp - the component to add

addln

public void addln(java.awt.Component comp)
Adds a component taking up the remainder of the line (using GridBagConstraints.REMAINDER), and increments the cursor to the next line.
Parameters:
comp - the component to add

addLines

public void addLines(java.awt.Component comp,
                     int height)
Adds a large multi - line component at the next cursor position, increments the cursor to the start of the next line immediately below the object.
Parameters:
comp - the component to add
height - the number of cells height the component is.

addWide

public void addWide(java.awt.Component comp,
                    int width)
Adds a wider-than-usual component, updating the cursor as appropriate.

toString

public java.lang.String toString()
for debugging... gets current state...
Overrides:
toString in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container