org.gicentre.utils.colour
Class ColourPicker

java.lang.Object
  extended by org.gicentre.utils.colour.ColourPicker
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

public class ColourPicker
extends java.lang.Object
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Creates a graphical colour picker using Cynthia Brewer's 'ColorBrewer' schemes. ColorBrewer specifications and designs developed by Cynthia Brewer (colorbrewer.org).

Version:
3.3, 1st August, 2011.
Author:
Jo Wood, giCentre, City University London.

Constructor Summary
ColourPicker(processing.core.PApplet sketch)
          Initialises the colour picker with default border size, but does not display it [requires setIsActive(true)].
ColourPicker(processing.core.PApplet sketch, int xBorder, int yBorder)
          Initialises the colour picker with the given border sizes, but does not display it (requires setIsActive(true)].
 
Method Summary
 void addPickerListener(PickerListener pickerListener)
          Adds the given pickerListener to those that will be informed when a colour has been chosen by the colour picker.
 void draw()
          Draws the colour swatches from which items may be picked.
 boolean getIsActive()
          Reports whether or not the colour picker is currently active.
 int getLastColour()
          Reports the last selected colour.
 ColourTable getLastColourTable()
          Reports the last selected colour table.
 void mouseClicked(java.awt.event.MouseEvent e)
          Responds to a mouse click in the colour picker, if active, updating the last selected colour and firing an event to all PickerListeners.
 void mouseDragged(java.awt.event.MouseEvent e)
          Responds to a mouse being dragged over the colour picker, if active, updating the last selected colour.
 void mouseEntered(java.awt.event.MouseEvent e)
          Would respond to a mouse entering the colour picker, but does nothing in this case.
 void mouseExited(java.awt.event.MouseEvent e)
          Would respond to a mouse leaving the colour picker, but does nothing in this case.
 void mouseMoved(java.awt.event.MouseEvent e)
          Would respond to a mouse being moved over the colour picker, but does nothing in this case.
 void mousePressed(java.awt.event.MouseEvent e)
          Would respond to a mouse being pressed in the colour picker, but does nothing in this case.
 void mouseReleased(java.awt.event.MouseEvent e)
          Responds to a mouse being released over the colour picker.
 boolean removePickerListener(PickerListener pickerListener)
          Removes the given pickerListener from those that will be informed when a colour has been chosen by the colour picker.
 void setIsActive(boolean isActive)
          Determines whether or not the colour picker should be currently active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColourPicker

public ColourPicker(processing.core.PApplet sketch)
Initialises the colour picker with default border size, but does not display it [requires setIsActive(true)].

Parameters:
sketch - Sketch that will use the colour picker.

ColourPicker

public ColourPicker(processing.core.PApplet sketch,
                    int xBorder,
                    int yBorder)
Initialises the colour picker with the given border sizes, but does not display it (requires setIsActive(true)]. The border defines the number of pixels from within the given sketch, the colour picker is drawn. So border values of 0 would take up the entire sketch, a border value of 10 would leave a 10 pixel wide band of the original sketch visible behind the colour picker.

Parameters:
sketch - Sketch that will use the colour picker.
xBorder - Width in pixels of the border to the left and right of the picker.
yBorder - Height in pixels of the border to the top and bottom of the picker.
Method Detail

draw

public void draw()
Draws the colour swatches from which items may be picked. This method should be called from within your sketch's draw() method. If the colour picker is not active, nothing will be drawn.


getIsActive

public boolean getIsActive()
Reports whether or not the colour picker is currently active. An active colour picker is one that is displayed in the current sketch and able to accept colour selection.

Returns:
True if the colour picker is active.

setIsActive

public void setIsActive(boolean isActive)
Determines whether or not the colour picker should be currently active. An active colour picker is one that is displayed in the current sketch and able to accept colour selection.

Parameters:
isActive - If true, the colour picker is made active.

getLastColour

public int getLastColour()
Reports the last selected colour. Colours are represented as a Processing integer value, so can be placed directly inside Processing methods such as fill() and stroke().

Returns:
Last selected colour or Integer.MAX_VALUE if no colour has yet been selected.

getLastColourTable

public ColourTable getLastColourTable()
Reports the last selected colour table.

Returns:
Last selected colour table or null if no colour table has yet been selected.

addPickerListener

public void addPickerListener(PickerListener pickerListener)
Adds the given pickerListener to those that will be informed when a colour has been chosen by the colour picker.

Parameters:
pickerListener - Listener to add to those informed when a colour has been chosen.

removePickerListener

public boolean removePickerListener(PickerListener pickerListener)
Removes the given pickerListener from those that will be informed when a colour has been chosen by the colour picker.

Parameters:
pickerListener - Listener to remove from those informed when a colour has been chosen.
Returns:
True if the given listener was present and then removed.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Responds to a mouse click in the colour picker, if active, updating the last selected colour and firing an event to all PickerListeners. event.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - Mouse event storing the location of the mouse click.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Would respond to a mouse entering the colour picker, but does nothing in this case.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Would respond to a mouse leaving the colour picker, but does nothing in this case.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Would respond to a mouse being pressed in the colour picker, but does nothing in this case.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Responds to a mouse being released over the colour picker. If this release is after a mouse drag and it is over a colour, it fires an event to all PickerListeners.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Responds to a mouse being dragged over the colour picker, if active, updating the last selected colour. Listeners are not informed until the mouse is released.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - Mouse event storing the location of the mouse drag.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Would respond to a mouse being moved over the colour picker, but does nothing in this case.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - Mouse event (ignored).


giCentre Utilities V.3.3, API documentation generated 6th April, 2013