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.Tools; 29 import org.objectweb.fractal.gui.graph.view.ComponentPart; 30 import org.objectweb.fractal.gui.model.ClientInterface; 31 import org.objectweb.fractal.gui.model.Interface; 32 import org.objectweb.fractal.gui.model.ServerInterface; 33 34 import java.awt.event.MouseEvent ; 35 36 import javax.swing.JOptionPane ; 37 38 43 44 public class BindTool extends EmptyGraphViewListener 45 implements BindingController 46 { 47 48 52 53 public final static String TOOLS_BINDING = "tools"; 54 55 58 59 private Tools tools; 60 61 64 65 private boolean mouseDragged; 66 67 70 71 public BindTool () { 72 } 73 74 78 public String [] listFc () { 79 return new String [] { TOOLS_BINDING }; 80 } 81 82 public Object lookupFc (final String clientItfName) { 83 if (TOOLS_BINDING.equals(clientItfName)) { 84 return tools; 85 } 86 return null; 87 } 88 89 public void bindFc ( 90 final String clientItfName, 91 final Object serverItf) 92 { 93 if (TOOLS_BINDING.equals(clientItfName)) { 94 tools = (Tools)serverItf; 95 } 96 } 97 98 public void unbindFc (final String clientItfName) { 99 if (TOOLS_BINDING.equals(clientItfName)) { 100 tools = null; 101 } 102 } 103 104 108 public void viewChanged () { 109 if (tools.getTool() == Tools.BIND) { 110 tools.setTool(Tools.SELECT); 111 mouseDragged = false; 112 } 113 } 114 115 public void mousePressed (final MouseEvent e, final ComponentPart p) { 116 if (tools.getTool() == Tools.BIND) { 117 if (!e.isConsumed()) { 118 tools.setTool(Tools.SELECT); 119 } 120 mouseDragged = false; 121 } 122 } 123 124 public void mouseReleased (final MouseEvent e, final ComponentPart p) { 125 if (tools.getTool() == Tools.BIND) { 126 tools.setTool(Tools.SELECT); 127 if (mouseDragged) { 128 ClientInterface citf = (ClientInterface)tools.getBindInterface(); 129 Interface sitf = p.getInterface(); 130 if (sitf != null) { 132 if (sitf instanceof ServerInterface) { 134 if (citf.getBinding() == null) { 135 citf.getOwner().bind(citf, null, (ServerInterface)sitf); 136 } else { 137 citf.getOwner().rebind(citf, (ServerInterface)sitf); 138 } 139 } else { 140 JOptionPane.showMessageDialog( 141 null, 142 "Cannot bind a client interface to another client interface", 143 "Error", 144 JOptionPane.ERROR_MESSAGE); 145 } 146 } else { 147 if (citf.getBinding() != null) { 149 citf.getOwner().unbind(citf); 150 } 151 } 152 156 } 157 } 158 } 159 160 public void mouseClicked (final MouseEvent e, final ComponentPart p) { 161 if (tools.getTool() == Tools.BIND) { 162 tools.setTool(Tools.SELECT); 163 mouseDragged = false; 164 } 165 } 166 167 public void mouseDragged (final MouseEvent e) { 168 if (tools.getTool() == Tools.BIND) { 169 mouseDragged = true; 170 } 171 } 172 173 public void mouseMoved (final MouseEvent e, final ComponentPart p) { 174 if (tools.getTool() == Tools.BIND) { 175 } 178 } 179 } 180 | Popular Tags |