author | wenzelm |
Thu, 14 Nov 2024 10:50:49 +0100 | |
changeset 81443 | 7f3416f35b5d |
parent 81387 | c677755779f5 |
child 81460 | 6ea0055fa42d |
permissions | -rw-r--r-- |
81336 | 1 |
/* Title: Tools/jEdit/src/output_area.scala |
81309 | 2 |
Author: Makarius |
3 |
||
81336 | 4 |
GUI component for structured output. |
81309 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
81318 | 12 |
import java.awt.Dimension |
13 |
import java.awt.event.{ComponentEvent, ComponentAdapter, FocusAdapter, FocusEvent, |
|
81309 | 14 |
MouseEvent, MouseAdapter} |
81323 | 15 |
import javax.swing.JComponent |
81309 | 16 |
|
81318 | 17 |
import scala.swing.{Component, ScrollPane, SplitPane, Orientation} |
81309 | 18 |
import scala.swing.event.ButtonClicked |
19 |
||
81318 | 20 |
import org.gjt.sp.jedit.View |
81309 | 21 |
|
22 |
||
81378 | 23 |
class Output_Area(view: View, |
24 |
root_name: String = "Overview", |
|
25 |
split: Boolean = false |
|
26 |
) { |
|
81309 | 27 |
GUI_Thread.require {} |
28 |
||
29 |
||
30 |
/* tree view */ |
|
31 |
||
81325 | 32 |
val tree: Tree_View = |
81329 | 33 |
new Tree_View(root = Tree_View.Node(root_name), single_selection_mode = true) |
81310 | 34 |
|
81309 | 35 |
|
36 |
/* text area */ |
|
37 |
||
38 |
val pretty_text_area: Pretty_Text_Area = new Pretty_Text_Area(view) |
|
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 | 41 |
def handle_update(): Unit = () |
42 |
||
81312 | 43 |
lazy val delay_resize: Delay = |
44 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
|
45 |
||
81309 | 46 |
|
81378 | 47 |
/* main GUI components */ |
48 |
||
49 |
lazy val tree_pane: Component = { |
|
50 |
val scroll_pane: ScrollPane = new ScrollPane(Component.wrap(tree)) |
|
51 |
scroll_pane.horizontalScrollBarPolicy = ScrollPane.BarPolicy.Always |
|
52 |
scroll_pane.verticalScrollBarPolicy = ScrollPane.BarPolicy.Always |
|
53 |
scroll_pane.minimumSize = new Dimension(200, 100) |
|
54 |
scroll_pane |
|
55 |
} |
|
81309 | 56 |
|
81378 | 57 |
lazy val text_pane: Component = Component.wrap(pretty_text_area) |
81309 | 58 |
|
81378 | 59 |
lazy val main_pane: Component = |
60 |
if (split) { |
|
61 |
new SplitPane(Orientation.Vertical) { |
|
62 |
oneTouchExpandable = true |
|
63 |
leftComponent = tree_pane |
|
64 |
rightComponent = text_pane |
|
65 |
} |
|
66 |
} |
|
67 |
else text_pane |
|
81314 | 68 |
|
69 |
||
70 |
/* GUI component */ |
|
71 |
||
72 |
def handle_focus(): Unit = () |
|
73 |
||
81316 | 74 |
def init_gui(parent: JComponent): Unit = { |
75 |
parent.addComponentListener( |
|
81314 | 76 |
new ComponentAdapter { |
77 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
|
78 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
|
79 |
}) |
|
81316 | 80 |
parent.addFocusListener( |
81314 | 81 |
new FocusAdapter { |
82 |
override def focusGained(e: FocusEvent): Unit = handle_focus() |
|
83 |
}) |
|
84 |
||
81315 | 85 |
tree.addMouseListener( |
86 |
new MouseAdapter { |
|
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 | 95 |
} |
96 |
}) |
|
97 |
||
81316 | 98 |
parent match { |
81314 | 99 |
case dockable: Dockable => dockable.set_content(main_pane) |
100 |
case _ => |
|
101 |
} |
|
102 |
} |
|
81309 | 103 |
} |