author | wenzelm |
Mon, 29 Dec 2008 21:01:55 +0100 | |
changeset 34458 | e2aa32bb73c0 |
parent 34456 | 14367c0715e8 |
child 34503 | 7d0726f19d04 |
permissions | -rw-r--r-- |
34408 | 1 |
/* |
34458
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34456
diff
changeset
|
2 |
* Information on command status left of scrollbar (with panel) |
34408 | 3 |
* |
4 |
* @author Fabian Immler, TU Munich |
|
5 |
*/ |
|
6 |
||
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
7 |
package isabelle.jedit |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
8 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
9 |
import isabelle.prover.Command |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
10 |
import isabelle.utils.Delay |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
11 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
12 |
import javax.swing._ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
13 |
import java.awt.event._ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
14 |
import java.awt._ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
15 |
import org.gjt.sp.jedit.gui.RolloverButton; |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
16 |
import org.gjt.sp.jedit.textarea.JEditTextArea; |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
17 |
import org.gjt.sp.jedit.buffer.JEditBuffer; |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
18 |
import org.gjt.sp.jedit._ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
19 |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
20 |
class PhaseOverviewPanel(prover : isabelle.prover.Prover) extends JPanel(new BorderLayout) { |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
21 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
22 |
private val WIDTH = 10 |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
23 |
private val HILITE_HEIGHT = 2 |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
24 |
var textarea : JEditTextArea = null |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
25 |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
26 |
val repaint_delay = new isabelle.utils.Delay(100, () => repaint()) |
34456 | 27 |
prover.command_info += (_ => repaint_delay.delay_or_ignore()) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
28 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
29 |
setRequestFocusEnabled(false); |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
30 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
31 |
addMouseListener(new MouseAdapter { |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
32 |
override def mousePressed(evt : MouseEvent) { |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
33 |
val line = yToLine(evt.getY) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
34 |
if(line >= 0 && line < textarea.getLineCount()) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
35 |
textarea.setCaretPosition(textarea.getLineStartOffset(line)) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
36 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
37 |
}) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
38 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
39 |
override def addNotify { |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
40 |
super.addNotify(); |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
41 |
ToolTipManager.sharedInstance.registerComponent(this); |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
42 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
43 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
44 |
override def removeNotify() |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
45 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
46 |
super.removeNotify |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
47 |
ToolTipManager.sharedInstance.unregisterComponent(this); |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
48 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
49 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
50 |
override def getToolTipText(evt : MouseEvent) : String = |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
51 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
52 |
val buffer = textarea.getBuffer |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
53 |
val lineCount = buffer.getLineCount |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
54 |
val line = yToLine(evt.getY()) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
55 |
if(line >= 0 && line < textarea.getLineCount) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
56 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
57 |
"TODO: Tooltip" |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
58 |
} else "" |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
59 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
60 |
|
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
61 |
private def paintCommand(command : Command, buffer : JEditBuffer, gfx : Graphics) { |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
62 |
val line1 = buffer.getLineOfOffset(command.start) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
63 |
val line2 = buffer.getLineOfOffset(command.stop - 1) + 1 |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
64 |
val y = lineToY(line1) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
65 |
val height = lineToY(line2) - y - 1 |
34458
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34456
diff
changeset
|
66 |
val (light, dark) = command.status match { |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34456
diff
changeset
|
67 |
case Command.Status.UNPROCESSED => (Color.yellow, new Color(128,128,0)) |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34456
diff
changeset
|
68 |
case Command.Status.FINISHED => (Color.green, new Color(0, 128, 0)) |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34456
diff
changeset
|
69 |
case Command.Status.FAILED => (Color.red, new Color(128,0,0)) |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
70 |
} |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
71 |
|
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
72 |
gfx.setColor(light) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
73 |
gfx.fillRect(0, y, getWidth - 1, 1 max height) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
74 |
if(height > 2){ |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
75 |
gfx.setColor(dark) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
76 |
gfx.drawRect(0, y, getWidth - 1, height) |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
77 |
} |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
78 |
|
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
79 |
} |
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
80 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
81 |
override def paintComponent(gfx : Graphics) { |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
82 |
super.paintComponent(gfx) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
83 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
84 |
val buffer = textarea.getBuffer |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
85 |
for(c <- prover.document.commands) |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34403
diff
changeset
|
86 |
paintCommand(c, buffer, gfx) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
87 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
88 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
89 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
90 |
override def getPreferredSize : Dimension = |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
91 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
92 |
new Dimension(10,0) |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
93 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
94 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
95 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
96 |
private def lineToY(line : Int) : Int = |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
97 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
98 |
(line * getHeight) / textarea.getBuffer.getLineCount |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
99 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
100 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
101 |
private def yToLine(y : Int) : Int = |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
102 |
{ |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
103 |
(y * textarea.getBuffer.getLineCount) / getHeight |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
104 |
} |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
105 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
106 |
} |