List of usage examples for com.google.gwt.user.client.ui MenuBar addItem
public MenuItem addItem(String text, MenuBar popup)
From source file:org.primordion.xholon.io.XholonGuiClassic.java
License:Open Source License
/** * Show the entire IXholon tree as a Tree. * @param node Node from which to start showing the tree. *//* ww w . ja v a2 s . c o m*/ public void showTree(IXholon node) { if (tiRoot != null) { // an existing model is already running //removeAll(); } if (app == null) { app = node.getApp(); } xhRoot = node; tiRoot = new TreeItem(); createNode(xhRoot, tiRoot, null); tree = new XholonGuiClassicTree(this); tree.addItem(tiRoot); tree.addSelectionHandler(new SelectionHandler<TreeItem>() { public void onSelection(SelectionEvent<TreeItem> event) { TreeItem ti = event.getSelectedItem(); handleNodeSelection(ti.getText(), ti, tree.isCtrlPressed()); } }); ScrollPanel scrollPanel = new ScrollPanel(tree); scrollPanel.setSize("500px", "500px"); DockPanel panel = new DockPanel(); //this; panel.setStylePrimaryName("xhgui"); panel.add(scrollPanel, DockPanel.CENTER); currentSelectionField = new TextBox(); currentSelectionField.setVisibleLength(60); // 58 currentSelectionField.setMaxLength(200); currentSelectionField.setText("Click on any node to show details"); panel.add(currentSelectionField, DockPanel.SOUTH); // main menu at top of GUI MenuBar mainMenu = new MenuBar(); mainMenu.setStylePrimaryName("mainMenu"); // File MenuBar fileMenu = new MenuBar(true); MenuBar localStorageMenu = new MenuBar(true); boolean enableFileItems = true; //consoleLog(enableFileItems); //consoleLog(Window.Location.getParameter("src")); if ("gist".equals(Window.Location.getParameter("src"))) { //consoleLog("setting to false"); enableFileItems = false; } //consoleLog(enableFileItems); localStorageMenu.addItem("Save", new Command() { @Override public void execute() { IApplication lsApp = new ApplicationNull(); String configFileName = app.getConfigFileName(); lsApp.setConfigFileName(configFileName); JavaApp2Workbook app2Wb = new JavaApp2Workbook(); app2Wb.setWinName("_blank"); // open in new tab or window app2Wb.save(configFileName, lsApp); } }).setEnabled(enableFileItems); // save to localStorage using a new name /*localStorageMenu.addItem("Save as", new Command() { @Override public void execute() { } }).setEnabled(enableFileItems);*/ localStorageMenu.addItem("Edit", new Command() { @Override public void execute() { IApplication lsApp = new ApplicationNull(); String configFileName = app.getConfigFileName(); lsApp.setConfigFileName(configFileName); JavaApp2Workbook app2Wb = new JavaApp2Workbook(); app2Wb.setWinName("_blank"); // open in new tab or window app2Wb.edit(configFileName, lsApp); } }).setEnabled(enableFileItems); localStorageMenu.addItem("Restart from", new Command() { @Override public void execute() { // restart the current app by reloading the HTML page (equivalent to browser F5) // the reloaded app will automatically include the edited changes in localStorage Window.Location.reload(); } }).setEnabled(enableFileItems); // remove from localStorage /*localStorageMenu.addItem("Remove from", new Command() { @Override public void execute() { } }).setEnabled(enableFileItems);*/ fileMenu.addItem("localStorage", localStorageMenu); mainMenu.addItem("File", fileMenu); // Application mainMenu.addItem("Application", new Command() { @Override public void execute() { if (app == null) { //app.println("Application not yet loaded."); } else { app.about(); } } }); // Help MenuBar helpMenu = new MenuBar(true); helpMenu.addItem("About", new Command() { @Override public void execute() { if (app == null) { //app.println("Application not yet loaded."); } else { app.about(); } } }); helpMenu.addItem("Getting Started", new Command() { @Override public void execute() { gettingStarted("Getting Started with Xholon", splashText, 375, 475); } }); helpMenu.addItem("Information", new Command() { @Override public void execute() { if (app == null) { //app.println("Application not yet loaded."); } else { app.information(); } } }); helpMenu.addItem("JavaScript API", new Command() { @Override public void execute() { Window.open(GwtEnvironment.gwtHostPageBaseURL + "jsapidoc/modules/XholonJsApi.html", "_blank", ""); } }); mainMenu.addItem("Help", helpMenu); HorizontalPanel mainMenuHp = new HorizontalPanel(); mainMenuHp.setStylePrimaryName("mainMenu"); mainMenuHp.add(mainMenu); // toolbar with Controller buttons just below main menu HorizontalPanel toolbar = new HorizontalPanel(); toolbar.setStylePrimaryName("toolbar"); IXholon controlNode = app.getControlRoot().getFirstChild(); while (controlNode != null) { toolbar.add(makeToolbarWidget(controlNode)); controlNode = controlNode.getNextSibling(); } VerticalPanel topVp = new VerticalPanel(); topVp.setStylePrimaryName("mainMenu"); topVp.setWidth("500px"); // 474 topVp.add(mainMenuHp); topVp.add(toolbar); panel.add(topVp, DockPanel.NORTH); RootPanel xhgui = RootPanel.get("xhgui"); if (xhgui == null) { node.consoleLog("WARNING xhgui element does not exist"); } else { xhgui.add(panel); } //((Application)app).clearConsole(); // clear the contents of the xhconsole /*Element element = Document.get().getElementById("xhconsole").getFirstChildElement(); if (element != null) { TextAreaElement textfield = element.cast(); textfield.setValue(""); }*/ }
From source file:org.vectomatic.client.rep.RepApplication.java
License:Open Source License
public void onModuleLoad() { _constants = (UIConstants) GWT.create(UIConstants.class); _messages = (UIMessages) GWT.create(UIMessages.class); _icons = (UIImageBundle) GWT.create(UIImageBundle.class); app = this;// w ww .j a v a2s . c om //debugArea = new TextArea(); _model = new DrawingModel(); _selection = new ShapeSelection(_model); _history = new CommandHistory(20); _paletteList = new PaletteList(); _paletteList.addPalette(Palette.getEGA()); _paletteList.addPalette(Palette.getGOLD()); RepresentationController repController = new RepresentationController(this); _view = new DrawingView(repController, _model, 400, 400); _view.setTabIndex(1); _view.setFocus(true); _selector = new MouseControllerSelector(_view); Attribute.LINE_STYLE.setName(_constants.lineStyleAttribute()); Attribute.LINE_OPACITY.setName(_constants.lineOpacityAttribute()); Attribute.LINE_PATTERN.setName(_constants.linePatternAttribute()); Attribute.LINE_CAP.setName(_constants.lineCapAttribute()); Attribute.LINE_WIDTH.setName(_constants.lineWidthAttribute()); Attribute.FILL_STYLE.setName(_constants.fillStyleAttribute()); Attribute.FILL_OPACITY.setName(_constants.fillOpacityAttribute()); _lineStyleController = new StyleController(this, _constants.lineLabel(), Attribute.LINE_STYLE, Attribute.LINE_OPACITY, Color.BLACK, new FloatAttributeValue(1f)); _fillStyleController = new StyleController(this, _constants.fillLabel(), Attribute.FILL_STYLE, Attribute.FILL_OPACITY, Color.fromRGB(0, 128, 255), new FloatAttributeValue(1f)); _lineWidthController = new LineWidthController(this); _clipBoard = new ClipBoard(); UndoController undoController = new UndoController(this); RedoController redoController = new RedoController(this); CopyController copyController = new CopyController(this); CutController cutController = new CutController(this); PasteController pasteController = new PasteController(this); GroupController groupController = new GroupController(this); UngroupController ungroupController = new UngroupController(this); DeleteController deleteController = new DeleteController(this); OrderingController orderingController = new OrderingController(this); ResizeController resizeController = new ResizeController(this, repController); FormPanel form = new FormPanel("export"); ExportController exportController = new ExportController(this, form); ContextualMenuVisitor contextVisitor = new ContextualMenuVisitor(deleteController, ungroupController, groupController, orderingController, _view); SelectShapeController selectShapeController = new SelectShapeController(this, deleteController, contextVisitor); NewRectController newRectController = new NewRectController(this); NewEllipseController newEllipseController = new NewEllipseController(this); NewPolylineController newPolylineController = new NewPolylineController(this); EditPolylineController editPolylineController = new EditPolylineController(this); NewPathController newPathController = new NewPathController(this); EditPathController editPathController = new EditPathController(this); _selector.add(selectShapeController.getButton()); _selector.add(newRectController.getButton()); _selector.add(newEllipseController.getButton()); _selector.add(newPolylineController.getButton()); _selector.add(editPolylineController.getButton()); _selector.add(newPathController.getButton()); _selector.add(editPathController.getButton()); _selector.selectController(newRectController.getButton()); final Grid commandButtons = new Grid(5, 2); commandButtons.setWidget(0, 0, selectShapeController.getButton()); commandButtons.setWidget(0, 1, repController.getSaveButton()); commandButtons.setWidget(1, 0, newRectController.getButton()); commandButtons.setWidget(1, 1, newEllipseController.getButton()); commandButtons.setWidget(2, 0, newPolylineController.getButton()); commandButtons.setWidget(2, 1, editPolylineController.getButton()); commandButtons.setWidget(3, 0, newPathController.getButton()); commandButtons.setWidget(3, 1, editPathController.getButton()); commandButtons.setWidget(4, 0, undoController.getUndoButton()); commandButtons.setWidget(4, 1, redoController.getRedoButton()); final VerticalPanel toolBar = new VerticalPanel(); toolBar.add(commandButtons); HorizontalPanel row1 = new HorizontalPanel(); row1.add(toolBar); HorizontalPanel row2 = new HorizontalPanel(); row2.add(_lineStyleController.getWidget()); row2.add(_lineWidthController.getWidget()); row2.add(_fillStyleController.getWidget()); VerticalPanel col1 = new VerticalPanel(); col1.add(row2); col1.add(_view); row1.add(col1); //debugArea.setCharacterWidth(80); //debugArea.setVisibleLines(20); //row1.add(debugArea); VerticalPanel col2 = new VerticalPanel(); MenuBar editMenu = new MenuBar(true); editMenu.addItem(_constants.resetViewCommand(), new Command() { public void execute() { _view.reset(); } }); editMenu.addItem(undoController.getUndoMenuItem()); editMenu.addItem(redoController.getRedoMenuItem()); editMenu.addItem(cutController.getCutMenuItem()); editMenu.addItem(copyController.getCopyMenuItem()); editMenu.addItem(pasteController.getPasteMenuItem()); editMenu.addItem(exportController.getExportSVG11Item()); editMenu.addItem(exportController.getExportSVG12Item()); MenuBar modifyMenu = new MenuBar(true); modifyMenu.addItem(groupController.getGroupMenuItem()); modifyMenu.addItem(ungroupController.getUngroupMenuItem()); modifyMenu.addItem(orderingController.newMenuItem(_view, ChangeOrderingCommand.BRING_TO_FRONT)); modifyMenu.addItem(orderingController.newMenuItem(_view, ChangeOrderingCommand.SEND_TO_BACK)); modifyMenu.addItem(orderingController.newMenuItem(_view, ChangeOrderingCommand.BRING_FORWARD)); modifyMenu.addItem(orderingController.newMenuItem(_view, ChangeOrderingCommand.SEND_BACKWARD)); modifyMenu.addItem(resizeController.getResizeMenuItem(_view)); MenuBar helpMenu = new MenuBar(true); helpMenu.addItem(_constants.helpCommand(), new Command() { public void execute() { } }); final AboutPanel panel = new AboutPanel(); helpMenu.addItem(_constants.aboutCommand(), new Command() { public void execute() { panel.show(); } }); MenuBar menuBar = new MenuBar(); menuBar.addItem(_constants.editMenu(), editMenu); menuBar.addItem(_constants.modifyMenu(), modifyMenu); menuBar.addItem(_constants.helpMenu(), helpMenu); col2.add(menuBar); col2.add(row1); col2.add(form); //EventPanel eventPanel = new EventPanel(_view); //eventPanel.add(col1); //RootPanel.get().add(eventPanel); RootPanel.get().add(col2); repController.open(); RootPanel rootPanel = RootPanel.get(); rootPanel.sinkEvents(0xFFFFFFFF); DOM.setEventListener(RootPanel.getBodyElement(), this); _view.render(); }
From source file:tn.spindox.client.ui.MenuBarExample.java
License:Apache License
public MenuBar getMenuBar() { // Make a command that we will execute from all leaves. Command cmd = new Command() { public void execute() { Window.alert("You selected a menu item!"); }/*from w ww.ja v a 2 s . co m*/ }; // Make some sub-menus that we will cascade from the top menu. MenuBar fooMenu = new MenuBar(true); fooMenu.addItem("the", cmd); fooMenu.addItem("foo", cmd); fooMenu.addItem("menu", cmd); MenuBar barMenu = new MenuBar(true); barMenu.addItem("the", cmd); barMenu.addItem("bar", cmd); barMenu.addItem("menu", cmd); MenuBar bazMenu = new MenuBar(true); bazMenu.addItem("the", cmd); bazMenu.addItem("baz", cmd); bazMenu.addItem("menu", cmd); // Make a new menu bar, adding a few cascading menus to it. MenuBar menu = new MenuBar(); menu.addItem("foo", fooMenu); menu.addItem("bar", barMenu); menu.addItem("baz", bazMenu); return menu; // // Add it to the root panel. // RootPanel.get().add(menu); }