@FXML void initialize() { // Create ContextMenu settingsMenuItm.setOnAction(e -> { settings.showWindow(); }); chngBckgrndMenuItem.setOnAction(e -> { settings.callBackgroundMngr(); }); // Add MenuItem to ContextMenu contextMenu.getItems().addAll(settingsMenuItm, chngBckgrndMenuItem); // When user right-click on desktop desktopArea.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() { @Override public void handle(ContextMenuEvent event) { contextMenu.show(desktopArea, event.getScreenX(), event.getScreenY()); } }); settings.setsettingsImgView(backgroundImgView); backgroundImgView.setImage(settings.getBackgroundInfo()); backgroundImgView.setFitWidth(1920); // Scale to view Note: need to do based on system parameters backgroundImgView.setFitHeight(1080); addIconTiles(); }
/** * Creates a new viewer instance. * * @param chart the chart ({@code null} permitted). * @param contextMenuEnabled enable the context menu? */ public ChartViewer(JFreeChart chart, boolean contextMenuEnabled) { this.canvas = new ChartCanvas(chart); this.canvas.setTooltipEnabled(true); this.canvas.addMouseHandler(new ZoomHandlerFX("zoom", this)); setFocusTraversable(true); getChildren().add(this.canvas); this.zoomRectangle = new Rectangle(0, 0, new Color(0, 0, 1, 0.25)); this.zoomRectangle.setManaged(false); this.zoomRectangle.setVisible(false); getChildren().add(this.zoomRectangle); this.contextMenu = createContextMenu(); setOnContextMenuRequested((ContextMenuEvent event) -> { contextMenu.show(ChartViewer.this.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); this.contextMenu.setOnShowing( e -> ChartViewer.this.getCanvas().setTooltipEnabled(false)); this.contextMenu.setOnHiding( e -> ChartViewer.this.getCanvas().setTooltipEnabled(true)); }
private ConsolePane createConsole() { ConsolePane console = new ConsolePane(); ContextMenu contextMenu = new ContextMenu(); MenuItem clearConsoleItem = new MenuItem("Clear"); clearConsoleItem.setOnAction(e -> console.clear()); contextMenu.getItems().add(clearConsoleItem); console.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> { contextMenu.show(console, event.getScreenX(), event.getScreenY()); event.consume(); }); console.setOnMouseClicked(event -> { if (event.getButton() == MouseButton.PRIMARY) contextMenu.hide(); }); return console; }
/** * Constructs a new month sheet view that is using the {@link SimpleDateCell}. */ public MonthSheetView() { getStyleClass().add(DEFAULT_STYLE_CLASS); setHeaderCellFactory(param -> new MonthHeaderCell(param.getView(), param.getYearMonth())); /* * This view has its own context menu. */ setContextMenu(createContextMenu()); addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, evt -> { final PickResult pickResult = evt.getPickResult(); final Node intersectedNode = pickResult.getIntersectedNode(); if (intersectedNode != null && intersectedNode instanceof DateCell) { this.dateCell = (DateCell) intersectedNode; } else { this.dateCell = null; } ctxMenuScreenX = evt.getScreenX(); ctxMenuScreenY = evt.getScreenY(); }); // Set the factory AFTER the context menu has been created or the cell factory // will be overridden again. setCellFactory(param -> new SimpleDateCell(param.getView(), param.getDate())); }
/******************************** * 작성일 : 2016. 6. 11. 작성자 : KYJ * * 트리 컨텍스트 요청 이벤트 * * @param event ********************************/ public void treeProjectFileOnContextMenuRequested(ContextMenuEvent event) { if (event.getSource() == treeProjectFile) { fileTreeContextMenu.hide(); TreeItem<JavaProjectFileWrapper> selectedItem = treeProjectFile.getSelectionModel().getSelectedItem(); if (selectedItem == null) return; tmpSelectFileWrapper = selectedItem.getValue(); fileTreeContextMenu.show(treeProjectFile, event.getScreenX(), event.getScreenY()); } else { fileTreeContextMenu.hide(); } }
@Override public void handle(ContextMenuEvent event) { GUIState guiState = mainController.getGUIController().getGuiState(); if (!(event.getSource() instanceof Rectangle) || !((Rectangle) event.getSource()).isFocusOutline()) { if (event.getSource() instanceof Node) { guiState.setSelectedObject((Node) event.getSource()); } FocusOutline focusOutline = guiState.getFocusOutline(); Rectangle focusRectangle = focusOutline.getFocusRectangle(); focusRectangle.fireEvent(event); } contextMenu.show(guiState.getSelectedObject(), event.getScreenX(), event.getScreenY()); }
@Test public void shouldHideAndShowSingleInstance() { when( menu.friendly_isShowing() ).thenReturn( false, true, false, true ); ContextMenuEvent event = new ContextMenuEvent( null, -1, -1, 0, 0, false, null ); systemUnderTest.handle( event ); verify( menu ).resetMenuOptions(); verify( menu, times( 1 ) ).friendly_show( Mockito.any(), Mockito.anyDouble(), Mockito.anyDouble() ); systemUnderTest.handle( event ); systemUnderTest.handle( event ); verify( menu, times( 2 ) ).resetMenuOptions(); verify( menu, times( 2 ) ).friendly_show( Mockito.any(), Mockito.anyDouble(), Mockito.anyDouble() ); systemUnderTest.handle( event ); verify( menu, times( 2 ) ).resetMenuOptions(); verify( menu, times( 2 ) ).friendly_show( Mockito.any(), Mockito.anyDouble(), Mockito.anyDouble() ); }
private void createPaneContextMenu(ContextMenuEvent e) { MenuItem clear = FxUtils.menuItem("Clear", __ -> { List<Tile> tiles = new ArrayList<>(pane.getTiles()); tiles.stream() .map((Function<Tile, Component>) pane::removeTile) .flatMap(Component::allComponents) .flatMap(TypeUtils.castStream(Sourced.class)) .forEach(Sourced::removeAllSources); }); ContextMenu contextMenu = new ContextMenu(clear); contextMenu.show(pane.getScene().getWindow(), e.getScreenX(), e.getScreenY()); }
/** * Creates the context menu for a given tile. */ private ContextMenu createContextMenu(ContextMenuEvent event) { ContextMenu menu = new ContextMenu(); LinkedHashMap<String, List<MenuItem>> actions = new LinkedHashMap<>(); if (event.getTarget() instanceof Node) { Node leaf = (Node) event.getTarget(); Stream .iterate(leaf, Node::getParent) // non-functional ugliness necessary due to the lack of takeWhile in java 8 .peek(node -> ActionList.actionsForNode(node).ifPresent(al -> { if (actions.containsKey(al.getName())) { actions.get(al.getName()).addAll(al.toMenuItems()); } else { actions.put(al.getName(), al.toMenuItems()); } })) .allMatch(n -> n.getParent() != null); // terminates infinite Stream#iterate } actions.forEach((key, menuItems) -> { menu.getItems().add(new SeparatorMenuItem()); menu.getItems().add(FxUtils.menuLabel(key)); menu.getItems().addAll(menuItems); }); // remove leading separator. menu.getItems().remove(0); return menu; }
public UICanvasEditor(@NotNull Resolution resolution, @NotNull UICanvasConfiguration configuration, @NotNull CanvasDisplay<? extends CanvasControl> display) { super(resolution, display); setConfig(configuration); gc.setTextBaseline(VPos.CENTER); this.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() { @Override public void handle(ContextMenuEvent event) { if (contextMenu != null) { Point2D p = getCanvas().localToScreen(contextMenuPosition.getX(), contextMenuPosition.getY()); contextMenu.show(getCanvas(), p.getX(), p.getY()); } } }); absRegionComponent = new ArmaAbsoluteBoxComponent(resolution); selection.selected.addListener(new ListChangeListener<CanvasControl>() { @Override public void onChanged(Change<? extends CanvasControl> c) { requestPaint(); } }); getTimer().getRunnables().add(new Runnable() { @Override public void run() { prepaint(); } }); initializeSelectionEffect(); }
/** * {@inheritDoc} */ @Override public void handle( ContextMenuEvent event ) { if ( contextMenu.friendly_isShowing() ) { return; } contextMenu.friendly_show( display, event.getScreenX(), event.getScreenY() ); }
/** * {@inheritDoc} */ @Override public void handle( ContextMenuEvent event ) { if ( contextMenu.friendly_isShowing() ) return; contextMenu.resetMenuOptions(); contextMenu.friendly_show( display, event.getScreenX(), event.getScreenY() ); }
@Test public void shouldNotShowIfAlreadyShowing(){ when( menu.friendly_isShowing() ).thenReturn( true ); final double x = 394857.234; final double y = 2387.938; ContextMenuEvent event = new ContextMenuEvent( null, -1, -1, x, y, false, null ); systemUnderTest.handle( event ); verify( menu, never() ).friendly_show( Mockito.any(), Mockito.anyDouble(), Mockito.anyDouble() ); }
@Test public void shouldShowIfNotShowing(){ when( menu.friendly_isShowing() ).thenReturn( false ); final double x = 394857.234; final double y = 2387.938; ContextMenuEvent event = new ContextMenuEvent( null, -1, -1, x, y, false, null ); systemUnderTest.handle( event ); verify( menu ).friendly_show( display, x, y ); }
@Ignore @Test public void menuStressing() throws InterruptedException { DecoupledPlatformImpl.setInstance( new PlatformDecouplerImpl() ); TestApplication.launch( () -> { systemUnderTest.setOnContextMenuRequested( new DualBuildWallContextMenuOpener( systemUnderTest ) ); return systemUnderTest; } ); Random random = new Random(); for ( int i = 0; i < 100000; i++ ) { EventHandler< ? super ContextMenuEvent > conextHandler = systemUnderTest.onContextMenuRequestedProperty().get(); } Thread.sleep( 10000000 ); }
@Test public void shouldPositionMenuAtMouseLocation() { final double x = 394857.234; final double y = 2387.938; ContextMenuEvent event = new ContextMenuEvent( null, -1, -1, x, y, false, null ); systemUnderTest.handle( event ); verify( menu ).resetMenuOptions(); verify( menu ).friendly_show( display, x, y ); }
@Test public void cancelShouldHideWhenUsingHeavySetup() throws InterruptedException{ fullLaunch(); PlatformImpl.runAndWait( () -> { opener.handle( new ContextMenuEvent( null, 0, 0, 0, 0, false, null ) ); } ); assertThat( systemUnderTest.friendly_isShowing(), is( true ) ); PlatformImpl.runAndWait( () -> { retrieveMenuItem( CANCEL ).getOnAction().handle( new ActionEvent() ); } ); assertThat( systemUnderTest.friendly_isShowing(), is( false ) ); }
/** * Context menu requested action. * * @param event * the event */ @FXML public void contextMenuRequested(ContextMenuEvent event) { Node node = event.getPickResult().getIntersectedNode(); if (node == flowPane) { viewContextMenu.show(node, event.getScreenX(), event.getScreenY()); } else if (node instanceof BorderPane) { fileContextMenu.show(node, event.getScreenX(), event.getScreenY()); } }
private void showContextMenu(ContextMenuEvent e) { ContextMenu menu = view.getContextMenu(); double xOffset = view.getContextMenuXOffset(); double yOffset = view.getContextMenuYOffset(); menu.show(view, e.getScreenX() + xOffset, e.getScreenY() + yOffset); }
@Override public void onRequestContext(final ContextMenuEvent event, final TreeItemIcon<String> source) { System.out.println(source + " -> context"); }
public void onRequestContext(final ContextMenuEvent event) { TreeItemIcon<String> source = (TreeItemIcon<String>) this.getTree().getSelectionModel().getSelectedItem(); this.onRequestContext(event, source); }
public ContextMenuParameterBase(ContextMenuEvent contextMenuEvent, DateControl dateControl) { this.contextMenuEvent = requireNonNull(contextMenuEvent); this.dateControl = requireNonNull(dateControl); }
public ContextMenuEvent getContextMenuEvent() { return contextMenuEvent; }
private void onTableContextMenu(ContextMenuEvent event) { tableListView.getSelectedTable() .ifPresent(table -> tableContext.show(this, event.getScreenX(), event.getScreenY())); }
protected ContextMenuEvent getContextMenuEvent(Object source) { return new ContextMenuEvent(source, null, ContextMenuEvent.CONTEXT_MENU_REQUESTED, 0, 0, 0, 0, false, null); }
@Override public void addHandleContextMenu(EventHandler<ContextMenuEvent> event) { contextMenuEvents.add(event); }
@Override public void handleContextMenu(ContextMenuEvent event) { for (EventHandler<ContextMenuEvent> h : contextMenuEvents) { h.handle(event); } }
private void initialize() { this.getStyleClass().add(DEFAULT_STYLE_CLASS); expanded.addListener((o, oldVal, newVal) -> { if (newVal) { expand(); } else { collapse(); } }); verticalGap.addListener((o, oldVal, newVal) -> { if (isExpanded()) { expand(); } else { collapse(); } }); // handle selection model on the list ( FOR NOW : we only support single selection on the list if it contains sublists) sublistsProperty.get().addListener((ListChangeListener.Change<? extends JFXListView<?>> c) -> { while (c.next()) { if (c.wasAdded() || c.wasUpdated() || c.wasReplaced()) { if (sublistsProperty.get().size() == 1) { this.getSelectionModel() .selectedItemProperty() .addListener((o, oldVal, newVal) -> clearSelection(this)); // prevent selecting the sublist item by clicking the right mouse button this.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume); } c.getAddedSubList() .forEach(item -> item.getSelectionModel() .selectedItemProperty() .addListener((o, oldVal, newVal) -> clearSelection(item))); } } }); // listen to index changes this.getSelectionModel().selectedIndexProperty().addListener((o, oldVal, newVal) -> { if (newVal.intValue() != -1) { updateOverAllSelectedIndex(); } }); }
private MenuHints getHints() { Optional<ContextMenuEvent> event = Optional.ofNullable(lastContextMenuClick.get()); return new MenuHints(event.map(e -> new Point2D(e.getX(), e.getY()))); }
/** * Constructs a new context menu parameter object. * * @param evt the event that triggered the context menu * @param control the date control where the event occurred * @param entryView the entry view for which the context menu will be created */ public EntryContextMenuParameter(ContextMenuEvent evt, DateControl control, EntryViewBase<?> entryView) { super(evt, control); this.entryView = requireNonNull(entryView); }
/** * Constructs a new parameter object. * * @param evt the event that triggered the context menu * @param dateControl the date control where the event occurred * @param calendar the (default) calendar where newly created entries should * be added * @param time the time where the mouse click occurred */ public ContextMenuParameter(ContextMenuEvent evt, DateControl dateControl, Calendar calendar, ZonedDateTime time) { super(evt, dateControl); this.calendar = requireNonNull(calendar); this.zonedDateTime = time; }
@Override public void handleContextMenu(ContextMenuEvent event) { }
public abstract void onRequestContext(ContextMenuEvent event, TreeItemIcon<String> source);
void handleContextMenu(ContextMenuEvent event);
void addHandleContextMenu(EventHandler<ContextMenuEvent> event);