Skip to content

Commit 466d7f6

Browse files
committed
list-view selection items is read only
1 parent 041d1ef commit 466d7f6

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/main/scala/scala/swing/ListView.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,27 @@ class ListView[A] extends Component {
185185
def iterator: Iterator[B] = a.iterator
186186
}
187187

188-
def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex
189-
def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex
188+
def leadIndex : Int = peer.getSelectionModel.getLeadSelectionIndex
189+
def anchorIndex : Int = peer.getSelectionModel.getAnchorSelectionIndex
190190

191191
/**
192192
* The indices of the currently selected items.
193193
*/
194194
object indices extends Indices(peer.getSelectedIndices) {
195-
override def subtractOne(n: Int): this.type = { peer.removeSelectionInterval(n,n); this }
196195
override def addOne (n: Int): this.type = { peer.addSelectionInterval (n,n); this }
196+
override def subtractOne(n: Int): this.type = { peer.removeSelectionInterval(n,n); this }
197197

198198
override def clear(): Unit = peer.clearSelection()
199199
}
200200

201-
// XXX TODO
202-
// /**
203-
// * The currently selected items.
204-
// */
205-
// object items extends scala.collection.SeqProxy[A] {
206-
// def self = peer.getSelectedValues.map(_.asInstanceOf[A])
207-
// }
208-
def items: Seq[A] = ???
201+
/**
202+
* The currently selected items.
203+
*/
204+
def items: Seq[A] = {
205+
// note: we should be using `getSelectedValuesList`, but it would break the Scala 2.11
206+
// promise of working with Java 6 (requires Java 7)
207+
peer.getSelectedValues.iterator.map(_.asInstanceOf[A]).toSeq
208+
}
209209

210210
def intervalMode: IntervalMode.Value = IntervalMode(peer.getSelectionModel.getSelectionMode)
211211
def intervalMode_=(m: IntervalMode.Value): Unit = peer.getSelectionModel.setSelectionMode(m.id)

src/main/scala/scala/swing/Swing.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import javax.swing.{BorderFactory, Icon, ImageIcon, JComponent, SwingUtilities}
1919
* Helpers for this package.
2020
*/
2121
object Swing {
22-
protected[swing] type PeerContainer = {def peer: awt.Container}
22+
protected[swing] type PeerContainer = { def peer: awt.Container }
2323

24-
protected[swing] def toNoIcon(i: Icon): Icon = if(i == null) EmptyIcon else i
25-
protected[swing] def toNullIcon(i: Icon): Icon = if(i == EmptyIcon) null else i
24+
protected[swing] def toNoIcon (i: Icon): Icon = if (i == null) EmptyIcon else i
25+
protected[swing] def toNullIcon (i: Icon): Icon = if (i == EmptyIcon) null else i
2626
protected[swing] def nullPeer(c: PeerContainer): awt.Container = if (c != null) c.peer else null
2727

2828
implicit def pair2Dimension(p: (Int, Int)) : Dimension = new Dimension (p._1, p._2)
@@ -76,7 +76,7 @@ object Swing {
7676
}
7777

7878
def unwrapIcon(icon: Icon): Icon = if (icon == null) EmptyIcon else icon
79-
def wrapIcon(icon: Icon): Icon = if (icon == EmptyIcon) null else icon
79+
def wrapIcon (icon: Icon): Icon = if (icon == EmptyIcon) null else icon
8080

8181
def EmptyBorder: Border = BorderFactory.createEmptyBorder()
8282
def EmptyBorder(weight: Int): Border =

0 commit comments

Comments
 (0)