src/Tools/jEdit/src/jedit/output_dockable.scala
author wenzelm
Fri, 21 May 2010 12:59:44 +0200
changeset 37037 35d45feccbc6
parent 37036 49559c4e85f9
child 37039 d01da9438170
permissions -rw-r--r--
added some tooltips;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     1
/*  Title:      Tools/jEdit/src/jedit/output_dockable.scala
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     2
    Author:     Makarius
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     3
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     4
Dockable window with result message output.
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     5
*/
34408
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     6
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     8
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
     9
36015
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    10
import isabelle._
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    11
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    12
import scala.actors.Actor._
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    13
37017
cf6625012282 try CheckBox instead of ToggleButton, which is visually confusing without window focus, e.g. in a floating instance (problem of MacOS look-and-feel);
wenzelm
parents: 37014
diff changeset
    14
import scala.swing.{FlowPanel, Button, CheckBox}
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    15
import scala.swing.event.ButtonClicked
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    16
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    17
import javax.swing.JPanel
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    18
import java.awt.{BorderLayout, Dimension}
37014
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
    19
import java.awt.event.{ComponentEvent, ComponentAdapter}
34748
a2ed621f5f52 reduced logging;
wenzelm
parents: 34747
diff changeset
    20
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    21
import org.gjt.sp.jedit.View
34424
c880492754d0 setPreferredSize for floating dockables;
wenzelm
parents: 34408
diff changeset
    22
import org.gjt.sp.jedit.gui.DockableWindowManager
34745
83b553bd3fa3 basic setup for Cobra HTML renderer;
wenzelm
parents: 34669
diff changeset
    23
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    24
34765
63ba7f0931e2 generic HTML_Panel -- specific Results_Dockable;
wenzelm
parents: 34760
diff changeset
    25
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34789
diff changeset
    26
class Output_Dockable(view: View, position: String) extends JPanel(new BorderLayout)
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    27
{
34424
c880492754d0 setPreferredSize for floating dockables;
wenzelm
parents: 34408
diff changeset
    28
  if (position == DockableWindowManager.FLOATING)
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    29
    setPreferredSize(new Dimension(500, 250))
34771
b63a88e2d75a misc tuning;
wenzelm
parents: 34769
diff changeset
    30
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    31
  val controls = new FlowPanel(FlowPanel.Alignment.Right)()
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    32
  add(controls.peer, BorderLayout.NORTH)
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    33
37036
49559c4e85f9 HTML_Panel.handler as overridable method;
wenzelm
parents: 37033
diff changeset
    34
  val html_panel = new HTML_Panel(Isabelle.system, scala.math.round(Isabelle.font_size()))
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    35
  add(html_panel, BorderLayout.CENTER)
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    36
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    37
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    38
  /* controls */
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    39
36989
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    40
  private case class Render(body: List[XML.Tree])
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    41
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    42
  private def handle_update()
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    43
  {
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    44
    Swing_Thread.now {
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    45
      Document_Model(view.getBuffer) match {
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    46
        case Some(model) =>
36989
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    47
          val document = model.recent_document
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    48
          document.command_at(view.getTextArea.getCaretPosition) match {
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    49
            case Some((cmd, _)) =>
36990
449628c148cf explicit Command.Status.UNDEFINED -- avoid fragile/cumbersome treatment of Option[State];
wenzelm
parents: 36989
diff changeset
    50
              output_actor ! Render(document.current_state(cmd).results)
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    51
            case None =>
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    52
          }
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    53
        case None =>
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    54
      }
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    55
    }
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    56
  }
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    57
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    58
  private var zoom_factor = 100
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    59
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    60
  private def handle_resize() =
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    61
    Swing_Thread.now {
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    62
      html_panel.resize(scala.math.round(Isabelle.font_size() * zoom_factor / 100))
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    63
    }
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    64
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    65
  private val zoom = Library.zoom_box(factor => { zoom_factor = factor; handle_resize() })
37037
35d45feccbc6 added some tooltips;
wenzelm
parents: 37036
diff changeset
    66
  zoom.tooltip = "Zoom factor for basic font size"
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    67
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    68
  private val update = new Button("Update") {
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    69
    reactions += { case ButtonClicked(_) => handle_update() }
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    70
  }
37037
35d45feccbc6 added some tooltips;
wenzelm
parents: 37036
diff changeset
    71
  update.tooltip = "Update display according to state of command at caret position"
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    72
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    73
  private val follow = new CheckBox("Follow")
37037
35d45feccbc6 added some tooltips;
wenzelm
parents: 37036
diff changeset
    74
  follow.tooltip = "Indicate automatic update according to caret movement or state changes"
36989
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    75
  follow.selected = true
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    76
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    77
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    78
  /* actor wiring */
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    79
34773
bb5d68f7fd5e renamed "raw output" to "protocol";
wenzelm
parents: 34771
diff changeset
    80
  private val output_actor = actor {
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    81
    loop {
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    82
      react {
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
    83
        case Session.Global_Settings => handle_resize()
36989
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    84
        case Render(body) => html_panel.render(body)
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    85
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    86
        case cmd: Command =>
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    87
          Swing_Thread.now {
36989
aaa7cac3e54a inverted "Freeze" to "Follow", which is the default;
wenzelm
parents: 36988
diff changeset
    88
            if (follow.selected) Document_Model(view.getBuffer) else None
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
    89
          } match {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
    90
            case None =>
36990
449628c148cf explicit Command.Status.UNDEFINED -- avoid fragile/cumbersome treatment of Option[State];
wenzelm
parents: 36989
diff changeset
    91
            case Some(model) => html_panel.render(model.recent_document.current_state(cmd).results)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
    92
          }
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34789
diff changeset
    93
34773
bb5d68f7fd5e renamed "raw output" to "protocol";
wenzelm
parents: 34771
diff changeset
    94
        case bad => System.err.println("output_actor: ignoring bad message " + bad)
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    95
      }
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    96
    }
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
    97
  }
34428
d69fd18f37f9 basic setup of anti-aliasing, according to jEdit property;
wenzelm
parents: 34424
diff changeset
    98
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
    99
  override def addNotify()
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
   100
  {
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
   101
    super.addNotify()
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
   102
    Isabelle.session.results += output_actor
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34789
diff changeset
   103
    Isabelle.session.global_settings += output_actor
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
   104
  }
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
   105
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
   106
  override def removeNotify()
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
   107
  {
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34775
diff changeset
   108
    Isabelle.session.results -= output_actor
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34789
diff changeset
   109
    Isabelle.session.global_settings -= output_actor
34768
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
   110
    super.removeNotify()
d8d321af1478 back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents: 34765
diff changeset
   111
  }
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
   112
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
   113
37014
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   114
  /* resize */
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   115
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   116
  addComponentListener(new ComponentAdapter {
37033
0e4073f19825 component resize: full handle_resize;
wenzelm
parents: 37019
diff changeset
   117
    val delay = Swing_Thread.delay_last(500) { handle_resize() }
37014
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   118
    override def componentResized(e: ComponentEvent) { delay() }
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   119
  })
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   120
1af0f718ffdc handle component resize for output / HTML panel;
wenzelm
parents: 36993
diff changeset
   121
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
   122
  /* init controls */
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
   123
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 37017
diff changeset
   124
  controls.contents ++= List(zoom, update, follow)
36988
fd641bc85222 basic controls to freeze/update prover results;
wenzelm
parents: 36817
diff changeset
   125
  handle_update()
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   126
}