1 23 24 package org.objectweb.fractal.gui.graph.view; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.graph.model.Tools; 29 import org.objectweb.fractal.gui.graph.model.ToolsListener; 30 import org.objectweb.fractal.swing.ActionAttributes; 31 32 import java.awt.event.ActionEvent ; 33 import java.awt.Insets ; 34 35 import javax.swing.ImageIcon ; 36 import javax.swing.JToggleButton ; 37 import javax.swing.Action ; 38 39 45 46 public class BasicToolView extends JToggleButton implements 47 Action , 48 ToolsListener, 49 BindingController, 50 ActionAttributes 51 { 52 53 57 58 public final static String TOOLS_BINDING = "tools"; 59 60 63 64 private Tools tools; 65 66 69 70 private String iconURL; 71 72 75 76 private String acceleratorKey; 77 78 82 83 private int tool; 84 85 88 89 public BasicToolView () { 90 setMargin(new Insets (2, 2, 2, 2)); 91 } 92 93 97 public String [] listFc () { 98 return new String [] { TOOLS_BINDING }; 99 } 100 101 public Object lookupFc (final String clientItfName) { 102 if (TOOLS_BINDING.equals(clientItfName)) { 103 return tools; 104 } 105 return null; 106 } 107 108 public void bindFc ( 109 final String clientItfName, 110 final Object serverItf) 111 { 112 if (TOOLS_BINDING.equals(clientItfName)) { 113 tools = (Tools)serverItf; 114 } 115 } 116 117 public void unbindFc (final String clientItfName) { 118 if (TOOLS_BINDING.equals(clientItfName)) { 119 tools = null; 120 } 121 } 122 123 127 public Object getValue (final String key) { 128 return null; 129 } 130 131 public void putValue (final String key, final Object value) { 132 } 133 134 public void actionPerformed (final ActionEvent e) { 135 } 136 137 141 public void setName (final String name) { 142 super.setName(name); 143 if (name.equals("Edit")) { 144 tool = Tools.SELECT; 145 } else if (name.equals("Move")) { 146 tool = Tools.MOVE; 147 } else if (name.equals("Zoomin")) { 148 tool = Tools.ZOOM_IN; 149 } else if (name.equals("Zoomout")) { 150 tool = Tools.ZOOM_OUT; 151 } 152 } 153 154 public String getIconURL () { 155 return iconURL; 156 } 157 158 public void setIconURL (final String iconURL) { 159 this.iconURL = iconURL; 160 setIcon(new ImageIcon (getClass().getResource(iconURL))); 161 } 162 163 public String getAcceleratorKey () { 164 return acceleratorKey; 165 } 166 167 public void setAcceleratorKey (final String acceleratorKey) { 168 this.acceleratorKey = acceleratorKey; 169 } 170 171 175 public void toolChanged () { 176 setSelected(tools.getTool() == tool); 177 } 178 179 183 protected void fireStateChanged () { 184 super.fireStateChanged(); 185 if (isSelected()) { 186 tools.setTool(tool); 187 } 188 } 189 } 190 | Popular Tags |