author | wenzelm |
Thu, 01 Jan 2015 14:37:25 +0100 | |
changeset 59225 | d0edf67253d3 |
parent 59219 | 6e77ddb1e3fb |
child 59226 | 7b8c50be8d42 |
permissions | -rw-r--r-- |
59202 | 1 |
/* Title: Tools/Graphview/graph_panel.scala |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Markus Kaiser, TU Muenchen |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
3 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
4 |
Graphview Java2D drawing panel. |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
5 |
*/ |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
6 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
7 |
package isabelle.graphview |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
8 |
|
55618 | 9 |
|
49558 | 10 |
import isabelle._ |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
11 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
12 |
import java.awt.{Dimension, Graphics2D, Point, Rectangle} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
13 |
import java.awt.geom.{AffineTransform, Point2D} |
49732 | 14 |
import java.awt.image.BufferedImage |
59225 | 15 |
import javax.swing.{JScrollPane, JComponent, SwingUtilities} |
49729 | 16 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
17 |
import scala.swing.{Panel, ScrollPane} |
59225 | 18 |
import scala.swing.event.{Event, Key, KeyTyped, MousePressed, MouseDragged, |
19 |
MouseMoved, MouseClicked, MouseWheelMoved, MouseEvent} |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
20 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
21 |
|
49731 | 22 |
class Graph_Panel( |
23 |
val visualizer: Visualizer, |
|
24 |
make_tooltip: (JComponent, Int, Int, XML.Body) => String) |
|
49729 | 25 |
extends ScrollPane |
26 |
{ |
|
49731 | 27 |
panel => |
49729 | 28 |
|
29 |
override lazy val peer: JScrollPane = new JScrollPane with SuperMixin { |
|
49730 | 30 |
override def getToolTipText(event: java.awt.event.MouseEvent): String = |
49732 | 31 |
node(Transform.pane_to_graph_coordinates(event.getPoint)) match { |
32 |
case Some(name) => |
|
33 |
visualizer.model.complete.get_node(name).content match { |
|
34 |
case Nil => null |
|
35 |
case content => make_tooltip(panel.peer, event.getX, event.getY, content) |
|
36 |
} |
|
37 |
case None => null |
|
38 |
} |
|
49729 | 39 |
} |
40 |
||
41 |
peer.setWheelScrollingEnabled(false) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
42 |
focusable = true |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
43 |
requestFocus() |
50470 | 44 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
45 |
horizontalScrollBarPolicy = ScrollPane.BarPolicy.Always |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
46 |
verticalScrollBarPolicy = ScrollPane.BarPolicy.Always |
49729 | 47 |
|
49732 | 48 |
def node(at: Point2D): Option[String] = |
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
55618
diff
changeset
|
49 |
visualizer.model.visible_nodes_iterator |
50476
1cb983bccb5b
more official graphics context with font metrics;
wenzelm
parents:
50474
diff
changeset
|
50 |
.find(name => visualizer.Drawer.shape(visualizer.gfx, Some(name)).contains(at)) |
49732 | 51 |
|
49735
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
wenzelm
parents:
49733
diff
changeset
|
52 |
def refresh() |
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
wenzelm
parents:
49733
diff
changeset
|
53 |
{ |
50491 | 54 |
if (paint_panel != null) { |
55 |
paint_panel.set_preferred_size() |
|
56 |
paint_panel.repaint() |
|
57 |
} |
|
49735
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
wenzelm
parents:
49733
diff
changeset
|
58 |
} |
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
wenzelm
parents:
49733
diff
changeset
|
59 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
60 |
def fit_to_window() = { |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
61 |
Transform.fit_to_window() |
49735
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
wenzelm
parents:
49733
diff
changeset
|
62 |
refresh() |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
63 |
} |
50470 | 64 |
|
57044 | 65 |
val zoom = new GUI.Zoom_Box { def changed = rescale(0.01 * factor) } |
50491 | 66 |
|
50478 | 67 |
def rescale(s: Double) |
68 |
{ |
|
69 |
Transform.scale = s |
|
57044 | 70 |
if (zoom != null) zoom.set_item((Transform.scale_discrete * 100).round.toInt) |
50478 | 71 |
refresh() |
72 |
} |
|
73 |
||
50470 | 74 |
def apply_layout() = visualizer.Coordinates.update_layout() |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
75 |
|
59218 | 76 |
private class Paint_Panel extends Panel |
77 |
{ |
|
78 |
def set_preferred_size() |
|
79 |
{ |
|
80 |
val (minX, minY, maxX, maxY) = visualizer.Coordinates.bounds() |
|
81 |
val s = Transform.scale_discrete |
|
82 |
val (px, py) = Transform.padding |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
83 |
|
59218 | 84 |
preferredSize = |
85 |
new Dimension( |
|
86 |
(math.abs(maxX - minX + px) * s).toInt, |
|
87 |
(math.abs(maxY - minY + py) * s).toInt) |
|
50470 | 88 |
|
59218 | 89 |
revalidate() |
90 |
} |
|
50470 | 91 |
|
59218 | 92 |
override def paint(g: Graphics2D) |
93 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
94 |
super.paintComponent(g) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
95 |
g.transform(Transform()) |
50470 | 96 |
|
49731 | 97 |
visualizer.Drawer.paint_all_visible(g, true) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
98 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
99 |
} |
49954
44658062d822
more explicit auxiliary classes to avoid warning "reflective access of structural type member method" of scala-2.10.0-RC1;
wenzelm
parents:
49745
diff
changeset
|
100 |
private val paint_panel = new Paint_Panel |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
101 |
contents = paint_panel |
50470 | 102 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
103 |
listenTo(keys) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
104 |
listenTo(mouse.moves) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
105 |
listenTo(mouse.clicks) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
106 |
listenTo(mouse.wheel) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
107 |
reactions += Interaction.Mouse.react |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
108 |
reactions += Interaction.Keyboard.react |
59218 | 109 |
reactions += |
110 |
{ |
|
111 |
case KeyTyped(_, _, _, _) => repaint(); requestFocus() |
|
112 |
case MousePressed(_, _, _, _, _) => repaint(); requestFocus() |
|
113 |
case MouseDragged(_, _, _) => repaint(); requestFocus() |
|
114 |
case MouseWheelMoved(_, _, _, _) => repaint(); requestFocus() |
|
115 |
case MouseClicked(_, _, _, _, _) => repaint(); requestFocus() |
|
116 |
case MouseMoved(_, _, _) => repaint() |
|
117 |
} |
|
49733
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
wenzelm
parents:
49732
diff
changeset
|
118 |
|
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
wenzelm
parents:
49732
diff
changeset
|
119 |
visualizer.model.Colors.events += { case _ => repaint() } |
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
wenzelm
parents:
49732
diff
changeset
|
120 |
visualizer.model.Mutators.events += { case _ => repaint() } |
50470 | 121 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
122 |
apply_layout() |
50491 | 123 |
rescale(1.0) |
50470 | 124 |
|
50469 | 125 |
private object Transform |
126 |
{ |
|
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50470
diff
changeset
|
127 |
val padding = (100, 40) |
50470 | 128 |
|
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50470
diff
changeset
|
129 |
private var _scale: Double = 1.0 |
50477 | 130 |
def scale: Double = _scale |
131 |
def scale_=(s: Double) |
|
50468 | 132 |
{ |
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50470
diff
changeset
|
133 |
_scale = (s min 10) max 0.1 |
50468 | 134 |
} |
50477 | 135 |
def scale_discrete: Double = |
136 |
(_scale * visualizer.font_size).round.toDouble / visualizer.font_size |
|
50470 | 137 |
|
59218 | 138 |
def apply() = |
139 |
{ |
|
49731 | 140 |
val (minX, minY, _, _) = visualizer.Coordinates.bounds() |
50470 | 141 |
|
50477 | 142 |
val at = AffineTransform.getScaleInstance(scale_discrete, scale_discrete) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
143 |
at.translate(-minX + padding._1 / 2, -minY + padding._2 / 2) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
144 |
at |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
145 |
} |
50470 | 146 |
|
59218 | 147 |
def fit_to_window() |
148 |
{ |
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
55618
diff
changeset
|
149 |
if (visualizer.model.visible_nodes_iterator.isEmpty) |
50491 | 150 |
rescale(1.0) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
151 |
else { |
49731 | 152 |
val (minX, minY, maxX, maxY) = visualizer.Coordinates.bounds() |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
153 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
154 |
val (dx, dy) = (maxX - minX + padding._1, maxY - minY + padding._2) |
49745 | 155 |
val (sx, sy) = (1.0 * size.width / dx, 1.0 * size.height / dy) |
50491 | 156 |
rescale(sx min sy) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
157 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
158 |
} |
50470 | 159 |
|
59218 | 160 |
def pane_to_graph_coordinates(at: Point2D): Point2D = |
161 |
{ |
|
50477 | 162 |
val s = Transform.scale_discrete |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
163 |
val p = Transform().inverseTransform(peer.getViewport.getViewPosition, null) |
50470 | 164 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
165 |
p.setLocation(p.getX + at.getX / s, p.getY + at.getY / s) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
166 |
p |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
167 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
168 |
} |
50470 | 169 |
|
59218 | 170 |
object Interaction |
171 |
{ |
|
172 |
object Keyboard |
|
173 |
{ |
|
174 |
val react: PartialFunction[Event, Unit] = |
|
175 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
176 |
case KeyTyped(_, c, m, _) => typed(c, m) |
50470 | 177 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
178 |
|
59225 | 179 |
def typed(c: Char, m: Key.Modifiers) = |
50470 | 180 |
(c, m) match { |
50491 | 181 |
case ('+', _) => rescale(Transform.scale * 5.0/4) |
182 |
case ('-', _) => rescale(Transform.scale * 4.0/5) |
|
50470 | 183 |
case ('0', _) => Transform.fit_to_window() |
184 |
case ('1', _) => visualizer.Coordinates.update_layout() |
|
185 |
case ('2', _) => Transform.fit_to_window() |
|
186 |
case _ => |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
187 |
} |
50470 | 188 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
189 |
|
59218 | 190 |
object Mouse |
191 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
192 |
type Dummy = ((String, String), Int) |
50470 | 193 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
194 |
private var draginfo: (Point, Iterable[String], Iterable[Dummy]) = null |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
195 |
|
59218 | 196 |
val react: PartialFunction[Event, Unit] = |
197 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
198 |
case MousePressed(_, p, _, _, _) => pressed(p) |
59218 | 199 |
case MouseDragged(_, to, _) => |
200 |
drag(draginfo, to) |
|
201 |
val (_, p, d) = draginfo |
|
202 |
draginfo = (to, p, d) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
203 |
case MouseWheelMoved(_, p, _, r) => wheel(r, p) |
59218 | 204 |
case e @ MouseClicked(_, p, m, n, _) => click(p, m, n, e) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
205 |
} |
50470 | 206 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
207 |
def dummy(at: Point2D): Option[Dummy] = |
59218 | 208 |
visualizer.model.visible_edges_iterator.map( |
209 |
i => visualizer.Coordinates(i).zipWithIndex.map((i, _))).flatten.find({ |
|
50470 | 210 |
case (_, ((x, y), _)) => |
50476
1cb983bccb5b
more official graphics context with font metrics;
wenzelm
parents:
50474
diff
changeset
|
211 |
visualizer.Drawer.shape(visualizer.gfx, None).contains(at.getX() - x, at.getY() - y) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
212 |
}) match { |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
213 |
case None => None |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
214 |
case Some((name, (_, index))) => Some((name, index)) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
215 |
} |
50470 | 216 |
|
59218 | 217 |
def pressed(at: Point) |
218 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
219 |
val c = Transform.pane_to_graph_coordinates(at) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
220 |
val l = node(c) match { |
49731 | 221 |
case Some(l) => |
222 |
if (visualizer.Selection(l)) visualizer.Selection() else List(l) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
223 |
case None => Nil |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
224 |
} |
59218 | 225 |
val d = |
226 |
l match { |
|
227 |
case Nil => |
|
228 |
dummy(c) match { |
|
229 |
case Some(d) => List(d) |
|
230 |
case None => Nil |
|
231 |
} |
|
232 |
case _ => Nil |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
233 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
234 |
draginfo = (at, l, d) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
235 |
} |
50470 | 236 |
|
59225 | 237 |
def click(at: Point, m: Key.Modifiers, clicks: Int, e: MouseEvent) |
59218 | 238 |
{ |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
239 |
val c = Transform.pane_to_graph_coordinates(at) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
240 |
val p = node(c) |
50470 | 241 |
|
59218 | 242 |
def left_click() |
243 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
244 |
(p, m) match { |
59225 | 245 |
case (Some(l), Key.Modifier.Control) => visualizer.Selection.add(l) |
246 |
case (None, Key.Modifier.Control) => |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
247 |
|
59225 | 248 |
case (Some(l), Key.Modifier.Shift) => visualizer.Selection.add(l) |
249 |
case (None, Key.Modifier.Shift) => |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
250 |
|
49731 | 251 |
case (Some(l), _) => visualizer.Selection.set(List(l)) |
252 |
case (None, _) => visualizer.Selection.clear |
|
50470 | 253 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
254 |
} |
50470 | 255 |
|
59218 | 256 |
def right_click() |
257 |
{ |
|
49731 | 258 |
val menu = Popups(panel, p, visualizer.Selection()) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
259 |
menu.show(panel.peer, at.x, at.y) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
260 |
} |
50470 | 261 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
262 |
if (clicks < 2) { |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
263 |
if (SwingUtilities.isRightMouseButton(e.peer)) right_click() |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
264 |
else left_click() |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
265 |
} |
50470 | 266 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
267 |
|
59218 | 268 |
def drag(draginfo: (Point, Iterable[String], Iterable[Dummy]), to: Point) |
269 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
270 |
val (from, p, d) = draginfo |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
271 |
|
50477 | 272 |
val s = Transform.scale_discrete |
50470 | 273 |
val (dx, dy) = (to.x - from.x, to.y - from.y) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
274 |
(p, d) match { |
59218 | 275 |
case (Nil, Nil) => |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
276 |
val r = panel.peer.getViewport.getViewRect |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
277 |
r.translate(-dx, -dy) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
278 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
279 |
paint_panel.peer.scrollRectToVisible(r) |
50470 | 280 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
281 |
case (Nil, ds) => |
49731 | 282 |
ds.foreach(d => visualizer.Coordinates.translate(d, (dx / s, dy / s))) |
50470 | 283 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
284 |
case (ls, _) => |
49731 | 285 |
ls.foreach(l => visualizer.Coordinates.translate(l, (dx / s, dy / s))) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
286 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
287 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
288 |
|
59218 | 289 |
def wheel(rotation: Int, at: Point) |
290 |
{ |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
291 |
val at2 = Transform.pane_to_graph_coordinates(at) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
292 |
// > 0 -> up |
50491 | 293 |
rescale(Transform.scale * (if (rotation > 0) 4.0/5 else 5.0/4)) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
294 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
295 |
// move mouseposition to center |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
296 |
Transform().transform(at2, at2) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
297 |
val r = panel.peer.getViewport.getViewRect |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
298 |
val (width, height) = (r.getWidth, r.getHeight) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
299 |
paint_panel.peer.scrollRectToVisible( |
59218 | 300 |
new Rectangle( |
301 |
(at2.getX() - width / 2).toInt, |
|
302 |
(at2.getY() - height / 2).toInt, |
|
303 |
width.toInt, |
|
304 |
height.toInt)) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
305 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
306 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
307 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
308 |
} |