diff options
Diffstat (limited to 'src/swing')
30 files changed, 154 insertions, 68 deletions
diff --git a/src/swing/scala/swing/AbstractButton.scala b/src/swing/scala/swing/AbstractButton.scala index e496d0566a..85fb6f39d1 100644 --- a/src/swing/scala/swing/AbstractButton.scala +++ b/src/swing/scala/swing/AbstractButton.scala @@ -45,8 +45,8 @@ abstract class AbstractButton extends Component with Action.Trigger with Publish def selected: Boolean = peer.isSelected def selected_=(b: Boolean) = peer.setSelected(b) - def contentAreaFilled: Boolean = peer.isContentAreaFilled() - def contentAreaFilled_=(b: Boolean) { peer.setContentAreaFilled(true) } + def contentAreaFilled: Boolean = peer.isContentAreaFilled + def contentAreaFilled_=(b: Boolean) { peer.setContentAreaFilled(b) } def borderPainted: Boolean = peer.isBorderPainted def borderPainted_=(b: Boolean) { peer.setBorderPainted(b) } diff --git a/src/swing/scala/swing/ComboBox.scala b/src/swing/scala/swing/ComboBox.scala index ef290781b0..4e400e726c 100644 --- a/src/swing/scala/swing/ComboBox.scala +++ b/src/swing/scala/swing/ComboBox.scala @@ -82,7 +82,6 @@ object ComboBox { val verifier = new javax.swing.InputVerifier { // TODO: should chain with potentially existing verifier in editor def verify(c: JComponent) = try { - println(c) value = string2A(c.asInstanceOf[JTextField].getText) true } @@ -155,11 +154,11 @@ class ComboBox[A](items: Seq[A]) extends Component with Publisher { object selection extends Publisher { def index: Int = peer.getSelectedIndex + def index_=(n: Int) { peer.setSelectedIndex(n) } def item: A = peer.getSelectedItem.asInstanceOf[A] + def item_=(a: A) { peer.setSelectedItem(a) } - println("created") peer.addActionListener(Swing.ActionListener { e => - println("action") publish(event.SelectionChanged(ComboBox.this)) }) } diff --git a/src/swing/scala/swing/Component.scala b/src/swing/scala/swing/Component.scala index 3a715e91aa..27ddde51bd 100644 --- a/src/swing/scala/swing/Component.scala +++ b/src/swing/scala/swing/Component.scala @@ -11,8 +11,8 @@ object Component { private val ClientKey = "scala.swingWrapper" /** - * Returns the wrapper for a given peer. - * Fails if there is no wrapper for the given component. + * Returns the wrapper for a given peer, null if there is no wrapper + * for the given component. */ protected[swing] def wrapperFor[C<:Component](c: javax.swing.JComponent): C = c.getClientProperty(ClientKey).asInstanceOf[C] @@ -20,7 +20,7 @@ object Component { /** * Wraps a given Java Swing Component into a new wrapper. */ - def wrap[A](c: JComponent) = new Component { + def wrap(c: JComponent): Component = new Component { override lazy val peer = c } } diff --git a/src/swing/scala/swing/Container.scala b/src/swing/scala/swing/Container.scala index 0c421f6f4a..c1a2c7cc32 100644 --- a/src/swing/scala/swing/Container.scala +++ b/src/swing/scala/swing/Container.scala @@ -9,7 +9,7 @@ object Container { def contents: Seq[Component] = _contents protected class Content extends BufferWrapper[Component] { - def wrap(c: java.awt.Component) = Component.wrapperFor(c.asInstanceOf[javax.swing.JComponent]) + def wrap(c: java.awt.Component): Component = Component.wrapperFor(c.asInstanceOf[javax.swing.JComponent]) override def clear { peer.removeAll() } def remove(n: Int): Component = { val c = peer.getComponent(n) diff --git a/src/swing/scala/swing/Frame.scala b/src/swing/scala/swing/Frame.scala index 4b790cc905..9d0162356f 100644 --- a/src/swing/scala/swing/Frame.scala +++ b/src/swing/scala/swing/Frame.scala @@ -33,6 +33,8 @@ class Frame extends UIElement with RootPanel with Publisher { def menuBar: MenuBar = Component.wrapperFor(peer.getJMenuBar) def menuBar_=(m: MenuBar) = peer.setJMenuBar(m.peer) + def setLocationRelativeTo(c: UIElement) { peer.setLocationRelativeTo(c.peer) } + peer.addWindowListener(new java.awt.event.WindowListener { def windowActivated(e: java.awt.event.WindowEvent) { publish(WindowActivated(Frame.this)) } def windowClosed(e: java.awt.event.WindowEvent) { publish(WindowClosed(Frame.this)) } diff --git a/src/swing/scala/swing/ListView.scala b/src/swing/scala/swing/ListView.scala index 25af541802..1b1fbb76e8 100644 --- a/src/swing/scala/swing/ListView.scala +++ b/src/swing/scala/swing/ListView.scala @@ -20,19 +20,28 @@ object ListView { def wrap[A](r: ListCellRenderer): Renderer[A] = new Wrapped[A](r) class Wrapped[A](override val peer: ListCellRenderer) extends Renderer[A] { - def componentFor(list: ListView[_<:A], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) = { + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) = { Component.wrap(peer.getListCellRendererComponent(list.peer, a, index, isSelected, hasFocus).asInstanceOf[JComponent]) } } + + def apply[A,B](f: A => B)(implicit renderer: Renderer[B]): Renderer[A] = new Renderer[A] { + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = + renderer.componentFor(list, isSelected, hasFocus, f(a), index) + } } + /*def Renderer[A,B](f: A => B)(implicit renderer: Renderer[B]): Renderer[A] = new Renderer[A] { + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = + renderer.componentFor(list, isSelected, hasFocus, f(a), index) + }*/ + abstract class Renderer[-A] { def peer: ListCellRenderer = new ListCellRenderer { - def getListCellRendererComponent(list: JList, a: Any, index: Int, isSelected: Boolean, hasFocus: Boolean) = { + def getListCellRendererComponent(list: JList, a: Any, index: Int, isSelected: Boolean, hasFocus: Boolean) = componentFor(ListView.wrap[A](list), isSelected, hasFocus, a.asInstanceOf[A], index).peer - } } - def componentFor(list: ListView[_<:A], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component } /** @@ -41,7 +50,7 @@ object ListView { * components type so clients can easily use component specific attributes * during configuration. */ - abstract class DefaultRenderer[-A, C<:Component](protected val component: C) extends Renderer[A] { + 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 background. @@ -50,7 +59,7 @@ object ListView { /** * Standard preconfiguration that is commonly done for any component. */ - def preConfigure(list: ListView[_<:A], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) { + def preConfigure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) { if (isSelected) { component.background = list.selectionBackground component.foreground = list.selectionForeground @@ -62,17 +71,26 @@ object ListView { /** * Configuration that is specific to the component and this renderer. */ - def configure(list: ListView[_<:A], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) + def configure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int) /** * Configures the component before returning it. */ - def componentFor(list: ListView[_<:A], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = { + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: A, index: Int): Component = { preConfigure(list, isSelected, hasFocus, a, index) configure(list, isSelected, hasFocus, a, index) component } } + + implicit object GenericRenderer extends Renderer[Any] { + override lazy val peer: ListCellRenderer = new DefaultListCellRenderer + def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: Any, index: Int): Component = { + val c = peer.getListCellRendererComponent(list.peer, a, index, isSelected, hasFocus).asInstanceOf[JComponent] + val w = Component.wrapperFor[Component](c) + if (w eq null) Component.wrap(c) else w + } + } } /** @@ -88,12 +106,35 @@ class ListView[A] extends Component { 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] { + def length = model.getSize + def elements = new Iterator[A] { + var idx = 0 + def next = { idx += 1; apply(idx-1) } + def hasNext = idx < length + } + 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 }) } + object selection extends Publisher { protected abstract class Indices[A](a: =>Seq[A]) extends scala.collection.mutable.Set[A] { def -=(n: A) @@ -110,9 +151,10 @@ class ListView[A] extends Component { def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex } + def selectIndices(ind: Int*) = peer.setSelectedIndices(ind.toArray) object items extends SeqProxy[A] { - def self = peer.getSelectedValues.projection.map(_.asInstanceOf[A]) + def self = peer.getSelectedValues.map(_.asInstanceOf[A]) def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex } @@ -122,11 +164,14 @@ class ListView[A] extends Component { peer.getSelectionModel.addListSelectionListener(new ListSelectionListener { def valueChanged(e: javax.swing.event.ListSelectionEvent) { - publish(ElementSelected(ListView.this, e.getFirstIndex to e.getLastIndex, e.getValueIsAdjusting)) + publish(ListSelectionChanged(ListView.this, e.getFirstIndex to e.getLastIndex, e.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) diff --git a/src/swing/scala/swing/SplitPane.scala b/src/swing/scala/swing/SplitPane.scala index 05d1da2b13..747dc4eb29 100644 --- a/src/swing/scala/swing/SplitPane.scala +++ b/src/swing/scala/swing/SplitPane.scala @@ -6,13 +6,11 @@ import Swing._ /** * @see javax.swing.JSplitPane */ -class SplitPane(o: Orientation.Value) extends Component with Container with Orientable { - override lazy val peer: javax.swing.JSplitPane = new javax.swing.JSplitPane(o.id) +class SplitPane(o: Orientation.Value, left: Component, right: Component) extends Component with Container with Orientable { + override lazy val peer: javax.swing.JSplitPane = new javax.swing.JSplitPane(o.id, left.peer, right.peer) + def this(o: Orientation.Value) = this(Orientation.Horizontal, new Component {}, new Component {}) def this() = this(Orientation.Horizontal) - leftComponent = new Component {} - rightComponent = new Component {} - def contents: Seq[Component] = List(leftComponent, rightComponent) def contents_=(left: Component, right: Component) { peer.setLeftComponent(left.peer) @@ -31,6 +29,12 @@ class SplitPane(o: Orientation.Value) extends Component with Container with Orie def dividerLocation: Int = peer.getDividerLocation def dividerLocation_=(n: Int) { peer.setDividerLocation(n) } + + /*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 diff --git a/src/swing/scala/swing/TabbedPane.scala b/src/swing/scala/swing/TabbedPane.scala index 7ccd747bd5..e86c1f060c 100644 --- a/src/swing/scala/swing/TabbedPane.scala +++ b/src/swing/scala/swing/TabbedPane.scala @@ -12,18 +12,18 @@ object TabbedPane { val Scroll = Value(JTabbedPane.SCROLL_TAB_LAYOUT) } - class Page protected(title0: String, content0: Component, tip0: String, index0: Int) extends Proxy { + 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) = - this(title0, content0, tip0, 0) + this(null, title0, content0, tip0) 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 = null + protected[TabbedPane] var parent: TabbedPane = parent0 protected var _title = title0 def title: String = _title//parent.peer.getTitleAt(index) @@ -50,8 +50,8 @@ object TabbedPane { // TODO: icon, disabledIcon - def index = _index - protected[TabbedPane] var _index: Int = index0 + def index = if(parent != null) parent.peer.indexOfTab(title) else 0//_index + //protected[TabbedPane] var _index: Int = index0 } } @@ -69,18 +69,18 @@ class TabbedPane extends Component with Publisher { val t = apply(n) peer.removeTabAt(n) t.parent = null - for(i <- n to length) apply(i)._index -= 1 + //for(i <- n to length) apply(i)._index -= 1 t } protected def insertAt(n: Int, t: Page) { - for(i <- n to length) apply(i)._index += 1 + //for(i <- n to length) apply(i)._index += 1 t.parent = TabbedPane.this peer.insertTab(t.title, null, t.content.peer, t.tip, n) } def +=(t: Page) { t.parent = TabbedPane.this; peer.addTab(t.title, null, t.content.peer, t.tip) } def length = peer.getTabCount - def apply(n: Int) = new Page(peer.getTitleAt(n), + def apply(n: Int) = new Page(TabbedPane.this, peer.getTitleAt(n), Component.wrapperFor(peer.getComponentAt(n).asInstanceOf[javax.swing.JComponent]), peer.getToolTipTextAt(n)) } diff --git a/src/swing/scala/swing/Table.scala b/src/swing/scala/swing/Table.scala index 22012b0b45..219b567526 100644 --- a/src/swing/scala/swing/Table.scala +++ b/src/swing/scala/swing/Table.scala @@ -38,7 +38,7 @@ object Table { def componentFor(table: Table, isSelected: Boolean, hasFocus: Boolean, a: A, row: Int, column: Int): Component } - abstract class DefaultRenderer[-A, C<:Component](val component: C) extends Renderer[A] { + 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 background. @@ -71,7 +71,7 @@ object Table { } } - class LabelRenderer[A](convert: A => (Icon, String)) extends DefaultRenderer[A, Label](new Label) { + class LabelRenderer[A](convert: A => (Icon, String)) extends AbstractRenderer[A, Label](new Label) { def configure(table: Table, isSelected: Boolean, hasFocus: Boolean, a: A, row: Int, column: Int) { val (icon, text) = convert(a) component.icon = icon diff --git a/src/swing/scala/swing/TextArea.scala b/src/swing/scala/swing/TextArea.scala index 12abe1b5ea..50e1767080 100644 --- a/src/swing/scala/swing/TextArea.scala +++ b/src/swing/scala/swing/TextArea.scala @@ -9,10 +9,10 @@ import event._ * * @see javax.swing.JTextArea */ -class TextArea(text0: String, rows0: Int, columns0: int) extends TextComponent with TextComponent.HasColumns with TextComponent.HasRows { +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) def this(text: String) = this(text, 0, 0) - def this(rows: Int, columns: int) = this("", rows, columns) + def this(rows: Int, columns: Int) = this("", rows, columns) def this() = this("", 0, 0) // TODO: we could make contents StringBuilder-like diff --git a/src/swing/scala/swing/UIElement.scala b/src/swing/scala/swing/UIElement.scala index 7101f0ae27..22370d33b0 100644 --- a/src/swing/scala/swing/UIElement.scala +++ b/src/swing/scala/swing/UIElement.scala @@ -5,8 +5,9 @@ import java.awt.{Color, Cursor, Font, Dimension} /** * The base trait of all user interface elements. */ -trait UIElement { +trait UIElement extends Proxy { def peer: java.awt.Component + def self = peer def foreground: Color = peer.getForeground def foreground_=(c: Color) = peer.setForeground(c) def background: Color = peer.getBackground diff --git a/src/swing/scala/swing/event/BackgroundChanged.scala b/src/swing/scala/swing/event/BackgroundChanged.scala index 2e9c212b97..6673ec47c1 100644 --- a/src/swing/scala/swing/event/BackgroundChanged.scala +++ b/src/swing/scala/swing/event/BackgroundChanged.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class BackgroundChanged(override val source: Component) extends ComponentEvent(source) +case class BackgroundChanged(override val source: Component) extends ComponentEvent diff --git a/src/swing/scala/swing/event/ButtonClicked.scala b/src/swing/scala/swing/event/ButtonClicked.scala index ce3fcf3c18..ce5b0c7cdd 100644 --- a/src/swing/scala/swing/event/ButtonClicked.scala +++ b/src/swing/scala/swing/event/ButtonClicked.scala @@ -1,4 +1,4 @@ package scala.swing.event -case class ButtonClicked(override val source: AbstractButton) extends ComponentEvent(source) with ActionEvent +case class ButtonClicked(override val source: AbstractButton) extends ComponentEvent with ActionEvent diff --git a/src/swing/scala/swing/event/CaretUpdate.scala b/src/swing/scala/swing/event/CaretUpdate.scala index 7bb6638ec9..f5cd1702ab 100644 --- a/src/swing/scala/swing/event/CaretUpdate.scala +++ b/src/swing/scala/swing/event/CaretUpdate.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class CaretUpdate(override val source: TextComponent) extends ComponentEvent(source) +case class CaretUpdate(override val source: TextComponent) extends ComponentEvent diff --git a/src/swing/scala/swing/event/ComponentEvent.scala b/src/swing/scala/swing/event/ComponentEvent.scala index e5bcd30633..a76207d144 100644 --- a/src/swing/scala/swing/event/ComponentEvent.scala +++ b/src/swing/scala/swing/event/ComponentEvent.scala @@ -1,8 +1,10 @@ package scala.swing.event -abstract class ComponentEvent(override val source: Component) extends UIEvent(source) +trait ComponentEvent extends UIEvent { + override val source: Component +} -case class ComponentMoved(override val source: Component) extends ComponentEvent(source) -case class ComponentResized(override val source: Component) extends ComponentEvent(source) -case class ComponentShown(override val source: Component) extends ComponentEvent(source) -case class ComponentHidden(override val source: Component) extends ComponentEvent(source) +case class ComponentMoved(override val source: Component) extends ComponentEvent +case class ComponentResized(override val source: Component) extends ComponentEvent +case class ComponentShown(override val source: Component) extends ComponentEvent +case class ComponentHidden(override val source: Component) extends ComponentEvent diff --git a/src/swing/scala/swing/event/ContainerEvent.scala b/src/swing/scala/swing/event/ContainerEvent.scala index e89e75a8e0..d15b0703cf 100644 --- a/src/swing/scala/swing/event/ContainerEvent.scala +++ b/src/swing/scala/swing/event/ContainerEvent.scala @@ -1,6 +1,6 @@ package scala.swing.event -abstract class ContainerEvent(override val source: Container) extends UIEvent(source) +abstract class ContainerEvent(override val source: Container) extends UIEvent case class ComponentAdded(override val source: Container, child: Component) extends ContainerEvent(source) case class ComponentRemoved(override val source: Container, child: Component) extends ContainerEvent(source) diff --git a/src/swing/scala/swing/event/Event.scala b/src/swing/scala/swing/event/Event.scala index 0538bdf3be..4de5930e09 100644 --- a/src/swing/scala/swing/event/Event.scala +++ b/src/swing/scala/swing/event/Event.scala @@ -1,3 +1,3 @@ package scala.swing.event -abstract class Event +trait Event diff --git a/src/swing/scala/swing/event/FocusEvent.scala b/src/swing/scala/swing/event/FocusEvent.scala index 31546f00d3..75b3bb0a5a 100644 --- a/src/swing/scala/swing/event/FocusEvent.scala +++ b/src/swing/scala/swing/event/FocusEvent.scala @@ -3,7 +3,7 @@ package scala.swing.event /** * The other component is None if it is a non Swing, i.e., AWT or native, component. */ -abstract class FocusEvent(override val source: Component, val other: Option[Component], val temporary: Boolean) extends ComponentEvent(source) +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) diff --git a/src/swing/scala/swing/event/FontChanged.scala b/src/swing/scala/swing/event/FontChanged.scala index 357c1b361e..b2e09024d4 100644 --- a/src/swing/scala/swing/event/FontChanged.scala +++ b/src/swing/scala/swing/event/FontChanged.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class FontChanged(override val source: Component) extends ComponentEvent(source) +case class FontChanged(override val source: Component) extends ComponentEvent diff --git a/src/swing/scala/swing/event/ForegroundChanged.scala b/src/swing/scala/swing/event/ForegroundChanged.scala index a486afa9a8..94a1a8a25d 100644 --- a/src/swing/scala/swing/event/ForegroundChanged.scala +++ b/src/swing/scala/swing/event/ForegroundChanged.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class ForegroundChanged(override val source: Component) extends ComponentEvent(source) +case class ForegroundChanged(override val source: Component) extends ComponentEvent diff --git a/src/swing/scala/swing/event/ListEvent.scala b/src/swing/scala/swing/event/ListEvent.scala index aa1f6d9878..efae65b24d 100644 --- a/src/swing/scala/swing/event/ListEvent.scala +++ b/src/swing/scala/swing/event/ListEvent.scala @@ -1,11 +1,13 @@ package scala.swing.event -abstract class ListEvent[A](override val source: ListView[A]) extends ComponentEvent(source) +trait ListEvent[A] extends ComponentEvent { + override val source: ListView[A] +} -case class ElementSelected[A](override val source: ListView[A], range: Range, live: Boolean) - extends ListEvent(source) with LiveEvent with ListSelectionEvent +//case class ElementSelected[A](override val source: ListView[A], range: Range, live: Boolean) +// extends ListEvent[A] with LiveEvent with ListSelectionEvent -abstract class ListChange[A](override val source: ListView[A]) extends ListEvent(source) +abstract class ListChange[A](override val source: ListView[A]) extends ListEvent[A] case class ListChanged[A](override val source: ListView[A]) extends ListChange(source) case class ListElementsAdded[A](override val source: ListView[A], range: Range) diff --git a/src/swing/scala/swing/event/MouseEvent.scala b/src/swing/scala/swing/event/MouseEvent.scala index 46009697f7..a9c43eb536 100644 --- a/src/swing/scala/swing/event/MouseEvent.scala +++ b/src/swing/scala/swing/event/MouseEvent.scala @@ -2,9 +2,9 @@ package scala.swing.event import java.awt.Point -class MouseEvent(source: Component, point: Point, modifiers: Int) extends ComponentEvent(source) +class MouseEvent(val source: Component, point: Point, modifiers: Int) extends ComponentEvent -class MouseButtonEvent(source: Component, point: Point, modifiers: Int, +class MouseButtonEvent(override val source: Component, point: Point, modifiers: Int, clicks: Int, triggersPopup: Boolean) extends MouseEvent(source, point, modifiers) case class MouseClicked(override val source: Component, point: Point, modifiers: Int, diff --git a/src/swing/scala/swing/event/SelectionEvent.scala b/src/swing/scala/swing/event/SelectionEvent.scala index d9d6d6d21f..7c597934c8 100644 --- a/src/swing/scala/swing/event/SelectionEvent.scala +++ b/src/swing/scala/swing/event/SelectionEvent.scala @@ -1,9 +1,11 @@ package scala.swing.event -trait SelectionEvent extends UIEvent +trait SelectionEvent extends ComponentEvent trait ListSelectionEvent extends SelectionEvent { def range: Range } -case class SelectionChanged(override val source: Component) extends UIEvent(source) with SelectionEvent
\ No newline at end of file +case class SelectionChanged(override val source: Component) extends ComponentEvent with SelectionEvent +case class ListSelectionChanged[A](override val source: ListView[A], range: Range, live: Boolean) + extends SelectionChanged(source) with ListEvent[A]
\ No newline at end of file diff --git a/src/swing/scala/swing/event/TableEvent.scala b/src/swing/scala/swing/event/TableEvent.scala index dc9f80a794..bf39a21001 100644 --- a/src/swing/scala/swing/event/TableEvent.scala +++ b/src/swing/scala/swing/event/TableEvent.scala @@ -1,6 +1,6 @@ package scala.swing.event -abstract class TableEvent(override val source: Table) extends ComponentEvent(source) +abstract class TableEvent(override val source: Table) extends ComponentEvent abstract class TableChange(override val source: Table) extends TableEvent(source) diff --git a/src/swing/scala/swing/event/UIEvent.scala b/src/swing/scala/swing/event/UIEvent.scala index 7e003089b6..f2941e7052 100644 --- a/src/swing/scala/swing/event/UIEvent.scala +++ b/src/swing/scala/swing/event/UIEvent.scala @@ -1,3 +1,5 @@ package scala.swing.event -abstract class UIEvent(val source: UIElement) extends Event +trait UIEvent extends Event { + val source: UIElement +} diff --git a/src/swing/scala/swing/event/ValueChanged.scala b/src/swing/scala/swing/event/ValueChanged.scala index 7070ea2d52..93faa92541 100644 --- a/src/swing/scala/swing/event/ValueChanged.scala +++ b/src/swing/scala/swing/event/ValueChanged.scala @@ -1,3 +1,3 @@ package scala.swing.event -case class ValueChanged(override val source: Component, live: Boolean) extends ComponentEvent(source) with LiveEvent +case class ValueChanged(override val source: Component, live: Boolean) extends ComponentEvent with LiveEvent diff --git a/src/swing/scala/swing/event/WindowEvent.scala b/src/swing/scala/swing/event/WindowEvent.scala index 5f88c0cc75..c0caf2bee9 100644 --- a/src/swing/scala/swing/event/WindowEvent.scala +++ b/src/swing/scala/swing/event/WindowEvent.scala @@ -1,3 +1,3 @@ package scala.swing.event -abstract class WindowEvent(source: Frame) extends UIEvent(source) +abstract class WindowEvent(override val source: Frame) extends UIEvent diff --git a/src/swing/scala/swing/test/ButtonApp.scala b/src/swing/scala/swing/test/ButtonApp.scala index c6f3e5ec94..577f3984a6 100755 --- a/src/swing/scala/swing/test/ButtonApp.scala +++ b/src/swing/scala/swing/test/ButtonApp.scala @@ -1,3 +1,5 @@ +package scala.swing.test + import swing._, swing.event._ object MyApp extends SimpleGUIApplication { diff --git a/src/swing/scala/swing/test/ComboBoxes.scala b/src/swing/scala/swing/test/ComboBoxes.scala index 46441dbeef..961866a815 100644 --- a/src/swing/scala/swing/test/ComboBoxes.scala +++ b/src/swing/scala/swing/test/ComboBoxes.scala @@ -56,8 +56,8 @@ object ComboBoxes extends SimpleGUIApplication { new ImageIcon(resourceFromUserDirectory("swing/images/banana.jpg").toURL)) val iconBox = new ComboBox(icons) { - renderer = new ListView.DefaultRenderer[Icon, Label](new Label) { - def configure(list: ListView[_<:Icon], isSelected: Boolean, hasFocus: Boolean, icon: Icon, index: Int) { + renderer = new ListView.AbstractRenderer[Icon, Label](new Label) { + def configure(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, icon: Icon, index: Int) { component.icon = icon component.xAlignment = Alignment.Center if(isSelected) { diff --git a/src/swing/scala/swing/test/UIDemo.scala b/src/swing/scala/swing/test/UIDemo.scala index a55913d47d..8dbec4379b 100644 --- a/src/swing/scala/swing/test/UIDemo.scala +++ b/src/swing/scala/swing/test/UIDemo.scala @@ -2,8 +2,12 @@ package scala.swing.test import swing._ import event._ +import Swing._ object UIDemo extends SimpleGUIApplication { + //new java.awt.Font("Bitstream Vera Sans", java.awt.Font.PLAIN, 16). + //javax.swing.UIManager.getLookAndFeelDefaults().put("defaultFont", new java.awt.Font("Bitstream Vera Sans", java.awt.Font.PLAIN, 16)) + def top = new MainFrame { title = "UIElement Test" @@ -32,7 +36,8 @@ object UIDemo extends SimpleGUIApplication { var reactLive = false - contents = new BoxPanel(Orientation.Vertical) { + contents = new BorderPanel { + import BorderPanel.Position._ val tabs = new TabbedPane { import TabbedPane._ val buttons = new FlowPanel { @@ -71,6 +76,9 @@ object UIDemo extends SimpleGUIApplication { pages += new Page("Tables", TableSelection.ui) pages += new Page("Dialogs", Dialogs.ui) pages += new Page("Combo Boxes", ComboBoxes.ui) + 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 ") @@ -87,7 +95,18 @@ object UIDemo extends SimpleGUIApplication { pages += new Page("Password", password) } - contents += tabs + + val list = new ListView(tabs.pages) { + selection.selectIndices(0) + selection.intervalMode = ListView.IntervalMode.Single + import ListView._ + renderer = ListView.Renderer(_.title) + } + val center = new SplitPane(Orientation.Vertical, new ScrollPane(list), tabs) { + oneTouchExpandable = true + continuousLayout = true + } + layout(center) = Center object slider extends Slider { min = 0 @@ -95,14 +114,20 @@ object UIDemo extends SimpleGUIApplication { max = tabs.pages.size-1 majorTickSpacing = 1 } - contents += slider + layout(slider) = South listenTo(slider) listenTo(tabs.selection) + listenTo(list.selection) reactions += { case ValueChanged(`slider`, live) => if(!live || live == reactLive) tabs.selection.index = slider.value - case SelectionChanged(`tabs`) => slider.value = tabs.selection.index + case SelectionChanged(`tabs`) => + slider.value = tabs.selection.index + list.selection.selectIndices(tabs.selection.index) + case SelectionChanged(`list`) => + if (list.selection.items.size == 1) + tabs.selection.page = list.selection.items(0) } } } |