author | wenzelm |
Tue, 11 Sep 2012 19:35:21 +0200 | |
changeset 49289 | 60424f123621 |
parent 49270 | e5d162d15867 |
child 49296 | 313369027391 |
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 |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
12 |
import javax.swing.{InputVerifier, JComponent, UIManager} |
49246 | 13 |
import javax.swing.text.JTextComponent |
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
14 |
|
49246 | 15 |
import scala.swing.{Component, CheckBox, TextArea} |
16 |
||
17 |
||
18 |
trait Option_Component extends Component |
|
19 |
{ |
|
20 |
val title: String |
|
49247 | 21 |
def load(): Unit |
49246 | 22 |
def save(): Unit |
23 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
24 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
25 |
class JEdit_Options extends Options_Variable |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
26 |
{ |
49270 | 27 |
def make_component(opt: Options.Opt): Option_Component = |
49246 | 28 |
{ |
29 |
Swing_Thread.require() |
|
30 |
||
49270 | 31 |
val opt_name = opt.name |
32 |
val opt_title = opt.title("jedit") |
|
49246 | 33 |
|
34 |
val component = |
|
35 |
if (opt.typ == Options.Bool) |
|
36 |
new CheckBox with Option_Component { |
|
49270 | 37 |
name = opt_name |
49246 | 38 |
val title = opt_title |
49247 | 39 |
def load = selected = bool(opt_name) |
49246 | 40 |
def save = bool(opt_name) = selected |
41 |
} |
|
42 |
else { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
43 |
val default_font = UIManager.getFont("TextField.font") |
49246 | 44 |
val text_area = |
45 |
new TextArea with Option_Component { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
46 |
if (default_font != null) font = default_font |
49270 | 47 |
name = opt_name |
49246 | 48 |
val title = opt_title |
49247 | 49 |
def load = text = value.check_name(opt_name).value |
49246 | 50 |
def save = update(value + (opt_name, text)) |
51 |
} |
|
52 |
text_area.peer.setInputVerifier(new InputVerifier { |
|
53 |
def verify(jcomponent: JComponent): Boolean = |
|
54 |
jcomponent match { |
|
55 |
case text: JTextComponent => |
|
56 |
try { value + (opt_name, text.getText); true } |
|
57 |
catch { case ERROR(_) => false } |
|
58 |
case _ => true |
|
59 |
} |
|
60 |
}) |
|
61 |
text_area |
|
62 |
} |
|
49247 | 63 |
component.load() |
49289 | 64 |
component.tooltip = Isabelle.tooltip(opt.print_default) |
49246 | 65 |
component |
66 |
} |
|
49270 | 67 |
|
68 |
def make_components(predefined: List[Option_Component], filter: String => Boolean) |
|
69 |
: List[(String, List[Option_Component])] = |
|
70 |
{ |
|
71 |
def mk_component(opt: Options.Opt): List[Option_Component] = |
|
72 |
predefined.find(opt.name == _.name) match { |
|
73 |
case Some(c) => List(c) |
|
74 |
case None => if (filter(opt.name)) List(make_component(opt)) else Nil |
|
75 |
} |
|
76 |
value.sections.sortBy(_._1).map( |
|
77 |
{ case (a, opts) => (a, opts.sortBy(_.title("jedit")).flatMap(mk_component _)) }) |
|
78 |
.filterNot(_._2.isEmpty) |
|
79 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
80 |
} |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
81 |