From d83917a2ee771186b151a151314dac092ae8530a Mon Sep 17 00:00:00 2001 From: Ingo Maier Date: Wed, 24 Jun 2009 10:48:29 +0000 Subject: * dialogs use named arguments now, messages are... * dialogs use named arguments now, messages are of type Any (fixes * #1922) components register listeners on demand (fixes #1595) Fix for * #2026 minor additions and fixes --- src/swing/scala/swing/Component.scala | 100 ++++++++++++------------ src/swing/scala/swing/GridBagPanel.scala | 2 +- src/swing/scala/swing/ListView.scala | 28 +++---- src/swing/scala/swing/Publisher.scala | 2 +- src/swing/scala/swing/RichWindows.scala | 78 +++++++++++------- src/swing/scala/swing/ScrollPane.scala | 40 +++++++++- src/swing/scala/swing/Table.scala | 9 ++- src/swing/scala/swing/UIElement.scala | 13 ++- src/swing/scala/swing/test/ComboBoxes.scala | 2 +- src/swing/scala/swing/test/Dialogs.scala | 69 ++++++++-------- src/swing/scala/swing/test/LinePainting.scala | 1 - src/swing/scala/swing/test/TableSelection.scala | 9 ++- src/swing/scala/swing/test/UIDemo.scala | 1 - 13 files changed, 204 insertions(+), 150 deletions(-) (limited to 'src/swing') diff --git a/src/swing/scala/swing/Component.scala b/src/swing/scala/swing/Component.scala index b6d8688127..5a3147b828 100644 --- a/src/swing/scala/swing/Component.scala +++ b/src/swing/scala/swing/Component.scala @@ -30,7 +30,7 @@ object Component { * @see http://java.sun.com/products/jfc/tsc/articles/painting/ for the component * painting mechanism */ -abstract class Component extends UIElement with Publisher { +abstract class Component extends UIElement with LazyPublisher { override lazy val peer: javax.swing.JComponent = new javax.swing.JComponent with SuperMixin {} var initP: JComponent = null @@ -92,39 +92,9 @@ abstract class Component extends UIElement with Publisher { }) }*/ - peer.addComponentListener(new java.awt.event.ComponentListener { - def componentHidden(e: java.awt.event.ComponentEvent) { - publish(ComponentHidden(Component.this)) - } - def componentShown(e: java.awt.event.ComponentEvent) { - publish(ComponentShown(Component.this)) - } - def componentMoved(e: java.awt.event.ComponentEvent) { - publish(ComponentMoved(Component.this)) - } - def componentResized(e: java.awt.event.ComponentEvent) { - publish(ComponentResized(Component.this)) - } - }) - peer.addFocusListener(new java.awt.event.FocusListener { - def other(e: java.awt.event.FocusEvent) = e.getOppositeComponent match { - case c: JComponent => Some(UIElement.cachedWrapper(c)) - case _ => None - } - def focusGained(e: java.awt.event.FocusEvent) { - publish(FocusGained(Component.this, other(e), e.isTemporary)) - } - def focusLost(e: java.awt.event.FocusEvent) { - publish(FocusLost(Component.this, other(e), e.isTemporary)) - } - }) - - /** - * @deprecated Use mouse instead. - */ - @deprecated lazy val Mouse = mouse + @deprecated("Use mouse instead") lazy val Mouse = mouse /** * Contains publishers for various mouse events. They are separated for @@ -202,28 +172,58 @@ abstract class Component extends UIElement with Publisher { def requestFocusInWindow() = peer.requestFocusInWindow() def hasFocus: Boolean = peer.isFocusOwner - peer.addPropertyChangeListener(new java.beans.PropertyChangeListener { - def propertyChange(e: java.beans.PropertyChangeEvent) { - e.getPropertyName match { - case "font" => publish(FontChanged(Component.this)) - case "background" => publish(ForegroundChanged(Component.this)) - case "foreground" => publish(BackgroundChanged(Component.this)) - case _ => - /*case "focusable" => - case "focusTraversalKeysEnabled" => - case "forwardFocusTraversalKeys" => - case "backwardFocusTraversalKeys" => - case "upCycleFocusTraversalKeys" => - case "downCycleFocusTraversalKeys" => - case "focusTraversalPolicy" => - case "focusCycleRoot" =>*/ + def onFirstSubscribe { + peer.addComponentListener(new java.awt.event.ComponentListener { + def componentHidden(e: java.awt.event.ComponentEvent) { + publish(ComponentHidden(Component.this)) } - } - }) + def componentShown(e: java.awt.event.ComponentEvent) { + publish(ComponentShown(Component.this)) + } + def componentMoved(e: java.awt.event.ComponentEvent) { + publish(ComponentMoved(Component.this)) + } + def componentResized(e: java.awt.event.ComponentEvent) { + publish(ComponentResized(Component.this)) + } + }) - def revalidate() { peer.revalidate() } + peer.addFocusListener(new java.awt.event.FocusListener { + def other(e: java.awt.event.FocusEvent) = e.getOppositeComponent match { + case c: JComponent => Some(UIElement.cachedWrapper(c)) + case _ => None + } + def focusGained(e: java.awt.event.FocusEvent) { + publish(FocusGained(Component.this, other(e), e.isTemporary)) + } + def focusLost(e: java.awt.event.FocusEvent) { + publish(FocusLost(Component.this, other(e), e.isTemporary)) + } + }) + peer.addPropertyChangeListener(new java.beans.PropertyChangeListener { + def propertyChange(e: java.beans.PropertyChangeEvent) { + e.getPropertyName match { + case "font" => publish(FontChanged(Component.this)) + case "background" => publish(ForegroundChanged(Component.this)) + case "foreground" => publish(BackgroundChanged(Component.this)) + case _ => + /*case "focusable" => + case "focusTraversalKeysEnabled" => + case "forwardFocusTraversalKeys" => + case "backwardFocusTraversalKeys" => + case "upCycleFocusTraversalKeys" => + case "downCycleFocusTraversalKeys" => + case "focusTraversalPolicy" => + case "focusCycleRoot" =>*/ + } + } + }) + } + def onLastUnsubscribe() {} + + def revalidate() { peer.revalidate() } /** * For custom painting, users should usually override this method. diff --git a/src/swing/scala/swing/GridBagPanel.scala b/src/swing/scala/swing/GridBagPanel.scala index d27299b023..50d9b4b548 100644 --- a/src/swing/scala/swing/GridBagPanel.scala +++ b/src/swing/scala/swing/GridBagPanel.scala @@ -19,7 +19,7 @@ object GridBagPanel { val SouthWest = Value(GridBagConstraints.SOUTHWEST) val West = Value(GridBagConstraints.WEST) val NorthWest = Value(GridBagConstraints.NORTHWEST) - val CENTER = Value(GridBagConstraints.CENTER) + val Center = Value(GridBagConstraints.CENTER) val PageStart = Value(GridBagConstraints.PAGE_START) val PageEnd = Value(GridBagConstraints.PAGE_END) diff --git a/src/swing/scala/swing/ListView.scala b/src/swing/scala/swing/ListView.scala index 1948fc71d7..61313aea5a 100644 --- a/src/swing/scala/swing/ListView.scala +++ b/src/swing/scala/swing/ListView.scala @@ -26,8 +26,8 @@ object ListView { * Wrapper for javax.swing.ListCellRenderers */ class Wrapped[A](override val peer: ListCellRenderer) extends Renderer[A] { - def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) = { - Component.wrap(peer.getListCellRendererComponent(list.peer, a, index, isSelected, hasFocus).asInstanceOf[JComponent]) + def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int) = { + Component.wrap(peer.getListCellRendererComponent(list.peer, a, index, isSelected, focused).asInstanceOf[JComponent]) } } @@ -46,8 +46,8 @@ object ListView { * */ def apply[A,B](f: A => B)(implicit renderer: Renderer[B]): Renderer[A] = new Renderer[A] { - def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = - renderer.componentFor(list, isSelected, hasFocus, f(a), index) + def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int): Component = + renderer.componentFor(list, isSelected, focused, f(a), index) } } @@ -61,10 +61,10 @@ object ListView { */ abstract class Renderer[-A] { def peer: ListCellRenderer = new ListCellRenderer { - def getListCellRendererComponent(list: JList, a: Any, index: Int, isSelected: Boolean, hasFocus: Boolean) = - componentFor(ListView.wrap[A](list), isSelected, hasFocus, a.asInstanceOf[A], index).peer + def getListCellRendererComponent(list: JList, a: Any, index: Int, isSelected: Boolean, focused: Boolean) = + componentFor(ListView.wrap[A](list), isSelected, focused, a.asInstanceOf[A], index).peer } - def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component + def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int): Component } /** @@ -84,7 +84,7 @@ object ListView { * This includes foreground and background colors, as well as colors * of item selections. */ - def preConfigure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) { + def preConfigure(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int) { if (isSelected) { component.background = list.selectionBackground component.foreground = list.selectionForeground @@ -96,14 +96,14 @@ object ListView { /** * Configuration that is specific to the component and this renderer. */ - def configure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) + def configure(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int) /** * Configures the component before returning it. */ - def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = { - preConfigure(list, isSelected, hasFocus, a, index) - configure(list, isSelected, hasFocus, a, index) + def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int): Component = { + preConfigure(list, isSelected, focused, a, index) + configure(list, isSelected, focused, a, index) component } } @@ -115,8 +115,8 @@ object ListView { */ implicit object GenericRenderer extends Renderer[Any] { override lazy val peer: ListCellRenderer = new DefaultListCellRenderer - def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: Any, index: Int): Component = { - val c = peer.getListCellRendererComponent(list.peer, a, index, isSelected, hasFocus).asInstanceOf[JComponent] + def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: Any, index: Int): Component = { + val c = peer.getListCellRendererComponent(list.peer, a, index, isSelected, focused).asInstanceOf[JComponent] val w = UIElement.cachedWrapper[Component](c) if (w eq null) Component.wrap(c) else w } diff --git a/src/swing/scala/swing/Publisher.scala b/src/swing/scala/swing/Publisher.scala index 5524e7ea29..ec15616a30 100644 --- a/src/swing/scala/swing/Publisher.scala +++ b/src/swing/scala/swing/Publisher.scala @@ -112,7 +112,7 @@ private[swing] trait SingleRefCollection[+A <: AnyRef] extends Iterable[A] { sel private[swing] class StrongReference[+T <: AnyRef](value: T) extends Reference[T] { private[this] var ref: Option[T] = Some(value) - @deprecated def isValid: Boolean = ref != None + def isValid: Boolean = ref != None def apply(): T = ref.get def get : Option[T] = ref override def toString = get.map(_.toString).getOrElse("") diff --git a/src/swing/scala/swing/RichWindows.scala b/src/swing/scala/swing/RichWindows.scala index f3e8208580..25a99db700 100644 --- a/src/swing/scala/swing/RichWindows.scala +++ b/src/swing/scala/swing/RichWindows.scala @@ -1,6 +1,6 @@ package scala.swing -import java.awt.{Image, Window => AWTWindow} +import java.awt.{Image, Window => AWTWindow, Frame => AWTFrame} import javax.swing._ import Swing._ @@ -9,6 +9,8 @@ object RichWindow { * Mixin this trait if you want an undecorated window. */ trait Undecorated extends RichWindow { + // we do a mixin here, since setUndecorated is only allowed to be called + // when the component is not displayable. peer.setUndecorated(true) } } @@ -62,6 +64,13 @@ class Frame extends RichWindow { } } + def iconify() { peer.setExtendedState(peer.getExtendedState | AWTFrame.ICONIFIED) } + def uniconify() { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.ICONIFIED) } + def iconified() { (peer.getExtendedState & AWTFrame.ICONIFIED) != 0 } + def maximize() { peer.setExtendedState(peer.getExtendedState | AWTFrame.MAXIMIZED_BOTH) } + def unmaximize() { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.MAXIMIZED_BOTH) } + def maximized() { (peer.getExtendedState & AWTFrame.MAXIMIZED_BOTH) != 0 } + def iconImage: Image = peer.getIconImage def iconImage_=(i: Image) { peer.setIconImage(i) } } @@ -104,44 +113,53 @@ object Dialog { val Closed = Value(JOptionPane.CLOSED_OPTION) } + private def uiString(txt: String) = UIManager.getString(txt) - def showConfirmation(parent: Component, message: String, title: String, - optionType: Options.Value, messageType: Message.Value, icon: Icon): Result.Value = + def showConfirmation(parent: Component = null, + message: Any, + title: String = uiString("OptionPane.titleText"), + optionType: Options.Value = Options.YesNo, + messageType: Message.Value = Message.Question, + icon: Icon = EmptyIcon): Result.Value = Result(JOptionPane.showConfirmDialog(nullPeer(parent), message, title, optionType.id, messageType.id, Swing.wrapIcon(icon))) - def showConfirmation(parent: Component, message: String, title: String, - optionType: Options.Value): Result.Value = - Result(JOptionPane.showConfirmDialog(nullPeer(parent), message, title, - optionType.id)) - def showOptions(parent: Component, message: String, title: String, - optionType: Options.Value, messageType: Message.Value, icon: Icon, - entries: Seq[Any], initialEntry: Int): Result.Value = { - val r = JOptionPane.showOptionDialog(nullPeer(parent), message, title, + def showOptions(parent: Component = null, + message: Any, + title: String = uiString("OptionPane.titleText"), + optionType: Options.Value = Options.YesNo, + messageType: Message.Value = Message.Question, + icon: Icon = EmptyIcon, + entries: Seq[Any], + initial: Int): Result.Value = { + val r = JOptionPane.showOptionDialog(nullPeer(parent), message, title, optionType.id, messageType.id, Swing.wrapIcon(icon), - entries.map(_.asInstanceOf[AnyRef]).toArray, entries(initialEntry)) - Result(r) - } - - def showInput[A](parent: Component, message: String, title: String, - messageType: Message.Value, icon: Icon, - entries: Seq[A], initialEntry: A): Option[A] = { - val e = if (entries.isEmpty) null - else entries.map(_.asInstanceOf[AnyRef]).toArray - val r = JOptionPane.showInputDialog(nullPeer(parent), message, title, - messageType.id, Swing.wrapIcon(icon), - e, initialEntry) - Swing.toOption(r) + entries.map(_.asInstanceOf[AnyRef]).toArray, entries(initial)) + Result(r) + } + + def showInput[A](parent: Component = null, + message: Any, + title: String = uiString("OptionPane.inputDialogTitle"), + messageType: Message.Value = Message.Question, + icon: Icon = EmptyIcon, + entries: Seq[A] = Nil, + initial: A): Option[A] = { + val e = if (entries.isEmpty) null + else entries.map(_.asInstanceOf[AnyRef]).toArray + val r = JOptionPane.showInputDialog(nullPeer(parent), message, title, + messageType.id, Swing.wrapIcon(icon), + e, initial) + Swing.toOption(r) } - def showMessage(parent: Component, message: String, title: String, - messageType: Message.Value, icon: Icon) { + def showMessage(parent: Component = null, + message: Any, + title: String = uiString("OptionPane.messageDialogTitle"), + messageType: Message.Value = Message.Info, + icon: Icon = EmptyIcon) { JOptionPane.showMessageDialog(nullPeer(parent), message, title, messageType.id, Swing.wrapIcon(icon)) } - - def showMessage(parent: Component, message: String) { - JOptionPane.showMessageDialog(nullPeer(parent), message) - } } /** diff --git a/src/swing/scala/swing/ScrollPane.scala b/src/swing/scala/swing/ScrollPane.scala index 829a02854d..c8fa7dc489 100644 --- a/src/swing/scala/swing/ScrollPane.scala +++ b/src/swing/scala/swing/ScrollPane.scala @@ -1,6 +1,27 @@ package scala.swing -import javax.swing.JScrollPane +import javax.swing.{JScrollPane, ScrollPaneConstants} + +object ScrollPane { + object BarPolicy extends Enumeration { + import ScrollPaneConstants._ + val AsNeeded = new Value(HORIZONTAL_SCROLLBAR_AS_NEEDED, + VERTICAL_SCROLLBAR_AS_NEEDED) + val Never = new Value(HORIZONTAL_SCROLLBAR_NEVER, + VERTICAL_SCROLLBAR_NEVER) + val Always = new Value(HORIZONTAL_SCROLLBAR_ALWAYS, + VERTICAL_SCROLLBAR_ALWAYS) + + def wrap(id: Int) = id match { + case HORIZONTAL_SCROLLBAR_AS_NEEDED | VERTICAL_SCROLLBAR_AS_NEEDED => AsNeeded + case HORIZONTAL_SCROLLBAR_NEVER | VERTICAL_SCROLLBAR_NEVER => Never + case HORIZONTAL_SCROLLBAR_ALWAYS | VERTICAL_SCROLLBAR_ALWAYS => Always + } + class Value(val horizontalPeer: Int, val verticalPeer: Int) extends super.Val { + override def id = horizontalPeer + } + } +} /** * Can have at most a single child component, which will be put inside a canvas (the viewport) @@ -9,10 +30,12 @@ import javax.swing.JScrollPane * @see javax.swing.JScrollPane */ class ScrollPane extends Component with Container { + import ScrollPane._ + override lazy val peer: JScrollPane = new JScrollPane def this(c: Component) = { this() - viewportView = c + contents = c } def contents: Seq[Component] = List(UIElement.cachedWrapper(peer.getViewport.getView.asInstanceOf[javax.swing.JComponent])) @@ -33,7 +56,18 @@ class ScrollPane extends Component with Container { def rowHeaderView_=(c: Component) = peer.setRowHeaderView(c.peer) def rowHeaderView_=(c: Option[Component]) = peer.setRowHeaderView(Swing.toNull(c.map(_.peer))) + def columnHeaderView: Option[Component] = Swing.toOption(peer.getColumnHeader.getView).map(UIElement.cachedWrapper(_)) + def columnHeaderView_=(c: Component) = peer.setColumnHeaderView(c.peer) + def columnHeaderView_=(c: Option[Component]) = peer.setColumnHeaderView(Swing.toNull(c.map(_.peer))) + def viewportView: Option[Component] = Swing.toOption(peer.getViewport.getView).map(UIElement.cachedWrapper(_)) def viewportView_=(c: Component) = peer.setViewportView(c.peer) def viewportView_=(c: Option[Component]) = peer.setViewportView(Swing.toNull(c.map(_.peer))) -} + + def verticalScrollBarPolicy = BarPolicy.wrap(peer.getVerticalScrollBarPolicy) + def verticalScrollBarPolicy_=(p: BarPolicy.Value) = peer.setVerticalScrollBarPolicy(p.verticalPeer) + + def horizontalScrollBarPolicy = BarPolicy.wrap(peer.getHorizontalScrollBarPolicy) + def horizontalScrollBarPolicy_=(p: BarPolicy.Value) = peer.setHorizontalScrollBarPolicy(p.horizontalPeer) + +} \ No newline at end of file diff --git a/src/swing/scala/swing/Table.scala b/src/swing/scala/swing/Table.scala index b6d8ecd115..91db9fcb55 100644 --- a/src/swing/scala/swing/Table.scala +++ b/src/swing/scala/swing/Table.scala @@ -94,6 +94,9 @@ object Table { /** * Displays a matrix of items. * + * To obtain a scrollable table or row and columns headers, + * wrap the table in a scroll pane. + * * @see javax.swing.JTable */ class Table extends Component with Scrollable with Publisher { @@ -234,15 +237,15 @@ class Table extends Component with Scrollable with Publisher { /** * Supplies a renderer component for a given cell. */ - protected def rendererComponent(isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component = + protected def rendererComponent(isSelected: Boolean, focused: Boolean, row: Int, column: Int): Component = new Component { override lazy val peer = { val v = apply(row, column).asInstanceOf[AnyRef] if (v != null) Table.this.peer.getDefaultRenderer(v.getClass).getTableCellRendererComponent(Table.this.peer, - v, isSelected, hasFocus, row, column).asInstanceOf[JComponent] + v, isSelected, focused, row, column).asInstanceOf[JComponent] else Table.this.peer.getDefaultRenderer(classOf[Object]).getTableCellRendererComponent(Table.this.peer, - v, isSelected, hasFocus, row, column).asInstanceOf[JComponent] + v, isSelected, focused, row, column).asInstanceOf[JComponent] } } diff --git a/src/swing/scala/swing/UIElement.scala b/src/swing/scala/swing/UIElement.scala index 385c5f5923..a440f76834 100644 --- a/src/swing/scala/swing/UIElement.scala +++ b/src/swing/scala/swing/UIElement.scala @@ -65,10 +65,8 @@ trait UIElement extends Proxy { def preferredSize = peer.getPreferredSize def preferredSize_=(x: Dimension) = peer.setPreferredSize(x) - /** - * @deprecated Use implicit conversion from Swing object instead. - */ - @deprecated def preferredSize_=(xy: (Int, Int)) { peer.setPreferredSize(new Dimension(xy._1, xy._2)) } + @deprecated("Use implicit conversion from Swing object instead") + def preferredSize_=(xy: (Int, Int)) { peer.setPreferredSize(new Dimension(xy._1, xy._2)) } def font: Font = peer.getFont def font_=(f: Font) = peer.setFont(f) @@ -78,10 +76,9 @@ trait UIElement extends Proxy { def bounds = peer.getBounds def size = peer.getSize def size_=(dim: Dimension) = peer.setSize(dim) - /** - * @deprecated Use implicit conversion from Swing object instead. - */ - @deprecated def size_=(xy: (Int, Int)) { peer.setSize(new Dimension(xy._1, xy._2)) } + + @deprecated("Use implicit conversion from Swing object instead") + def size_=(xy: (Int, Int)) { peer.setSize(new Dimension(xy._1, xy._2)) } def locale = peer.getLocale def toolkit = peer.getToolkit diff --git a/src/swing/scala/swing/test/ComboBoxes.scala b/src/swing/scala/swing/test/ComboBoxes.scala index 87bb21dc33..1dcdad4238 100644 --- a/src/swing/scala/swing/test/ComboBoxes.scala +++ b/src/swing/scala/swing/test/ComboBoxes.scala @@ -64,7 +64,7 @@ object ComboBoxes extends SimpleGUIApplication { val iconBox = new ComboBox(icons) { renderer = new ListView.AbstractRenderer[Icon, Label](new Label) { - def configure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, icon: Icon, index: Int) { + def configure(list: ListView[_], isSelected: Boolean, focused: Boolean, icon: Icon, index: Int) { component.icon = icon component.xAlignment = Alignment.Center if(isSelected) { diff --git a/src/swing/scala/swing/test/Dialogs.scala b/src/swing/scala/swing/test/Dialogs.scala index a2e8b1b9ba..601c78e71d 100644 --- a/src/swing/scala/swing/test/Dialogs.scala +++ b/src/swing/scala/swing/test/Dialogs.scala @@ -60,38 +60,39 @@ object Dialogs extends SimpleGUIApplication { case `ok` => showMessage(buttons, "Eggs aren't supposed to be green.") case `ynlf` => - showConfirmation(buttons, "Would you like green eggs and ham?", - "An Inane Question", Options.YesNo) match { - case Result.Yes => label.text = "Ewww!" - case Result.No => label.text = "Me neither!" - case _ => label.text = "Come on -- tell me!" + label.text = showConfirmation(buttons, + "Would you like green eggs and ham?", + "An Inane Question") match { + case Result.Yes => "Ewww!" + case Result.No => "Me neither!" + case _ => "Come on -- tell me!" } case `ynp` => val options = List("Yes, please", "No, thanks", "No eggs, no ham!") - showOptions(buttons, + label.text = showOptions(buttons, "Would you like some green eggs to go with that ham?", "A Silly Question", - Options.YesNo, Message.Question, - Swing.EmptyIcon, options, 2) match { - case Result.Yes => label.text = "You're kidding!" - case Result.No => label.text = "I don't like them, either." - case _ => label.text = "Come on -- 'fess up!" + entries = options, + initial = 2) match { + case Result.Yes => "You're kidding!" + case Result.No => "I don't like them, either." + case _ => "Come on -- 'fess up!" } case `yncp` => val options = List("Yes, please", "No, thanks", "No eggs, no ham!") - showOptions(buttons, - "Would you like some green eggs to go with that ham?", - "A Silly Question", - Options.YesNoCancel, Message.Question, - Swing.EmptyIcon, options, 2) match { - case Result.Yes => label.text = "Here you go: green eggs and ham!" - case Result.No => label.text = "OK, just the ham, then." - case Result.Cancel => label.text = "Well, I'm certainly not going to eat them!" - case _ => label.text = "Please tell me what you want!" + label.text = showOptions(buttons, + message = "Would you like some green eggs to go with that ham?", + title = "A Silly Question", + entries = options, + initial = 2) match { + case Result.Yes => "Here you go: green eggs and ham!" + case Result.No => "OK, just the ham, then." + case Result.Cancel => "Well, I'm certainly not going to eat them!" + case _ => "Please tell me what you want!" } } })) = Position.South @@ -117,30 +118,30 @@ object Dialogs extends SimpleGUIApplication { case `pick` => val possibilities = List("ham", "spam", "yam") val s = showInput(buttons, - "Complete the sentence:\n" - + "\"Green eggs and...\"", + "Complete the sentence:\n\"Green eggs and...\"", "Customized Dialog", - Message.Plain, Swing.EmptyIcon, + Message.Plain, + Swing.EmptyIcon, possibilities, "ham") - //If a string was returned, say so. - if ((s != None) && (s.get.length > 0)) - label.text = "Green eggs and... " + s.get + "!" + //If a string was returned, say so. + label.text = if ((s != None) && (s.get.length > 0)) + "Green eggs and... " + s.get + "!" else - label.text = "Come on, finish the sentence!" + "Come on, finish the sentence!" case `enter` => val s = showInput(buttons, - "Complete the sentence:\n" - + "\"Green eggs and...\"", + "Complete the sentence:\n\"Green eggs and...\"", "Customized Dialog", - Message.Plain, Swing.EmptyIcon, + Message.Plain, + Swing.EmptyIcon, Nil, "ham") - //If a string was returned, say so. - if ((s != None) && (s.get.length > 0)) - label.text = "Green eggs and... " + s.get + "!" + //If a string was returned, say so. + label.text = if ((s != None) && (s.get.length > 0)) + "Green eggs and... " + s.get + "!" else - label.text = "Come on, finish the sentence!" + "Come on, finish the sentence!" case `custom` => val dialog = new Dialog(top) dialog.open() diff --git a/src/swing/scala/swing/test/LinePainting.scala b/src/swing/scala/swing/test/LinePainting.scala index 946d267ece..fdccb226a7 100644 --- a/src/swing/scala/swing/test/LinePainting.scala +++ b/src/swing/scala/swing/test/LinePainting.scala @@ -17,7 +17,6 @@ object LinePainting extends SimpleGUIApplication { focusable = true listenTo(mouse.clicks, mouse.moves, keys) - reactions += { case e: MousePressed => moveTo(e.point) diff --git a/src/swing/scala/swing/test/TableSelection.scala b/src/swing/scala/swing/test/TableSelection.scala index 52d50e39aa..e7218da9be 100644 --- a/src/swing/scala/swing/test/TableSelection.scala +++ b/src/swing/scala/swing/test/TableSelection.scala @@ -10,15 +10,18 @@ object TableSelection extends SimpleGUIApplication { List("Kathy", "Walrath", "Knitting", 5, false).toArray, List("Sharon", "Zakhour", "Speed reading", 5, false).toArray, List("Philip", "Milne", "Pool", 5, false).toArray) + /*val model = Array.tabulate(10000) { i => + List("Mary", "Campione", "Snowboarding", i, false).toArray + }*/ lazy val ui = new BoxPanel(Orientation.Vertical) { val table = new Table(model, Array("First Name", "Last Name", "Sport", "# of Years", "Vegetarian")) { preferredViewportSize = new Dimension(500, 70) val l = new Table.LabelRenderer[String] - override def rendererComponent(isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component = + override def rendererComponent(isSelected: Boolean, focused: Boolean, row: Int, column: Int): Component = this(row, column) match { - case s: String => l.componentFor(this, isSelected, hasFocus, s, row, column) - case _ => super.rendererComponent(isSelected, hasFocus, row, column) + case s: String => l.componentFor(this, isSelected, focused, s, row, column) + case _ => super.rendererComponent(isSelected, focused, row, column) } } //1.6:table.fillsViewportHeight = true diff --git a/src/swing/scala/swing/test/UIDemo.scala b/src/swing/scala/swing/test/UIDemo.scala index b1bab2ace1..5382db8281 100644 --- a/src/swing/scala/swing/test/UIDemo.scala +++ b/src/swing/scala/swing/test/UIDemo.scala @@ -7,7 +7,6 @@ import Swing._ object UIDemo extends SimpleGUIApplication { def top = new MainFrame { title = "UIElement Test" - menuBar = new MenuBar val menu = new Menu("A Menu") -- cgit v1.2.3