diff options
author | Martin Odersky <odersky@gmail.com> | 2009-05-12 09:58:25 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-05-12 09:58:25 +0000 |
commit | ca3d31e7b25e4709839671f2ee5c5bd643cbc08e (patch) | |
tree | e44fe21fe1202a7c4ebc026a9bc2bd851b16bdec /src/swing | |
parent | e4a8be83c10545e318fcb53bea39e86b26a71555 (diff) | |
download | scala-ca3d31e7b25e4709839671f2ee5c5bd643cbc08e.tar.gz scala-ca3d31e7b25e4709839671f2ee5c5bd643cbc08e.tar.bz2 scala-ca3d31e7b25e4709839671f2ee5c5bd643cbc08e.zip |
separated mutable and immutable maps
Diffstat (limited to 'src/swing')
-rw-r--r-- | src/swing/scala/swing/ButtonGroup.scala | 4 | ||||
-rw-r--r-- | src/swing/scala/swing/Container.scala | 2 | ||||
-rw-r--r-- | src/swing/scala/swing/LayoutContainer.scala | 6 | ||||
-rw-r--r-- | src/swing/scala/swing/ListView.scala | 8 | ||||
-rw-r--r-- | src/swing/scala/swing/Publisher.scala | 6 | ||||
-rw-r--r-- | src/swing/scala/swing/Reactions.scala | 8 | ||||
-rw-r--r-- | src/swing/scala/swing/TabbedPane.scala | 2 | ||||
-rw-r--r-- | src/swing/scala/swing/Table.scala | 18 |
8 files changed, 29 insertions, 25 deletions
diff --git a/src/swing/scala/swing/ButtonGroup.scala b/src/swing/scala/swing/ButtonGroup.scala index b0fad49988..ace17bd57b 100644 --- a/src/swing/scala/swing/ButtonGroup.scala +++ b/src/swing/scala/swing/ButtonGroup.scala @@ -15,8 +15,8 @@ class ButtonGroup(initialButtons: AbstractButton*) { val peer: javax.swing.ButtonGroup = new javax.swing.ButtonGroup val buttons: mutable.Set[AbstractButton] = new mutable.Set[AbstractButton] { - def -=(b: AbstractButton) { peer.remove(b.peer) } - def +=(b: AbstractButton) { peer.add(b.peer) } + def remove(b: AbstractButton): Boolean = { peer.remove(b.peer); true } // !!! Ingo: what to return? + def put(b: AbstractButton): Boolean = { peer.add(b.peer); true } // !!! Ingo: what to return? def contains(b: AbstractButton) = elements.contains(b) override def size = peer.getButtonCount def elements: Iterator[AbstractButton] = new Iterator[AbstractButton] { diff --git a/src/swing/scala/swing/Container.scala b/src/swing/scala/swing/Container.scala index 03c581ecab..b56e2adcd7 100644 --- a/src/swing/scala/swing/Container.scala +++ b/src/swing/scala/swing/Container.scala @@ -21,7 +21,7 @@ object Container { wrap(c) } protected def insertAt(n: Int, c: Component) { peer.add(c.peer, n) } - def +=(c: Component) { peer.add(c.peer) } + def +=(c: Component): this.type = { peer.add(c.peer); this } def length = peer.getComponentCount def apply(n: Int) = wrap(peer.getComponent(n)) } diff --git a/src/swing/scala/swing/LayoutContainer.scala b/src/swing/scala/swing/LayoutContainer.scala index b9a426d544..35375742cd 100644 --- a/src/swing/scala/swing/LayoutContainer.scala +++ b/src/swing/scala/swing/LayoutContainer.scala @@ -44,11 +44,13 @@ trait LayoutContainer extends Container.Wrapper { * also ensures that myComponent is properly add to this container. */ def layout: Map[Component, Constraints] = new Map[Component, Constraints] { - def -=(c: Component) { _contents -= c } - def update(c: Component, l: Constraints) { + def remove(c: Component): Option[Constraints] = { val r = get(c); _contents -= c; r } + def put(c: Component, l: Constraints): Option[Constraints] = { + val r = get(c) val (v, msg) = areValid(l) if (!v) throw new IllegalArgumentException(msg) add(c, l) + r } def get(c: Component) = Swing.toOption(constraintsFor(c)) override def size = peer.getComponentCount diff --git a/src/swing/scala/swing/ListView.scala b/src/swing/scala/swing/ListView.scala index 3a01fb1c46..695c6476db 100644 --- a/src/swing/scala/swing/ListView.scala +++ b/src/swing/scala/swing/ListView.scala @@ -171,8 +171,8 @@ class ListView[A] extends Component { */ object selection extends Publisher { protected abstract class Indices[A](a: =>Seq[A]) extends scala.collection.mutable.Set[A] { - def -=(n: A) - def +=(n: A) + def put(n: A): Boolean + def remove(n: A): Boolean def contains(n: A) = a.contains(n) override def size = a.length def elements = a.elements @@ -182,8 +182,8 @@ class ListView[A] extends Component { * The indices of the currently selected items. */ object indices extends Indices(peer.getSelectedIndices) { - def -=(n: Int) { peer.removeSelectionInterval(n,n) } - def +=(n: Int) { peer.addSelectionInterval(n,n) } + def remove(n: Int): Boolean = { peer.removeSelectionInterval(n,n); true } // !!! Ingo; What to return? } + def put(n: Int): Boolean = { peer.addSelectionInterval(n,n); true } // !!! Ingo; What to return? } def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex diff --git a/src/swing/scala/swing/Publisher.scala b/src/swing/scala/swing/Publisher.scala index 3dbc3f46ec..fa8887fe88 100644 --- a/src/swing/scala/swing/Publisher.scala +++ b/src/swing/scala/swing/Publisher.scala @@ -123,7 +123,7 @@ private[swing] class StrongReference[+T <: AnyRef](value: T) extends Reference[T abstract class RefBuffer[A <: AnyRef] extends Buffer[A] with SingleRefCollection[A] { self => protected val underlying: Buffer[Reference[A]] - def +=(el: A) { purgeReferences(); underlying += Ref(el) } + def +=(el: A): this.type = { purgeReferences(); underlying += Ref(el); this } def +:(el: A) = { purgeReferences(); Ref(el) +: underlying; this } def remove(el: A) { underlying -= Ref(el); purgeReferences(); } def remove(n: Int) = { val el = apply(n); remove(el); el } @@ -155,8 +155,8 @@ abstract class RefBuffer[A <: AnyRef] extends Buffer[A] with SingleRefCollection private[swing] abstract class RefSet[A <: AnyRef] extends Set[A] with SingleRefCollection[A] { self => protected val underlying: Set[Reference[A]] - def -=(el: A) { underlying -= Ref(el); purgeReferences() } - def +=(el: A) { purgeReferences(); underlying += Ref(el) } + def remove(el: A): Boolean = { val r = underlying remove Ref(el); purgeReferences(); r } + def put(el: A): Boolean = { purgeReferences(); underlying put Ref(el) } def contains(el: A) = { purgeReferences(); underlying.contains(Ref(el)) } override def size = { purgeReferences(); underlying.size } diff --git a/src/swing/scala/swing/Reactions.scala b/src/swing/scala/swing/Reactions.scala index 8d5c4ae576..1220a5d862 100644 --- a/src/swing/scala/swing/Reactions.scala +++ b/src/swing/scala/swing/Reactions.scala @@ -9,8 +9,8 @@ object Reactions { class Impl extends Reactions { private val parts: Buffer[Reaction] = new ListBuffer[Reaction] def isDefinedAt(e: Event) = parts.exists(_ isDefinedAt e) - def += (r: Reaction) = { parts += r } - def -= (r: Reaction) { parts -= r } + def += (r: Reaction): this.type = { parts += r; this } + def -= (r: Reaction): this.type = { parts -= r; this } def apply(e: Event) { for (p <- parts) if (p isDefinedAt e) p(e) } @@ -37,10 +37,10 @@ abstract class Reactions extends Reactions.Reaction { /** * Add a reaction. */ - def += (r: Reactions.Reaction) + def += (r: Reactions.Reaction): this.type /** * Remove the given reaction. */ - def -= (r: Reactions.Reaction) + def -= (r: Reactions.Reaction): this.type } diff --git a/src/swing/scala/swing/TabbedPane.scala b/src/swing/scala/swing/TabbedPane.scala index 3661c6988a..dd8ac36203 100644 --- a/src/swing/scala/swing/TabbedPane.scala +++ b/src/swing/scala/swing/TabbedPane.scala @@ -82,7 +82,7 @@ class TabbedPane extends Component with Publisher { 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 +=(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), Component.wrapperFor(peer.getComponentAt(n).asInstanceOf[javax.swing.JComponent]), diff --git a/src/swing/scala/swing/Table.scala b/src/swing/scala/swing/Table.scala index 17025c4454..e6af3a0c5b 100644 --- a/src/swing/scala/swing/Table.scala +++ b/src/swing/scala/swing/Table.scala @@ -160,24 +160,24 @@ class Table extends Component with Scrollable with Publisher { object selection extends Publisher { // TODO: could be a sorted set protected abstract class SelectionSet[A](a: =>Seq[A]) extends scala.collection.mutable.Set[A] { - def -=(n: A) - def +=(n: A) + def put(n: A): Boolean + def remove(n: A): Boolean def contains(n: A) = a.contains(n) override def size = a.length def elements = a.elements } object rows extends SelectionSet(peer.getSelectedRows) { - def -=(n: Int) { peer.removeRowSelectionInterval(n,n) } - def +=(n: Int) { peer.addRowSelectionInterval(n,n) } + def remove(n: Int): Boolean = { peer.removeRowSelectionInterval(n,n); true } // !!! Ingo; What to return? } + def put(n: Int): Boolean = { peer.addRowSelectionInterval(n,n); true } // !!! Ingo; What to return? } def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex } object columns extends SelectionSet(peer.getSelectedColumns) { - def -=(n: Int) { peer.removeColumnSelectionInterval(n,n) } - def +=(n: Int) { peer.addColumnSelectionInterval(n,n) } + def remove(n: Int): Boolean = { peer.removeColumnSelectionInterval(n,n); true } // !!! Ingo; What to return? } + def put(n: Int): Boolean = { peer.addColumnSelectionInterval(n,n); true } // !!! Ingo; What to return? } def leadIndex: Int = peer.getColumnModel.getSelectionModel.getLeadSelectionIndex def anchorIndex: Int = peer.getColumnModel.getSelectionModel.getAnchorSelectionIndex @@ -185,13 +185,15 @@ class Table extends Component with Scrollable with Publisher { def cells: Set[(Int, Int)] = new SelectionSet[(Int, Int)]((for(r <- selection.rows; c <- selection.columns) yield (r,c)).toSeq) { outer => - def -=(n: (Int, Int)) { + def remove(n: (Int, Int)): Boolean = { peer.removeRowSelectionInterval(n._1,n._1) peer.removeColumnSelectionInterval(n._2,n._2) + true// !!! Ingo: what to return? } - def +=(n: (Int, Int)) { + def put(n: (Int, Int)): Boolean = { peer.addRowSelectionInterval(n._1,n._1) peer.addColumnSelectionInterval(n._2,n._2) + false// !!! Ingo: what to return? } override def size = peer.getSelectedRowCount * peer.getSelectedColumnCount } |