| author | wenzelm | 
| Mon, 05 Jan 2015 22:41:09 +0100 | |
| changeset 59292 | fef652c88263 | 
| parent 59291 | 506660c6792f | 
| child 59294 | 126293918a37 | 
| 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 =  | 
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
29  | 
      find_visible_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  | 
|
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
47  | 
def find_visible_node(at: Point2D): Option[Graph_Display.Node] =  | 
| 59290 | 48  | 
visualizer.visible_graph.keys_iterator.find(node =>  | 
| 59291 | 49  | 
Shapes.Node.shape(visualizer, node).contains(at))  | 
| 49732 | 50  | 
|
| 
49735
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
51  | 
def refresh()  | 
| 
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
52  | 
  {
 | 
| 50491 | 53  | 
    if (paint_panel != null) {
 | 
54  | 
paint_panel.set_preferred_size()  | 
|
55  | 
paint_panel.repaint()  | 
|
56  | 
}  | 
|
| 
49735
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
57  | 
}  | 
| 
 
30e2f3f1c623
more precise repaint and revalidate -- the latter is important to keep in sync with content update;
 
wenzelm 
parents: 
49733 
diff
changeset
 | 
58  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
59  | 
  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
 | 
60  | 
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
 | 
61  | 
refresh()  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
62  | 
}  | 
| 50470 | 63  | 
|
| 57044 | 64  | 
  val zoom = new GUI.Zoom_Box { def changed = rescale(0.01 * factor) }
 | 
| 50491 | 65  | 
|
| 50478 | 66  | 
def rescale(s: Double)  | 
67  | 
  {
 | 
|
68  | 
Transform.scale = s  | 
|
| 
59255
 
db265648139c
clarified fit_to_window: floor scale within window bounds;
 
wenzelm 
parents: 
59253 
diff
changeset
 | 
69  | 
if (zoom != null) zoom.set_item((Transform.scale_discrete * 100).floor.toInt)  | 
| 50478 | 70  | 
refresh()  | 
71  | 
}  | 
|
72  | 
||
| 59253 | 73  | 
def apply_layout()  | 
74  | 
  {
 | 
|
75  | 
visualizer.Coordinates.update_layout()  | 
|
76  | 
repaint()  | 
|
77  | 
}  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
78  | 
|
| 59218 | 79  | 
private class Paint_Panel extends Panel  | 
80  | 
  {
 | 
|
81  | 
def set_preferred_size()  | 
|
82  | 
    {
 | 
|
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
83  | 
val box = visualizer.Coordinates.bounding_box()  | 
| 59218 | 84  | 
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
 | 
85  | 
|
| 59218 | 86  | 
preferredSize =  | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
87  | 
new Dimension((box.width * s).ceil.toInt, (box.height * s).ceil.toInt)  | 
| 50470 | 88  | 
|
| 59218 | 89  | 
revalidate()  | 
90  | 
}  | 
|
| 50470 | 91  | 
|
| 59250 | 92  | 
override def paint(gfx: Graphics2D)  | 
| 59218 | 93  | 
    {
 | 
| 59250 | 94  | 
super.paintComponent(gfx)  | 
95  | 
gfx.setColor(visualizer.background_color)  | 
|
96  | 
gfx.fillRect(0, 0, peer.getWidth, peer.getHeight)  | 
|
97  | 
gfx.transform(Transform())  | 
|
| 50470 | 98  | 
|
| 59250 | 99  | 
visualizer.Drawer.paint_all_visible(gfx, true)  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
100  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
101  | 
}  | 
| 
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
 | 
102  | 
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
 | 
103  | 
contents = paint_panel  | 
| 50470 | 104  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
105  | 
listenTo(mouse.moves)  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
106  | 
listenTo(mouse.clicks)  | 
| 59253 | 107  | 
reactions += Mouse_Interaction.react  | 
| 59218 | 108  | 
reactions +=  | 
109  | 
  {
 | 
|
| 59253 | 110  | 
case MousePressed(_, _, _, _, _) => repaint()  | 
111  | 
case MouseDragged(_, _, _) => repaint()  | 
|
112  | 
case MouseClicked(_, _, _, _, _) => repaint()  | 
|
| 59218 | 113  | 
}  | 
| 
49733
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
114  | 
|
| 
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
115  | 
  visualizer.model.Colors.events += { case _ => repaint() }
 | 
| 
 
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
 
wenzelm 
parents: 
49732 
diff
changeset
 | 
116  | 
  visualizer.model.Mutators.events += { case _ => repaint() }
 | 
| 50470 | 117  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
118  | 
apply_layout()  | 
| 50491 | 119  | 
rescale(1.0)  | 
| 50470 | 120  | 
|
| 50469 | 121  | 
private object Transform  | 
122  | 
  {
 | 
|
| 
50474
 
6ee044e2d1a7
initial layout coordinates more like old browser;
 
wenzelm 
parents: 
50470 
diff
changeset
 | 
123  | 
private var _scale: Double = 1.0  | 
| 50477 | 124  | 
def scale: Double = _scale  | 
125  | 
def scale_=(s: Double)  | 
|
| 50468 | 126  | 
    {
 | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
127  | 
_scale = (s min 10.0) max 0.1  | 
| 50468 | 128  | 
}  | 
| 
59255
 
db265648139c
clarified fit_to_window: floor scale within window bounds;
 
wenzelm 
parents: 
59253 
diff
changeset
 | 
129  | 
|
| 50477 | 130  | 
def scale_discrete: Double =  | 
| 
59286
 
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
 
wenzelm 
parents: 
59262 
diff
changeset
 | 
131  | 
    {
 | 
| 59290 | 132  | 
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
 | 
133  | 
(scale * font_height).floor / font_height  | 
| 
 
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
 
wenzelm 
parents: 
59262 
diff
changeset
 | 
134  | 
}  | 
| 50470 | 135  | 
|
| 59218 | 136  | 
def apply() =  | 
137  | 
    {
 | 
|
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
138  | 
val box = visualizer.Coordinates.bounding_box()  | 
| 50477 | 139  | 
val at = AffineTransform.getScaleInstance(scale_discrete, scale_discrete)  | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
140  | 
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
 | 
141  | 
at  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
142  | 
}  | 
| 50470 | 143  | 
|
| 59218 | 144  | 
def fit_to_window()  | 
145  | 
    {
 | 
|
| 59290 | 146  | 
if (visualizer.visible_graph.is_empty)  | 
| 50491 | 147  | 
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
 | 
148  | 
      else {
 | 
| 
59241
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
149  | 
val box = visualizer.Coordinates.bounding_box()  | 
| 
 
541b95e94dc7
clarified bounding box, similar to old graph browser;
 
wenzelm 
parents: 
59240 
diff
changeset
 | 
150  | 
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
 | 
151  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
152  | 
}  | 
| 50470 | 153  | 
|
| 59218 | 154  | 
def pane_to_graph_coordinates(at: Point2D): Point2D =  | 
155  | 
    {
 | 
|
| 50477 | 156  | 
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
 | 
157  | 
val p = Transform().inverseTransform(peer.getViewport.getViewPosition, null)  | 
| 50470 | 158  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
159  | 
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
 | 
160  | 
p  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
161  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
162  | 
}  | 
| 50470 | 163  | 
|
| 59253 | 164  | 
object Mouse_Interaction  | 
| 59218 | 165  | 
  {
 | 
| 59262 | 166  | 
private var draginfo: (Point, List[Graph_Display.Node], List[(Graph_Display.Edge, Int)]) = null  | 
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
167  | 
|
| 59253 | 168  | 
val react: PartialFunction[Event, Unit] =  | 
169  | 
    {
 | 
|
170  | 
case MousePressed(_, p, _, _, _) => pressed(p)  | 
|
171  | 
case MouseDragged(_, to, _) =>  | 
|
172  | 
drag(draginfo, to)  | 
|
173  | 
val (_, p, d) = draginfo  | 
|
174  | 
draginfo = (to, p, d)  | 
|
175  | 
case e @ MouseClicked(_, p, m, n, _) => click(p, m, n, e)  | 
|
176  | 
}  | 
|
177  | 
||
| 59262 | 178  | 
def dummy(at: Point2D): Option[(Graph_Display.Edge, Int)] =  | 
| 59290 | 179  | 
visualizer.visible_graph.edges_iterator.map(edge =>  | 
| 59291 | 180  | 
visualizer.Coordinates.get_dummies(edge).zipWithIndex.map((edge, _))).flatten.  | 
181  | 
          collectFirst({
 | 
|
182  | 
case (edge, (d, index))  | 
|
183  | 
if Shapes.Dummy.shape(visualizer, d).contains(at) => (edge, index)  | 
|
184  | 
})  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
185  | 
|
| 59253 | 186  | 
def pressed(at: Point)  | 
| 59218 | 187  | 
    {
 | 
| 59253 | 188  | 
val c = Transform.pane_to_graph_coordinates(at)  | 
189  | 
val l =  | 
|
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
190  | 
        find_visible_node(c) match {
 | 
| 59253 | 191  | 
case Some(node) =>  | 
192  | 
if (visualizer.Selection.contains(node)) visualizer.Selection.get()  | 
|
193  | 
else List(node)  | 
|
194  | 
case None => Nil  | 
|
195  | 
}  | 
|
196  | 
val d =  | 
|
197  | 
        l match {
 | 
|
198  | 
case Nil =>  | 
|
199  | 
            dummy(c) match {
 | 
|
200  | 
case Some(d) => List(d)  | 
|
201  | 
case None => Nil  | 
|
202  | 
}  | 
|
203  | 
case _ => Nil  | 
|
204  | 
}  | 
|
205  | 
draginfo = (at, l, d)  | 
|
206  | 
}  | 
|
| 50470 | 207  | 
|
| 59253 | 208  | 
def click(at: Point, m: Key.Modifiers, clicks: Int, e: MouseEvent)  | 
209  | 
    {
 | 
|
210  | 
val c = Transform.pane_to_graph_coordinates(at)  | 
|
| 50470 | 211  | 
|
| 59253 | 212  | 
def left_click()  | 
| 59218 | 213  | 
      {
 | 
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
214  | 
        (find_visible_node(c), m) match {
 | 
| 59253 | 215  | 
case (Some(node), Key.Modifier.Control) => visualizer.Selection.add(node)  | 
216  | 
case (None, Key.Modifier.Control) =>  | 
|
| 50470 | 217  | 
|
| 59253 | 218  | 
case (Some(node), Key.Modifier.Shift) => visualizer.Selection.add(node)  | 
219  | 
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
 | 
220  | 
|
| 59253 | 221  | 
case (Some(node), _) =>  | 
222  | 
visualizer.Selection.clear()  | 
|
223  | 
visualizer.Selection.add(node)  | 
|
224  | 
case (None, _) =>  | 
|
225  | 
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
 | 
226  | 
}  | 
| 50470 | 227  | 
}  | 
| 
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  | 
def right_click()  | 
| 59218 | 230  | 
      {
 | 
| 
59259
 
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
 
wenzelm 
parents: 
59255 
diff
changeset
 | 
231  | 
val menu = Popups(panel, find_visible_node(c), visualizer.Selection.get())  | 
| 59253 | 232  | 
menu.show(panel.peer, at.x, at.y)  | 
233  | 
}  | 
|
234  | 
||
235  | 
      if (clicks < 2) {
 | 
|
236  | 
if (SwingUtilities.isRightMouseButton(e.peer)) right_click()  | 
|
237  | 
else left_click()  | 
|
238  | 
}  | 
|
239  | 
}  | 
|
| 
49557
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
240  | 
|
| 59262 | 241  | 
def drag(info: (Point, List[Graph_Display.Node], List[(Graph_Display.Edge, Int)]), to: Point)  | 
| 59253 | 242  | 
    {
 | 
| 59262 | 243  | 
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
 | 
244  | 
|
| 59253 | 245  | 
val s = Transform.scale_discrete  | 
246  | 
val (dx, dy) = (to.x - from.x, to.y - from.y)  | 
|
247  | 
      (p, d) match {
 | 
|
248  | 
case (Nil, Nil) =>  | 
|
249  | 
val r = panel.peer.getViewport.getViewRect  | 
|
250  | 
r.translate(-dx, -dy)  | 
|
| 50470 | 251  | 
|
| 59253 | 252  | 
paint_panel.peer.scrollRectToVisible(r)  | 
| 50470 | 253  | 
|
| 59253 | 254  | 
case (Nil, ds) =>  | 
| 59262 | 255  | 
ds.foreach(d => visualizer.Coordinates.translate_dummy(d, dx / s, dy / s))  | 
| 59253 | 256  | 
|
257  | 
case (ls, _) =>  | 
|
| 59262 | 258  | 
ls.foreach(l => visualizer.Coordinates.translate_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
 | 
259  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
260  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
261  | 
}  | 
| 
 
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
 
Markus Kaiser <markus.kaiser@in.tum.de> 
parents:  
diff
changeset
 | 
262  | 
}  |