-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ListSelection replaces Selection with ComboBox where necessary.
* Fixes #332 on OS X, but looks really ugly. * Spinner might be an alternative, but is hard to use for different reasons * Maybe I can find a way to limit the Lists to 3 items each
- Loading branch information
Showing
3 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
Platform_FX/src/net/sf/anathema/platform/fx/selection/ListSelectionView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package net.sf.anathema.platform.fx.selection; | ||
|
||
import com.sun.javafx.collections.ObservableListWrapper; | ||
import javafx.beans.value.ChangeListener; | ||
import javafx.beans.value.ObservableValue; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ListView; | ||
import net.sf.anathema.lib.control.ObjectValueListener; | ||
import net.sf.anathema.lib.gui.AgnosticUIConfiguration; | ||
import net.sf.anathema.platform.fx.ConfigurableListCellFactory; | ||
import net.sf.anathema.platform.fx.FxObjectSelectionView; | ||
import net.sf.anathema.platform.fx.FxThreading; | ||
import org.jmock.example.announcer.Announcer; | ||
import org.tbee.javafx.scene.layout.MigPane; | ||
|
||
import java.util.Arrays; | ||
|
||
import static net.sf.anathema.lib.gui.layout.LayoutUtils.withoutInsets; | ||
|
||
public class ListSelectionView<T> implements FxObjectSelectionView<T> { | ||
private ListView<T> list; | ||
private Label label; | ||
private MigPane pane; | ||
private final Announcer<ObjectValueListener> announcer = Announcer.to(ObjectValueListener.class); | ||
|
||
@SuppressWarnings("unchecked") | ||
public ListSelectionView(final String description, final AgnosticUIConfiguration<T> ui) { | ||
FxThreading.runOnCorrectThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
list = new ListView<>(); | ||
label = new Label(description); | ||
pane = new MigPane(withoutInsets()); | ||
pane.add(label); | ||
pane.add(list); | ||
} | ||
}); | ||
FxThreading.runOnCorrectThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
list.setCellFactory(new ConfigurableListCellFactory<>(ui)); | ||
list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<T>() { | ||
@Override | ||
public void changed(ObservableValue<? extends T> observableValue, T v, T newValue) { | ||
announcer.announce().valueChanged(newValue); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void setSelectedObject(final T object) { | ||
FxThreading.runOnCorrectThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
list.getSelectionModel().select(object); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void addObjectSelectionChangedListener(ObjectValueListener<T> listener) { | ||
announcer.addListener(listener); | ||
} | ||
|
||
@Override | ||
public void removeObjectSelectionChangedListener(ObjectValueListener<T> listener) { | ||
announcer.removeListener(listener); | ||
} | ||
|
||
@Override | ||
public void setObjects(T[] objects) { | ||
waitForContent(); | ||
list.setItems(new ObservableListWrapper<>(Arrays.asList(objects))); | ||
} | ||
|
||
@Override | ||
public T getSelectedObject() { | ||
return list.getSelectionModel().getSelectedItem(); | ||
} | ||
|
||
@Override | ||
public boolean isObjectSelected() { | ||
return getSelectedObject() != null; | ||
} | ||
|
||
@Override | ||
public void setEnabled(boolean enabled) { | ||
list.setDisable(!enabled); | ||
} | ||
|
||
@Override | ||
public Node getNode() { | ||
return pane; | ||
} | ||
|
||
private void waitForContent() { | ||
try { | ||
while (pane == null) { | ||
Thread.sleep(50); | ||
} | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Platform_FX/src/net/sf/anathema/platform/fx/selection/PopUpLessSelectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.sf.anathema.platform.fx.selection; | ||
|
||
import net.sf.anathema.lib.gui.AgnosticUIConfiguration; | ||
import net.sf.anathema.platform.fx.FxObjectSelectionView; | ||
|
||
public class PopUpLessSelectionFactory implements SelectionViewFactory{ | ||
@Override | ||
public <T> FxObjectSelectionView<T> create(String label, AgnosticUIConfiguration<T> ui) { | ||
return new ListSelectionView<>(label, ui); | ||
} | ||
} |