Class SwatchGridCanvas
java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
com.iizigo.prop.editor.color.swt.SwatchGridCanvas
- All Implemented Interfaces:
Drawable
A grid of color cells on a Canvas (CC-COLOR-CHOOSER-SWT-PANELS, 2026-10-10): the swatch palette and the recent colors of the Swatches tab. A cell of value zero is empty: painted with the background, without tooltip, and picking it does nothing.
Mouse button 1 picks a cell. The keyboard moves a visible focus cell with the arrow keys (Home and End to the ends of the row), Space picks the focus cell, and Enter picks it too and leaves the Return traversal to the chooser, which accepts; Tab leaves the grid. The tooltip of a cell is #RRGGBB r,g,b. Sizes are in points, scaled by SWT. The background and the shade lines of the cells are the theme's field background and border colors (ChooserColors, CC-FIX-COLOR-CHOOSER-DARK); the cells are the real colors.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener of picks.Field Summary
Constructor Summary
ConstructorsConstructorDescriptionSwatchGridCanvas(Composite parent, int columns, int rows, IntUnaryOperator colorAt, ChooserColors colors) Creates the grid.Method Summary
Modifier and TypeMethodDescriptionvoidAdds a pick listener.intcellAt(int x, int y) Gets the cell index at a point of the canvas, -1 outside the cells.cellBounds(int index) Gets the bounds of a cell in the canvas.intcellColor(int index) Gets the color of a cell, zero for an empty cell.computeSize(int wHint, int hHint, boolean changed) intGets the cell size in points.intGets the columns.intGets the focus cell: the one the keyboard acts on.intgetRows()Gets the rows.booleanpick(int index) Picks a cell: an empty or invalid cell does nothing.booleanPicks the focus cell (Space, Enter).voidRemoves a pick listener.voidsetCellSize(int size) Sets the cell size in points, at leastChooserMetrics.MIN_CELL; the parent must lay out again.voidsetFocusCell(int index) Sets the focus cell, clamped to the grid.sizeFor(int size) Gets the size of the grid at a cell size: the cells, the gaps and the margin for the focus ring, in points.Methods inherited from class Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIMEMethods inherited from class Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, redraw, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toStringMethods inherited from class Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar, setScrollbarsModeMethods inherited from class Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setAutoscalingMode, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, updateMethods inherited from class Widget
addDisposeListener, addListener, addTypedListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setDataMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Drawable
isAutoScalable
Constructor Details
SwatchGridCanvas
public SwatchGridCanvas(Composite parent, int columns, int rows, IntUnaryOperator colorAt, ChooserColors colors) Creates the grid.- Parameters:
parent- The parent.columns- The columns, at least 1.rows- The rows, at least 1.colorAt- The color of a cell by row-major index, zero for empty.colors- The theme colors: the field background behind the cells, the border for the shade lines of a cell.
Method Details
getColumns
public int getColumns()Gets the columns.getRows
public int getRows()Gets the rows.getCellSize
public int getCellSize()Gets the cell size in points.setCellSize
public void setCellSize(int size) Sets the cell size in points, at leastChooserMetrics.MIN_CELL; the parent must lay out again.computeSize
- Overrides:
computeSizein classComposite
sizeFor
Gets the size of the grid at a cell size: the cells, the gaps and the margin for the focus ring, in points.- Parameters:
size- The cell size in points.
cellAt
public int cellAt(int x, int y) Gets the cell index at a point of the canvas, -1 outside the cells.cellBounds
Gets the bounds of a cell in the canvas.cellColor
public int cellColor(int index) Gets the color of a cell, zero for an empty cell.- Parameters:
index- The row-major index.
getFocusCell
public int getFocusCell()Gets the focus cell: the one the keyboard acts on.setFocusCell
public void setFocusCell(int index) Sets the focus cell, clamped to the grid.addPickListener
Adds a pick listener.removePickListener
Removes a pick listener.pick
public boolean pick(int index) Picks a cell: an empty or invalid cell does nothing.- Parameters:
index- The row-major index.- Returns:
- true if a color was picked.
pickFocusCell
public boolean pickFocusCell()Picks the focus cell (Space, Enter).- Returns:
- true if a color was picked.