com.ccg.awt
Class InsetPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by com.ccg.awt.InsetPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class InsetPanel
extends Panel

A panel with a decoratable border area.

This class extends the standard Panel object in a way that one can paint fancy little border areas around the exteriour of the contained components. This can be used to add spacing for the entire panel area. The default implementation of the border painting is to simply fill the border area with the background color, and then draw some rectangles in the foreground color. Classes which extend this object will probably just need to implement the paintEdges(java.awt.Graphics) method.

Note, you may want to implement the update() method in any class which extends this one. The default implementation this class inherits is to blank the area and then paint it. It seems that this is seldom what you want.

The following example shows how to add a standard component to a applet which will have a 8 pixel gap filled in the color red around the component which was added (copy and paste the code to a file called "IC.java"):

import com.ccg.awt.*;

import java.awt.*;

public class IC extends java.applet.Applet {

  public void init() {
    InsetPanel ic = new InsetPanel();
    ic.setBackground(Color.green);
    ic.setForeground(Color.red);
    ic.setEvenGap(16);
    ic.setRight(48);
    ic.add(new Label("Hello World"));
    add(ic);
  }
}
 

Since:
1.0
Version:
$Revision: 1.2 $
Author:
$Author: pkb $
See Also:
paintEdges(java.awt.Graphics), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
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
 
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
InsetPanel()
          Default constructor of the object.
 
Method Summary
 int getBottom()
          Get the inset from the bottom edge
 Insets getInsets()
          Get the insets from the edges
 int getLeft()
          Get the inset from the left edge
 int getRight()
          Get the inset from the right edge
 int getTop()
          Get the inset from the top edge
 void paint(Graphics g)
          Paint the edges and components.
 void paintEdges(Graphics g)
          Paint the "border" edges.
 void setBottom(int val)
          Set the inset from the bottom edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.
 void setEvenGap(int gap)
          Set the indentation to the same number of pixels.
 void setInsets(Insets val)
          Set the insets from the edges
 void setLeft(int val)
          Set the inset from the left edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.
 void setRight(int val)
          Set the inset from the right edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.
 void setTop(int val)
          Set the inset from the top edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

InsetPanel

public InsetPanel()
Default constructor of the object. This default constructor simply sets a default 8 pixel gap.

Since:
1.0
See Also:
setEvenGap(int)
Method Detail

paint

public void paint(Graphics g)
Paint the edges and components. This method first invokes paintEdges(java.awt.Graphics) to paint any edge decorations. It then invokes its parent's method to paint the components contained.

Overrides:
paint in class Container
Parameters:
g - Graphics object to drawn onto.
Since:
1.0
See Also:
paintEdges(java.awt.Graphics)

paintEdges

public void paintEdges(Graphics g)
Paint the "border" edges. This method is intended to be overridden by derived classes. It is responsible for painting the "border" edges around the container. This default implementation simply fills the border edges with the foreground color.

It should be noted that this method is invoked PRIOR to the painting of the interior components. So, if you draw outside of your edge boundaries, it will probably be drawn over by the interior components.

Parameters:
g - Graphics object to drawn onto.
Since:
1.0
See Also:
paint(java.awt.Graphics)

setLeft

public void setLeft(int val)
Set the inset from the left edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.

Parameters:
val - The inset (in pixels) from the left side.
See Also:
getLeft()

getLeft

public int getLeft()
Get the inset from the left edge

Returns:
Current number of pixels from the left side.
See Also:
setLeft(int)

setRight

public void setRight(int val)
Set the inset from the right edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.

Parameters:
val - The inset (in pixels) from the right side.
See Also:
getRight()

getRight

public int getRight()
Get the inset from the right edge

Returns:
Current number of pixels from the right side.
See Also:
setRight(int)

setTop

public void setTop(int val)
Set the inset from the top edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.

Parameters:
val - The inset (in pixels) from the top side.
See Also:
getTop()

getTop

public int getTop()
Get the inset from the top edge

Returns:
Current number of pixels from the top side.
See Also:
setTop(int)

setBottom

public void setBottom(int val)
Set the inset from the bottom edge After adjusting this value (and any others which may affect the components size), you will want to layout you panels.

Parameters:
val - The inset (in pixels) from the bottom side.
See Also:
getBottom()

getBottom

public int getBottom()
Get the inset from the bottom edge

Returns:
Current number of pixels from the bottom side.
See Also:
setBottom(int)

setEvenGap

public void setEvenGap(int gap)
Set the indentation to the same number of pixels. This method allows one to set all four indent values (left, right, top and bottom) to the same value in one shot.

Parameters:
gap - The gap (in pixels) you want around the components in the panel.
Since:
1.0
See Also:
setInsets(java.awt.Insets)

setInsets

public void setInsets(Insets val)
Set the insets from the edges

Parameters:
val - New Insets value to assign.
See Also:
getInsets()

getInsets

public Insets getInsets()
Get the insets from the edges

Overrides:
getInsets in class Container
Returns:
Current Insets value assigned.
See Also:
setInsets(java.awt.Insets)


Copyright 1998-1998-2006 null. All Rights Reserved.