KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > menu > control > ChangeColorAction


1 /**
2  * copyright area
3  */

4
5 package org.objectweb.fractal.gui.menu.control;
6
7 import org.objectweb.fractal.api.control.BindingController;
8
9 import org.objectweb.fractal.gui.selection.model.Selection;
10 import org.objectweb.fractal.gui.selection.model.SelectionListener;
11 import org.objectweb.fractal.gui.graph.model.GraphModel;
12 import org.objectweb.fractal.gui.model.Component;
13 import org.objectweb.fractal.swing.AbstractAction;
14
15 import java.awt.event.ActionEvent JavaDoc;
16 import java.awt.Color JavaDoc;
17 import java.net.URL JavaDoc;
18
19 import javax.swing.JColorChooser JavaDoc;
20 import javax.swing.ImageIcon JavaDoc;
21
22 public class ChangeColorAction extends AbstractAction implements
23   SelectionListener,
24   BindingController
25 {
26
27   /**
28    * A mandatory client interface bound to a {@link Selection selection} model.
29    * This model is used to select the created components or interfaces, and
30    * to add them to the selected component.
31    */

32
33   public final static String JavaDoc SELECTION_BINDING = "selection";
34
35   /**
36    * A mandatory client interface bound to a {@link GraphModel graph model}
37    * component.
38    */

39
40   public final static String JavaDoc GRAPH_BINDING = "graph";
41
42   /**
43    * The selection client interface.
44    */

45
46   Selection selection;
47
48   /**
49    * The graph model client interface.
50    */

51
52   GraphModel graph;
53
54   public ChangeColorAction () {
55     putValue(NAME, "Color...");
56     putValue(SHORT_DESCRIPTION, "Color");
57     URL JavaDoc url = getClass().getResource(
58       "/org/objectweb/fractal/gui/resources/empty.gif");
59     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
60   }
61
62   // -------------------------------------------------------------------------
63
// Implementation of the BindingController interface
64
// -------------------------------------------------------------------------
65

66   public String JavaDoc[] listFc () {
67     return new String JavaDoc[] { SELECTION_BINDING, GRAPH_BINDING };
68   }
69
70   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
71     if (SELECTION_BINDING.equals(clientItfName)) {
72       return selection;
73     } else if (GRAPH_BINDING.equals(clientItfName)) {
74       return graph;
75     }
76     return null;
77   }
78
79   public void bindFc (
80     final String JavaDoc clientItfName,
81     final Object JavaDoc serverItf)
82   {
83     if (SELECTION_BINDING.equals(clientItfName)) {
84       selection = (Selection)serverItf;
85     } else if (GRAPH_BINDING.equals(clientItfName)) {
86       graph = (GraphModel)serverItf;
87     }
88   }
89
90   public void unbindFc (final String JavaDoc clientItfName) {
91     if (SELECTION_BINDING.equals(clientItfName)) {
92       selection = null;
93     } else if (GRAPH_BINDING.equals(clientItfName)) {
94       graph = null;
95     }
96   }
97
98   // -------------------------------------------------------------------------
99
// Implementation of the SelectionListener interface
100
// -------------------------------------------------------------------------
101

102   public void selectionChanged () {
103     setEnabled(selection.getSelection() instanceof Component);
104   }
105
106   // -------------------------------------------------------------------------
107
// Implementation of the ActionListener interface
108
// -------------------------------------------------------------------------
109

110   public void actionPerformed (final ActionEvent JavaDoc e) {
111     Object JavaDoc o = selection.getSelection();
112     Component c = (Component)o;
113     Color JavaDoc color = graph.getComponentColor(c);
114     color = JColorChooser.showDialog(null, "Choose component color", color);
115     if (color != null) {
116       graph.setComponentColor(c, color);
117     }
118   }
119 }
120
Popular Tags