scala-swing
scala-swing copied to clipboard
scala.swing.ComboBox should support mutable item lists
To enable dynamical Swing comboboxes, scala.swing.ComboBox should also be able to use the MutableComboBoxModel. Something like the addition of a mutable model in addition to the existing constant model:
class MutableModel[A](items: Buffer[A]) extends ConstantModel(items) with MutableComboBoxModel {
def removeElementAt( n: Int ) = items.remove( n )
def removeElement( item: Any ) = items.remove( items.indexOf(item) )
def insertElementAt( item: Any, n: Int ) = items.insert( n, item.asInstanceOf[A] )
def addElement( item: Any ) = items.append( item.asInstanceOf[A] )
}
The choice of the model could depend on some parameters in the constructor (e.g. matching Seq or Buffer).
Imported From: https://issues.scala-lang.org/browse/SI-1613?orig=1 Reporter: Daniel Willmann (dwillmann)
Thomas Santana (mailleux) said: I achieved this using a combo box which you can specify the model.
Here is the example: https://github.com/nebulorum/virtual-combat-cards/blob/master/vcc-swing/src/main/scala/vcc/util/swing/ExplicitModelComboBox.scala
I would recommend making ComboBox accept a mode. Provide a default mutable model implementation and allows users to create their own. The example above uses an immutable Seq because I rather use this.
I would also suggest making the model type visible so you don't have to add a bunch o methods in ComboBox and have to deal with mutable and immutable collections.