1 23 24 package org.objectweb.fractal.gui.graph.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.graph.model.Display; 29 import org.objectweb.fractal.gui.graph.model.Rect; 30 import org.objectweb.fractal.gui.graph.model.Tools; 31 import org.objectweb.fractal.gui.graph.view.ComponentPart; 32 33 import java.awt.Cursor ; 34 import java.awt.Rectangle ; 35 import java.awt.event.MouseEvent ; 36 37 import javax.swing.JComponent ; 38 39 43 44 public class MoveTool extends EmptyGraphViewListener 45 implements BindingController 46 { 47 48 52 53 public final static String TOOLS_BINDING = "tools"; 54 55 59 60 public final static String DISPLAY_BINDING = "display"; 61 62 65 66 private Tools tools; 67 68 71 72 private Display display; 73 74 77 78 private int startX; 79 80 83 84 private int startY; 85 86 90 91 private double startX0; 92 93 97 98 private double startY0; 99 100 104 105 private double startX1; 106 107 111 112 private double startY1; 113 114 117 118 private boolean drag; 119 120 123 124 public MoveTool () { 125 } 126 127 131 public String [] listFc () { 132 return new String [] { DISPLAY_BINDING, TOOLS_BINDING }; 133 } 134 135 public Object lookupFc (final String clientItfName) { 136 if (DISPLAY_BINDING.equals(clientItfName)) { 137 return display; 138 } else if (TOOLS_BINDING.equals(clientItfName)) { 139 return tools; 140 } 141 return null; 142 } 143 144 public void bindFc ( 145 final String clientItfName, 146 final Object serverItf) 147 { 148 if (DISPLAY_BINDING.equals(clientItfName)) { 149 display = (Display)serverItf; 150 } else if (TOOLS_BINDING.equals(clientItfName)) { 151 tools = (Tools)serverItf; 152 } 153 } 154 155 public void unbindFc (final String clientItfName) { 156 if (DISPLAY_BINDING.equals(clientItfName)) { 157 display = null; 158 } else if (TOOLS_BINDING.equals(clientItfName)) { 159 tools = null; 160 } 161 } 162 163 167 public void viewChanged () { 168 drag = false; 169 } 170 171 public void mousePressed (final MouseEvent e, final ComponentPart p) { 172 if (tools.getTool() == Tools.MOVE) { 173 startX = e.getX(); 174 startY = e.getY(); 175 Rect position = display.getDisplayedArea(); 176 startX0 = position.x0; 177 startY0 = position.y0; 178 startX1 = position.x1; 179 startY1 = position.y1; 180 drag = true; 181 } else { 182 drag = false; 183 } 184 } 185 186 public void mouseReleased (final MouseEvent e, final ComponentPart p) { 187 drag = false; 188 } 189 190 public void mouseClicked (final MouseEvent e, final ComponentPart p) { 191 drag = false; 192 } 193 194 public void mouseDragged (final MouseEvent e) { 195 if (drag) { 196 Rectangle r = display.getScreenSize(); 197 double X0 = startX0 + ((double)(e.getX() - startX))/r.width; 198 double Y0 = startY0 + ((double)(e.getY() - startY))/r.height; 199 double X1 = startX1 + ((double)(e.getX() - startX))/r.width; 200 double Y1 = startY1 + ((double)(e.getY() - startY))/r.height; 201 display.setDisplayedArea(new Rect(X0, Y0, X1, Y1)); 202 } 203 } 204 205 public void mouseMoved (final MouseEvent e, final ComponentPart p) { 206 if (tools.getTool() == Tools.MOVE) { 208 ((JComponent )e.getSource()).setCursor( 209 Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 210 } 211 } 212 } 213 | Popular Tags |