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.Rectangle ; 34 import java.awt.event.MouseEvent ; 35 import java.awt.Cursor ; 36 import javax.swing.JComponent ; 37 38 42 43 public class ZoomTool extends EmptyGraphViewListener 44 implements BindingController 45 { 46 47 51 52 public final static String TOOLS_BINDING = "tools"; 53 54 58 59 public final static String DISPLAY_BINDING = "display"; 60 61 64 65 private Tools tools; 66 67 70 71 private Display display; 72 73 76 77 public ZoomTool () { 78 } 79 80 84 public String [] listFc () { 85 return new String [] { DISPLAY_BINDING, TOOLS_BINDING }; 86 } 87 88 public Object lookupFc (final String clientItfName) { 89 if (DISPLAY_BINDING.equals(clientItfName)) { 90 return display; 91 } else if (TOOLS_BINDING.equals(clientItfName)) { 92 return tools; 93 } 94 return null; 95 } 96 97 public void bindFc ( 98 final String clientItfName, 99 final Object serverItf) 100 { 101 if (DISPLAY_BINDING.equals(clientItfName)) { 102 display = (Display)serverItf; 103 } else if (TOOLS_BINDING.equals(clientItfName)) { 104 tools = (Tools)serverItf; 105 } 106 } 107 108 public void unbindFc (final String clientItfName) { 109 if (DISPLAY_BINDING.equals(clientItfName)) { 110 display = null; 111 } else if (TOOLS_BINDING.equals(clientItfName)) { 112 tools = null; 113 } 114 } 115 116 120 public void mouseClicked (final MouseEvent e, final ComponentPart p) { 121 int tool = tools.getTool(); 122 if (tool == Tools.ZOOM_IN || tool == Tools.ZOOM_OUT) { 123 Rect position = display.getDisplayedArea(); 124 Rectangle r = display.getScreenSize(); 125 double X0 = position.x0; 126 double Y0 = position.y0; 127 double X1 = position.x1; 128 double Y1 = position.y1; 129 X0 += ((double)(r.width/2 - e.getX()))/r.width; 130 Y0 += ((double)(r.height/2 - e.getY()))/r.height; 131 X1 += ((double)(r.width/2 - e.getX()))/r.width; 132 Y1 += ((double)(r.height/2 - e.getY()))/r.height; 133 if (tool == Tools.ZOOM_IN) { 134 display.setDisplayedArea(new Rect( 135 0.5 + (X0 - 0.5)*1.2, 136 0.5 + (Y0 - 0.5)*1.2, 137 0.5 + (X1 - 0.5)*1.2, 138 0.5 + (Y1 - 0.5)*1.2 139 )); 140 } else { 141 display.setDisplayedArea(new Rect( 142 0.5 + (X0 - 0.5)/1.2, 143 0.5 + (Y0 - 0.5)/1.2, 144 0.5 + (X1 - 0.5)/1.2, 145 0.5 + (Y1 - 0.5)/1.2 146 )); 147 } 148 } 149 } 150 151 public void mouseMoved (final MouseEvent e, final ComponentPart p) { 152 int tool = tools.getTool(); 153 if (tool == Tools.ZOOM_IN) { 154 ((JComponent )e.getSource()).setCursor( 156 Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)); 157 } else if (tool == Tools.ZOOM_OUT) { 158 ((JComponent )e.getSource()).setCursor( 160 Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); 161 } 162 } 163 } 164 | Popular Tags |