1 /* Title: Pure/library.scala
9 import java.lang.System
10 import java.awt.Component
11 import javax.swing.JOptionPane
16 /* reverse CharSequence */
18 class Reverse(text: CharSequence, start: Int, end: Int) extends CharSequence
20 require(0 <= start && start <= end && end <= text.length)
22 def this(text: CharSequence) = this(text, 0, text.length)
24 def length: Int = end - start
25 def charAt(i: Int): Char = text.charAt(end - i - 1)
27 def subSequence(i: Int, j: Int): CharSequence =
28 if (0 <= i && i <= j && j <= length) new Reverse(text, end - j, end - i)
29 else throw new IndexOutOfBoundsException
31 override def toString: String =
33 val buf = new StringBuilder(length)
34 for (i <- 0 until length)
43 private def simple_dialog(kind: Int, default_title: String)
44 (parent: Component, title: String, message: Any*)
46 JOptionPane.showMessageDialog(parent,
47 message.toArray.asInstanceOf[Array[AnyRef]],
48 if (title == null) default_title else title, kind)
51 def dialog = simple_dialog(JOptionPane.PLAIN_MESSAGE, null) _
52 def warning_dialog = simple_dialog(JOptionPane.WARNING_MESSAGE, "Warning") _
53 def error_dialog = simple_dialog(JOptionPane.ERROR_MESSAGE, "Error") _
58 def timeit[A](e: => A) =
60 val start = System.currentTimeMillis()
61 val result = Exn.capture(e)
62 val stop = System.currentTimeMillis()
63 System.err.println((stop - start) + "ms elapsed time")