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