27987
|
1 |
/* Title: lib/jedit/plugin/isabelle_dock.scala
|
|
2 |
ID: $Id$
|
|
3 |
Author: Makarius
|
|
4 |
|
|
5 |
Dockable window for Isabelle process control.
|
|
6 |
*/
|
|
7 |
|
|
8 |
package isabelle.jedit
|
|
9 |
|
|
10 |
import org.gjt.sp.jedit.View
|
|
11 |
import org.gjt.sp.jedit.gui.DefaultFocusComponent
|
|
12 |
import org.gjt.sp.jedit.gui.DockableWindowManager
|
|
13 |
import org.gjt.sp.jedit.gui.RolloverButton
|
|
14 |
import org.gjt.sp.jedit.gui.HistoryTextField
|
|
15 |
import org.gjt.sp.jedit.GUIUtilities
|
|
16 |
|
|
17 |
import java.awt.Color
|
|
18 |
import java.awt.Insets
|
|
19 |
import java.awt.BorderLayout
|
|
20 |
import java.awt.Dimension
|
|
21 |
import java.awt.event.ActionListener
|
|
22 |
import java.awt.event.ActionEvent
|
|
23 |
import javax.swing.BoxLayout
|
|
24 |
import javax.swing.JPanel
|
|
25 |
import javax.swing.JScrollPane
|
|
26 |
import javax.swing.JTextPane
|
|
27 |
import javax.swing.text.{StyledDocument, StyleConstants}
|
|
28 |
import javax.swing.SwingUtilities
|
|
29 |
import javax.swing.Icon
|
|
30 |
import javax.swing.Box
|
|
31 |
import javax.swing.JTextField
|
|
32 |
import javax.swing.JComboBox
|
|
33 |
import javax.swing.DefaultComboBoxModel
|
|
34 |
|
|
35 |
|
|
36 |
class IsabelleDock(view: View, position: String)
|
|
37 |
extends JPanel(new BorderLayout) with DefaultFocusComponent
|
|
38 |
{
|
|
39 |
private val text = new HistoryTextField("isabelle", false, true)
|
27988
|
40 |
private val logic_combo = new JComboBox
|
27987
|
41 |
|
|
42 |
{
|
|
43 |
// output pane
|
|
44 |
val pane = new JTextPane
|
|
45 |
pane.setEditable(false)
|
|
46 |
add(BorderLayout.CENTER, new JScrollPane(pane))
|
|
47 |
if (position == DockableWindowManager.FLOATING)
|
|
48 |
setPreferredSize(new Dimension(1000, 500))
|
|
49 |
|
|
50 |
val doc = pane.getDocument.asInstanceOf[StyledDocument]
|
|
51 |
|
27988
|
52 |
def make_style(name: String, bg: Boolean, color: Color) = {
|
27987
|
53 |
val style = doc.addStyle(name, null)
|
|
54 |
if (bg) StyleConstants.setBackground(style, color)
|
|
55 |
else StyleConstants.setForeground(style, color)
|
|
56 |
style
|
|
57 |
}
|
27988
|
58 |
val raw_style = make_style("raw", false, Color.GRAY)
|
|
59 |
val info_style = make_style("info", true, new Color(160, 255, 160))
|
|
60 |
val warning_style = make_style("warning", true, new Color(255, 255, 160))
|
|
61 |
val error_style = make_style("error", true, new Color(255, 160, 160))
|
27987
|
62 |
|
27988
|
63 |
IsabellePlugin.add_permanent_consumer (result =>
|
27987
|
64 |
if (result != null && !result.is_system) {
|
|
65 |
SwingUtilities.invokeLater(new Runnable {
|
|
66 |
def run = {
|
|
67 |
val logic = IsabellePlugin.isabelle.session
|
27988
|
68 |
logic_combo.setModel(new DefaultComboBoxModel(Array(logic).asInstanceOf[Array[AnyRef]]))
|
|
69 |
logic_combo.setPrototypeDisplayValue("AAAA") // FIXME ??
|
27987
|
70 |
|
|
71 |
val doc = pane.getDocument.asInstanceOf[StyledDocument]
|
|
72 |
val style = result.kind match {
|
27988
|
73 |
case IsabelleProcess.Kind.WARNING => warning_style
|
|
74 |
case IsabelleProcess.Kind.ERROR => error_style
|
|
75 |
case IsabelleProcess.Kind.TRACING => info_style
|
|
76 |
case _ => if (result.is_raw) raw_style else null
|
27987
|
77 |
}
|
|
78 |
doc.insertString(doc.getLength, IsabellePlugin.result_content(result), style)
|
|
79 |
if (!result.is_raw) doc.insertString(doc.getLength, "\n", style)
|
|
80 |
pane.setCaretPosition(doc.getLength)
|
|
81 |
}
|
|
82 |
})
|
|
83 |
})
|
|
84 |
|
|
85 |
|
|
86 |
// control box
|
|
87 |
val box = new Box(BoxLayout.X_AXIS)
|
|
88 |
add(BorderLayout.SOUTH, box)
|
|
89 |
|
|
90 |
|
|
91 |
// logic combo
|
27988
|
92 |
logic_combo.setToolTipText("Isabelle logics")
|
|
93 |
logic_combo.setRequestFocusEnabled(false)
|
|
94 |
logic_combo.setModel(new DefaultComboBoxModel(Array("default").asInstanceOf[Array[AnyRef]]))
|
|
95 |
box.add(logic_combo)
|
27987
|
96 |
|
|
97 |
|
|
98 |
// mode combo
|
27988
|
99 |
val mode_Isar = "Isar"
|
|
100 |
val mode_ML = "ML"
|
|
101 |
val modes = Array(mode_Isar, mode_ML)
|
|
102 |
var mode = mode_Isar
|
27987
|
103 |
|
27988
|
104 |
val mode_combo = new JComboBox
|
|
105 |
mode_combo.setToolTipText("Toplevel mode")
|
|
106 |
mode_combo.setRequestFocusEnabled(false)
|
|
107 |
mode_combo.setModel(new DefaultComboBoxModel(modes.asInstanceOf[Array[AnyRef]]))
|
|
108 |
mode_combo.setPrototypeDisplayValue("AAAA")
|
|
109 |
mode_combo.addActionListener(new ActionListener {
|
27987
|
110 |
def actionPerformed(evt: ActionEvent): Unit = {
|
27988
|
111 |
mode = mode_combo.getSelectedItem.asInstanceOf[String]
|
27987
|
112 |
}
|
|
113 |
})
|
27988
|
114 |
box.add(mode_combo)
|
27987
|
115 |
|
|
116 |
|
|
117 |
// input field
|
|
118 |
text.setToolTipText("Command line")
|
|
119 |
text.addActionListener(new ActionListener {
|
|
120 |
def actionPerformed(evt: ActionEvent): Unit = {
|
28006
|
121 |
val command = IsabellePlugin.symbols.encode(text.getText)
|
27987
|
122 |
if (command.length > 0) {
|
27988
|
123 |
if (mode == mode_Isar)
|
27987
|
124 |
IsabellePlugin.isabelle.command(command)
|
27988
|
125 |
else if (mode == mode_ML)
|
27987
|
126 |
IsabellePlugin.isabelle.ML(command)
|
|
127 |
text.setText("")
|
|
128 |
}
|
|
129 |
}
|
|
130 |
})
|
|
131 |
box.add(text)
|
|
132 |
|
|
133 |
|
|
134 |
// buttons
|
27996
|
135 |
def icon_button(icon: String, tip: String, action: => Unit) = {
|
27987
|
136 |
val button = new RolloverButton(GUIUtilities.loadIcon(icon))
|
|
137 |
button.setToolTipText(tip)
|
|
138 |
button.setMargin(new Insets(0,0,0,0))
|
|
139 |
button.setRequestFocusEnabled(false)
|
|
140 |
button.addActionListener(new ActionListener {
|
|
141 |
def actionPerformed(evt: ActionEvent): Unit = action
|
|
142 |
})
|
|
143 |
box.add(button)
|
|
144 |
}
|
|
145 |
|
27996
|
146 |
icon_button("Cancel.png", "Stop", IsabellePlugin.isabelle.interrupt)
|
|
147 |
icon_button("Clear.png", "Clear", pane.setText(""))
|
27987
|
148 |
}
|
|
149 |
|
|
150 |
def focusOnDefaultComponent: Unit = text.requestFocus
|
|
151 |
}
|