diff options
author | Ingo Maier <ingo.maier@epfl.ch> | 2008-10-20 10:09:14 +0000 |
---|---|---|
committer | Ingo Maier <ingo.maier@epfl.ch> | 2008-10-20 10:09:14 +0000 |
commit | 95dd7d914a8aa469d025600a4f0852bbfd2b8172 (patch) | |
tree | e55da015c92085e719a862473eeb0253e69c82bb | |
parent | e5868320d48d38687d67c8c3ffc2954815b2f14f (diff) | |
download | scala-95dd7d914a8aa469d025600a4f0852bbfd2b8172.tar.gz scala-95dd7d914a8aa469d025600a4f0852bbfd2b8172.tar.bz2 scala-95dd7d914a8aa469d025600a4f0852bbfd2b8172.zip |
Applied some of Andy Hicks' patches
-rw-r--r-- | src/swing/scala/swing/AbstractButton.scala | 8 | ||||
-rw-r--r-- | src/swing/scala/swing/Alignment.scala | 6 | ||||
-rw-r--r-- | src/swing/scala/swing/Button.scala | 5 | ||||
-rw-r--r-- | src/swing/scala/swing/CheckBox.scala | 3 | ||||
-rw-r--r-- | src/swing/scala/swing/Component.scala | 22 | ||||
-rw-r--r-- | src/swing/scala/swing/FormattedTextField.scala | 19 | ||||
-rw-r--r-- | src/swing/scala/swing/Label.scala | 37 | ||||
-rw-r--r-- | src/swing/scala/swing/Panel.scala | 2 | ||||
-rw-r--r-- | src/swing/scala/swing/Slider.scala | 4 | ||||
-rw-r--r-- | src/swing/scala/swing/UIElement.scala | 3 |
10 files changed, 96 insertions, 13 deletions
diff --git a/src/swing/scala/swing/AbstractButton.scala b/src/swing/scala/swing/AbstractButton.scala index 85fb6f39d1..8cc9062b84 100644 --- a/src/swing/scala/swing/AbstractButton.scala +++ b/src/swing/scala/swing/AbstractButton.scala @@ -1,6 +1,6 @@ package scala.swing -import java.awt.Dimension +import java.awt.{Dimension, Insets} import javax.swing.{AbstractButton => JAbstractButton, Icon} import event._ @@ -76,4 +76,10 @@ abstract class AbstractButton extends Component with Action.Trigger with Publish def multiClickThreshold: Long = peer.getMultiClickThreshhold def multiClickThreshold_=(n: Long) { peer.setMultiClickThreshhold(n) } + + 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/src/swing/scala/swing/Alignment.scala b/src/swing/scala/swing/Alignment.scala index 6ef638ff95..524fefe92e 100644 --- a/src/swing/scala/swing/Alignment.scala +++ b/src/swing/scala/swing/Alignment.scala @@ -9,10 +9,12 @@ import javax.swing.SwingConstants._ object Alignment extends Enumeration { val Left = Value(LEFT) val Right = Value(RIGHT) - val Center = Value(CENTER) - 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/src/swing/scala/swing/Button.scala b/src/swing/scala/swing/Button.scala index c146e66cb0..3e3e05aa8f 100644 --- a/src/swing/scala/swing/Button.scala +++ b/src/swing/scala/swing/Button.scala @@ -15,4 +15,9 @@ class Button(text0: String) extends AbstractButton with Publisher { this("") action = a } + + def defaultButton: Boolean = peer.isDefaultButton + + def defaultCapable: Boolean = peer.isDefaultCapable + def defaultCapable_=(capable: Boolean) { peer.setDefaultCapable(capable) } } diff --git a/src/swing/scala/swing/CheckBox.scala b/src/swing/scala/swing/CheckBox.scala index ed266cca27..199179d83b 100644 --- a/src/swing/scala/swing/CheckBox.scala +++ b/src/swing/scala/swing/CheckBox.scala @@ -10,4 +10,7 @@ import javax.swing._ class CheckBox(text: String) extends ToggleButton { override lazy val peer: JCheckBox = new JCheckBox(text) with SuperMixin def this() = this("") + + def borderPaintedFlat: Boolean = peer.isBorderPaintedFlat + def borderPaintedFlat_=(flat: Boolean) { peer.setBorderPaintedFlat(flat) } }
\ No newline at end of file diff --git a/src/swing/scala/swing/Component.scala b/src/swing/scala/swing/Component.scala index 7f3b004299..0677761d5f 100644 --- a/src/swing/scala/swing/Component.scala +++ b/src/swing/scala/swing/Component.scala @@ -35,13 +35,23 @@ abstract class Component extends UIElement with Publisher { var initP: JComponent = null peer.putClientProperty(Component.ClientKey, this) - trait SuperMixin extends JComponent { + /** + * 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 { override def paintComponent(g: java.awt.Graphics) { Component.this.paintComponent(g) } def __super__paintComponent(g: java.awt.Graphics) { super.paintComponent(g) } + override def paint(g: java.awt.Graphics) { + Component.this.paint(g) + } + def __super__paint(g: java.awt.Graphics) { + super.paint(g) + } } @@ -203,6 +213,9 @@ abstract class Component extends UIElement with Publisher { def requestFocus() { peer.requestFocus() } + /** + * For custom painting, users should usually override this method. + */ protected def paintComponent(g: java.awt.Graphics) { peer match { case peer: SuperMixin => peer.__super__paintComponent(g) @@ -210,5 +223,12 @@ abstract class Component extends UIElement with Publisher { } } + protected def paint(g: java.awt.Graphics) { + peer match { + case peer: SuperMixin => peer.__super__paint(g) + case _ => // it's a wrapper created on the fly + } + } + override def toString = "scala.swing wrapper " + peer.toString } diff --git a/src/swing/scala/swing/FormattedTextField.scala b/src/swing/scala/swing/FormattedTextField.scala index 75d32ee323..b771078f37 100644 --- a/src/swing/scala/swing/FormattedTextField.scala +++ b/src/swing/scala/swing/FormattedTextField.scala @@ -4,9 +4,26 @@ import javax.swing._ import java.awt.event._ import event._ +object FormattedTextField { + object FocusLostBehavior extends Enumeration { + val Commit = Value(JFormattedTextField.COMMIT) + val CommitOrRevert = Value(JFormattedTextField.COMMIT_OR_REVERT) + val Persist = Value(JFormattedTextField.PERSIST) + val Revert = Value(JFormattedTextField.REVERT) + } +} + /** * @see javax.swing.JFormattedTextField */ class FormattedTextField(format: java.text.Format) extends TextComponent { override lazy val peer: JFormattedTextField = new JFormattedTextField(format) -} + + 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) } +}
\ No newline at end of file diff --git a/src/swing/scala/swing/Label.scala b/src/swing/scala/swing/Label.scala index bcb421e344..40189475aa 100644 --- a/src/swing/scala/swing/Label.scala +++ b/src/swing/scala/swing/Label.scala @@ -1,24 +1,51 @@ package scala.swing import javax.swing._ +import scala.swing.Swing._ /** * A label component. * * @see javax.swing.JLabel */ -class Label(text0: String) extends Component { - override lazy val peer: JLabel = new JLabel(text0) - def this() = this("") +class Label(text0: String, icon0: Icon, align: Alignment.Value) extends Component { + 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. */ def xAlignment: Alignment.Value = Alignment(peer.getHorizontalAlignment) - def xAlignment_=(x: Alignment.Value) = peer.setHorizontalAlignment(x.id) + 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) + 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() */ + def horizontalAlignment_=(x: Alignment.Value) { peer.setHorizontalAlignment(x.id) } + + 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/src/swing/scala/swing/Panel.scala b/src/swing/scala/swing/Panel.scala index ac5a8de047..579d23220a 100644 --- a/src/swing/scala/swing/Panel.scala +++ b/src/swing/scala/swing/Panel.scala @@ -6,5 +6,5 @@ package scala.swing * @see javax.swing.JPanel */ abstract class Panel extends Component with Container.Wrapper { - override lazy val peer: javax.swing.JPanel = new javax.swing.JPanel + override lazy val peer: javax.swing.JPanel = new javax.swing.JPanel with SuperMixin } diff --git a/src/swing/scala/swing/Slider.scala b/src/swing/scala/swing/Slider.scala index d03704f482..b66c37dc8e 100644 --- a/src/swing/scala/swing/Slider.scala +++ b/src/swing/scala/swing/Slider.scala @@ -39,7 +39,9 @@ class Slider extends Component with Orientable with Publisher { def adjusting = peer.getValueIsAdjusting def labels: scala.collection.Map[Int, Label] = - new scala.collection.jcl.MapWrapper[Int, Label] { def underlying = peer.getLabelTable.asInstanceOf[java.util.Hashtable[Int, Label]] } + new scala.collection.jcl.MapWrapper[Int, Label] { + def underlying = peer.getLabelTable.asInstanceOf[java.util.Hashtable[Int, Label]] + } def labels_=(l: scala.collection.Map[Int, Label]) { val table = new java.util.Hashtable[Any, Any] for ((k,v) <- l) table.put(k, v) diff --git a/src/swing/scala/swing/UIElement.scala b/src/swing/scala/swing/UIElement.scala index 843262bcab..d20bff1ef3 100644 --- a/src/swing/scala/swing/UIElement.scala +++ b/src/swing/scala/swing/UIElement.scala @@ -20,6 +20,7 @@ trait UIElement extends Proxy { def maximumSize_=(x: Dimension) = peer.setMaximumSize(x) def preferredSize = peer.getPreferredSize def preferredSize_=(x: Dimension) = peer.setPreferredSize(x) + def preferredSize_=(xy: (Int, Int)) { peer.setPreferredSize(new Dimension(xy._1, xy._2)) } def font: Font = peer.getFont def font_=(f: Font) = peer.setFont(f) @@ -29,7 +30,7 @@ trait UIElement extends Proxy { def bounds = peer.getBounds def size = peer.getSize def size_=(dim: Dimension) = peer.setSize(dim) - def size_=(xy: (Int, Int)) = peer.setSize(new Dimension(xy._1, xy._2)) + def size_=(xy: (Int, Int)) { peer.setSize(new Dimension(xy._1, xy._2)) } def locale = peer.getLocale def toolkit = peer.getToolkit |