Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

scala.swing update

  • Loading branch information...
commit bc99ad9be7575299658e8c4cd1104969abee304b 1 parent 6b6afed
NAME authored
View
6 src/swing/scala/swing/Color.scala
@@ -1,5 +1,5 @@
-package scala.swing;
+package scala.swing
-case class Color(r: Int, g: Int, b: Int) extends java.awt.Color(r, g, b) {
+/*case class Color(r: Int, g: Int, b: Int) extends java.awt.Color(r, g, b) {
def this(col: java.awt.Color) = this(col.getRed, col.getGreen, col.getBlue)
-}
+}*/
View
20 src/swing/scala/swing/Component.scala
@@ -2,7 +2,7 @@ package scala.swing
import event._
import geometry._
-import java.awt.Font
+
import java.awt.event._
import javax.swing.JComponent
import javax.swing.border.Border
@@ -23,20 +23,18 @@ abstract class Component extends UIElement with Showable.Swing with Publisher {
def preferredSize = peer.getPreferredSize
def preferredSize_=(x: Dimension) = peer.setPreferredSize(x.peer)
- def xAlignment: Double = peer.getAlignmentX
- def xAlignment_=(x: Double) = peer.setAlignmentX(x.toFloat)
- def yAlignment: Double = peer.getAlignmentY
- def yAlignment_=(y: Double) = peer.setAlignmentY(y.toFloat)
+ /**
+ * 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 foreground: Color = new Color(peer.getForeground)
- def foreground_=(c: Color) = peer.setForeground(c)
- def background: Color = new Color(peer.getBackground)
- def background_=(c: Color) = peer.setBackground(c)
def border: Border = peer.getBorder
def border_=(b: Border) { peer.setBorder(b) }
- def font: Font = peer.getFont
- def font_=(f: Font) = peer.setFont(f)
def opaque: Boolean = peer.isOpaque
def opaque_=(b: Boolean) = peer.setOpaque(b)
View
2  src/swing/scala/swing/Frame.scala
@@ -7,7 +7,7 @@ class Frame(val peer: JFrame) extends UIElement with RootPanel with Showable.Swi
def this() = this(new JFrame)
def title: String = peer.getTitle
def title_=(s: String) = peer.setTitle(s)
- content = new Component {}
+ content = new Component { opaque = false }
override def content_=(c: Component) {
super.content_=(c)
View
17 src/swing/scala/swing/Label.scala
@@ -1,14 +1,17 @@
-package scala.swing;
+package scala.swing
-import javax.swing._;
+import javax.swing._
class Label(override val peer: JLabel) extends Component {
def this(txt: String) = this(new JLabel(txt))
- def this() = this("Untitled Label")
+ def this() = this("")
def text: String = peer.getText()
def text_=(s: String) = peer.setText(s)
- def xLabelAlignment: XAlignment = XAlignment.wrap(peer.getHorizontalAlignment)
- def xLabelAlignment_=(x: XAlignment) = peer.setHorizontalAlignment(x.peer)
- def yLabelAlignment: YAlignment = YAlignment.wrap(peer.getVerticalAlignment)
- def yLabelAlignment_=(x: YAlignment) = peer.setVerticalAlignment(x.peer)
+ /**
+ * The alignment of the label's contents relative to its bounding box.
+ */
+ def xAlignment: XAlignment = XAlignment.wrap(peer.getHorizontalAlignment)
+ def xAlignment_=(x: XAlignment) = peer.setHorizontalAlignment(x.peer)
+ def yAlignment: YAlignment = YAlignment.wrap(peer.getVerticalAlignment)
+ def yAlignment_=(x: YAlignment) = peer.setVerticalAlignment(x.peer)
}
View
13 src/swing/scala/swing/PushButton.scala
@@ -4,12 +4,11 @@ import javax.swing._
import event._
/** A class for buttons; standard constructor wraps around a swing button */
-class PushButton(override val peer: JButton) extends Component with Publisher {
+class PushButton(override val peer: JButton) extends Button with Publisher {
def this(txt: String) = this(new JButton(txt))
- def this() = this(new JButton)
- 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 this() = this("")
+ def this(a: Action) = {
+ this("")
+ action = a
+ }
}
View
1  src/swing/scala/swing/ScrollPane.scala
@@ -10,5 +10,4 @@ class ScrollPane(override val peer: JScrollPane) extends Component with Publishe
def rowHeaderView_=(c: Component) = peer.setRowHeaderView(c.peer)
def viewportView: Component = null
def viewportView_=(c: Component) = peer.setViewportView(c.peer)
-
}
View
5 src/swing/scala/swing/TabbedPane.scala
@@ -3,6 +3,7 @@ package scala.swing
import geometry._
import scala.collection.mutable.Buffer
import javax.swing.{JTabbedPane, JComponent}
+import java.awt.Color
object TabbedPane {
@@ -31,9 +32,9 @@ class TabbedPane(override val peer: JTabbedPane) extends Component with Publishe
def enabled_=(b: Boolean) { peer.setEnabledAt(index, b) }
def mnemonic: Int = peer.getMnemonicAt(index)
def mnemonic_=(k: Int) = peer.setMnemonicAt(index, k)
- def foreground: Color = new Color(peer.getForegroundAt(index))
+ def foreground: Color = peer.getForegroundAt(index)
def foreground_=(c: Color) = peer.setForegroundAt(index, c)
- def background: Color = new Color(peer.getBackgroundAt(index))
+ def background: Color = peer.getBackgroundAt(index)
def background_=(c: Color) = peer.setBackgroundAt(index, c)
def bounds: Rectangle = Rectangle.wrap(peer.getBoundsAt(index))
View
6 src/swing/scala/swing/Table.scala
@@ -5,9 +5,11 @@ import model.Matrix
import javax.swing._
import javax.swing.table._
import javax.swing.event._
+import java.awt.Color
import event._
import scala.collection.mutable.Set
+
object Table {
object AutoResizeMode extends Enumeration {
import JTable._
@@ -55,8 +57,8 @@ class Table(override val peer: JTable) extends Component with Scrollable with Pu
def showGrid = peer.getShowHorizontalLines && peer.getShowVerticalLines
def showGrid_=(grid: Boolean) = peer.setShowGrid(grid)
- def gridColor = new swing.Color(peer.getGridColor)
- def gridColor_=(color: swing.Color) = peer.setGridColor(color)
+ def gridColor = peer.getGridColor
+ def gridColor_=(color: Color) = peer.setGridColor(color)
def preferredViewportSize_=(dim: Dimension) = peer.setPreferredScrollableViewportSize(dim.peer)
def fillsViewportHeight: Boolean = peer.getFillsViewportHeight
View
10 src/swing/scala/swing/UIElement.scala
@@ -1,5 +1,15 @@
package scala.swing
+import java.awt.Color
+import java.awt.Font
+
trait UIElement {
+ def peer: java.awt.Component
+ 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 font: Font = peer.getFont
+ def font_=(f: Font) = peer.setFont(f)
}
View
7 src/swing/scala/swing/Views.scala
@@ -0,0 +1,7 @@
+package scala.swing
+
+object Views {
+ implicit def action2MenuItem(a: Action): MenuItem = new MenuItem(a)
+ //implicit def action2PushButton(a: Action): PushButton = new PushButton(a)
+ //implicit def string2Label(s: String): Label = new Label(s)
+}
View
2  src/swing/scala/swing/event/ComponentEvent.scala
@@ -1,6 +1,6 @@
package scala.swing.event
-abstract class ComponentEvent(override val source: Component) extends Event(source)
+abstract class ComponentEvent(override val source: Component) extends UIEvent(source)
case class ComponentMoved(override val source: Component) extends ComponentEvent(source)
case class ComponentResized(override val source: Component) extends ComponentEvent(source)
View
2  src/swing/scala/swing/event/ContainerEvent.scala
@@ -1,6 +1,6 @@
package scala.swing.event
-abstract class ContainerEvent(override val source: Container) extends Event(source)
+abstract class ContainerEvent(override val source: Container) extends UIEvent(source)
case class ComponentAdded(override val source: Container, child: Component) extends ContainerEvent(source)
case class ComponentRemoved(override val source: Container, child: Component) extends ContainerEvent(source)
View
2  src/swing/scala/swing/event/Event.scala
@@ -1,3 +1,3 @@
package scala.swing.event
-abstract class Event(val source: UIElement)
+abstract class Event
View
3  src/swing/scala/swing/event/UIEvent.scala
@@ -0,0 +1,3 @@
+package scala.swing.event
+
+abstract class UIEvent(val source: UIElement) extends Event
View
2  src/swing/scala/swing/event/WindowEvent.scala
@@ -1,3 +1,3 @@
package scala.swing.event
-abstract class WindowEvent(source: Frame) extends Event(source)
+abstract class WindowEvent(source: Frame) extends UIEvent(source)
View
2  src/swing/scala/swing/test/MenuDemo.scala
@@ -8,7 +8,7 @@ object MenuDemo extends SimpleGUIApplication {
title = "Menu Demo"
menuBar = new MenuBar
- implicit def action2MenuItem(a: Action): MenuItem = new MenuItem(a)
+ import Views._
val menu = new Menu("A Menu")
menu.contents += new MenuItem("An item")
View
13 src/swing/scala/swing/test/UIElementTest.scala
@@ -0,0 +1,13 @@
+package scala.swing.test
+
+import swing._
+import swing.event._
+import java.awt.Color
+
+object UIElementTest extends SimpleGUIApplication {
+ def top = new MainFrame {
+ title = "UIElement Test"
+ background = Color.RED
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.