jcolorchooser.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 645 行 · 第 1/2 页
JAVA
645 行
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) { 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)); } /** * 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); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?