001 /*
002 * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing;
027
028 import java.awt.*;
029 import java.awt.event.*;
030 import java.beans.*;
031 import java.io.*;
032 import java.util.*;
033
034 import javax.swing.colorchooser.*;
035 import javax.swing.plaf.ColorChooserUI;
036 import javax.swing.event.*;
037 import javax.accessibility.*;
038
039 import sun.swing.SwingUtilities2;
040
041 /**
042 * <code>JColorChooser</code> provides a pane of controls designed to allow
043 * a user to manipulate and select a color.
044 * For information about using color choosers, see
045 * <a
046 href="http://java.sun.com/docs/books/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
047 * a section in <em>The Java Tutorial</em>.
048 *
049 * <p>
050 *
051 * This class provides three levels of API:
052 * <ol>
053 * <li>A static convenience method which shows a modal color-chooser
054 * dialog and returns the color selected by the user.
055 * <li>A static convenience method for creating a color-chooser dialog
056 * where <code>ActionListeners</code> can be specified to be invoked when
057 * the user presses one of the dialog buttons.
058 * <li>The ability to create instances of <code>JColorChooser</code> panes
059 * directly (within any container). <code>PropertyChange</code> listeners
060 * can be added to detect when the current "color" property changes.
061 * </ol>
062 * <p>
063 * <strong>Warning:</strong> Swing is not thread safe. For more
064 * information see <a
065 * href="package-summary.html#threading">Swing's Threading
066 * Policy</a>.
067 * <p>
068 * <strong>Warning:</strong>
069 * Serialized objects of this class will not be compatible with
070 * future Swing releases. The current serialization support is
071 * appropriate for short term storage or RMI between applications running
072 * the same version of Swing. As of 1.4, support for long term storage
073 * of all JavaBeans<sup><font size="-2">TM</font></sup>
074 * has been added to the <code>java.beans</code> package.
075 * Please see {@link java.beans.XMLEncoder}.
076 *
077 *
078 * @beaninfo
079 * attribute: isContainer false
080 * description: A component that supports selecting a Color.
081 *
082 *
083 * @version 1.58 05/05/07
084 * @author James Gosling
085 * @author Amy Fowler
086 * @author Steve Wilson
087 */
088 public class JColorChooser extends JComponent implements Accessible {
089
090 /**
091 * @see #getUIClassID
092 * @see #readObject
093 */
094 private static final String uiClassID = "ColorChooserUI";
095
096 private ColorSelectionModel selectionModel;
097
098 private JComponent previewPanel;
099
100 private AbstractColorChooserPanel[] chooserPanels = new AbstractColorChooserPanel[0];
101
102 private boolean dragEnabled;
103
104 /**
105 * The selection model property name.
106 */
107 public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
108
109 /**
110 * The preview panel property name.
111 */
112 public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
113
114 /**
115 * The chooserPanel array property name.
116 */
117 public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
118
119 /**
120 * Shows a modal color-chooser dialog and blocks until the
121 * dialog is hidden. If the user presses the "OK" button, then
122 * this method hides/disposes the dialog and returns the selected color.
123 * If the user presses the "Cancel" button or closes the dialog without
124 * pressing "OK", then this method hides/disposes the dialog and returns
125 * <code>null</code>.
126 *
127 * @param component the parent <code>Component</code> for the dialog
128 * @param title the String containing the dialog's title
129 * @param initialColor the initial Color set when the color-chooser is shown
130 * @return the selected color or <code>null</code> if the user opted out
131 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
132 * returns true.
133 * @see java.awt.GraphicsEnvironment#isHeadless
134 */
135 public static Color showDialog(Component component, String title,
136 Color initialColor) throws HeadlessException {
137
138 final JColorChooser pane = new JColorChooser(
139 initialColor != null ? initialColor : Color.white);
140
141 ColorTracker ok = new ColorTracker(pane);
142 JDialog dialog = createDialog(component, title, true, pane, ok,
143 null);
144
145 dialog
146 .addComponentListener(new ColorChooserDialog.DisposeOnClose());
147
148 dialog.show(); // blocks until user brings dialog down...
149
150 return ok.getColor();
151 }
152
153 /**
154 * Creates and returns a new dialog containing the specified
155 * <code>ColorChooser</code> pane along with "OK", "Cancel", and "Reset"
156 * buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is
157 * automatically hidden (but not disposed). If the "Reset"
158 * button is pressed, the color-chooser's color will be reset to the
159 * color which was set the last time <code>show</code> was invoked on the
160 * dialog and the dialog will remain showing.
161 *
162 * @param c the parent component for the dialog
163 * @param title the title for the dialog
164 * @param modal a boolean. When true, the remainder of the program
165 * is inactive until the dialog is closed.
166 * @param chooserPane the color-chooser to be placed inside the dialog
167 * @param okListener the ActionListener invoked when "OK" is pressed
168 * @param cancelListener the ActionListener invoked when "Cancel" is pressed
169 * @return a new dialog containing the color-chooser pane
170 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
171 * returns true.
172 * @see java.awt.GraphicsEnvironment#isHeadless
173 */
174 public static JDialog createDialog(Component c, String title,
175 boolean modal, JColorChooser chooserPane,
176 ActionListener okListener, ActionListener cancelListener)
177 throws HeadlessException {
178
179 Window window = JOptionPane.getWindowForComponent(c);
180 ColorChooserDialog dialog;
181 if (window instanceof Frame) {
182 dialog = new ColorChooserDialog((Frame) window, title,
183 modal, c, chooserPane, okListener, cancelListener);
184 } else {
185 dialog = new ColorChooserDialog((Dialog) window, title,
186 modal, c, chooserPane, okListener, cancelListener);
187 }
188 return dialog;
189 }
190
191 /**
192 * Creates a color chooser pane with an initial color of white.
193 */
194 public JColorChooser() {
195 this (Color.white);
196 }
197
198 /**
199 * Creates a color chooser pane with the specified initial color.
200 *
201 * @param initialColor the initial color set in the chooser
202 */
203 public JColorChooser(Color initialColor) {
204 this (new DefaultColorSelectionModel(initialColor));
205
206 }
207
208 /**
209 * Creates a color chooser pane with the specified
210 * <code>ColorSelectionModel</code>.
211 *
212 * @param model the <code>ColorSelectionModel</code> to be used
213 */
214 public JColorChooser(ColorSelectionModel model) {
215 selectionModel = model;
216 updateUI();
217 dragEnabled = false;
218 }
219
220 /**
221 * Returns the L&F object that renders this component.
222 *
223 * @return the <code>ColorChooserUI</code> object that renders
224 * this component
225 */
226 public ColorChooserUI getUI() {
227 return (ColorChooserUI) ui;
228 }
229
230 /**
231 * Sets the L&F object that renders this component.
232 *
233 * @param ui the <code>ColorChooserUI</code> L&F object
234 * @see UIDefaults#getUI
235 *
236 * @beaninfo
237 * bound: true
238 * hidden: true
239 * description: The UI object that implements the color chooser's LookAndFeel.
240 */
241 public void setUI(ColorChooserUI ui) {
242 super .setUI(ui);
243 }
244
245 /**
246 * Notification from the <code>UIManager</code> that the L&F has changed.
247 * Replaces the current UI object with the latest version from the
248 * <code>UIManager</code>.
249 *
250 * @see JComponent#updateUI
251 */
252 public void updateUI() {
253 setUI((ColorChooserUI) UIManager.getUI(this ));
254 }
255
256 /**
257 * Returns the name of the L&F class that renders this component.
258 *
259 * @return the string "ColorChooserUI"
260 * @see JComponent#getUIClassID
261 * @see UIDefaults#getUI
262 */
263 public String getUIClassID() {
264 return uiClassID;
265 }
266
267 /**
268 * Gets the current color value from the color chooser.
269 * By default, this delegates to the model.
270 *
271 * @return the current color value of the color chooser
272 */
273 public Color getColor() {
274 return selectionModel.getSelectedColor();
275 }
276
277 /**
278 * Sets the current color of the color chooser to the specified color.
279 * The <code>ColorSelectionModel</code> will fire a <code>ChangeEvent</code>
280 * @param color the color to be set in the color chooser
281 * @see JComponent#addPropertyChangeListener
282 *
283 * @beaninfo
284 * bound: false
285 * hidden: false
286 * description: The current color the chooser is to display.
287 */
288 public void setColor(Color color) {
289 selectionModel.setSelectedColor(color);
290
291 }
292
293 /**
294 * Sets the current color of the color chooser to the
295 * specified RGB color. Note that the values of red, green,
296 * and blue should be between the numbers 0 and 255, inclusive.
297 *
298 * @param r an int specifying the amount of Red
299 * @param g an int specifying the amount of Green
300 * @param b an int specifying the amount of Blue
301 * @exception IllegalArgumentException if r,g,b values are out of range
302 * @see java.awt.Color
303 */
304 public void setColor(int r, int g, int b) {
305 setColor(new Color(r, g, b));
306 }
307
308 /**
309 * Sets the current color of the color chooser to the
310 * specified color.
311 *
312 * @param c an integer value that sets the current color in the chooser
313 * where the low-order 8 bits specify the Blue value,
314 * the next 8 bits specify the Green value, and the 8 bits
315 * above that specify the Red value.
316 */
317 public void setColor(int c) {
318 setColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
319 }
320
321 /**
322 * Sets the <code>dragEnabled</code> property,
323 * which must be <code>true</code> to enable
324 * automatic drag handling (the first part of drag and drop)
325 * on this component.
326 * The <code>transferHandler</code> property needs to be set
327 * to a non-<code>null</code> value for the drag to do
328 * anything. The default value of the <code>dragEnabled</code>
329 * property
330 * is <code>false</code>.
331 *
332 * <p>
333 *
334 * When automatic drag handling is enabled,
335 * most look and feels begin a drag-and-drop operation
336 * when the user presses the mouse button over the preview panel.
337 * Some look and feels might not support automatic drag and drop;
338 * they will ignore this property. You can work around such
339 * look and feels by modifying the component
340 * to directly call the <code>exportAsDrag</code> method of a
341 * <code>TransferHandler</code>.
342 *
343 * @param b the value to set the <code>dragEnabled</code> property to
344 * @exception HeadlessException if
345 * <code>b</code> is <code>true</code> and
346 * <code>GraphicsEnvironment.isHeadless()</code>
347 * returns <code>true</code>
348 *
349 * @since 1.4
350 *
351 * @see java.awt.GraphicsEnvironment#isHeadless
352 * @see #getDragEnabled
353 * @see #setTransferHandler
354 * @see TransferHandler
355 *
356 * @beaninfo
357 * description: Determines whether automatic drag handling is enabled.
358 * bound: false
359 */
360 public void setDragEnabled(boolean b) {
361 if (b && GraphicsEnvironment.isHeadless()) {
362 throw new HeadlessException();
363 }
364 dragEnabled = b;
365 }
366
367 /**
368 * Gets the value of the <code>dragEnabled</code> property.
369 *
370 * @return the value of the <code>dragEnabled</code> property
371 * @see #setDragEnabled
372 * @since 1.4
373 */
374 public boolean getDragEnabled() {
375 return dragEnabled;
376 }
377
378 /**
379 * Sets the current preview panel.
380 * This will fire a <code>PropertyChangeEvent</code> for the property
381 * named "previewPanel".
382 *
383 * @param preview the <code>JComponent</code> which displays the current color
384 * @see JComponent#addPropertyChangeListener
385 *
386 * @beaninfo
387 * bound: true
388 * hidden: true
389 * description: The UI component which displays the current color.
390 */
391 public void setPreviewPanel(JComponent preview) {
392
393 if (previewPanel != preview) {
394 JComponent oldPreview = previewPanel;
395 previewPanel = preview;
396 firePropertyChange(JColorChooser.PREVIEW_PANEL_PROPERTY,
397 oldPreview, preview);
398 }
399 }
400
401 /**
402 * Returns the preview panel that shows a chosen color.
403 *
404 * @return a <code>JComponent</code> object -- the preview panel
405 */
406 public JComponent getPreviewPanel() {
407 return previewPanel;
408 }
409
410 /**
411 * Adds a color chooser panel to the color chooser.
412 *
413 * @param panel the <code>AbstractColorChooserPanel</code> to be added
414 */
415 public void addChooserPanel(AbstractColorChooserPanel panel) {
416 AbstractColorChooserPanel[] oldPanels = getChooserPanels();
417 AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[oldPanels.length + 1];
418 System.arraycopy(oldPanels, 0, newPanels, 0, oldPanels.length);
419 newPanels[newPanels.length - 1] = panel;
420 setChooserPanels(newPanels);
421 }
422
423 /**
424 * Removes the Color Panel specified.
425 *
426 * @param panel a string that specifies the panel to be removed
427 * @return the color panel
428 * @exception IllegalArgumentException if panel is not in list of
429 * known chooser panels
430 */
431 public AbstractColorChooserPanel removeChooserPanel(
432 AbstractColorChooserPanel panel) {
433
434 int containedAt = -1;
435
436 for (int i = 0; i < chooserPanels.length; i++) {
437 if (chooserPanels[i] == panel) {
438 containedAt = i;
439 break;
440 }
441 }
442 if (containedAt == -1) {
443 throw new IllegalArgumentException(
444 "chooser panel not in this chooser");
445 }
446
447 AbstractColorChooserPanel[] newArray = new AbstractColorChooserPanel[chooserPanels.length - 1];
448
449 if (containedAt == chooserPanels.length - 1) { // at end
450 System.arraycopy(chooserPanels, 0, newArray, 0,
451 newArray.length);
452 } else if (containedAt == 0) { // at start
453 System.arraycopy(chooserPanels, 1, newArray, 0,
454 newArray.length);
455 } else { // in middle
456 System
457 .arraycopy(chooserPanels, 0, newArray, 0,
458 containedAt);
459 System.arraycopy(chooserPanels, containedAt + 1, newArray,
460 containedAt,
461 (chooserPanels.length - containedAt - 1));
462 }
463
464 setChooserPanels(newArray);
465
466 return panel;
467 }
468
469 /**
470 * Specifies the Color Panels used to choose a color value.
471 *
472 * @param panels an array of <code>AbstractColorChooserPanel</code>
473 * objects
474 *
475 * @beaninfo
476 * bound: true
477 * hidden: true
478 * description: An array of different chooser types.
479 */
480 public void setChooserPanels(AbstractColorChooserPanel[] panels) {
481 AbstractColorChooserPanel[] oldValue = chooserPanels;
482 chooserPanels = panels;
483 firePropertyChange(CHOOSER_PANELS_PROPERTY, oldValue, panels);
484 }
485
486 /**
487 * Returns the specified color panels.
488 *
489 * @return an array of <code>AbstractColorChooserPanel</code> objects
490 */
491 public AbstractColorChooserPanel[] getChooserPanels() {
492 return chooserPanels;
493 }
494
495 /**
496 * Returns the data model that handles color selections.
497 *
498 * @return a <code>ColorSelectionModel</code> object
499 */
500 public ColorSelectionModel getSelectionModel() {
501 return selectionModel;
502 }
503
504 /**
505 * Sets the model containing the selected color.
506 *
507 * @param newModel the new <code>ColorSelectionModel</code> object
508 *
509 * @beaninfo
510 * bound: true
511 * hidden: true
512 * description: The model which contains the currently selected color.
513 */
514 public void setSelectionModel(ColorSelectionModel newModel) {
515 ColorSelectionModel oldModel = selectionModel;
516 selectionModel = newModel;
517 firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY,
518 oldModel, newModel);
519 }
520
521 /**
522 * See <code>readObject</code> and <code>writeObject</code> in
523 * <code>JComponent</code> for more
524 * information about serialization in Swing.
525 */
526 private void writeObject(ObjectOutputStream s) throws IOException {
527 s.defaultWriteObject();
528 if (getUIClassID().equals(uiClassID)) {
529 byte count = JComponent.getWriteObjCounter(this );
530 JComponent.setWriteObjCounter(this , --count);
531 if (count == 0 && ui != null) {
532 ui.installUI(this );
533 }
534 }
535 }
536
537 /**
538 * Returns a string representation of this <code>JColorChooser</code>.
539 * This method
540 * is intended to be used only for debugging purposes, and the
541 * content and format of the returned string may vary between
542 * implementations. The returned string may be empty but may not
543 * be <code>null</code>.
544 *
545 * @return a string representation of this <code>JColorChooser</code>
546 */
547 protected String paramString() {
548 StringBuffer chooserPanelsString = new StringBuffer("");
549 for (int i = 0; i < chooserPanels.length; i++) {
550 chooserPanelsString.append("["
551 + chooserPanels[i].toString() + "]");
552 }
553 String previewPanelString = (previewPanel != null ? previewPanel
554 .toString()
555 : "");
556
557 return super .paramString() + ",chooserPanels="
558 + chooserPanelsString.toString() + ",previewPanel="
559 + previewPanelString;
560 }
561
562 /////////////////
563 // Accessibility support
564 ////////////////
565
566 protected AccessibleContext accessibleContext = null;
567
568 /**
569 * Gets the AccessibleContext associated with this JColorChooser.
570 * For color choosers, the AccessibleContext takes the form of an
571 * AccessibleJColorChooser.
572 * A new AccessibleJColorChooser instance is created if necessary.
573 *
574 * @return an AccessibleJColorChooser that serves as the
575 * AccessibleContext of this JColorChooser
576 */
577 public AccessibleContext getAccessibleContext() {
578 if (accessibleContext == null) {
579 accessibleContext = new AccessibleJColorChooser();
580 }
581 return accessibleContext;
582 }
583
584 /**
585 * This class implements accessibility support for the
586 * <code>JColorChooser</code> class. It provides an implementation of the
587 * Java Accessibility API appropriate to color chooser user-interface
588 * elements.
589 */
590 protected class AccessibleJColorChooser extends
591 AccessibleJComponent {
592
593 /**
594 * Get the role of this object.
595 *
596 * @return an instance of AccessibleRole describing the role of the
597 * object
598 * @see AccessibleRole
599 */
600 public AccessibleRole getAccessibleRole() {
601 return AccessibleRole.COLOR_CHOOSER;
602 }
603
604 } // inner class AccessibleJColorChooser
605 }
606
607 /*
608 * Class which builds a color chooser dialog consisting of
609 * a JColorChooser with "Ok", "Cancel", and "Reset" buttons.
610 *
611 * Note: This needs to be fixed to deal with localization!
612 */
613 class ColorChooserDialog extends JDialog {
614 private Color initialColor;
615 private JColorChooser chooserPane;
616 private JButton cancelButton;
617
618 public ColorChooserDialog(Dialog owner, String title,
619 boolean modal, Component c, JColorChooser chooserPane,
620 ActionListener okListener, ActionListener cancelListener)
621 throws HeadlessException {
622 super (owner, title, modal);
623 initColorChooserDialog(c, chooserPane, okListener,
624 cancelListener);
625 }
626
627 public ColorChooserDialog(Frame owner, String title, boolean modal,
628 Component c, JColorChooser chooserPane,
629 ActionListener okListener, ActionListener cancelListener)
630 throws HeadlessException {
631 super (owner, title, modal);
632 initColorChooserDialog(c, chooserPane, okListener,
633 cancelListener);
634 }
635
636 protected void initColorChooserDialog(Component c,
637 JColorChooser chooserPane, ActionListener okListener,
638 ActionListener cancelListener) {
639 //setResizable(false);
640
641 this .chooserPane = chooserPane;
642
643 String okString = UIManager.getString("ColorChooser.okText");
644 String cancelString = UIManager
645 .getString("ColorChooser.cancelText");
646 String resetString = UIManager
647 .getString("ColorChooser.resetText");
648
649 Container contentPane = getContentPane();
650 contentPane.setLayout(new BorderLayout());
651 contentPane.add(chooserPane, BorderLayout.CENTER);
652
653 /*
654 * Create Lower button panel
655 */
656 JPanel buttonPane = new JPanel();
657 buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
658 JButton okButton = new JButton(okString);
659 getRootPane().setDefaultButton(okButton);
660 okButton.setActionCommand("OK");
661 okButton.addActionListener(new ActionListener() {
662 public void actionPerformed(ActionEvent e) {
663 hide();
664 }
665 });
666 if (okListener != null) {
667 okButton.addActionListener(okListener);
668 }
669 buttonPane.add(okButton);
670
671 cancelButton = new JButton(cancelString);
672
673 // The following few lines are used to register esc to close the dialog
674 Action cancelKeyAction = new AbstractAction() {
675 public void actionPerformed(ActionEvent e) {
676 ((AbstractButton) e.getSource()).fireActionPerformed(e);
677 }
678 };
679 KeyStroke cancelKeyStroke = KeyStroke.getKeyStroke(
680 (char) KeyEvent.VK_ESCAPE, false);
681 InputMap inputMap = cancelButton
682 .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
683 ActionMap actionMap = cancelButton.getActionMap();
684 if (inputMap != null && actionMap != null) {
685 inputMap.put(cancelKeyStroke, "cancel");
686 actionMap.put("cancel", cancelKeyAction);
687 }
688 // end esc handling
689
690 cancelButton.setActionCommand("cancel");
691 cancelButton.addActionListener(new ActionListener() {
692 public void actionPerformed(ActionEvent e) {
693 hide();
694 }
695 });
696 if (cancelListener != null) {
697 cancelButton.addActionListener(cancelListener);
698 }
699 buttonPane.add(cancelButton);
700
701 JButton resetButton = new JButton(resetString);
702 resetButton.addActionListener(new ActionListener() {
703 public void actionPerformed(ActionEvent e) {
704 reset();
705 }
706 });
707 int mnemonic = SwingUtilities2.getUIDefaultsInt(
708 "ColorChooser.resetMnemonic", -1);
709 if (mnemonic != -1) {
710 resetButton.setMnemonic(mnemonic);
711 }
712 buttonPane.add(resetButton);
713 contentPane.add(buttonPane, BorderLayout.SOUTH);
714
715 if (JDialog.isDefaultLookAndFeelDecorated()) {
716 boolean supportsWindowDecorations = UIManager
717 .getLookAndFeel().getSupportsWindowDecorations();
718 if (supportsWindowDecorations) {
719 getRootPane().setWindowDecorationStyle(
720 JRootPane.COLOR_CHOOSER_DIALOG);
721 }
722 }
723 applyComponentOrientation(((c == null) ? getRootPane() : c)
724 .getComponentOrientation());
725
726 pack();
727 setLocationRelativeTo(c);
728
729 this .addWindowListener(new Closer());
730 }
731
732 public void show() {
733 initialColor = chooserPane.getColor();
734 super .show();
735 }
736
737 public void reset() {
738 chooserPane.setColor(initialColor);
739 }
740
741 class Closer extends WindowAdapter implements Serializable {
742 public void windowClosing(WindowEvent e) {
743 cancelButton.doClick(0);
744 Window w = e.getWindow();
745 w.hide();
746 }
747 }
748
749 static class DisposeOnClose extends ComponentAdapter implements
750 Serializable {
751 public void componentHidden(ComponentEvent e) {
752 Window w = (Window) e.getComponent();
753 w.dispose();
754 }
755 }
756
757 }
758
759 class ColorTracker implements ActionListener, Serializable {
760 JColorChooser chooser;
761 Color color;
762
763 public ColorTracker(JColorChooser c) {
764 chooser = c;
765 }
766
767 public void actionPerformed(ActionEvent e) {
768 color = chooser.getColor();
769 }
770
771 public Color getColor() {
772 return color;
773 }
774 }
|