dirk_krause.wstools
Class DkColorArea

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 dirk_krause.wstools.DkColorArea
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class DkColorArea
extends javax.swing.JPanel
implements java.awt.event.MouseListener

An area to show a color. If your application needs to set a color in a dialog box, perform the following steps: - add a DkColorArea to the dialog box, - use the setColor() method so the object can show the current color setting, - set an action listener, - set the action command, - make the dialog box visible. The action listener should perform the following: - use the getColor() method to retrieve the current color setting, - use JColorChooser toa configure a new color and - use the setColor() method to update the color shown by the DkColorArea object.

See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String actionCommand
          The action command to send on mouse-clicks
protected  java.util.ArrayList<java.awt.event.ActionListener> all
          The list of all action listeners to notify on mouse-clicks
protected  java.awt.Color c
          The color to show.
static java.lang.String defaultActionCommand
          The default action command to send on mouse-click
protected  java.awt.Dimension minimumSize
          The minimum size of the component
protected  boolean mouseKeyPressed
          Flag to indicate whether or not the mouse key is pressed
protected  boolean mouseOverArea
          Flag to indicate whether or not the mouse is over the component
protected  java.awt.Dimension preferredSize
          The preferred size of the component
 
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
DkColorArea()
          Create a DkColorArea.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener a)
          Add action listener.
 java.awt.Color getColor()
          Get the color.
 java.awt.Dimension getMinimumSize()
          Get the minimum size of the component.
 java.awt.Dimension getPreferredSize()
          Get the preferred size of the component.
 void mouseClicked(java.awt.event.MouseEvent e)
          Perform action after mouse-click (choose new color)
 void mouseEntered(java.awt.event.MouseEvent e)
          Handle mouse-entered event.
 void mouseExited(java.awt.event.MouseEvent e)
          Handle mouse-exited event.
 void mousePressed(java.awt.event.MouseEvent e)
          Handle mouse-pressed event.
 void mouseReleased(java.awt.event.MouseEvent e)
          Handle mouse-released event.
protected  void paintComponent(java.awt.Graphics g)
          Redraw the component.
 void removeActionListener(java.awt.event.ActionListener a)
          Remove action listener.
 void setActionCommand(java.lang.String s)
          Set the action string.
 void setColor(java.awt.Color co)
          Set the color.
 void setMinimumSize(java.awt.Dimension d)
          Set the minimum size of the component.
 void setPreferredSize(java.awt.Dimension d)
          Set the preferred size of the component.
 
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setNextFocusableComponent, setOpaque, 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
 

Field Detail

defaultActionCommand

public static final java.lang.String defaultActionCommand
The default action command to send on mouse-click

See Also:
Constant Field Values

mouseOverArea

protected boolean mouseOverArea
Flag to indicate whether or not the mouse is over the component


mouseKeyPressed

protected boolean mouseKeyPressed
Flag to indicate whether or not the mouse key is pressed


c

protected java.awt.Color c
The color to show.


minimumSize

protected java.awt.Dimension minimumSize
The minimum size of the component


preferredSize

protected java.awt.Dimension preferredSize
The preferred size of the component


actionCommand

protected java.lang.String actionCommand
The action command to send on mouse-clicks


all

protected java.util.ArrayList<java.awt.event.ActionListener> all
The list of all action listeners to notify on mouse-clicks

Constructor Detail

DkColorArea

public DkColorArea()
Create a DkColorArea.

Method Detail

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the minimum size of the component.

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
The minimum size.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size of the component.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
The preferred size.

setMinimumSize

public void setMinimumSize(java.awt.Dimension d)
Set the minimum size of the component.

Overrides:
setMinimumSize in class javax.swing.JComponent
Parameters:
d - The minimum size.

setPreferredSize

public void setPreferredSize(java.awt.Dimension d)
Set the preferred size of the component.

Overrides:
setPreferredSize in class javax.swing.JComponent
Parameters:
d - The preferred size.

paintComponent

protected void paintComponent(java.awt.Graphics g)
Redraw the component.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphics context to draw to.

setColor

public void setColor(java.awt.Color co)
Set the color.

Parameters:
co - The color to show.

getColor

public java.awt.Color getColor()
Get the color.

Returns:
The current color.

addActionListener

public void addActionListener(java.awt.event.ActionListener a)
Add action listener.

Parameters:
a - The action listener to add to the list of listeners.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener a)
Remove action listener.

Parameters:
a - The action listener to remove.

setActionCommand

public void setActionCommand(java.lang.String s)
Set the action string.

Parameters:
s - The action string to use for creation of new events.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Perform action after mouse-click (choose new color)

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - The mouse-click event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Handle mouse-pressed event.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - The mouse pressed event.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Handle mouse-released event.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - The mouse released event.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Handle mouse-entered event.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - The mouse entered event.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Handle mouse-exited event.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - The mouse exited event.