本文整理汇总了Java中org.eclipse.swt.widgets.MenuItem类的典型用法代码示例。如果您正苦于以下问题:Java MenuItem类的具体用法?Java MenuItem怎么用?Java MenuItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuItem类属于org.eclipse.swt.widgets包,在下文中一共展示了MenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildContextMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private void buildContextMenu(MouseEvent e) {
Point point = new Point(e.x, e.y);
TreeItem treeItem = getTree().getItem(point);
Menu menu = new Menu((Control)e.getSource());
Iterator<MenuMaker> i = menuMakers.iterator();
int cpt = 0;
while(i.hasNext()) {
i.next().makeMenu(this, treeItem, e, menu);
if (i.hasNext() && menu.getItemCount() != cpt) {
new MenuItem(menu, SWT.SEPARATOR);
cpt = menu.getItemCount();
}
}
if (menu.getItemCount() > 0) {
menu.setVisible(true);
} else {
menu.dispose();
}
}
示例2: DropDownSelectionListener
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
/**
* Construct the DropDownSelectionListener with the specific menu to be used.
*/
public DropDownSelectionListener(Menu menu) {
this.menu = menu;
MenuItem[] menuItems = menu.getItems();
for (int i=0; i<menuItems.length; i++) {
/*
* Add a menu selection listener so that the menu is hidden
* when the user selects an item from the drop down menu.
*/
menuItems[i].addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setMenuVisible(false);
}
});
}
}
示例3: showPreferenceDialogMAC
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private SWTBotShell showPreferenceDialogMAC() {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
Menu appMenu = workbench.getDisplay().getSystemMenu();
for (MenuItem item : appMenu.getItems()) {
if (item.getText().startsWith("Preferences")) {
Event event = new Event();
event.time = (int) System.currentTimeMillis();
event.widget = item;
event.display = workbench.getDisplay();
item.setSelection(true);
item.notifyListeners(SWT.Selection, event);
break;
}
}
}
}
});
return getPreferenceDialog() ;
}
示例4: addCopyToClipMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
public static void
addCopyToClipMenu(
final Menu menu,
final String text )
{
MenuItem item = new MenuItem( menu,SWT.NONE );
String msg_text_id= "label.copy.to.clipboard";
item.setText( MessageText.getString( msg_text_id ));
item.addSelectionListener(
new SelectionAdapter()
{
@Override
public void
widgetSelected(
SelectionEvent arg0)
{
new Clipboard(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
}
});
}
示例5: openPopupMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
protected void openPopupMenu(NodeType[] availableTypes, final AvroNode targetNode, final AvroContext context) {
Shell shell = Display.getCurrent().getActiveShell();
final Menu menu = new Menu(shell, SWT.POP_UP);
for (NodeType availableType : availableTypes) {
final NodeType type = availableType;
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(type.getDisplayLabel());
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
menu.dispose();
IEditCommand cmd = context.getService(IEditCommandFactory.class)
.createAddElementCommand(targetNode, type, getNotifications());
context.getService(ICommandExecutor.class).execute(cmd);
}
});
}
Point location = MouseInfo.getPointerInfo().getLocation();
int x = location.x;
int y = location.y;
menu.setLocation(x, y);
menu.setVisible(true);
}
示例6: widgetSelected
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
public void widgetSelected(SelectionEvent event) {
System.out.println("You selected " + ((MenuItem) event.widget).getText());
System.out.println("You selected cont.1 " + EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText()));
// System.out.println("You selected cont.2 " + EnumUtils.indexOf(EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText())));
//Storage.getInstance().getTranscriptMetadata().setStatus(EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText()));
// Storage.getInstance().saveTranscript(Storage.getInstance().getCurrentDocumentCollectionId(), null);
// Storage.getInstance().setLatestTranscriptAsCurrent();
/*
* change status:
*/
String tmp = ((MenuItem) event.widget).getText();
changeVersionStatus(tmp);
gallery.redraw();
gallery.deselectAll();
}
示例7: createNewWorkItemMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private Menu createNewWorkItemMenu(final Shell shell, final TeamExplorerContext context) {
final WorkItemClient client = context.getServer().getConnection().getWorkItemClient();
final Project project = client.getProjects().get(context.getCurrentProjectInfo().getName());
final Menu menu = new Menu(shell, SWT.POP_UP);
for (final WorkItemType workItemType : project.getVisibleWorkItemTypes()) {
final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText(workItemType.getName());
menuItem.setData(workItemType);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
final WorkItem workItem = client.newWorkItem(workItemType);
WorkItemEditorHelper.openEditor(context.getServer(), workItem);
}
});
}
return menu;
}
示例8: getSubActionMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
protected Menu getSubActionMenu(final Control parent) {
if (subActionMenu != null) {
return subActionMenu;
}
subActionMenu = new Menu(parent);
for (final Iterator<IAction> it = subActions.iterator(); it.hasNext();) {
final IAction subAction = it.next();
final ActionContributionItem aci = new ActionContributionItem(subAction);
aci.fill(subActionMenu, -1);
final MenuItem menuItem = subActionMenu.getItem(subActionMenu.getItemCount() - 1);
menuItem.addSelectionListener(menuItemSelectionListener);
}
return subActionMenu;
}
示例9: click
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
/**
* Clicks on the {@link MenuItem}.
*
* @param menuItem
* the {@link MenuItem} to click on
*/
private static void click(final MenuItem menuItem) {
final Event event = new Event();
event.time = (int) System.currentTimeMillis();
event.widget = menuItem;
event.display = menuItem.getDisplay();
event.type = SWT.Selection;
UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
@Override
public void run() {
if (SWTUtils.hasStyle(menuItem, SWT.CHECK) || SWTUtils.hasStyle(menuItem, SWT.RADIO)) {
menuItem.setSelection(!menuItem.getSelection());
}
menuItem.notifyListeners(SWT.Selection, event);
}
});
}
示例10: fill
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
@Override
public void fill(Menu menu, int index) {
final IProject project = getSelectedProject();
final boolean exists = AddBuilder.hasBuilder(project);
MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
menuItem.setText((exists ? "Remove" : "Add") + " Layered Builder");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
G.reset();
if (exists) {
RemoveBuilder.removeBuilder(project);
} else {
AddBuilder.addBuilder(project);
}
Activator.getDefault().getAnalysis().removeWarnings(1000);
}
});
}
示例11: createMenuItem
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private void createMenuItem(Menu parent, final TableColumn column) {
final MenuItem itemName = new MenuItem(parent, SWT.CHECK);
itemName.setText(column.getText());
itemName.setSelection(column.getResizable());
itemName.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (itemName.getSelection()) {
column.setWidth(150);
column.setResizable(true);
} else {
column.setWidth(0);
column.setResizable(false);
}
}
});
}
示例12: updateTypes
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
public void updateTypes(){
MenuItem[] items = this.newCollection.getItems();
for(int i = 0;i < items.length; i ++){
items[i].dispose();
}
Iterator<TGBrowserFactory> bookTypes = TGBrowserManager.getInstance(getBrowser().getContext()).getFactories();
while(bookTypes.hasNext()){
final TGBrowserFactory bookType = (TGBrowserFactory)bookTypes.next();
MenuItem item = new MenuItem(this.newCollection,SWT.PUSH);
item.setText(bookType.getName());
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
newCollection( bookType.getType());
}
});
}
}
示例13: createMenu
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
public void createMenu(TGToolBar toolBar, ToolItem item) {
Rectangle rect = item.getBounds();
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
Menu menu = new Menu(item.getParent().getShell());
TGCustomChordManager customChordManager = TuxGuitar.getInstance().getCustomChordManager();
for(int i = 0; i < customChordManager.countChords(); i++){
TGChord chord = TuxGuitar.getInstance().getCustomChordManager().getChord(i);
MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText(chord.getName());
menuItem.addSelectionListener(this.createInsertChordAction(toolBar, chord));
}
menu.setLocation(pt.x, pt.y + rect.height);
menu.setVisible(true);
}
示例14: createMenuItem
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private void createMenuItem(Menu menu, BookmarkId selectedBookmarkId, BookmarkNumber bookmarkNumber) {
Optional<BookmarkId> bookmarkId = numberedBookmarks.getBookmark(bookmarkNumber);
final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
menuItem.setSelection(bookmarkId.isPresent() ? bookmarkId.get().equals(selectedBookmarkId) : false);
menuItem.setText(getText(bookmarkId));
menuItem.setAccelerator('0' + bookmarkNumber.getNumber());
Image image = getImage(bookmarkNumber, bookmarkId);
if (image != null) {
menuItem.setImage(image);
}
Listener listener = new Listener() {
@Override
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Selection:
if (menuItem.getSelection()) {
bookmarksService.addNumberedBookmark(selectedBookmarkId, bookmarkNumber);
}
break;
}
}
};
menuItem.addListener(SWT.Selection, listener);
}
示例15: addMenuItem
import org.eclipse.swt.widgets.MenuItem; //导入依赖的package包/类
private MenuItem addMenuItem(Menu menu, String text, int accelerator,
Object data, SelectionListener listener) {
MenuItem item = new MenuItem(menu, SWT.NONE);
item.setText(text);
item.addSelectionListener(listener);
if (accelerator != SWT.NONE)
item.setAccelerator(accelerator);
item.setData(data);
return item;
}