1 package fi.jyu.mit.fxgui;
4 import java.util.function.Consumer;
6 import javafx.beans.property.BooleanProperty;
7 import javafx.beans.property.SimpleBooleanProperty;
8 import javafx.beans.property.SimpleStringProperty;
9 import javafx.beans.property.StringProperty;
10 import javafx.beans.value.ChangeListener;
11 import javafx.beans.value.ObservableValue;
12 import javafx.collections.ObservableList;
13 import javafx.scene.control.ComboBox;
24 public class ComboBoxChooser<T>
extends ComboBox<StringAndObject<T>> implements Chooser<T> {
25 private StringProperty rivit =
new SimpleStringProperty();
29 protected BooleanProperty selectFirst =
new SimpleBooleanProperty(
true);
37 this.getSelectionModel().selectFirst();
42 ObservableList<StringAndObject<T>> objects = getItems();
44 for (String
string : strings) {
48 this.getSelectionModel().selectFirst();
59 String[] strings = jono.split(
"\n");
66 StringBuilder sb =
new StringBuilder();
68 for (String
s: rivit) { sb.append(sep).append(
s); sep =
"\n"; }
69 this.rivit.set(sb.toString());
96 public void add(String name, T
object){
106 public void add(T
object){
133 if ( item == null )
return null;
141 if ( item == null )
return null;
147 return getSelectionModel().getSelectedIndex();
153 int oldIndex = getSelectedIndex();
154 getSelectionModel().select(index);
164 return selectFirst.get();
173 selectFirst.set(value);
179 this.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<
StringAndObject<T>>() {
200 return item.replaceFirst(
"_",
"");