author | wenzelm |
Sat, 19 Apr 2014 19:03:32 +0200 | |
changeset 56622 | 891d1b8b64fb |
parent 56611 | eb088da48f86 |
child 56662 | f373fb77e0a4 |
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 |
{ |
|
39 |
Swing_Thread.require() |
|
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 |
{ |
58 |
Swing_Thread.require() |
|
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 |
}) |
|
96 |
text_area |
|
97 |
} |
|
49247 | 98 |
component.load() |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56611
diff
changeset
|
99 |
component.tooltip = GUI.tooltip_lines(opt.print_default) |
49246 | 100 |
component |
101 |
} |
|
49270 | 102 |
|
103 |
def make_components(predefined: List[Option_Component], filter: String => Boolean) |
|
104 |
: List[(String, List[Option_Component])] = |
|
105 |
{ |
|
106 |
def mk_component(opt: Options.Opt): List[Option_Component] = |
|
107 |
predefined.find(opt.name == _.name) match { |
|
108 |
case Some(c) => List(c) |
|
109 |
case None => if (filter(opt.name)) List(make_component(opt)) else Nil |
|
110 |
} |
|
111 |
value.sections.sortBy(_._1).map( |
|
112 |
{ case (a, opts) => (a, opts.sortBy(_.title("jedit")).flatMap(mk_component _)) }) |
|
113 |
.filterNot(_._2.isEmpty) |
|
114 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
115 |
} |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
116 |