|
| 1 | +package scala.swing |
| 2 | + |
| 3 | +import javax.swing.{Icon, JInternalFrame, WindowConstants} |
| 4 | + |
| 5 | +import scala.swing.MenuBar.NoMenuBar |
| 6 | +import scala.swing.event.{InternalFrameActivated, InternalFrameClosed, InternalFrameClosing, InternalFrameDeactivated, InternalFrameDeiconified, InternalFrameIconified, InternalFrameOpened} |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * A window that can be nested inside another window (typically within a [[DesktopPane]]). |
| 11 | + */ |
| 12 | +class InternalFrame extends Component with RootPanel with Publisher { outer => |
| 13 | + import javax.swing.event.{InternalFrameEvent => PeerEvent, InternalFrameListener => PeerListener} |
| 14 | + |
| 15 | + override lazy val peer: JInternalFrame = new JInternalFrame with InterfaceMixin |
| 16 | + peer.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) |
| 17 | + |
| 18 | + trait InterfaceMixin extends JInternalFrame with SuperMixin { |
| 19 | + override def doDefaultCloseAction(): Unit = { |
| 20 | + super.doDefaultCloseAction() |
| 21 | + closeOperation() |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + def title: String = peer.getTitle |
| 26 | + def title_=(s: String): Unit = peer.setTitle(s) |
| 27 | + |
| 28 | + /** |
| 29 | + * The menu bar of this frame or [[NoMenuBar]] if no menu bar is set. |
| 30 | + */ |
| 31 | + def menuBar: MenuBar = { |
| 32 | + val m = UIElement.cachedWrapper[MenuBar](peer.getJMenuBar) |
| 33 | + if (m != null) m else MenuBar.NoMenuBar |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Set the current menu bar of this frame. Pass `NoMenuBar` if this frame |
| 38 | + * should not show a menu bar. |
| 39 | + */ |
| 40 | + def menuBar_=(m: MenuBar): Unit = |
| 41 | + peer.setJMenuBar(if (m == MenuBar.NoMenuBar) null else m.peer) |
| 42 | + |
| 43 | + def resizable_=(b: Boolean): Unit = peer.setResizable(b) |
| 44 | + def resizable: Boolean = peer.isResizable |
| 45 | + |
| 46 | + def maximizable : Boolean = peer.isMaximizable |
| 47 | + def maximizable_= (b : Boolean) : Unit = peer.setMaximizable(b) |
| 48 | + |
| 49 | + def maximized : Boolean = peer.isMaximum |
| 50 | + def maximize() : Unit = peer.setMaximum(true) |
| 51 | + def unmaximize() : Unit = peer.setMaximum(false) |
| 52 | + |
| 53 | + def location_=(p: Point): Unit = peer.setLocation(p) |
| 54 | + def size_=(size: Dimension): Unit = peer.setSize(size) |
| 55 | + def bounds_=(rect: Rectangle): Unit = peer.setBounds(rect) |
| 56 | + |
| 57 | + def closable : Boolean = peer.isClosable |
| 58 | + def closable_= (b : Boolean): Unit = peer.setClosable(b) |
| 59 | + |
| 60 | + def closed : Boolean = peer.isClosed |
| 61 | + def close() : Unit = peer.setClosed(true) |
| 62 | + |
| 63 | + def iconifiable : Boolean = peer.isIconifiable |
| 64 | + def iconifiable_= (b : Boolean) : Unit = peer.setIconifiable(b) |
| 65 | + |
| 66 | + def iconified : Boolean = peer.isIcon |
| 67 | + def iconify() : Unit = peer.setIcon(true) |
| 68 | + def uniconify() : Unit = peer.setIcon(false) |
| 69 | + |
| 70 | + def frameIcon : Icon = peer.getFrameIcon |
| 71 | + def frameIcon_= (icon : Icon) : Unit = peer.setFrameIcon(icon) |
| 72 | + |
| 73 | + def dispose(): Unit = peer.dispose() |
| 74 | + |
| 75 | + def pack(): this.type = { peer.pack(); this } |
| 76 | + |
| 77 | + def show() : Unit = peer.show() |
| 78 | + def hide() : Unit = peer.hide() |
| 79 | + |
| 80 | + def moveToBack() : Unit = peer.moveToBack() |
| 81 | + def moveToFront() : Unit = peer.moveToFront() |
| 82 | + |
| 83 | + def layer : Int = peer.getLayer |
| 84 | + def layer_= (n : Int) : Unit = peer.setLayer(n) |
| 85 | + |
| 86 | + def selected : Boolean = peer.isSelected |
| 87 | + def select() : Unit = peer.setSelected(true) |
| 88 | + def deselect() : Unit = peer.setSelected(false) |
| 89 | + |
| 90 | + /** |
| 91 | + * This method is called when the window is closing, after all other window |
| 92 | + * event listeners have been processed. |
| 93 | + * |
| 94 | + * Default behavior is to dispose of the internal frame, but other options include hiding the frame |
| 95 | + * or doing nothing at all. |
| 96 | + */ |
| 97 | + def closeOperation(): Unit = dispose() |
| 98 | + |
| 99 | + peer.addInternalFrameListener(new PeerListener { |
| 100 | + override def internalFrameOpened(e: PeerEvent): Unit = publish(InternalFrameOpened(outer)) |
| 101 | + |
| 102 | + override def internalFrameClosing(e: PeerEvent): Unit = publish(InternalFrameClosing(outer)) |
| 103 | + |
| 104 | + override def internalFrameClosed(e: PeerEvent): Unit = publish(InternalFrameClosed(outer)) |
| 105 | + |
| 106 | + override def internalFrameIconified(e: PeerEvent): Unit = publish(InternalFrameIconified(outer)) |
| 107 | + |
| 108 | + override def internalFrameDeiconified(e: PeerEvent): Unit = publish(InternalFrameDeiconified(outer)) |
| 109 | + |
| 110 | + override def internalFrameActivated(e: PeerEvent): Unit = publish(InternalFrameActivated(outer)) |
| 111 | + |
| 112 | + override def internalFrameDeactivated(e: PeerEvent): Unit = publish(InternalFrameDeactivated(outer)) |
| 113 | + }) |
| 114 | +} |
0 commit comments