Class ColorDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class ColorDialog extends JDialog
Modal dialog used to select a color.

This dialog is a thin wrapper around ColorPanel. It preserves the original MDI usage pattern and API while delegating all color selection logic to the panel.

In this refactored version, transparency is controlled only by the embedded JColorChooser. The legacy custom transparency slider has been removed from ColorPanel, eliminating conflicting alpha controls.

Author:
heddle
See Also:
  • Field Details

    • colorPanel

      protected ColorPanel colorPanel
      The embedded color selection panel.
    • answer

      protected int answer
      The dialog close status.
  • Constructor Details

    • ColorDialog

      public ColorDialog(Window owner, Color initColor, boolean allowNoColor, boolean allowTransparency)
      Creates a modal color-selection dialog.
      Parameters:
      owner - the parent window; may be null
      initColor - the initial color; may be null
      allowNoColor - if true, the user may select "No Color"
      allowTransparency - if true, transparency selection is allowed through the chooser's built-in alpha support
    • ColorDialog

      public ColorDialog(Window owner, String title, Color initColor, boolean allowNoColor, boolean allowTransparency)
      Creates a modal color-selection dialog.
      Parameters:
      owner - the parent window; may be null
      title - the dialog title; may be null
      initColor - the initial color; may be null
      allowNoColor - if true, the user may select "No Color"
      allowTransparency - if true, transparency selection is allowed through the chooser's built-in alpha support
  • Method Details

    • showDialog

      public static Color showDialog(Window owner, Color initColor, boolean allowNoColor, boolean allowTransparency)
      Displays a modal color dialog and returns the resulting color.
      Parameters:
      owner - the parent window; may be null
      initColor - the initial color; may be null
      allowNoColor - if true, the user may select "No Color"
      allowTransparency - if true, transparency selection is allowed through the chooser's built-in alpha support
      Returns:
      the selected color if the user presses OK; otherwise the original initColor
    • showDialog

      public static Color showDialog(Window owner, String title, Color initColor, boolean allowNoColor, boolean allowTransparency)
      Displays a modal color dialog and returns the resulting color.
      Parameters:
      owner - the parent window; may be null
      title - the dialog title; may be null
      initColor - the initial color; may be null
      allowNoColor - if true, the user may select "No Color"
      allowTransparency - if true, transparency selection is allowed through the chooser's built-in alpha support
      Returns:
      the selected color if the user presses OK; otherwise the original initColor
    • setup

      protected void setup()
      Builds the static dialog layout, including the OK and Cancel buttons.
    • getColor

      public Color getColor()
      Gets the selected color.
      Returns:
      the selected color, or null if "No Color" was selected
    • doClose

      protected void doClose(int reason)
      Closes the dialog with the given reason code.
      Parameters:
      reason - either DialogUtils.OK_RESPONSE or DialogUtils.CANCEL_RESPONSE
    • getAnswer

      public int getAnswer()
      Gets the answer code indicating how the dialog was dismissed.
      Returns:
      the dialog response code