162 } |
162 } |
163 } |
163 } |
164 |
164 |
165 object Mouse_Interaction |
165 object Mouse_Interaction |
166 { |
166 { |
167 type Dummy = (Graph_Display.Edge, Int) |
167 private var draginfo: (Point, List[Graph_Display.Node], List[(Graph_Display.Edge, Int)]) = null |
168 |
|
169 private var draginfo: (Point, List[Graph_Display.Node], List[Dummy]) = null |
|
170 |
168 |
171 val react: PartialFunction[Event, Unit] = |
169 val react: PartialFunction[Event, Unit] = |
172 { |
170 { |
173 case MousePressed(_, p, _, _, _) => pressed(p) |
171 case MousePressed(_, p, _, _, _) => pressed(p) |
174 case MouseDragged(_, to, _) => |
172 case MouseDragged(_, to, _) => |
176 val (_, p, d) = draginfo |
174 val (_, p, d) = draginfo |
177 draginfo = (to, p, d) |
175 draginfo = (to, p, d) |
178 case e @ MouseClicked(_, p, m, n, _) => click(p, m, n, e) |
176 case e @ MouseClicked(_, p, m, n, _) => click(p, m, n, e) |
179 } |
177 } |
180 |
178 |
181 def dummy(at: Point2D): Option[Dummy] = |
179 def dummy(at: Point2D): Option[(Graph_Display.Edge, Int)] = |
182 { |
180 { |
183 val m = visualizer.metrics() |
181 val m = visualizer.metrics() |
184 visualizer.model.make_visible_graph().edges_iterator.map( |
182 visualizer.model.make_visible_graph().edges_iterator.map( |
185 edge => visualizer.Coordinates(edge).zipWithIndex.map((edge, _))).flatten.find( |
183 edge => |
186 { |
184 visualizer.Coordinates.get_dummies(edge).zipWithIndex.map((edge, _))).flatten.find( |
187 case (_, ((x, y), _)) => |
185 { |
188 visualizer.Drawer.shape(m, Graph_Display.Node.dummy). |
186 case (_, (p, _)) => |
189 contains(at.getX() - x, at.getY() - y) |
187 visualizer.Drawer.shape(m, Graph_Display.Node.dummy). |
190 }) match { |
188 contains(at.getX() - p.x, at.getY() - p.y) |
191 case None => None |
189 }) match { |
192 case Some((edge, (_, index))) => Some((edge, index)) |
190 case None => None |
193 } |
191 case Some((edge, (_, index))) => Some((edge, index)) |
|
192 } |
194 } |
193 } |
195 |
194 |
196 def pressed(at: Point) |
195 def pressed(at: Point) |
197 { |
196 { |
198 val c = Transform.pane_to_graph_coordinates(at) |
197 val c = Transform.pane_to_graph_coordinates(at) |
246 if (SwingUtilities.isRightMouseButton(e.peer)) right_click() |
245 if (SwingUtilities.isRightMouseButton(e.peer)) right_click() |
247 else left_click() |
246 else left_click() |
248 } |
247 } |
249 } |
248 } |
250 |
249 |
251 def drag(draginfo: (Point, List[Graph_Display.Node], List[Dummy]), to: Point) |
250 def drag(info: (Point, List[Graph_Display.Node], List[(Graph_Display.Edge, Int)]), to: Point) |
252 { |
251 { |
253 val (from, p, d) = draginfo |
252 val (from, p, d) = info |
254 |
253 |
255 val s = Transform.scale_discrete |
254 val s = Transform.scale_discrete |
256 val (dx, dy) = (to.x - from.x, to.y - from.y) |
255 val (dx, dy) = (to.x - from.x, to.y - from.y) |
257 (p, d) match { |
256 (p, d) match { |
258 case (Nil, Nil) => |
257 case (Nil, Nil) => |
260 r.translate(-dx, -dy) |
259 r.translate(-dx, -dy) |
261 |
260 |
262 paint_panel.peer.scrollRectToVisible(r) |
261 paint_panel.peer.scrollRectToVisible(r) |
263 |
262 |
264 case (Nil, ds) => |
263 case (Nil, ds) => |
265 ds.foreach(d => visualizer.Coordinates.translate(d, (dx / s, dy / s))) |
264 ds.foreach(d => visualizer.Coordinates.translate_dummy(d, dx / s, dy / s)) |
266 |
265 |
267 case (ls, _) => |
266 case (ls, _) => |
268 ls.foreach(l => visualizer.Coordinates.translate(l, (dx / s, dy / s))) |
267 ls.foreach(l => visualizer.Coordinates.translate_node(l, dx / s, dy / s)) |
269 } |
268 } |
270 } |
269 } |
271 } |
270 } |
272 } |
271 } |