diff --git a/README b/README
index 6e2bbaa..b36342b 100644
--- a/README
+++ b/README
@@ -1,13 +1,13 @@
The scala.swing package
-This is a UI library that will wrap most of Java Swing for Scala in a straightforward manner.
+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 library comprises three main packages:
scala.swing
All widget classes and traits.
-
+
scala.swing.event
The event hierarchy.
diff --git a/doc/README b/doc/README
index cdfee01..e5177ce 100644
--- a/doc/README
+++ b/doc/README
@@ -1,39 +1,39 @@
scala.swing BETA
-This is a UI library that will wrap most of Java Swing for Scala in a straightforward manner.
+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:
- In Java Swing all components are containers per default. This doesn't make much sense for
- a number of components, like TextField, CheckBox, RadioButton, and so on. Our guess is that
- this architecture was chosen because Java lacks multiple inheritance.
+ In Java Swing all components are containers per default. This doesn't make much sense for
+ a number of components, like TextField, CheckBox, RadioButton, and so on. Our guess is that
+ this architecture was chosen because Java lacks multiple inheritance.
In scala.swing, components that can have child components extend the Container trait.
-
- Layout managers and panels are coupled. There is no way to exchange the layout manager
- of a panel. As a result, the layout constraints for widgets can be typed.
- (Note that you gain more type-safety and don't loose much flexibility here. Besides
- being not a common operation, exchanging the layout manager of a panel in Java
- Swing almost always leads to exchanging the layout constraints for every of the panel's
- child component. In the end, it is not more work to move all children to a newly created
+
+ Layout managers and panels are coupled. There is no way to exchange the layout manager
+ of a panel. As a result, the layout constraints for widgets can be typed.
+ (Note that you gain more type-safety and don't loose much flexibility here. Besides
+ being not a common operation, exchanging the layout manager of a panel in Java
+ Swing almost always leads to exchanging the layout constraints for every of the panel's
+ child component. In the end, it is not more work to move all children to a newly created
panel.)
-
+
The event system. TODO
-
+
The library comprises three main packages:
scala.swing
All widget classes and traits.
-
+
scala.swing.event
The event hierarchy.
scala.swing.test
A set of demos.
-
+
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.
diff --git a/scala/swing/AbstractButton.scala b/scala/swing/AbstractButton.scala
index 4325944..ee26a6d 100644
--- a/scala/swing/AbstractButton.scala
+++ b/scala/swing/AbstractButton.scala
@@ -14,9 +14,9 @@ import event._
import javax.swing.{AbstractButton => JAbstractButton, Icon}
/**
- * Base class of all button-like widgets, such as push buttons,
+ * Base class of all button-like widgets, such as push buttons,
* check boxes, and radio buttons.
- *
+ *
* @see javax.swing.AbstractButton
*/
abstract class AbstractButton extends Component with Action.Trigger.Wrapper with Publisher {
@@ -24,7 +24,7 @@ abstract class AbstractButton extends Component with Action.Trigger.Wrapper with
def text: String = peer.getText
def text_=(s: String) = peer.setText(s)
-
+
def icon: Icon = peer.getIcon
def icon_=(i: Icon) = peer.setIcon(i)
def pressedIcon: Icon = peer.getPressedIcon
@@ -39,49 +39,49 @@ abstract class AbstractButton extends Component with Action.Trigger.Wrapper with
def rolloverIcon_=(b: Icon) = peer.setRolloverIcon(b)
def rolloverSelectedIcon: Icon = peer.getRolloverSelectedIcon
def rolloverSelectedIcon_=(b: Icon) = peer.setRolloverSelectedIcon(b)
-
+
peer.addActionListener(Swing.ActionListener { e =>
publish(ButtonClicked(AbstractButton.this))
})
-
+
def selected: Boolean = peer.isSelected
def selected_=(b: Boolean) = peer.setSelected(b)
-
+
def contentAreaFilled: Boolean = peer.isContentAreaFilled
def contentAreaFilled_=(b: Boolean) { peer.setContentAreaFilled(b) }
-
+
def borderPainted: Boolean = peer.isBorderPainted
def borderPainted_=(b: Boolean) { peer.setBorderPainted(b) }
def focusPainted: Boolean = peer.isFocusPainted
def focusPainted_=(b: Boolean) { peer.setFocusPainted(b) }
-
+
def rolloverEnabled: Boolean = peer.isRolloverEnabled
def rolloverEnabled_=(b: Boolean) = peer.setRolloverEnabled(b)
-
+
def verticalTextPosition: Alignment.Value = Alignment(peer.getVerticalTextPosition)
def verticalTextPosition_=(a: Alignment.Value) { peer.setVerticalTextPosition(a.id) }
def verticalAlignment: Alignment.Value = Alignment(peer.getVerticalAlignment)
def verticalAlignment_=(a: Alignment.Value) { peer.setVerticalAlignment(a.id) }
-
+
def horizontalTextPosition: Alignment.Value = Alignment(peer.getHorizontalTextPosition)
def horizontalTextPosition_=(a: Alignment.Value) { peer.setHorizontalTextPosition(a.id) }
def horizontalAlignment: Alignment.Value = Alignment(peer.getHorizontalAlignment)
def horizontalAlignment_=(a: Alignment.Value) { peer.setHorizontalAlignment(a.id) }
-
+
def iconTextGap: Int = peer.getIconTextGap
def iconTextGap_=(x: Int) { peer.setIconTextGap(x) }
-
+
def mnemonic: Key.Value = Key(peer.getMnemonic)
- def mnemonic_=(k: Key.Value) { peer.setMnemonic(k.id) }
+ def mnemonic_=(k: Key.Value) { peer.setMnemonic(k.id) }
def displayedMnemonicIndex: Int = peer.getDisplayedMnemonicIndex
def displayedMnemonicIndex_=(n: Int) { peer.setDisplayedMnemonicIndex(n) }
-
+
def multiClickThreshold: Long = peer.getMultiClickThreshhold
def multiClickThreshold_=(n: Long) { peer.setMultiClickThreshhold(n) }
- def doClick() { peer.doClick() }
+ def doClick() { peer.doClick() }
def doClick(times: Int) { peer.doClick(times) }
-
+
def margin: Insets = peer.getMargin
def margin_=(i: Insets) { peer.setMargin(i) }
}
diff --git a/scala/swing/Action.scala b/scala/swing/Action.scala
index 8d73c23..4c3e92b 100644
--- a/scala/swing/Action.scala
+++ b/scala/swing/Action.scala
@@ -16,74 +16,74 @@ import java.awt.event.ActionListener
object Action {
/**
* Special action that has an empty title and all default properties and does nothing.
- * Use this as a "null action", i.e., to tell components that they do not have any
- * associated action. A component may then obtain its properties from its direct members
+ * Use this as a "null action", i.e., to tell components that they do not have any
+ * associated action. A component may then obtain its properties from its direct members
* instead of from its action.
* In Java Swing, one would use `null` instead of a designated action.
*/
case object NoAction extends Action("") { def apply() {} }
-
+
object Trigger {
- trait Wrapper extends Action.Trigger {
- def peer: javax.swing.JComponent {
- def addActionListener(a: ActionListener)
+ trait Wrapper extends Action.Trigger {
+ def peer: javax.swing.JComponent {
+ def addActionListener(a: ActionListener)
def removeActionListener(a: ActionListener)
def setAction(a: javax.swing.Action)
def getAction(): javax.swing.Action
}
-
+
// TODO: we need an action cache
private var _action: Action = Action.NoAction
def action: Action = _action
def action_=(a: Action) { _action = a; peer.setAction(a.peer) }
-
+
//1.6: def hideActionText: Boolean = peer.getHideActionText
//def hideActionText_=(b: Boolean) = peer.setHideActionText(b)
}
}
-
+
/**
* Something that triggers an action.
*/
trait Trigger {
def action: Action
def action_=(a: Action)
-
+
//1.6: def hideActionText: Boolean
//def hideActionText_=(b: Boolean)
}
-
+
/**
* Convenience method to create an action with a given title and body to run.
*/
- def apply(title: String)(body: =>Unit) = new Action(title) {
+ def apply(title: String)(body: =>Unit) = new Action(title) {
def apply() { body }
}
}
/**
* An abstract action to be performed in reaction to user input.
- *
- * Not every action component will honor every property of its action.
- * An action itself can generally be configured so that certain properties
- * should be ignored and instead taken from the component directly. In the
+ *
+ * Not every action component will honor every property of its action.
+ * An action itself can generally be configured so that certain properties
+ * should be ignored and instead taken from the component directly. In the
* end, it is up to a component which property it uses in which way.
- *
+ *
* @see javax.swing.Action
*/
abstract class Action(title0: String) {
import Swing._
-
+
lazy val peer: javax.swing.Action = new javax.swing.AbstractAction(title0) {
def actionPerformed(a: java.awt.event.ActionEvent) = apply()
}
-
+
/**
* Title is not optional.
*/
def title: String = ifNull(peer.getValue(javax.swing.Action.NAME),"")
def title_=(t: String) { peer.putValue(javax.swing.Action.NAME, t) }
-
+
/**
* None if large icon and small icon are not equal.
*/
@@ -93,65 +93,65 @@ abstract class Action(title0: String) {
// def largeIcon_=(i: Icon) { peer.putValue(javax.swing.Action.LARGE_ICON_KEY, toNullIcon(i)) }
def smallIcon: Icon = toNoIcon(peer.getValue(javax.swing.Action.SMALL_ICON).asInstanceOf[Icon])
def smallIcon_=(i: Icon) { peer.putValue(javax.swing.Action.SMALL_ICON, toNullIcon(i)) }
-
+
/**
* For all components.
*/
- def toolTip: String =
- ifNull(peer.getValue(javax.swing.Action.SHORT_DESCRIPTION), "")
- def toolTip_=(t: String) {
- peer.putValue(javax.swing.Action.SHORT_DESCRIPTION, t)
+ def toolTip: String =
+ ifNull(peer.getValue(javax.swing.Action.SHORT_DESCRIPTION), "")
+ def toolTip_=(t: String) {
+ peer.putValue(javax.swing.Action.SHORT_DESCRIPTION, t)
}
/**
* Can be used for status bars, for example.
*/
- def longDescription: String =
- ifNull(peer.getValue(javax.swing.Action.LONG_DESCRIPTION), "")
- def longDescription_=(t: String) {
- peer.putValue(javax.swing.Action.LONG_DESCRIPTION, t)
+ def longDescription: String =
+ ifNull(peer.getValue(javax.swing.Action.LONG_DESCRIPTION), "")
+ def longDescription_=(t: String) {
+ peer.putValue(javax.swing.Action.LONG_DESCRIPTION, t)
}
-
+
/**
* Default: java.awt.event.KeyEvent.VK_UNDEFINED, i.e., no mnemonic key.
* For all buttons and thus menu items.
*/
- def mnemonic: Int = ifNull(peer.getValue(javax.swing.Action.MNEMONIC_KEY),
+ def mnemonic: Int = ifNull(peer.getValue(javax.swing.Action.MNEMONIC_KEY),
java.awt.event.KeyEvent.VK_UNDEFINED)
def mnemonic_=(m: Int) { peer.putValue(javax.swing.Action.MNEMONIC_KEY, m) }
-
+
/*/**
* Indicates which character of the title should be underlined to indicate the mnemonic key.
- * Ignored if out of bounds of the title string. Default: -1, i.e., ignored.
+ * Ignored if out of bounds of the title string. Default: -1, i.e., ignored.
* For all buttons and thus menu items.
*/
- 1.6: def mnemonicIndex: Int =
+ 1.6: def mnemonicIndex: Int =
ifNull(peer.getValue(javax.swing.Action.DISPLAYED_MNEMONIC_INDEX_KEY), -1)
def mnemonicIndex_=(n: Int) { peer.putValue(javax.swing.Action.DISPLAYED_MNEMONIC_INDEX_KEY, n) }
*/
-
+
/**
* For menus.
*/
- def accelerator: Option[KeyStroke] =
+ def accelerator: Option[KeyStroke] =
toOption(peer.getValue(javax.swing.Action.ACCELERATOR_KEY))
- def accelerator_=(k: Option[KeyStroke]) {
+ def accelerator_=(k: Option[KeyStroke]) {
peer.putValue(javax.swing.Action.ACCELERATOR_KEY, k orNull)
- }
-
+ }
+
/**
* For all components.
*/
- def enabled: Boolean = peer.isEnabled
+ def enabled: Boolean = peer.isEnabled
def enabled_=(b: Boolean) { peer.setEnabled(b) }
-
+
/*/**
* Only honored if not None. For various buttons.
*/
1.6: def selected: Option[Boolean] = Option(peer.getValue(javax.swing.Action.SELECTED_KEY))
- def selected_=(b: Option[Boolean]) {
- peer.putValue(javax.swing.Action.SELECTED_KEY,
- if (b == None) null else new java.lang.Boolean(b.get))
- }*/
-
+ def selected_=(b: Option[Boolean]) {
+ peer.putValue(javax.swing.Action.SELECTED_KEY,
+ if (b == None) null else new java.lang.Boolean(b.get))
+ }*/
+
def apply()
}
diff --git a/scala/swing/Adjustable.scala b/scala/swing/Adjustable.scala
index bc5dc64..590153f 100644
--- a/scala/swing/Adjustable.scala
+++ b/scala/swing/Adjustable.scala
@@ -40,12 +40,12 @@ trait Adjustable extends Oriented {
def minimum_=(m: Int)
def maximum: Int
def maximum_=(m: Int)
-
+
// Needs implementation of AdjustmentEvent
//
// val adjustments: Publisher = new Publisher {
// peer.addAdjustmentListener(new AdjustmentListener {
-// def adjustmentValueChanged(e: java.awt.event.AdjustmentEvent) {
+// def adjustmentValueChanged(e: java.awt.event.AdjustmentEvent) {
// publish(new AdjustmentEvent(e))
// }
// })
diff --git a/scala/swing/Alignment.scala b/scala/swing/Alignment.scala
index 439727c..a864afe 100644
--- a/scala/swing/Alignment.scala
+++ b/scala/swing/Alignment.scala
@@ -15,7 +15,7 @@ import javax.swing.SwingConstants._
/**
* Horizontal and vertical alignments. We sacrifice a bit of type-safety
* for simplicity here.
- *
+ *
* @see javax.swing.SwingConstants
*/
object Alignment extends Enumeration {
@@ -25,7 +25,7 @@ object Alignment extends Enumeration {
val Top = Value(TOP)
val Bottom = Value(BOTTOM)
//1.6: val Baseline = Value(BASELINE)
-
+
val Leading = Value(LEADING)
val Trailing = Value(TRAILING)
}
diff --git a/scala/swing/Applet.scala b/scala/swing/Applet.scala
index b2590a4..ab6bb50 100644
--- a/scala/swing/Applet.scala
+++ b/scala/swing/Applet.scala
@@ -19,18 +19,18 @@ import javax.swing.JApplet
*
* Note: Applet extends javax.swing.JApplet
* to satisfy Java's applet loading mechanism. The usual component wrapping
- * scheme doesn't work here.
+ * scheme doesn't work here.
*
ListView
- * (both, in the pull-down menu as well as in the box itself), hence the
+ * The underlying combo box renders all items in a ListView
+ * (both, in the pull-down menu as well as in the box itself), hence the
* ListView.Renderer.
*
- * Note that the UI peer of a combo box usually changes the colors
- * of the component to its own defaults _after_ the renderer has been
+ * Note that the UI peer of a combo box usually changes the colors
+ * of the component to its own defaults _after_ the renderer has been
* configured. That's Swing's principle of most suprise.
*/
def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setRenderer(r.peer) }
-
+
/* XXX: currently not safe to expose:
- def editor: ComboBox.Editor[A] =
+ def editor: ComboBox.Editor[A] =
def editor_=(r: ComboBox.Editor[A]) { peer.setEditor(r.comboBoxPeer) }
*/
def editable: Boolean = peer.isEditable
-
+
/**
- * Makes this combo box editable. In order to do so, this combo needs an
+ * Makes this combo box editable. In order to do so, this combo needs an
* editor which is supplied by the implicit argument. For default
* editors, see ComboBox companion object.
*/
@@ -202,9 +202,9 @@ class ComboBox[A](items: Seq[A]) extends Component with Publisher {
peer.setEditable(true)
peer.setEditor(editor(this).comboBoxPeer)
}
-
+
def prototypeDisplayValue: Option[A] = toOption[A](peer.getPrototypeDisplayValue)
- def prototypeDisplayValue_=(v: Option[A]) {
+ def prototypeDisplayValue_=(v: Option[A]) {
peer.setPrototypeDisplayValue(v map toAnyRef orNull)
}
}
diff --git a/scala/swing/Component.scala b/scala/swing/Component.scala
index 50a1579..62344bd 100644
--- a/scala/swing/Component.scala
+++ b/scala/swing/Component.scala
@@ -26,28 +26,28 @@ object Component {
*/
def wrap(c: JComponent): Component = {
val w = UIElement.cachedWrapper[Component](c)
- if (w != null) w
+ if (w != null) w
else new Component { override lazy val peer = c }
}
}
/**
* Base class for all UI elements that can be displayed in a window.
- * Components are publishers that fire the following event classes:
+ * Components are publishers that fire the following event classes:
* ComponentEvent, FocusEvent, FontChanged, ForegroundChanged, BackgroundChanged.
- *
+ *
* @note [Java Swing] Unlike in Java Swing, not all components are also containers.
*
* @see javax.swing.JComponent
- * @see http://java.sun.com/products/jfc/tsc/articles/painting/ for the component
+ * @see http://java.sun.com/products/jfc/tsc/articles/painting/ for the component
* painting mechanism
*/
abstract class Component extends UIElement {
override lazy val peer: javax.swing.JComponent = new javax.swing.JComponent with SuperMixin {}
var initP: JComponent = null
-
+
/**
- * This trait is used to redirect certain calls from the peer to the wrapper
+ * This trait is used to redirect certain calls from the peer to the wrapper
* and back. Useful to expose methods that can be customized by overriding.
*/
protected trait SuperMixin extends JComponent {
@@ -69,43 +69,43 @@ abstract class Component extends UIElement {
def __super__paintChildren(g: Graphics) {
super.paintChildren(g)
}
-
+
override def paint(g: Graphics) {
Component.this.paint(g.asInstanceOf[Graphics2D])
}
- def __super__paint(g: Graphics) {
+ def __super__paint(g: Graphics) {
super.paint(g)
}
}
-
+
def name: String = peer.getName
def name_=(s: String) = peer.setName(s)
-
+
/**
- * Used by certain layout managers, e.g., BoxLayout or OverlayLayout to
+ * Used by certain layout managers, e.g., BoxLayout or OverlayLayout to
* align components relative to each other.
*/
def xLayoutAlignment: Double = peer.getAlignmentX
def xLayoutAlignment_=(x: Double) = peer.setAlignmentX(x.toFloat)
def yLayoutAlignment: Double = peer.getAlignmentY
def yLayoutAlignment_=(y: Double) = peer.setAlignmentY(y.toFloat)
-
+
def border: Border = peer.getBorder
def border_=(b: Border) { peer.setBorder(b) }
-
+
def opaque: Boolean = peer.isOpaque
def opaque_=(b: Boolean) = peer.setOpaque(b)
-
+
def enabled: Boolean = peer.isEnabled
def enabled_=(b: Boolean) = peer.setEnabled(b)
-
+
def tooltip: String = peer.getToolTipText
def tooltip_=(t: String) = peer.setToolTipText(t)
-
+
def inputVerifier: Component => Boolean = { a =>
peer.getInputVerifier.verify(a.peer)
}
- def inputVerifier_=(v: Component => Boolean) {
+ def inputVerifier_=(v: Component => Boolean) {
peer.setInputVerifier(new javax.swing.InputVerifier {
def verify(c: javax.swing.JComponent) = v(UIElement.cachedWrapper[Component](c))
})
@@ -114,18 +114,18 @@ abstract class Component extends UIElement {
/*def verifyOnTraversal: (Component, Component) => Boolean = { a =>
peer.getInputVerifier().verify(a.peer)
}
- def verifyOnTraversal_=(v: (Component, Component) => Boolean) {
+ def verifyOnTraversal_=(v: (Component, Component) => Boolean) {
peer.setInputVerifier(new javax.swing.InputVerifier {
def verify(c: javax.swing.JComponent) = v(UIElement.cachedWrapper[Component](c))
})
}*/
-
-
+
+
@deprecated("Use mouse instead") lazy val Mouse = mouse
-
+
/**
- * Contains publishers for various mouse events. They are separated for
+ * Contains publishers for various mouse events. They are separated for
* efficiency reasons.
*/
object mouse {
@@ -136,13 +136,13 @@ abstract class Component extends UIElement {
peer.addMouseListener(new MouseListener {
def mouseEntered(e: java.awt.event.MouseEvent) { }
def mouseExited(e: java.awt.event.MouseEvent) { }
- def mouseClicked(e: java.awt.event.MouseEvent) {
+ def mouseClicked(e: java.awt.event.MouseEvent) {
publish(new MouseClicked(e))
}
- def mousePressed(e: java.awt.event.MouseEvent) {
+ def mousePressed(e: java.awt.event.MouseEvent) {
publish(new MousePressed(e))
}
- def mouseReleased(e: java.awt.event.MouseEvent) {
+ def mouseReleased(e: java.awt.event.MouseEvent) {
publish(new MouseReleased(e))
}
})
@@ -152,7 +152,7 @@ abstract class Component extends UIElement {
*/
val moves: Publisher = new Publisher {
peer.addMouseListener(new MouseListener {
- def mouseEntered(e: java.awt.event.MouseEvent) {
+ def mouseEntered(e: java.awt.event.MouseEvent) {
publish(new MouseEntered(e))
}
def mouseExited(e: java.awt.event.MouseEvent) {
@@ -163,10 +163,10 @@ abstract class Component extends UIElement {
def mouseReleased(e: java.awt.event.MouseEvent) { }
})
peer.addMouseMotionListener(new MouseMotionListener {
- def mouseMoved(e: java.awt.event.MouseEvent) {
+ def mouseMoved(e: java.awt.event.MouseEvent) {
publish(new MouseMoved(e))
}
- def mouseDragged(e: java.awt.event.MouseEvent) {
+ def mouseDragged(e: java.awt.event.MouseEvent) {
publish(new MouseDragged(e))
}
})
@@ -175,17 +175,17 @@ abstract class Component extends UIElement {
* Publishes mouse wheel moves.
*/
val wheel: Publisher = new LazyPublisher {
- // We need to subscribe lazily and unsubscribe, since components in scroll panes capture
+ // We need to subscribe lazily and unsubscribe, since components in scroll panes capture
// mouse wheel events if there is a listener installed. See ticket #1442.
lazy val l = new MouseWheelListener {
- def mouseWheelMoved(e: java.awt.event.MouseWheelEvent) {
+ def mouseWheelMoved(e: java.awt.event.MouseWheelEvent) {
publish(new MouseWheelMoved(e)) }
}
def onFirstSubscribe() = peer.addMouseWheelListener(l)
def onLastUnsubscribe() = peer.removeMouseWheelListener(l)
}
}
-
+
object keys extends Publisher {
peer.addKeyListener(new KeyListener {
def keyPressed(e: java.awt.event.KeyEvent) { publish(new KeyPressed(e)) }
@@ -193,28 +193,28 @@ abstract class Component extends UIElement {
def keyTyped(e: java.awt.event.KeyEvent) { publish(new KeyTyped(e)) }
})
}
-
+
def focusable: Boolean = peer.isFocusable
def focusable_=(b: Boolean) = peer.setFocusable(b)
def requestFocus() = peer.requestFocus()
def requestFocusInWindow() = peer.requestFocusInWindow()
def hasFocus: Boolean = peer.isFocusOwner
-
+
protected override def onFirstSubscribe {
super.onFirstSubscribe
// TODO: deprecated, remove after 2.8
peer.addComponentListener(new java.awt.event.ComponentListener {
- def componentHidden(e: java.awt.event.ComponentEvent) {
- publish(ComponentHidden(Component.this))
+ def componentHidden(e: java.awt.event.ComponentEvent) {
+ publish(ComponentHidden(Component.this))
}
- def componentShown(e: java.awt.event.ComponentEvent) {
- publish(ComponentShown(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 componentMoved(e: java.awt.event.ComponentEvent) {
+ publish(ComponentMoved(Component.this))
}
- def componentResized(e: java.awt.event.ComponentEvent) {
- publish(ComponentResized(Component.this))
+ def componentResized(e: java.awt.event.ComponentEvent) {
+ publish(ComponentResized(Component.this))
}
})
@@ -223,17 +223,17 @@ abstract class Component extends UIElement {
case c: JComponent => Some(UIElement.cachedWrapper[Component](c))
case _ => None
}
-
- def focusGained(e: java.awt.event.FocusEvent) {
- publish(FocusGained(Component.this, other(e), e.isTemporary))
+
+ 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))
+ publish(FocusLost(Component.this, other(e), e.isTemporary))
}
})
-
+
peer.addPropertyChangeListener(new java.beans.PropertyChangeListener {
- def propertyChange(e: java.beans.PropertyChangeEvent) {
+ def propertyChange(e: java.beans.PropertyChangeEvent) {
e.getPropertyName match {
case "font" => publish(FontChanged(Component.this))
case "background" => publish(BackgroundChanged(Component.this))
@@ -251,39 +251,39 @@ abstract class Component extends UIElement {
}
})
}
-
+
def revalidate() { peer.revalidate() }
-
+
/**
* For custom painting, users should usually override this method.
*/
protected def paintComponent(g: Graphics2D) {
peer match {
case peer: SuperMixin => peer.__super__paintComponent(g)
- case _ =>
+ case _ =>
}
}
-
+
protected def paintBorder(g: Graphics2D) {
peer match {
case peer: SuperMixin => peer.__super__paintBorder(g)
- case _ =>
+ case _ =>
}
}
-
+
protected def paintChildren(g: Graphics2D) {
peer match {
case peer: SuperMixin => peer.__super__paintChildren(g)
- case _ =>
+ case _ =>
}
}
-
+
def paint(g: Graphics2D) {
peer match {
case peer: SuperMixin => peer.__super__paint(g)
case _ => peer.paint(g)
}
}
-
+
override def toString = "scala.swing wrapper " + peer.toString
}
diff --git a/scala/swing/Container.scala b/scala/swing/Container.scala
index d4ac241..33201eb 100644
--- a/scala/swing/Container.scala
+++ b/scala/swing/Container.scala
@@ -15,18 +15,18 @@ import scala.collection.mutable.Buffer
object Container {
/**
- * Utility trait for wrapping containers. Provides an immutable
+ * Utility trait for wrapping containers. Provides an immutable
* implementation of the contents member.
*/
trait Wrapper extends Container with Publisher {
override def peer: javax.swing.JComponent
-
+
protected val _contents = new Content
def contents: Seq[Component] = _contents
-
+
protected class Content extends BufferWrapper[Component] {
override def clear { peer.removeAll() }
- override def remove(n: Int): Component = {
+ override def remove(n: Int): Component = {
val c = peer.getComponent(n)
peer.remove(n)
UIElement.cachedWrapper[Component](c)
@@ -36,15 +36,15 @@ object Container {
def length = peer.getComponentCount
def apply(n: Int) = UIElement.cachedWrapper[Component](peer.getComponent(n))
}
-
+
peer.addContainerListener(new java.awt.event.ContainerListener {
- def componentAdded(e: java.awt.event.ContainerEvent) {
- publish(ComponentAdded(Wrapper.this,
- UIElement.cachedWrapper[Component](e.getChild.asInstanceOf[javax.swing.JComponent])))
+ def componentAdded(e: java.awt.event.ContainerEvent) {
+ publish(ComponentAdded(Wrapper.this,
+ UIElement.cachedWrapper[Component](e.getChild.asInstanceOf[javax.swing.JComponent])))
}
- def componentRemoved(e: java.awt.event.ContainerEvent) {
- publish(ComponentRemoved(Wrapper.this,
- UIElement.cachedWrapper[Component](e.getChild.asInstanceOf[javax.swing.JComponent])))
+ def componentRemoved(e: java.awt.event.ContainerEvent) {
+ publish(ComponentRemoved(Wrapper.this,
+ UIElement.cachedWrapper[Component](e.getChild.asInstanceOf[javax.swing.JComponent])))
}
})
}
@@ -52,8 +52,8 @@ object Container {
/**
* The base traits for UI elements that can contain Components.
- *
- * @note [Java Swing] This is not the wrapper for java.awt.Container but a trait
+ *
+ * @note [Java Swing] This is not the wrapper for java.awt.Container but a trait
* that extracts a common interface for components, menus, and windows.
*/
trait Container extends UIElement {
diff --git a/scala/swing/EditorPane.scala b/scala/swing/EditorPane.scala
index 042596b..9302650 100644
--- a/scala/swing/EditorPane.scala
+++ b/scala/swing/EditorPane.scala
@@ -22,10 +22,10 @@ import java.awt.event._
class EditorPane(contentType0: String, text0: String) extends TextComponent {
override lazy val peer: JEditorPane = new JEditorPane(contentType0, text0) with SuperMixin
def this() = this("text/plain", "")
-
+
def contentType: String = peer.getContentType
def contentType_=(t: String) = peer.setContentType(t)
-
+
def editorKit: EditorKit = peer.getEditorKit
def editorKit_=(k: EditorKit) = peer.setEditorKit(k)
}
diff --git a/scala/swing/FileChooser.scala b/scala/swing/FileChooser.scala
index 0c4fae2..f9eda4a 100644
--- a/scala/swing/FileChooser.scala
+++ b/scala/swing/FileChooser.scala
@@ -17,7 +17,7 @@ import javax.swing.filechooser._
object FileChooser {
/**
* The result of a file dialog. The precise meaning of the Approve
- * result depends on the specific dialog type. Could be "save" or "open" for
+ * result depends on the specific dialog type. Could be "save" or "open" for
* example.
*/
object Result extends Enumeration {
@@ -25,7 +25,7 @@ object FileChooser {
val Approve = Value(JFileChooser.APPROVE_OPTION)
val Error = Value(JFileChooser.ERROR_OPTION)
}
-
+
/**
* The kind of elements a user can select in a file dialog.
*/
@@ -44,46 +44,46 @@ object FileChooser {
class FileChooser(dir: File) {
import FileChooser._
lazy val peer: JFileChooser = new JFileChooser(dir)
-
+
def this() = this(null)
-
+
import Swing._
def showOpenDialog(over: Component): Result.Value = Result(peer.showOpenDialog(nullPeer(over)))
def showSaveDialog(over: Component): Result.Value = Result(peer.showSaveDialog(nullPeer(over)))
def showDialog(over: Component, approveText: String): Result.Value = Result(peer.showDialog(nullPeer(over), approveText))
-
+
def controlButtonsAreShown: Boolean = peer.getControlButtonsAreShown
def controlButtonsAreShown_=(b: Boolean) { peer.setControlButtonsAreShown(b) }
-
+
def title: String = peer.getDialogTitle
def title_=(t: String) { peer.setDialogTitle(t) }
-
+
def accessory: Component = UIElement.cachedWrapper[Component](peer.getAccessory)
def accessory_=(c: Component) { peer.setAccessory(c.peer) }
-
+
def fileHidingEnabled: Boolean = peer.isFileHidingEnabled
def fileHidingEnabled_=(b: Boolean) { peer.setFileHidingEnabled(b) }
def fileSelectionMode: SelectionMode.Value = SelectionMode(peer.getFileSelectionMode)
def fileSelectionMode_=(s: SelectionMode.Value) { peer.setFileSelectionMode(s.id) }
def fileFilter: FileFilter = peer.getFileFilter
def fileFilter_=(f: FileFilter) { peer.setFileFilter(f) }
-
+
def selectedFile: File = peer.getSelectedFile
def selectedFile_=(file: File) { peer.setSelectedFile(file) }
def selectedFiles: Seq[File] = peer.getSelectedFiles
def selectedFiles_=(files: File*) { peer.setSelectedFiles(files.toArray) }
-
- def multiSelectionEnabled: Boolean = peer.isMultiSelectionEnabled
+
+ def multiSelectionEnabled: Boolean = peer.isMultiSelectionEnabled
def multiSelectionEnabled_=(b: Boolean) { peer.setMultiSelectionEnabled(b) }
-
+
def iconFor(f: File) = peer.getIcon(f)
def descriptionFor(f: File) = peer.getDescription(f)
def nameFor(f: File) = peer.getName(f)
def typeDescriptionFor(f: File) = peer.getTypeDescription(f)
def traversable(f: File) = peer.isTraversable(f)
-
+
def acceptAllFileFilter = peer.getAcceptAllFileFilter
-
+
/*peer.addPropertyChangeListener(new java.beans.PropertyChangeListener {
def propertyChange(e: java.beans.PropertyChangeEvent) {
import JFileChooser._
@@ -106,7 +106,7 @@ class FileChooser(dir: File) {
case MULTI_SELECTION_ENABLED_CHANGED_PROPERTY =>
case SELECTED_FILE_CHANGED_PROPERTY =>
case SELECTED_FILES_CHANGED_PROPERTY =>
- case _ =>
+ case _ =>
}
}
})*/
diff --git a/scala/swing/FlowPanel.scala b/scala/swing/FlowPanel.scala
index f823849..25f128d 100644
--- a/scala/swing/FlowPanel.scala
+++ b/scala/swing/FlowPanel.scala
@@ -24,21 +24,21 @@ object FlowPanel {
}
/**
- * A panel that arranges its contents horizontally, one after the other.
+ * A panel that arranges its contents horizontally, one after the other.
* If they don't fit, this panel will try to insert line breaks.
- *
+ *
* @see java.awt.FlowLayout
*/
class FlowPanel(alignment: FlowPanel.Alignment.Value)(contents0: Component*) extends Panel with SequentialContainer.Wrapper {
- override lazy val peer: JPanel =
+ override lazy val peer: JPanel =
new JPanel(new java.awt.FlowLayout(alignment.id)) with SuperMixin
def this(contents0: Component*) = this(FlowPanel.Alignment.Center)(contents0: _*)
def this() = this(FlowPanel.Alignment.Center)()
-
+
contents ++= contents0
-
+
private def layoutManager = peer.getLayout.asInstanceOf[java.awt.FlowLayout]
-
+
def vGap: Int = layoutManager.getVgap
def vGap_=(n: Int) { layoutManager.setVgap(n) }
def hGap: Int = layoutManager.getHgap
diff --git a/scala/swing/Font.scala.disabled b/scala/swing/Font.scala.disabled
index 6eebd66..a58c896 100644
--- a/scala/swing/Font.scala.disabled
+++ b/scala/swing/Font.scala.disabled
@@ -1,36 +1,36 @@
package scala.swing
-/*object Font {
- def apply(fontFormat: Int, fontFile: java.io.File) = java.awt.Font.createFont(fontFormat, fontFile)
- def apply(fontFormat: Int, fontStream: java.io.InputStream) = java.awt.Font.createFont(fontFormat, fontStream)
+/*object Font {
+ def apply(fontFormat: Int, fontFile: java.io.File) = java.awt.Font.createFont(fontFormat, fontFile)
+ def apply(fontFormat: Int, fontStream: java.io.InputStream) = java.awt.Font.createFont(fontFormat, fontStream)
def decode(str: String) = java.awt.Font.decode(str)
-
+
/* TODO: finish implementation
/**
* See [java.awt.Font.getFont].
*/
- def get(attributes: Map[_ <: java.text.AttributedCharacterIterator.Attribute, _]) =
+ def get(attributes: Map[_ <: java.text.AttributedCharacterIterator.Attribute, _]) =
java.awt.Font.getFont(ImmutableMapWrapper(attributes))
-
+
import java.{util => ju}
private case class ImmutableMapWrapper[A, B](underlying : Map[A, B])(m : ClassManifest[A]) extends ju.AbstractMap[A, B] {
self =>
override def size = underlying.size
- override def put(k : A, v : B) =
+ override def put(k : A, v : B) =
throw new UnsupportedOperationException("This is a wrapper that does not support mutation")
- override def remove(k : AnyRef) =
+ override def remove(k : AnyRef) =
throw new UnsupportedOperationException("This is a wrapper that does not support mutation")
-
+
override def entrySet : ju.Set[ju.Map.Entry[A, B]] = new ju.AbstractSet[ju.Map.Entry[A, B]] {
def size = self.size
def iterator = new ju.Iterator[ju.Map.Entry[A, B]] {
val ui = underlying.iterator
var prev : Option[A] = None
-
+
def hasNext = ui.hasNext
-
+
def next = {
val (k, v) = ui.next
prev = Some(k)
@@ -44,7 +44,7 @@ package scala.swing
}
}
}
-
+
def remove = prev match {
case Some(k) => val v = self.remove(k.asInstanceOf[AnyRef]) ; prev = None ; v
case _ => throw new IllegalStateException("next must be called at least once before remove")
@@ -53,7 +53,7 @@ package scala.swing
}
}
*/
-
+
/**
* See [java.awt.Font.getFont].
*/
@@ -62,9 +62,9 @@ package scala.swing
* See [java.awt.Font.getFont].
*/
def get(nm: String, font: Font) = java.awt.Font.getFont(nm, font)
-
+
def Insets(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height)
def Rectangle(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height)
def Point(x: Int, y: Int) = new Point(x, y)
- def Dimension(x: Int, y: Int) = new Dimension(x, y)
+ def Dimension(x: Int, y: Int) = new Dimension(x, y)
}*/
\ No newline at end of file
diff --git a/scala/swing/FormattedTextField.scala b/scala/swing/FormattedTextField.scala
index 7996e4f..0253750 100644
--- a/scala/swing/FormattedTextField.scala
+++ b/scala/swing/FormattedTextField.scala
@@ -28,17 +28,17 @@ object FormattedTextField {
/**
* A text field with formatted input.
- *
+ *
* @see javax.swing.JFormattedTextField
*/
class FormattedTextField(format: java.text.Format) extends TextComponent {
override lazy val peer: JFormattedTextField = new JFormattedTextField(format) with SuperMixin
-
+
import FormattedTextField._
-
+
def commitEdit() { peer.commitEdit() }
def editValid: Boolean = peer.isEditValid
-
+
def focusLostBehavior: FocusLostBehavior.Value = FocusLostBehavior(peer.getFocusLostBehavior)
def focusLostBehavior_=(b: FocusLostBehavior.Value) { peer.setFocusLostBehavior(b.id) }
}
diff --git a/scala/swing/GridBagPanel.scala b/scala/swing/GridBagPanel.scala
index e7d38e2..586d941 100644
--- a/scala/swing/GridBagPanel.scala
+++ b/scala/swing/GridBagPanel.scala
@@ -30,7 +30,7 @@ object GridBagPanel {
val West = Value(GridBagConstraints.WEST)
val NorthWest = Value(GridBagConstraints.NORTHWEST)
val Center = Value(GridBagConstraints.CENTER)
-
+
val PageStart = Value(GridBagConstraints.PAGE_START)
val PageEnd = Value(GridBagConstraints.PAGE_END)
val LineStart = Value(GridBagConstraints.LINE_START)
@@ -43,7 +43,7 @@ object GridBagPanel {
}
/**
- * A panel that arranges its children in a grid. Layout details can be
+ * A panel that arranges its children in a grid. Layout details can be
* given for each cell of the grid.
*
* @see java.awt.GridBagLayout
@@ -51,11 +51,11 @@ object GridBagPanel {
class GridBagPanel extends Panel with LayoutContainer {
override lazy val peer = new javax.swing.JPanel(new GridBagLayout) with SuperMixin
import GridBagPanel._
-
+
private def layoutManager = peer.getLayout.asInstanceOf[GridBagLayout]
/**
- * Convenient conversion from xy-coords given as pairs to
+ * Convenient conversion from xy-coords given as pairs to
* grid bag constraints.
*/
implicit def pair2Constraints(p: (Int, Int)): Constraints = {
@@ -67,15 +67,15 @@ class GridBagPanel extends Panel with LayoutContainer {
class Constraints(val peer: GridBagConstraints) extends Proxy {
def self = peer
- def this(gridx: Int, gridy: Int,
- gridwidth: Int, gridheight: Int,
- weightx: Double, weighty: Double,
- anchor: Int, fill: Int, insets: Insets,
- ipadx: Int, ipady: Int) =
- this(new GridBagConstraints(gridx, gridy,
- gridwidth, gridheight,
- weightx, weighty,
- anchor, fill, insets,
+ def this(gridx: Int, gridy: Int,
+ gridwidth: Int, gridheight: Int,
+ weightx: Double, weighty: Double,
+ anchor: Int, fill: Int, insets: Insets,
+ ipadx: Int, ipady: Int) =
+ this(new GridBagConstraints(gridx, gridy,
+ gridwidth, gridheight,
+ weightx, weighty,
+ anchor, fill, insets,
ipadx, ipady))
def this() = this(new GridBagConstraints())
def gridx: Int = peer.gridx
@@ -87,11 +87,11 @@ class GridBagPanel extends Panel with LayoutContainer {
gridx = c._1
gridy = c._2
}
-
+
def gridwidth: Int = peer.gridwidth
def gridwidth_=(w: Int) { peer.gridwidth = w }
def gridheight: Int = peer.gridheight
- def gridheight_=(h: Int) { peer.gridheight = h }
+ def gridheight_=(h: Int) { peer.gridheight = h }
def weightx: Double = peer.weightx
def weightx_=(x: Double) { peer.weightx = x }
def weighty: Double = peer.weighty
@@ -107,10 +107,10 @@ class GridBagPanel extends Panel with LayoutContainer {
def ipady: Int = peer.ipady
def ipady_=(y: Int) { peer.ipady = y }
}
-
+
protected def constraintsFor(comp: Component) =
new Constraints(layoutManager.getConstraints(comp.peer))
-
+
protected def areValid(c: Constraints): (Boolean, String) = (true, "")
protected def add(c: Component, l: Constraints) { peer.add(c.peer, l.peer) }
}
diff --git a/scala/swing/GridPanel.scala b/scala/swing/GridPanel.scala
index 2fb8b5a..acba29e 100644
--- a/scala/swing/GridPanel.scala
+++ b/scala/swing/GridPanel.scala
@@ -15,16 +15,16 @@ object GridPanel {
}
/**
- * A panel that lays out its contents in a uniform grid.
- *
+ * A panel that lays out its contents in a uniform grid.
+ *
* @see java.awt.GridLayout
*/
class GridPanel(rows0: Int, cols0: Int) extends Panel with SequentialContainer.Wrapper {
- override lazy val peer =
+ override lazy val peer =
new javax.swing.JPanel(new java.awt.GridLayout(rows0, cols0)) with SuperMixin
-
+
/*type Constraints = (Int, Int)
-
+
protected def constraintsFor(comp: Component) = {
assert(peer.getComponentOrientation.isHorizontal)
val idx = contents.indexOf(comp)
@@ -32,18 +32,18 @@ class GridPanel(rows0: Int, cols0: Int) extends Panel with SequentialContainer.W
if (peer.getComponentOrientation.isLeftToRight) (r, c)
else (r, columns-c+1)
}
-
+
protected def add(c: Component, l: Constraints) { peer.add(c.peer, (l._1-1)*columns+l._2) }
- protected def areValid(c: Constraints): (Boolean, String) =
+ protected def areValid(c: Constraints): (Boolean, String) =
((c._1 > 0 && c._2 > 0), "Grid coordinates (row,col) must be >= 1 but where " + c)*/
-
+
private def layoutManager = peer.getLayout.asInstanceOf[java.awt.GridLayout]
-
+
def rows: Int = layoutManager.getRows
def rows_=(n: Int) { layoutManager.setRows(n) }
def columns: Int = layoutManager.getColumns
def columns_=(n: Int) { layoutManager.setColumns(n) }
-
+
def vGap: Int = layoutManager.getVgap
def vGap_=(n: Int) { layoutManager.setVgap(n) }
def hGap: Int = layoutManager.getHgap
diff --git a/scala/swing/Label.scala b/scala/swing/Label.scala
index 177f71e..00b1b28 100644
--- a/scala/swing/Label.scala
+++ b/scala/swing/Label.scala
@@ -19,16 +19,16 @@ import scala.swing.Swing._
* @see javax.swing.JLabel
*/
class Label(text0: String, icon0: Icon, align: Alignment.Value) extends Component {
- override lazy val peer: JLabel =
+ override lazy val peer: JLabel =
new JLabel(text0, toNullIcon(icon0), align.id) with SuperMixin
-
+
def this() = this("", EmptyIcon, Alignment.Center)
def this(s: String) = this(s, EmptyIcon, Alignment.Center)
def text: String = peer.getText
def text_=(s: String) = peer.setText(s)
def icon: Icon = peer.getIcon
def icon_=(i: Icon) = peer.setIcon(i)
-
+
/**
* The alignment of the label's contents relative to its bounding box.
*/
@@ -36,7 +36,7 @@ class Label(text0: String, icon0: Icon, align: Alignment.Value) extends Componen
def xAlignment_=(x: Alignment.Value) { peer.setHorizontalAlignment(x.id) }
def yAlignment: Alignment.Value = Alignment(peer.getVerticalAlignment)
def yAlignment_=(x: Alignment.Value) { peer.setVerticalAlignment(x.id) }
-
+
/** @see javax.swing.JLabel#getHorizontalAlignment() */
def horizontalAlignment: Alignment.Value = Alignment(peer.getHorizontalAlignment)
/** @see javax.swing.JLabel#setHorizontalAlignment() */
@@ -44,19 +44,19 @@ class Label(text0: String, icon0: Icon, align: Alignment.Value) extends Componen
def verticalAlignment: Alignment.Value = Alignment(peer.getVerticalAlignment)
def verticalAlignment_=(x: Alignment.Value) { peer.setVerticalAlignment(x.id) }
-
+
def horizontalTextPosition: Alignment.Value = Alignment(peer.getHorizontalTextPosition)
def horizontalTextPosition_=(x: Alignment.Value) { peer.setHorizontalTextPosition(x.id) }
-
+
def verticalTextPosition: Alignment.Value = Alignment(peer.getVerticalTextPosition)
def verticalTextPosition_=(x: Alignment.Value) { peer.setVerticalTextPosition(x.id) }
-
+
def disabledIcon: Icon = peer.getDisabledIcon
def disabledIcon_=(icon: Icon) { peer.setDisabledIcon(icon) }
-
+
def iconTextGap: Int = peer.getIconTextGap
def iconTextGap_=(gap: Int) { peer.setIconTextGap(gap) }
-
+
def displayedMnemonicIndex: Int = peer.getDisplayedMnemonicIndex
def displayedMnemonicIndex_=(index: Int) { peer.setDisplayedMnemonicIndex(index) }
}
diff --git a/scala/swing/LayoutContainer.scala b/scala/swing/LayoutContainer.scala
index b4519be..1b16ba9 100644
--- a/scala/swing/LayoutContainer.scala
+++ b/scala/swing/LayoutContainer.scala
@@ -16,10 +16,10 @@ import scala.collection.mutable.Map
/**
* A container that associates layout constraints of member type
* Constraints with its children. See GridBagPanel
- * for an example container with custom constraints.
+ * for an example container with custom constraints.
*
javax.swing.ListCellRenderers
*/
@@ -39,13 +39,13 @@ object ListView {
Component.wrap(peer.getListCellRendererComponent(list.peer, a, index, isSelected, focused).asInstanceOf[JComponent])
}
}
-
+
/**
- * Returns a renderer for items of type A. The given function
- * converts items of type A to items of type B
- * for which a renderer is implicitly given. This allows chaining of
+ * Returns a renderer for items of type A. The given function
+ * converts items of type A to items of type B
+ * for which a renderer is implicitly given. This allows chaining of
* renderers, e.g.:
- *
+ *
*
* case class Person(name: String, email: String)
* val persons = List(Person("John", "j.doe@a.com"), Person("Mary", "m.jane@b.com"))
@@ -55,42 +55,42 @@ object ListView {
*
*/
def apply[A,B](f: A => B)(implicit renderer: Renderer[B]): Renderer[A] = new Renderer[A] {
- def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int): Component =
- renderer.componentFor(list, isSelected, focused, f(a), index)
+ def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int): Component =
+ renderer.componentFor(list, isSelected, focused, f(a), index)
}
}
-
+
/**
- * Item renderer for a list view. This is contravariant on the type of the
- * items, so a more general renderer can be used in place of a more specific
- * one. For instance, an Any renderer can be used for a list view
+ * Item renderer for a list view. This is contravariant on the type of the
+ * items, so a more general renderer can be used in place of a more specific
+ * one. For instance, an Any renderer can be used for a list view
* of strings.
- *
+ *
* @see javax.swing.ListCellRenderer
*/
abstract class Renderer[-A] {
def peer: ListCellRenderer = new ListCellRenderer {
- def getListCellRendererComponent(list: JList, a: Any, index: Int, isSelected: Boolean, focused: Boolean) =
+ 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, focused: Boolean, a: A, index: Int): Component
}
-
+
/**
- * A default renderer that maintains a single component for item rendering
- * and preconfigures it to sensible defaults. It is polymorphic on the
- * component's type so clients can easily use component specific attributes
+ * A default renderer that maintains a single component for item rendering
+ * and preconfigures it to sensible defaults. It is polymorphic on the
+ * component's type so clients can easily use component specific attributes
* during configuration.
*/
abstract class AbstractRenderer[-A, C<:Component](protected val component: C) extends Renderer[A] {
- // The renderer component is responsible for painting selection
- // backgrounds. Hence, make sure it is opaque to let it draw
+ // The renderer component is responsible for painting selection
+ // backgrounds. Hence, make sure it is opaque to let it draw
// the background.
component.opaque = true
/**
- * Standard preconfiguration that is commonly done for any component.
- * This includes foreground and background colors, as well as colors
+ * Standard preconfiguration that is commonly done for any component.
+ * This includes foreground and background colors, as well as colors
* of item selections.
*/
def preConfigure(list: ListView[_], isSelected: Boolean, focused: Boolean, a: A, index: Int) {
@@ -116,10 +116,10 @@ object ListView {
component
}
}
-
+
/**
- * A generic renderer that uses Swing's built-in renderers. If there is no
- * specific renderer for a type, this renderer falls back to a renderer
+ * A generic renderer that uses Swing's built-in renderers. If there is no
+ * specific renderer for a type, this renderer falls back to a renderer
* that renders the string returned from an item's toString.
*/
implicit object GenericRenderer extends Renderer[Any] {
@@ -132,28 +132,28 @@ object ListView {
}
/**
- * A component that displays a number of elements in a list. A list view does
+ * A component that displays a number of elements in a list. A list view does
* not support inline editing of items. If you need it, use a table view instead.
- *
- * Named ListView to avoid a clash with the frequently used
+ *
+ * Named ListView to avoid a clash with the frequently used
* scala.List
- *
+ *
* @see javax.swing.JList
*/
class ListView[A] extends Component {
import ListView._
override lazy val peer: JList = new JList with SuperMixin
-
+
def this(items: Seq[A]) = {
this()
listData = items
}
-
+
protected class ModelWrapper(val items: Seq[A]) extends AbstractListModel {
def getElementAt(n: Int) = items(n).asInstanceOf[AnyRef]
def getSize = items.size
}
-
+
def listData: Seq[A] = peer.getModel match {
case model: ModelWrapper => model.items
case model @ _ => new Seq[A] { selfSeq =>
@@ -166,29 +166,29 @@ class ListView[A] extends Component {
def apply(n: Int) = model.getElementAt(n).asInstanceOf[A]
}
}
-
+
def listData_=(items: Seq[A]) {
peer.setModel(new AbstractListModel {
def getElementAt(n: Int) = items(n).asInstanceOf[AnyRef]
def getSize = items.size
})
- }
-
+ }
+
/**
* The current item selection.
*/
object selection extends Publisher {
- protected abstract class Indices[A](a: =>Seq[A]) extends scala.collection.mutable.Set[A] {
- def -=(n: A): this.type
+ protected abstract class Indices[A](a: =>Seq[A]) extends scala.collection.mutable.Set[A] {
+ def -=(n: A): this.type
def +=(n: A): this.type
def contains(n: A) = a.contains(n)
override def size = a.length
def iterator = a.iterator
}
-
+
def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex
def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex
-
+
/**
* The indices of the currently selected items.
*/
@@ -200,10 +200,10 @@ class ListView[A] extends Component {
@deprecated("Use ListView.selection.anchorIndex")
def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex
}
-
- @deprecated("Use ListView.selectIndices")
+
+ @deprecated("Use ListView.selectIndices")
def selectIndices(ind: Int*) = peer.setSelectedIndices(ind.toArray)
-
+
/**
* The currently selected items.
*/
@@ -214,7 +214,7 @@ class ListView[A] extends Component {
@deprecated("Use ListView.selection.anchorIndex")
def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex
}
-
+
def intervalMode: IntervalMode.Value = IntervalMode(peer.getSelectionModel.getSelectionMode)
def intervalMode_=(m: IntervalMode.Value) { peer.getSelectionModel.setSelectionMode(m.id) }
@@ -226,26 +226,26 @@ class ListView[A] extends Component {
def adjusting = peer.getSelectionModel.getValueIsAdjusting
}
-
+
def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getCellRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setCellRenderer(r.peer) }
-
+
def fixedCellWidth = peer.getFixedCellWidth
def fixedCellWidth_=(x: Int) = peer.setFixedCellWidth(x)
-
+
def fixedCellHeight = peer.getFixedCellHeight
def fixedCellHeight_=(x: Int) = peer.setFixedCellHeight(x)
-
+
def prototypeCellValue: A = peer.getPrototypeCellValue.asInstanceOf[A]
def prototypeCellValue_=(a: A) { peer.setPrototypeCellValue(a) }
-
+
def selectionForeground: Color = peer.getSelectionForeground
def selectionForeground_=(c: Color) = peer.setSelectionForeground(c)
def selectionBackground: Color = peer.getSelectionBackground
def selectionBackground_=(c: Color) = peer.setSelectionBackground(c)
-
+
def selectIndices(ind: Int*) = peer.setSelectedIndices(ind.toArray)
-
+
peer.getModel.addListDataListener(new ListDataListener {
def contentsChanged(e: ListDataEvent) { publish(ListChanged(ListView.this)) }
def intervalRemoved(e: ListDataEvent) { publish(ListElementsRemoved(ListView.this, e.getIndex0 to e.getIndex1)) }
diff --git a/scala/swing/MainFrame.scala b/scala/swing/MainFrame.scala
index 415301f..4bc855d 100644
--- a/scala/swing/MainFrame.scala
+++ b/scala/swing/MainFrame.scala
@@ -13,7 +13,7 @@ package scala.swing
import event._
/**
- * A frame that can be used for main application windows. Shuts down the
+ * A frame that can be used for main application windows. Shuts down the
* framework and quits the application when closed.
*/
class MainFrame extends Frame {
diff --git a/scala/swing/Menu.scala b/scala/swing/Menu.scala
index 1cb5ab4..21d1d7a 100644
--- a/scala/swing/Menu.scala
+++ b/scala/swing/Menu.scala
@@ -19,14 +19,14 @@ object MenuBar {
/**
* A menu bar. Each window can contain at most one. Contains a number of menus.
- *
+ *
* @see javax.swing.JMenuBar
*/
class MenuBar extends Component with SequentialContainer.Wrapper {
override lazy val peer: JMenuBar = new JMenuBar with SuperMixin
-
+
def menus: Seq[Menu] = contents.filter(_.isInstanceOf[Menu]).map(_.asInstanceOf[Menu])
-
+
// Not implemented by Swing
//def helpMenu: Menu = UIElement.cachedWrapper(peer.getHelpMenu)
//def helpMenu_=(m: Menu) { peer.setHelpMenu(m.peer) }
@@ -34,7 +34,7 @@ class MenuBar extends Component with SequentialContainer.Wrapper {
/**
* A menu item that can be used in a menu.
- *
+ *
* @see javax.swing.JMenuItem
*/
class MenuItem(title0: String) extends AbstractButton {
@@ -47,7 +47,7 @@ class MenuItem(title0: String) extends AbstractButton {
/**
* A menu. Contains menu items. Being a menu item itself, menus can be nested.
- *
+ *
* @see javax.swing.JMenu
*/
class Menu(title0: String) extends MenuItem(title0) with SequentialContainer.Wrapper { self: Menu =>
@@ -56,7 +56,7 @@ class Menu(title0: String) extends MenuItem(title0) with SequentialContainer.Wra
/**
* A menu item with a radio button.
- *
+ *
* @see javax.swing.JRadioButtonMenuItem
*/
class RadioMenuItem(title0: String) extends MenuItem(title0) {
@@ -64,7 +64,7 @@ class RadioMenuItem(title0: String) extends MenuItem(title0) {
}
/**
* A menu item with a check box.
- *
+ *
* @see javax.swing.JCheckBoxMenuItem
*/
class CheckMenuItem(title0: String) extends MenuItem(title0) {
diff --git a/scala/swing/Oriented.scala b/scala/swing/Oriented.scala
index cb1bdd5..b19a5f8 100644
--- a/scala/swing/Oriented.scala
+++ b/scala/swing/Oriented.scala
@@ -13,14 +13,14 @@ package scala.swing
object Oriented {
trait Wrapper extends Oriented {
def peer: OrientedMixin
-
+
/*
- * Need to revert to structural type, since scroll bars are oriented
+ * Need to revert to structural type, since scroll bars are oriented
* and these are created by scroll panes. Shouldn't be a bootleneck.
*/
protected type OrientedMixin = {
def getOrientation(): Int
- def setOrientation(n: Int)
+ def setOrientation(n: Int)
}
def orientation: Orientation.Value = Orientation(peer.getOrientation)
}
diff --git a/scala/swing/PasswordField.scala b/scala/swing/PasswordField.scala
index 7c18b92..aac9c39 100644
--- a/scala/swing/PasswordField.scala
+++ b/scala/swing/PasswordField.scala
@@ -15,8 +15,8 @@ import javax.swing._
import java.awt.event._
/**
- * A password field, that displays a replacement character for each character in the password.
- *
+ * A password field, that displays a replacement character for each character in the password.
+ *
* @see javax.swing.JPasswordField
*/
class PasswordField(text0: String, columns0: Int) extends TextField(text0, columns0) {
@@ -24,12 +24,12 @@ class PasswordField(text0: String, columns0: Int) extends TextField(text0, colum
def this(text: String) = this(text, 0)
def this(columns: Int) = this("", columns)
def this() = this("")
-
+
def echoChar: Char = peer.getEchoChar
def echoChar_=(c: Char) = peer.setEchoChar(c)
-
+
/**
- * The text property should not be used on a password field for
+ * The text property should not be used on a password field for
* security reasons.
*/
override def text: String = ""
diff --git a/scala/swing/ProgressBar.scala b/scala/swing/ProgressBar.scala
index 94347e7..557d7b8 100644
--- a/scala/swing/ProgressBar.scala
+++ b/scala/swing/ProgressBar.scala
@@ -13,32 +13,32 @@ package scala.swing
import event._
/**
- * A bar indicating progress of some action. Can be in indeterminate mode,
- * in which it indicates that the action is in progress (usually by some
+ * A bar indicating progress of some action. Can be in indeterminate mode,
+ * in which it indicates that the action is in progress (usually by some
* animation) but does not indicate the amount of work done or to be done.
- *
+ *
* @see javax.swing.JProgressBar
*/
class ProgressBar extends Component with Orientable.Wrapper {
- override lazy val peer: javax.swing.JProgressBar =
+ override lazy val peer: javax.swing.JProgressBar =
new javax.swing.JProgressBar with SuperMixin
-
+
def min: Int = peer.getMinimum
def min_=(v: Int) { peer.setMinimum(v) }
def max: Int = peer.getMaximum
def max_=(v: Int) { peer.setMaximum(v) }
def value: Int = peer.getValue
def value_=(v: Int) { peer.setValue(v) }
-
+
def labelPainted: Boolean = peer.isStringPainted
def labelPainted_=(v: Boolean) { peer.setStringPainted(v) }
-
+
def label: String = peer.getString
def label_=(v: String) = peer.setString(v)
-
+
def indeterminate: Boolean = peer.isIndeterminate
def indeterminate_=(v: Boolean) { peer.setIndeterminate(v) }
-
+
def paintBorder: Boolean = peer.isBorderPainted
def paintBorder(v: Boolean) { peer.setBorderPainted(v) }
}
diff --git a/scala/swing/Publisher.scala b/scala/swing/Publisher.scala
index 44de7eb..3fa9fc7 100644
--- a/scala/swing/Publisher.scala
+++ b/scala/swing/Publisher.scala
@@ -15,22 +15,22 @@ import scala.collection.mutable.{Buffer, HashSet, Set}
import event.Event
/**
- * Notifies registered reactions when an event is published. Publishers are
+ * Notifies registered reactions when an event is published. Publishers are
* also reactors and listen to themselves per default as a convenience.
*
*
- * In order to reduce memory leaks, reactions are weakly referenced by default,
- * unless they implement Reactions.StronglyReferenced. That way,
- * the lifetime of reactions are more easily bound to the registering object,
- * which are reactors in common client code and hold strong references to their
- * reactions. As a result, reactors can be garbage collected even though they
+ * In order to reduce memory leaks, reactions are weakly referenced by default,
+ * unless they implement Reactions.StronglyReferenced. That way,
+ * the lifetime of reactions are more easily bound to the registering object,
+ * which are reactors in common client code and hold strong references to their
+ * reactions. As a result, reactors can be garbage collected even though they
* still have reactions registered at some publisher, but not vice versa
* since reactors (strongly) reference publishers they are interested in.
*
*/
trait Publisher extends Reactor {
import Reactions._
-
+
protected val listeners = new RefSet[Reaction] {
import scala.ref._
val underlying = new HashSet[Reference[Reaction]]
@@ -42,31 +42,31 @@ trait Publisher extends Reactor {
private[swing] def subscribe(listener: Reaction) { listeners += listener }
private[swing] def unsubscribe(listener: Reaction) { listeners -= listener }
-
+
/**
* Notify all registered reactions.
*/
def publish(e: Event) { for (l <- listeners) l(e) }
-
+
listenTo(this)
}
/**
- * A publisher that subscribes itself to an underlying event source not before the first
+ * A publisher that subscribes itself to an underlying event source not before the first
* reaction is installed. Can unsubscribe itself when the last reaction is uninstalled.
*/
private[swing] trait LazyPublisher extends Publisher {
import Reactions._
-
+
protected def onFirstSubscribe()
protected def onLastUnsubscribe()
-
- override def subscribe(listener: Reaction) {
- if(listeners.size == 1) onFirstSubscribe()
- super.subscribe(listener)
+
+ override def subscribe(listener: Reaction) {
+ if(listeners.size == 1) onFirstSubscribe()
+ super.subscribe(listener)
}
- override def unsubscribe(listener: Reaction) {
- super.unsubscribe(listener)
+ override def unsubscribe(listener: Reaction) {
+ super.unsubscribe(listener)
if(listeners.size == 1) onLastUnsubscribe()
}
}
@@ -83,7 +83,7 @@ private[swing] trait SingleRefCollection[+A <: AnyRef] extends Iterable[A] { sel
if (v == None) 0 else v.get.##
}
override def equals(that: Any) = that match {
- case that: ReferenceWrapper[_] =>
+ case that: ReferenceWrapper[_] =>
val v1 = this.get
val v2 = that.get
v1 == v2
@@ -94,29 +94,29 @@ private[swing] trait SingleRefCollection[+A <: AnyRef] extends Iterable[A] { sel
//type Ref <: Reference[A] // TODO: could use higher kinded types, but currently crashes
protected[this] def Ref(a: A): Ref[A]
protected[this] val referenceQueue = new ReferenceQueue[A]
-
+
protected val underlying: Iterable[Reference[A]]
-
- def purgeReferences() {
+
+ def purgeReferences() {
var ref = referenceQueue.poll
- while (ref != None) {
+ while (ref != None) {
removeReference(ref.get.asInstanceOf[Reference[A]])
ref = referenceQueue.poll
}
}
-
+
protected[this] def removeReference(ref: Reference[A])
-
+
def iterator = new Iterator[A] {
private val elems = self.underlying.iterator
private var hd: A = _
private var ahead: Boolean = false
private def skip: Unit =
while (!ahead && elems.hasNext) {
- // make sure we have a reference to the next element,
+ // make sure we have a reference to the next element,
// otherwise it might be garbage collected
val next = elems.next.get
- ahead = next != None
+ ahead = next != None
if (ahead) hd = next.get
}
def hasNext: Boolean = { skip; ahead }
@@ -136,7 +136,7 @@ private[swing] class StrongReference[+T <: AnyRef](value: T) extends Reference[T
def enqueue(): Boolean = false
def isEnqueued(): Boolean = false
}
-
+
abstract class RefBuffer[A <: AnyRef] extends Buffer[A] with SingleRefCollection[A] { self =>
protected val underlying: Buffer[Reference[A]]
@@ -149,7 +149,7 @@ abstract class RefBuffer[A <: AnyRef] extends Buffer[A] with SingleRefCollection
underlying.insertAll(n, iter.view.map(Ref(_)))
}
def update(n: Int, el: A) { purgeReferences(); underlying(n) = Ref(el) }
- def apply(n: Int) = {
+ def apply(n: Int) = {
purgeReferences()
var el = underlying(n).get
while (el == None) {
@@ -157,20 +157,20 @@ abstract class RefBuffer[A <: AnyRef] extends Buffer[A] with SingleRefCollection
}
el.get
}
-
+
def length = { purgeReferences(); underlying.length }
def clear() { underlying.clear(); purgeReferences() }
protected[this] def removeReference(ref: Reference[A]) { underlying -= ref }
}
-
+
private[swing] abstract class RefSet[A <: AnyRef] extends Set[A] with SingleRefCollection[A] { self =>
protected val underlying: Set[Reference[A]]
-
+
def -=(el: A): this.type = { underlying -= Ref(el); purgeReferences(); this }
def +=(el: A): this.type = { purgeReferences(); underlying += Ref(el); this }
def contains(el: A): Boolean = { purgeReferences(); underlying.contains(Ref(el)) }
override def size = { purgeReferences(); underlying.size }
-
+
protected[this] def removeReference(ref: Reference[A]) { underlying -= ref }
}
diff --git a/scala/swing/RadioButton.scala b/scala/swing/RadioButton.scala
index 9cd5650..c030b3c 100644
--- a/scala/swing/RadioButton.scala
+++ b/scala/swing/RadioButton.scala
@@ -13,8 +13,8 @@ package scala.swing
import javax.swing._
/**
- * A two state button that is usually used in a ButtonGroup
- * together with other RadioButtons, in order to indicate
+ * A two state button that is usually used in a ButtonGroup
+ * together with other RadioButtons, in order to indicate
* that at most one of them can be selected.
*
* @see javax.swing.JRadioButton
diff --git a/scala/swing/Reactions.scala b/scala/swing/Reactions.scala
index 7c1662b..a30cb9f 100644
--- a/scala/swing/Reactions.scala
+++ b/scala/swing/Reactions.scala
@@ -15,7 +15,7 @@ import scala.collection.mutable.{Buffer, ListBuffer}
object Reactions {
import scala.ref._
-
+
class Impl extends Reactions {
private val parts: Buffer[Reaction] = new ListBuffer[Reaction]
def isDefinedAt(e: Event) = parts.exists(_ isDefinedAt e)
@@ -25,14 +25,14 @@ object Reactions {
for (p <- parts) if (p isDefinedAt e) p(e)
}
}
-
+
type Reaction = PartialFunction[Event, Unit]
-
+
/**
* A Reaction implementing this trait is strongly referenced in the reaction list
*/
trait StronglyReferenced
-
+
class Wrapper(listener: Any)(r: Reaction) extends Reaction with StronglyReferenced with Proxy {
def self = listener
def isDefinedAt(e: Event) = r.isDefinedAt(e)
diff --git a/scala/swing/Reactor.scala b/scala/swing/Reactor.scala
index 48ea23d..8fdd6cf 100644
--- a/scala/swing/Reactor.scala
+++ b/scala/swing/Reactor.scala
@@ -19,7 +19,7 @@ trait Reactor {
*/
val reactions: Reactions = new Reactions.Impl
/**
- * Listen to the given publisher as long as deafTo isn't called for
+ * Listen to the given publisher as long as deafTo isn't called for
* them.
*/
def listenTo(ps: Publisher*) = for (p <- ps) p.subscribe(reactions)
diff --git a/scala/swing/RichWindow.scala b/scala/swing/RichWindow.scala
index 10c6321..10e3962 100644
--- a/scala/swing/RichWindow.scala
+++ b/scala/swing/RichWindow.scala
@@ -21,20 +21,20 @@ object RichWindow {
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)
+ peer.setUndecorated(true)
}
}
/**
- * A window that adds some functionality to the plain Window class and serves as
+ * A window that adds some functionality to the plain Window class and serves as
* the common base class for frames and dialogs.
- *
+ *
* Implementation note: this class is sealed since we need to know that a rich
* window is either a dialog or a frame at some point.
*/
sealed trait RichWindow extends Window {
def peer: AWTWindow with InterfaceMixin
-
+
trait InterfaceMixin extends super.InterfaceMixin {
def getJMenuBar: JMenuBar
def setJMenuBar(b: JMenuBar)
@@ -44,39 +44,39 @@ sealed trait RichWindow extends Window {
def setResizable(b: Boolean)
def isResizable: Boolean
}
-
+
def title: String = peer.getTitle
def title_=(s: String) = peer.setTitle(s)
-
+
/**
* The menu bar of this frame or `NoMenuBar` if no menu bar is set.
*/
def menuBar: MenuBar = {
val m = UIElement.cachedWrapper[MenuBar](peer.getJMenuBar)
- if (m != null) m else MenuBar.NoMenuBar
+ if (m != null) m else MenuBar.NoMenuBar
}
/**
- * Set the current menu bar of this frame. Pass `NoMenuBar` if this frame
+ * Set the current menu bar of this frame. Pass `NoMenuBar` if this frame
* should not show a menu bar.
*/
- def menuBar_=(m: MenuBar) =
+ def menuBar_=(m: MenuBar) =
peer.setJMenuBar(if(m == MenuBar.NoMenuBar) null else m.peer)
-
+
def resizable_=(b: Boolean) { peer.setResizable(b) }
def resizable = peer.isResizable
}
/**
* A window with decoration such as a title, border, and action buttons.
- *
- * An AWT window cannot be wrapped dynamically with this class, i.e., you cannot
+ *
+ * An AWT window cannot be wrapped dynamically with this class, i.e., you cannot
* write something like new Window { def peer = myAWTWindow }
- *
+ *
* @see javax.swing.JFrame
*/
class Frame extends RichWindow {
override lazy val peer: JFrame with InterfaceMixin = new JFrame with InterfaceMixin with SuperMixin
-
+
protected trait SuperMixin extends JFrame {
override protected def processWindowEvent(e: java.awt.event.WindowEvent) {
super.processWindowEvent(e)
@@ -91,14 +91,14 @@ class Frame extends RichWindow {
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) }
}
/**
* Simple predefined dialogs.
- *
+ *
* @see javax.swing.JOptionPane
*/
object Dialog {
@@ -112,7 +112,7 @@ object Dialog {
val Question = Value(JOptionPane.QUESTION_MESSAGE)
val Plain = Value(JOptionPane.PLAIN_MESSAGE)
}
-
+
/**
* The possible answers a user can select.
*/
@@ -122,7 +122,7 @@ object Dialog {
val YesNoCancel = Value(JOptionPane.YES_NO_CANCEL_OPTION)
val OkCancel = Value(JOptionPane.OK_CANCEL_OPTION)
}
-
+
/**
* The selected result of dialog.
*/
@@ -133,72 +133,72 @@ object Dialog {
val Cancel = Value(JOptionPane.CANCEL_OPTION)
val Closed = Value(JOptionPane.CLOSED_OPTION)
}
-
+
private def uiString(txt: String) = UIManager.getString(txt)
-
+
def showConfirmation(parent: Component = null,
- message: Any,
- title: String = uiString("OptionPane.titleText"),
- optionType: Options.Value = Options.YesNo,
- messageType: Message.Value = Message.Question,
+ 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,
+ Result(JOptionPane.showConfirmDialog(nullPeer(parent), message, title,
optionType.id, messageType.id, Swing.wrapIcon(icon)))
-
- 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],
+
+ 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),
+ val r = JOptionPane.showOptionDialog(nullPeer(parent), message, title,
+ optionType.id, messageType.id, Swing.wrapIcon(icon),
entries map toAnyRef toArray, entries(initial))
Result(r)
}
- def showInput[A](parent: Component = null,
- message: Any,
+ 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,
+ 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 toAnyRef toArray
val r = JOptionPane.showInputDialog(nullPeer(parent), message, title,
- messageType.id, Swing.wrapIcon(icon),
+ messageType.id, Swing.wrapIcon(icon),
e, initial)
-
+
toOption[A](r)
}
- def showMessage(parent: Component = null,
- message: Any,
- title: String = uiString("OptionPane.messageDialogTitle"),
- messageType: Message.Value = Message.Info,
+ 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,
+ JOptionPane.showMessageDialog(nullPeer(parent), message, title,
messageType.id, Swing.wrapIcon(icon))
}
}
/**
* A dialog window.
- *
+ *
* @see javax.swing.JDialog
*/
class Dialog(owner: Window) extends RichWindow {
- override lazy val peer: JDialog with InterfaceMixin =
+ override lazy val peer: JDialog with InterfaceMixin =
if (owner == null) new JDialog with InterfaceMixin
else owner match {
case f: Frame => new JDialog(f.peer) with InterfaceMixin
case d: Dialog => new JDialog(d.peer) with InterfaceMixin
}
-
+
def this() = this(null)
-
+
def modal_=(b: Boolean) { peer.setModal(b) }
def modal = peer.isModal
}
diff --git a/scala/swing/RootPanel.scala b/scala/swing/RootPanel.scala
index 931b82a..86bfd09 100644
--- a/scala/swing/RootPanel.scala
+++ b/scala/swing/RootPanel.scala
@@ -11,23 +11,23 @@
package scala.swing
/**
- * The root of a component hierarchy. Contains at most one component.
+ * The root of a component hierarchy. Contains at most one component.
*
* @see javax.swing.RootPaneContainer
*/
-trait RootPanel extends Container {
+trait RootPanel extends Container {
def peer: java.awt.Component with javax.swing.RootPaneContainer
-
+
/**
* At most one component.
*/
- def contents: Seq[Component] =
+ def contents: Seq[Component] =
if (peer.getContentPane.getComponentCount == 0) Nil
else {
val c = peer.getContentPane.getComponent(0).asInstanceOf[javax.swing.JComponent]
List(UIElement.cachedWrapper[Component](c))
}
-
+
def contents_=(c: Component) {
if (peer.getContentPane.getComponentCount > 0) {
val old = peer.getContentPane.getComponent(0)
diff --git a/scala/swing/ScrollBar.scala b/scala/swing/ScrollBar.scala
index 148228a..cd2fbdc 100644
--- a/scala/swing/ScrollBar.scala
+++ b/scala/swing/ScrollBar.scala
@@ -14,9 +14,9 @@ import javax.swing.{JScrollBar, BoundedRangeModel}
import java.awt.event.{AdjustmentListener}
object ScrollBar {
- def wrap(c: JScrollBar): ScrollBar = {
+ def wrap(c: JScrollBar): ScrollBar = {
val w = UIElement.cachedWrapper[ScrollBar](c)
- if (w != null) w
+ if (w != null) w
else new ScrollBar { override lazy val peer = c }
}
}
@@ -28,11 +28,11 @@ class ScrollBar extends Component with Orientable.Wrapper with Adjustable.Wrappe
def valueIsAjusting_=(b : Boolean) = peer.setValueIsAdjusting(b)
// TODO: can we find a better interface?
- //def setValues(value: Int = this.value, visible: Int = visibleAmount,
- // min: Int = minimum, max: Int = maximum) =
+ //def setValues(value: Int = this.value, visible: Int = visibleAmount,
+ // min: Int = minimum, max: Int = maximum) =
// peer.setValues(value, visible, min, max)
-// Not currently needed, requires wrapper for BoundedRangeModel
+// Not currently needed, requires wrapper for BoundedRangeModel
//
// def model = peer.getModel
// def model_=(m : BoundedRangeModel) = peer.setModel(m)
diff --git a/scala/swing/ScrollPane.scala b/scala/swing/ScrollPane.scala
index c4796ec..a840bf2 100644
--- a/scala/swing/ScrollPane.scala
+++ b/scala/swing/ScrollPane.scala
@@ -41,48 +41,48 @@ object ScrollPane {
*/
class ScrollPane extends Component with Container {
import ScrollPane._
-
+
override lazy val peer: JScrollPane = new JScrollPane with SuperMixin
def this(c: Component) = {
this()
contents = c
- }
- def contents: Seq[Component] =
+ }
+ def contents: Seq[Component] =
List(UIElement.cachedWrapper[Component](peer.getViewport.getView.asInstanceOf[javax.swing.JComponent]))
-
+
/**
* Sets the single child.
*/
def contents_=(c: Component) { peer.setViewportView(c.peer) }
-
+
/**
- * The component being displayed in this pane's row header.
- *
- * If you want to create a row header for lists or tables, you probably
- * want to let the row header be a list view with the same row height as
+ * The component being displayed in this pane's row header.
+ *
+ * If you want to create a row header for lists or tables, you probably
+ * want to let the row header be a list view with the same row height as
* the viewport component.
*/
- def rowHeaderView: Option[Component] =
+ def rowHeaderView: Option[Component] =
Option(peer.getRowHeader.getView) map UIElement.cachedWrapper[Component]
def rowHeaderView_=(c: Component) = peer.setRowHeaderView(c.peer)
def rowHeaderView_=(c: Option[Component]) = peer.setRowHeaderView(c map (_.peer) orNull)
-
- def columnHeaderView: Option[Component] =
+
+ def columnHeaderView: Option[Component] =
Option(peer.getColumnHeader.getView) map UIElement.cachedWrapper[Component]
def columnHeaderView_=(c: Component) = peer.setColumnHeaderView(c.peer)
def columnHeaderView_=(c: Option[Component]) = peer.setColumnHeaderView(c map (_.peer) orNull)
-
- def viewportView: Option[Component] =
+
+ def viewportView: Option[Component] =
Option(peer.getViewport.getView) map UIElement.cachedWrapper[Component]
def viewportView_=(c: Component) = peer.setViewportView(c.peer)
def viewportView_=(c: Option[Component]) = peer.setViewportView(c map (_.peer) orNull)
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)
-
+
def horizontalScrollBar = ScrollBar.wrap(peer.getHorizontalScrollBar)
def verticalScrollBar = ScrollBar.wrap(peer.getVerticalScrollBar)
}
diff --git a/scala/swing/Scrollable.scala b/scala/swing/Scrollable.scala
index 24512ad..34c0261 100644
--- a/scala/swing/Scrollable.scala
+++ b/scala/swing/Scrollable.scala
@@ -14,13 +14,13 @@ object Scrollable {
trait Wrapper extends Scrollable {
protected def scrollablePeer: javax.swing.Scrollable
def preferredViewportSize = scrollablePeer.getPreferredScrollableViewportSize
-
+
def tracksViewportHeight: Boolean = scrollablePeer.getScrollableTracksViewportHeight
def tracksViewportWidth: Boolean = scrollablePeer.getScrollableTracksViewportWidth
-
+
def blockIncrement(visibleRect: Rectangle, orientation: Orientation.Value, direction: Int): Int =
scrollablePeer.getScrollableBlockIncrement(visibleRect, orientation.id, direction)
-
+
def unitIncrement(visibleRect: Rectangle, orientation: Orientation.Value, direction: Int): Int =
scrollablePeer.getScrollableUnitIncrement(visibleRect, orientation.id, direction)
}
@@ -28,16 +28,16 @@ object Scrollable {
/**
* A component that is specially suitable for being placed inside a
- * ScrollPane.
- *
+ * ScrollPane.
+ *
* @see javax.swing.Scrollable
*/
trait Scrollable extends Component {
def preferredViewportSize: Dimension
-
+
def tracksViewportHeight: Boolean
def tracksViewportWidth: Boolean
-
- def blockIncrement(visibleRect: Rectangle, orientation: Orientation.Value, direction: Int): Int
+
+ def blockIncrement(visibleRect: Rectangle, orientation: Orientation.Value, direction: Int): Int
def unitIncrement(visibleRect: Rectangle, orientation: Orientation.Value, direction: Int): Int
}
diff --git a/scala/swing/Separator.scala b/scala/swing/Separator.scala
index ff81133..f5eaa5d 100644
--- a/scala/swing/Separator.scala
+++ b/scala/swing/Separator.scala
@@ -14,7 +14,7 @@ import javax.swing._
/**
* A bar that can be used a separator, most commonly in menus.
- *
+ *
* @see javax.swing.JSeparator
*/
class Separator(o: Orientation.Value) extends Component with Oriented.Wrapper {
diff --git a/scala/swing/SequentialContainer.scala b/scala/swing/SequentialContainer.scala
index 0d72652..ba2b105 100644
--- a/scala/swing/SequentialContainer.scala
+++ b/scala/swing/SequentialContainer.scala
@@ -23,12 +23,12 @@ object SequentialContainer {
}
/**
- * A container for which a sequential order of children makes sense, such as
+ * A container for which a sequential order of children makes sense, such as
* flow panels, or menus. Its contents are mutable.
*/
trait SequentialContainer extends Container {
/**
- * The mutable child components of this container. The order matters and
+ * The mutable child components of this container. The order matters and
* usually indicates the layout of the children.
*/
override def contents: Buffer[Component]
diff --git a/scala/swing/SimpleGUIApplication.scala b/scala/swing/SimpleGUIApplication.scala
index df6b6a2..fec8dbf 100644
--- a/scala/swing/SimpleGUIApplication.scala
+++ b/scala/swing/SimpleGUIApplication.scala
@@ -13,20 +13,20 @@ package scala.swing
import javax.swing._
/**
- * Extend this class for most simple UI applications. Clients need to implement the
+ * Extend this class for most simple UI applications. Clients need to implement the
* top method. Framework initialization is done by this class.
- *
- * In order to conform to Swing's threading policy, never implement top or any additional
- * member that created Swing components as a value unless component creation happens on
+ *
+ * In order to conform to Swing's threading policy, never implement top or any additional
+ * member that created Swing components as a value unless component creation happens on
* the EDT (see Swing.onEDT and Swing.onEDTWait). Lazy values are okay for the same reason
* if they are initialized on the EDT always.
*/
@deprecated("Use SimpleSwingApplication instead") abstract class SimpleGUIApplication extends GUIApplication {
-
+
/**
- * A GUI application's version of the main method. Called by the default
+ * A GUI application's version of the main method. Called by the default
* main method implementation provided by this class.
- * Implement to return the top-level frame of this application.
+ * Implement to return the top-level frame of this application.
*/
def top: Frame
@@ -38,10 +38,10 @@ import javax.swing._
t.pack()
t.visible = true
}
-
+
def resourceFromClassloader(path: String): java.net.URL =
this.getClass.getResource(path)
-
+
def resourceFromUserDirectory(path: String): java.io.File =
new java.io.File(util.Properties.userDir, path)
}
diff --git a/scala/swing/SimpleSwingApplication.scala b/scala/swing/SimpleSwingApplication.scala
index 3416eed..786c7b4 100644
--- a/scala/swing/SimpleSwingApplication.scala
+++ b/scala/swing/SimpleSwingApplication.scala
@@ -2,16 +2,16 @@ package scala.swing
abstract class SimpleSwingApplication extends SwingApplication {
def top: Frame
-
+
override def startup(args: Array[String]) {
val t = top
if (t.size == new Dimension(0,0)) t.pack()
t.visible = true
}
-
+
def resourceFromClassloader(path: String): java.net.URL =
this.getClass.getResource(path)
-
+
def resourceFromUserDirectory(path: String): java.io.File =
new java.io.File(util.Properties.userDir, path)
}
diff --git a/scala/swing/Slider.scala b/scala/swing/Slider.scala
index f3dafa1..47065af 100644
--- a/scala/swing/Slider.scala
+++ b/scala/swing/Slider.scala
@@ -16,15 +16,15 @@ import event._
/**
* Lets users select a value from a given range. Visually, this is represented
* as a draggable knob on a horizontal or vertical bar.
- *
- * Fires a ValueChanged event whenever the slider's value changes and
+ *
+ * Fires a ValueChanged event whenever the slider's value changes and
* when the knob is released.
- *
+ *
* @see javax.swing.JSlider
*/
class Slider extends Component with Orientable.Wrapper with Publisher {
override lazy val peer: JSlider = new JSlider with SuperMixin
-
+
def min: Int = peer.getMinimum
def min_=(v: Int) { peer.setMinimum(v) }
def max: Int = peer.getMaximum
@@ -33,24 +33,24 @@ class Slider extends Component with Orientable.Wrapper with Publisher {
def value_=(v: Int) { peer.setValue(v) }
def extent: Int = peer.getExtent
def extent_=(v: Int) { peer.setExtent(v) }
-
+
def paintLabels: Boolean = peer.getPaintLabels
def paintLabels_=(v: Boolean) { peer.setPaintLabels(v) }
def paintTicks: Boolean = peer.getPaintTicks
def paintTicks_=(v: Boolean) { peer.setPaintTicks(v) }
def paintTrack: Boolean = peer.getPaintTrack
def paintTrack_=(v: Boolean) { peer.setPaintTrack(v) }
-
+
def snapToTicks: Boolean = peer.getSnapToTicks
def snapToTicks_=(v: Boolean) { peer.setSnapToTicks(v) }
-
+
def minorTickSpacing: Int = peer.getMinorTickSpacing
def minorTickSpacing_=(v: Int) { peer.setMinorTickSpacing(v) }
def majorTickSpacing: Int = peer.getMajorTickSpacing
def majorTickSpacing_=(v: Int) { peer.setMajorTickSpacing(v) }
-
+
def adjusting = peer.getValueIsAdjusting
-
+
def labels: scala.collection.Map[Int, Label] = {
val labelTable = peer.getLabelTable.asInstanceOf[java.util.Hashtable[Int, JLabel]]
new scala.collection.JavaConversions.JMapWrapper(labelTable)
@@ -62,10 +62,10 @@ class Slider extends Component with Orientable.Wrapper with Publisher {
for ((k,v) <- l) table.put(k, v.peer)
peer.setLabelTable(table)
}
-
+
peer.addChangeListener(new javax.swing.event.ChangeListener {
- def stateChanged(e: javax.swing.event.ChangeEvent) {
- publish(new ValueChanged(Slider.this))
+ def stateChanged(e: javax.swing.event.ChangeEvent) {
+ publish(new ValueChanged(Slider.this))
}
})
}
diff --git a/scala/swing/SplitPane.scala b/scala/swing/SplitPane.scala
index 901e4d5..583e480 100644
--- a/scala/swing/SplitPane.scala
+++ b/scala/swing/SplitPane.scala
@@ -14,51 +14,51 @@ import event._
import Swing._
/**
- * A container with exactly two children. Arranges them side by side, either
- * horizontally or vertically. Displays a draggable divider component between
- * them that lets the user adjust the size ratio of the children.
- *
+ * A container with exactly two children. Arranges them side by side, either
+ * horizontally or vertically. Displays a draggable divider component between
+ * them that lets the user adjust the size ratio of the children.
+ *
* @see javax.swing.JSplitPane
*/
class SplitPane(o: Orientation.Value, left: Component, right: Component) extends Component with Container with Orientable.Wrapper {
- override lazy val peer: javax.swing.JSplitPane =
+ override lazy val peer: javax.swing.JSplitPane =
new javax.swing.JSplitPane(o.id, left.peer, right.peer) with SuperMixin
def this(o: Orientation.Value) = this(o, new Component {}, new Component {})
def this() = this(Orientation.Horizontal)
-
+
def contents: Seq[Component] = List(leftComponent, rightComponent)
def contents_=(left: Component, right: Component) {
peer.setLeftComponent(left.peer)
peer.setRightComponent(right.peer)
}
-
- def topComponent: Component =
+
+ def topComponent: Component =
UIElement.cachedWrapper[Component](peer.getTopComponent.asInstanceOf[javax.swing.JComponent])
def topComponent_=(c: Component) { peer.setTopComponent(c.peer) }
- def bottomComponent: Component =
+ def bottomComponent: Component =
UIElement.cachedWrapper[Component](peer.getBottomComponent.asInstanceOf[javax.swing.JComponent])
def bottomComponent_=(c: Component) { peer.setBottomComponent(c.peer) }
-
+
def leftComponent: Component = topComponent
def leftComponent_=(c: Component) { topComponent = c }
def rightComponent: Component = bottomComponent
def rightComponent_=(c: Component) { bottomComponent = c }
-
+
def dividerLocation: Int = peer.getDividerLocation
def dividerLocation_=(n: Int) { peer.setDividerLocation(n) }
-
- /*def proportionalDividerLocation: Double =
+
+ /*def proportionalDividerLocation: Double =
if (orientation == Orientation.Vertical) dividerLocation / (size.height - dividerSize)
else dividerLocation / (size.width - dividerSize)*/
def dividerLocation_=(f: Double) { peer.setDividerLocation(f) }
-
+
def dividerSize: Int = peer.getDividerSize
def dividerSize_=(n: Int) { peer.setDividerSize(n) }
def resizeWeight: Double = peer.getResizeWeight
def resizeWeight_=(n: Double) { peer.setResizeWeight(n) }
-
+
def resetToPreferredSizes() { peer.resetToPreferredSizes() }
-
+
def oneTouchExpandable: Boolean = peer.isOneTouchExpandable
def oneTouchExpandable_=(b: Boolean) { peer.setOneTouchExpandable(b) }
def continuousLayout: Boolean = peer.isContinuousLayout
diff --git a/scala/swing/Swing.scala b/scala/swing/Swing.scala
index 05533b5..551c154 100644
--- a/scala/swing/Swing.scala
+++ b/scala/swing/Swing.scala
@@ -26,7 +26,7 @@ object Swing {
implicit def pair2Dimension(p: (Int, Int)): Dimension = new Dimension(p._1, p._2)
implicit def pair2Point(p: (Int, Int)): Point = new Point(p._1, p._2)
implicit def pair2Point(p: (Int, Int, Int, Int)): Rectangle = new Rectangle(p._1, p._2, p._3, p._4)
-
+
@inline final def Runnable(@inline block: =>Unit) = new Runnable {
def run = block
}
@@ -36,9 +36,9 @@ object Swing {
final def ActionListener(f: ActionEvent => Unit) = new ActionListener {
def actionPerformed(e: ActionEvent) { f(e) }
}
-
+
def Box(min: Dimension, pref: Dimension, max: Dimension) = new Component {
- override lazy val peer = new javax.swing.Box.Filler(min, pref, max)
+ override lazy val peer = new javax.swing.Box.Filler(min, pref, max)
}
def HGlue = new Component {
override lazy val peer = javax.swing.Box.createHorizontalGlue.asInstanceOf[JComponent]
@@ -58,13 +58,13 @@ object Swing {
def VStrut(height: Int) = new Component {
override lazy val peer = javax.swing.Box.createVerticalStrut(height).asInstanceOf[JComponent]
}
-
+
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 null to indicate
+ * The empty icon. Use this icon instead of null to indicate
* that you don't want an icon.
*/
case object EmptyIcon extends Icon {
@@ -72,33 +72,33 @@ object Swing {
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) =
+ def EmptyBorder(weight: Int) =
BorderFactory.createEmptyBorder(weight, weight, weight, weight)
- def EmptyBorder(top: Int, left: Int, bottom: Int, right: Int) =
+ 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) =
+ 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,
+ 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
@@ -107,7 +107,7 @@ object Swing {
def bevelPeer = BevelBorder.RAISED
def etchPeer = javax.swing.border.EtchedBorder.RAISED
}
-
+
def EtchedBorder = BorderFactory.createEtchedBorder()
def EtchedBorder(kind: Embossing) =
BorderFactory.createEtchedBorder(kind.etchPeer)
@@ -118,21 +118,21 @@ object Swing {
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) =
+
+ def CompoundBorder(outside: Border, inside: Border) =
BorderFactory.createCompoundBorder(outside, inside)
-
- def TitledBorder(border: Border, title: String) =
- BorderFactory.createTitledBorder(border, title)
-
+
+ def TitledBorder(border: Border, title: String) =
+ BorderFactory.createTitledBorder(border, title)
+
/**
- * Schedule the given code to be executed on the Swing event dispatching
+ * Schedule the given code to be executed on the Swing event dispatching
* thread (EDT). Returns immediately.
*/
@inline final def onEDT(op: =>Unit) = SwingUtilities invokeLater Runnable(op)
/**
- * Schedule the given code to be executed on the Swing event dispatching
+ * Schedule the given code to be executed on the Swing event dispatching
* thread (EDT). Blocks until after the code has been run.
*/
@inline final def onEDTWait(op: =>Unit) = SwingUtilities invokeAndWait Runnable(op)
diff --git a/scala/swing/SwingApplication.scala b/scala/swing/SwingApplication.scala
index a7285a5..e4a51ca 100644
--- a/scala/swing/SwingApplication.scala
+++ b/scala/swing/SwingApplication.scala
@@ -2,7 +2,7 @@ package scala.swing
abstract class SwingApplication extends Reactor {
def main(args: Array[String]) = Swing.onEDT { startup(args) }
-
+
def startup(args: Array[String])
def quit() { shutdown(); System.exit(0) }
def shutdown() {}
diff --git a/scala/swing/SwingWorker.scala b/scala/swing/SwingWorker.scala
index 1755990..0e514e3 100644
--- a/scala/swing/SwingWorker.scala
+++ b/scala/swing/SwingWorker.scala
@@ -3,18 +3,18 @@ package scala.swing
import scala.actors._
object SwingWorker {
-
+
}
-abstract class SwingWorker extends Actor {
+abstract class SwingWorker extends Actor {
def queue() {
-
+
}
-
+
def done() {
-
+
}
-
+
private var _cancelled = false
def cancelled: Boolean = _cancelled
def cancelled_=(b: Boolean) { _cancelled = b }
diff --git a/scala/swing/TabbedPane.scala b/scala/swing/TabbedPane.scala
index 92dd148..f87209f 100644
--- a/scala/swing/TabbedPane.scala
+++ b/scala/swing/TabbedPane.scala
@@ -20,26 +20,26 @@ object TabbedPane {
val Wrap = Value(JTabbedPane.WRAP_TAB_LAYOUT)
val Scroll = Value(JTabbedPane.SCROLL_TAB_LAYOUT)
}
-
+
class Page protected[TabbedPane](parent0: TabbedPane, title0: String, content0: Component, tip0: String) extends Proxy {
def self = content0
-
- def this(title0: String, content0: Component, tip0: String) =
+
+ def this(title0: String, content0: Component, tip0: String) =
this(null, title0, content0, tip0)
- def this(title0: String, content0: Component) =
+ def this(title0: String, content0: Component) =
this(title0, content0, "")
content = content0 // first add component, *then* set other things
title = title0
tip = tip0
-
+
protected[TabbedPane] var parent: TabbedPane = parent0
-
+
protected var _title = title0
def title: String = _title
- def title_=(t: String) {
+ def title_=(t: String) {
// beware to keep this order since, index depends on the _old_ title
if (parent != null) parent.peer.setTitleAt(index, t)
- _title = t
+ _title = t
}
protected var _content = content0
def content: Component = _content//UIElement.cachedWrapper(peer.getComponentAt(index).asInstanceOf[JComponent])
@@ -60,28 +60,28 @@ object TabbedPane {
def background: Color = _background //peer.getBackgroundAt(index)
def background_=(c: Color) { _background = c; if (parent != null) parent.peer.setBackgroundAt(index, c)}
def bounds: Rectangle = parent.peer.getBoundsAt(index)
-
+
// TODO: icon, disabledIcon
-
+
def index = if(parent != null) parent.peer.indexOfTab(title) else 0//_index
//protected[TabbedPane] var _index: Int = index0
}
}
/**
- * Displays the contents of one of several pages at a time. For each page a tab is
- * visible at all times. The user can click on one of these tabs to move the
+ * Displays the contents of one of several pages at a time. For each page a tab is
+ * visible at all times. The user can click on one of these tabs to move the
* corresponding page to the front.
- *
+ *
* @see javax.swing.JTabbedPane
*/
class TabbedPane extends Component with Publisher {
override lazy val peer: JTabbedPane = new JTabbedPane with SuperMixin
import TabbedPane._
-
+
object pages extends BufferWrapper[Page] {
def runCount: Int = peer.getTabRunCount
-
+
def remove(n: Int): Page = {
val t = apply(n)
peer.removeTabAt(n)
@@ -92,38 +92,38 @@ class TabbedPane extends Component with Publisher {
protected def insertAt(n: Int, t: Page) {
//for(i <- n to length) apply(i)._index += 1
t.parent = TabbedPane.this
- peer.insertTab(t.title, null, t.content.peer, t.tip, n)
+ peer.insertTab(t.title, null, t.content.peer, t.tip, n)
}
def +=(t: Page): this.type = { t.parent = TabbedPane.this; peer.addTab(t.title, null, t.content.peer, t.tip); this }
def length = peer.getTabCount
def apply(n: Int) = new Page(TabbedPane.this, peer.getTitleAt(n),
- UIElement.cachedWrapper[Component](peer.getComponentAt(n).asInstanceOf[javax.swing.JComponent]),
+ UIElement.cachedWrapper[Component](peer.getComponentAt(n).asInstanceOf[javax.swing.JComponent]),
peer.getToolTipTextAt(n))
}
-
+
def tabLayoutPolicy: Layout.Value = Layout(peer.getTabLayoutPolicy)
def tabLayoutPolicy_=(p: Layout.Value) { peer.setTabLayoutPolicy(p.id) }
-
-
+
+
def tabPlacement: Alignment.Value = Alignment(peer.getTabPlacement)
/**
* Possible values are Left, Right, Top, Bottom.
*/
def tabPlacement(b: Alignment.Value) { peer.setTabPlacement(b.id) }
-
+
/**
* The current page selection
*/
object selection extends Publisher {
def page: Page = pages(index)
def page_=(p: Page) { index = p.index }
-
+
def index: Int = peer.getSelectedIndex
def index_=(n: Int) { peer.setSelectedIndex(n) }
-
+
peer.addChangeListener(new javax.swing.event.ChangeListener {
- def stateChanged(e: javax.swing.event.ChangeEvent) {
+ def stateChanged(e: javax.swing.event.ChangeEvent) {
publish(SelectionChanged(TabbedPane.this))
}
})
diff --git a/scala/swing/Table.scala b/scala/swing/Table.scala
index 5673198..0a9eb63 100644
--- a/scala/swing/Table.scala
+++ b/scala/swing/Table.scala
@@ -25,7 +25,7 @@ object Table {
val LastColumn = Value(AUTO_RESIZE_LAST_COLUMN, "LastColumn")
val AllColumns = Value(AUTO_RESIZE_ALL_COLUMNS, "AllColumns")
}
-
+
object IntervalMode extends Enumeration {
val Single = Value(ListSelectionModel.SINGLE_SELECTION)
val SingleInterval = Value(ListSelectionModel.SINGLE_INTERVAL_SELECTION)
@@ -34,10 +34,10 @@ object Table {
object ElementMode extends Enumeration {
val Row, Column, Cell, None = Value
}
-
+
/**
* A table item renderer.
- *
+ *
* @see javax.swing.table.TableCellRenderer
*/
abstract class Renderer[-A] {
@@ -51,10 +51,10 @@ object Table {
}
def componentFor(table: Table, isSelected: Boolean, hasFocus: Boolean, a: A, row: Int, column: Int): Component
}
-
+
abstract class AbstractRenderer[-A, C<:Component](val component: C) extends Renderer[A] {
- // The renderer component is responsible for painting selection
- // backgrounds. Hence, make sure it is opaque to let it draw
+ // The renderer component is responsible for painting selection
+ // backgrounds. Hence, make sure it is opaque to let it draw
// the background.
component.opaque = true
@@ -84,42 +84,42 @@ object Table {
component
}
}
-
+
class LabelRenderer[A](convert: A => (Icon, String)) extends AbstractRenderer[A, Label](new Label) {
def this() {
this{ a => (null, a.toString) }
}
-
+
def configure(table: Table, isSelected: Boolean, hasFocus: Boolean, a: A, row: Int, column: Int) {
val (icon, text) = convert(a)
component.icon = icon
component.text = text
}
}
-
+
private[swing] trait JTableMixin { def tableWrapper: Table }
}
/**
* Displays a matrix of items.
- *
- * To obtain a scrollable table or row and columns headers,
+ *
+ * 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.Wrapper {
override lazy val peer: JTable = new JTable with Table.JTableMixin with SuperMixin {
def tableWrapper = Table.this
override def getCellRenderer(r: Int, c: Int) = new TableCellRenderer {
- def getTableCellRendererComponent(table: JTable, value: AnyRef, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int) =
+ def getTableCellRendererComponent(table: JTable, value: AnyRef, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int) =
Table.this.rendererComponent(isSelected, hasFocus, row, column).peer
}
override def getCellEditor(r: Int, c: Int) = editor(r, c)
override def getValueAt(r: Int, c: Int) = Table.this.apply(r,c).asInstanceOf[AnyRef]
}
import Table._
-
+
// TODO: use IndexedSeq[_ <: IndexedSeq[Any]], see ticket #2005
def this(rowData: Array[Array[Any]], columnNames: Seq[_]) = {
this()
@@ -145,81 +145,81 @@ class Table extends Component with Scrollable.Wrapper {
}
protected def scrollablePeer = peer
-
+
def rowHeight = peer.getRowHeight
def rowHeight_=(x: Int) = peer.setRowHeight(x)
-
+
def rowCount = peer.getRowCount
-
+
def model = peer.getModel()
def model_=(x: TableModel) = {
peer.setModel(x)
model.removeTableModelListener(modelListener)
model.addTableModelListener(modelListener)
}
-
+
def autoResizeMode: AutoResizeMode.Value = AutoResizeMode(peer.getAutoResizeMode)
def autoResizeMode_=(x: Table.AutoResizeMode.Value) = peer.setAutoResizeMode(x.id)
-
+
def showGrid = peer.getShowHorizontalLines && peer.getShowVerticalLines
def showGrid_=(grid: Boolean) = peer.setShowGrid(grid)
-
+
def gridColor = peer.getGridColor
def gridColor_=(color: Color) = peer.setGridColor(color)
-
+
def preferredViewportSize_=(dim: Dimension) = peer.setPreferredScrollableViewportSize(dim)
//1.6: def fillsViewportHeight: Boolean = peer.getFillsViewportHeight
//def fillsViewportHeight_=(b: Boolean) = peer.setFillsViewportHeight(b)
-
+
object selection extends Publisher {
// TODO: could be a sorted set
- protected abstract class SelectionSet[A](a: =>Seq[A]) extends mutable.Set[A] {
- def -=(n: A): this.type
+ protected abstract class SelectionSet[A](a: =>Seq[A]) extends mutable.Set[A] {
+ def -=(n: A): this.type
def +=(n: A): this.type
def contains(n: A) = a.contains(n)
override def size = a.length
def iterator = a.iterator
}
-
+
object rows extends SelectionSet(peer.getSelectedRows) {
def -=(n: Int) = { peer.removeRowSelectionInterval(n,n); this }
def +=(n: Int) = { peer.addRowSelectionInterval(n,n); this }
-
+
def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex
def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex
}
-
- object columns extends SelectionSet(peer.getSelectedColumns) {
+
+ object columns extends SelectionSet(peer.getSelectedColumns) {
def -=(n: Int) = { peer.removeColumnSelectionInterval(n,n); this }
def +=(n: Int) = { peer.addColumnSelectionInterval(n,n); this }
-
+
def leadIndex: Int = peer.getColumnModel.getSelectionModel.getLeadSelectionIndex
def anchorIndex: Int = peer.getColumnModel.getSelectionModel.getAnchorSelectionIndex
}
- def cells: mutable.Set[(Int, Int)] =
+ def cells: mutable.Set[(Int, Int)] =
new SelectionSet[(Int, Int)]((for(r <- selection.rows; c <- selection.columns) yield (r,c)).toSeq) { outer =>
- def -=(n: (Int, Int)) = {
+ def -=(n: (Int, Int)) = {
peer.removeRowSelectionInterval(n._1,n._1)
peer.removeColumnSelectionInterval(n._2,n._2)
this
}
- def +=(n: (Int, Int)) = {
+ def +=(n: (Int, Int)) = {
peer.addRowSelectionInterval(n._1,n._1)
peer.addColumnSelectionInterval(n._2,n._2)
this
}
override def size = peer.getSelectedRowCount * peer.getSelectedColumnCount
}
-
+
/**
- * From the JTable Swing tutorial:
- * You can specify selection by cell in multiple interval selection mode,
+ * From the JTable Swing tutorial:
+ * You can specify selection by cell in multiple interval selection mode,
* but the result is a table that does not produce useful selections.
*/
def intervalMode: IntervalMode.Value = IntervalMode(peer.getSelectionModel.getSelectionMode)
def intervalMode_=(m: IntervalMode.Value) { peer.setSelectionMode(m.id) }
- def elementMode: ElementMode.Value =
+ def elementMode: ElementMode.Value =
if(peer.getColumnSelectionAllowed && peer.getRowSelectionAllowed) ElementMode.Cell
else if(peer.getColumnSelectionAllowed) ElementMode.Column
else if(peer.getRowSelectionAllowed) ElementMode.Row
@@ -232,7 +232,7 @@ class Table extends Component with Scrollable.Wrapper {
case ElementMode.None => peer.setRowSelectionAllowed(false); peer.setColumnSelectionAllowed(false)
}
}
-
+
peer.getColumnModel.getSelectionModel.addListSelectionListener(new ListSelectionListener {
def valueChanged(e: javax.swing.event.ListSelectionEvent) {
publish(TableColumnsSelected(Table.this, e.getFirstIndex to e.getLastIndex, e.getValueIsAdjusting))
@@ -244,22 +244,22 @@ class Table extends Component with Scrollable.Wrapper {
}
})
}
-
+
/**
* Supplies a renderer component for a given cell.
*/
- protected def rendererComponent(isSelected: Boolean, focused: Boolean, row: Int, column: Int): Component =
- new 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,
+ Table.this.peer.getDefaultRenderer(v.getClass).getTableCellRendererComponent(Table.this.peer,
v, isSelected, focused, row, column).asInstanceOf[JComponent]
- else Table.this.peer.getDefaultRenderer(classOf[Object]).getTableCellRendererComponent(Table.this.peer,
+ else Table.this.peer.getDefaultRenderer(classOf[Object]).getTableCellRendererComponent(Table.this.peer,
v, isSelected, focused, row, column).asInstanceOf[JComponent]
}
}
-
+
// TODO: a public API for setting editors
protected def editor(row: Int, column: Int) = {
val v = apply(row, column).asInstanceOf[AnyRef]
@@ -268,18 +268,18 @@ class Table extends Component with Scrollable.Wrapper {
else
Table.this.peer.getDefaultEditor(classOf[Object])
}
-
+
/**
- * Get the current value of the given cell.
- * The given cell coordinates are in view coordinates and thus not
+ * Get the current value of the given cell.
+ * The given cell coordinates are in view coordinates and thus not
* necessarily the same as for the model.
*/
def apply(row: Int, column: Int): Any = model.getValueAt(row, viewToModelColumn(column))
-
+
def viewToModelColumn(idx: Int) = peer.convertColumnIndexToModel(idx)
def modelToViewColumn(idx: Int) = peer.convertColumnIndexToView(idx)
-
+
/**
* Change the value of the given cell.
*/
@@ -294,7 +294,7 @@ class Table extends Component with Scrollable.Wrapper {
def selectionForeground_=(c: Color) = peer.setSelectionForeground(c)
def selectionBackground: Color = peer.getSelectionBackground
def selectionBackground_=(c: Color) = peer.setSelectionBackground(c)
-
+
protected val modelListener = new TableModelListener {
def tableChanged(e: TableModelEvent) = publish(
e.getType match {
diff --git a/scala/swing/TextArea.scala b/scala/swing/TextArea.scala
index 0292a88..fe2baa6 100644
--- a/scala/swing/TextArea.scala
+++ b/scala/swing/TextArea.scala
@@ -19,25 +19,25 @@ import java.awt.event._
*
* @see javax.swing.JTextArea
*/
-class TextArea(text0: String, rows0: Int, columns0: Int) extends TextComponent
+class TextArea(text0: String, rows0: Int, columns0: Int) extends TextComponent
with TextComponent.HasColumns with TextComponent.HasRows {
override lazy val peer: JTextArea = new JTextArea(text0, rows0, columns0) with SuperMixin
def this(text: String) = this(text, 0, 0)
def this(rows: Int, columns: Int) = this("", rows, columns)
def this() = this("", 0, 0)
-
+
// TODO: we could make contents StringBuilder-like
def append(t: String) { peer.append(t) }
-
+
def rows: Int = peer.getRows
def rows_=(n: Int) = peer.setRows(n)
def columns: Int = peer.getColumns
def columns_=(n: Int) = peer.setColumns(n)
-
+
def tabSize: Int = peer.getTabSize
def tabSize_=(n: Int) = peer.setTabSize(n)
def lineCount: Int = peer.getLineCount
-
+
def lineWrap: Boolean = peer.getLineWrap
def lineWrap_=(w: Boolean) = peer.setLineWrap(w)
def wordWrap: Boolean = peer.getWrapStyleWord
diff --git a/scala/swing/TextComponent.scala b/scala/swing/TextComponent.scala
index 5abc5cc..61ff330 100644
--- a/scala/swing/TextComponent.scala
+++ b/scala/swing/TextComponent.scala
@@ -16,7 +16,7 @@ import javax.swing.text._
import javax.swing.event._
object TextComponent {
- trait HasColumns extends TextComponent {
+ trait HasColumns extends TextComponent {
def columns: Int
def columns_=(n: Int)
}
@@ -35,7 +35,7 @@ class TextComponent extends Component with Publisher {
override lazy val peer: JTextComponent = new JTextComponent with SuperMixin {}
def text: String = peer.getText
def text_=(t: String) = peer.setText(t)
-
+
class Caret extends Publisher {
def dot: Int = peer.getCaret.getDot
def dot_=(n: Int) { peer.getCaret.setDot(n) }
@@ -51,14 +51,14 @@ class TextComponent extends Component with Publisher {
def color_=(c: Color) = peer.setCaretColor(c)
def position: Int = peer.getCaretPosition
def position_=(p: Int) = peer.setCaretPosition(p)
-
+
peer.addCaretListener {
new CaretListener {
- def caretUpdate(e: CaretEvent) { publish(CaretUpdate(TextComponent.this)) }
+ def caretUpdate(e: CaretEvent) { publish(CaretUpdate(TextComponent.this)) }
}
}
}
-
+
object caret extends Caret
def editable: Boolean = peer.isEditable
@@ -67,9 +67,9 @@ class TextComponent extends Component with Publisher {
def copy() { peer.copy() }
def paste() { peer.paste() }
def selected: String = peer.getSelectedText
-
+
def selectAll() { peer.selectAll() }
-
+
peer.getDocument.addDocumentListener(new DocumentListener {
def changedUpdate(e:DocumentEvent) { publish(new ValueChanged(TextComponent.this)) }
def insertUpdate(e:DocumentEvent) { publish(new ValueChanged(TextComponent.this)) }
diff --git a/scala/swing/TextField.scala b/scala/swing/TextField.scala
index d7dd83c..dc5a4a3 100644
--- a/scala/swing/TextField.scala
+++ b/scala/swing/TextField.scala
@@ -26,11 +26,11 @@ import java.awt.event._
/**
* A text component that allows single line text input and display.
- *
+ *
* @see javax.swing.JTextField
*/
class TextField(text0: String, columns0: Int) extends TextComponent with TextComponent.HasColumns with Action.Trigger.Wrapper {
- override lazy val peer: JTextField = new JTextField(text0, columns0) with SuperMixin
+ override lazy val peer: JTextField = new JTextField(text0, columns0) with SuperMixin
def this(text: String) = this(text, 0)
def this(columns: Int) = this("", columns)
def this() = this("")
@@ -42,11 +42,11 @@ class TextField(text0: String, columns0: Int) extends TextComponent with TextCom
def horizontalAlignment: Alignment.Value = Alignment(peer.getHorizontalAlignment)
/** @see javax.swing.JTextField#setHorizontalAlignment() */
def horizontalAlignment_=(x: Alignment.Value) { peer.setHorizontalAlignment(x.id) }
-
+
private lazy val actionListener = Swing.ActionListener { e =>
publish(EditDone(TextField.this))
}
-
+
protected override def onFirstSubscribe {
super.onFirstSubscribe
peer.addActionListener(actionListener)
@@ -54,22 +54,22 @@ class TextField(text0: String, columns0: Int) extends TextComponent with TextCom
override def focusLost(e: java.awt.event.FocusEvent) { publish(EditDone(TextField.this)) }
})
}
-
+
protected override def onLastUnsubscribe {
super.onLastUnsubscribe
peer.removeActionListener(actionListener)
}
-
- def verifier: String => Boolean = s => peer.getInputVerifier.verify(peer)
- def verifier_=(v: String => Boolean) {
+
+ def verifier: String => Boolean = s => peer.getInputVerifier.verify(peer)
+ def verifier_=(v: String => Boolean) {
peer.setInputVerifier(new InputVerifier {
private val old = peer.getInputVerifier
def verify(c: JComponent) = v(text)
override def shouldYieldFocus(c: JComponent) = old.shouldYieldFocus(c)
- })
+ })
}
def shouldYieldFocus: String=>Boolean = s => peer.getInputVerifier.shouldYieldFocus(peer)
- def shouldYieldFocus_=(y: String=>Boolean) {
+ def shouldYieldFocus_=(y: String=>Boolean) {
peer.setInputVerifier(new InputVerifier {
private val old = peer.getInputVerifier
def verify(c: JComponent) = old.verify(c)
diff --git a/scala/swing/ToggleButton.scala b/scala/swing/ToggleButton.scala
index 0e7b7f0..45a2f89 100644
--- a/scala/swing/ToggleButton.scala
+++ b/scala/swing/ToggleButton.scala
@@ -14,9 +14,9 @@ import event._
import javax.swing._
/**
- * A two state button with a push button like user interface.
+ * A two state button with a push button like user interface.
* Usually used in tool bars.
- *
+ *
* @see javax.swing.JToggleButton
*/
class ToggleButton(text0: String) extends AbstractButton {
diff --git a/scala/swing/UIElement.scala b/scala/swing/UIElement.scala
index d58d12f..8ba9493 100644
--- a/scala/swing/UIElement.scala
+++ b/scala/swing/UIElement.scala
@@ -24,16 +24,16 @@ object UIElement {
case p: javax.swing.JComponent => p.putClientProperty(ClientKey, e)
case _ => wrapperCache.put(e.peer, new WeakReference(e))
}
-
+
/**
- * Looks up the internal component cache for a wrapper of the given
- * Java Swing peer. If this method finds one of the given type `C`,
- * it will return that wrapper. Otherwise it returns `null`. This
+ * Looks up the internal component cache for a wrapper of the given
+ * Java Swing peer. If this method finds one of the given type `C`,
+ * it will return that wrapper. Otherwise it returns `null`. This
* method never throws an exception.
- *
- * Clients should be extremely careful with type parameter `C` and
- * its interaction with type inference. Better err on the side of caution
- * and explicitly specify `C`.
+ *
+ * Clients should be extremely careful with type parameter `C` and
+ * its interaction with type inference. Better err on the side of caution
+ * and explicitly specify `C`.
*/
private[swing] def cachedWrapper[C>:Null<:UIElement](c: java.awt.Component): C = {
val w = c match {
@@ -42,33 +42,33 @@ object UIElement {
}
try { w.asInstanceOf[C] } catch { case _ => null }
}
-
+
/**
- * Returns a wrapper for a given Java Swing peer. If there is a
+ * Returns a wrapper for a given Java Swing peer. If there is a
* compatible wrapper in use, this method will return it.
- *
- * `wrap` methods in companion objects of subclasses of UIElement have the
+ *
+ * `wrap` methods in companion objects of subclasses of UIElement have the
* same behavior, except that they return more specific wrappers.
*/
def wrap(c: java.awt.Component): UIElement = {
val w = cachedWrapper[UIElement](c)
- if (w != null) w
+ if (w != null) w
else new UIElement { def peer = c }
}
}
/**
- * The base trait of all user interface elements. Subclasses belong to one
- * of two groups: top-level elements such as windows and dialogs, or
+ * The base trait of all user interface elements. Subclasses belong to one
+ * of two groups: top-level elements such as windows and dialogs, or
* Components.
- *
- * @note [Java Swing] This trait does not have an exact counterpart in
- * Java Swing. The peer is of type java.awt.Component since this is the
+ *
+ * @note [Java Swing] This trait does not have an exact counterpart in
+ * Java Swing. The peer is of type java.awt.Component since this is the
* least common upper bound of possible underlying peers.
- *
- * @note [Implementation] A UIElement automatically adds itself to the
+ *
+ * @note [Implementation] A UIElement automatically adds itself to the
* component cache on creation.
- *
+ *
* @see java.awt.Component
*/
trait UIElement extends Proxy with LazyPublisher {
@@ -77,61 +77,61 @@ trait UIElement extends Proxy with LazyPublisher {
*/
def peer: java.awt.Component
def self = peer
-
+
UIElement.cache(this)
-
+
def foreground: Color = peer.getForeground
def foreground_=(c: Color) = peer.setForeground(c)
def background: Color = peer.getBackground
def background_=(c: Color) = peer.setBackground(c)
-
+
def minimumSize = peer.getMinimumSize
def minimumSize_=(x: Dimension) = peer.setMinimumSize(x)
def maximumSize = peer.getMaximumSize
def maximumSize_=(x: Dimension) = peer.setMaximumSize(x)
def preferredSize = peer.getPreferredSize
def preferredSize_=(x: Dimension) = peer.setPreferredSize(x)
-
+
def font: Font = peer.getFont
def font_=(f: Font) = peer.setFont(f)
-
+
def locationOnScreen = peer.getLocationOnScreen
def location = peer.getLocation
def bounds = peer.getBounds
def size = peer.getSize
@deprecated("Explicit size assignement for UIElements is not supported anymore. " +
- "Use a layout manager or subclass Window.")
+ "Use a layout manager or subclass Window.")
def size_=(dim: Dimension) = peer.setSize(dim)
def locale = peer.getLocale
def toolkit = peer.getToolkit
-
+
def cursor: Cursor = peer.getCursor
def cursor_=(c: Cursor) { peer.setCursor(c) }
-
+
def visible: Boolean = peer.isVisible
def visible_=(b: Boolean) { peer.setVisible(b) }
def showing: Boolean = peer.isShowing
def displayable: Boolean = peer.isDisplayable
-
+
def repaint() { peer.repaint }
def repaint(rect: Rectangle) { peer.repaint(rect.x, rect.y, rect.width, rect.height) }
def ignoreRepaint: Boolean = peer.getIgnoreRepaint
def ignoreRepaint_=(b: Boolean) { peer.setIgnoreRepaint(b) }
-
+
protected def onFirstSubscribe {
peer.addComponentListener(new java.awt.event.ComponentListener {
- def componentHidden(e: java.awt.event.ComponentEvent) {
- publish(UIElementHidden(UIElement.this))
+ def componentHidden(e: java.awt.event.ComponentEvent) {
+ publish(UIElementHidden(UIElement.this))
}
- def componentShown(e: java.awt.event.ComponentEvent) {
- publish(UIElementShown(UIElement.this))
+ def componentShown(e: java.awt.event.ComponentEvent) {
+ publish(UIElementShown(UIElement.this))
}
- def componentMoved(e: java.awt.event.ComponentEvent) {
- publish(UIElementMoved(UIElement.this))
+ def componentMoved(e: java.awt.event.ComponentEvent) {
+ publish(UIElementMoved(UIElement.this))
}
- def componentResized(e: java.awt.event.ComponentEvent) {
- publish(UIElementResized(UIElement.this))
+ def componentResized(e: java.awt.event.ComponentEvent) {
+ publish(UIElementResized(UIElement.this))
}
})
}
diff --git a/scala/swing/Window.scala b/scala/swing/Window.scala
index 101cd2d..4eeefc0 100644
--- a/scala/swing/Window.scala
+++ b/scala/swing/Window.scala
@@ -16,19 +16,19 @@ import javax.swing._
/**
* A window with decoration such as a title, border, and action buttons.
- *
- * An AWT window cannot be wrapped dynamically with this class, i.e., you cannot
+ *
+ * An AWT window cannot be wrapped dynamically with this class, i.e., you cannot
* write something like new Window { def peer = myAWTWindow }
- *
+ *
* @see javax.swing.JFrame
*/
abstract class Window extends UIElement with RootPanel with Publisher { outer =>
def peer: AWTWindow with InterfaceMixin
-
+
protected trait InterfaceMixin extends javax.swing.RootPaneContainer
-
+
/**
- * This method is called when the window is closing, after all other window
+ * This method is called when the window is closing, after all other window
* event listeners have been processed.
*/
def closeOperation() {}
@@ -37,30 +37,30 @@ abstract class Window extends UIElement with RootPanel with Publisher { outer =>
super.contents_=(c)
peer.pack() // pack also validates, which is generally required after an add
}
- def defaultButton: Option[Button] =
+ def defaultButton: Option[Button] =
toOption(peer.getRootPane.getDefaultButton) map UIElement.cachedWrapper[Button]
- def defaultButton_=(b: Button) {
- peer.getRootPane.setDefaultButton(b.peer)
+ def defaultButton_=(b: Button) {
+ peer.getRootPane.setDefaultButton(b.peer)
}
- def defaultButton_=(b: Option[Button]) {
+ def defaultButton_=(b: Option[Button]) {
peer.getRootPane.setDefaultButton(b map (_.peer) orNull)
}
-
+
def dispose() { peer.dispose() }
-
+
def pack(): this.type = { peer.pack(); this }
-
+
def setLocationRelativeTo(c: UIElement) { peer.setLocationRelativeTo(c.peer) }
def centerOnScreen() { peer.setLocationRelativeTo(null) }
def location_=(p: Point) { peer.setLocation(p) }
override def size_=(size: Dimension) { peer.setSize(size) }
def bounds_=(rect: Rectangle) { peer.setBounds(rect) }
-
+
def owner: Window = UIElement.cachedWrapper[Window](peer.getOwner)
-
+
def open() { peer setVisible true }
def close() { peer setVisible false }
-
+
peer.addWindowListener(new java.awt.event.WindowListener {
def windowActivated(e: java.awt.event.WindowEvent) { publish(WindowActivated(outer)) }
def windowClosed(e: java.awt.event.WindowEvent) { publish(WindowClosed(outer)) }
diff --git a/scala/swing/event/AdjustingEvent.scala b/scala/swing/event/AdjustingEvent.scala
index 823ee1f..55e51d7 100644
--- a/scala/swing/event/AdjustingEvent.scala
+++ b/scala/swing/event/AdjustingEvent.scala
@@ -13,7 +13,7 @@ package event
/**
* An event that indicates some editing operation that can be still in
- * progress.
+ * progress.
* Example: dragging a slider creates a number of AdjustmentEvents
* with adjusting == true until the user finally releases the
* mouse button.
diff --git a/scala/swing/event/ComponentEvent.scala b/scala/swing/event/ComponentEvent.scala
index ae015ef..582932a 100644
--- a/scala/swing/event/ComponentEvent.scala
+++ b/scala/swing/event/ComponentEvent.scala
@@ -15,11 +15,11 @@ trait ComponentEvent extends UIEvent {
val source: Component
}
-@deprecated("Use UIElementMoved instead.")
+@deprecated("Use UIElementMoved instead.")
case class ComponentMoved(source: Component) extends ComponentEvent
-@deprecated("Use UIElementResized instead.")
+@deprecated("Use UIElementResized instead.")
case class ComponentResized(source: Component) extends ComponentEvent
-@deprecated("Use UIElementShown instead.")
+@deprecated("Use UIElementShown instead.")
case class ComponentShown(source: Component) extends ComponentEvent
-@deprecated("Use UIElementHidden instead.")
+@deprecated("Use UIElementHidden instead.")
case class ComponentHidden(source: Component) extends ComponentEvent
diff --git a/scala/swing/event/FocusEvent.scala b/scala/swing/event/FocusEvent.scala
index d20bdd5..7f74000 100644
--- a/scala/swing/event/FocusEvent.scala
+++ b/scala/swing/event/FocusEvent.scala
@@ -16,8 +16,8 @@ package event
*/
abstract class FocusEvent(override val source: Component, val other: Option[Component], val temporary: Boolean) extends ComponentEvent
-case class FocusGained(override val source: Component, override val other: Option[Component], override val temporary: Boolean)
- extends FocusEvent(source, other, temporary)
+case class FocusGained(override val source: Component, override val other: Option[Component], override val temporary: Boolean)
+ extends FocusEvent(source, other, temporary)
-case class FocusLost(override val source: Component, override val other: Option[Component], override val temporary: Boolean)
- extends FocusEvent(source, other, temporary)
+case class FocusLost(override val source: Component, override val other: Option[Component], override val temporary: Boolean)
+ extends FocusEvent(source, other, temporary)
diff --git a/scala/swing/event/Key.scala b/scala/swing/event/Key.scala
index ec72767..5bc3ad6 100644
--- a/scala/swing/event/Key.scala
+++ b/scala/swing/event/Key.scala
@@ -24,9 +24,9 @@ object Key extends Enumeration {
val Standard = Value(java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)
val Unknown = Value(java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN)
}
-
+
type Modifiers = Int
-
+
object Modifier {
import java.awt.event.InputEvent._
val Shift = SHIFT_DOWN_MASK
@@ -36,21 +36,21 @@ object Key extends Enumeration {
val Meta = META_DOWN_MASK
def text(mods: Int) = java.awt.event.KeyEvent.getKeyModifiersText(mods)
}
-
+
//def text(k: Value) = java.awt.event.KeyEvent.getKeyText(k.id)
-
+
val Shift = Value(VK_SHIFT, getKeyText(VK_SHIFT))
val Control = Value(VK_CONTROL, getKeyText(VK_CONTROL))
val Alt = Value(VK_ALT, getKeyText(VK_ALT))
val AltGraph = Value(VK_ALT_GRAPH, getKeyText(VK_ALT_GRAPH))
val Meta = Value(VK_META, getKeyText(VK_META))
-
+
val Enter = Value(VK_ENTER, getKeyText(VK_ENTER))
val BackSpace = Value(VK_BACK_SPACE, getKeyText(VK_BACK_SPACE))
val Tab = Value(VK_TAB, getKeyText(VK_TAB))
val Cancel = Value(VK_CANCEL, getKeyText(VK_CANCEL))
val Clear = Value(VK_CLEAR, getKeyText(VK_CLEAR))
-
+
val Pause = Value(VK_PAUSE, getKeyText(VK_PAUSE))
val CapsLock = Value(VK_CAPS_LOCK, getKeyText(VK_CAPS_LOCK))
val Escape = Value(VK_ESCAPE, getKeyText(VK_ESCAPE))
diff --git a/scala/swing/event/KeyEvent.scala b/scala/swing/event/KeyEvent.scala
index d014f0b..ff0da50 100644
--- a/scala/swing/event/KeyEvent.scala
+++ b/scala/swing/event/KeyEvent.scala
@@ -17,27 +17,27 @@ sealed abstract class KeyEvent extends InputEvent {
def peer: java.awt.event.KeyEvent
}
-case class KeyTyped(val source: Component, char: Char, val modifiers: Key.Modifiers,
+case class KeyTyped(val source: Component, char: Char, val modifiers: Key.Modifiers,
location: Key.Location.Value)
(val peer: java.awt.event.KeyEvent) extends KeyEvent {
- def this(e: java.awt.event.KeyEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getKeyChar, e.getModifiersEx,
+ def this(e: java.awt.event.KeyEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getKeyChar, e.getModifiersEx,
Key.Location(e.getKeyLocation))(e)
-}
+}
-case class KeyPressed(val source: Component, key: Key.Value, val modifiers: Key.Modifiers,
+case class KeyPressed(val source: Component, key: Key.Value, val modifiers: Key.Modifiers,
location: Key.Location.Value)
(val peer: java.awt.event.KeyEvent) extends KeyEvent {
- def this(e: java.awt.event.KeyEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- Key(e.getKeyCode), e.getModifiersEx, Key.Location(e.getKeyLocation))(e)
+ def this(e: java.awt.event.KeyEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ Key(e.getKeyCode), e.getModifiersEx, Key.Location(e.getKeyLocation))(e)
}
-case class KeyReleased(val source: Component, key: Key.Value, val modifiers: Key.Modifiers,
+case class KeyReleased(val source: Component, key: Key.Value, val modifiers: Key.Modifiers,
location: Key.Location.Value)
(val peer: java.awt.event.KeyEvent) extends KeyEvent {
- def this(e: java.awt.event.KeyEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- Key(e.getKeyCode), e.getModifiersEx, Key.Location(e.getKeyLocation))(e)
+ def this(e: java.awt.event.KeyEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ Key(e.getKeyCode), e.getModifiersEx, Key.Location(e.getKeyLocation))(e)
}
diff --git a/scala/swing/event/ListEvent.scala b/scala/swing/event/ListEvent.scala
index 0c3c06e..b0dfc70 100644
--- a/scala/swing/event/ListEvent.scala
+++ b/scala/swing/event/ListEvent.scala
@@ -15,7 +15,7 @@ trait ListEvent[A] extends ComponentEvent {
override val source: ListView[A]
}
-//case class ElementSelected[A](override val source: ListView[A], range: Range, live: Boolean)
+//case class ElementSelected[A](override val source: ListView[A], range: Range, live: Boolean)
// extends ListEvent[A] with AdjustingEvent with ListSelectionEvent
abstract class ListChange[A](override val source: ListView[A]) extends ListEvent[A]
@@ -25,19 +25,19 @@ object ListChanged {
def apply[A](source: ListView[A]) = new ListChanged(source)
}
-class ListChanged[A](override val source: ListView[A]) extends ListChange(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)
+
+class ListElementsAdded[A](override val source: ListView[A], val range: Range)
extends ListChange(source)
-
+
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)
+class ListElementsRemoved[A](override val source: ListView[A], val range: Range)
+ extends ListChange(source)
diff --git a/scala/swing/event/MouseEvent.scala b/scala/swing/event/MouseEvent.scala
index 1e22887..8176a2a 100644
--- a/scala/swing/event/MouseEvent.scala
+++ b/scala/swing/event/MouseEvent.scala
@@ -23,57 +23,57 @@ sealed abstract class MouseButtonEvent extends MouseEvent {
def clicks: Int
def triggersPopup: Boolean
}
-case class MouseClicked(val source: Component, point: Point, val modifiers: Key.Modifiers,
+case class MouseClicked(val source: Component, point: Point, val modifiers: Key.Modifiers,
clicks: Int, triggersPopup: Boolean)(val peer: java.awt.event.MouseEvent)
extends MouseButtonEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
}
-case class MousePressed(val source: Component, point: Point, val modifiers: Key.Modifiers,
+case class MousePressed(val source: Component, point: Point, val modifiers: Key.Modifiers,
clicks: Int, triggersPopup: Boolean)(val peer: java.awt.event.MouseEvent)
extends MouseButtonEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
}
-case class MouseReleased(val source: Component, point: Point, val modifiers: Key.Modifiers,
+case class MouseReleased(val source: Component, point: Point, val modifiers: Key.Modifiers,
clicks: Int, triggersPopup: Boolean)(val peer: java.awt.event.MouseEvent)
extends MouseButtonEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx, e.getClickCount, e.isPopupTrigger)(e)
}
sealed abstract class MouseMotionEvent extends MouseEvent
case class MouseMoved(val source: Component, point: Point, val modifiers: Key.Modifiers)(val peer: java.awt.event.MouseEvent)
extends MouseMotionEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx)(e)
}
case class MouseDragged(val source: Component, point: Point, val modifiers: Key.Modifiers)(val peer: java.awt.event.MouseEvent)
extends MouseMotionEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx)(e)
}
case class MouseEntered(val source: Component, point: Point, val modifiers: Key.Modifiers)(val peer: java.awt.event.MouseEvent)
extends MouseMotionEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx)(e)
}
case class MouseExited(val source: Component, point: Point, val modifiers: Key.Modifiers)(val peer: java.awt.event.MouseEvent)
extends MouseMotionEvent {
- def this(e: java.awt.event.MouseEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx)(e)
+ def this(e: java.awt.event.MouseEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx)(e)
}
case class MouseWheelMoved(val source: Component, point: Point, val modifiers: Key.Modifiers, rotation: Int)(val peer: java.awt.event.MouseEvent)
extends MouseEvent {
- def this(e: java.awt.event.MouseWheelEvent) =
- this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
- e.getPoint, e.getModifiersEx, e.getWheelRotation)(e)
+ def this(e: java.awt.event.MouseWheelEvent) =
+ this(UIElement.cachedWrapper[Component](e.getSource.asInstanceOf[JComponent]),
+ e.getPoint, e.getModifiersEx, e.getWheelRotation)(e)
}
diff --git a/scala/swing/event/SelectionEvent.scala b/scala/swing/event/SelectionEvent.scala
index 7035978..898713a 100644
--- a/scala/swing/event/SelectionEvent.scala
+++ b/scala/swing/event/SelectionEvent.scala
@@ -26,9 +26,9 @@ trait ListSelectionEvent extends SelectionEvent {
case class SelectionChanged(override val source: Component) extends ComponentEvent with SelectionEvent
object ListSelectionChanged {
- def unapply[A](e: ListSelectionChanged[A]): Option[(ListView[A], Range, Boolean)] =
+ def unapply[A](e: ListSelectionChanged[A]): Option[(ListView[A], Range, Boolean)] =
Some((e.source, e.range, e.live))
}
-class ListSelectionChanged[A](override val source: ListView[A], val range: Range, val live: Boolean)
+class ListSelectionChanged[A](override val source: ListView[A], val range: Range, val live: Boolean)
extends SelectionChanged(source) with ListEvent[A]
diff --git a/scala/swing/event/TableEvent.scala b/scala/swing/event/TableEvent.scala
index 2864290..6003464 100644
--- a/scala/swing/event/TableEvent.scala
+++ b/scala/swing/event/TableEvent.scala
@@ -16,31 +16,31 @@ abstract class TableEvent(override val source: Table) extends ComponentEvent
abstract class TableChange(override val source: Table) extends TableEvent(source)
/**
- * The most general table change. The table might have changed completely,
- * i.e., columns might have been reordered, rows added or removed, etc.
+ * The most general table change. The table might have changed completely,
+ * i.e., columns might have been reordered, rows added or removed, etc.
* No other event indicates that the structure might have changed.
*/
case class TableStructureChanged(override val source: Table) extends TableChange(source)
/**
- * The table structure, i.e., the column order, names, and types stay the same,
+ * The table structure, i.e., the column order, names, and types stay the same,
* but anything else might have changed.
*/
case class TableChanged(override val source: Table) extends TableChange(source)
/**
- * The size of the table stays the same, but the given range of rows might
- * have changed but only in the given column. A value of -1 for the column
+ * The size of the table stays the same, but the given range of rows might
+ * have changed but only in the given column. A value of -1 for the column
* denotes all columns.
*/
-case class TableUpdated(override val source: Table, range: Range, column: Int)
+case class TableUpdated(override val source: Table, range: Range, column: Int)
extends TableChange(source)
/**
* Any change that caused the table to change it's size
- */
+ */
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, adjusting: Boolean)
+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)
+case class TableRowsSelected(override val source: Table, range: Range, adjusting: Boolean)
extends TableEvent(source) with AdjustingEvent with ListSelectionEvent
diff --git a/scala/swing/model/Matrix.scala b/scala/swing/model/Matrix.scala
index 7ff056a..f91512a 100644
--- a/scala/swing/model/Matrix.scala
+++ b/scala/swing/model/Matrix.scala
@@ -14,79 +14,79 @@ package model
trait Matrix { }
/*trait Matrix[A] extends Function2[Int, Int, A] {
-
+
val width: Int
val height: Int
-
+
assert(width > 0 && height > 0)
-
+
private val delegate = new Array[A](width * height)
-
+
override def apply(col: Int, row: Int): A =
delegate(col * height + row)
-
- def apply(coord: (Int, Int)): A =
+
+ def apply(coord: (Int, Int)): A =
apply(coord._1, coord._2)
-
+
def col(index: Int): Matrix.FlatSeq[A] =
new Matrix.SubArray[A](delegate, index * height, height)
-
+
def row(index: Int): Matrix.FlatSeq[A] =
new Matrix.SparseArray[A](delegate, index, height)
-
+
def update(xpos: Int, ypos: Int, elem: A) {
delegate(xpos % width * height + ypos % height) = elem
}
-
+
def update(coord: (Int, Int), elem: A) {
update(coord._1, coord._2, elem)
}
-
+
def initializeWith(f: (Int, Int) => A): this.type = {
for (index <- 0 until (width * height))
delegate(index) = f(index / height, index % height)
this
}
-
+
def initializeTo(v: => A): this.type = {
for (index <- 0 until (width * height))
delegate(index) = v
this
}
-
+
def size: (Int, Int) = (width, height)
-
+
/** A flattened view of the matrix. The flattening is done on columns i.e.
* the first values of the flattened sequence are the cells of the first
* column. As this is a view of the matrix, any change to the matrix will
* also be visible in the flattened array, and vice-versa. */
def flat: Array[A] = delegate
-
+
}
object Matrix {
-
+
def apply[A](columns: Int, rows: Int) = new Matrix[A] {
val width = columns
val height = rows
}
-
+
def apply[A](default: (Int, Int) => A, columns: Int, rows: Int) = new Matrix[A] {
val width = columns
val height = rows
initializeWith(default)
}
-
+
def apply[A](default: => A, columns: Int, rows: Int) = new Matrix[A] {
val width = columns
val height = rows
initializeTo(default)
}
-
+
trait FlatSeq[A] extends RandomAccessSeq[A] {
def update (index: Int, elem: A): Unit
}
-
+
private class SubArray[A](delegate: Array[A], start: Int, val length: Int) extends FlatSeq[A] {
def apply(index: Int): A =
if (index < length)
@@ -97,7 +97,7 @@ object Matrix {
delegate(index + start) = elem
else throw new IndexOutOfBoundsException
}
-
+
private class SparseArray[A](delegate: Array[A], start: Int, span: Int) extends FlatSeq[A] {
def apply(index: Int): A = {
if (index < length)
@@ -110,12 +110,12 @@ object Matrix {
delegate((index * span) + start) = elem
else throw new IndexOutOfBoundsException
}
-
+
implicit def MatrixToSeqs[A](matrix: Matrix[A]): Seq[Seq[A]] = {
val result = new Array[SubArray[A]](matrix.width)
for (col <- 0 until matrix.width)
result(col) = new SubArray[A](matrix.delegate, col * matrix.height, matrix.height)
result
}
-
+
}*/
diff --git a/scala/swing/package.scala b/scala/swing/package.scala
index 763ee85..deb291d 100644
--- a/scala/swing/package.scala
+++ b/scala/swing/package.scala
@@ -8,12 +8,12 @@ package object swing {
type Dimension = java.awt.Dimension
type Rectangle = java.awt.Rectangle
type Insets = java.awt.Insets
-
+
type Graphics2D = java.awt.Graphics2D
type Color = java.awt.Color
type Image = java.awt.Image
type Font = java.awt.Font
-
+
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 toAnyRef(x: Any): AnyRef = x.asInstanceOf[AnyRef]
diff --git a/scala/swing/test/CelsiusConverter.scala b/scala/swing/test/CelsiusConverter.scala
index 36bd047..4ead632 100644
--- a/scala/swing/test/CelsiusConverter.scala
+++ b/scala/swing/test/CelsiusConverter.scala
@@ -5,7 +5,7 @@ import swing._
import event._
/** A GUI app to convert celsius to centigrade
- */
+ */
object CelsiusConverter extends SimpleSwingApplication {
def top = new MainFrame {
title = "Convert Celsius to Fahrenheit"
@@ -22,13 +22,13 @@ object CelsiusConverter extends SimpleSwingApplication {
text = "Fahrenheit "
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 = ""+f+" Fahrenheit"
}
-
+
reactions += {
case ButtonClicked(_) | EditDone(_) => convert()
}
diff --git a/scala/swing/test/CelsiusConverter2.scala b/scala/swing/test/CelsiusConverter2.scala
index b3f2cf4..5ce1b15 100644
--- a/scala/swing/test/CelsiusConverter2.scala
+++ b/scala/swing/test/CelsiusConverter2.scala
@@ -5,14 +5,14 @@ import swing._
import event._
object CelsiusConverter2 extends SimpleSwingApplication {
- def newField = new TextField {
+ def newField = new TextField {
text = "0"
columns = 5
horizontalAlignment = Alignment.Right
}
val celsius = newField
val fahrenheit = newField
-
+
listenTo(fahrenheit, celsius)
reactions += {
case EditDone(`fahrenheit`) =>
@@ -24,8 +24,8 @@ object CelsiusConverter2 extends SimpleSwingApplication {
val f = c * 9 / 5 + 32
fahrenheit.text = f.toString
}
-
- lazy val ui = new FlowPanel(celsius, new Label(" Celsius = "),
+
+ lazy val ui = new FlowPanel(celsius, new Label(" Celsius = "),
fahrenheit, new Label(" Fahrenheit")) {
border = Swing.EmptyBorder(15, 10, 10, 10)
}
diff --git a/scala/swing/test/ComboBoxes.scala b/scala/swing/test/ComboBoxes.scala
index d202c9d..cf1a70d 100644
--- a/scala/swing/test/ComboBoxes.scala
+++ b/scala/swing/test/ComboBoxes.scala
@@ -10,14 +10,14 @@ import javax.swing.{Icon, ImageIcon}
/**
* Demonstrates how to use combo boxes and custom item renderers.
- *
+ *
* TODO: clean up layout
*/
object ComboBoxes extends SimpleSwingApplication {
import ComboBox._
lazy val ui = new FlowPanel {
contents += new ComboBox(List(1,2,3,4))
-
+
val patterns = List("dd MMMMM yyyy",
"dd.MM.yy",
"MM/dd/yy",
@@ -31,12 +31,12 @@ object ComboBoxes extends SimpleSwingApplication {
contents += dateBox
val field = new TextField(20) { editable = false }
contents += field
-
+
reactions += {
case SelectionChanged(`dateBox`) => reformat()
}
listenTo(dateBox.selection)
-
+
def reformat() {
try {
val today = new Date
@@ -50,15 +50,15 @@ object ComboBoxes extends SimpleSwingApplication {
field.text = "Error: " + e.getMessage
}
}
-
-
- val icons = try {
+
+
+ val icons = try {
List(new ImageIcon(resourceFromClassloader("images/margarita1.jpg")),
- new ImageIcon(resourceFromClassloader("images/margarita2.jpg")),
+ new ImageIcon(resourceFromClassloader("images/margarita2.jpg")),
new ImageIcon(resourceFromClassloader("images/rose.jpg")),
new ImageIcon(resourceFromClassloader("images/banana.jpg")))
} catch {
- case _ =>
+ case _ =>
println("Couldn't load images for combo box")
List(Swing.EmptyIcon)
}
@@ -78,7 +78,7 @@ object ComboBoxes extends SimpleSwingApplication {
}
contents += iconBox
}
-
+
def top = new MainFrame {
title = "ComboBoxes Demo"
contents = ui
diff --git a/scala/swing/test/CountButton.scala b/scala/swing/test/CountButton.scala
index 36828c2..373db78 100644
--- a/scala/swing/test/CountButton.scala
+++ b/scala/swing/test/CountButton.scala
@@ -1,8 +1,8 @@
package scala.swing
package test
-import scala.swing._
-import scala.swing.event._
+import scala.swing._
+import scala.swing.event._
object CountButton extends SimpleSwingApplication {
def top = new MainFrame {
@@ -14,17 +14,17 @@ object CountButton extends SimpleSwingApplication {
text = "Press Me!"
}
contents += button
- val label = new Label {
- text = "No button clicks registered"
+ val label = new Label {
+ text = "No button clicks registered"
}
contents += label
-
- listenTo(button)
- var nclicks = 0
- reactions += {
- case ButtonClicked(b) =>
- nclicks += 1
- label.text = "Number of button clicks: "+nclicks
+
+ listenTo(button)
+ var nclicks = 0
+ reactions += {
+ case ButtonClicked(b) =>
+ nclicks += 1
+ label.text = "Number of button clicks: "+nclicks
}
}
}
diff --git a/scala/swing/test/Dialogs.scala b/scala/swing/test/Dialogs.scala
index 0e3ea03..14fa2fe 100644
--- a/scala/swing/test/Dialogs.scala
+++ b/scala/swing/test/Dialogs.scala
@@ -6,39 +6,39 @@ import swing.event._
object Dialogs extends SimpleSwingApplication {
import TabbedPane._
-
+
lazy val label = new Label("No Result yet")
lazy val tabs = new TabbedPane {
pages += new Page("File", new GridBagPanel { grid =>
import GridBagPanel._
val buttonText = new TextField("Click Me")
-
+
val c = new Constraints
c.fill = Fill.Horizontal
c.grid = (1,1)
-
+
val chooser = new FileChooser
layout(new Button(Action("Open") {
- chooser.showOpenDialog(grid)
+ chooser.showOpenDialog(grid)
})) = c
-
+
c.grid = (1,2)
layout(new Button(Action("Save") {
- chooser.showSaveDialog(grid)
+ chooser.showSaveDialog(grid)
})) = c
-
+
c.grid = (1,3)
- layout(new Button(Action("Custom") {
+ layout(new Button(Action("Custom") {
chooser.showDialog(grid, buttonText.text)
})) = c
-
+
c.grid = (2,3)
layout(new Label(" with Text ")) = c
-
+
c.grid = (3,3)
c.ipadx = 50
layout(buttonText) = c
-
+
border = Swing.EmptyBorder(5, 5, 5, 5)
})
pages += new Page("Simple Modal Dialogs", new BorderPanel {
@@ -49,8 +49,8 @@ object Dialogs extends SimpleSwingApplication {
val ynp = new RadioButton("Yes/No (in the programmer's words)")
val yncp = new RadioButton("Yes/No/Cancel (in the programmer's words)")
val radios = List(ok, ynlf, ynp, yncp)
- mutex.buttons ++= radios
- mutex.select(ok)
+ mutex.buttons ++= radios
+ mutex.select(ok)
val buttons = new BoxPanel(Orientation.Vertical) {
contents ++= radios
}
@@ -58,44 +58,44 @@ object Dialogs extends SimpleSwingApplication {
layout(new Button(Action("Show It!") {
import Dialog._
mutex.selected.get match {
- case `ok` =>
+ case `ok` =>
showMessage(buttons, "Eggs aren't supposed to be green.")
- case `ynlf` =>
- label.text = showConfirmation(buttons,
+ case `ynlf` =>
+ 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` =>
+ case `ynp` =>
val options = List("Yes, please",
"No, thanks",
"No eggs, no ham!")
label.text = showOptions(buttons,
"Would you like some green eggs to go with that ham?",
"A Silly Question",
- entries = options,
+ 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` =>
+ case `yncp` =>
val options = List("Yes, please",
"No, thanks",
"No eggs, no ham!")
label.text = showOptions(buttons,
message = "Would you like some green eggs to go with that ham?",
title = "A Silly Question",
- entries = options,
+ 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
})
pages += new Page("More Dialogs", new BorderPanel {
@@ -108,7 +108,7 @@ object Dialogs extends SimpleSwingApplication {
val custom2 = new RadioButton("2 custom dialogs")
val radios = List(pick, enter, custom, customUndec, custom2)
mutex.buttons ++= radios
- mutex.select(pick)
+ mutex.select(pick)
val buttons = new BoxPanel(Orientation.Vertical) {
contents ++= radios
}
@@ -116,12 +116,12 @@ object Dialogs extends SimpleSwingApplication {
layout(new Button(Action("Show It!") {
import Dialog._
mutex.selected.get match {
- case `pick` =>
+ case `pick` =>
val possibilities = List("ham", "spam", "yam")
val s = showInput(buttons,
"Complete the sentence:\n\"Green eggs and...\"",
"Customized Dialog",
- Message.Plain,
+ Message.Plain,
Swing.EmptyIcon,
possibilities, "ham")
@@ -130,11 +130,11 @@ object Dialogs extends SimpleSwingApplication {
"Green eggs and... " + s.get + "!"
else
"Come on, finish the sentence!"
- case `enter` =>
+ case `enter` =>
val s = showInput(buttons,
"Complete the sentence:\n\"Green eggs and...\"",
"Customized Dialog",
- Message.Plain,
+ Message.Plain,
Swing.EmptyIcon,
Nil, "ham")
@@ -158,18 +158,18 @@ object Dialogs extends SimpleSwingApplication {
d2.open()
d1.contents = Button("Close Me! I am the owner and will automatically close the other one") { d1.close() }
d2.contents = Button("Close Me!") { d2.close() }
- }
+ }
})) = Position.South
})
}
-
+
lazy val ui: Panel = new BorderPanel {
layout(tabs) = BorderPanel.Position.Center
layout(label) = BorderPanel.Position.South
}
-
-
- lazy val top = new MainFrame {
+
+
+ lazy val top = new MainFrame {
title = "Dialog Demo"
contents = ui
}
diff --git a/scala/swing/test/GridBagDemo.scala b/scala/swing/test/GridBagDemo.scala
index 26b1f82..ebb538f 100644
--- a/scala/swing/test/GridBagDemo.scala
+++ b/scala/swing/test/GridBagDemo.scala
@@ -14,8 +14,8 @@ object GridBagDemo extends SimpleSwingApplication {
c.fill = Fill.Horizontal
}
- val button1 = new Button("Button 1")
-
+ val button1 = new Button("Button 1")
+
c.weightx = 0.5
c.fill = Fill.Horizontal
@@ -57,7 +57,7 @@ object GridBagDemo extends SimpleSwingApplication {
c.gridy = 2; //third row
layout(button5) = c
}
-
+
def top = new MainFrame {
title = "GridBag Demo"
contents = ui
diff --git a/scala/swing/test/LabelTest.scala b/scala/swing/test/LabelTest.scala
index f1d7005..47eedb8 100644
--- a/scala/swing/test/LabelTest.scala
+++ b/scala/swing/test/LabelTest.scala
@@ -6,13 +6,13 @@ import scala.swing.event._
object LabelTest extends SimpleSwingApplication {
def top = new MainFrame{
- contents = new Label {
+ contents = new Label {
text = "Hello"
import java.awt.event._
listenTo(mouse.clicks)
reactions += {
- case MousePressed(_,_,_,_,_) =>
- println("Mouse pressed2")
+ case MousePressed(_,_,_,_,_) =>
+ println("Mouse pressed2")
}
}
}
diff --git a/scala/swing/test/LinePainting.scala b/scala/swing/test/LinePainting.scala
index 0824934..78a94db 100644
--- a/scala/swing/test/LinePainting.scala
+++ b/scala/swing/test/LinePainting.scala
@@ -7,7 +7,7 @@ import java.awt.{Color, Dimension, Graphics, Graphics2D, Point, geom}
/**
* Dragging the mouse draws a simple graph
- *
+ *
* @author Frank Teubler, Ingo Maier
*/
object LinePainting extends SimpleSwingApplication {
@@ -17,14 +17,14 @@ object LinePainting extends SimpleSwingApplication {
focusable = true
listenTo(mouse.clicks, mouse.moves, keys)
-
+
reactions += {
- case e: MousePressed =>
+ case e: MousePressed =>
moveTo(e.point)
requestFocusInWindow()
case e: MouseDragged => lineTo(e.point)
case e: MouseReleased => lineTo(e.point)
- case KeyTyped(_,'c',_,_) =>
+ case KeyTyped(_,'c',_,_) =>
path = new geom.GeneralPath
repaint()
case _: FocusLost => repaint()
@@ -39,13 +39,13 @@ object LinePainting extends SimpleSwingApplication {
override def paintComponent(g: Graphics2D) = {
super.paintComponent(g)
g.setColor(new Color(100,100,100))
- g.drawString("Press left mouse button and drag to paint." +
+ g.drawString("Press left mouse button and drag to paint." +
(if(hasFocus) " Press 'c' to clear." else ""), 10, size.height-10)
g.setColor(Color.black)
g.draw(path)
}
}
-
+
def top = new MainFrame {
title = "Simple Line Painting Demo"
contents = ui
diff --git a/scala/swing/test/ListViewDemo.scala b/scala/swing/test/ListViewDemo.scala
index c36e6cf..2b8c8c0 100644
--- a/scala/swing/test/ListViewDemo.scala
+++ b/scala/swing/test/ListViewDemo.scala
@@ -5,7 +5,7 @@ object ListViewDemo extends SimpleSwingApplication {
def top = new MainFrame {
case class City(name: String, country: String, population: Int, capital: Boolean)
val items = List(City("Lausanne", "Switzerland", 129273, false),
- City("Paris", "France", 2203817, true),
+ City("Paris", "France", 2203817, true),
City("New York", "USA", 8363710 , false),
City("Berlin", "Germany", 3416300, true),
City("Tokio", "Japan", 12787981, true))
diff --git a/scala/swing/test/SimpleApplet.scala b/scala/swing/test/SimpleApplet.scala
index 4531952..d5f17f8 100644
--- a/scala/swing/test/SimpleApplet.scala
+++ b/scala/swing/test/SimpleApplet.scala
@@ -16,4 +16,4 @@ class SimpleApplet extends Applet {
contents = new BoxPanel(Orientation.Vertical) { contents.append(button, text) }
}
}
-}
+}
diff --git a/scala/swing/test/SwingApp.scala b/scala/swing/test/SwingApp.scala
index 0ec664e..b47d778 100644
--- a/scala/swing/test/SwingApp.scala
+++ b/scala/swing/test/SwingApp.scala
@@ -10,7 +10,7 @@ object SwingApp extends SimpleSwingApplication {
var numclicks = 0
object label extends Label {
val prefix = "Number of button clicks: "
- text = prefix + "0 "
+ text = prefix + "0 "
listenTo(button)
reactions += {
case ButtonClicked(button) =>
diff --git a/scala/swing/test/TableSelection.scala b/scala/swing/test/TableSelection.scala
index 1631214..bbfef80 100644
--- a/scala/swing/test/TableSelection.scala
+++ b/scala/swing/test/TableSelection.scala
@@ -10,20 +10,20 @@ object TableSelection extends SimpleSwingApplication {
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
+ /*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)
}
//1.6:table.fillsViewportHeight = true
listenTo(table.selection)
-
+
contents += new ScrollPane(table)
contents += new Label("Selection Mode")
-
+
def radio(mutex: ButtonGroup, text: String): RadioButton = {
val b = new RadioButton(text)
listenTo(b)
@@ -31,25 +31,25 @@ object TableSelection extends SimpleSwingApplication {
contents += b
b
}
-
+
val intervalMutex = new ButtonGroup
val multiInterval = radio(intervalMutex, "Multiple Interval Selection")
val elementInterval = radio(intervalMutex, "Single Selection")
val singleInterval = radio(intervalMutex, "Single Interval Selection")
intervalMutex.select(multiInterval)
-
+
contents += new Label("Selection Options")
val elemMutex = new ButtonGroup
val rowSelection = radio(elemMutex, "Row Selection")
val columnSelection = radio(elemMutex, "Column Selection")
val cellSelection = radio(elemMutex, "Cell Selection")
elemMutex.select(rowSelection)
-
+
val output = new TextArea(5, 40) { editable = false }
contents += new ScrollPane(output)
-
+
def outputSelection() {
- output.append("Lead: " + table.selection.rows.leadIndex + "," +
+ output.append("Lead: " + table.selection.rows.leadIndex + "," +
table.selection.columns.leadIndex + ". ")
output.append("Rows:")
for (c <- table.selection.rows) output.append(" " + c)
@@ -57,9 +57,9 @@ object TableSelection extends SimpleSwingApplication {
for (c <- table.selection.columns) output.append(" " + c)
output.append(".\n")
}
-
+
reactions += {
- case ButtonClicked(`multiInterval`) =>
+ case ButtonClicked(`multiInterval`) =>
table.selection.intervalMode = Table.IntervalMode.MultiInterval
if (cellSelection.selected) {
elemMutex.select(rowSelection)
@@ -72,24 +72,24 @@ object TableSelection extends SimpleSwingApplication {
case ButtonClicked(`singleInterval`) =>
table.selection.intervalMode = Table.IntervalMode.SingleInterval
cellSelection.enabled = true
- case ButtonClicked(`rowSelection`) =>
- if (rowSelection.selected)
+ case ButtonClicked(`rowSelection`) =>
+ if (rowSelection.selected)
table.selection.elementMode = Table.ElementMode.Row
case ButtonClicked(`columnSelection`) =>
- if (columnSelection.selected)
+ if (columnSelection.selected)
table.selection.elementMode = Table.ElementMode.Column
case ButtonClicked(`cellSelection`) =>
- if (cellSelection.selected)
+ if (cellSelection.selected)
table.selection.elementMode = Table.ElementMode.Cell
- case TableRowsSelected(_, range, false) =>
+ case TableRowsSelected(_, range, false) =>
output.append("Rows selected, changes: " + range + "\n")
outputSelection()
- case TableColumnsSelected(_, range, false) =>
+ case TableColumnsSelected(_, range, false) =>
output.append("Columns selected, changes " + range + "\n")
outputSelection()
}
}
-
+
def top = new MainFrame {
title = "Table Selection"
contents = ui
diff --git a/scala/swing/test/UIDemo.scala b/scala/swing/test/UIDemo.scala
index 8e4ac40..9207c82 100644
--- a/scala/swing/test/UIDemo.scala
+++ b/scala/swing/test/UIDemo.scala
@@ -9,9 +9,9 @@ import ListView._
object UIDemo extends SimpleSwingApplication {
def top = new MainFrame {
title = "Scala Swing Demo"
-
+
/*
- * Create a menu bar with a couple of menus and menu items and
+ * Create a menu bar with a couple of menus and menu items and
* set the result as this frame's menu bar.
*/
menuBar = new MenuBar {
@@ -32,20 +32,20 @@ object UIDemo extends SimpleSwingApplication {
}
contents += new Menu("Empty Menu")
}
-
+
/*
- * The root component in this frame is a panel with a border layout.
+ * The root component in this frame is a panel with a border layout.
*/
contents = new BorderPanel {
import BorderPanel.Position._
-
+
var reactLive = false
-
+
val tabs = new TabbedPane {
import TabbedPane._
val buttons = new FlowPanel {
border = Swing.EmptyBorder(5,5,5,5)
-
+
contents += new BoxPanel(Orientation.Vertical) {
border = CompoundBorder(TitledBorder(EtchedBorder, "Radio Buttons"), EmptyBorder(5,5,5,10))
val a = new RadioButton("Green Vegetables")
@@ -63,29 +63,29 @@ object UIDemo extends SimpleSwingApplication {
contents.append(paintLabels, paintTicks, snapTicks, live)
listenTo(paintLabels, paintTicks, snapTicks, live)
reactions += {
- case ButtonClicked(`paintLabels`) =>
+ case ButtonClicked(`paintLabels`) =>
slider.paintLabels = paintLabels.selected
- case ButtonClicked(`paintTicks`) =>
+ case ButtonClicked(`paintTicks`) =>
slider.paintTicks = paintTicks.selected
- case ButtonClicked(`snapTicks`) =>
+ case ButtonClicked(`snapTicks`) =>
slider.snapToTicks = snapTicks.selected
- case ButtonClicked(`live`) =>
+ case ButtonClicked(`live`) =>
reactLive = live.selected
}
}
contents += new Button(Action("Center Frame") { centerOnScreen() })
}
- pages += new Page("Buttons", buttons)
+ pages += new Page("Buttons", buttons)
pages += new Page("GridBag", GridBagDemo.ui)
pages += new Page("Converter", CelsiusConverter2.ui)
pages += new Page("Tables", TableSelection.ui)
pages += new Page("Dialogs", Dialogs.ui)
pages += new Page("Combo Boxes", ComboBoxes.ui)
- pages += new Page("Split Panes",
+ pages += new Page("Split Panes",
new SplitPane(Orientation.Vertical, new Button("Hello"), new Button("World")) {
continuousLayout = true
})
-
+
val password = new FlowPanel {
contents += new Label("Enter your secret password here ")
val field = new PasswordField(10)
@@ -97,12 +97,12 @@ object UIDemo extends SimpleSwingApplication {
case EditDone(`field`) => label.text = field.password.mkString
}
}
-
+
pages += new Page("Password", password)
pages += new Page("Painting", LinePainting.ui)
//pages += new Page("Text Editor", TextEditor.ui)
}
-
+
val list = new ListView(tabs.pages) {
selectIndices(0)
selection.intervalMode = ListView.IntervalMode.Single
@@ -111,12 +111,12 @@ object UIDemo extends SimpleSwingApplication {
val center = new SplitPane(Orientation.Vertical, new ScrollPane(list), tabs) {
oneTouchExpandable = true
continuousLayout = true
- }
- layout(center) = Center
-
+ }
+ layout(center) = Center
+
/*
* This slider is used above, so we need lazy initialization semantics.
- * Objects or lazy vals are the way to go, but objects give us better
+ * Objects or lazy vals are the way to go, but objects give us better
* type inference at times.
*/
object slider extends Slider {
@@ -134,9 +134,9 @@ object UIDemo extends SimpleSwingApplication {
listenTo(tabs.selection)
listenTo(list.selection)
reactions += {
- case ValueChanged(`slider`) =>
+ case ValueChanged(`slider`) =>
if(!slider.adjusting || reactLive) tabs.selection.index = slider.value
- case SelectionChanged(`tabs`) =>
+ case SelectionChanged(`tabs`) =>
slider.value = tabs.selection.index
list.selectIndices(tabs.selection.index)
case SelectionChanged(`list`) =>