| author | wenzelm | 
| Sat, 17 Jan 2015 22:20:57 +0100 | |
| changeset 59384 | c75327a34960 | 
| parent 59305 | b5e33012180e | 
| child 59386 | 32b162d1d9b5 | 
| 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  | 
| 59240 | 3  | 
Author: Makarius  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
4  | 
|
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
5  | 
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
 | 
6  | 
*/  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
8  | 
package isabelle.graphview  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
9  | 
|
| 55618 | 10  | 
|
| 49558 | 11  | 
import isabelle._  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
12  | 
|
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
13  | 
import java.awt.{Dimension, Graphics2D, Point}
 | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
14  | 
import java.awt.geom.{AffineTransform, Point2D}
 | 
| 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}
 | 
| 59253 | 18  | 
import scala.swing.event.{Event, Key, MousePressed, MouseDragged, MouseClicked, MouseEvent}
 | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
19  | 
|
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
20  | 
|
| 59233 | 21  | 
class Graph_Panel(val visualizer: Visualizer) extends ScrollPane  | 
| 49729 | 22  | 
{
 | 
| 49731 | 23  | 
panel =>  | 
| 49729 | 24  | 
|
| 
59243
 
21ef04bd4e17
recovered tooltip from 6e77ddb1e3fb: non-null default is required as prerequisite;
 
wenzelm 
parents: 
59241 
diff
changeset
 | 
25  | 
tooltip = ""  | 
| 
 
21ef04bd4e17
recovered tooltip from 6e77ddb1e3fb: non-null default is required as prerequisite;
 
wenzelm 
parents: 
59241 
diff
changeset
 | 
26  | 
|
| 49729 | 27  | 
  override lazy val peer: JScrollPane = new JScrollPane with SuperMixin {
 | 
| 49730 | 28  | 
override def getToolTipText(event: java.awt.event.MouseEvent): String =  | 
| 59305 | 29  | 
      visualizer.find_node(Transform.pane_to_graph_coordinates(event.getPoint)) match {
 | 
| 
59245
 
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
 
wenzelm 
parents: 
59243 
diff
changeset
 | 
30  | 
case Some(node) =>  | 
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
31  | 
          visualizer.model.full_graph.get_node(node) match {
 | 
| 49732 | 32  | 
case Nil => null  | 
| 59233 | 33  | 
case content => visualizer.make_tooltip(panel.peer, event.getX, event.getY, content)  | 
| 49732 | 34  | 
}  | 
35  | 
case None => null  | 
|
36  | 
}  | 
|
| 49729 | 37  | 
}  | 
38  | 
||
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
39  | 
focusable = true  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
40  | 
requestFocus()  | 
| 50470 | 41  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
42  | 
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
 | 
43  | 
verticalScrollBarPolicy = ScrollPane.BarPolicy.Always  | 
| 49729 | 44  | 
|
| 
59237
 
ac135eff1ffb
clarified mouse wheel: conventional scrolling, not scaling;
 
wenzelm 
parents: 
59234 
diff
changeset
 | 
45  | 
peer.getVerticalScrollBar.setUnitIncrement(10)  | 
| 
 
ac135eff1ffb
clarified mouse wheel: conventional scrolling, not scaling;
 
wenzelm 
parents: 
59234 
diff
changeset
 | 
46  | 
|
| 
49735
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
47  | 
def refresh()  | 
| 
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
48  | 
  {
 | 
| 50491 | 49  | 
    if (paint_panel != null) {
 | 
50  | 
paint_panel.set_preferred_size()  | 
|
51  | 
paint_panel.repaint()  | 
|
52  | 
}  | 
|
| 
49735
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
53  | 
}  | 
| 
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
54  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
55  | 
  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
 | 
56  | 
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
 | 
57  | 
refresh()  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
58  | 
}  | 
| 50470 | 59  | 
|
| 57044 | 60  | 
  val zoom = new GUI.Zoom_Box { def changed = rescale(0.01 * factor) }
 | 
| 50491 | 61  | 
|
| 50478 | 62  | 
def rescale(s: Double)  | 
63  | 
  {
 | 
|
64  | 
Transform.scale = s  | 
|
| 
59255
 
db265648139c
clarified fit_to_window: floor scale within window bounds;
 
wenzelm 
parents: 
59253 
diff
changeset
 | 
65  | 
if (zoom != null) zoom.set_item((Transform.scale_discrete * 100).floor.toInt)  | 
| 50478 | 66  | 
refresh()  | 
67  | 
}  | 
|
68  | 
||
| 59253 | 69  | 
def apply_layout()  | 
70  | 
  {
 | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
71  | 
visualizer.update_layout()  | 
| 59253 | 72  | 
repaint()  | 
73  | 
}  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
74  | 
|
| 59218 | 75  | 
private class Paint_Panel extends Panel  | 
76  | 
  {
 | 
|
77  | 
def set_preferred_size()  | 
|
78  | 
    {
 | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
79  | 
val box = visualizer.bounding_box()  | 
| 59218 | 80  | 
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
 | 
81  | 
|
| 59218 | 82  | 
preferredSize =  | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
83  | 
new Dimension((box.width * s).ceil.toInt, (box.height * s).ceil.toInt)  | 
| 50470 | 84  | 
|
| 59218 | 85  | 
revalidate()  | 
86  | 
}  | 
|
| 50470 | 87  | 
|
| 59250 | 88  | 
override def paint(gfx: Graphics2D)  | 
| 59218 | 89  | 
    {
 | 
| 59250 | 90  | 
super.paintComponent(gfx)  | 
91  | 
gfx.setColor(visualizer.background_color)  | 
|
92  | 
gfx.fillRect(0, 0, peer.getWidth, peer.getHeight)  | 
|
93  | 
gfx.transform(Transform())  | 
|
| 50470 | 94  | 
|
| 59294 | 95  | 
visualizer.paint_all_visible(gfx)  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
96  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
97  | 
}  | 
| 
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
 | 
98  | 
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
 | 
99  | 
contents = paint_panel  | 
| 50470 | 100  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
101  | 
listenTo(mouse.moves)  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
102  | 
listenTo(mouse.clicks)  | 
| 59253 | 103  | 
reactions += Mouse_Interaction.react  | 
| 59218 | 104  | 
reactions +=  | 
105  | 
  {
 | 
|
| 59253 | 106  | 
case MousePressed(_, _, _, _, _) => repaint()  | 
107  | 
case MouseDragged(_, _, _) => repaint()  | 
|
108  | 
case MouseClicked(_, _, _, _, _) => repaint()  | 
|
| 59218 | 109  | 
}  | 
| 
49733
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
110  | 
|
| 
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
111  | 
  visualizer.model.Colors.events += { case _ => repaint() }
 | 
| 
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
112  | 
  visualizer.model.Mutators.events += { case _ => repaint() }
 | 
| 50470 | 113  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
114  | 
apply_layout()  | 
| 50491 | 115  | 
rescale(1.0)  | 
| 50470 | 116  | 
|
| 50469 | 117  | 
private object Transform  | 
118  | 
  {
 | 
|
| 
50474
 
6ee044e2d1a7
initial layout coordinates more like old browser;
 
wenzelm 
parents: 
50470 
diff
changeset
 | 
119  | 
private var _scale: Double = 1.0  | 
| 50477 | 120  | 
def scale: Double = _scale  | 
121  | 
def scale_=(s: Double)  | 
|
| 50468 | 122  | 
    {
 | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
123  | 
_scale = (s min 10.0) max 0.1  | 
| 50468 | 124  | 
}  | 
| 
59255
 
db265648139c
clarified fit_to_window: floor scale within window bounds;
 
wenzelm 
parents: 
59253 
diff
changeset
 | 
125  | 
|
| 50477 | 126  | 
def scale_discrete: Double =  | 
| 
59286
 
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
 
wenzelm 
parents: 
59262 
diff
changeset
 | 
127  | 
    {
 | 
| 59290 | 128  | 
val font_height = GUI.line_metrics(visualizer.metrics.font).getHeight.toInt  | 
| 
59286
 
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
 
wenzelm 
parents: 
59262 
diff
changeset
 | 
129  | 
(scale * font_height).floor / font_height  | 
| 
 
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
 
wenzelm 
parents: 
59262 
diff
changeset
 | 
130  | 
}  | 
| 50470 | 131  | 
|
| 59218 | 132  | 
def apply() =  | 
133  | 
    {
 | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
134  | 
val box = visualizer.bounding_box()  | 
| 50477 | 135  | 
val at = AffineTransform.getScaleInstance(scale_discrete, scale_discrete)  | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
136  | 
at.translate(- box.x, - box.y)  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
137  | 
at  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
138  | 
}  | 
| 50470 | 139  | 
|
| 59218 | 140  | 
def fit_to_window()  | 
141  | 
    {
 | 
|
| 59290 | 142  | 
if (visualizer.visible_graph.is_empty)  | 
| 50491 | 143  | 
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
 | 
144  | 
      else {
 | 
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
145  | 
val box = visualizer.bounding_box()  | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
146  | 
rescale((size.width / box.width) min (size.height / box.height))  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
147  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
148  | 
}  | 
| 50470 | 149  | 
|
| 59218 | 150  | 
def pane_to_graph_coordinates(at: Point2D): Point2D =  | 
151  | 
    {
 | 
|
| 50477 | 152  | 
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
 | 
153  | 
val p = Transform().inverseTransform(peer.getViewport.getViewPosition, null)  | 
| 50470 | 154  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
155  | 
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
 | 
156  | 
p  | 
| 
 
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  | 
|
| 59253 | 160  | 
object Mouse_Interaction  | 
| 59218 | 161  | 
  {
 | 
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
162  | 
private var draginfo: (Point, List[Graph_Display.Node], List[Layout.Dummy]) = null  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
163  | 
|
| 59253 | 164  | 
val react: PartialFunction[Event, Unit] =  | 
165  | 
    {
 | 
|
166  | 
case MousePressed(_, p, _, _, _) => pressed(p)  | 
|
167  | 
case MouseDragged(_, to, _) =>  | 
|
168  | 
drag(draginfo, to)  | 
|
169  | 
val (_, p, d) = draginfo  | 
|
170  | 
draginfo = (to, p, d)  | 
|
171  | 
case e @ MouseClicked(_, p, m, n, _) => click(p, m, n, e)  | 
|
172  | 
}  | 
|
173  | 
||
174  | 
def pressed(at: Point)  | 
|
| 59218 | 175  | 
    {
 | 
| 59253 | 176  | 
val c = Transform.pane_to_graph_coordinates(at)  | 
177  | 
val l =  | 
|
| 59305 | 178  | 
        visualizer.find_node(c) match {
 | 
| 59253 | 179  | 
case Some(node) =>  | 
180  | 
if (visualizer.Selection.contains(node)) visualizer.Selection.get()  | 
|
181  | 
else List(node)  | 
|
182  | 
case None => Nil  | 
|
183  | 
}  | 
|
184  | 
val d =  | 
|
185  | 
        l match {
 | 
|
| 59305 | 186  | 
case Nil => visualizer.find_dummy(c).toList  | 
| 59253 | 187  | 
case _ => Nil  | 
188  | 
}  | 
|
189  | 
draginfo = (at, l, d)  | 
|
190  | 
}  | 
|
| 50470 | 191  | 
|
| 59253 | 192  | 
def click(at: Point, m: Key.Modifiers, clicks: Int, e: MouseEvent)  | 
193  | 
    {
 | 
|
194  | 
val c = Transform.pane_to_graph_coordinates(at)  | 
|
| 50470 | 195  | 
|
| 59253 | 196  | 
def left_click()  | 
| 59218 | 197  | 
      {
 | 
| 59305 | 198  | 
        (visualizer.find_node(c), m) match {
 | 
| 59253 | 199  | 
case (Some(node), Key.Modifier.Control) => visualizer.Selection.add(node)  | 
200  | 
case (None, Key.Modifier.Control) =>  | 
|
| 50470 | 201  | 
|
| 59253 | 202  | 
case (Some(node), Key.Modifier.Shift) => visualizer.Selection.add(node)  | 
203  | 
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
 | 
204  | 
|
| 59253 | 205  | 
case (Some(node), _) =>  | 
206  | 
visualizer.Selection.clear()  | 
|
207  | 
visualizer.Selection.add(node)  | 
|
208  | 
case (None, _) =>  | 
|
209  | 
visualizer.Selection.clear()  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
210  | 
}  | 
| 50470 | 211  | 
}  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
212  | 
|
| 59253 | 213  | 
def right_click()  | 
| 59218 | 214  | 
      {
 | 
| 59305 | 215  | 
val menu = Popups(panel, visualizer.find_node(c), visualizer.Selection.get())  | 
| 59253 | 216  | 
menu.show(panel.peer, at.x, at.y)  | 
217  | 
}  | 
|
218  | 
||
219  | 
      if (clicks < 2) {
 | 
|
220  | 
if (SwingUtilities.isRightMouseButton(e.peer)) right_click()  | 
|
221  | 
else left_click()  | 
|
222  | 
}  | 
|
223  | 
}  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
224  | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
225  | 
def drag(info: (Point, List[Graph_Display.Node], List[Layout.Dummy]), to: Point)  | 
| 59253 | 226  | 
    {
 | 
| 59262 | 227  | 
val (from, p, d) = info  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
228  | 
|
| 59253 | 229  | 
val s = Transform.scale_discrete  | 
230  | 
val (dx, dy) = (to.x - from.x, to.y - from.y)  | 
|
231  | 
      (p, d) match {
 | 
|
232  | 
case (Nil, Nil) =>  | 
|
233  | 
val r = panel.peer.getViewport.getViewRect  | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
234  | 
r.translate(- dx, - dy)  | 
| 59253 | 235  | 
paint_panel.peer.scrollRectToVisible(r)  | 
| 50470 | 236  | 
|
| 59253 | 237  | 
case (Nil, ds) =>  | 
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
238  | 
ds.foreach(d => visualizer.translate_vertex(d, dx / s, dy / s))  | 
| 59253 | 239  | 
|
240  | 
case (ls, _) =>  | 
|
| 
59302
 
4d985afc0565
explict layout graph structure, with dummies and coordinates;
 
wenzelm 
parents: 
59294 
diff
changeset
 | 
241  | 
ls.foreach(l => visualizer.translate_vertex(Layout.Node(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
 | 
242  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
243  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
244  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
245  | 
}  |