1 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 ; 16 import java.awt.Color ; 17 import java.net.URL ; 18 19 import javax.swing.JColorChooser ; 20 import javax.swing.ImageIcon ; 21 22 public class ChangeColorAction extends AbstractAction implements 23 SelectionListener, 24 BindingController 25 { 26 27 32 33 public final static String SELECTION_BINDING = "selection"; 34 35 39 40 public final static String GRAPH_BINDING = "graph"; 41 42 45 46 Selection selection; 47 48 51 52 GraphModel graph; 53 54 public ChangeColorAction () { 55 putValue(NAME, "Color..."); 56 putValue(SHORT_DESCRIPTION, "Color"); 57 URL url = getClass().getResource( 58 "/org/objectweb/fractal/gui/resources/empty.gif"); 59 putValue(SMALL_ICON, new ImageIcon (url)); 60 } 61 62 66 public String [] listFc () { 67 return new String [] { SELECTION_BINDING, GRAPH_BINDING }; 68 } 69 70 public Object lookupFc (final String 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 clientItfName, 81 final Object 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 clientItfName) { 91 if (SELECTION_BINDING.equals(clientItfName)) { 92 selection = null; 93 } else if (GRAPH_BINDING.equals(clientItfName)) { 94 graph = null; 95 } 96 } 97 98 102 public void selectionChanged () { 103 setEnabled(selection.getSelection() instanceof Component); 104 } 105 106 110 public void actionPerformed (final ActionEvent e) { 111 Object o = selection.getSelection(); 112 Component c = (Component)o; 113 Color 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 |