| 21 | | def Frame(commands: Array[AnyRef]): JFrame = { |
| 22 | | val frame = new JFrame() |
| 23 | | for(command <- commands) command match { |
| 24 | | case ('title, title: String) => |
| 25 | | frame.setTitle(title) |
| 26 | | case ('exitOnClose, b: Boolean) => |
| 27 | | if(b) |
| 28 | | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) |
| 29 | | else |
| 30 | | frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) |
| 31 | | case pane: java.awt.Component => |
| 32 | | frame.getContentPane.add(pane) |
| 33 | | case ('size, (width: Int, height: Int)) => |
| 34 | | frame.setSize(width, height) |
| 35 | | case 'pack => |
| 36 | | frame.pack |
| 37 | | case ('visible, b: Boolean) => |
| 38 | | frame.setVisible(b) |
| 39 | | case command: Any => { |
| 40 | | command match { |
| 41 | | case (name: Symbol, value: AnyRef) => |
| 42 | | println("NG: (" + name.getClass.getName + ", " + value.getClass.getName + ")") |
| 43 | | case value: Any => |
| 44 | | println("NG: " + value.getClass.getName) |
| | 26 | class Frame extends JFrame with SwingCommand { |
| | 27 | def this(commands: Array[AnyRef]) { |
| | 28 | this() |
| | 29 | exec(commands) |
| | 30 | } |
| | 31 | def exec(commands: Array[AnyRef]) { |
| | 32 | for(command <- commands) command match { |
| | 33 | case ('title, title: String) => |
| | 34 | setTitle(title) |
| | 35 | case 'exitOnClose => |
| | 36 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) |
| | 37 | case pane: java.awt.Component => |
| | 38 | getContentPane.add(pane) |
| | 39 | case ('size, (width: Int, height: Int)) => |
| | 40 | setSize(width, height) |
| | 41 | case 'pack => |
| | 42 | pack |
| | 43 | case ('visible, b: Boolean) => |
| | 44 | setVisible(b) |
| | 45 | case command: Any => { |
| | 46 | command match { |
| | 47 | case (name: Symbol, value: AnyRef) => |
| | 48 | println("NG: (" + name.getClass.getName + ", " + value.getClass.getName + ")") |
| | 49 | case value: Any => |
| | 50 | println("NG: " + value.getClass.getName) |
| | 51 | } |
| | 56 | |
| | 57 | class Button(text: String) extends JButton(text) with SwingCommand { |
| | 58 | def this(text: String, commands: Array[AnyRef]) { |
| | 59 | this(text) |
| | 60 | exec(commands) |
| | 61 | } |
| | 62 | def exec(commands: Array[AnyRef]) { |
| | 63 | for(command <- commands) { |
| | 64 | command match { |
| | 65 | case ('action, proc: (ActionEvent => Unit)) => |
| | 66 | addActionListener(new ActionAdapter(proc)) |
| | 67 | case ('text, text: String) => |
| | 68 | setText(text) |
| | 69 | case _ => println("NG: " + command) |
| | 70 | } |
| | 71 | } |
| | 72 | } |
| | 73 | } |
| | 74 | |
| | 75 | def Frame(commands: AnyRef*): Frame = new Frame(commands.toArray) |
| | 107 | def FileChooser(commands: Any*): JFileChooser = { |
| | 108 | val chooser = new JFileChooser() |
| | 109 | for(command <- commands) |
| | 110 | command match { |
| | 111 | case ('name, name: String) => |
| | 112 | chooser.setName(name) |
| | 113 | case ('dialogTitle, title: String) => |
| | 114 | chooser.setDialogTitle(title) |
| | 115 | case ('showOpen, parent: java.awt.Component) => |
| | 116 | chooser.showOpenDialog(parent) |
| | 117 | case ('showSave, parent: java.awt.Component) => |
| | 118 | chooser.showSaveDialog(parent) |
| | 119 | case ('action, proc: (ActionEvent => Unit)) => |
| | 120 | chooser.addActionListener(new ActionAdapter(proc)) |
| | 121 | case _ => |
| | 122 | println("NG: " + command) |
| | 123 | } |
| | 124 | chooser |
| | 125 | } |
| | 126 | |