Class ColorPaletteChooserDialog

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

public class ColorPaletteChooserDialog extends JDialog
A ColorPaletteChooserDialog shows a dialog window for selecting a color palette.
Author:
Peter Rose, code adopted from ColorChooserDialog
See Also:
  • Field Details

    • parent

      protected Window parent
      The parent window.
    • innerPanel

      protected JPanel innerPanel
      The inner panel containing everything.
    • colorChooser

      protected JColorChooser colorChooser
      The style editor panel.
    • startingColor

      protected Color startingColor
      Starting color, set by setColor, and the color we return to on a reset.
    • startingColorBrewer

      protected ColorBrewer startingColorBrewer
      Starting color, set by setColor, and the color we return to on a reset.
    • okWasPressed

      protected boolean okWasPressed
      True if OK was pressed; false otherwise.
  • Constructor Details

    • ColorPaletteChooserDialog

      public ColorPaletteChooserDialog()
      Create a non-modal color chooser dialog to select a color.

      This constructor does not require a parent argument to specify a parent window or dialog for this dialog. As a result, this dialog is always non-modal - it does not block interaction with the rest of the application.

    • ColorPaletteChooserDialog

      public ColorPaletteChooserDialog(Frame parent)
      Create a modal color chooser dialog to select a color.
      Parameters:
      parent - the parent frame for this dialog
    • ColorPaletteChooserDialog

      public ColorPaletteChooserDialog(Dialog parent)
      Create a modal color chooser dialog to select a color.
      Parameters:
      parent - the parent dialog for this dialog
  • Method Details

    • initialize

      protected void initialize()
      Initializes the GUI for the window. That GUI includes a JColorChooser panel, framed with an empty border.
    • show

      public void show()
      Show the dialog box. The dialog is automatically centered on the parent window, or on the screen if there is no parent.

      By default, the dialog box is modal and this method call blocks until the dialog box is closed by the user pressing OK or Cancel. The wasOKPressed() method returns true if OK was pressed.

      Overrides:
      show in class Dialog
      See Also:
    • setBackground

      public void setBackground(Color background)
      Set the background color for the window.
      Overrides:
      setBackground in class Dialog
      Parameters:
      background - the new background color
    • showDialog

      public boolean showDialog()
      Shows the dialog box and waits for the user to press OK or Cancel. When either is pressed, the dialog box is hidden. A true is returned if OK was pressed, and false otherwise.

      This method blocks until the dialog is closed by the user, regardless of whether the dialog box is modal or not.

      Returns:
      true if OK was pressed
    • wasOKPressed

      public boolean wasOKPressed()
      Returns true if the OK button was pressed to close the window, and false otherwise.
      Returns:
      true if OK was pressed
    • getColor

      public Color getColor()
      Get the current color in the color chooser.
      Returns:
      the current color
    • setColor

      public void setColor(Color color)
      Set the current color in the color chooser.
      Parameters:
      color - the new color
    • setColor

      public void setColor(int red, int green, int blue)
      Set the current color in the color chooser.
      Parameters:
      red - the red component of the new color
      green - the green component of the new color
      blue - the blue component of the new color
    • getColorPalette

      public ColorBrewer getColorPalette()
      Get the current color in the color chooser.
      Returns:
      the current color
    • setColorBrewer

      public void setColorBrewer(ColorBrewer brewer)
      Set the current color in the color chooser.
      Parameters:
      color - the new color
    • main

      public static void main(String[] args)