Class ColorDiagramCanvas

All Implemented Interfaces:
Drawable

public class ColorDiagramCanvas extends Canvas
A color diagram on a Canvas (CC-COLOR-CHOOSER-SWT-PANELS, 2026-10-10): the two-dimensional plane of two channels of a color model (saturation across, value or lightness up) at the current value of the third, or the one-dimensional vertical strip of the third channel (the hue). The image is computed from a plane function per zoom through an ImageDataProvider, so a monitor at 200 % gets a 200 % image rather than a scaled one; it is rebuilt when the function changes (another hue) or the canvas is resized.

A marker shows the position, a light ring between two dark ones in the theme's marker pair (ChooserColors, CC-FIX-COLOR-CHOOSER-DARK): a contrast pair over any color of the plane. Mouse button 1 and dragging move it and report the position; the arrow keys nudge it by a hundredth (Page Up and Down by a tenth); Tab leaves the canvas. Positions are in [0,1], y=0 at the bottom.

Author:
Christopher Mindus
  • Constructor Details

    • ColorDiagramCanvas

      public ColorDiagramCanvas(Composite parent, ColorDiagramCanvas.IPlane plane, boolean isStrip, int width, int height, ChooserColors colors)
      Creates the diagram.
      Parameters:
      parent - The parent.
      plane - The function.
      isStrip - true for a vertical one-dimensional strip, false for a plane.
      width - The preferred width in points.
      height - The preferred height in points.
      colors - The theme colors: the marker's light and dark rings.
  • Method Details

    • isStrip

      public boolean isStrip()
      Checks if this is a strip.
    • setPlane

      public void setPlane(ColorDiagramCanvas.IPlane plane)
      Sets the function and rebuilds the image.
    • invalidateImage

      public void invalidateImage()
      Rebuilds the image at the next paint: the function's result changed (another hue).
    • setPreferredSize

      public void setPreferredSize(int width, int height)
      Sets the preferred size in points; the parent must lay out again.
    • computeSize

      public Point computeSize(int wHint, int hHint, boolean changed)
      Overrides:
      computeSize in class Composite
    • getX

      public float getX()
      Gets the marker position across, [0,1].
    • getY

      public float getY()
      Gets the marker position up, [0,1], 0 at the bottom.
    • setPosition

      public void setPosition(float x, float y)
      Sets the marker position without notifying the listeners (the model changed elsewhere).
    • addPositionListener

      public void addPositionListener(ColorDiagramCanvas.IPositionListener listener)
      Adds a position listener.
    • removePositionListener

      public void removePositionListener(ColorDiagramCanvas.IPositionListener listener)
      Removes a position listener.
    • moveTo

      public void moveTo(float x, float y)
      Moves the marker as the user does and notifies the listeners.
    • buildImageData

      public ImageData buildImageData(int width, int height, int zoom)
      Builds the image data of the diagram at a zoom. Public for the test fragment, which is hosted by another bundle and so cannot see package-private members.
      Parameters:
      width - The width in points.
      height - The height in points.
      zoom - The zoom in percent.