4 import java.awt.Component;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.beans.PropertyChangeEvent;
8 import java.beans.PropertyChangeListener;
10 import javax.swing.JColorChooser;
11 import javax.swing.plaf.UIResource;
14 * A simple Asynchronous file chooser for JavaScript; synchronous with Java.
16 * Allows two modes -- using an ActionListener (setAction(ActionListener) or constructor(ActionListener))
21 public class AsyncColorChooser implements PropertyChangeListener {
23 private ActionListener listener;
24 private Color selectedColor;
26 public void showDialog(Component component, String title, Color initialColor, ActionListener listener) {
27 setListener(listener);
28 process(JColorChooser.showDialog(component, title, initialColor));
32 public Color getSelectedColor() {
38 public void propertyChange(PropertyChangeEvent evt) {
40 Color c = (Color) evt.getNewValue();
42 switch (evt.getPropertyName()) {
49 private void setListener(ActionListener a) {
51 /** @j2sNative Clazz.load("javax.swing.JColorChooser");javax.swing.JColorChooser.listener = this */
54 private void unsetListener() {
55 /** @j2sNative javax.swing.JColorChooser.listener = null */
60 private void process(Color c) {
61 if (c instanceof UIResource)
64 listener.actionPerformed(new ActionEvent(this, c == null ? 0 : c.getRGB(), c == null ? null : c.toString()));