uci.beans.editors
Class ColorTilePanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--uci.beans.editors.ColorTilePanel

public class ColorTilePanel
extends JPanel
implements MouseListener, MouseMotionListener

A Panel that shows an array of little colored squares to allow the user to pick a color. By default I use "netscape colors" which are colors that Netscape Navigator (TM) tries to allocate when it starts.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
protected  boolean _allowSelection
          True iff the user can select a color, false if this widget is /** disabled.
protected  Vector _colors
          The colors that will be shown
protected  int _nCols
          The number of columns to use when displaying the array of /** colors.
static Vector _NetscapeColors
           
protected  ActionListener _onlyListener
           
protected  int _selected
          The index of the selected color
static int TILESIZE
           
 
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
 
Constructor Summary
ColorTilePanel()
           
ColorTilePanel(int nCols)
           
ColorTilePanel(Vector cs)
           
ColorTilePanel(Vector cs, int nCols)
           
 
Method Summary
 void addActionListener(ActionListener list)
           
 void allowSelection(boolean as)
          The user can be prevented from selecting a color if there would be nothing to do the the selected color.
 void fireActionEvent(ActionEvent ae)
           
 Color getColor()
           
 Dimension getMinimumSize()
           
 Dimension getPreferredSize()
           
 void mouseClicked(MouseEvent me)
           
 void mouseDragged(MouseEvent me)
           
 void mouseEntered(MouseEvent me)
           
 void mouseExited(MouseEvent me)
           
 void mouseMoved(MouseEvent me)
           
 void mousePressed(MouseEvent me)
          Mousedown is the same as mouse up: it selects the color under the mouse
 void mouseReleased(MouseEvent me)
          When the user releases the mouse button that signifies that (s)he has made a selection, post an ACTION_EVENT that the enclosing Container can handle.
static Vector netscapeColors()
           
 void paint(Graphics g)
           
 void paintTile(Graphics g, int tileNum)
           
 void removeActionListener(ActionListener list)
           
 void setColor(Color c)
          Select the little rectangle for the given color, ONLY if it is one of the displayed colors.
 boolean setSelectionIndex(int s)
           
 void showSelection(Graphics g)
          Draw a black or white hollow rectangle to indicate which color the user selected.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TILESIZE

public static final int TILESIZE

_colors

protected Vector _colors
The colors that will be shown

_selected

protected int _selected
The index of the selected color

_nCols

protected int _nCols
The number of columns to use when displaying the array of /** colors.

_allowSelection

protected boolean _allowSelection
True iff the user can select a color, false if this widget is /** disabled.

_onlyListener

protected ActionListener _onlyListener

_NetscapeColors

public static Vector _NetscapeColors
Constructor Detail

ColorTilePanel

public ColorTilePanel()

ColorTilePanel

public ColorTilePanel(int nCols)

ColorTilePanel

public ColorTilePanel(Vector cs)

ColorTilePanel

public ColorTilePanel(Vector cs,
                      int nCols)
Method Detail

getColor

public Color getColor()

setColor

public void setColor(Color c)
Select the little rectangle for the given color, ONLY if it is one of the displayed colors.

allowSelection

public void allowSelection(boolean as)
The user can be prevented from selecting a color if there would be nothing to do the the selected color. E.g., the Color Picker window is open but no DiagramElement is selected.

paint

public void paint(Graphics g)
Overrides:
paint in class JComponent

paintTile

public void paintTile(Graphics g,
                      int tileNum)

showSelection

public void showSelection(Graphics g)
Draw a black or white hollow rectangle to indicate which color the user selected.

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

setSelectionIndex

public boolean setSelectionIndex(int s)

mouseReleased

public void mouseReleased(MouseEvent me)
When the user releases the mouse button that signifies that (s)he has made a selection, post an ACTION_EVENT that the enclosing Container can handle.
Specified by:
mouseReleased in interface MouseListener

mousePressed

public void mousePressed(MouseEvent me)
Mousedown is the same as mouse up: it selects the color under the mouse
Specified by:
mousePressed in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent me)
Specified by:
mouseMoved in interface MouseMotionListener

mouseDragged

public void mouseDragged(MouseEvent me)
Specified by:
mouseDragged in interface MouseMotionListener

mouseClicked

public void mouseClicked(MouseEvent me)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent me)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent me)
Specified by:
mouseExited in interface MouseListener

netscapeColors

public static Vector netscapeColors()

addActionListener

public void addActionListener(ActionListener list)

removeActionListener

public void removeActionListener(ActionListener list)

fireActionEvent

public void fireActionEvent(ActionEvent ae)