diff options
author | Ingo Maier <ingo.maier@epfl.ch> | 2009-04-14 13:03:23 +0000 |
---|---|---|
committer | Ingo Maier <ingo.maier@epfl.ch> | 2009-04-14 13:03:23 +0000 |
commit | 6ea08aefa313cf203e0f2e91dd1015aadc0eaa37 (patch) | |
tree | a73a9a42d235c64266a38aadeb07ca4fbd59241d /src | |
parent | a51564d27807a7f4ab8ace603b17867996722da8 (diff) | |
download | scala-6ea08aefa313cf203e0f2e91dd1015aadc0eaa37.tar.gz scala-6ea08aefa313cf203e0f2e91dd1015aadc0eaa37.tar.bz2 scala-6ea08aefa313cf203e0f2e91dd1015aadc0eaa37.zip |
Hopefully fixed #1599, removed apparently stupi...
Hopefully fixed #1599, removed apparently stupid code from Table demo
and another small bug in Table
Diffstat (limited to 'src')
-rw-r--r-- | src/swing/scala/swing/Table.scala | 22 | ||||
-rw-r--r-- | src/swing/scala/swing/test/TableSelection.scala | 35 |
2 files changed, 28 insertions, 29 deletions
diff --git a/src/swing/scala/swing/Table.scala b/src/swing/scala/swing/Table.scala index 15e7128304..915f879264 100644 --- a/src/swing/scala/swing/Table.scala +++ b/src/swing/scala/swing/Table.scala @@ -77,6 +77,10 @@ object Table { } class LabelRenderer[A](convert: A => (Icon, String)) extends AbstractRenderer[A, Label](new Label) { + def this() { + this{ a => (null, a.toString) } + } + def configure(table: Table, isSelected: Boolean, hasFocus: Boolean, a: A, row: Int, column: Int) { val (icon, text) = convert(a) component.icon = icon @@ -198,7 +202,7 @@ class Table extends Component with Scrollable with Publisher { * but the result is a table that does not produce useful selections. */ def intervalMode: IntervalMode.Value = IntervalMode(peer.getSelectionModel.getSelectionMode) - def intervalMode_=(m: IntervalMode.Value) { peer.getSelectionModel.setSelectionMode(m.id) } + def intervalMode_=(m: IntervalMode.Value) { peer.setSelectionMode(m.id) } def elementMode: ElementMode.Value = if(peer.getColumnSelectionAllowed && peer.getRowSelectionAllowed) ElementMode.Cell else if(peer.getColumnSelectionAllowed) ElementMode.Column @@ -225,15 +229,13 @@ class Table extends Component with Scrollable with Publisher { }) } - private val initialRenderer = peer.getDefaultRenderer(classOf[AnyRef]) - /** * Supplies a renderer component for a given cell. */ protected def rendererComponent(isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component = new Component { override lazy val peer = { - val v = Table.this.peer.getValueAt(row, column) + val v = apply(row, column).asInstanceOf[AnyRef] if (v != null) Table.this.peer.getDefaultRenderer(v.getClass).getTableCellRendererComponent(Table.this.peer, v, isSelected, hasFocus, row, column).asInstanceOf[JComponent] @@ -244,7 +246,7 @@ class Table extends Component with Scrollable with Publisher { // TODO: a public API for setting editors protected def editor(row: Int, column: Int) = { - val v = Table.this.peer.getValueAt(row, column) + val v = apply(row, column).asInstanceOf[AnyRef] if (v != null) Table.this.peer.getDefaultEditor(v.getClass) else @@ -253,13 +255,19 @@ class Table extends Component with Scrollable with Publisher { /** * Get the current value of the given cell. + * The given cell coordinates are in view coordinates and thus not + * necessarily the same as for the model. */ - def apply(row: Int, column: Int): Any = model.getValueAt(row, column) + def apply(row: Int, column: Int): Any = model.getValueAt(row, viewToModelColumn(column)) + + def viewToModelColumn(idx: Int) = peer.convertColumnIndexToModel(idx) + def modelToViewColumn(idx: Int) = peer.convertColumnIndexToView(idx) + /** * Change the value of the given cell. */ - def update(row: Int, column: Int, value: Any) { model.setValueAt(value, row, column) } + def update(row: Int, column: Int, value: Any) { model.setValueAt(value, row, viewToModelColumn(column)) } /** * Visually update the given cell. diff --git a/src/swing/scala/swing/test/TableSelection.scala b/src/swing/scala/swing/test/TableSelection.scala index 4d5ce47da3..e0a3a77a74 100644 --- a/src/swing/scala/swing/test/TableSelection.scala +++ b/src/swing/scala/swing/test/TableSelection.scala @@ -6,26 +6,25 @@ import swing.event._ object TableSelection extends SimpleGUIApplication { val model = Array(List("Mary", "Campione", "Snowboarding", 5, false).toArray, - List("Alison", "Huml", "Rowing", 5, false).toArray, - List("Kathy", "Walrath", "Knitting", 5, false).toArray, - List("Sharon", "Zakhour", "Speed reading", 5, false).toArray, - List("Philip", "Milne", "Pool", 5, false).toArray) + List("Alison", "Huml", "Rowing", 5, false).toArray, + List("Kathy", "Walrath", "Knitting", 5, false).toArray, + List("Sharon", "Zakhour", "Speed reading", 5, false).toArray, + List("Philip", "Milne", "Pool", 5, false).toArray) val ui = new BoxPanel(Orientation.Vertical) { - val table = new Table(model, Array("First Name", "Last Name", "Sport", "# of Years", "Vegetarian")) { - preferredViewportSize = new Dimension(500, 70) - val l = new Table.LabelRenderer[String](a => (null,a)) - override def rendererComponent(isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component = - TableSelection.model(row)(column) match { - case s: String => l.componentFor(this, isSelected, hasFocus, s, row, column) - case _ => super.rendererComponent(isSelected, hasFocus, row, column) - } + val table = new Table(model, Array("First Name", "Last Name", "Sport", "# of Years", "Vegetarian")) { + preferredViewportSize = new Dimension(500, 70) + val l = new Table.LabelRenderer[String] + override def rendererComponent(isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component = + this(row, column) match { + case s: String => l.componentFor(this, isSelected, hasFocus, s, row, column) + case _ => super.rendererComponent(isSelected, hasFocus, row, column) + } } //1.6:table.fillsViewportHeight = true listenTo(table.selection) contents += new ScrollPane(table) - contents += new Label("Selection Mode") def radio(mutex: ButtonGroup, text: String): RadioButton = { @@ -61,14 +60,6 @@ object TableSelection extends SimpleGUIApplication { for (c <- table.selection.columns) output.append(" " + c) output.append(".\n") } - reactions += { - case ButtonClicked(_) => - rowSelection.selected = table.selection.elementMode == Table.ElementMode.Row - columnSelection.selected = table.selection.elementMode == Table.ElementMode.Column - if (cellSelection.enabled) { - cellSelection.selected = table.selection.elementMode == Table.ElementMode.Cell - } - } reactions += { case ButtonClicked(`multiInterval`) => @@ -100,7 +91,7 @@ object TableSelection extends SimpleGUIApplication { output.append("Columns selected, changes " + range + "\n") outputSelection() } - } + } def top = new MainFrame { title = "Table Selection" |