📄 jcolorchooser.java
字号:
super.setUI(ui); } // setUI() /** * This method resets the UI Component property to the Look and Feel * default. */ public void updateUI() { setUI((ColorChooserUI) UIManager.getUI(this)); revalidate(); } // updateUI() /** * This method returns a String identifier for the UI Class to be used with * the JColorChooser. * * @return The String identifier for the UI Class. */ public String getUIClassID() { return "ColorChooserUI"; } // getUIClassID() /** * This method returns the current color for the JColorChooser. * * @return The current color for the JColorChooser. */ public Color getColor() { return selectionModel.getSelectedColor(); // TODO } // getColor() /** * This method changes the previewPanel property for the JTabbedPane. The * previewPanel is responsible for indicating the current color of the * JColorChooser. * * @param component The Component that will act as the previewPanel. */ public void setPreviewPanel(JComponent component) { if (component != previewPanel) { JComponent old = previewPanel; previewPanel = component; firePropertyChange(PREVIEW_PANEL_PROPERTY, old, previewPanel); } } // setPreviewPanel() /** * This method returns the current previewPanel used with this * JColorChooser. * * @return The current previewPanel. */ public JComponent getPreviewPanel() { return previewPanel; // TODO } // getPreviewPanel() /** * This method adds the given AbstractColorChooserPanel to the list of the * JColorChooser's chooserPanels. * * @param panel The AbstractColorChooserPanel to add. */ public void addChooserPanel(AbstractColorChooserPanel panel) { if (panel == null) return; AbstractColorChooserPanel[] old = chooserPanels; AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[(old == null) ? 1 : old.length + 1]; if (old != null) System.arraycopy(old, 0, newPanels, 0, old.length); newPanels[newPanels.length - 1] = panel; chooserPanels = newPanels; panel.installChooserPanel(this); firePropertyChange(CHOOSER_PANELS_PROPERTY, old, newPanels); } // addChooserPanel() /** * This method removes the given AbstractColorChooserPanel from the * JColorChooser's list of chooserPanels. * * @param panel The AbstractColorChooserPanel to remove. * * @return The AbstractColorChooserPanel that was removed. */ public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel) { int index = -1; for (int i = 0; i < chooserPanels.length; i++) if (panel == chooserPanels[i]) { index = i; break; } if (index == -1) return null; AbstractColorChooserPanel[] old = chooserPanels; if (chooserPanels.length == 1) chooserPanels = null; else { AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[chooserPanels.length - 1]; System.arraycopy(chooserPanels, 0, newPanels, 0, index); System.arraycopy(chooserPanels, index, newPanels, index - 1, chooserPanels.length - index); chooserPanels = newPanels; } panel.uninstallChooserPanel(this); firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels); return panel; } /** * This method sets the chooserPanels property for this JColorChooser. * * @param panels The new set of AbstractColorChooserPanels to use. */ public void setChooserPanels(AbstractColorChooserPanel[] panels) { if (panels != chooserPanels) { if (chooserPanels != null) for (int i = 0; i < chooserPanels.length; i++) if (chooserPanels[i] != null) chooserPanels[i].uninstallChooserPanel(this); AbstractColorChooserPanel[] old = chooserPanels; chooserPanels = panels; if (panels != null) for (int i = 0; i < panels.length; i++) if (panels[i] != null) panels[i].installChooserPanel(this); firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels); } } // setChooserPanels() /** * This method returns the AbstractColorChooserPanels used with this * JColorChooser. * * @return The AbstractColorChooserPanels used with this JColorChooser. */ public AbstractColorChooserPanel[] getChooserPanels() { return chooserPanels; } // getChooserPanels() /** * This method returns the ColorSelectionModel used with this JColorChooser. * * @return The ColorSelectionModel. */ public ColorSelectionModel getSelectionModel() { return selectionModel; } // getSelectionModel() /** * This method sets the ColorSelectionModel to be used with this * JColorChooser. * * @param model The ColorSelectionModel to be used with this JColorChooser. * * @throws AWTError If the given model is null. */ public void setSelectionModel(ColorSelectionModel model) { if (model == null) throw new AWTError("ColorSelectionModel is not allowed to be null."); selectionModel = model; } // setSelectionModel() /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean getDragEnabled() { return dragEnabled; } /** * DOCUMENT ME! * * @param b DOCUMENT ME! */ public void setDragEnabled(boolean b) { dragEnabled = b; } /** * This method returns a String describing the JColorChooser. * * @return A String describing the JColorChooser. */ protected String paramString() { return "JColorChooser"; } // paramString() /** * getAccessibleContext * * @return AccessibleContext */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) accessibleContext = new AccessibleJColorChooser(); return accessibleContext; } /** * A helper class that hides a JDialog when the action is performed. */ static class DefaultOKCancelListener implements ActionListener { /** The JDialog to hide. */ private JDialog dialog; /** * Creates a new DefaultOKCancelListener with the given JDialog to hide. * * @param dialog The JDialog to hide. */ public DefaultOKCancelListener(JDialog dialog) { super(); this.dialog = dialog; } /** * This method hides the JDialog when called. * * @param e The ActionEvent. */ public void actionPerformed(ActionEvent e) { dialog.hide(); } } /** * This method resets the JColorChooser color to the initial color when the * action is performed. */ static class DefaultResetListener implements ActionListener { /** The JColorChooser to reset. */ private JColorChooser chooser; /** The initial color. */ private Color init; /** * Creates a new DefaultResetListener with the given JColorChooser. * * @param chooser The JColorChooser to reset. */ public DefaultResetListener(JColorChooser chooser) { super(); this.chooser = chooser; init = chooser.getColor(); } /** * This method resets the JColorChooser to its initial color. * * @param e The ActionEvent. */ public void actionPerformed(ActionEvent e) { chooser.setColor(init); } } /** * This is a custom JDialog that will notify when it is hidden and the modal * property is set. */ static class ModalDialog extends JDialog { /** The modal property. */ private boolean modal; /** * Creates a new ModalDialog object with the given parent and title. * * @param parent The parent of the JDialog. * @param title The title of the JDialog. */ public ModalDialog(Frame parent, String title) { super(parent, title); } /** * Creates a new ModalDialog object with the given parent and title. * * @param parent The parent of the JDialog. * @param title The title of the JDialog. */ public ModalDialog(Dialog parent, String title) { super(parent, title); } /** * This method sets the modal property. * * @param modal The modal property. */ public void setModal(boolean modal) { this.modal = modal; } /** * This method shows the ModalDialog. */ public void show() { super.show(); if (modal) makeModal(this); } /** * This method hides the ModalDialog. */ public synchronized void hide() { super.hide(); notifyAll(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -