edu.neu.ccs.gui
Class LayeredComponent

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byedu.neu.ccs.gui.LayeredComponent
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class LayeredComponent
extends JComponent

Class LayeredComponent encapsulates a JComponent which is in the foreground of the panel and a background which consists of multiple layers.

The multiple layers of the background are provided as follows:

Both the repeated tile and the topmost paintable may be provided as general objects. In that case, they are converted to Paintable via ComponentFactory.makePaintable.

Any of the background layers may be null. If all layers are null, however, this panel is not very useful. On the other hand, if all layers are non-null, the background may be too busy and may overwhelm the foreground. Hence, this facility must be used with good taste.

The user of this class should not add additional components to an instance of this class beyond those installed by the constructor of the instance and should not change the layout manager. Methods of the class will permit the paint, the repeat tile, the topmost paintable, and the opacity to be changed, and when this happens the panel will repaint.

When the foreground JComponent is passed to the constructor of this class, the opaqueness of the foreground is set to false via setOpaque(false). This is what allows the background to show through. This call is not made recursively since it is up to the user of this class to decide what to do about opaqueness inside the foreground component.

Experiment has shown that, for some Java components, things do not render properly if the opaqueness is set to false. This problem, if it occurs, cannot be resolved by this class. Hence, thorough testing is recommended.

Version:
2.6.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  boolean centered
          Whether or not the topmost object should be centered.
protected  XPoint2D corner
          The corner of the topmost object.
protected  JComponent foreground
          The foreground component on which this layered component is built.
protected  PaintableComponent lowerLayer
          The lower layer of this layered component.
protected  Tile tile1
          The innermost Tile helper object.
protected  Tile tile2
          The outermost Tile helper object.
protected  Paintable tilePaintable
          The paintable used as the tile.
protected  Paintable topmostPaintable
          The paintable used as the topmost object.
 
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.Container
 
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
LayeredComponent(JComponent foreground, Object topmost, Object tile, Paint paint, float opacity, boolean centered)
          Constructs a LayeredComponent.
 
Method Summary
 Paint getBackgroundPaint()
          Gets the background paint for the bottom layer of this layered component.
 Paintable getBackgroundTile()
          Gets the tile paintable object for the middle layer of this layered component.
 float getOpacity()
          Gets the opacity of the background layers of this layered component.
 Paintable getTopmostPaintable()
          Gets the topmost background paintable object of this layered component.
 boolean isCentered()
          Gets whether or not the topmost background object is centered in this layered component.
 void setBackgroundPaint(Paint paint)
          Sets the background paint for the bottom layer of this layered component.
 void setBackgroundTile(Object tile)
          Sets the tile paintable object for the middle layer of this layered component.
 void setCentered(boolean centered)
          Sets whether or not the topmost background object is centered in this layered component.
 void setOpacity(float opacity)
          Sets the opacity of the background layers of this layered component.
 void setTopmostPaintable(Object topmost)
          Sets the topmost background paintable object of this layered component.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Field Detail

foreground

protected JComponent foreground
The foreground component on which this layered component is built.


lowerLayer

protected PaintableComponent lowerLayer
The lower layer of this layered component.


topmostPaintable

protected Paintable topmostPaintable
The paintable used as the topmost object.


tilePaintable

protected Paintable tilePaintable
The paintable used as the tile.


corner

protected XPoint2D corner
The corner of the topmost object.


tile1

protected Tile tile1
The innermost Tile helper object.


tile2

protected Tile tile2
The outermost Tile helper object.


centered

protected boolean centered
Whether or not the topmost object should be centered.

Constructor Detail

LayeredComponent

public LayeredComponent(JComponent foreground,
                        Object topmost,
                        Object tile,
                        Paint paint,
                        float opacity,
                        boolean centered)

Constructs a LayeredComponent.

See the introduction to this class for detailed discussion.

Parameters:
foreground - the foreground component
topmost - the paintable in the topmost background layer
tile - the paintable to tile the middle background layer
paint - the paint to paint the bottom background layer
opacity - the opacity of the background layers
centered - whether or not the topmost object is centered
Method Detail

setTopmostPaintable

public void setTopmostPaintable(Object topmost)

Sets the topmost background paintable object of this layered component.

The topmost object is an object which should either be null or be an object that is convertible to a Paintable using ComponentFactory.makePaintable.

Parameters:
topmost - the topmost background paintable object

getTopmostPaintable

public Paintable getTopmostPaintable()

Gets the topmost background paintable object of this layered component.


setBackgroundTile

public void setBackgroundTile(Object tile)

Sets the tile paintable object for the middle layer of this layered component.

The tile tile object is an object which should either be null or be an object that is convertible to a Paintable using ComponentFactory.makePaintable.

Parameters:
tile - the tile paintable object

getBackgroundTile

public Paintable getBackgroundTile()

Gets the tile paintable object for the middle layer of this layered component.


setBackgroundPaint

public void setBackgroundPaint(Paint paint)

Sets the background paint for the bottom layer of this layered component.

Parameters:
paint - the background paint for the bottom layer

getBackgroundPaint

public Paint getBackgroundPaint()

Gets the background paint for the bottom layer of this layered component.


setOpacity

public void setOpacity(float opacity)
Sets the opacity of the background layers of this layered component.

Parameters:
opacity - the opacity of the background layers

getOpacity

public float getOpacity()
Gets the opacity of the background layers of this layered component.


setCentered

public void setCentered(boolean centered)
Sets whether or not the topmost background object is centered in this layered component.

Parameters:
centered - the centered setting for the topmost background object

isCentered

public boolean isCentered()
Gets whether or not the topmost background object is centered in this layered component.