org.gicentre.utils.colour

## Class ColourPicker

- java.lang.Object
- - org.gicentre.utils.colour.ColourPicker

-     public class ColourPicker
      extends java.lang.Object

  Creates a graphical colour picker using Cynthia Brewer's 'ColorBrewer' schemes. ColorBrewer specifications and designs developed by Cynthia Brewer (colorbrewer.org).
  Version:
    3.4, 5th February, 2016.
  Author:
    Jo Wood, giCentre, City University London.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `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

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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` | `mouseEvent(processing.event.MouseEvent e)` Responds to mouse events by allowing colours to be picked with the mouse pointer.
    `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.

    - #### mouseEvent

          public void mouseEvent(processing.event.MouseEvent e)

      Responds to mouse events by allowing colours to be picked with the mouse pointer.
      Parameters:
        `e` - Mouse event.