⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcolorchooser.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* JColorChooser.java --   Copyright (C) 2002, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.AWTError;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dialog;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.swing.colorchooser.AbstractColorChooserPanel;import javax.swing.colorchooser.ColorSelectionModel;import javax.swing.colorchooser.DefaultColorSelectionModel;import javax.swing.plaf.ColorChooserUI;/** * A Swing widget that offers users different ways to * select a color. By default, three different panels are presented to the * user that are capable of changing the selected color. There are three ways * to utilize JColorChooser. The first is to build a JColorChooser and add it * to the content pane. The second is to use the createDialog method to * create a JDialog that holds a JColorChooser. The third is to show a * JColorChooser in a JDialog directly using the showDialog method. * * @author original author unknown */public class JColorChooser extends JComponent implements Accessible{  /** DOCUMENT ME! */  private static final long serialVersionUID = 9168066781620640889L;  /**   * Accessibility support for <code>JColorChooser</code>.   */  protected class AccessibleJColorChooser    extends JComponent.AccessibleJComponent  {    /** DOCUMENT ME! */    private static final long serialVersionUID = -2038297864782299082L;    /**     * Constructor AccessibleJColorChooser     */    protected AccessibleJColorChooser()    {      // Nothing to do here.    }    /**     * getAccessibleRole     *     * @return AccessibleRole     */    public AccessibleRole getAccessibleRole()    {      return AccessibleRole.COLOR_CHOOSER;    } // getAccessibleRole()  } // AccessibleJColorChooser  /** The model used with the JColorChooser. */  private ColorSelectionModel selectionModel;  /** The preview panel associated with the JColorChooser. */  private JComponent previewPanel;  /**   * The set of AbstractColorChooserPanels associated with the JColorChooser.   */  private AbstractColorChooserPanel[] chooserPanels;  /** A Drag and Drop property. */  private boolean dragEnabled;  /**   * The property fired by the JColorChooser when the selectionModel property   * changes.   */  public static final String SELECTION_MODEL_PROPERTY = "selectionModel";  /**   * The property fired by the JColorChooser when the previewPanel property   * changes.   */  public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";  /**   * The property fired by the JColorChooser when the chooserPanels property   * changes.   */  public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";  /** accessibleContext */  protected AccessibleContext accessibleContext;  /**   * This method creates a new JColorChooser with the default initial color.   */  public JColorChooser()  {    this(new DefaultColorSelectionModel());  } // JColorChooser()  /**   * This method creates a new JColorChooser with the given initial color.   *   * @param initial The initial color.   */  public JColorChooser(Color initial)  {    this(new DefaultColorSelectionModel(initial));  } // JColorChooser()  /**   * This method creates a new JColorChooser with the given model. The model   * will dictate what the initial color for the JColorChooser is.   *   * @param model The Model to use with the JColorChooser.   */  public JColorChooser(ColorSelectionModel model)  {    if (model == null)      model = new DefaultColorSelectionModel();    selectionModel = model;    updateUI();  } // JColorChooser()  /**   * This method sets the current color for the JColorChooser.   *   * @param color The new color for the JColorChooser.   */  public void setColor(Color color)  {    if (color != null)      selectionModel.setSelectedColor(color);  } // setColor()  /**   * This method sets the current color for the JColorChooser using RGB   * values.   *   * @param r The red value.   * @param g The green value.   * @param b The blue value.   */  public void setColor(int r, int g, int b)  {    selectionModel.setSelectedColor(new Color(r, g, b));  } // setColor()  /**   * This method sets the current color for the JColorChooser using the   * integer value. Bits 0-7 represent the blue value. Bits 8-15 represent   * the green value. Bits 16-23 represent the red value.   *   * @param color The new current color of the JColorChooser.   */  public void setColor(int color)  {    setColor(new Color(color, false));  } // setColor()  /**   * This method shows a JColorChooser inside a JDialog. The JDialog will   * block until it is hidden. The JDialog comes with three buttons: OK,   * Cancel, and Reset. Pressing OK or Cancel hide the JDialog. Pressing   * Reset will reset the JColorChooser to its initial value.   *   * @param component The Component that parents the JDialog.   * @param title The title displayed in the JDialog.   * @param initial The initial color.   *   * @return The selected color.   */  public static Color showDialog(Component component, String title,                                 Color initial)  {    JColorChooser choose = new JColorChooser(initial);    JDialog dialog = createDialog(component, title, true, choose, null, null);    dialog.getContentPane().add(choose);    dialog.pack();    dialog.show();    return choose.getColor();  } // showDialog()  /**   * This is a helper method to make the given JDialog block until it is   * hidden.  This is package-private to avoid an accessor method.   *   * @param dialog The JDialog to block.   */  static void makeModal(JDialog dialog)  {    try      {        synchronized (dialog)          {            while (dialog.isVisible())              dialog.wait();          }      }    catch (InterruptedException e)      {        // TODO: Should this be handled?      }  }  /**   * This is a helper method to find the first Frame or Dialog ancestor of the   * given Component.   *   * @param c The Component to find ancestors for.   *   * @return A Frame or Dialog ancestor. Null if none are found.   */  private static Component findParent(Component c)  {    Component parent = SwingUtilities.getAncestorOfClass(Frame.class, c);    if (parent != null)      return parent;    parent = SwingUtilities.getAncestorOfClass(Dialog.class, c);    return parent;  }  /**   * This method will take the given JColorChooser and place it in a JDialog   * with the given modal property. Three buttons are displayed in the   * JDialog: OK, Cancel and Reset. If OK or Cancel are pressed, the JDialog   * is hidden. If Reset is pressed, then the JColorChooser will take on its   * default color value. The given okListener will be registered to the OK   * button and the cancelListener will be registered to the Cancel button.   * If the modal property is set, then the JDialog will block until it is   * hidden.   *   * @param component The Component that will parent the JDialog.   * @param title The title displayed in the JDialog.   * @param modal The modal property.   * @param chooserPane The JColorChooser to place in the JDialog.   * @param okListener The ActionListener to register to the OK button.   * @param cancelListener The ActionListener to register to the Cancel   *        button.   *   * @return A JDialog with the JColorChooser inside of it.   *   * @throws AWTError If the component is not a suitable parent.   */  public static JDialog createDialog(Component component, String title,                                     boolean modal, JColorChooser chooserPane,                                     ActionListener okListener,                                     ActionListener cancelListener)  {    Component parent = findParent(component);    if (parent == null)      throw new AWTError("No suitable parent found for Component.");    JDialog dialog;    if (parent instanceof Frame)      dialog = new ModalDialog((Frame) parent, title);    else      dialog = new ModalDialog((Dialog) parent, title);    dialog.setModal(modal);    dialog.getContentPane().setLayout(new BorderLayout());    JPanel panel = new JPanel();    panel.setLayout(new FlowLayout());    ActionListener al = new DefaultOKCancelListener(dialog);    JButton ok = new JButton("OK");    ok.addActionListener(okListener);    ok.addActionListener(al);    JButton cancel = new JButton("Cancel");    cancel.addActionListener(cancelListener);    cancel.addActionListener(al);    JButton reset = new JButton("Reset");    reset.addActionListener(new DefaultResetListener(chooserPane));    dialog.getContentPane().add(chooserPane, BorderLayout.NORTH);    panel.add(ok);    panel.add(cancel);    panel.add(reset);    dialog.getContentPane().add(panel, BorderLayout.SOUTH);    return dialog;  } // createDialog()  /**   * This method returns the UI Component used for this JColorChooser.   *   * @return The UI Component for this JColorChooser.   */  public ColorChooserUI getUI()  {    return (ColorChooserUI) ui;  } // getUI()  /**   * This method sets the UI Component used for this JColorChooser.   *   * @param ui The UI Component to use with this JColorChooser.   */  public void setUI(ColorChooserUI ui)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -