author | wenzelm |
Tue, 21 Oct 2014 17:49:51 +0200 | |
changeset 58749 | 83b0f633190e |
parent 57612 | 990ffb84489b |
child 60843 | 9980f3bcdea2 |
permissions | -rw-r--r-- |
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/jedit_options.scala |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
3 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
4 |
Options for Isabelle/jEdit. |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
5 |
*/ |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
6 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
8 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
9 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
11 |
|
49356 | 12 |
import java.awt.Color |
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
13 |
import javax.swing.{InputVerifier, JComponent, UIManager} |
49246 | 14 |
import javax.swing.text.JTextComponent |
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
15 |
|
49246 | 16 |
import scala.swing.{Component, CheckBox, TextArea} |
17 |
||
49296 | 18 |
import org.gjt.sp.jedit.gui.ColorWellButton |
19 |
||
49246 | 20 |
|
21 |
trait Option_Component extends Component |
|
22 |
{ |
|
23 |
val title: String |
|
49247 | 24 |
def load(): Unit |
49246 | 25 |
def save(): Unit |
26 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
27 |
|
52065
78f2475aa126
explicit notion of public options, which are shown in the editor options dialog;
wenzelm
parents:
51616
diff
changeset
|
28 |
object JEdit_Options |
78f2475aa126
explicit notion of public options, which are shown in the editor options dialog;
wenzelm
parents:
51616
diff
changeset
|
29 |
{ |
78f2475aa126
explicit notion of public options, which are shown in the editor options dialog;
wenzelm
parents:
51616
diff
changeset
|
30 |
val RENDERING_SECTION = "Rendering of Document Content" |
78f2475aa126
explicit notion of public options, which are shown in the editor options dialog;
wenzelm
parents:
51616
diff
changeset
|
31 |
} |
78f2475aa126
explicit notion of public options, which are shown in the editor options dialog;
wenzelm
parents:
51616
diff
changeset
|
32 |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
33 |
class JEdit_Options extends Options_Variable |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
34 |
{ |
49356 | 35 |
def color_value(s: String): Color = Color_Value(string(s)) |
36 |
||
49296 | 37 |
def make_color_component(opt: Options.Opt): Option_Component = |
38 |
{ |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56752
diff
changeset
|
39 |
GUI_Thread.require {} |
49296 | 40 |
|
41 |
val opt_name = opt.name |
|
42 |
val opt_title = opt.title("jedit") |
|
43 |
||
44 |
val button = new ColorWellButton(Color_Value(opt.value)) |
|
45 |
val component = new Component with Option_Component { |
|
46 |
override lazy val peer = button |
|
47 |
name = opt_name |
|
48 |
val title = opt_title |
|
49 |
def load = button.setSelectedColor(Color_Value(string(opt_name))) |
|
50 |
def save = string(opt_name) = Color_Value.print(button.getSelectedColor) |
|
51 |
} |
|
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56611
diff
changeset
|
52 |
component.tooltip = GUI.tooltip_lines(opt.print_default) |
49296 | 53 |
component |
54 |
} |
|
55 |
||
49270 | 56 |
def make_component(opt: Options.Opt): Option_Component = |
49246 | 57 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56752
diff
changeset
|
58 |
GUI_Thread.require {} |
49246 | 59 |
|
49270 | 60 |
val opt_name = opt.name |
61 |
val opt_title = opt.title("jedit") |
|
49246 | 62 |
|
63 |
val component = |
|
64 |
if (opt.typ == Options.Bool) |
|
65 |
new CheckBox with Option_Component { |
|
49270 | 66 |
name = opt_name |
49246 | 67 |
val title = opt_title |
49247 | 68 |
def load = selected = bool(opt_name) |
49246 | 69 |
def save = bool(opt_name) = selected |
70 |
} |
|
71 |
else { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
72 |
val default_font = UIManager.getFont("TextField.font") |
49246 | 73 |
val text_area = |
74 |
new TextArea with Option_Component { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
75 |
if (default_font != null) font = default_font |
49270 | 76 |
name = opt_name |
49246 | 77 |
val title = opt_title |
49247 | 78 |
def load = text = value.check_name(opt_name).value |
49317 | 79 |
def save = |
80 |
try { update(value + (opt_name, text)) } |
|
81 |
catch { |
|
82 |
case ERROR(msg) => |
|
51616 | 83 |
GUI.error_dialog(this.peer, "Failed to update options", |
84 |
GUI.scrollable_text(msg)) |
|
49317 | 85 |
} |
49246 | 86 |
} |
87 |
text_area.peer.setInputVerifier(new InputVerifier { |
|
88 |
def verify(jcomponent: JComponent): Boolean = |
|
89 |
jcomponent match { |
|
90 |
case text: JTextComponent => |
|
91 |
try { value + (opt_name, text.getText); true } |
|
92 |
catch { case ERROR(_) => false } |
|
93 |
case _ => true |
|
94 |
} |
|
95 |
}) |
|
56752
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56662
diff
changeset
|
96 |
GUI.plain_focus_traversal(text_area.peer) |
49246 | 97 |
text_area |
98 |
} |
|
49247 | 99 |
component.load() |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56611
diff
changeset
|
100 |
component.tooltip = GUI.tooltip_lines(opt.print_default) |
49246 | 101 |
component |
102 |
} |
|
49270 | 103 |
|
104 |
def make_components(predefined: List[Option_Component], filter: String => Boolean) |
|
105 |
: List[(String, List[Option_Component])] = |
|
106 |
{ |
|
107 |
def mk_component(opt: Options.Opt): List[Option_Component] = |
|
108 |
predefined.find(opt.name == _.name) match { |
|
109 |
case Some(c) => List(c) |
|
110 |
case None => if (filter(opt.name)) List(make_component(opt)) else Nil |
|
111 |
} |
|
112 |
value.sections.sortBy(_._1).map( |
|
113 |
{ case (a, opts) => (a, opts.sortBy(_.title("jedit")).flatMap(mk_component _)) }) |
|
114 |
.filterNot(_._2.isEmpty) |
|
115 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
116 |
} |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
117 |