Scala #035: TabbedPane.selection
|中級篇|
Java.use(better, src=Scala) # ソースコードの歩き方《中級篇》
ソースコードの歩き方《Scala2.8.0》
《著》小粒ちゃん@湘南組、小粒ちゃん@博多組《監修》小泉ひよ子とタマゴ倶楽部
第1版♪2010/07/14
|関連記事|
Scala #035: TabbedPane.selection
》作業中です《
■ リスト項目を選択する
37: val control = new Table() { ... 51: Command.listenTo(selection) 52: }表項目を選択すると、Command が TabbedPane.selection に呼応します。
74: object Command extends Publisher { 75: reactions += { 76: case TableRowsSelected(source, range, live) => 77: val row = source.selection.rows.leadIndex 78: val value = source.model.getValueAt(row, 0) 79: _update(value.toString) 80: } 81: }選択した項目が変化すると、イベント TableRowsSelected が発生するので、それに反応する処理を記述します。
@
174 object selection extends Publisher { 175 // TODO: could be a sorted set 176 protected abstract class SelectionSet[A](a: =>Seq[A]) extends mutable.Set[A] { 177 def -=(n: A): this.type 178 def +=(n: A): this.type 179 def contains(n: A) = a.contains(n) 180 override def size = a.length 181 def iterator = a.iterator 182 } 183 184 object rows extends SelectionSet(peer.getSelectedRows) { 185 def -=(n: Int) = { peer.removeRowSelectionInterval(n,n); this } 186 def +=(n: Int) = { peer.addRowSelectionInterval(n,n); this } 187 188 def leadIndex: Int = peer.getSelectionModel.getLeadSelectionIndex 189 def anchorIndex: Int = peer.getSelectionModel.getAnchorSelectionIndex 190 } 236 peer.getColumnModel.getSelectionModel.addListSelectionListener(new ListSelectionListener { 237 def valueChanged(e: javax.swing.event.ListSelectionEvent) { 238 publish(TableColumnsSelected(Table.this, e.getFirstIndex to e.getLastIndex, e.getValueIsAdjusting)) 239 } 240 }) 241 peer.getSelectionModel.addListSelectionListener(new ListSelectionListener { 242 def valueChanged(e: javax.swing.event.ListSelectionEvent) { 243 publish(TableRowsSelected(Table.this, e.getFirstIndex to e.getLastIndex, e.getValueIsAdjusting)) 244 } 245 }) 246 }
》作業中です《