List of usage examples for javafx.event EventHandler EventHandler
EventHandler
From source file:dtv.controller.FXMLMainController.java
public void init(ObservableList<DVBChannel> serviceData, TableView<DVBChannel> table, TableColumn<DVBChannel, Integer> idx, TableColumn<DVBChannel, String> name, TableColumn<DVBChannel, String> type, TableColumn<DVBChannel, String> ppr) { table.setEditable(true);/*from w w w .j a v a 2 s. com*/ idx.setCellValueFactory(cellData -> cellData.getValue().idxProperty().asObject()); name.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); name.setEditable(true); type.setCellValueFactory(cellData -> cellData.getValue().typeProperty()); // nid.setCellValueFactory(cellData -> cellData.getValue().nidProperty().asObject()); ppr.setCellValueFactory(cellData -> cellData.getValue().pprProperty()); // newCol.setCellValueFactory(cellData -> cellData.getValue().neewProperty()); // Context menu table.setRowFactory(tableView -> { final TableRow<DVBChannel> row = new TableRow<>(); final ContextMenu rowMenu = new ContextMenu(); final MenuItem removeItem = new MenuItem("Delete"); removeItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final DVBChannel service = row.getItem(); serviceData.removeAll(service); } }); rowMenu.getItems().addAll(removeItem); row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty())).then(rowMenu) .otherwise((ContextMenu) null)); return row; }); ppr.setCellFactory(col -> { final TableCell<DVBChannel, String> cell = new TableCell<>(); cell.textProperty().bind(cell.itemProperty()); cell.itemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { final ContextMenu cellMenu = new ContextMenu(); for (String pref : Utils.prefTab) { final CheckMenuItem prefMenuItem = new CheckMenuItem(pref); if (Utils.isPreferenceOn(cell.getText(), pref)) { prefMenuItem.setSelected(true); } prefMenuItem.selectedProperty().addListener((obs1, old_val, new_val) -> { final String new_ppr; final DVBChannel service = (DVBChannel) cell.getTableRow().getItem(); if (new_val) { new_ppr = Utils.add_ppr(cell.getText(), pref); } else { new_ppr = Utils.remove_ppr(cell.getText(), pref); } service.setPpr(new_ppr); service.setModified(true); }); cellMenu.getItems().add(prefMenuItem); cell.setContextMenu(cellMenu); } } else { cell.setContextMenu(null); } }); return cell; }); // Editable service name name.setCellFactory(p -> new EditingCell()); name.setOnEditCommit(t -> { final DVBChannel service = t.getTableView().getItems().get(t.getTablePosition().getRow()); service.setName(t.getNewValue()); service.setModified(true); }); }
From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java
private void createPopup() { popup = new PopupControl() { {/*from w w w .ja va 2s .c o m*/ setSkin(new Skin() { @Override public Skinnable getSkinnable() { return LookupFieldSkin.this.lookupField; } @Override public Node getNode() { return listView; } @Override public void dispose() { } }); } }; popup.setAutoHide(true); popup.setAutoFix(true); popup.setHideOnEscape(true); popup.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { popup.hide(); } }); listView.setCellFactory(new Callback() { @Override public Object call(Object p) { return new PropertyListCell(lookupField.getPropertyName()); } }); /** * Taken from * {@link com.sun.javafx.scene.control.skin.ComboBoxListViewSkin} */ listView.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { // RT-18672: Without checking if the user is clicking in the // scrollbar area of the ListView, the comboBox will hide. Therefore, // we add the check below to prevent this from happening. EventTarget target = t.getTarget(); if (target instanceof Parent) { List<String> s = ((Parent) target).getStyleClass(); if (s.contains("thumb") || s.contains("track") || s.contains("decrement-arrow") || s.contains("increment-arrow")) { return; } } needValidation = false; lookupField.setValue(listView.getSelectionModel().getSelectedItem()); popup.hide(); } }); listView.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent t) { if (t.getCode() == KeyCode.ENTER) { needValidation = false; lookupField.setValue(listView.getSelectionModel().getSelectedItem()); popup.hide(); } else if (t.getCode() == KeyCode.ESCAPE) { popup.hide(); } } }); }
From source file:com.properned.application.SystemController.java
public void initialize() { logger.info("Initialize System controller"); localeButton.disableProperty().bind(multiLanguageProperties.isLoadedProperty().not()); saveButton.disableProperty().bind(multiLanguageProperties.isDirtyProperty().not() .or(multiLanguageProperties.isLoadedProperty().not())); Stage primaryStage = Properned.getInstance().getPrimaryStage(); primaryStage.titleProperty()// w w w.ja va2 s .c om .bind(multiLanguageProperties.baseNameProperty() .concat(Bindings.when(multiLanguageProperties.isLoadedProperty()) .then(new SimpleStringProperty(" (") .concat(multiLanguageProperties.parentDirectoryPathProperty()).concat(")")) .otherwise("")) .concat(Bindings.when(multiLanguageProperties.isDirtyProperty()).then(" *").otherwise(""))); FilteredList<String> filteredList = new FilteredList<>(multiLanguageProperties.getListMessageKey(), new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); SortedList<String> sortedList = new SortedList<>(filteredList, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); messageKeyList.setItems(sortedList); filterText.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { // Filter the list filteredList.setPredicate(new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); // check the add button disabled status if (isKeyCanBeAdded(newValue)) { addButton.setDisable(false); } else { addButton.setDisable(true); } } }); ChangeListener<String> changeMessageListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { logger.info("Message key selection changed : " + newValue); valueList.setItems(FXCollections.observableArrayList()); valueList.setItems(FXCollections .observableArrayList(multiLanguageProperties.getMapPropertiesByLocale().keySet())); } }; messageKeyList.getSelectionModel().selectedItemProperty().addListener(changeMessageListener); messageKeyList.setCellFactory(c -> new MessageKeyListCell(multiLanguageProperties)); valueList.setCellFactory(c -> new ValueListCell(multiLanguageProperties, messageKeyList)); filterText.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.DOWN) { messageKeyList.requestFocus(); event.consume(); } else if (event.getCode() == KeyCode.ENTER) { addKey(); event.consume(); } } }); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("Menu Sample"); Scene scene = new Scene(new VBox(), 400, 350); scene.setFill(Color.OLDLACE); name.setFont(new Font("Verdana Bold", 22)); binName.setFont(new Font("Arial Italic", 10)); pic.setFitHeight(150);//w w w. j ava 2s .c o m pic.setPreserveRatio(true); description.setWrapText(true); description.setTextAlignment(TextAlignment.JUSTIFY); shuffle(); MenuBar menuBar = new MenuBar(); // --- Graphical elements final VBox vbox = new VBox(); vbox.setAlignment(Pos.CENTER); vbox.setSpacing(10); vbox.setPadding(new Insets(0, 10, 0, 10)); vbox.getChildren().addAll(name, binName, pic, description); // --- Menu File Menu menuFile = new Menu("File"); MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png"))); add.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { shuffle(); vbox.setVisible(true); } }); MenuItem clear = new MenuItem("Clear"); clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X")); clear.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { vbox.setVisible(false); } }); MenuItem exit = new MenuItem("Exit"); exit.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.exit(0); } }); menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit); // --- Menu Edit Menu menuEdit = new Menu("Edit"); Menu menuEffect = new Menu("Picture Effect"); final ToggleGroup groupEffect = new ToggleGroup(); for (Entry effect : effects) { RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey()); itemEffect.setUserData(effect.getValue()); itemEffect.setToggleGroup(groupEffect); menuEffect.getItems().add(itemEffect); } final MenuItem noEffects = new MenuItem("No Effects"); noEffects.setDisable(true); noEffects.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { pic.setEffect(null); groupEffect.getSelectedToggle().setSelected(false); noEffects.setDisable(true); } }); groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) { if (groupEffect.getSelectedToggle() != null) { Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData(); pic.setEffect(effect); noEffects.setDisable(false); } else { noEffects.setDisable(true); } } }); menuEdit.getItems().addAll(menuEffect, noEffects); // --- Menu View Menu menuView = new Menu("View"); CheckMenuItem titleView = createMenuItem("Title", name); CheckMenuItem binNameView = createMenuItem("Binomial name", binName); CheckMenuItem picView = createMenuItem("Picture", pic); CheckMenuItem descriptionView = createMenuItem("Decsription", description); menuView.getItems().addAll(titleView, binNameView, picView, descriptionView); menuBar.getMenus().addAll(menuFile, menuEdit, menuView); // --- Context Menu final ContextMenu cm = new ContextMenu(); MenuItem cmItem1 = new MenuItem("Copy Image"); cmItem1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putImage(pic.getImage()); clipboard.setContent(content); } }); cm.getItems().add(cmItem1); pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) cm.show(pic, e.getScreenX(), e.getScreenY()); } }); ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox); stage.setScene(scene); stage.show(); }
From source file:org.jacp.demo.components.ContactTableViewComponent.java
private void showDialogIfEmpty(final Contact contact) { // show popup to ask how many contacts to create final JACPOptionPane dialog = JACPDialogUtil.createOptionPane("Contact Demo Pane", "Currently are no contact in this category available. Do you want to create " + Util.MAX + " contacts?"); dialog.setDefaultButton(JACPDialogButton.NO); dialog.setDefaultCloseButtonVisible(true); dialog.setOnYesAction(new EventHandler<ActionEvent>() { @Override//from w w w . j a va 2 s .co m public void handle(final ActionEvent arg0) { contact.setAmount(Util.MAX); contact.setEmpty(false); // redirect contact to coordinator callback to create // contacts context.send("id01.id004", contact); } }); dialog.setOnNoAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent arg0) { } }); JACPModalDialog.getInstance().showModalDialog(dialog); }
From source file:com.mycompany.pfinanzaspersonales.BuscadorController.java
@FXML private void btnBuscar(ActionEvent event) throws IOException { String desde_t = "", hasta_t = ""; if (input_desde.getValue() != null) { desde_t = input_desde.getValue().toString(); }/* w ww. j a v a 2 s .co m*/ if (input_hasta.getValue() != null) { hasta_t = input_hasta.getValue().toString(); } final String desde = desde_t; final String hasta = hasta_t; final Task<Void> tarea = new Task<Void>() { @Override protected Void call() throws Exception { HttpResponse response; List<NameValuePair> parametros = new ArrayList<NameValuePair>(); parametros.add(new BasicNameValuePair("tipo", cbb_tipo.getValue().toString())); parametros.add(new BasicNameValuePair("pago", cbb_pago.getValue().toString())); parametros.add(new BasicNameValuePair("desde", desde)); parametros.add(new BasicNameValuePair("hasta", hasta)); System.out.println(desde); response = JSON.request(Config.URL + "usuarios/buscar.json", parametros); JSONObject jObject = JSON.JSON(response); tabla_json = new ArrayList<TablaBuscar>(); try { editar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("editar")); eliminar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("eliminar")); fecha.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("fecha")); categoria.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("categoria")); tpago.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("pago")); tmonto.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("monto")); ttipo.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("tipo")); tabla_json = new ArrayList<TablaBuscar>(); if (!jObject.get("data").equals(null)) { JSONArray jsonArr = jObject.getJSONArray("data"); for (int i = 0; i < jsonArr.length(); i++) { JSONObject data_json = jsonArr.getJSONObject(i); tabla_json.add(new TablaBuscar(data_json.get("idgastos").toString(), data_json.get("idgastos").toString(), data_json.get("idgastos").toString(), data_json.get("monto").toString(), data_json.get("fecha").toString(), data_json.get("nom_mediopago").toString(), data_json.get("categoria").toString(), data_json.get("tipo").toString())); } } tabla_buscador.setItems(FXCollections.observableArrayList(tabla_json)); } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void succeeded() { super.succeeded(); eliminar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() { @Override public TableCell<String, String> call(TableColumn<String, String> p) { return new TableCell<String, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (!isEmpty() && !empty) { final VBox vbox = new VBox(5); Image image = new Image(getClass().getResourceAsStream("/Imagenes/delete.png")); final Button boton = new Button("", new ImageView(image)); boton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Action response = Dialogs.create().title("Eliminar Gasto") .message("Ests seguro que desaeas eliminar el gasto?") .showConfirm(); if (response == Dialog.ACTION_YES) { TablaBuscar tabla = tabla_json.get(getTableRow().getIndex()); List<NameValuePair> parametros = new ArrayList<NameValuePair>(); String url = ""; if (tabla.getTipo() == "Gastos") { parametros .add(new BasicNameValuePair("idgastos", tabla.getId())); url = Config.URL + "gastos/eliminar.json"; } else { parametros.add( new BasicNameValuePair("idingresos", tabla.getId())); url = Config.URL + "ingresos/eliminar.json"; } HttpResponse responseJSON = JSON.request(url, parametros); JSONObject jObject = JSON.JSON(responseJSON); int code = Integer.parseInt(jObject.get("code").toString()); if (code == 201) { int selectdIndex = getTableRow().getIndex(); tabla_json.remove(selectdIndex); tabla_buscador.getItems().remove(selectdIndex); } else { Dialogs.create().title("Error sincronizacin").message( "Hubo un error al intentar eliminar . ERROR: 301") .showInformation(); } } } }); vbox.getChildren().add(boton); setGraphic(vbox); } else { setGraphic(null); } } }; } }); editar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() { @Override public TableCell<String, String> call(TableColumn<String, String> p) { return new TableCell<String, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (!isEmpty() && !empty) { final VBox vbox = new VBox(5); Image image = new Image(getClass().getResourceAsStream("/Imagenes/edit.png")); final Button boton = new Button("", new ImageView(image)); boton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TablaBuscar tabla = tabla_json.get(getTableRow().getIndex()); Parent parent = null; if (tabla.getTipo() == "Gastos") { AgregarGastos AG = AgregarGastos.getInstance(); AG.setID(tabla.getId()); AG.setMonto(tabla.getMonto()); AG.setCategoria(tabla.getCategoria()); AG.setPago(tabla.getPago()); AG.setActualizacion(true); try { parent = FXMLLoader.load(this.getClass() .getResource("/fxml/AgregarGastos.fxml")); } catch (IOException ex) { Logger.getLogger(FXMLController.class.getName()) .log(Level.SEVERE, null, ex); } } else { AgregarIngresos AI = AgregarIngresos.getInstance(); AI.setID(tabla.getId()); AI.setMonto(tabla.getMonto()); AI.setCategoria(tabla.getCategoria()); AI.setPago(tabla.getPago()); AI.setActualizar(true); try { parent = FXMLLoader.load(this.getClass() .getResource("/fxml/AgregarIngresos.fxml")); } catch (IOException ex) { Logger.getLogger(FXMLController.class.getName()) .log(Level.SEVERE, null, ex); } } Stage stage = new Stage(); Scene scene = new Scene(parent); stage.setScene(scene); stage.show(); } }); vbox.getChildren().add(boton); setGraphic(vbox); } else { setGraphic(null); } } }; } }); } }; new Thread(tarea).start(); }
From source file:gov.va.isaac.gui.ConceptNode.java
/** * descriptionReader is optional// www . ja va 2 s . c o m */ public ConceptNode(ConceptVersionBI initialConcept, boolean flagAsInvalidWhenBlank, ObservableList<SimpleDisplayConcept> dropDownOptions, Function<ConceptVersionBI, String> descriptionReader) { c_ = initialConcept; //We can't simply use the ObservableList from the CommonlyUsedConcepts, because it infinite loops - there doesn't seem to be a way //to change the items in the drop down without changing the selection. So, we have this hack instead. listChangeListener_ = new ListChangeListener<SimpleDisplayConcept>() { @Override public void onChanged(Change<? extends SimpleDisplayConcept> c) { //TODO I still have an infinite loop here. Find and fix. logger.debug("updating concept dropdown"); disableChangeListener_ = true; SimpleDisplayConcept temp = cb_.getValue(); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setValue(temp); cb_.getSelectionModel().select(temp); disableChangeListener_ = false; } }; descriptionReader_ = (descriptionReader == null ? (conceptVersion) -> { return conceptVersion == null ? "" : OTFUtility.getDescription(conceptVersion); } : descriptionReader); dropDownOptions_ = dropDownOptions == null ? AppContext.getService(CommonlyUsedConcepts.class).getObservableConcepts() : dropDownOptions; dropDownOptions_.addListener(new WeakListChangeListener<SimpleDisplayConcept>(listChangeListener_)); conceptBinding_ = new ObjectBinding<ConceptVersionBI>() { @Override protected ConceptVersionBI computeValue() { return c_; } }; flagAsInvalidWhenBlank_ = flagAsInvalidWhenBlank; cb_ = new ComboBox<>(); cb_.setConverter(new StringConverter<SimpleDisplayConcept>() { @Override public String toString(SimpleDisplayConcept object) { return object == null ? "" : object.getDescription(); } @Override public SimpleDisplayConcept fromString(String string) { return new SimpleDisplayConcept(string, 0); } }); cb_.setValue(new SimpleDisplayConcept("", 0)); cb_.setEditable(true); cb_.setMaxWidth(Double.MAX_VALUE); cb_.setPrefWidth(ComboBox.USE_COMPUTED_SIZE); cb_.setMinWidth(200.0); cb_.setPromptText("Type, drop or select a concept"); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setVisibleRowCount(11); cm_ = new ContextMenu(); MenuItem copyText = new MenuItem("Copy Description"); copyText.setGraphic(Images.COPY.createImageView()); copyText.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { CustomClipboard.set(cb_.getEditor().getText()); } }); cm_.getItems().add(copyText); CommonMenusNIdProvider nidProvider = new CommonMenusNIdProvider() { @Override public Set<Integer> getNIds() { Set<Integer> nids = new HashSet<>(); if (c_ != null) { nids.add(c_.getNid()); } return nids; } }; CommonMenuBuilderI menuBuilder = CommonMenus.CommonMenuBuilder.newInstance(); menuBuilder.setInvisibleWhenFalse(isValid); CommonMenus.addCommonMenus(cm_, menuBuilder, nidProvider); cb_.getEditor().setContextMenu(cm_); updateGUI(); new LookAheadConceptPopup(cb_); if (cb_.getValue().getNid() == 0) { if (flagAsInvalidWhenBlank_) { isValid.setInvalid("Concept Required"); } } else { isValid.setValid(); } cb_.valueProperty().addListener(new ChangeListener<SimpleDisplayConcept>() { @Override public void changed(ObservableValue<? extends SimpleDisplayConcept> observable, SimpleDisplayConcept oldValue, SimpleDisplayConcept newValue) { if (newValue == null) { logger.debug("Combo Value Changed - null entry"); } else { logger.debug("Combo Value Changed: {} {}", newValue.getDescription(), newValue.getNid()); } if (disableChangeListener_) { logger.debug("change listener disabled"); return; } if (newValue == null) { //This can happen if someone calls clearSelection() - it passes in a null. cb_.setValue(new SimpleDisplayConcept("", 0)); return; } else { if (newValue.shouldIgnoreChange()) { logger.debug("One time change ignore"); return; } //Whenever the focus leaves the combo box editor, a new combo box is generated. But, the new box will have 0 for an id. detect and ignore if (oldValue != null && oldValue.getDescription().equals(newValue.getDescription()) && newValue.getNid() == 0) { logger.debug("Not a real change, ignore"); newValue.setNid(oldValue.getNid()); return; } lookup(); } } }); AppContext.getService(DragRegistry.class).setupDragAndDrop(cb_, new SingleConceptIdProvider() { @Override public String getConceptId() { return cb_.getValue().getNid() + ""; } }, true); pi_ = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); pi_.visibleProperty().bind(isLookupInProgress_); pi_.setPrefHeight(16.0); pi_.setPrefWidth(16.0); pi_.setMaxWidth(16.0); pi_.setMaxHeight(16.0); lookupFailImage_ = Images.EXCLAMATION.createImageView(); lookupFailImage_.visibleProperty().bind(isValid.not().and(isLookupInProgress_.not())); Tooltip t = new Tooltip(); t.textProperty().bind(isValid.getReasonWhyInvalid()); Tooltip.install(lookupFailImage_, t); StackPane sp = new StackPane(); sp.setMaxWidth(Double.MAX_VALUE); sp.getChildren().add(cb_); sp.getChildren().add(lookupFailImage_); sp.getChildren().add(pi_); StackPane.setAlignment(cb_, Pos.CENTER_LEFT); StackPane.setAlignment(lookupFailImage_, Pos.CENTER_RIGHT); StackPane.setMargin(lookupFailImage_, new Insets(0.0, 30.0, 0.0, 0.0)); StackPane.setAlignment(pi_, Pos.CENTER_RIGHT); StackPane.setMargin(pi_, new Insets(0.0, 30.0, 0.0, 0.0)); hbox_ = new HBox(); hbox_.setSpacing(5.0); hbox_.setAlignment(Pos.CENTER_LEFT); hbox_.getChildren().add(sp); HBox.setHgrow(sp, Priority.SOMETIMES); }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
public ChartViewer(String title, int width, int height, int maxChartNumberInARow) { stage = new Stage(); stage.setTitle(title);//from ww w .ja v a 2s .c o m stage.setWidth(width); stage.setHeight(height); this.maxChartNumberInARow = maxChartNumberInARow; this.setContextMenu(createContextMenu()); vBoxPane = new VBox(); scrollPane = new ScrollPane(); scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); scrollPane.setPannable(true); scrollPane.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { MouseButton button = event.getButton(); if (button == MouseButton.SECONDARY) { menu.show(stage, event.getScreenX(), event.getScreenY()); } } }); scrollPane.widthProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { refreshChartPositionAndSize(); } }); scrollPane.heightProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { refreshChartPositionAndSize(); } }); vBoxPane.getChildren().add(new HBox()); scrollPane.setContent(vBoxPane); chartCanvasList = new ArrayList<>(); stage.setScene(new Scene(scrollPane)); }
From source file:nars.rl.util.ThreeDView.java
private void handleKeyboard(Scene scene, final Node root) { final boolean moveCamera = true; scene.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override/*from w ww. j a va2 s . c o m*/ public void handle(KeyEvent event) { Duration currentTime; switch (event.getCode()) { case Z: if (event.isShiftDown()) { cameraXform.ry.setAngle(0.0); cameraXform.rx.setAngle(0.0); camera.setTranslateZ(-300.0); } cameraXform2.t.setX(0.0); cameraXform2.t.setY(0.0); break; case X: if (event.isControlDown()) { if (axisGroup.isVisible()) { axisGroup.setVisible(false); } else { axisGroup.setVisible(true); } } break; case S: if (event.isControlDown()) { if (space.isVisible()) { space.setVisible(false); } else { space.setVisible(true); } } break; case SPACE: if (timelinePlaying) { timeline.pause(); timelinePlaying = false; } else { timeline.play(); timelinePlaying = true; } break; case UP: if (event.isControlDown() && event.isShiftDown()) { cameraXform2.t.setY(cameraXform2.t.getY() - 10.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown() && event.isShiftDown()) { cameraXform.rx.setAngle(cameraXform.rx.getAngle() - 10.0 * ALT_MULTIPLIER); } else if (event.isControlDown()) { cameraXform2.t.setY(cameraXform2.t.getY() - 1.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown()) { cameraXform.rx.setAngle(cameraXform.rx.getAngle() - 2.0 * ALT_MULTIPLIER); } else if (event.isShiftDown()) { double z = camera.getTranslateZ(); double newZ = z + 5.0 * SHIFT_MULTIPLIER; camera.setTranslateZ(newZ); } break; case DOWN: if (event.isControlDown() && event.isShiftDown()) { cameraXform2.t.setY(cameraXform2.t.getY() + 10.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown() && event.isShiftDown()) { cameraXform.rx.setAngle(cameraXform.rx.getAngle() + 10.0 * ALT_MULTIPLIER); } else if (event.isControlDown()) { cameraXform2.t.setY(cameraXform2.t.getY() + 1.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown()) { cameraXform.rx.setAngle(cameraXform.rx.getAngle() + 2.0 * ALT_MULTIPLIER); } else if (event.isShiftDown()) { double z = camera.getTranslateZ(); double newZ = z - 5.0 * SHIFT_MULTIPLIER; camera.setTranslateZ(newZ); } break; case RIGHT: if (event.isControlDown() && event.isShiftDown()) { cameraXform2.t.setX(cameraXform2.t.getX() + 10.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown() && event.isShiftDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() - 10.0 * ALT_MULTIPLIER); } else if (event.isControlDown()) { cameraXform2.t.setX(cameraXform2.t.getX() + 1.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() - 2.0 * ALT_MULTIPLIER); } break; case LEFT: if (event.isControlDown() && event.isShiftDown()) { cameraXform2.t.setX(cameraXform2.t.getX() - 10.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown() && event.isShiftDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() + 10.0 * ALT_MULTIPLIER); // - } else if (event.isControlDown()) { cameraXform2.t.setX(cameraXform2.t.getX() - 1.0 * CONTROL_MULTIPLIER); } else if (event.isAltDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() + 2.0 * ALT_MULTIPLIER); // - } break; } } }); }
From source file:be.makercafe.apps.makerbench.editors.JFXScadEditor.java
public JFXScadEditor(String tabText, Path path) { super(tabText); this.viewGroup = new Group(); this.editorContainer = new BorderPane(); this.viewContainer = new Pane(); this.caCodeArea = new CodeArea(""); this.caCodeArea.setEditable(true); this.caCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(caCodeArea)); this.caCodeArea.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE); this.caCodeArea.getStylesheets().add(this.getClass().getResource("java-keywords.css").toExternalForm()); this.caCodeArea.richChanges().subscribe(change -> { caCodeArea.setStyleSpans(0, computeHighlighting(caCodeArea.getText())); });/* w w w .java 2 s .c o m*/ addContextMenu(this.caCodeArea); EventStream<Change<String>> textEvents = EventStreams.changesOf(caCodeArea.textProperty()); textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(3000)).subscribe(code -> { if (autoCompile) { compile(code.getNewValue()); } }); if (path == null) { this.caCodeArea.replaceText("CSG cube = new Cube(2).toCSG()\n" + "CSG sphere = new Sphere(1.25).toCSG()\n" + "\n" + "cube.difference(sphere)"); } else { try { this.caCodeArea.replaceText(FileUtils.readFileToString(path.toFile())); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading file.", ex); } } //editorContainer.setCenter(this.codeArea); subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED); subScene.widthProperty().bind(viewContainer.widthProperty()); subScene.heightProperty().bind(viewContainer.heightProperty()); PerspectiveCamera subSceneCamera = new PerspectiveCamera(false); subScene.setCamera(subSceneCamera); viewContainer.getChildren().add(subScene); SplitPane editorPane = new SplitPane(caCodeArea, viewContainer); editorPane.setOrientation(Orientation.HORIZONTAL); BorderPane rootPane = new BorderPane(); BorderPane pane = (BorderPane) this.getTab().getContent(); toolBar = createToolBar(); rootPane.setTop(toolBar); rootPane.setCenter(editorPane); this.getTab().setContent(rootPane); subScene.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out .println(String.format("deltaX: %.3f deltaY: %.3f", event.getDeltaX(), event.getDeltaY())); double z = subSceneCamera.getTranslateZ(); double newZ = z + event.getDeltaY(); subSceneCamera.setTranslateZ(newZ); } }); }