use of javafx.beans.InvalidationListener in project org.csstudio.display.builder by kasemir.
the class ActionsDialog method createExecuteScriptDetails.
/**
* @return Sub-pane for ExecuteScript action
*/
private GridPane createExecuteScriptDetails() {
final InvalidationListener update = whatever -> {
if (updating || selected_action_index < 0)
return;
actions.set(selected_action_index, getExecuteScriptAction());
};
final GridPane execute_script_details = new GridPane();
execute_script_details.setHgap(10);
execute_script_details.setVgap(10);
execute_script_details.add(new Label(Messages.ActionsDialog_Description), 0, 0);
execute_script_description = new TextField();
execute_script_description.textProperty().addListener(update);
execute_script_details.add(execute_script_description, 1, 0);
GridPane.setHgrow(execute_script_description, Priority.ALWAYS);
execute_script_details.add(new Label(Messages.ActionsDialog_ScriptPath), 0, 1);
execute_script_file = new TextField();
execute_script_file.textProperty().addListener(update);
final Button select = new Button("...");
select.setOnAction(event -> {
try {
final String path = FilenameSupport.promptForRelativePath(widget, execute_script_file.getText());
if (path != null)
execute_script_file.setText(path);
FilenameSupport.performMostAwfulTerribleNoGoodHack(action_list);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot prompt for filename", ex);
}
});
final HBox path_box = new HBox(execute_script_file, select);
HBox.setHgrow(execute_script_file, Priority.ALWAYS);
execute_script_details.add(path_box, 1, 1);
final Button btn_embed_py = new Button(Messages.ScriptsDialog_BtnEmbedPy, JFXUtil.getIcon("embedded_script.png"));
btn_embed_py.setOnAction(event -> {
execute_script_file.setText(ScriptInfo.EMBEDDED_PYTHON);
final String text = execute_script_text.getText();
if (text == null || text.trim().isEmpty() || text.trim().equals(ScriptInfo.EXAMPLE_JAVASCRIPT))
execute_script_text.setText(ScriptInfo.EXAMPLE_PYTHON);
});
final Button btn_embed_js = new Button(Messages.ScriptsDialog_BtnEmbedJS, JFXUtil.getIcon("embedded_script.png"));
btn_embed_js.setOnAction(event -> {
execute_script_file.setText(ScriptInfo.EMBEDDED_JAVASCRIPT);
final String text = execute_script_text.getText();
if (text == null || text.trim().isEmpty() || text.trim().equals(ScriptInfo.EXAMPLE_PYTHON))
execute_script_text.setText(ScriptInfo.EXAMPLE_JAVASCRIPT);
});
execute_script_details.add(new HBox(10, btn_embed_py, btn_embed_js), 1, 2);
execute_script_details.add(new Label(Messages.ActionsDialog_ScriptText), 0, 3);
execute_script_text = new TextArea();
execute_script_text.setText(null);
execute_script_text.textProperty().addListener(update);
execute_script_details.add(execute_script_text, 0, 4, 2, 1);
GridPane.setVgrow(execute_script_text, Priority.ALWAYS);
return execute_script_details;
}
use of javafx.beans.InvalidationListener in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method createModelRoot.
/**
* Create scrollpane etc. for hosting the model
*
* @return ScrollPane
* @throws IllegalStateException if had already been called
*/
public final ScrollPane createModelRoot() {
if (model_root != null)
throw new IllegalStateException("Already created model root");
widget_parent = new Pane();
scroll_body = new Group(widget_parent);
if (isEditMode()) {
horiz_bound = new Line();
horiz_bound.getStyleClass().add("display_model_bounds");
horiz_bound.setStartX(0);
vert_bound = new Line();
vert_bound.getStyleClass().add("display_model_bounds");
vert_bound.setStartY(0);
scroll_body.getChildren().addAll(vert_bound, horiz_bound);
}
model_root = new ScrollPane(scroll_body);
final InvalidationListener resized = prop -> handleViewportChanges();
model_root.widthProperty().addListener(resized);
model_root.heightProperty().addListener(resized);
// Middle Button (Wheel press) drag panning started
final EventHandler<MouseEvent> onMousePressedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
lastMouseCoordinates.set(new Point2D(evt.getX(), evt.getY()));
scroll_body.setCursor(Cursor.CLOSED_HAND);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedHandler);
else
scroll_body.setOnMousePressed(onMousePressedHandler);
// Middle Button (Wheel press) drag panning function
final EventHandler<MouseEvent> onMouseDraggedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
double deltaX = evt.getX() - lastMouseCoordinates.get().getX();
double extraWidth = scroll_body.getLayoutBounds().getWidth() - model_root.getViewportBounds().getWidth();
double deltaH = deltaX * (model_root.getHmax() - model_root.getHmin()) / extraWidth;
double desiredH = model_root.getHvalue() - deltaH;
model_root.setHvalue(Math.max(0, Math.min(model_root.getHmax(), desiredH)));
double deltaY = evt.getY() - lastMouseCoordinates.get().getY();
double extraHeight = scroll_body.getLayoutBounds().getHeight() - model_root.getViewportBounds().getHeight();
double deltaV = deltaY * (model_root.getHmax() - model_root.getHmin()) / extraHeight;
double desiredV = model_root.getVvalue() - deltaV;
model_root.setVvalue(Math.max(0, Math.min(model_root.getVmax(), desiredV)));
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedHandler);
else
scroll_body.setOnMouseDragged(onMouseDraggedHandler);
// Middle Button (Wheel press) drag panning finished
final EventHandler<MouseEvent> onMouseReleasedHandler = evt -> {
if (scroll_body.getCursor() == Cursor.CLOSED_HAND) {
scroll_body.setCursor(Cursor.DEFAULT);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedHandler);
else
scroll_body.setOnMouseReleased(onMouseReleasedHandler);
// also handle the wheel
if (isEditMode())
model_root.addEventFilter(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
doWheelZoom(evt.getDeltaY(), evt.getX(), evt.getY());
}
});
else
widget_parent.addEventHandler(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
ScrollEvent gevt = evt.copyFor(model_root, scroll_body);
doWheelZoom(evt.getDeltaY(), gevt.getX(), gevt.getY());
}
});
return model_root;
}
use of javafx.beans.InvalidationListener in project org.csstudio.display.builder by kasemir.
the class ZoomPan method createScene.
public static Scene createScene() {
// Stuff to show as 'widgets'
final Node[] stuff = new Node[3];
for (int i = 0; i < stuff.length; ++i) {
final Rectangle rect = new Rectangle(50 + i * 100, 100, 10 + i * 50, 20 + i * 40);
rect.setFill(Color.BLUE);
stuff[i] = rect;
}
// With 'Group', stuff would start in top-left (0, 0) corner,
// not at (50, 100) based on its coordinates
final Pane widgets = new Pane(stuff);
widgets.setStyle("-fx-background-color: coral;");
final ScrollPane scroll;
if (true) {
// Additional Group to help ScrollPane get correct bounds
final Group scroll_content = new Group(widgets);
scroll = new ScrollPane(scroll_content);
} else
scroll = new ScrollPane(widgets);
final InvalidationListener resized = prop -> handleViewportChanges(scroll);
scroll.widthProperty().addListener(resized);
scroll.heightProperty().addListener(resized);
System.out.println("Press 'space' to change zoom");
final Scene scene = new Scene(scroll);
scene.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
if (event.getCode() == KeyCode.SPACE) {
zoom_in = !zoom_in;
if (zoom_in)
widgets.getTransforms().setAll(new Scale(2.5, 2.5));
else
widgets.getTransforms().setAll(new Scale(0.5, 0.5));
}
});
return scene;
}
use of javafx.beans.InvalidationListener in project org.csstudio.display.builder by kasemir.
the class MacrosTable method fixup.
/**
* Fix table: Delete empty rows in middle, but keep one empty final row
* @param changed_row Row to check, and remove if it's empty
*/
private void fixup(final int changed_row) {
// Check if edited row is now empty and should be deleted
if (changed_row < data.size()) {
final MacroItem item = data.get(changed_row);
final String name = item.getName().trim();
final String value = item.getValue().trim();
if (name.isEmpty() && value.isEmpty())
data.remove(changed_row);
}
// Assert one empty row at bottom
final int len = data.size();
if (len <= 0 || (data.get(len - 1).getName().trim().length() > 0 && data.get(len - 1).getValue().trim().length() > 0))
data.add(new MacroItem("", ""));
for (InvalidationListener listener : listeners) listener.invalidated(data);
}
use of javafx.beans.InvalidationListener in project POL-POM-5 by PhoenicisOrg.
the class ApplicationPanel method populateCenter.
private void populateCenter() {
this.appDescription = new WebView();
this.appDescription.getEngine().loadContent("<body>" + application.getDescription() + "</body>");
themeManager.bindWebEngineStylesheet(appDescription.getEngine().userStyleSheetLocationProperty());
this.installers = new Label(tr("Installers"));
this.installers.getStyleClass().add("descriptionTitle");
this.scriptGrid = new GridPane();
filteredScripts.addListener((InvalidationListener) change -> this.refreshScripts());
this.refreshScripts();
this.miniaturesPane = new HBox();
this.miniaturesPane.getStyleClass().add("appPanelMiniaturesPane");
this.miniaturesPaneWrapper = new ScrollPane(miniaturesPane);
this.miniaturesPaneWrapper.getStyleClass().add("appPanelMiniaturesPaneWrapper");
for (URI miniatureUri : application.getMiniatures()) {
Region image = new Region();
image.getStyleClass().add("appMiniature");
image.setStyle(String.format("-fx-background-image: url(\"%s\");", miniatureUri.toString()));
image.prefHeightProperty().bind(miniaturesPaneWrapper.heightProperty().multiply(0.8));
image.prefWidthProperty().bind(image.prefHeightProperty().multiply(1.5));
miniaturesPane.getChildren().add(image);
}
this.center = new VBox(appDescription, installers, scriptGrid, miniaturesPaneWrapper);
VBox.setVgrow(appDescription, Priority.ALWAYS);
this.setCenter(center);
}
Aggregations