List of usage examples for javafx.event EventHandler EventHandler
EventHandler
From source file:net.rptools.tokentool.client.TokenTool.java
@Override public void start(Stage primaryStage) throws IOException { stage = primaryStage;/* ww w . ja va 2s .c o m*/ setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML), ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE)); root = fxmlLoader.load(); tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController(); Scene scene = new Scene(root); primaryStage.setTitle(I18N.getString("TokenTool.stage.title")); primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON))); primaryStage.setScene(scene); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaX += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaX > 1 || deltaX < -1) { if (deltaX % 2 == 0) { tokentool_Controller.updatePortraitLocation(deltaX, 0); deltaX = 0; } else { tokentool_Controller.updatePortraitLocation(deltaX - 1, 0); deltaX = 1; } } }); primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaY += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaY > 1 || deltaY < -1) { if (deltaY % 2 == 0) { tokentool_Controller.updatePortraitLocation(0, deltaY); deltaY = 0; } else { tokentool_Controller.updatePortraitLocation(0, deltaY - 1); deltaY = 1; } } }); primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { tokentool_Controller.exitApplication(); } }); // Load all the overlays into the treeview tokentool_Controller.updateOverlayTreeview(overlayTreeItems); // Restore saved settings AppPreferences.restorePreferences(tokentool_Controller); // Add recent list to treeview tokentool_Controller.updateOverlayTreeViewRecentFolder(true); // Set the Overlay Options accordion to be default open view tokentool_Controller.expandOverlayOptionsPane(true); primaryStage.show(); // Finally, update token preview image after everything is done loading Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView()); }
From source file:application.Main.java
public void createTrayIcon(final Stage stage) { // if the operating system // supports the system tray if (SystemTray.isSupported()) { // get the SystemTray instance SystemTray tray = SystemTray.getSystemTray(); // load an image java.awt.Image image = null; try {/* www . j av a2 s.com*/ // File file = new File(iconLocation); // image = ImageIO.read(file); URL urlIcon = Main.class.getResource(iconLocation); image = ImageIO.read(urlIcon); } catch (IOException ex) { System.out.println(ex); } stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { hide(stage); } }); // create an action listener to listen for default action executed on the tray icon final ActionListener closeListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.close(); controller.terminate(); // // fileWatcher.setTerminateWatching(Boolean.TRUE); System.out.println(applicationTitle + " terminated!"); Platform.exit(); System.exit(0); } }); } }; ActionListener showListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.show(); } }); } }; // create a pop-up menu PopupMenu popupMenu = new PopupMenu(); MenuItem nameItem = new MenuItem(applicationTitle); nameItem.addActionListener(showListener); popupMenu.add(nameItem); popupMenu.addSeparator(); MenuItem showItem = new MenuItem("Show"); showItem.addActionListener(showListener); popupMenu.add(showItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(closeListener); popupMenu.add(closeItem); /// ... add other menu items // construct a TrayIcon, scaling the image to 16x16 (the default dimensions of a tray icon) trayIcon = new TrayIcon(image.getScaledInstance(24, 24, Image.SCALE_DEFAULT), applicationTitle, popupMenu); // set the TrayIcon properties trayIcon.addActionListener(showListener); // add the tray image try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } } }
From source file:com.loop81.fxcomparer.FXComparerController.java
/** Enabled drag & drop support on the anchor-panels for the file selections. */ private void initiateDragNDropp() { anchorPaneDropFile1.setOnDragOver(new EventHandler<DragEvent>() { @Override/*from ww w .ja v a 2s . c o m*/ public void handle(DragEvent event) { if (event.getDragboard().hasFiles() && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) { event.acceptTransferModes(TransferMode.COPY); } else { event.consume(); } } }); anchorPaneDropFile1.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { if (event.getDragboard().hasFiles() && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) { try { archive1 = new ComparableArchive(event.getDragboard().getFiles().get(0)); handleFile(archive1, textFieldArchive1, labelArchive1Info); } catch (ArchiveException e) { new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show(); } } } }); anchorPaneDropFile2.setOnDragOver(new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { if (event.getDragboard().hasFiles() && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) { event.acceptTransferModes(TransferMode.COPY); } else { event.consume(); } } }); anchorPaneDropFile2.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { if (event.getDragboard().hasFiles() && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) { try { archive2 = new ComparableArchive(event.getDragboard().getFiles().get(0)); handleFile(archive2, textFieldArchive2, labelArchive2Info); } catch (ArchiveException e) { new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show(); } } } }); }
From source file:calendarioSeries.vistas.MainViewController.java
public void populateImagenes() { Platform.runLater(new Runnable() { @Override//from w ww . ja v a 2 s .co m public void run() { imagenes.getChildren().clear(); for (Serie serie : series) { //System.out.println(serie.getLastVisto()); try { Image image = new Image(serie.getUrlImagen()); ImageView poster = new ImageView(); ContextMenu menu = new ContextMenu(); //String css = MainApp.class.getResource("resources/MainTheme.css").toExternalForm(); MenuItem delete = new MenuItem("Eliminar"); delete.setId(serie.getId()); delete.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { menu.hide(); MenuItem clicked = (MenuItem) event.getSource(); String toDelete = clicked.getId(); for (Serie serie : series) { if (serie.getId().equals(toDelete)) { series.remove(serie); populateImagenes(); showDetallesMes(mesActual); } } event.consume(); } }); menu.getItems().add(delete); poster.setId(serie.getTitulo()); poster.setImage(image); poster.setCache(true); // poster.setPreserveRatio(true); poster.setFitWidth(210); poster.setFitHeight(300); poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() { @Override public void handle(ContextMenuEvent event) { menu.show(poster, event.getScreenX(), event.getScreenY()); //menu.getScene().getRoot().getStylesheets().add(css); event.consume(); } }); poster.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { try { //serieToPass = serie; sceneToPass = mainApp.scene; FXMLLoader loader = new FXMLLoader( getClass().getResource("DetailsSerieController.fxml")); Parent root = loader.load(); DetailsSerieController controller = loader.getController(); controller.setData(serie, series); controller.setMainApp(mainApp); Scene scene = new Scene(root); mainApp.primaryStage.setScene(scene); mainApp.primaryStage.show(); } catch (IOException ex) { ex.printStackTrace(); } } } }); imagenes.getChildren().add(poster); } catch (IllegalArgumentException e) { Image image = new Image("file:src/calendarioSeries/resources/no-image.png"); ImageView poster = new ImageView(); ContextMenu menu = new ContextMenu(); MenuItem delete = new MenuItem("Eliminar"); delete.setId(serie.getId()); delete.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { menu.hide(); MenuItem clicked = (MenuItem) event.getSource(); String toDelete = clicked.getId(); for (Serie serie : series) { if (serie.getId().equals(toDelete)) { series.remove(serie); populateImagenes(); showDetallesMes(mesActual); } } event.consume(); } }); menu.getItems().add(delete); poster.setId(serie.getTitulo()); poster.setImage(image); poster.setCache(true); //poster.setPreserveRatio(true); poster.setFitWidth(210); poster.setFitHeight(300); poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() { @Override public void handle(ContextMenuEvent event) { menu.show(poster, event.getScreenX(), event.getScreenY()); event.consume(); } }); Text text = new Text(serie.getTitulo()); text.getStyleClass().add("label"); StackPane pane = new StackPane(); pane.getChildren().addAll(poster, text); imagenes.getChildren().add(pane); } finally { rellenarArchivo(); } } } }); }
From source file:context.ui.control.codebooknetwork.CodebookNetworkController.java
/** * * @param event//from www .j a v a 2s.c o m */ @Override public void handleStep3RunButton(ActionEvent event) { if (!this.validateInputOutput()) { return; } CodebookApplicationTaskInstance instance = (CodebookApplicationTaskInstance) getTaskInstance(); CodebookNetworkConfigurationController confController = (CodebookNetworkConfigurationController) configurationController; StringProperty inputPath = basicInputViewController.getSelectedItemLabel().textProperty(); StringProperty inputname = basicInputViewController.getSelectedCorpusName(); CorpusData input = new CorpusData(inputname, inputPath); instance.setInput(input); final StringProperty outputPath = basicOutputViewController.getOutputDirTextField().textProperty(); final String subdirectory = outputPath.get() + "/CB-Results/"; FileHandler.createDirectory(subdirectory); System.out.println("Created sub dir: " + subdirectory); FileList output = new FileList(NamingPolicy.generateOutputName(inputname.get(), outputPath.get(), instance), subdirectory); instance.setTextOutput(output); StringProperty tabularName = NamingPolicy.generateTabularName(inputname.get(), outputPath.get(), instance); StringProperty csvTabularPath = NamingPolicy.generateTabularPath(inputname.get(), outputPath.get(), instance); StringProperty gexfTabularPath = NamingPolicy.generateTabularPath(inputname.get(), outputPath.get(), instance, ".gexf"); csvTabularPath.set(FilenameUtils.getFullPath(csvTabularPath.get()) + "CorpusNetwork.csv"); gexfTabularPath.set(FilenameUtils.getFullPath(gexfTabularPath.get()) + "CorpusNetwork.gexf"); System.out.println("CSV Path: " + csvTabularPath.get() + "\nGexF Path: " + gexfTabularPath.get()); List<TabularData> td = new ArrayList<TabularData>(); td.add(0, new TabularData(tabularName, csvTabularPath)); td.add(1, new TabularData(new SimpleStringProperty(tabularName.get() + "-gexf"), gexfTabularPath)); instance.setTabularOutput(td); instance.setCodebookFile(confController.getCodebookFile()); instance.setDistance(confController.getDistance()); instance.setIsDrop(confController.getCodebookMode()); instance.setIsNormal(confController.getCodebookMethod()); if (confController.getAggregationType() == 0) { // per document instance.setNetInputCorpus(false); } else { //per corpus instance.setNetInputCorpus(true); } instance.setNetOutputCSV(true); instance.setNetOutputGEXF(true); instance.setNetOutputType(confController.getNetworkType()); instance.setNetwork(true); instance.setSeparator(confController.getUnitOfAnalysis()); instance.setCustomTag(confController.getCustomTag()); CTask task = new CodebookApplicationTask(this.getProgress(), this.getProgressMessage()); task.setTaskInstance(instance); task.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { activeAllControls(); nextStepsViewController = new CodebookNetworkNextStepsController( NamingPolicy.generateTaskName(CodebookApplicationTaskInstance.class).get()); nextStepsViewController.setParent(CodebookNetworkController.this); nextStepsViewController.setOutputDir(outputPath.get()); nextStepsViewController.setTabular(getTaskInstance().getTabularOutput(0)); nextStepsViewController.setFilelist((FileList) getTaskInstance().getTextOutput()); nextStepsViewController.init(); ProjectManager.getThisProject().addResult(getTaskInstance().getTabularOutput(0)); ProjectManager.getThisProject().addData(getTaskInstance().getTextOutput()); // ProjectManager.getThisProject().addResult(getTaskInstance().getTabularOutput(1)); if (isNew()) { ProjectManager.getThisProject().addTask(getTaskInstance()); setNew(false); } showNextStepPane(nextStepsViewController); } }); getProgressBar().setVisible(true); deactiveAllControls(); task.start(); setTaskInstance(task.getTaskInstance()); }
From source file:Main.java
private EventHandler<ActionEvent> createPlayHandler(final AudioClip clip) { return new EventHandler<ActionEvent>() { @Override/*w w w . j a v a2 s . c om*/ public void handle(ActionEvent event) { clip.play(volumeSlider.getValue(), balanceSlider.getValue(), rateSlider.getValue(), 0, 0); } }; }
From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java
public ClassTree(JEVisDataSource ds) { super();/*from w ww .j a v a2 s . co m*/ try { _ds = ds; _itemCache = new HashMap<>(); _graphicCache = new HashMap<>(); _itemChildren = new HashMap<>(); JEVisClass root = new JEVisRootClass(ds); TreeItem<JEVisClass> rootItem = buildItem(root); setShowRoot(true); rootItem.setExpanded(true); getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); _editor.setTreeView(this); setCellFactory(new Callback<TreeView<JEVisClass>, TreeCell<JEVisClass>>() { // @Override // public TreeCell<JEVisClass> call(TreeView<JEVisClass> p) { // return new ClassCell(); // } @Override public TreeCell<JEVisClass> call(TreeView<JEVisClass> param) { return new TreeCell<JEVisClass>() { // private ImageView imageView = new ImageView(); @Override protected void updateItem(JEVisClass item, boolean empty) { super.updateItem(item, empty); if (!empty) { ClassGraphic gc = getClassGraphic(item); setContextMenu(gc.getContexMenu()); // setText(item); setGraphic(gc.getGraphic()); } else { setText(null); setGraphic(null); } } }; } }); getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<JEVisClass>>() { @Override public void changed(ObservableValue<? extends TreeItem<JEVisClass>> ov, TreeItem<JEVisClass> t, TreeItem<JEVisClass> t1) { try { if (t1 != null) { _editor.setJEVisClass(t1.getValue()); } } catch (Exception ex) { System.out.println("Error while changing editor: " + ex); } } }); addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent t) { if (t.getCode() == KeyCode.F2) { System.out.println("F2 rename event"); Platform.runLater(new Runnable() { @Override public void run() { fireEventRename(); } }); } else if (t.getCode() == KeyCode.DELETE) { fireDelete(getSelectionModel().getSelectedItem().getValue()); } } }); setId("objecttree"); getStylesheets().add("/styles/Styles.css"); setPrefWidth(500); setRoot(rootItem); setEditable(true); } catch (Exception ex) { // Logger.getLogger(ObjectTree.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } }
From source file:com.imesha.imageprocessor.controllers.MainController.java
private void setOpenMenuItemActionListener() { // Open an image, then show the image in the imageView openMenuItem.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter("Images", "*.*"); FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add(extensionFilter); fileChooser.setTitle("Select an Image to be opened"); File file = fileChooser.showOpenDialog(parentPane.getScene().getWindow()); if (file == null) return; try { bufferedImage = ImageIO.read(file); MainController.showImageInUI(bufferedImage, imageView); } catch (IOException e) { System.out.println(e.getMessage()); }//from ww w . ja va2 s .c om } }); }
From source file:aajavafx.Schedule1Controller.java
@Override public void initialize(URL url, ResourceBundle rb) { schIdColumn.setCellValueFactory(cellData -> cellData.getValue().schIdProperty().asObject()); schDateColumn.setCellValueFactory(cellData -> cellData.getValue().schDateProperty()); schFromTimeColumn.setCellValueFactory(cellData -> cellData.getValue().schFromTimeProperty()); schUntilTimeColumn.setCellValueFactory(cellData -> cellData.getValue().schUntilTimeProperty()); emplVisitedCustColumn// w w w .j a v a2 s .c om .setCellValueFactory(cellData -> cellData.getValue().emplVisitedCustProperty().asObject()); customersCuIdColumn.setCellValueFactory(cellData -> cellData.getValue().customersCuIdProperty()); employeesEmpIdColumn.setCellValueFactory(cellData -> cellData.getValue().employeesEmpIdProperty()); empIdColumn.setCellValueFactory(cellData -> cellData.getValue().idProperty().asObject()); empFirstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNProperty()); empLastColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty()); empUserNameColumn.setCellValueFactory(cellData -> cellData.getValue().empUserNameProperty()); cuIdColumn.setCellValueFactory(cellData -> cellData.getValue().customerIdProperty().asObject()); cuFirstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty()); cuLastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty()); cuPersonnumerColumn.setCellValueFactory(cellData -> cellData.getValue().personnumerProperty()); pickADate.setValue(LocalDate.now()); pickADate.setOnAction(new EventHandler() { public void handle(Event t) { LocalDate date = pickADate.getValue(); System.err.println("Selected date: " + date); setDate(pickADate.getValue().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); System.out.println("Date now: " + getDate()); } }); try { tableEmployee.setItems(getEmployee()); tableCustomer.setItems(getCustomer()); tableSchedule.setItems(getSchedule()); } catch (IOException ex) { Logger.getLogger(EmployeeController.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(EmployeeController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
private static Node createConfirmationPanel() { final Label acceptanceLabel = new Label("Not Available"); final Button acceptButton = new Button("Accept"); acceptButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent event) { acceptanceLabel.setText("Accepted"); }//from w w w. j ava2s . c o m }); final Button declineButton = new Button("Decline"); declineButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent event) { acceptanceLabel.setText("Declined"); } }); final HBox panel = createHBox(6, acceptButton, declineButton, acceptanceLabel); panel.setAlignment(Pos.CENTER_LEFT); configureBorder(panel); return panel; }