本文整理汇总了Java中javafx.scene.input.ContextMenuEvent类的典型用法代码示例。如果您正苦于以下问题:Java ContextMenuEvent类的具体用法?Java ContextMenuEvent怎么用?Java ContextMenuEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextMenuEvent类属于javafx.scene.input包,在下文中一共展示了ContextMenuEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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();
}
示例2: ChartViewer
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/**
* 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));
}
示例3: createConsole
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
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;
}
示例4: MonthSheetView
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/**
* 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()));
}
示例5: treeProjectFileOnContextMenuRequested
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/********************************
* 작성일 : 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();
}
}
示例6: handle
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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());
}
示例7: shouldHideAndShowSingleInstance
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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() );
}
示例8: createPaneContextMenu
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
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());
}
示例9: createContextMenu
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/**
* 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;
}
示例10: UICanvasEditor
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
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();
}
示例11: handle
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override public void handle( ContextMenuEvent event ) {
if ( contextMenu.friendly_isShowing() ) {
return;
}
contextMenu.friendly_show( display, event.getScreenX(), event.getScreenY() );
}
示例12: handle
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override public void handle( ContextMenuEvent event ) {
if ( contextMenu.friendly_isShowing() ) return;
contextMenu.resetMenuOptions();
contextMenu.friendly_show( display, event.getScreenX(), event.getScreenY() );
}
示例13: shouldNotShowIfAlreadyShowing
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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() );
}
示例14: shouldShowIfNotShowing
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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 );
}
示例15: menuStressing
import javafx.scene.input.ContextMenuEvent; //导入依赖的package包/类
@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 );
}