private void buildConnectContextMenu() { MenuItem createDb = new MenuItem("Create db..."); createDb.setOnAction(this::onCreateNewDb); MenuItem disconnect = new MenuItem("Disconnect"); disconnect.setOnAction(this::onDisconnectDb); connectContextMenu = new ContextMenu(createDb, disconnect); }
private void buildDbContextMenu() { MenuItem openShell = new MenuItem("Open Shell"); openShell.setOnAction(this::onOpenShell); MenuItem createCollection = new MenuItem("Create collection"); createCollection.setOnAction(this::onCreateNewCollection); MenuItem dropCollection = new MenuItem("Drop db"); dropCollection.setOnAction(this::onDropDB); dbContextMenu = new ContextMenu(openShell, createCollection, dropCollection); }
private void buildCollectionContextMenu() { MenuItem openShell = new MenuItem("Open Shell"); openShell.setOnAction(this::onOpenShell); MenuItem renameCollection = new MenuItem("Rename collection..."); renameCollection.setOnAction(this::onReanameCollection); MenuItem copyCollection = new MenuItem("Copy collection..."); copyCollection.setOnAction(this::onCopyCollection); MenuItem removeAllDocs = new MenuItem("Remove All Documents..."); removeAllDocs.setOnAction(this::onRemoveAllDocuments); MenuItem dropCollection = new MenuItem("Drop Collection..."); dropCollection.setOnAction(this::onDropCollection); collectionContextMenu = new ContextMenu(openShell, renameCollection, copyCollection, removeAllDocs, dropCollection); }
private MenuItem menuItem(String title, Runnable r) { MenuItem mi = new MenuItem(title); mi.setOnAction( event -> { r.run(); }); return mi; }
/** * Inizializes the filechooser that loads the pdbfile * * @param primaryStage */ public void setOpenFileEvent(Stage primaryStage) { openItem.setOnAction( value -> { File selectedFile = fileChooser.showOpenDialog(primaryStage); if (selectedFile.exists() && !selectedFile.isDirectory()) { try { onPdbFileOpened(selectedFile); } catch (IOException e) { e.printStackTrace(); } } }); }
private void setupMainMenu() { countdownMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { OptionsDialog.open(); } }); mIEnglish.setGraphic(new ImageView(new Image("/media/Canada.png"))); mIPortuguese.setGraphic(new ImageView(new Image("/media/Brazil.png"))); mICzech.setGraphic(new ImageView(new Image("/media/Czech-Republic.png"))); mIEnglish.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { try { changeLanguage("en", "CA"); } catch (Exception e) { Qui.showMessageBox("OOps", "EpicWorship could not switch language"); e.printStackTrace(); } } }); mIPortuguese.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { try { changeLanguage("pt", "BR"); } catch (Exception e) { Qui.showMessageBox("OOps", "EpicWorship could not switch language"); e.printStackTrace(); } } }); mICzech.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { try { changeLanguage("cs", "CZ"); } catch (Exception e) { Qui.showMessageBox("OOps", "EpicWorship could not switch language"); e.printStackTrace(); } } }); settingsMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { Image flag; // = new Image(getClass().getResourceAsStream("/media/Canada.png")); try { Parent settings = FXMLLoader.load( getClass().getResource("/fxml/SettingsView.fxml"), EpicSettings.bundle); Scene scene = new Scene(settings); Stage stageSettings = new Stage(); stageSettings.setTitle(EpicSettings.bundle.getString("menu.application.settings")); if (defLoc.equals(Locale.forLanguageTag("en-CA"))) { flag = new Image(getClass().getResourceAsStream("/media/Canada.png")); } else if (defLoc.equals(Locale.forLanguageTag("pt-BR"))) { flag = new Image(getClass().getResourceAsStream("/media/Brazil.png")); } else if (defLoc.equals(Locale.forLanguageTag("cs-CZ"))) { flag = new Image(getClass().getResourceAsStream("/media/Czech-Republic.png")); } else { flag = new Image( getClass().getResourceAsStream("/media/United States of America.png")); } stageSettings.getIcons().add(flag); stageSettings.centerOnScreen(); stageSettings.setResizable(false); stageSettings.setScene(scene); stageSettings.show(); } catch (Exception e) { } } }); exitMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { int response = JOptionPane.showConfirmDialog( null, EpicSettings.bundle.getString("director.exit.message"), EpicSettings.bundle.getString("director.exit.title"), JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { System.exit(0); } } }); } }); instructionsMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { InstructionsDialog.launch(); } }); aboutnMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { InstructionsDialog.launch(); } }); defaultImportMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { Importer.importDefaults(); } }); epcImportMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { Importer.importEPCFiles(); } }); MIPowerPoint.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { Importer.importPowerPointFiles(); } }); epcExportMenuItem.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { Exporter.exportEPCFiles(); } }); }
@Override public void start(Stage primaryStage) throws Exception { /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem saveMenuItem = new MenuItem("Save", imageFile("images/save.png")); fileMenu.getItems().add(saveMenuItem); MenuItem saveAsMenuItem = new MenuItem("Save As...", imageFile("images/save_as.png")); fileMenu.getItems().add(saveAsMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); primaryStage.setTitle("Lab08"); // grid contains all of the textfeilds, labels , buttons, ect.. GridPane grid = new GridPane(); // the tableview puts all of our data into a exel like format TableView<StudentRecord> table = new TableView<>(); table.setItems(DataSource.getAllMarks()); table.setEditable(true); TableColumn<StudentRecord, String> IDColumn = null; IDColumn = new TableColumn<>("SID"); IDColumn.setMinWidth(100); // the thing in quotes is what it will search for in the StudentRecords.java (MAKE SURE THERE IS // A GET FUNCTION FOR THAT VARIBALE) IDColumn.setCellValueFactory(new PropertyValueFactory<>("ID")); TableColumn<StudentRecord, Double> AssignmentColumn = null; AssignmentColumn = new TableColumn<>("Assignment"); AssignmentColumn.setMinWidth(100); AssignmentColumn.setCellValueFactory(new PropertyValueFactory<>("Assign")); TableColumn<StudentRecord, Float> MidtermColumn = null; MidtermColumn = new TableColumn<>("Midterm"); MidtermColumn.setMinWidth(100); MidtermColumn.setCellValueFactory(new PropertyValueFactory<>("Midterm")); TableColumn<StudentRecord, Float> FinalColumn = null; FinalColumn = new TableColumn<>("Final Exam"); FinalColumn.setMinWidth(100); FinalColumn.setCellValueFactory(new PropertyValueFactory<>("Final")); TableColumn<StudentRecord, String> GradeColumn = null; GradeColumn = new TableColumn<>("Letter Grade"); GradeColumn.setMinWidth(100); GradeColumn.setCellValueFactory(new PropertyValueFactory<>("Grade")); table.getColumns().add(IDColumn); table.getColumns().add(AssignmentColumn); table.getColumns().add(MidtermColumn); table.getColumns().add(FinalColumn); table.getColumns().add(GradeColumn); Label IDLabel = new Label("SID:"); grid.add(IDLabel, 0, 0); TextField IDField = new TextField(); IDField.setPromptText("SID"); grid.add(IDField, 1, 0); Label AssignLabel = new Label("Assignments:"); grid.add(AssignLabel, 2, 0); TextField AssignField = new TextField(); AssignField.setPromptText("Assignment"); grid.add(AssignField, 3, 0); Label MidLabel = new Label("Midterm:"); grid.add(MidLabel, 0, 1); TextField midField = new TextField(); midField.setPromptText("Midterm"); grid.add(midField, 1, 1); Label FinalLabel = new Label("Final:"); grid.add(FinalLabel, 2, 1); TextField FinalField = new TextField(); FinalField.setPromptText("Final"); grid.add(FinalField, 3, 1); Button AddButton = new Button("Add"); AddButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { char Grade; String SID = IDField.getText(); Float Assignment = Float.parseFloat(AssignField.getText()); Float Midterm = Float.parseFloat(midField.getText()); Float Final = Float.parseFloat(FinalField.getText()); table.getItems().add(new StudentRecord(SID, Assignment, Midterm, Final)); IDField.setText(""); AssignField.setText(""); midField.setText(""); FinalField.setText(""); } }); grid.add(AddButton, 0, 2); layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(grid); Scene scene = new Scene(layout); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(10); grid.setHgap(10); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Demo"); /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Save", imageFile("images/save.png"))); fileMenu.getItems().add(new MenuItem("Save As...", imageFile("images/save_as.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); /* create the table (for the center of the user interface) */ table = new TableView<>(); table.setItems(DataSource.getAllStudents()); table.setEditable(true); /* create the table's columns */ TableColumn<Student, Integer> sidColumn = null; sidColumn = new TableColumn<>("SID"); sidColumn.setMinWidth(100); sidColumn.setCellValueFactory(new PropertyValueFactory<>("sid")); TableColumn<Student, String> firstNameColumn = null; firstNameColumn = new TableColumn<>("First Name"); firstNameColumn.setMinWidth(200); firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName")); firstNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); firstNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setFirstName(event.getNewValue()); }); TableColumn<Student, String> lastNameColumn = null; lastNameColumn = new TableColumn<>("Last Name"); lastNameColumn.setMinWidth(200); lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName")); lastNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); lastNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setLastName(event.getNewValue()); }); TableColumn<Student, Double> gpaColumn = null; gpaColumn = new TableColumn<>("GPA"); gpaColumn.setMinWidth(100); gpaColumn.setCellValueFactory(new PropertyValueFactory<>("gpa")); table.getColumns().add(sidColumn); table.getColumns().add(lastNameColumn); table.getColumns().add(firstNameColumn); table.getColumns().add(gpaColumn); /* create an edit form (for the bottom of the user interface) */ GridPane editArea = new GridPane(); editArea.setPadding(new Insets(10, 10, 10, 10)); editArea.setVgap(10); editArea.setHgap(10); Label sidLabel = new Label("SID:"); editArea.add(sidLabel, 0, 0); TextField sidField = new TextField(); sidField.setPromptText("SID"); editArea.add(sidField, 1, 0); Label fnameLabel = new Label("First name:"); editArea.add(fnameLabel, 0, 1); TextField fnameField = new TextField(); fnameField.setPromptText("First Name"); editArea.add(fnameField, 1, 1); Label lnameLabel = new Label("Last name:"); editArea.add(lnameLabel, 0, 2); TextField lnameField = new TextField(); lnameField.setPromptText("Last Name"); editArea.add(lnameField, 1, 2); Label gpaLabel = new Label("GPA:"); editArea.add(gpaLabel, 0, 3); TextField gpaField = new TextField(); gpaField.setPromptText("GPA"); editArea.add(gpaField, 1, 3); Button addButton = new Button("Add"); addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { int sid = Integer.parseInt(sidField.getText()); String firstName = fnameField.getText(); String lastName = lnameField.getText(); double gpa = Double.parseDouble(gpaField.getText()); table.getItems().add(new Student(sid, firstName, lastName, gpa)); sidField.setText(""); fnameField.setText(""); lnameField.setText(""); gpaField.setText(""); } }); editArea.add(addButton, 1, 4); /* arrange all components in the main user interface */ layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(editArea); Scene scene = new Scene(layout, 600, 600); primaryStage.setScene(scene); primaryStage.show(); }
public PathTreeCell(/*final Stage owner, */ final StringProperty messageProp) { this.messageProp = messageProp; MenuItem expandMenu = new MenuItem("Expand"); expandMenu.setOnAction( (ActionEvent event) -> { getTreeItem().setExpanded(true); }); MenuItem expandAllMenu = new MenuItem("Expand All"); expandAllMenu.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { expandTreeItem(getTreeItem()); } private void expandTreeItem(TreeItem<PathItem> item) { if (item.isLeaf()) { return; } item.setExpanded(true); ObservableList<TreeItem<PathItem>> children = item.getChildren(); children .stream() .filter(child -> (!child.isLeaf())) .forEach(child -> expandTreeItem(child)); } }); MenuItem addMenu = new MenuItem("Add Directory"); addMenu.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { Path newDir = createNewDirectory(); if (newDir != null) { TreeItem<PathItem> addItem = PathTreeItem.createNode(new PathItem(newDir)); getTreeItem().getChildren().add(addItem); } } private Path createNewDirectory() { Path newDir = null; while (true) { Path path = getTreeItem().getValue().getPath(); newDir = Paths.get( path.toAbsolutePath().toString(), "newDirectory" + String.valueOf(getItem().getCountNewDir())); try { Files.createDirectory(newDir); break; } catch (FileAlreadyExistsException ex) { continue; } catch (IOException ex) { cancelEdit(); messageProp.setValue( String.format("Creating directory(%s) failed", newDir.getFileName())); break; } } return newDir; } }); MenuItem deleteMenu = new MenuItem("Delete"); deleteMenu.setOnAction( (ActionEvent event) -> { ObjectProperty<TreeItem<PathItem>> prop = new SimpleObjectProperty<>(); new ModalDialog(/*owner, */ getTreeItem(), prop); prop.addListener( (ObservableValue<? extends TreeItem<PathItem>> ov, TreeItem<PathItem> oldItem, TreeItem<PathItem> newItem) -> { try { Files.walkFileTree(newItem.getValue().getPath(), new VisitorForDelete()); if (getTreeItem().getParent() == null) { // when the root is deleted how to clear the TreeView??? } else { getTreeItem().getParent().getChildren().remove(newItem); } } catch (IOException ex) { messageProp.setValue( String.format( "Deleting %s failed", newItem.getValue().getPath().getFileName())); } }); }); dirMenu.getItems().addAll(expandMenu, expandAllMenu, deleteMenu, addMenu); fileMenu.getItems().addAll(deleteMenu); }
/** * The opening class. When the launch method is run, the code in here begins to execute. All code * * @param primaryStage The intial stage opened on run * @throws Exception */ @SuppressWarnings("unchecked") public void start(Stage primaryStage) throws Exception { primaryStage.setMaximized(true); primaryStage.setTitle("Equipment Manager"); Button executive = new Button("Executive Options"); TextField search = new TextField(); search.setPromptText("Search"); TableView<Item> table; // create filenames String fileName = System.getProperty("user.home") + "/item.csv"; String passFileName = System.getProperty("user.home") + "/notoflookinghere.csv"; String IDFileName = System.getProperty("user.home") + "/memberlist.csv"; String logFileName = System.getProperty("user.home") + "/Log.csv"; File x = new File(fileName); // if no file exists with given names, create default files if (!x.exists()) { csvFileWriter write = new csvFileWriter(); write.writeCsvFile(logFileName); write.writeCsvFile(fileName); write.writeCsvFile(IDFileName); ArrayList<Item> list = new ArrayList<>(); list.add(new Item(1000, "password", true, "none", false)); write.enterData(list); write.writeCsvFile(passFileName); } else { System.out.println("Files Read"); } manage.searchFor(fileName, search.getText()); table = new TableView<>(); table.setItems(UIManager.getItems(fileName, search.getText())); table.setMaxWidth(675); table .getColumns() .addAll( UIManager.referenceColumn(), UIManager.nameColumn(), UIManager.availableColumn(), UIManager.IDColumn(), UIManager.permColumn()); Button checkout = new Button("Checkout"); checkout.setOnAction( e -> { Checking.checkOut(fileName, IDFileName, passFileName); table.setItems(UIManager.getItems(fileName, search.getText())); }); Button checkIn = new Button("Checkin"); checkIn.setOnAction( e -> { Checking.checkIn(fileName); table.setItems(UIManager.getItems(fileName, search.getText())); }); search.setOnKeyPressed(e -> table.setItems(UIManager.getItems(fileName, search.getText()))); // This creates and sets up all the menu bars on the top of the page MenuBar menuBar = new MenuBar(); // Menu Tabs Menu help = new Menu("_Help"); Menu exec = new Menu("_Executive Settings"); menuBar.getMenus().addAll(help, exec); // Menu Items MenuItem code = new MenuItem("View Code"); MenuItem report = new MenuItem("Report a Bug"); MenuItem openOptions = new MenuItem("Open Executive Options"); help.getItems().addAll(code, report); exec.getItems().addAll(openOptions); // Menu External Links URI codeLink = new URI("https://github.com/NHSTechTeam/Equipment-System"); URI reportLink = new URI("https://github.com/NHSTechTeam/Equipment-System/issues"); // Menu Actions code.setOnAction(e -> UIManager.openWebpage(codeLink)); report.setOnAction(e -> UIManager.openWebpage(reportLink)); openOptions.setOnAction( e -> { try { ExecutiveMain.executive(fileName, passFileName, logFileName, IDFileName); } catch (URISyntaxException e1) { e1.printStackTrace(); } }); HBox menu = new HBox(); menu.setPadding(new Insets(10, 10, 10, 10)); menu.setSpacing(10); menu.setAlignment(Pos.CENTER); menu.getChildren().addAll(checkout, checkIn); executive.setOnAction( e -> { try { ExecutiveMain.executive(fileName, passFileName, logFileName, IDFileName); } catch (URISyntaxException e1) { e1.printStackTrace(); } }); BorderPane borderLayout = new BorderPane(); VBox layout = new VBox(10); borderLayout.setTop(menuBar); borderLayout.setCenter(layout); layout.getChildren().addAll(search, table, menu, executive); layout.setAlignment(Pos.CENTER); Scene scene = new Scene(borderLayout, 300, 250); scene.getStylesheets().add("style.css"); primaryStage.getIcons().add(new Image("images/icon.png")); primaryStage.setScene(scene); primaryStage.show(); }
/** * Set action that happens on button "close" press * * @param primaryStage */ public void setOnCloseEvent(Stage primaryStage) { closeItem.setOnAction(value -> primaryStage.close()); }
public void initialize() { // if (Objects.equals(System.getProperty("os.name"), "Mac OS X")){ // // } JSON json = new JSON(); String[] result = json.returner(); String name1 = result[3].replace(".zip", ""); JCalPropertiesReader jCalPropertiesReader = new JCalPropertiesReader(); String[] strings = jCalPropertiesReader.reader(); new PropertiesWriter(name1, strings[5], result[1], result[2]); Text text1 = new Text(result[2]); text1.setFont(Font.font("Courier New", FontWeight.BOLD, 15)); name.setFont(Font.font("", FontWeight.BOLD, 12)); name.setText(name1); newVersion.setFont(Font.font("", FontWeight.BOLD, 12)); newVersion.setText(result[1]); PropertiesReader propertiesReader = new PropertiesReader(); String[] tempString = propertiesReader.reader(); currentVersion.setText(tempString[1]); if (Objects.equals(result[1], tempString[1])) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("GUpdater"); alert.setHeaderText("JCal up to date"); alert.setContentText("Looks like your software is up to date"); Optional<ButtonType> result1 = alert.showAndWait(); if (result1.get() == ButtonType.OK) { Platform.exit(); } } summary.getChildren().add(text1); close.setOnAction(event -> Platform.exit()); update.setOnAction( event -> { Window ownerWindow = ((Node) event.getTarget()).getScene().getWindow(); Stage stage = new Stage(); stage.initStyle(StageStyle.UNDECORATED); stage.initModality(Modality.APPLICATION_MODAL); stage.initOwner(ownerWindow); Parent parent = null; try { parent = FXMLLoader.load(getClass().getResource("/resource/GUpdater-progress.fxml")); } catch (IOException e) { e.printStackTrace(); } assert parent != null; Scene scene = new Scene(parent, 600, 148); stage.setResizable(false); stage.getIcons().add(new Image("/resource/g-4.png")); stage.setTitle("GUpdater"); stage.setScene(scene); stage.show(); }); cancel.setOnAction(event -> Platform.exit()); }
@FXML void initialize() { // // Defines for event list // removeButton.setDisable(true); editButton.setDisable(true); listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); listView .getSelectionModel() .selectedItemProperty() .addListener( new ChangeListener() { @Override public void changed(ObservableValue observableValue, Object o, Object o2) { // Selected if (listView.getSelectionModel().getSelectedItem() == null) { removeButton.setDisable(true); editButton.setDisable(true); } else { removeButton.setDisable(false); editButton.setDisable(false); } // if (listView.getItems().size() != 0) { clearButton.setDisable(false); } else { clearButton.setDisable(true); } } }); // // Defines for date picker // datePicker.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { listView.getItems().clear(); List<EventController.EventInfo> list = EventController._eventMap.get(datePicker.getValue()); if (list == null) { // No items } else { // Sorting by time TreeMap<String, String> sortedMap = new TreeMap<String, String>(); for (EventController.EventInfo info : list) { sortedMap.put(info.Time, info.Description); } for (Map.Entry<String, String> entry : sortedMap.entrySet()) { mainApplication.addEvent(entry.getKey(), entry.getValue()); } } } }); // // Defines for clear button // clearButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { List<EventController.EventInfo> list = EventController._eventMap.get(datePicker.getValue()); if (list == null) { // No items } else { listView.getItems().clear(); list.clear(); } } }); // // Defines for add button // addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { mainApplication.displayAdd(); } }); // // Defines for remove button // removeButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // Not null TempClass selectedTemp = itemMap.get(listView.getSelectionModel().getSelectedItem()); if (listView.getSelectionModel().getSelectedItem() != null) { listView.getItems().remove(listView.getSelectionModel().getSelectedItem()); EventController.RemoveEvent( datePicker.getValue(), selectedTemp.Time, selectedTemp.Description); } } }); // // Defines for edit button // editButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // Not null Object selectedItem = listView.getSelectionModel().getSelectedItem(); if (selectedItem != null) { TempClass temp = itemMap.get(selectedItem); mainApplication.displayEdit( datePicker.getValue(), temp.Time, temp.Description, selectedItem); } } }); }
public MyTab createTab() { MyTab tab = new MyTab() { @Override public ButtonType close() { if (Objects.nonNull(this.getPath())) closedPaths.add(Optional.ofNullable(current.currentTab().getPath())); ButtonType closeType = super.close(); Platform.runLater( () -> { ObservableList<Tab> tabs = controller.getTabPane().getTabs(); if (tabs.isEmpty()) { controller.newDoc(null); } }); return closeType; } }; tab.setOnCloseRequest( event -> { event.consume(); tab.close(); }); MenuItem menuItem0 = new MenuItem("Close"); menuItem0.setOnAction( actionEvent -> { tab.close(); }); MenuItem menuItem1 = new MenuItem("Close All"); menuItem1.setOnAction( actionEvent -> { ObservableList<Tab> tabs = controller.getTabPane().getTabs(); ObservableList<Tab> clonedTabs = FXCollections.observableArrayList(tabs); if (clonedTabs.size() > 0) { clonedTabs.forEach( (closedTab) -> { MyTab myTab = (MyTab) closedTab; myTab.close(); }); } }); MenuItem menuItem2 = new MenuItem("Close Others"); menuItem2.setOnAction( actionEvent -> { ObservableList<Tab> blackList = FXCollections.observableArrayList(); blackList.addAll(controller.getTabPane().getTabs()); blackList.remove(tab); blackList.forEach( t -> { MyTab closeTab = (MyTab) t; closeTab.close(); }); }); // // MenuItem menuItem3 = new MenuItem("Close Unmodified"); // menuItem3.setOnAction(actionEvent -> { // // ObservableList<Tab> clonedTabs = FXCollections.observableArrayList(); // clonedTabs.addAll(controller.getTabPane().getTabs()); // // // for (Tab clonedTab : clonedTabs) { // MyTab myTab = (MyTab) clonedTab; // if (!myTab.getTabText().contains(" *")) // threadService.runActionLater(()->{ // myTab.close(); // }); // } // }); MenuItem menuItem4 = new MenuItem("Select Next Tab"); menuItem4.setOnAction( actionEvent -> { TabPane tabPane = controller.getTabPane(); if (tabPane.getSelectionModel().isSelected(tabPane.getTabs().size() - 1)) tabPane.getSelectionModel().selectFirst(); else tabPane.getSelectionModel().selectNext(); }); MenuItem menuItem5 = new MenuItem("Select Previous Tab"); menuItem5.setOnAction( actionEvent -> { SingleSelectionModel<Tab> selectionModel = controller.getTabPane().getSelectionModel(); if (selectionModel.isSelected(0)) selectionModel.selectLast(); else selectionModel.selectPrevious(); }); MenuItem menuItem6 = new MenuItem("Reopen Closed Tab"); menuItem6.setOnAction( actionEvent -> { if (closedPaths.size() > 0) { int index = closedPaths.size() - 1; closedPaths.get(index).filter(pathResolver::isAsciidoc).ifPresent(this::addTab); closedPaths.get(index).filter(pathResolver::isMarkdown).ifPresent(this::addTab); closedPaths.get(index).filter(pathResolver::isImage).ifPresent(this::addImageTab); closedPaths.remove(index); } }); MenuItem menuItem7 = new MenuItem("Open File Location"); menuItem7.setOnAction( event -> { current .currentPath() .ifPresent( path -> { controller .getHostServices() .showDocument(path.getParent().toUri().toASCIIString()); }); }); MenuItem menuItem8 = new MenuItem("New File"); menuItem8.setOnAction(controller::newDoc); MenuItem gotoWorkdir = new MenuItem("Go to Workdir"); gotoWorkdir.setOnAction( event -> { current.currentPath().map(Path::getParent).ifPresent(directoryService::changeWorkigDir); }); ContextMenu contextMenu = new ContextMenu(); contextMenu .getItems() .addAll( menuItem0, menuItem1, menuItem2, new SeparatorMenuItem(), menuItem4, menuItem5, menuItem6, new SeparatorMenuItem(), gotoWorkdir, new SeparatorMenuItem(), menuItem7, menuItem8); tab.contextMenuProperty().setValue(contextMenu); Label label = tab.getLabel(); label.setOnMouseClicked( mouseEvent -> { if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) { tab.select(); } else if (mouseEvent.getClickCount() > 1) { controller.adjustSplitPane(); } }); return tab; }
private void buildIndexContextMenu() { MenuItem dropIndex = new MenuItem("Drop Index..."); dropIndex.setOnAction(this::onDropIndex); indexContextMenu = new ContextMenu(dropIndex); }