Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package javajs.async

File AsyncColorChooser.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

6
14
6
1
67
41
10
0.71
2.33
6
1.67

Classes

Class Line # Actions
AsyncColorChooser 21 14 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package javajs.async;
2   
3    import java.awt.Color;
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;
9   
10    import javax.swing.JColorChooser;
11    import javax.swing.plaf.UIResource;
12   
13    /**
14    * A simple Asynchronous file chooser for JavaScript; synchronous with Java.
15    *
16    * Allows two modes -- using an ActionListener (setAction(ActionListener) or constructor(ActionListener))
17    *
18    * @author Bob Hanson
19    */
20   
 
21    public class AsyncColorChooser implements PropertyChangeListener {
22   
23    private ActionListener listener;
24    private Color selectedColor;
25   
 
26  0 toggle public void showDialog(Component component, String title, Color initialColor, ActionListener listener) {
27  0 setListener(listener);
28  0 process(JColorChooser.showDialog(component, title, initialColor));
29  0 unsetListener();
30    }
31   
 
32  0 toggle public Color getSelectedColor() {
33  0 return selectedColor;
34    }
35   
36   
 
37  0 toggle @Override
38    public void propertyChange(PropertyChangeEvent evt) {
39    // JavaScript only
40  0 Color c = (Color) evt.getNewValue();
41   
42  0 switch (evt.getPropertyName()) {
43  0 case "SelectedColor":
44  0 process(c);
45  0 break;
46    }
47    }
48   
 
49  0 toggle private void setListener(ActionListener a) {
50  0 listener = a;
51    /** @j2sNative Clazz.load("javax.swing.JColorChooser");javax.swing.JColorChooser.listener = this */
52    }
53   
 
54  0 toggle private void unsetListener() {
55    /** @j2sNative javax.swing.JColorChooser.listener = null */
56    }
57   
58   
59   
 
60  0 toggle private void process(Color c) {
61  0 if (c instanceof UIResource)
62  0 return;
63  0 selectedColor = c;
64  0 listener.actionPerformed(new ActionEvent(this, c == null ? 0 : c.getRGB(), c == null ? null : c.toString()));
65    }
66   
67    }