diff options
Diffstat (limited to 'src')
25 files changed, 221 insertions, 189 deletions
diff --git a/src/swing/doc/README b/src/swing/doc/README index efc60275a1..dcd7470130 100644 --- a/src/swing/doc/README +++ b/src/swing/doc/README @@ -1,4 +1,4 @@ -scala.swing +scala.swing BETA This is a UI library that will wrap most of Java Swing for Scala in a straightforward manner. The widget class hierarchy loosely resembles that of Java Swing. The main differences are: @@ -33,6 +33,7 @@ The library comprises three main packages: Notes: -Visual appearance of combo boxes using the GTK LaF is broken on JDKs < 1.7b30. +Visual appearance of combo boxes using the GTK LaF is broken on JDKs < 1.7b30. +This is a Java Swing problem. To download the latest version, go to http://lamp.epfl.ch/~imaier or use sbaz.
\ No newline at end of file diff --git a/src/swing/scala/swing/Border.scala b/src/swing/scala/swing/Border.scala deleted file mode 100644 index bdc347763e..0000000000 --- a/src/swing/scala/swing/Border.scala +++ /dev/null @@ -1,61 +0,0 @@ -package scala.swing - -import java.awt.Color -import javax.swing.{Icon, BorderFactory} -import javax.swing.border._ - -/** - * Helper object for creating <code>java.awt.Border</code>s more conveniently. - * - * @see javax.swing.BorderFactory - */ -object Border { - def Empty = BorderFactory.createEmptyBorder() - def Empty(weight: Int) = - BorderFactory.createEmptyBorder(weight, weight, weight, weight) - def Empty(top: Int, left: Int, bottom: Int, right: Int) = - BorderFactory.createEmptyBorder(top, left, bottom, right) - - def Line(c: Color) = BorderFactory.createLineBorder(c) - def Line(c: Color, weight: Int) = BorderFactory.createLineBorder(c, weight) - - def Beveled(kind: Embossing) = BorderFactory.createBevelBorder(kind.bevelPeer) - def Beveled(kind: Embossing, highlight: Color, shadow: Color) = - BorderFactory.createBevelBorder(kind.bevelPeer, highlight, shadow) - def Beveled(kind: Embossing, - highlightOuter: Color, highlightInner: Color, - shadowOuter: Color, shadowInner: Color) = - BorderFactory.createBevelBorder(kind.bevelPeer, - highlightOuter, highlightInner, - shadowOuter, shadowInner) - - sealed abstract class Embossing { - def bevelPeer: Int - def etchPeer: Int - } - case object Lowered extends Embossing { - def bevelPeer = BevelBorder.LOWERED - def etchPeer = EtchedBorder.LOWERED - } - case object Raised extends Embossing { - def bevelPeer = BevelBorder.RAISED - def etchPeer = EtchedBorder.RAISED - } - - def Etched = BorderFactory.createEtchedBorder() - def Etched(kind: Embossing) = - BorderFactory.createEtchedBorder(kind.etchPeer) - def Etched(kind: Embossing, highlight: Color, shadow: Color) = - BorderFactory.createEtchedBorder(kind.etchPeer, highlight, shadow) - - def Matte(top: Int, left: Int, bottom: Int, right: Int, color: Color) = - BorderFactory.createMatteBorder(top, left, bottom, right, color) - def Matte(top: Int, left: Int, bottom: Int, right: Int, icon: Icon) = - BorderFactory.createMatteBorder(top, left, bottom, right, icon) - - def Compound(outside: Border, inside: Border) = - BorderFactory.createCompoundBorder(outside, inside) - - def Titled(border: Border, title: String) = - BorderFactory.createTitledBorder(border, title) -}
\ No newline at end of file diff --git a/src/swing/scala/swing/Component.scala b/src/swing/scala/swing/Component.scala index 27ddde51bd..7f3b004299 100644 --- a/src/swing/scala/swing/Component.scala +++ b/src/swing/scala/swing/Component.scala @@ -127,15 +127,15 @@ abstract class Component extends UIElement with Publisher { def mouseExited(e: java.awt.event.MouseEvent) { } def mouseClicked(e: java.awt.event.MouseEvent) { publish(MouseClicked(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers, e.getClickCount, e.isPopupTrigger)) + e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e.getWhen)) } def mousePressed(e: java.awt.event.MouseEvent) { publish(MousePressed(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers, e.getClickCount, e.isPopupTrigger)) + e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e.getWhen)) } def mouseReleased(e: java.awt.event.MouseEvent) { publish(MouseReleased(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers, e.getClickCount, e.isPopupTrigger)) + e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e.getWhen)) } }) } @@ -146,11 +146,11 @@ abstract class Component extends UIElement with Publisher { peer.addMouseListener(new MouseListener { def mouseEntered(e: java.awt.event.MouseEvent) { publish(MouseEntered(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers)) + e.getPoint, e.getModifiersEx)(e.getWhen)) } def mouseExited(e: java.awt.event.MouseEvent) { publish(MouseExited(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers)) + e.getPoint, e.getModifiersEx)(e.getWhen)) } def mouseClicked(e: java.awt.event.MouseEvent) {} def mousePressed(e: java.awt.event.MouseEvent) { } @@ -159,11 +159,11 @@ abstract class Component extends UIElement with Publisher { peer.addMouseMotionListener(new MouseMotionListener { def mouseMoved(e: java.awt.event.MouseEvent) { publish(MouseMoved(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers)) + e.getPoint, e.getModifiersEx)(e.getWhen)) } def mouseDragged(e: java.awt.event.MouseEvent) { publish(MouseDragged(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers)) + e.getPoint, e.getModifiersEx)(e.getWhen)) } }) } @@ -174,7 +174,7 @@ abstract class Component extends UIElement with Publisher { peer.addMouseWheelListener(new MouseWheelListener { def mouseWheelMoved(e: java.awt.event.MouseWheelEvent) { publish(MouseWheelMoved(Component.wrapperFor(e.getSource.asInstanceOf[JComponent]), - e.getPoint, e.getModifiers, e.getWheelRotation)) } + e.getPoint, e.getModifiersEx, e.getWheelRotation)(e.getWhen)) } }) } } diff --git a/src/swing/scala/swing/Dialog.scala b/src/swing/scala/swing/Dialog.scala index e7a2c7c02b..05928b5dc1 100644 --- a/src/swing/scala/swing/Dialog.scala +++ b/src/swing/scala/swing/Dialog.scala @@ -28,7 +28,7 @@ object Dialog { def showConfirmation(parent: Component, message: String, title: String, optionType: Options.Value, messageType: Message.Value, icon: Icon): Result.Value = Result(JOptionPane.showConfirmDialog(parent.peer, message, title, - optionType.id, messageType.id, Icon.wrap(icon))) + optionType.id, messageType.id, Swing.wrapIcon(icon))) def showConfirmation(parent: Component, message: String, title: String, optionType: Options.Value): Result.Value = Result(JOptionPane.showConfirmDialog(parent.peer, message, title, @@ -38,7 +38,7 @@ object Dialog { optionType: Options.Value, messageType: Message.Value, icon: Icon, entries: Seq[Any], initialEntry: Int): Result.Value = { val r = JOptionPane.showOptionDialog(parent.peer, message, title, - optionType.id, messageType.id, Icon.wrap(icon), + optionType.id, messageType.id, Swing.wrapIcon(icon), entries.map(_.asInstanceOf[AnyRef]).toArray, entries(initialEntry)) Result(r) } @@ -49,14 +49,14 @@ object Dialog { val e = if (entries.isEmpty) null else entries.map(_.asInstanceOf[AnyRef]).toArray val r = JOptionPane.showInputDialog(parent.peer, message, title, - messageType.id, Icon.wrap(icon), + messageType.id, Swing.wrapIcon(icon), e, initialEntry) Swing.toOption(r) } def showMessage(parent: Component, message: String, title: String, messageType: Message.Value, icon: Icon) { JOptionPane.showMessageDialog(parent.peer, message, title, - messageType.id, Icon.wrap(icon)) + messageType.id, Swing.wrapIcon(icon)) } def showMessage(parent: Component, message: String) { diff --git a/src/swing/scala/swing/Icon.scala b/src/swing/scala/swing/Icon.scala deleted file mode 100644 index 44e8af337b..0000000000 --- a/src/swing/scala/swing/Icon.scala +++ /dev/null @@ -1,21 +0,0 @@ -package scala.swing - -import javax.swing._ - -/** - * Helper object for icons. - */ -object Icon { - /** - * The empty icon. Use this icon instead of <code>null</code> to indicate - * that you don't want an icon. - */ - case object Empty extends Icon { - def getIconHeight: Int = 0 - def getIconWidth: Int = 0 - def paintIcon(c: java.awt.Component, g: java.awt.Graphics, x: Int, y: Int) {} - } - - def unwrap(icon: Icon): Icon = if (icon == null) Empty else icon - def wrap(icon: Icon): Icon = if (icon == Empty) null else icon -} diff --git a/src/swing/scala/swing/Slider.scala b/src/swing/scala/swing/Slider.scala index e33d079c13..348fdc0c4e 100644 --- a/src/swing/scala/swing/Slider.scala +++ b/src/swing/scala/swing/Slider.scala @@ -43,7 +43,7 @@ class Slider extends Component with Orientable with Publisher { peer.addChangeListener(new javax.swing.event.ChangeListener { def stateChanged(e: javax.swing.event.ChangeEvent) { - publish(ValueChanged(Slider.this, peer.getValueIsAdjusting)) + publish(ValueChanged(Slider.this)(peer.getValueIsAdjusting)) } }) }
\ No newline at end of file diff --git a/src/swing/scala/swing/Swing.scala b/src/swing/scala/swing/Swing.scala index 445c9c85f8..3026cf4dd2 100644 --- a/src/swing/scala/swing/Swing.scala +++ b/src/swing/scala/swing/Swing.scala @@ -1,9 +1,10 @@ package scala.swing -import java.awt.Dimension import java.awt.event._ -import javax.swing._ import javax.swing.event._ +import java.awt.{Color, Dimension} +import javax.swing.border._ +import javax.swing.{JComponent, Icon, BorderFactory} /** * Helpers for this package. @@ -12,8 +13,8 @@ object Swing { protected[swing] def ifNull[A](o: Object, a: A): A = if(o eq null) a else o.asInstanceOf[A] protected[swing] def toOption[A](o: Object): Option[A] = if(o eq null) None else Some(o.asInstanceOf[A]) protected[swing] def toNull[A>:Null<:AnyRef](a: Option[A]): A = if(a == None) null else a.get - protected[swing] def toNoIcon(i: Icon): Icon = if(i == null) swing.Icon.Empty else i - protected[swing] def toNullIcon(i: Icon): Icon = if(i == swing.Icon.Empty) null else i + protected[swing] def toNoIcon(i: Icon): Icon = if(i == null) EmptyIcon else i + protected[swing] def toNullIcon(i: Icon): Icon = if(i == EmptyIcon) null else i implicit def block2Runnable(block: =>Unit): Runnable = new Runnable { override def run = block @@ -50,4 +51,66 @@ object Swing { def Icon(image: java.awt.Image) = new javax.swing.ImageIcon(image) def Icon(filename: String) = new javax.swing.ImageIcon(filename) def Icon(url: java.net.URL) = new javax.swing.ImageIcon(url) + + /** + * The empty icon. Use this icon instead of <code>null</code> to indicate + * that you don't want an icon. + */ + case object EmptyIcon extends Icon { + def getIconHeight: Int = 0 + def getIconWidth: Int = 0 + def paintIcon(c: java.awt.Component, g: java.awt.Graphics, x: Int, y: Int) {} + } + + def unwrapIcon(icon: Icon): Icon = if (icon == null) EmptyIcon else icon + def wrapIcon(icon: Icon): Icon = if (icon == EmptyIcon) null else icon + + def EmptyBorder = BorderFactory.createEmptyBorder() + def EmptyBorder(weight: Int) = + BorderFactory.createEmptyBorder(weight, weight, weight, weight) + def EmptyBorder(top: Int, left: Int, bottom: Int, right: Int) = + BorderFactory.createEmptyBorder(top, left, bottom, right) + + def LineBorder(c: Color) = BorderFactory.createLineBorder(c) + def LineBorder(c: Color, weight: Int) = BorderFactory.createLineBorder(c, weight) + + def BeveledBorder(kind: Embossing) = BorderFactory.createBevelBorder(kind.bevelPeer) + def BeveledBorder(kind: Embossing, highlight: Color, shadow: Color) = + BorderFactory.createBevelBorder(kind.bevelPeer, highlight, shadow) + def BeveledBorder(kind: Embossing, + highlightOuter: Color, highlightInner: Color, + shadowOuter: Color, shadowInner: Color) = + BorderFactory.createBevelBorder(kind.bevelPeer, + highlightOuter, highlightInner, + shadowOuter, shadowInner) + + sealed abstract class Embossing { + def bevelPeer: Int + def etchPeer: Int + } + case object Lowered extends Embossing { + def bevelPeer = BevelBorder.LOWERED + def etchPeer = javax.swing.border.EtchedBorder.LOWERED + } + case object Raised extends Embossing { + def bevelPeer = BevelBorder.RAISED + def etchPeer = javax.swing.border.EtchedBorder.RAISED + } + + def EtchedBorder = BorderFactory.createEtchedBorder() + def EtchedBorder(kind: Embossing) = + BorderFactory.createEtchedBorder(kind.etchPeer) + def EtchedBorder(kind: Embossing, highlight: Color, shadow: Color) = + BorderFactory.createEtchedBorder(kind.etchPeer, highlight, shadow) + + def MatteBorder(top: Int, left: Int, bottom: Int, right: Int, color: Color) = + BorderFactory.createMatteBorder(top, left, bottom, right, color) + def MatteBorder(top: Int, left: Int, bottom: Int, right: Int, icon: Icon) = + BorderFactory.createMatteBorder(top, left, bottom, right, icon) + + def CompoundBorder(outside: Border, inside: Border) = + BorderFactory.createCompoundBorder(outside, inside) + + def TitledBorder(border: Border, title: String) = + BorderFactory.createTitledBorder(border, title) } diff --git a/src/swing/scala/swing/TextComponent.scala b/src/swing/scala/swing/TextComponent.scala index e24940680e..712c524978 100644 --- a/src/swing/scala/swing/TextComponent.scala +++ b/src/swing/scala/swing/TextComponent.scala @@ -56,9 +56,9 @@ class TextComponent extends Component with Publisher { def selectAll() { peer.selectAll() } peer.getDocument.addDocumentListener(new DocumentListener { - def changedUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this, true)) } - def insertUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this, true)) } - def removeUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this, true)) } + def changedUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this)(true)) } + def insertUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this)(true)) } + def removeUpdate(e:DocumentEvent) { publish(ValueChanged(TextComponent.this)(true)) } }) } diff --git a/src/swing/scala/swing/TextField.scala b/src/swing/scala/swing/TextField.scala index 3844c8c515..d32aa8fa4d 100644 --- a/src/swing/scala/swing/TextField.scala +++ b/src/swing/scala/swing/TextField.scala @@ -4,6 +4,16 @@ import javax.swing._ import java.awt.event._ import event._ + +/*object TextField { + object FocusLostBehavior extends Enumeration { + val Revert = Value(JFormattedTextField.REVERT) + val Commit = Value(JFormattedTextField.REVERT) + val CommitOrRevert = Value(JFormattedTextField.REVERT) + val Persist = Value(JFormattedTextField.REVERT) + } +}*/ + /** * A text component that allows single line text input and display. * @@ -19,6 +29,26 @@ class TextField(text0: String, columns0: Int) extends TextComponent with TextCom def columns_=(n: Int) = peer.setColumns(n) peer.addActionListener(Swing.ActionListener { e => - publish(ValueChanged(TextField.this, false)) + publish(ValueChanged(TextField.this)(false)) }) + + peer.addFocusListener(new FocusAdapter { + override def focusLost(e: java.awt.event.FocusEvent) { ValueChanged(TextField.this)(true) } + }) + + def verifier: String => Boolean = s => peer.getInputVerifier.verify(peer) + def verifier_=(v: String => Boolean) { + peer.setInputVerifier(new InputVerifier { + def verify(c: JComponent) = v(text) + override def shouldYieldFocus(c: JComponent) = + peer.getInputVerifier.shouldYieldFocus(c) + }) + } + def shouldYieldFocus: String=>Boolean = s => peer.getInputVerifier.shouldYieldFocus(peer) + def shouldYieldFocus_=(y: String=>Boolean) { + peer.setInputVerifier(new InputVerifier { + def verify(c: JComponent) = peer.getInputVerifier.verify(c) + override def shouldYieldFocus(c: JComponent) = y(text) + }) + } } diff --git a/src/swing/scala/swing/Views.scala b/src/swing/scala/swing/Views.scala index 4afe32f956..0b7305e54d 100644 --- a/src/swing/scala/swing/Views.scala +++ b/src/swing/scala/swing/Views.scala @@ -1,7 +1,7 @@ package scala.swing -object Views { +//object Views { //implicit def action2MenuItem(a: Action): MenuItem = new MenuItem(a) //implicit def action2Button(a: Action): Button = new Button(a) //implicit def string2Label(s: String): Label = new Label(s) -} +//} diff --git a/src/swing/scala/swing/event/ActionEvent.scala b/src/swing/scala/swing/event/ActionEvent.scala index e1020fe82c..c800f20a69 100644 --- a/src/swing/scala/swing/event/ActionEvent.scala +++ b/src/swing/scala/swing/event/ActionEvent.scala @@ -1,7 +1,3 @@ package scala.swing.event -object ActionEvent { - def unapply(e: ActionEvent): Option[Component] = Some(e.source) -} - -trait ActionEvent extends ComponentEvent +case class ActionEvent(override val source: Component) extends ComponentEvent diff --git a/src/swing/scala/swing/event/AdjustingEvent.scala b/src/swing/scala/swing/event/AdjustingEvent.scala new file mode 100644 index 0000000000..e06256ea4f --- /dev/null +++ b/src/swing/scala/swing/event/AdjustingEvent.scala @@ -0,0 +1,11 @@ +package scala.swing.event + +/** + * An event that indicates some editing operation that can be still in progress. + * Example: dragging a slider creates a number of AdjustmentEvents with + * adjusting == true until the user finally releases the mouse button. + */ +trait AdjustingEvent extends ComponentEvent { + def adjusting: Boolean + def committed: Boolean = !adjusting +}
\ No newline at end of file diff --git a/src/swing/scala/swing/event/ButtonClicked.scala b/src/swing/scala/swing/event/ButtonClicked.scala index ce5b0c7cdd..1f9049a03f 100644 --- a/src/swing/scala/swing/event/ButtonClicked.scala +++ b/src/swing/scala/swing/event/ButtonClicked.scala @@ -1,4 +1,4 @@ package scala.swing.event -case class ButtonClicked(override val source: AbstractButton) extends ComponentEvent with ActionEvent +case class ButtonClicked(override val source: AbstractButton) extends ActionEvent(source) diff --git a/src/swing/scala/swing/event/InputEvent.scala b/src/swing/scala/swing/event/InputEvent.scala new file mode 100644 index 0000000000..ae24d537a7 --- /dev/null +++ b/src/swing/scala/swing/event/InputEvent.scala @@ -0,0 +1,6 @@ +package scala.swing.event + +trait InputEvent extends ComponentEvent { + val when: Long + val modifiers: Int +} diff --git a/src/swing/scala/swing/event/ListEvent.scala b/src/swing/scala/swing/event/ListEvent.scala index efae65b24d..1768d84955 100644 --- a/src/swing/scala/swing/event/ListEvent.scala +++ b/src/swing/scala/swing/event/ListEvent.scala @@ -5,12 +5,28 @@ trait ListEvent[A] extends ComponentEvent { } //case class ElementSelected[A](override val source: ListView[A], range: Range, live: Boolean) -// extends ListEvent[A] with LiveEvent with ListSelectionEvent +// extends ListEvent[A] with AdjustingEvent with ListSelectionEvent abstract class ListChange[A](override val source: ListView[A]) extends ListEvent[A] -case class ListChanged[A](override val source: ListView[A]) extends ListChange(source) -case class ListElementsAdded[A](override val source: ListView[A], range: Range) +object ListChanged { + def unapply[A](e: ListChanged[A]) = Some(e.source) + def apply[A](source: ListView[A]) = new ListChanged(source) +} + +class ListChanged[A](override val source: ListView[A]) extends ListChange(source) + +object ListElementsAdded { + def unapply[A](e: ListElementsAdded[A]) = Some(e.source, e.range) + def apply[A](source: ListView[A], range: Range) = new ListElementsAdded(source, range) +} + +class ListElementsAdded[A](override val source: ListView[A], val range: Range) extends ListChange(source) -case class ListElementsRemoved[A](override val source: ListView[A], range: Range) + +object ListElementsRemoved { + def unapply[A](e: ListElementsRemoved[A]) = Some(e.source, e.range) + def apply[A](source: ListView[A], range: Range) = new ListElementsRemoved(source, range) +} +class ListElementsRemoved[A](override val source: ListView[A], val range: Range) extends ListChange(source)
\ No newline at end of file diff --git a/src/swing/scala/swing/event/LiveEvent.scala b/src/swing/scala/swing/event/LiveEvent.scala deleted file mode 100644 index 868a2d0164..0000000000 --- a/src/swing/scala/swing/event/LiveEvent.scala +++ /dev/null @@ -1,14 +0,0 @@ -package scala.swing.event - -object LiveEvent { - def unapply(e: LiveEvent): Option[(Component, Boolean)] = Some(e.source, e.live) -} - -/** - * An event that indicates some editing operation that can be explicitly - * finished by some final action. Example: entering text in a text field - * (not a text area) is finalized not before the user hits enter. - */ -trait LiveEvent extends ComponentEvent { - def live: Boolean -} diff --git a/src/swing/scala/swing/event/MouseEvent.scala b/src/swing/scala/swing/event/MouseEvent.scala index a9c43eb536..3b671bfa6b 100644 --- a/src/swing/scala/swing/event/MouseEvent.scala +++ b/src/swing/scala/swing/event/MouseEvent.scala @@ -2,31 +2,31 @@ package scala.swing.event import java.awt.Point -class MouseEvent(val source: Component, point: Point, modifiers: Int) extends ComponentEvent +class MouseEvent(val source: Component, point: Point, val modifiers: Int)(val when: Long) extends InputEvent -class MouseButtonEvent(override val source: Component, point: Point, modifiers: Int, - clicks: Int, triggersPopup: Boolean) - extends MouseEvent(source, point, modifiers) -case class MouseClicked(override val source: Component, point: Point, modifiers: Int, - clicks: Int, triggersPopup: Boolean) - extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup) -case class MousePressed(override val source: Component, point: Point, modifiers: Int, - clicks: Int, triggersPopup: Boolean) - extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup) -case class MouseReleased(override val source: Component, point: Point, modifiers: Int, - clicks: Int, triggersPopup: Boolean) - extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup) +class MouseButtonEvent(source: Component, point: Point, override val modifiers: Int, + clicks: Int, triggersPopup: Boolean)(when: Long) + extends MouseEvent(source, point, modifiers)(when) +case class MouseClicked(override val source: Component, point: Point, override val modifiers: Int, + clicks: Int, triggersPopup: Boolean)(when: Long) + extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup)(when) +case class MousePressed(override val source: Component, point: Point, override val modifiers: Int, + clicks: Int, triggersPopup: Boolean)(when: Long) + extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup)(when) +case class MouseReleased(override val source: Component, point: Point, override val modifiers: Int, + clicks: Int, triggersPopup: Boolean)(when: Long) + extends MouseButtonEvent(source, point, modifiers, clicks, triggersPopup)(when) -class MouseMotionEvent(override val source: Component, point: Point, modifiers: Int) - extends MouseEvent(source, point, modifiers) -case class MouseMoved(override val source: Component, point: Point, modifiers: Int) - extends MouseMotionEvent(source, point, modifiers) -case class MouseDragged(override val source: Component, point: Point, modifiers: Int) - extends MouseMotionEvent(source, point, modifiers) -case class MouseEntered(override val source: Component, point: Point, modifiers: Int) - extends MouseMotionEvent(source, point, modifiers) -case class MouseExited(override val source: Component, point: Point, modifiers: Int) - extends MouseMotionEvent(source, point, modifiers) +class MouseMotionEvent(source: Component, point: Point, modifiers: Int)(when: Long) + extends MouseEvent(source, point, modifiers)(when) +case class MouseMoved(override val source: Component, point: Point, override val modifiers: Int)(when: Long) + extends MouseMotionEvent(source, point, modifiers)(when) +case class MouseDragged(override val source: Component, point: Point, override val modifiers: Int)(when: Long) + extends MouseMotionEvent(source, point, modifiers)(when) +case class MouseEntered(override val source: Component, point: Point, override val modifiers: Int)(when: Long) + extends MouseMotionEvent(source, point, modifiers)(when) +case class MouseExited(override val source: Component, point: Point, override val modifiers: Int)(when: Long) + extends MouseMotionEvent(source, point, modifiers)(when) -case class MouseWheelMoved(override val source: Component, point: Point, modifiers: Int, rotation: Int) - extends MouseEvent(source, point, modifiers)
\ No newline at end of file +case class MouseWheelMoved(override val source: Component, point: Point, override val modifiers: Int, rotation: Int)(when: Long) + extends MouseEvent(source, point, modifiers)(when)
\ No newline at end of file diff --git a/src/swing/scala/swing/event/TableEvent.scala b/src/swing/scala/swing/event/TableEvent.scala index bf39a21001..390ae211d8 100644 --- a/src/swing/scala/swing/event/TableEvent.scala +++ b/src/swing/scala/swing/event/TableEvent.scala @@ -29,7 +29,7 @@ case class TableResized(override val source: Table) extends TableChange(source) case class TableRowsAdded(override val source: Table, range: Range) extends TableResized(source) case class TableRowsRemoved(override val source: Table, range: Range) extends TableResized(source) -case class TableColumnsSelected(override val source: Table, range: Range, live: Boolean) - extends TableEvent(source) with LiveEvent with ListSelectionEvent -case class TableRowsSelected(override val source: Table, range: Range, live: Boolean) - extends TableEvent(source) with LiveEvent with ListSelectionEvent
\ No newline at end of file +case class TableColumnsSelected(override val source: Table, range: Range, adjusting: Boolean) + extends TableEvent(source) with AdjustingEvent with ListSelectionEvent +case class TableRowsSelected(override val source: Table, range: Range, adjusting: Boolean) + extends TableEvent(source) with AdjustingEvent with ListSelectionEvent
\ No newline at end of file diff --git a/src/swing/scala/swing/event/ValueChanged.scala b/src/swing/scala/swing/event/ValueChanged.scala index 93faa92541..991a6b6570 100644 --- a/src/swing/scala/swing/event/ValueChanged.scala +++ b/src/swing/scala/swing/event/ValueChanged.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class ValueChanged(override val source: Component, live: Boolean) extends ComponentEvent with LiveEvent +case class ValueChanged(override val source: Component)(val adjusting: Boolean) extends ComponentEvent with AdjustingEvent diff --git a/src/swing/scala/swing/test/CelsiusConverter.scala b/src/swing/scala/swing/test/CelsiusConverter.scala index baa644b30a..a4c1921606 100644 --- a/src/swing/scala/swing/test/CelsiusConverter.scala +++ b/src/swing/scala/swing/test/CelsiusConverter.scala @@ -8,11 +8,10 @@ import event._ object CelsiusConverter extends SimpleGUIApplication { def top = new MainFrame { title = "Convert Celsius to Fahrenheit" - defaultButton = Some(convertButton) val tempCelsius = new TextField val celsiusLabel = new Label { text = "Celsius" - border = Border.Empty(5, 5, 5, 5) + border = Swing.EmptyBorder(5, 5, 5, 5) } val convertButton = new Button { text = "Convert"//new javax.swing.ImageIcon("c:\\workspace\\gui\\images\\convert.gif") @@ -20,19 +19,25 @@ object CelsiusConverter extends SimpleGUIApplication { } val fahrenheitLabel = new Label { text = "Fahrenheit " - border = Border.Empty(5, 5, 5, 5) + border = Swing.EmptyBorder(5, 5, 5, 5) listenTo(convertButton, tempCelsius) + + def convert() { + val c = Integer.parseInt(tempCelsius.text) + val f = c * 9 / 5 + 32 + text = "<html><font color = red>"+f+"</font> Fahrenheit</html>" + } + reactions += { - case ButtonClicked(_) | ValueChanged(_,false) => - val c = Integer.parseInt(tempCelsius.text) - val f = c * 9 / 5 + 32 - text = "<html><font color = red>"+f+"</font> Fahrenheit</html>" + case ButtonClicked(_) => convert() + case v @ ValueChanged(_) if v.committed => convert() } } contents = new GridPanel(2,2) { contents.append(tempCelsius, celsiusLabel, convertButton, fahrenheitLabel) - border = Border.Empty(10, 10, 10, 10) + border = Swing.EmptyBorder(10, 10, 10, 10) } + defaultButton = Some(convertButton) } } diff --git a/src/swing/scala/swing/test/CelsiusConverter2.scala b/src/swing/scala/swing/test/CelsiusConverter2.scala index 200fd67d4b..0b382ba96b 100644 --- a/src/swing/scala/swing/test/CelsiusConverter2.scala +++ b/src/swing/scala/swing/test/CelsiusConverter2.scala @@ -9,15 +9,15 @@ object CelsiusConverter2 extends SimpleGUIApplication { val Fahrenheit = new TextField { columns = 5 } contents.append(Celsius, new Label(" Celsius = "), Fahrenheit, new Label(" Fahrenheit")) - border = Border.Empty(15, 10, 10, 10) + border = Swing.EmptyBorder(15, 10, 10, 10) listenTo(Fahrenheit, Celsius) reactions += { - case ValueChanged(Fahrenheit, false) => + case v @ ValueChanged(Fahrenheit) if v.committed => val f = Integer.parseInt(Fahrenheit.text) val c = (f - 32) * 5 / 9 Celsius.text = c.toString - case ValueChanged(Celsius, false) => + case v @ ValueChanged(Celsius) if v.committed => val c = Integer.parseInt(Celsius.text) val f = c * 9 / 5 + 32 Fahrenheit.text = f.toString diff --git a/src/swing/scala/swing/test/ComboBoxes.scala b/src/swing/scala/swing/test/ComboBoxes.scala index 2d0767f299..c5e730a1a5 100644 --- a/src/swing/scala/swing/test/ComboBoxes.scala +++ b/src/swing/scala/swing/test/ComboBoxes.scala @@ -59,7 +59,7 @@ object ComboBoxes extends SimpleGUIApplication { } catch { case _ => println("Couldn't load images for combo box") - List(scala.swing.Icon.Empty) + List(Swing.EmptyIcon) } val iconBox = new ComboBox(icons) { @@ -68,9 +68,9 @@ object ComboBoxes extends SimpleGUIApplication { component.icon = icon component.xAlignment = Alignment.Center if(isSelected) { - component.border = Border.Line(list.selectionBackground, 3) + component.border = Swing.LineBorder(list.selectionBackground, 3) } else { - component.border = Border.Empty(3) + component.border = Swing.EmptyBorder(3) } } } diff --git a/src/swing/scala/swing/test/Dialogs.scala b/src/swing/scala/swing/test/Dialogs.scala index a126d7f9c9..dfee916fb1 100644 --- a/src/swing/scala/swing/test/Dialogs.scala +++ b/src/swing/scala/swing/test/Dialogs.scala @@ -38,7 +38,7 @@ object Dialogs extends SimpleGUIApplication { c.ipadx = 50 layout(buttonText) = c - border = Border.Empty(5, 5, 5, 5) + border = Swing.EmptyBorder(5, 5, 5, 5) }) pages += new Page("Simple Modal Dialogs", new BorderPanel { import BorderPanel._ @@ -74,7 +74,7 @@ object Dialogs extends SimpleGUIApplication { "Would you like some green eggs to go with that ham?", "A Silly Question", Options.YesNo, Message.Question, - Icon.Empty, options, 2) match { + 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!" @@ -87,7 +87,7 @@ object Dialogs extends SimpleGUIApplication { "Would you like some green eggs to go with that ham?", "A Silly Question", Options.YesNoCancel, Message.Question, - Icon.Empty, options, 2) match { + 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!" @@ -120,7 +120,7 @@ object Dialogs extends SimpleGUIApplication { "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", - Message.Plain, Icon.Empty, + Message.Plain, Swing.EmptyIcon, possibilities, "ham") //If a string was returned, say so. @@ -133,7 +133,7 @@ object Dialogs extends SimpleGUIApplication { "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", - Message.Plain, Icon.Empty, + Message.Plain, Swing.EmptyIcon, Nil, "ham") //If a string was returned, say so. diff --git a/src/swing/scala/swing/test/SwingApp.scala b/src/swing/scala/swing/test/SwingApp.scala index f125ef84c6..b6f4e53771 100644 --- a/src/swing/scala/swing/test/SwingApp.scala +++ b/src/swing/scala/swing/test/SwingApp.scala @@ -22,7 +22,7 @@ object SwingApp extends SimpleGUIApplication { } contents = new FlowPanel { contents.append(button, label) - border = Border.Empty(5, 5, 5, 5) + border = Swing.EmptyBorder(5, 5, 5, 5) } } } diff --git a/src/swing/scala/swing/test/UIDemo.scala b/src/swing/scala/swing/test/UIDemo.scala index 880438f97f..8c94b94975 100644 --- a/src/swing/scala/swing/test/UIDemo.scala +++ b/src/swing/scala/swing/test/UIDemo.scala @@ -10,8 +10,6 @@ object UIDemo extends SimpleGUIApplication { menuBar = new MenuBar - import Border._ - val menu = new Menu("A Menu") menu.contents += new MenuItem("An item") menu.contents += new MenuItem(Action("An action item") { @@ -32,14 +30,16 @@ object UIDemo extends SimpleGUIApplication { var reactLive = false + import Swing._ + contents = new BorderPanel { import BorderPanel.Position._ val tabs = new TabbedPane { import TabbedPane._ val buttons = new FlowPanel { - border = Empty(5,5,5,5) + border = Swing.EmptyBorder(5,5,5,5) contents += new BoxPanel(Orientation.Vertical) { - border = Compound(Titled(Etched, "Radio Buttons"), Empty(5,5,5,10)) + border = CompoundBorder(TitledBorder(EtchedBorder, "Radio Buttons"), EmptyBorder(5,5,5,10)) val a = new RadioButton("Green Vegetables") val b = new RadioButton("Red Meat") val c = new RadioButton("White Tofu") @@ -47,7 +47,7 @@ object UIDemo extends SimpleGUIApplication { contents ++= mutex.buttons } contents += new BoxPanel(Orientation.Vertical) { - border = Compound(Titled(Etched, "Check Boxes"), Empty(5,5,5,10)) + border = CompoundBorder(TitledBorder(EtchedBorder, "Check Boxes"), EmptyBorder(5,5,5,10)) val paintLabels = new CheckBox("Paint Labels") val paintTicks = new CheckBox("Paint Ticks") val snapTicks = new CheckBox("Snap To Ticks") @@ -85,7 +85,7 @@ object UIDemo extends SimpleGUIApplication { contents += label listenTo(field) reactions += { - case ValueChanged(`field`, false) => label.text = field.password.mkString + case v @ ValueChanged(`field`) if v.committed => label.text = field.password.mkString } } @@ -116,8 +116,8 @@ object UIDemo extends SimpleGUIApplication { listenTo(tabs.selection) listenTo(list.selection) reactions += { - case ValueChanged(`slider`, live) => - if(!live || live == reactLive) tabs.selection.index = slider.value + case v @ ValueChanged(`slider`) => + if(v.committed || reactLive) tabs.selection.index = slider.value case SelectionChanged(`tabs`) => slider.value = tabs.selection.index list.selection.selectIndices(tabs.selection.index) |