List of usage examples for javafx.beans.property SimpleObjectProperty SimpleObjectProperty
public SimpleObjectProperty(T initialValue)
From source file:qupath.lib.gui.tma.TMASummaryViewer.java
private void refreshTableData() { // int nn = 0; // double nPositive = 0; // for (TMAEntry entry : entriesBase) { // if (entry.isMissing()) // continue; // nPositive += entry.getMeasurementAsDouble("Num Positive"); // nn++; // }// ww w . j a va 2 s . c o m // System.err.println(nPositive + " positive cells across " + nn + " tissue samples"); Collection<? extends TMAEntry> entries = groupByIDProperty.get() ? createSummaryEntries(entriesBase) : entriesBase; // Ensure that we don't try to modify a filtered list List<TreeTableColumn<TMAEntry, ?>> columns = new ArrayList<>(); // Add an empty column. // Its purpose is to provide the space needed for the little expansion arrows, to avoid // these stealing space from the first interesting column. // Note: there's nothing to prevent the user reordering it along with other columns... // but hopefully it looks 'right' enough where it is that few would try to do that TreeTableColumn<TMAEntry, String> columnEmpty = new TreeTableColumn<>(" "); columnEmpty .setCellValueFactory(new Callback<CellDataFeatures<TMAEntry, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<TMAEntry, String> p) { return Bindings.createStringBinding(() -> ""); } }); columnEmpty.setSortable(false); columnEmpty.setResizable(false); columns.add(columnEmpty); // Check if we have any images or overlays boolean hasImages = entries.stream().anyMatch(e -> e.hasImage()); boolean hasOverlay = entries.stream().anyMatch(e -> e.hasOverlay()); // Add columns to show images, if we have them if (hasImages || hasOverlay) { TreeTableColumn<TMAEntry, TMAEntry> columnImage = hasImages ? new TreeTableColumn<>("Thumbnail") : null; TreeTableColumn<TMAEntry, TMAEntry> columnOverlay = hasOverlay ? new TreeTableColumn<>("Overlay") : null; if (hasImages) { columnImage.setCellValueFactory( new Callback<CellDataFeatures<TMAEntry, TMAEntry>, ObservableValue<TMAEntry>>() { @Override public ObservableValue<TMAEntry> call(CellDataFeatures<TMAEntry, TMAEntry> p) { return p.getValue().valueProperty(); } }); columnImage.setCellFactory(c -> new ImageTableCell(imageCache, false)); columnImage.maxWidthProperty().bind(maxSmallWidth); columnImage.widthProperty().addListener((v, o, n) -> { if (n.doubleValue() == columnImage.getPrefWidth()) return; if (hasOverlay) columnOverlay.setPrefWidth(n.doubleValue()); table.refresh(); }); columns.add(columnImage); } if (hasOverlay) { columnOverlay.setCellValueFactory( new Callback<CellDataFeatures<TMAEntry, TMAEntry>, ObservableValue<TMAEntry>>() { @Override public ObservableValue<TMAEntry> call(CellDataFeatures<TMAEntry, TMAEntry> p) { return p.getValue().valueProperty(); } }); columnOverlay.setCellFactory(c -> new ImageTableCell(imageCache, true)); columnOverlay.maxWidthProperty().bind(maxSmallWidth); columnOverlay.widthProperty().addListener((v, o, n) -> { if (n.doubleValue() == columnOverlay.getPrefWidth()) return; columnImage.setPrefWidth(n.doubleValue()); if (hasImages) table.refresh(); }); columns.add(columnOverlay); } } // Update image availability if (hasImages) { if (hasOverlay) imageAvailability.set(ImageAvailability.BOTH); else imageAvailability.set(ImageAvailability.IMAGE_ONLY); } else if (hasOverlay) { imageAvailability.set(ImageAvailability.OVERLAY_ONLY); } else imageAvailability.set(ImageAvailability.NONE); for (String name : model.getAllNames()) { if (model.getMeasurementNames().contains(name)) { TreeTableColumn<TMAEntry, Number> column = new TreeTableColumn<>(name); column.setCellValueFactory( new Callback<CellDataFeatures<TMAEntry, Number>, ObservableValue<Number>>() { @Override public ObservableValue<Number> call(CellDataFeatures<TMAEntry, Number> p) { double value = p.getValue() == null ? Double.NaN : model.getNumericValue(p.getValue().getValue(), name); return new SimpleDoubleProperty(value); } }); column.setCellFactory(c -> new NumericTableCell<>()); columns.add(column); } else { TreeTableColumn<TMAEntry, Object> column = new TreeTableColumn<>(name); column.setCellValueFactory( new Callback<CellDataFeatures<TMAEntry, Object>, ObservableValue<Object>>() { @Override public ObservableValue<Object> call(CellDataFeatures<TMAEntry, Object> p) { return new SimpleObjectProperty<>(p.getValue() == null ? null : model.getStringValue(p.getValue().getValue(), name)); } }); column.setCellFactory(c -> new BasicTableCell<>()); columns.add(column); } } // Set the column visibility depending upon whether they were hidden previously columns.stream().forEach(c -> c.setVisible(!lastHiddenColumns.contains(c.getText()))); // Set columns for table table.getColumns().setAll(columns); // Set new root for table TreeItem<TMAEntry> root = new RootTreeItem(entries, combinedPredicate); table.setShowRoot(false); table.setRoot(root); model.refreshList(); }
From source file:sonicScream.controllers.CategoryTabController.java
public CategoryTabController(Category category) { URL location = getClass().getResource("/sonicScream/views/CategoryTab.fxml"); FXMLLoader loader = new FXMLLoader(location); loader.setRoot(this); loader.setController(this); try {// w ww . j a v a 2 s .c o m loader.load(); } catch (IOException ex) { throw new RuntimeException(ex); } _category = category; this.textProperty().bind(_category.categoryNameProperty()); CategoryTabComboBox.setItems(_category.getCategoryScripts()); //These two bindings handle changing between categories with only a single //script (items) and those with multiple (everything else) SimpleListProperty bindableList = new SimpleListProperty(); bindableList.bind(new SimpleObjectProperty<>(_category.getCategoryScripts())); CategoryTabComboBox.visibleProperty().bind(Bindings.greaterThan(bindableList.sizeProperty(), 1)); selectedScriptNodeProperty().bind(CategoryTabTreeView.getSelectionModel().selectedItemProperty()); selectedScript.bind(CategoryTabComboBox.getSelectionModel().selectedItemProperty()); if (_category.getCategoryScripts() != null && !_category.getCategoryScripts().isEmpty()) { CategoryTabComboBox.valueProperty().set(_category.getCategoryScripts().get(0)); handleComboBoxChanged(null); } SwapDisplayModeButton.textProperty().bind(Bindings.when(displayMode.isEqualTo(CategoryDisplayMode.SIMPLE)) .then("Advanced >>").otherwise("<< Simple")); CategoryTabTreeView.getSelectionModel().selectedItemProperty() .addListener((observable, oldValue, newValue) -> { if (newValue != null) { TreeItem<String> scriptValue = TreeUtils.getRootMinusOne((TreeItem<String>) newValue); TreeItem<String> selectedValue = (TreeItem<String>) newValue; CategoryTabScriptValueLabel.setText(scriptValue.getValue()); selectedScriptNodeIsLeaf.set(selectedValue.isLeaf()); } }); }