src/Tools/jEdit/src/tree_text_area.scala
author wenzelm
Sat, 02 Nov 2024 14:58:50 +0100
changeset 81309 ccdbe1b538fc
child 81310 e3b0c7aec1ed
permissions -rw-r--r--
clarified modules: more re-usable;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81309
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/tree_text_area.scala
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     3
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
     4
GUI component for tree view with pretty-printed text area.
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
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    12
import java.awt.{BorderLayout, Dimension}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent, FocusAdapter, FocusEvent,
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    14
  MouseEvent, MouseAdapter}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    15
import javax.swing.{JTree, JMenuItem}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    16
import javax.swing.tree.{DefaultMutableTreeNode, DefaultTreeModel, TreeSelectionModel}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    17
import javax.swing.event.{TreeSelectionEvent, TreeSelectionListener}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    18
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    19
import scala.collection.immutable.SortedMap
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    20
import scala.swing.{Button, Label, Component, ScrollPane, SplitPane, Orientation, BorderPanel}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    21
import scala.swing.event.ButtonClicked
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    22
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    23
import org.gjt.sp.jedit.{jEdit, View}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    24
import org.gjt.sp.jedit.menu.EnhancedMenuItem
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    25
import org.gjt.sp.jedit.textarea.JEditTextArea
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    26
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    27
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    28
class Tree_Text_Area(view: View, root_name: String = "Overview") {
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    29
  GUI_Thread.require {}
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    30
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    31
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    32
  /* tree view */
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    33
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    34
  val root: DefaultMutableTreeNode = new DefaultMutableTreeNode(root_name)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    35
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    36
  val tree: JTree = new JTree(root)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    37
  tree.setRowHeight(0)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    38
  tree.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    39
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    40
  def clear(): Unit = {
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    41
    tree.clearSelection()
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    42
    root.removeAllChildren()
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    43
  }
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    44
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    45
  def reload(): Unit =
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    46
    tree.getModel.asInstanceOf[DefaultTreeModel].reload(root)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    47
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    48
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    49
  /* text area */
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    50
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    51
  val pretty_text_area: Pretty_Text_Area = new Pretty_Text_Area(view)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    52
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    53
  def handle_resize(): Unit = ()
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    54
  def handle_update(): Unit = ()
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    55
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    56
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    57
  /* main pane */
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    58
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    59
  val tree_pane: ScrollPane = new ScrollPane(Component.wrap(tree))
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    60
  tree_pane.horizontalScrollBarPolicy = ScrollPane.BarPolicy.Always
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    61
  tree_pane.verticalScrollBarPolicy = ScrollPane.BarPolicy.Always
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    62
  tree_pane.minimumSize = new Dimension(200, 100)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    63
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    64
  val main_pane: SplitPane = new SplitPane(Orientation.Vertical) {
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    65
    oneTouchExpandable = true
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    66
    leftComponent = tree_pane
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    67
    rightComponent = Component.wrap(pretty_text_area)
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    68
  }
ccdbe1b538fc clarified modules: more re-usable;
wenzelm
parents:
diff changeset
    69
}