src/Tools/jEdit/src/jedit_options.scala
author wenzelm
Mon, 10 Sep 2012 19:56:08 +0200
changeset 49248 bff772033a97
parent 49247 ffd9ad9dc35b
child 49252 9e10481dd3c4
permissions -rw-r--r--
proper multi-line tooltip;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    12
import javax.swing.{InputVerifier, JComponent}
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    13
import javax.swing.text.JTextComponent
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    14
import scala.swing.{Component, CheckBox, TextArea}
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    15
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    16
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    17
trait Option_Component extends Component
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    18
{
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    19
  val title: String
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    20
  def load(): Unit
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    21
  def save(): Unit
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    22
}
49245
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff changeset
    23
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff changeset
    24
class JEdit_Options extends Options_Variable
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff changeset
    25
{
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    26
  def title(opt_name: String): String = value.title("jedit", opt_name)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    27
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    28
  def make_component(opt_name: String): Option_Component =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    29
  {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    30
    Swing_Thread.require()
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    31
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    32
    val opt = value.check_name(opt_name)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    33
    val opt_title = title(opt_name)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    34
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    35
    val component =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    36
      if (opt.typ == Options.Bool)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    37
        new CheckBox with Option_Component {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    38
          val title = opt_title
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    39
          def load = selected = bool(opt_name)
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    40
          def save = bool(opt_name) = selected
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    41
        }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    42
      else {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    43
        val text_area =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    44
          new TextArea with Option_Component {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    45
            val title = opt_title
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    46
            def load = text = value.check_name(opt_name).value
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    47
            def save = update(value + (opt_name, text))
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    48
          }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    49
        text_area.peer.setInputVerifier(new InputVerifier {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    50
          def verify(jcomponent: JComponent): Boolean =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    51
            jcomponent match {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    52
              case text: JTextComponent =>
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    53
                try { value + (opt_name, text.getText); true }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    54
                catch { case ERROR(_) => false }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    55
              case _ => true
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    56
            }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    57
          })
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    58
        text_area
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    59
      }
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    60
    component.load()
49248
bff772033a97 proper multi-line tooltip;
wenzelm
parents: 49247
diff changeset
    61
    component.tooltip = Isabelle.tooltip(opt.print)
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    62
    component
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents: 49245
diff changeset
    63
  }
49245
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff changeset
    64
}
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
diff changeset
    65