src/Tools/jEdit/src/output_area.scala
author wenzelm
Thu, 14 Nov 2024 10:50:49 +0100
changeset 81443 7f3416f35b5d
parent 81387 c677755779f5
child 81460 6ea0055fa42d
permissions -rw-r--r--
more careful isConsumed() / consume() for key and mouse events;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81336
40af19b10f8a clarified modules;
wenzelm
parents: 81329
diff changeset
     1
/*  Title:      Tools/jEdit/src/output_area.scala
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     3
81336
40af19b10f8a clarified modules;
wenzelm
parents: 81329
diff changeset
     4
GUI component for structured output.
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     5
*/
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     6
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     8
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     9
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    10
import isabelle._
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    11
81318
f870d42c4946 tuned imports;
wenzelm
parents: 81316
diff changeset
    12
import java.awt.Dimension
f870d42c4946 tuned imports;
wenzelm
parents: 81316
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter, FocusAdapter, FocusEvent,
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    14
  MouseEvent, MouseAdapter}
81323
33fbf90fbc1d clarified signature: more explicit types;
wenzelm
parents: 81320
diff changeset
    15
import javax.swing.JComponent
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    16
81318
f870d42c4946 tuned imports;
wenzelm
parents: 81316
diff changeset
    17
import scala.swing.{Component, ScrollPane, SplitPane, Orientation}
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    18
import scala.swing.event.ButtonClicked
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    19
81318
f870d42c4946 tuned imports;
wenzelm
parents: 81316
diff changeset
    20
import org.gjt.sp.jedit.View
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    21
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    22
81378
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    23
class Output_Area(view: View,
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    24
  root_name: String = "Overview",
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    25
  split: Boolean = false
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    26
) {
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    27
  GUI_Thread.require {}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    28
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    29
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    30
  /* tree view */
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    31
81325
458e9e3b356e clarified signature;
wenzelm
parents: 81323
diff changeset
    32
  val tree: Tree_View =
81329
1775fdc7274e clarified signature;
wenzelm
parents: 81325
diff changeset
    33
    new Tree_View(root = Tree_View.Node(root_name), single_selection_mode = true)
81310
e3b0c7aec1ed clarified signature;
wenzelm
parents: 81309
diff changeset
    34
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    35
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    36
  /* text area */
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    37
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    38
  val pretty_text_area: Pretty_Text_Area = new Pretty_Text_Area(view)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    39
81387
c677755779f5 more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents: 81378
diff changeset
    40
  def handle_resize(): Unit = pretty_text_area.zoom()
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    41
  def handle_update(): Unit = ()
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    42
81312
a00d4d50b851 clarified signature;
wenzelm
parents: 81310
diff changeset
    43
  lazy val delay_resize: Delay =
a00d4d50b851 clarified signature;
wenzelm
parents: 81310
diff changeset
    44
    Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() }
a00d4d50b851 clarified signature;
wenzelm
parents: 81310
diff changeset
    45
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    46
81378
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    47
  /* main GUI components */
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    48
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    49
  lazy val tree_pane: Component = {
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    50
    val scroll_pane: ScrollPane = new ScrollPane(Component.wrap(tree))
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    51
    scroll_pane.horizontalScrollBarPolicy = ScrollPane.BarPolicy.Always
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    52
    scroll_pane.verticalScrollBarPolicy = ScrollPane.BarPolicy.Always
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    53
    scroll_pane.minimumSize = new Dimension(200, 100)
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    54
    scroll_pane
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    55
  }
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    56
81378
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    57
  lazy val text_pane: Component = Component.wrap(pretty_text_area)
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    58
81378
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    59
  lazy val main_pane: Component =
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    60
    if (split) {
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    61
      new SplitPane(Orientation.Vertical) {
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    62
        oneTouchExpandable = true
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    63
        leftComponent = tree_pane
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    64
        rightComponent = text_pane
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    65
      }
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    66
    }
969280db8ca5 clarified signature;
wenzelm
parents: 81376
diff changeset
    67
    else text_pane
81314
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    68
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    69
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    70
  /* GUI component */
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    71
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    72
  def handle_focus(): Unit = ()
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    73
81316
wenzelm
parents: 81315
diff changeset
    74
  def init_gui(parent: JComponent): Unit = {
wenzelm
parents: 81315
diff changeset
    75
    parent.addComponentListener(
81314
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    76
      new ComponentAdapter {
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    77
        override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    78
        override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    79
      })
81316
wenzelm
parents: 81315
diff changeset
    80
    parent.addFocusListener(
81314
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    81
      new FocusAdapter {
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    82
        override def focusGained(e: FocusEvent): Unit = handle_focus()
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    83
      })
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    84
81315
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    85
    tree.addMouseListener(
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    86
      new MouseAdapter {
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    87
        override def mouseClicked(e: MouseEvent): Unit = {
81443
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    88
          if (!e.isConsumed()) {
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    89
            val click = tree.getPathForLocation(e.getX, e.getY)
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    90
            if (click != null && e.getClickCount == 1) {
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    91
              e.consume()
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    92
              handle_focus()
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    93
            }
7f3416f35b5d more careful isConsumed() / consume() for key and mouse events;
wenzelm
parents: 81387
diff changeset
    94
          }
81315
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    95
        }
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    96
      })
b796e59ec3ef clarified modules;
wenzelm
parents: 81314
diff changeset
    97
81316
wenzelm
parents: 81315
diff changeset
    98
    parent match {
81314
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
    99
      case dockable: Dockable => dockable.set_content(main_pane)
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
   100
      case _ =>
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
   101
    }
fad1278d0f5b clarified signature;
wenzelm
parents: 81313
diff changeset
   102
  }
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
   103
}