Java Code Examples for javafx.event.Event#fireEvent()
The following examples show how to use
javafx.event.Event#fireEvent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileResource.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public Resource rename(String text) { try { File sourceFile = path.toFile(); File destinationFile = path.resolveSibling(text).toFile(); Path moved; if (!sourceFile.getParent().equals(destinationFile.getParent())) { moved = Files.move(path, path.resolveSibling(text)); } else { sourceFile.renameTo(destinationFile); moved = destinationFile.toPath(); } FileResource to = new FileResource(moved.toFile()); Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.MOVED, this, to)); return to; } catch (IOException e) { FXUIUtils.showMessageDialog(null, "Unable to rename file: " + e.getMessage(), e.getClass().getName(), AlertType.ERROR); return null; } }
Example 2
Source File: TooltippedTextFieldTableCell.java From pdfsam with GNU Affero General Public License v3.0 | 6 votes |
@Override public void commitEdit(String item) { // This block is necessary to support commit on losing focus, because the baked-in mechanism // sets our editing state to false before we can intercept the loss of focus. // The default commitEdit(...) method simply bails if we are not editing... if (!isEditing() && !item.equals(getItem())) { TableView<SelectionTableRowData> table = getTableView(); if (table != null) { TableColumn<SelectionTableRowData, String> column = getTableColumn(); CellEditEvent<SelectionTableRowData, String> event = new CellEditEvent<>(table, new TablePosition<>(table, getIndex(), column), TableColumn.editCommitEvent(), item); Event.fireEvent(column, event); } } super.commitEdit(item); setContentDisplay(ContentDisplay.TEXT_ONLY); }
Example 3
Source File: FXTestUtils.java From graph-editor with Eclipse Public License 1.0 | 6 votes |
/** * Drags the given {@link Node} from the start location to the end location. * * @param node the {@link Node} which should be dragged * @param offsetX the x offset on the node where the drag gesture starts from * @param offsetY the y offset on the node where the drag gesture starts from * @param endX the x coordinate of the targeted location * @param endY the y coordinate of the targeted location */ public static void dragTo(final Node node, final double offsetX, final double offsetY, final double endX, final double endY) { final double startX = node.getLayoutX() + offsetX; final double startY = node.getLayoutY() + offsetY; final double dragX = startX + (endX - node.getLayoutX()); final double dragY = startY + (endY - node.getLayoutY()); final MouseEvent pressed = createMouseEvent(MouseEvent.MOUSE_PRESSED, startX, startY); final MouseEvent dragged = createMouseEvent(MouseEvent.MOUSE_DRAGGED, dragX, dragY); final MouseEvent released = createMouseEvent(MouseEvent.MOUSE_RELEASED, dragX, dragY); Event.fireEvent(node, pressed); Event.fireEvent(node, dragged); Event.fireEvent(node, released); }
Example 4
Source File: FileEditorTabPane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
boolean closeEditor(FileEditor fileEditor, boolean save) { if (fileEditor == null) return true; Tab tab = fileEditor.getTab(); if (save) { Event event = new Event(tab,tab,Tab.TAB_CLOSE_REQUEST_EVENT); Event.fireEvent(tab, event); if (event.isConsumed()) return false; } runWithoutSavingEditorsState(() -> { tabPane.getTabs().remove(tab); if (tab.getOnClosed() != null) Event.fireEvent(tab, new Event(Tab.CLOSED_EVENT)); }); saveEditorsState(); return true; }
Example 5
Source File: ProjectFolderResource.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void updated(Resource resource) { Path projectFilePath = super.getFilePath().resolve(ProjectFile.PROJECT_FILE); if (projectFilePath.equals(resource.getFilePath())) { setName(); Event.fireEvent(this, new TreeModificationEvent<Resource>(valueChangedEvent(), this, this)); } }
Example 6
Source File: TestTarget.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
@Test public void testLeftArrowKeyResizeTarget() { double oldWidth = pepperPopper.getDimension().getWidth(); double oldHeight = pepperPopper.getDimension().getHeight(); KeyEvent leftArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "left", "left", KeyCode.LEFT, true, false, false, false); Event.fireEvent(pepperPopper.getTargetGroup(), leftArrowEvent); assertEquals(oldWidth + TargetView.SCALE_DELTA, pepperPopper.getDimension().getWidth(), .001); assertEquals(oldHeight, pepperPopper.getDimension().getHeight(), .001); }
Example 7
Source File: ProjectFolderResource.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public Resource rename(String text) { try { ProjectFile.updateProjectProperty(Constants.PROP_PROJECT_NAME, text); name = text; Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.UPDATE, this)); } catch (IOException e) { e.printStackTrace(); } return this; }
Example 8
Source File: FolderResource.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public Optional<ButtonType> delete(Optional<ButtonType> option) { if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) { option = FXUIUtils.showConfirmDialog(null, "Do you want to delete the folder `" + path + "` and all its children?", "Confirm", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL); } if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) { if (Files.exists(path)) { try { File file = path.toFile(); File[] listFiles = file.listFiles(); option = Copy.delete(path, option); if (listFiles.length > 0) for (File f : listFiles) { Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, new FileResource(f))); } Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, this)); getParent().getChildren().remove(this); } catch (IOException e) { String message = String.format("Unable to delete: %s: %s%n", path, e); FXUIUtils.showMessageDialog(null, message, "Unable to delete", AlertType.ERROR); } } } return option; }
Example 9
Source File: FolderResource.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public Resource rename(String text) { try { Path moved = Files.move(path, path.resolveSibling(text)); FileResource to = new FileResource(moved.toFile()); Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.MOVED, this, to)); return to; } catch (IOException e) { FXUIUtils.showMessageDialog(null, "Unable to rename folder: " + e.getMessage(), e.getClass().getName(), AlertType.ERROR); return null; } }
Example 10
Source File: TestTarget.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
@Test public void testLeftArrowKeyMoveTarget() { double oldX = pepperPopper.getPosition().getX(); double oldY = pepperPopper.getPosition().getY(); KeyEvent leftArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "left", "left", KeyCode.LEFT, false, false, false, false); Event.fireEvent(pepperPopper.getTargetGroup(), leftArrowEvent); assertEquals(oldX - TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getX(), .001); assertEquals(oldY, pepperPopper.getPosition().getY(), .001); }
Example 11
Source File: EventRedirector.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
private void redirect(@NotNull final GestureEvent event) { final EventTarget target = event.getTarget(); if (target == destination) return; final FileEditor currentEditor = editorAreaComponent.getCurrentEditor(); if (currentEditor == null || !currentEditor.isInside(event.getSceneX(), event.getSceneY(), event.getClass())) { return; } Event.fireEvent(destination, event.copyFor(event.getSource(), destination)); }
Example 12
Source File: GroupResource.java From marathonv5 with Apache License 2.0 | 5 votes |
public void paste(int index, Clipboard clipboard, Operation operation) { if (!clipboard.hasFiles() || !type.droppable(clipboard.getFiles(), getFilePath())) { return; } List<File> files = clipboard.getFiles(); ObservableList<TreeItem<Resource>> cs = getChildren(); for (File file : files) { GroupEntry ge = null; try { if (Constants.isSuiteFile(file)) { ge = new GroupGroupEntry(GroupEntryType.SUITE, file.toPath().toString()); } else if (Constants.isFeatureFile(file)) { ge = new GroupGroupEntry(GroupEntryType.FEATURE, file.toPath().toString()); } else if (Constants.isStoryFile(file)) { ge = new GroupGroupEntry(GroupEntryType.STORY, file.toPath().toString()); } else if (Constants.isIssueFile(file)) { ge = new GroupGroupEntry(GroupEntryType.ISSUE, file.toPath().toString()); } else if (Constants.isTestFile(file)) { ge = getTestEntry(file); } } catch (IOException e) { e.printStackTrace(); continue; } cs.add(index, new GroupEntryResource(ge)); group.getEntries().add(index, ge); index++; } try { Group.updateFile(group); } catch (IOException e1) { e1.printStackTrace(); } Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.UPDATE, this)); return; }
Example 13
Source File: TestTarget.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
@Test public void testUpArrowKeyProportionalResizeTarget() { double oldWidth = pepperPopper.getDimension().getWidth(); double oldHeight = pepperPopper.getDimension().getHeight(); KeyEvent upArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "up", "up", KeyCode.UP, true, true, false, false); Event.fireEvent(pepperPopper.getTargetGroup(), upArrowEvent); assertEquals(oldWidth + (TargetView.SCALE_DELTA * (oldWidth / oldHeight)), pepperPopper.getDimension().getWidth(), .001); assertEquals(oldHeight + TargetView.SCALE_DELTA, pepperPopper.getDimension().getHeight(), .001); }
Example 14
Source File: TestTarget.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
@Test public void testRightArrowKeyMoveTarget() { double oldX = pepperPopper.getPosition().getX(); double oldY = pepperPopper.getPosition().getY(); KeyEvent rightArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "right", "right", KeyCode.RIGHT, false, false, false, false); Event.fireEvent(pepperPopper.getTargetGroup(), rightArrowEvent); assertEquals(oldX + TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getX(), .001); assertEquals(oldY, pepperPopper.getPosition().getY(), .001); }
Example 15
Source File: JFXDialog.java From JFoenix with Apache License 2.0 | 5 votes |
private void showDialog() { if (dialogContainer == null) { throw new RuntimeException("ERROR: JFXDialog container is not set!"); } if (isCacheContainer()) { tempContent = new ArrayList<>(dialogContainer.getChildren()); SnapshotParameters snapShotparams = new SnapshotParameters(); snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = dialogContainer.snapshot(snapShotparams, new WritableImage((int) dialogContainer.getWidth(), (int) dialogContainer.getHeight())); ImageView tempImage = new ImageView(temp); tempImage.setCache(true); tempImage.setCacheHint(CacheHint.SPEED); dialogContainer.getChildren().setAll(tempImage, this); } else { //prevent error if opening an already opened dialog dialogContainer.getChildren().remove(this); tempContent = null; dialogContainer.getChildren().add(this); } if (animation != null) { animation.play(); } else { setVisible(true); setOpacity(1); Event.fireEvent(JFXDialog.this, new JFXDialogEvent(JFXDialogEvent.OPENED)); } }
Example 16
Source File: TestTarget.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
@Test public void testDownArrowKeyMoveTarget() { double oldX = pepperPopper.getPosition().getX(); double oldY = pepperPopper.getPosition().getY(); KeyEvent downArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "down", "down", KeyCode.DOWN, false, false, false, false); Event.fireEvent(pepperPopper.getTargetGroup(), downArrowEvent); assertEquals(oldX, pepperPopper.getPosition().getX(), .001); assertEquals(oldY + TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getY(), .001); }
Example 17
Source File: DockTitleBar.java From DockFX with GNU Lesser General Public License v3.0 | 4 votes |
/** * Traverse the scene graph for all open stages and pick an event target for a dock event based on * the location. Once the event target is chosen run the event task with the target and the * previous target of the last dock event if one is cached. If an event target is not found fire * the explicit dock event on the stage root if one is provided. * * @param location The location of the dock event in screen coordinates. * @param eventTask The event task to be run when the event target is found. * @param explicit The explicit event to be fired on the stage root when no event target is found. */ private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) { // RFE for public scene graph traversal API filed but closed: // https://bugs.openjdk.java.net/browse/JDK-8133331 List<DockPane> dockPanes = DockPane.dockPanes; // fire the dock over event for the active stages for (DockPane dockPane : dockPanes) { Window window = dockPane.getScene().getWindow(); if (!(window instanceof Stage)) continue; Stage targetStage = (Stage) window; // obviously this title bar does not need to receive its own events // though users of this library may want to know when their // dock node is being dragged by subclassing it or attaching // an event listener in which case a new event can be defined or // this continue behavior can be removed if (targetStage == this.dockNode.getStage()) continue; eventTask.reset(); Node dragNode = dragNodes.get(targetStage); Parent root = targetStage.getScene().getRoot(); Stack<Parent> stack = new Stack<Parent>(); if (root.contains(root.screenToLocal(location.getX(), location.getY())) && !root.isMouseTransparent()) { stack.push(root); } // depth first traversal to find the deepest node or parent with no children // that intersects the point of interest while (!stack.isEmpty()) { Parent parent = stack.pop(); // if this parent contains the mouse click in screen coordinates in its local bounds // then traverse its children boolean notFired = true; for (Node node : parent.getChildrenUnmodifiable()) { if (node.contains(node.screenToLocal(location.getX(), location.getY())) && !node.isMouseTransparent()) { if (node instanceof Parent) { stack.push((Parent) node); } else { eventTask.run(node, dragNode); } notFired = false; break; } } // if none of the children fired the event or there were no children // fire it with the parent as the target to receive the event if (notFired) { eventTask.run(parent, dragNode); } } if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) { Event.fireEvent(dragNode, explicit.copyFor(this, dragNode)); dragNodes.put(targetStage, null); } } }
Example 18
Source File: FolderResource.java From marathonv5 with Apache License 2.0 | 4 votes |
@Override public void pasteInto(Clipboard clipboard, Operation operation) { if (clipboard.hasFiles()) { List<File> files = clipboard.getFiles(); List<Path> paths = new ArrayList<>(); for (File file : files) { paths.add(file.toPath().toAbsolutePath()); } Collections.sort(paths); Path lastCopiedPath = null; for (Path path : paths) { try { if (lastCopiedPath == null || !path.startsWith(lastCopiedPath)) { Path newPath = Copy.copy(path, this.path, operation); if (newPath == null) { continue; } Resource to; if (Files.isDirectory(newPath)) { to = new FolderResource(newPath.toFile(), watcher); } else { to = new FileResource(newPath.toFile()); } lastCopiedPath = path; Resource from; if (path.toFile().isDirectory()) { from = new FolderResource(path.toFile(), watcher); } else { from = new FileResource(path.toFile()); } Event.fireEvent(this, new ResourceView.ResourceModificationEvent( operation == Operation.CUT ? ResourceModificationEvent.MOVED : ResourceModificationEvent.COPIED, from, to)); } } catch (IOException e) { FXUIUtils.showMessageDialog(null, "Error in copying files.", e.getMessage(), AlertType.ERROR); } } } Platform.runLater(() -> refresh()); }
Example 19
Source File: MainWindow.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 4 votes |
private void fileExit() { Window window = scene.getWindow(); Event.fireEvent(window, new WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST)); }
Example 20
Source File: AutoCompletePopupSkin2.java From BlockMap with MIT License | 4 votes |
private void onSuggestionChoosen(T suggestion) { if (suggestion != null) { Event.fireEvent(control, new AutoCompletePopup.SuggestionEvent<>(suggestion)); } }