Class ColorChooserComposite
- All Implemented Interfaces:
Drawable
Composite the color dialog embeds and the color field's drop-down shows in its shell: no SWT_AWT, no AWT thread, every size in SWT points scaled by the monitor's zoom, every text in the dialog font.Six tabs in the order of the Swing chooser, the last one shown remembered in the preference store under "colorChooserPage": Swatches (the generated palette and the recent colors, SwatchesTab), Palette (the platform roles and the modules' palette colors by reference, PaletteTab), HSV, HSL, RGB and CMYK (ColorModelTab: sliders and spinners per channel, a diagram and a hue strip for HSV and HSL). Below the tabs a preview of the initial and the current color, the hex field (RRGGBB, or AARRGGBB when transparency is allowed and the color is not opaque) and, when transparency is allowed, the alpha control.
Keys: Enter anywhere commits a value typed and not yet entered and runs the accept handler (by default the shell's default button); Escape runs the cancel handler (by default the shell closes). In the swatch grids the arrows move a focus cell, Space picks it, Enter picks and accepts. getColor() commits a pending typed value first, so OK without Enter keeps it. Everything runs on the SWT thread, synchronously.
Theme: every surface the chooser paints itself - its own panels (this composite and the tab pages), the swatch grids' background and cell shade lines, the preview's frame and transparency checkerboard, the palette swatches' background, frame and unresolved cross, the diagram marker - takes its color from the environment's ChooserColors (in the Designer: ApplicationUI's named theme members), so the chooser follows the light and the dark Eclipse theme (CC-FIX-COLOR-CHOOSER-DARK, 2026-10-19). The panels need it because Eclipse's theme styles a widget by its exact class and leaves a Composite subclass at SWT's default. The plain SWT widgets (tabs, tables, labels, sliders, fields, and the strip - a plain Composite, which Eclipse restyles after its creation) are themed by Eclipse: nothing here sets a background or foreground on them. The color samples are the real colors.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener of color changes.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe preference key of the tab shown last, an index; the Swing chooser's key, kept.static final intstatic final intThe number of tabs.static final intstatic final intstatic final intstatic final intstatic final intThe tabs, in order.Constructor Summary
ConstructorsConstructorDescriptionColorChooserComposite(Composite parent, int style, IChooserEnvironment env, int argb, boolean isTransparent, GProp<?> context, String currentRef) Creates the chooser.Method Summary
Modifier and TypeMethodDescriptionvoidaccept()Accepts: commits a pending typed value and runs the accept handler, by default the shell's default button.voidAdds a color listener, called on the SWT thread when the color or the reference changes.voidcancel()Cancels: runs the cancel handler, by default closing the shell.booleanCommits a value typed in the hex field or a spinner and not yet entered.static ColorChooserCompositeCreates the chooser with the Designer's environment.Gets the alpha slider, null when transparency is not allowed.Gets the alpha spinner, null when transparency is not allowed.intgetColor()Gets the current color after committing a value typed in the hex field or a spinner and not yet entered, so that OK keeps what was typed.intGets the current color without committing a pending typed value.Gets the theme colors the chooser paints its own surfaces with, as read from the environment when the chooser was created.Gets the environment.Gets the hex field.intGets the initial color.getModelTab(int model) Gets a color-model tab.Gets the Palette tab.Gets the preferred size of the chooser in points: what a dialog or a drop-down shell sizes itself by.Gets the preview canvas.Gets the recent colors.Gets the palette reference chosen on the Palette tab.intGets the tab shown, one of theTAB_constants.Gets the Swatches tab.Gets the tab folder.booleanChecks if transparency is allowed: the alpha byte can be edited and is kept.voidRemoves a color listener.static voidForgets the shared recent colors, so that the next chooser loads them from its store again (for tests that use another store).voidsetAcceptHandler(Runnable handler) Sets what Enter does once a pending typed value is committed.voidsetCancelHandler(Runnable handler) Sets what Escape does.voidsetColor(int argb) Sets the color from outside, as a literal: every tab follows, a palette reference is dropped, the listeners are told.voidsetSelectedTab(int tab) Shows a tab, and remembers it as the user's choice.Methods inherited from class Composite
changed, checkSubclass, computeSize, 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, setFont, 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
Field Details
TAB_SWATCHES
public static final int TAB_SWATCHESThe tabs, in order.- See Also:
TAB_PALETTE
public static final int TAB_PALETTE- See Also:
TAB_HSV
public static final int TAB_HSV- See Also:
TAB_HSL
public static final int TAB_HSL- See Also:
TAB_RGB
public static final int TAB_RGB- See Also:
TAB_CMYK
public static final int TAB_CMYK- See Also:
TAB_COUNT
public static final int TAB_COUNTThe number of tabs.- See Also:
PREF_LAST_TAB
The preference key of the tab shown last, an index; the Swing chooser's key, kept.- See Also:
Constructor Details
ColorChooserComposite
public ColorChooserComposite(Composite parent, int style, IChooserEnvironment env, int argb, boolean isTransparent, GProp<?> context, String currentRef) Creates the chooser.- Parameters:
parent- The parent.style- The composite style.env- The environment: fonts, preferences, palette entries.argb- The initial color, the resolved literal for a referenced color.isTransparent- true to allow editing the alpha byte, false for opaque colors only.context- A property of the tree the chosen color is written in, or null.currentRef- The reference the edited color holds, or null.
Method Details
create
public static ColorChooserComposite create(Composite parent, int argb, boolean isTransparent, GProp<?> context, String currentRef) Creates the chooser with the Designer's environment.- Parameters:
parent- The parent.argb- The initial color, the resolved literal for a referenced color.isTransparent- true to allow editing the alpha byte, false for opaque colors only.context- A property of the tree the chosen color is written in, for the Palette tab's references, or null.currentRef- The reference the edited color holds, to preselect in the Palette tab and to show that tab first, or null.
getEnvironment
Gets the environment.getColors
Gets the theme colors the chooser paints its own surfaces with, as read from the environment when the chooser was created.isTransparencyAllowed
public boolean isTransparencyAllowed()Checks if transparency is allowed: the alpha byte can be edited and is kept.getInitialColor
public int getInitialColor()Gets the initial color.getColor
public int getColor()Gets the current color after committing a value typed in the hex field or a spinner and not yet entered, so that OK keeps what was typed. A commit drops a palette reference.- Returns:
- The color, opaque when transparency is not allowed.
getColorNoUpdate
public int getColorNoUpdate()Gets the current color without committing a pending typed value.getSelectedReference
Gets the palette reference chosen on the Palette tab.- Returns:
- The reference without the leading
%, or null when the color is a literal.
setColor
public void setColor(int argb) Sets the color from outside, as a literal: every tab follows, a palette reference is dropped, the listeners are told.- Parameters:
argb- The color.
getRecentColors
Gets the recent colors.getTabFolder
Gets the tab folder.getSelectedTab
public int getSelectedTab()Gets the tab shown, one of theTAB_constants.setSelectedTab
public void setSelectedTab(int tab) Shows a tab, and remembers it as the user's choice.- Parameters:
tab- One of theTAB_constants.
getSwatchesTab
Gets the Swatches tab.getPaletteTab
Gets the Palette tab.getModelTab
Gets a color-model tab.- Parameters:
model-ColorModelTab.HSV,ColorModelTab.HSL,ColorModelTab.RGBorColorModelTab.CMYK.
getHexField
Gets the hex field.getAlphaSpinner
Gets the alpha spinner, null when transparency is not allowed.getAlphaScale
Gets the alpha slider, null when transparency is not allowed.getPreview
Gets the preview canvas.getPreferredSizeInPoints
Gets the preferred size of the chooser in points: what a dialog or a drop-down shell sizes itself by.addColorListener
Adds a color listener, called on the SWT thread when the color or the reference changes.removeColorListener
Removes a color listener.setAcceptHandler
Sets what Enter does once a pending typed value is committed. The default presses the shell's default button, if any.- Parameters:
handler- Run on the SWT thread, or null for the default.
setCancelHandler
Sets what Escape does. The default closes the shell.- Parameters:
handler- Run on the SWT thread, or null for the default.
accept
public void accept()Accepts: commits a pending typed value and runs the accept handler, by default the shell's default button. A second call during the same key press is ignored.cancel
public void cancel()Cancels: runs the cancel handler, by default closing the shell.commitPendingEdits
public boolean commitPendingEdits()Commits a value typed in the hex field or a spinner and not yet entered. A commit drops a palette reference.- Returns:
- true if a value was committed.