本文整理汇总了Java中javafx.scene.control.ContextMenu.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java ContextMenu.getItems方法的具体用法?Java ContextMenu.getItems怎么用?Java ContextMenu.getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.getItems方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateMenuItems
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
private void populateMenuItems(ContextMenu contextMenu, Tab tab) {
int tabCount = getTabs().size();
int tabIndex = getTabs().indexOf(tab);
ObservableList<MenuItem> items = contextMenu.getItems();
items.clear();
MenuItem closeMenuItem = new MenuItem("Close");
closeMenuItem.setOnAction((e) -> requestClose(tab));
items.add(closeMenuItem);
if (tabCount > 1) {
MenuItem closeRestMenuItem = new MenuItem("Close Others");
closeRestMenuItem.setOnAction((e) -> closeOtherTabs(tab));
items.add(closeRestMenuItem);
}
if (tabCount > 1 && tabIndex != 0) {
MenuItem closeLeftTabsMenuItem = new MenuItem("Close Tabs to the Left");
closeLeftTabsMenuItem.setOnAction((e) -> closeTabsToLeft(tab));
items.add(closeLeftTabsMenuItem);
}
if (tabCount > 1 && tabIndex != tabCount - 1) {
MenuItem closeRigthTabsMenuItem = new MenuItem("Close Tabs to the Right");
closeRigthTabsMenuItem.setOnAction((e) -> closeTabsToRight(tab));
items.add(closeRigthTabsMenuItem);
}
if (tabCount > 1) {
MenuItem closeAllMenuItem = new MenuItem("Close All");
closeAllMenuItem.setOnAction((e) -> closeAllTabs());
items.addAll(new SeparatorMenuItem(), closeAllMenuItem);
}
}
示例2: installBookmark
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
/**
* @param chrome the browser chrome the bookmark is to control.
* @param bookmarksMenu the menu into which the bookmark is to be installed.
* @param bookmarkName the name of the bookmark.
* @param bookmarkUrl the url of the bookmark.
*
* @return true if the bookmark was not already installed in the chrome, otherwise false.
*/
public static boolean installBookmark(
final Willow chrome,
final ContextMenu bookmarksMenu,
final String bookmarkName,
final String bookmarkUrl
) {
for (MenuItem item : bookmarksMenu.getItems()) {
if (item.getText().equals(bookmarkName)) {
return false;
}
}
final MenuItem menuItem = new MenuItem(bookmarkName);
menuItem.setOnAction(actionEvent -> chrome.getBrowser().navTo(bookmarkUrl));
bookmarksMenu.getItems().add(menuItem);
return true;
}
示例3: eventTriggerOnIssueSelection_byRightClick_selectionEventNotTriggered
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
@Test
public void eventTriggerOnIssueSelection_byRightClick_selectionEventNotTriggered() {
AtomicInteger eventCount = new AtomicInteger(0);
UI.events.registerEvent((IssueSelectedEventHandler) e -> eventCount.incrementAndGet());
ListPanel issuePanel = getPanel(0);
//testing whether right click occurred by checking the presence of context menu items
rightClickIssue(0, 9);
ContextMenu contextMenu = issuePanel.getContextMenu();
for (MenuItem menuItem : contextMenu.getItems()) {
assertTrue(!menuItem.isDisable());
}
// testing IssueSelectedEvent not registered on right click
assertEquals(0, eventCount.get());
}
示例4: clickAndMarkIssuesBelow
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
/**
* Marks issues in the panel from Issue index in the UI right to the end of the list as read/unread
*
* @param isMarkAsRead If true, marks the selected issue and below as read
* If false, marks the selected issue and below as unread
* @param index The issue number in the panel
*/
private void clickAndMarkIssuesBelow(ListPanel issuePanel, int index, boolean isMarkAsRead) {
clickIssue(0, index);
rightClickIssue(0, index);
ContextMenu contextMenu = issuePanel.getContextMenu();
for (MenuItem menuItem : contextMenu.getItems()) {
awaitCondition(menuItem::isVisible);
}
if (isMarkAsRead){
clickMenuItem(contextMenu, ListPanel.MARK_ALL_AS_READ_MENU_ITEM_TEXT);
} else {
clickMenuItem(contextMenu, ListPanel.MARK_ALL_AS_UNREAD_MENU_ITEM_TEXT);
}
sleep(EVENT_DELAY);
}
示例5: installBookmark
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
/**
* @param chrome the browser chrome the bookmark is to control.
* @param bookmarksMenu the menu into which the bookmark is to be installed.
* @param bookmarkName the name of the bookmark.
* @param bookmarkUrl the url of the bookmark.
*
* @return true if the bookmark was not already installed in the chrome, otherwise false.
*/
public static boolean installBookmark(
final WebBrowser chrome,
final ContextMenu bookmarksMenu,
final String bookmarkName,
final String bookmarkUrl
) {
for (MenuItem item : bookmarksMenu.getItems()) {
if (item.getText().equals(bookmarkName)) {
return false;
}
}
final MenuItem menuItem = new MenuItem(bookmarkName);
menuItem.setOnAction(actionEvent -> chrome.getBrowser().go(bookmarkUrl));
bookmarksMenu.getItems().add(menuItem);
return true;
}
示例6: createContextMenu
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
private ContextMenu createContextMenu() {
final ContextMenu contextMenu = new ContextMenu();
final ObservableList<MenuItem> menuItems = contextMenu.getItems();
menuItems.add(createMenuAdd());
menuItems.add(createMenuDelete());
menuItems.add(createMenuRename());
menuItems.add(new SeparatorMenuItem());
menuItems.add(new MenuItem("Cancel"));
return contextMenu;
}
示例7: setSubItemBehavior
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
public static void setSubItemBehavior(final ContextMenu contextMenu, final Tab tab)
{
for (final MenuItem menus : contextMenu.getItems())
menus.setOnAction((final ActionEvent e) ->
{
final MenuItem item = (MenuItem) e.getSource();
switch (item.getId())
{
case "close":
closeTab(tab);
break;
case "close_other":
int index = 0;
while (tab.getTabPane().getTabs().size() != 1)
{
if (tab.getTabPane().getTabs().get(index).getId().equals(tab.getId()))
index = 1;
tab.getTabPane().getTabs().remove(index);
}
break;
case "close_left":
while (tab.getTabPane().getTabs().indexOf(tab) != 0)
tab.getTabPane().getTabs().remove(0);
break;
case "close_right":
while (tab.getTabPane().getTabs().indexOf(tab) != tab.getTabPane().getTabs().size() - 1)
tab.getTabPane().getTabs().remove(tab.getTabPane().getTabs().size() - 1);
break;
case "close_all":
closeAllWindows(tab.getTabPane());
break;
default:
// do nothing
break;
}
});
}
示例8: createContextMenu
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
private ContextMenu createContextMenu() {
final ContextMenu contextMenu = new ContextMenu();
final ObservableList<MenuItem> menuItems = contextMenu.getItems();
menuItems.add(createMenuAdd());
menuItems.add(createMenuDelete());
menuItems.add(new SeparatorMenuItem());
menuItems.add(new MenuItem("Cancel"));
return contextMenu;
}
示例9: finalize
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
@Override
protected void finalize() throws Throwable
{
// Help deal with javafx memory leaks
styleProperty().unbind();
ContextMenu cm = getContextMenu();
if (cm != null)
{
for (MenuItem mi : cm.getItems())
{
mi.visibleProperty().unbind();
}
}
super.finalize();
}
示例10: removeTabs
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
private void removeTabs(List<? extends DockTab> removedList) {
for (final DockTab tab : removedList) {
stopCurrentAnimation(tab);
// Animate the tab removal
final TabHeaderSkin tabRegion = tabHeaderArea.getTabHeaderSkin(tab);
if (tabRegion != null) {
tabRegion.isClosing = true;
tabRegion.removeListeners(tab);
removeTabContent(tab);
// remove the menu item from the popup menu
ContextMenu popupMenu = tabHeaderArea.controlButtons.popup;
TabMenuItem tabItem = null;
if (popupMenu != null) {
for (MenuItem item : popupMenu.getItems()) {
tabItem = (TabMenuItem) item;
if (tab == tabItem.getTab()) {
break;
}
tabItem = null;
}
}
if (tabItem != null) {
tabItem.dispose();
popupMenu.getItems().remove(tabItem);
}
// end of removing menu item
EventHandler<ActionEvent> cleanup = ae -> {
tabRegion.animationState = TabAnimationState.NONE;
tabHeaderArea.removeTab(tab);
tabHeaderArea.requestLayout();
if (getSkinnable().getTabs().isEmpty()) {
tabHeaderArea.setVisible(false);
}
};
if (closeTabAnimation.get() == TabAnimation.GROW) {
tabRegion.animationState = TabAnimationState.HIDING;
Timeline closedTabTimeline = tabRegion.currentAnimation = createTimeline(tabRegion, Duration.millis(ANIMATION_SPEED),
0.0F, cleanup);
closedTabTimeline.play();
} else {
cleanup.handle(null);
}
}
}
}
示例11: SqlTab
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
/**
*
*/
public SqlTab(EventHandler<KeyEvent> excutable) {
this();
setText(NEW_TAB);
SqlKeywords createNewSqlPane = createNewSqlPane();
sqlPane.set(createNewSqlPane);
setContent(createNewSqlPane);
// content.setOnKeyPressed(excutable);
createNewSqlPane.addEventHandler(KeyEvent.KEY_RELEASED, excutable);
EventDispatcher eventDispatcher = createNewSqlPane.getEventDispatcher();
createNewSqlPane.setEventDispatcher((event, tail) -> {
EventType<? extends Event> eventType = event.getEventType();
if (eventType == KeyEvent.KEY_PRESSED) {
tail.append(keyEventDispatcher);
tail.append(eventDispatcher);
}
Event dispatchEvent = eventDispatcher.dispatchEvent(event, tail);
return dispatchEvent;
});
/***************************************************************************************************************************/
/* 컨텍스트 메뉴 추가. */
ContextMenu contextMenu = createNewSqlPane.getCodeArea().getContextMenu();
ObservableList<MenuItem> items = contextMenu.getItems();
MenuItem muOpen = new MenuItem("Open");
muOpen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
muOpen.setOnAction(this::miOenOnAction);
items.add(0, muOpen);
MenuItem muSave = new MenuItem("Save");
muSave.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN));
muSave.setOnAction(this::muSaveOnAction);
items.add(1, muSave);
/***************************************************************************************************************************/
}
示例12: addCommonMenus
import javafx.scene.control.ContextMenu; //导入方法依赖的package包/类
public static void addCommonMenus(
ContextMenu existingMenu,
CommonMenuBuilderI passedBuilder,
CommonMenusDataProvider dataProvider,
CommonMenusNIdProvider tmpNids,
CommonMenusTaskIdProvider tmpTaskIds)
{
CommonMenuBuilder builder = null;
if (passedBuilder == null) {
builder = new CommonMenuBuilder();
} else if (! (passedBuilder instanceof CommonMenuBuilder)) {
builder = new CommonMenuBuilder(passedBuilder);
} else {
builder = (CommonMenuBuilder)passedBuilder;
}
CommonMenusDataProvider dataProviderLocal = (dataProvider == null ? new CommonMenusDataProvider() {} : dataProvider);
if (tmpNids == null) {
tmpNids = CommonMenusNIdProvider.getEmptyCommonMenusNIdProvider();
}
CommonMenusNIdProvider nids = tmpNids;
if (tmpTaskIds == null) {
tmpTaskIds = CommonMenusTaskIdProvider.getEmptyCommonMenusTaskIdProvider();
}
CommonMenusTaskIdProvider taskIds = tmpTaskIds;
//Check the nid provider just before each display of the menu - and see if we have a nid or not.
//If we don't have a nid, set the observable flag to false, so all of the menus that care, go invisible.
//else, set to true, to menus that care about nids will be visible.
existingMenu.setOnShowing((windowEvent) ->
{
taskIds.invalidateAll();
nids.invalidateAll();
dataProviderLocal.invalidateAll();
});
List<MenuItem> menuItems = getCommonMenus(builder, dataProviderLocal, nids, taskIds);
if (menuItems.size() > 0) {
for (MenuItem newItem : menuItems) {
MenuItem existingMatch = null;
for (MenuItem existingItem : existingMenu.getItems()) {
if (existingItem.getText().equals(newItem.getText())) {
existingMatch = existingItem;
break;
}
}
switch (builder.getMergeMode()) {
case ADD_TO_EXISTING:
if (existingMatch != null) {
Log.debug("Adding MenuItem with same name as existing MenuItem \"" + existingMatch.getText() + "\"");
}
existingMenu.getItems().add(newItem);
break;
case REPLACE_EXISTING:
if (existingMatch != null) {
Log.debug("Removing and replacing existing MenuItem \"" + existingMatch.getText() + "\"");
existingMenu.getItems().remove(existingMatch);
}
existingMenu.getItems().add(newItem);
break;
case USE_EXISTING:
if (existingMatch == null) {
existingMenu.getItems().add(newItem);
} else {
Log.debug("Not adding MenuItem with same name as existing MenuItem \"" + existingMatch.getText() + "\"");
}
break;
default:
throw new RuntimeException("Unsupported enum value " + builder.getMergeMode() + " for " + MergeMode.class.getName());
}
}
}
}