src/Pure/library.scala
author wenzelm
Fri, 14 Dec 2012 21:50:21 +0100
changeset 50539 3b68e5760a2d
parent 50491 0faaa279faee
child 50845 477ca927676f
permissions -rw-r--r--
tuned error dialog;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/library.scala
45673
cd41e3903fbf separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents: 45667
diff changeset
     2
    Module:     PIDE
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     4
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     5
Basic library.
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     6
*/
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     7
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     8
package isabelle
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
     9
38258
dd7dcb9b2637 added Library.thread_actor -- thread as actor;
wenzelm
parents: 38232
diff changeset
    10
38636
b7647ca7de5a module for simplified thread operations (Scala version);
wenzelm
parents: 38583
diff changeset
    11
import java.lang.System
49245
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents: 48996
diff changeset
    12
import java.util.Locale
50414
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
    13
import java.util.concurrent.{Future => JFuture, TimeUnit}
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
    14
import java.awt.Component
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
    15
import javax.swing.JOptionPane
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
    16
47867
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
    17
import scala.swing.{ComboBox, TextArea, ScrollPane}
37018
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
    18
import scala.swing.event.SelectionChanged
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    19
import scala.collection.mutable
37018
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
    20
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
    21
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
    22
object Library
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
    23
{
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    24
  /* user errors */
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    25
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    26
  object ERROR
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    27
  {
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    28
    def apply(message: String): Throwable = new RuntimeException(message)
48479
819f7a5f3e7f more general notion of user ERROR (cf. 44f56fe01528);
wenzelm
parents: 48425
diff changeset
    29
    def unapply(exn: Throwable): Option[String] = Exn.user_message(exn)
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    30
  }
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    31
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    32
  def error(message: String): Nothing = throw ERROR(message)
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    33
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    34
  def cat_error(msg1: String, msg2: String): Nothing =
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    35
    if (msg1 == "") error(msg1)
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    36
    else error(msg1 + "\n" + msg2)
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    37
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
    38
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    39
  /* separated chunks */
36688
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    40
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    41
  def separate[A](s: A, list: List[A]): List[A] =
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    42
    list match {
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    43
      case x :: xs if !xs.isEmpty => x :: s :: separate(s, xs)
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    44
      case _ => list
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    45
    }
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
    46
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    47
  def separated_chunks(sep: Char, source: CharSequence): Iterator[CharSequence] =
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    48
    new Iterator[CharSequence] {
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    49
      private val end = source.length
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    50
      private def next_chunk(i: Int): Option[(CharSequence, Int)] =
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    51
      {
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    52
        if (i < end) {
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    53
          var j = i; do j += 1 while (j < end && source.charAt(j) != sep)
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    54
          Some((source.subSequence(i + 1, j), j))
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    55
        }
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    56
        else None
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    57
      }
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    58
      private var state: Option[(CharSequence, Int)] = if (end == 0) None else next_chunk(-1)
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    59
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    60
      def hasNext(): Boolean = state.isDefined
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    61
      def next(): CharSequence =
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    62
        state match {
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    63
          case Some((s, i)) => { state = next_chunk(i); s }
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    64
          case None => Iterator.empty.next()
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    65
        }
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    66
    }
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    67
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    68
  def space_explode(sep: Char, str: String): List[String] =
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    69
    separated_chunks(sep, str).map(_.toString).toList
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    70
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    71
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    72
  /* lines */
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    73
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    74
  def cat_lines(lines: TraversableOnce[String]): String = lines.mkString("\n")
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    75
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
    76
  def split_lines(str: String): List[String] = space_explode('\n', str)
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
    77
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    78
  def first_line(source: CharSequence): String =
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    79
  {
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    80
    val lines = separated_chunks('\n', source)
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    81
    if (lines.hasNext) lines.next.toString
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    82
    else ""
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    83
  }
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    84
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48362
diff changeset
    85
  def trim_line(str: String): String =
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48362
diff changeset
    86
    if (str.endsWith("\n")) str.substring(0, str.length - 1)
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48362
diff changeset
    87
    else str
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48362
diff changeset
    88
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 49470
diff changeset
    89
  def lowercase(str: String): String = str.toLowerCase(Locale.ENGLISH)
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 49470
diff changeset
    90
  def uppercase(str: String): String = str.toUpperCase(Locale.ENGLISH)
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 49470
diff changeset
    91
49245
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents: 48996
diff changeset
    92
  def capitalize(str: String): String =
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents: 48996
diff changeset
    93
    if (str.length == 0) str
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 49470
diff changeset
    94
    else uppercase(str.substring(0, 1)) + str.substring(1)
49245
cb70157293c0 manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents: 48996
diff changeset
    95
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    96
48996
a8bad1369ada clarified separated_chunks vs. space_explode;
wenzelm
parents: 48479
diff changeset
    97
  /* quote */
46196
805de058722b added cat_lines convenience;
wenzelm
parents: 45900
diff changeset
    98
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
    99
  def quote(s: String): String = "\"" + s + "\""
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
   100
  def commas(ss: Iterable[String]): String = ss.iterator.mkString(", ")
48362
c3192ccb0ff4 proper commas_quote;
wenzelm
parents: 48345
diff changeset
   101
  def commas_quote(ss: Iterable[String]): String = ss.iterator.map(quote).mkString(", ")
43598
826ddd91ae2b basic operations on lists and strings;
wenzelm
parents: 43442
diff changeset
   102
36688
321d392ab12e added separate;
wenzelm
parents: 36685
diff changeset
   103
34141
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   104
  /* reverse CharSequence */
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   105
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   106
  class Reverse(text: CharSequence, start: Int, end: Int) extends CharSequence
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   107
  {
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   108
    require(0 <= start && start <= end && end <= text.length)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   109
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   110
    def this(text: CharSequence) = this(text, 0, text.length)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   111
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   112
    def length: Int = end - start
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   113
    def charAt(i: Int): Char = text.charAt(end - i - 1)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   114
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   115
    def subSequence(i: Int, j: Int): CharSequence =
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   116
      if (0 <= i && i <= j && j <= length) new Reverse(text, end - j, end - i)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   117
      else throw new IndexOutOfBoundsException
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   118
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   119
    override def toString: String =
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   120
    {
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   121
      val buf = new StringBuilder(length)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   122
      for (i <- 0 until length)
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   123
        buf.append(charAt(i))
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   124
      buf.toString
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   125
    }
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   126
  }
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   127
297b2149077d simiplified result of keyword parser (again);
wenzelm
parents: 34136
diff changeset
   128
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   129
  /* simple dialogs */
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   130
50539
3b68e5760a2d tuned error dialog;
wenzelm
parents: 50491
diff changeset
   131
  def scrollable_text(txt: String, width: Int = 60, editable: Boolean = false): ScrollPane =
47867
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   132
  {
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   133
    val text = new TextArea(txt)
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   134
    if (width > 0) text.columns = width
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   135
    text.editable = editable
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   136
    new ScrollPane(text)
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   137
  }
dd9cbe708e6b some attempts to make critical errors fit on screen;
wenzelm
parents: 46997
diff changeset
   138
46997
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   139
  private def simple_dialog(kind: Int, default_title: String,
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   140
    parent: Component, title: String, message: Seq[Any])
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   141
  {
36791
b8384c455b40 simple dialogs: ensure Swing thread;
wenzelm
parents: 36688
diff changeset
   142
    Swing_Thread.now {
38232
00b72526dc64 simple_dialog: allow scala.swing.Component as well;
wenzelm
parents: 37686
diff changeset
   143
      val java_message = message map { case x: scala.swing.Component => x.peer case x => x }
36791
b8384c455b40 simple dialogs: ensure Swing thread;
wenzelm
parents: 36688
diff changeset
   144
      JOptionPane.showMessageDialog(parent,
38232
00b72526dc64 simple_dialog: allow scala.swing.Component as well;
wenzelm
parents: 37686
diff changeset
   145
        java_message.toArray.asInstanceOf[Array[AnyRef]],
36791
b8384c455b40 simple dialogs: ensure Swing thread;
wenzelm
parents: 36688
diff changeset
   146
        if (title == null) default_title else title, kind)
b8384c455b40 simple dialogs: ensure Swing thread;
wenzelm
parents: 36688
diff changeset
   147
    }
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   148
  }
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   149
46997
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   150
  def dialog(parent: Component, title: String, message: Any*) =
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   151
    simple_dialog(JOptionPane.PLAIN_MESSAGE, null, parent, title, message)
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   152
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   153
  def warning_dialog(parent: Component, title: String, message: Any*) =
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   154
    simple_dialog(JOptionPane.WARNING_MESSAGE, "Warning", parent, title, message)
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   155
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   156
  def error_dialog(parent: Component, title: String, message: Any*) =
395b7277ed76 misc tuning to accomodate scala-2.10.0-M2;
wenzelm
parents: 46723
diff changeset
   157
    simple_dialog(JOptionPane.ERROR_MESSAGE, "Error", parent, title, message)
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   158
44573
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   159
  def confirm_dialog(parent: Component, title: String, option_type: Int, message: Any*): Int =
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   160
    Swing_Thread.now {
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   161
      val java_message = message map { case x: scala.swing.Component => x.peer case x => x }
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   162
      JOptionPane.showConfirmDialog(parent,
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   163
        java_message.toArray.asInstanceOf[Array[AnyRef]], title,
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   164
          option_type, JOptionPane.QUESTION_MESSAGE)
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   165
    }
51f8895b9ad9 some dialog for auto loading of required files (still inactive);
wenzelm
parents: 44158
diff changeset
   166
34216
ada8eb23a08e added simple dialogs;
wenzelm
parents: 34198
diff changeset
   167
37018
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
   168
  /* zoom box */
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
   169
37048
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   170
  class Zoom_Box(apply_factor: Int => Unit) extends ComboBox[String](
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   171
    List("50%", "70%", "85%", "100%", "125%", "150%", "175%", "200%", "300%", "400%"))
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   172
  {
47993
135fd6f2dadd less warning in scala-2.10.0-M3;
wenzelm
parents: 47867
diff changeset
   173
    val Factor = "([0-9]+)%?".r
37048
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   174
    def parse(text: String): Int =
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   175
      text match {
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   176
        case Factor(s) =>
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   177
          val i = Integer.parseInt(s)
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   178
          if (10 <= i && i <= 1000) i else 100
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   179
        case _ => 100
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   180
      }
50491
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   181
37048
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   182
    def print(i: Int): String = i.toString + "%"
37018
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
   183
50491
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   184
    def set_item(i: Int) {
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   185
      peer.getEditor match {
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   186
        case null =>
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   187
        case editor => editor.setItem(print(i))
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   188
      }
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   189
    }
0faaa279faee improved coupling of zoom_box and scale;
wenzelm
parents: 50414
diff changeset
   190
37048
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   191
    makeEditable()(c => new ComboBox.BuiltInEditor(c)(text => print(parse(text)), x => x))
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   192
    reactions += {
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   193
      case SelectionChanged(_) => apply_factor(parse(selection.item))
37018
39f4cce5a22c added somewhat generic zoom box;
wenzelm
parents: 36791
diff changeset
   194
    }
37048
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   195
    listenTo(selection)
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   196
    selection.index = 3
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   197
    prototypeDisplayValue = Some("00000%")
d014976dd690 tuned zoom_box;
wenzelm
parents: 37035
diff changeset
   198
  }
50414
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   199
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   200
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   201
  /* Java futures */
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   202
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   203
  def future_value[A](x: A) = new JFuture[A]
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   204
  {
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   205
    def cancel(may_interrupt: Boolean): Boolean = false
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   206
    def isCancelled(): Boolean = false
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   207
    def isDone(): Boolean = true
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   208
    def get(): A = x
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   209
    def get(timeout: Long, time_unit: TimeUnit): A = x
e17a1f179bb0 explore theory_body_files via future, for improved performance;
wenzelm
parents: 50299
diff changeset
   210
  }
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents:
diff changeset
   211
}
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   212
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   213
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   214
class Basic_Library
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   215
{
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
   216
  val ERROR = Library.ERROR
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
   217
  val error = Library.error _
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
   218
  val cat_error = Library.cat_error _
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
   219
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   220
  val space_explode = Library.space_explode _
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43652
diff changeset
   221
  val split_lines = Library.split_lines _
46196
805de058722b added cat_lines convenience;
wenzelm
parents: 45900
diff changeset
   222
  val cat_lines = Library.cat_lines _
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   223
  val quote = Library.quote _
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   224
  val commas = Library.commas _
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   225
  val commas_quote = Library.commas_quote _
49470
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   226
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   227
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   228
  /* parallel tasks */
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   229
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   230
  implicit def function_as_callable[A](f: () => A) =
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   231
    new java.util.concurrent.Callable[A] { def call = f() }
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   232
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   233
  val default_thread_pool =
ee564db2649b more management of Invoke_Scala tasks;
wenzelm
parents: 49245
diff changeset
   234
    scala.collection.parallel.ThreadPoolTasks.defaultThreadPool
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43598
diff changeset
   235
}