author | wenzelm |
Mon, 26 Nov 2012 10:37:05 +0100 | |
changeset 50210 | 747db833fbf7 |
parent 49701 | e2762f962042 |
child 51616 | 949e2cf02a3d |
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 |
|
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
28 |
class JEdit_Options extends Options_Variable |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
29 |
{ |
49356 | 30 |
def color_value(s: String): Color = Color_Value(string(s)) |
31 |
||
49296 | 32 |
def make_color_component(opt: Options.Opt): Option_Component = |
33 |
{ |
|
34 |
Swing_Thread.require() |
|
35 |
||
36 |
val opt_name = opt.name |
|
37 |
val opt_title = opt.title("jedit") |
|
38 |
||
39 |
val button = new ColorWellButton(Color_Value(opt.value)) |
|
40 |
val component = new Component with Option_Component { |
|
41 |
override lazy val peer = button |
|
42 |
name = opt_name |
|
43 |
val title = opt_title |
|
44 |
def load = button.setSelectedColor(Color_Value(string(opt_name))) |
|
45 |
def save = string(opt_name) = Color_Value.print(button.getSelectedColor) |
|
46 |
} |
|
49701 | 47 |
component.tooltip = opt.print_default |
49296 | 48 |
component |
49 |
} |
|
50 |
||
49270 | 51 |
def make_component(opt: Options.Opt): Option_Component = |
49246 | 52 |
{ |
53 |
Swing_Thread.require() |
|
54 |
||
49270 | 55 |
val opt_name = opt.name |
56 |
val opt_title = opt.title("jedit") |
|
49246 | 57 |
|
58 |
val component = |
|
59 |
if (opt.typ == Options.Bool) |
|
60 |
new CheckBox with Option_Component { |
|
49270 | 61 |
name = opt_name |
49246 | 62 |
val title = opt_title |
49247 | 63 |
def load = selected = bool(opt_name) |
49246 | 64 |
def save = bool(opt_name) = selected |
65 |
} |
|
66 |
else { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
67 |
val default_font = UIManager.getFont("TextField.font") |
49246 | 68 |
val text_area = |
69 |
new TextArea with Option_Component { |
|
49252
9e10481dd3c4
prefer global default font over IsabelleText of jEdit TextArea;
wenzelm
parents:
49248
diff
changeset
|
70 |
if (default_font != null) font = default_font |
49270 | 71 |
name = opt_name |
49246 | 72 |
val title = opt_title |
49247 | 73 |
def load = text = value.check_name(opt_name).value |
49317 | 74 |
def save = |
75 |
try { update(value + (opt_name, text)) } |
|
76 |
catch { |
|
77 |
case ERROR(msg) => |
|
78 |
Library.error_dialog(this.peer, "Failed to update options", |
|
79 |
Library.scrollable_text(msg)) |
|
80 |
} |
|
49246 | 81 |
} |
82 |
text_area.peer.setInputVerifier(new InputVerifier { |
|
83 |
def verify(jcomponent: JComponent): Boolean = |
|
84 |
jcomponent match { |
|
85 |
case text: JTextComponent => |
|
86 |
try { value + (opt_name, text.getText); true } |
|
87 |
catch { case ERROR(_) => false } |
|
88 |
case _ => true |
|
89 |
} |
|
90 |
}) |
|
91 |
text_area |
|
92 |
} |
|
49247 | 93 |
component.load() |
49701 | 94 |
component.tooltip = opt.print_default |
49246 | 95 |
component |
96 |
} |
|
49270 | 97 |
|
98 |
def make_components(predefined: List[Option_Component], filter: String => Boolean) |
|
99 |
: List[(String, List[Option_Component])] = |
|
100 |
{ |
|
101 |
def mk_component(opt: Options.Opt): List[Option_Component] = |
|
102 |
predefined.find(opt.name == _.name) match { |
|
103 |
case Some(c) => List(c) |
|
104 |
case None => if (filter(opt.name)) List(make_component(opt)) else Nil |
|
105 |
} |
|
106 |
value.sections.sortBy(_._1).map( |
|
107 |
{ case (a, opts) => (a, opts.sortBy(_.title("jedit")).flatMap(mk_component _)) }) |
|
108 |
.filterNot(_._2.isEmpty) |
|
109 |
} |
|
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
110 |
} |
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff
changeset
|
111 |