1 package fi.jyu.mit.fxgui;
3 import java.util.function.Consumer;
5 import javafx.beans.property.BooleanProperty;
6 import javafx.beans.property.SimpleBooleanProperty;
7 import javafx.beans.property.SimpleStringProperty;
8 import javafx.beans.property.StringProperty;
9 import javafx.beans.value.ChangeListener;
10 import javafx.beans.value.ObservableValue;
11 import javafx.collections.ObservableList;
12 import javafx.scene.control.ListView;
23 public class ListChooser<T>
extends ListView<StringAndObject<T>> implements Chooser<T> {
25 private StringProperty rivit =
new SimpleStringProperty(
"\n");
26 private BooleanProperty nollataanko =
new SimpleBooleanProperty(
false);
44 public void add(String name, T
object){
54 public void add(T
object){
79 ObservableList<StringAndObject<T>> objects = getItems();
81 for (String
string : strings) {
84 this.getSelectionModel().selectFirst();
97 String[] strings = jono.split(
"\n");
105 StringBuilder sb =
new StringBuilder();
107 for (String
s: rivit) { sb.append(sep).append(
s); sep =
"\n"; }
108 this.rivit.set(sb.toString());
119 if ( item == null )
return null;
139 nollataanko.set(reset);
148 return nollataanko.get();
155 if ( item == null )
return null;
161 return getSelectionModel().getSelectedIndex();
167 int oldIndex = getSelectedIndex();
168 getSelectionModel().select(index);
175 this.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<
StringAndObject<T>>() {
193 return item.replaceFirst(
"_",
"");