diff options
author | Martin Odersky <odersky@gmail.com> | 2009-05-12 18:33:22 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-05-12 18:33:22 +0000 |
commit | 39fdbddb881220f7e64e5cb9016458edc9e314e5 (patch) | |
tree | a6ada1c0b7640865ea625edd068b5037f1978bfb /src/swing | |
parent | 7cfc53fb4b77f70af5de28a057b1d333bee415d8 (diff) | |
download | scala-39fdbddb881220f7e64e5cb9016458edc9e314e5.tar.gz scala-39fdbddb881220f7e64e5cb9016458edc9e314e5.tar.bz2 scala-39fdbddb881220f7e64e5cb9016458edc9e314e5.zip |
changes to maps and sets
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 | 8 | ||||
-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/Table.scala | 20 |
6 files changed, 24 insertions, 24 deletions
diff --git a/src/swing/scala/swing/ButtonGroup.scala b/src/swing/scala/swing/ButtonGroup.scala index ace17bd57b..4b5eeab74c 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 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 -=(b: AbstractButton): this.type = { peer.remove(b.peer); this } + def +=(b: AbstractButton): this.type = { peer.add(b.peer); this } 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 b56e2adcd7..0bea4d8c46 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): this.type = { peer.add(c.peer); this } + 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 35375742cd..e05273ab5f 100644 --- a/src/swing/scala/swing/LayoutContainer.scala +++ b/src/swing/scala/swing/LayoutContainer.scala @@ -44,13 +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 remove(c: Component): Option[Constraints] = { val r = get(c); _contents -= c; r } - def put(c: Component, l: Constraints): Option[Constraints] = { - val r = get(c) + def -= (c: Component): this.type = { _contents -= c; this } + def += (cl: (Component, Constraints)): this.type = { update(cl._1, cl._2); this } + override def update (c: Component, l: Constraints) { val (v, msg) = areValid(l) if (!v) throw new IllegalArgumentException(msg) add(c, l) - r + this } 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 695c6476db..fe9f34de57 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 put(n: A): Boolean - def remove(n: A): Boolean + def -=(n: A): this.type + def +=(n: A): this.type 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 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 -=(n: Int): this.type = { peer.removeSelectionInterval(n,n); this } + def +=(n: Int): this.type = { peer.addSelectionInterval(n,n); this } 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 fa8887fe88..f586af8813 100644 --- a/src/swing/scala/swing/Publisher.scala +++ b/src/swing/scala/swing/Publisher.scala @@ -155,9 +155,9 @@ 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 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)) } + 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/src/swing/scala/swing/Table.scala b/src/swing/scala/swing/Table.scala index e6af3a0c5b..f9568782c3 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 put(n: A): Boolean - def remove(n: A): Boolean + def -=(n: A): this.type + def +=(n: A): this.type def contains(n: A) = a.contains(n) override def size = a.length def elements = a.elements } object rows extends SelectionSet(peer.getSelectedRows) { - 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 -=(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) { - 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 -=(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 @@ -185,15 +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 remove(n: (Int, Int)): Boolean = { + def -=(n: (Int, Int)) = { peer.removeRowSelectionInterval(n._1,n._1) peer.removeColumnSelectionInterval(n._2,n._2) - true// !!! Ingo: what to return? + this } - def put(n: (Int, Int)): Boolean = { + def +=(n: (Int, Int)) = { peer.addRowSelectionInterval(n._1,n._1) peer.addColumnSelectionInterval(n._2,n._2) - false// !!! Ingo: what to return? + this } override def size = peer.getSelectedRowCount * peer.getSelectedColumnCount } |