root/lang/scala/sandbox/src/jp/ne/cappuccino/keisuken/scl/swing/SwingBuilder.scala @ 6788

Revision 6788, 2.2 kB (checked in by keisuken, 7 years ago)

Simple Swing Framework add.

  • Property svn:executable set to *
Line 
1package jp.ne.cappuccino.keisuken.scl.swing
2
3import java.awt.{Dimension}
4import java.awt.event._
5import javax.swing._
6
7import jp.ne.cappuccino.keisuken.awt._
8
9/**
10 * Swing GUI framwork.
11 * @author   NISHIMOTO Keisuke,
12 */
13object SwingBuilder {
14
15  class JFrameTable(panel: TablePanel) extends JFrame {
16
17    def this(commands: AnyRef*) {
18      this(new TablePanel())
19      add(panel)
20      set(commands.toArray)
21    }
22
23    def apply(commands: AnyRef*) = set(commands.toArray)
24
25    def set(commands: Array[AnyRef]) = commands.foreach(_ match {
26        case ('title, title: String) =>
27          setTitle(title)
28        case ('exitOnClose, b: Boolean) =>
29          if(b)
30            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
31          else
32            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
33        case ('layout, lines: Array[Array[java.lang.Object]]) =>
34          tableLayout(lines)
35        case ('size, (width: Int, height: Int)) =>
36          setSize(width, height)
37        case 'pack =>
38          pack
39        case ('visible, b: Boolean) =>
40          setVisible(b)
41        case command: Any => {
42          command match {
43            case (name: Symbol, value: AnyRef) =>
44              println("NG: (" + name.getClass.getName + ", " + value.getClass.getName + ")")
45            case value: Any =>
46              println("NG: " + value.getClass.getName)
47          }
48        }
49      })
50
51    def tableLayout(lines: Array[java.lang.Object]*): Unit =
52      tableLayout(lines.toArray)
53
54    def tableLayout(lines: Array[Array[java.lang.Object]]): Unit =
55      panel.setLayout(lines)
56  }
57
58  def layout(lines: Array[java.lang.Object]*):
59    (Symbol, Array[Array[java.lang.Object]]) =
60      ('layout, lines.toArray.asInstanceOf[Array[Array[java.lang.Object]]])
61
62  def line(cols: Any*): Array[java.lang.Object] =
63    cols.map(_.asInstanceOf[java.lang.Object]).toArray
64
65  /**
66   * Sample codes.
67   */
68  def main(args: Array[String]) {
69    val frame = new JFrameTable(
70      'exitOnClose -> true,
71      'title -> "Hello, world",
72      'size -> (320, 240),
73      layout(
74        line("aaa", "bbb"),
75        line("ccc", "ddd")
76      ),
77      'pack,
78      'visible -> true
79    )
80    println(frame)
81  }
82}
Note: See TracBrowser for help on using the browser.