8 |
8 |
9 |
9 |
10 import isabelle._ |
10 import isabelle._ |
11 |
11 |
12 import java.awt.{Color, Point, BorderLayout, Window, Dimension} |
12 import java.awt.{Color, Point, BorderLayout, Window, Dimension} |
13 import java.awt.event.{ActionListener, ActionEvent, KeyEvent, WindowEvent, WindowAdapter} |
13 import java.awt.event.{WindowEvent, WindowAdapter} |
14 import javax.swing.{SwingUtilities, JDialog, JPanel, JComponent, KeyStroke} |
14 import javax.swing.{SwingUtilities, JDialog, JPanel, JComponent} |
15 import javax.swing.border.LineBorder |
15 import javax.swing.border.LineBorder |
16 |
16 |
17 import scala.swing.{FlowPanel, Label} |
17 import scala.swing.{FlowPanel, Label} |
18 import scala.swing.event.MouseClicked |
18 import scala.swing.event.MouseClicked |
19 |
19 |
35 Swing_Thread.require() |
35 Swing_Thread.require() |
36 |
36 |
37 |
37 |
38 window.setUndecorated(true) |
38 window.setUndecorated(true) |
39 window.setFocusableWindowState(true) |
39 window.setFocusableWindowState(true) |
40 window.setAutoRequestFocus(true) |
|
41 |
40 |
42 window.addWindowFocusListener(new WindowAdapter { |
41 window.addWindowFocusListener(new WindowAdapter { |
43 override def windowLostFocus(e: WindowEvent) { |
42 override def windowLostFocus(e: WindowEvent) { |
44 if (!Window.getWindows.exists(w => |
43 if (!Window.getWindows.exists(w => |
45 w.isDisplayable && JEdit_Lib.ancestors(w).exists(_ == window))) |
44 w.isDisplayable && JEdit_Lib.ancestors(w).exists(_ == window))) |
46 window.dispose() |
45 window.dispose() |
47 } |
46 } |
48 }) |
47 }) |
49 |
48 |
50 private val action_listener = new ActionListener { |
|
51 def actionPerformed(e: ActionEvent) { |
|
52 e.getActionCommand match { |
|
53 case "close_all" => |
|
54 Window.getWindows foreach { |
|
55 case c: Pretty_Tooltip => c.dispose |
|
56 case _ => |
|
57 } |
|
58 case _ => |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 window.setContentPane(new JPanel(new BorderLayout) { |
49 window.setContentPane(new JPanel(new BorderLayout) { |
64 setBackground(rendering.tooltip_color) |
50 setBackground(rendering.tooltip_color) |
65 registerKeyboardAction(action_listener, "close_all", |
|
66 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED) |
|
67 |
|
68 override def getFocusTraversalKeysEnabled(): Boolean = false |
51 override def getFocusTraversalKeysEnabled(): Boolean = false |
69 }) |
52 }) |
70 window.getRootPane.setBorder(new LineBorder(Color.BLACK)) |
53 window.getRootPane.setBorder(new LineBorder(Color.BLACK)) |
71 |
54 |
72 |
55 |
74 |
57 |
75 val pretty_text_area = new Pretty_Text_Area(view, Some(rendering.tooltip_color)) |
58 val pretty_text_area = new Pretty_Text_Area(view, Some(rendering.tooltip_color)) |
76 pretty_text_area.resize(Rendering.font_family(), |
59 pretty_text_area.resize(Rendering.font_family(), |
77 Rendering.font_size("jedit_tooltip_font_scale").round) |
60 Rendering.font_size("jedit_tooltip_font_scale").round) |
78 pretty_text_area.update(rendering.snapshot, results, body) |
61 pretty_text_area.update(rendering.snapshot, results, body) |
79 |
|
80 pretty_text_area.registerKeyboardAction(action_listener, "close_all", |
|
81 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED) |
|
82 |
62 |
83 window.add(pretty_text_area) |
63 window.add(pretty_text_area) |
84 |
64 |
85 |
65 |
86 /* controls */ |
66 /* controls */ |
134 val y = screen_point.y min (screen_bounds.y + screen_bounds.height - window.getHeight) |
114 val y = screen_point.y min (screen_bounds.y + screen_bounds.height - window.getHeight) |
135 window.setLocation(x, y) |
115 window.setLocation(x, y) |
136 } |
116 } |
137 |
117 |
138 window.setVisible(true) |
118 window.setVisible(true) |
|
119 pretty_text_area.requestFocus |
139 pretty_text_area.refresh() |
120 pretty_text_area.refresh() |
140 } |
121 } |
141 |
122 |