List of usage examples for com.google.gwt.user.client.ui DockLayoutPanel forceLayout
public void forceLayout()
From source file:org.iplantc.phyloviewer.viewer.client.Phyloviewer.java
License:Creative Commons License
/** * This is the entry point method./* w ww . j av a 2 s . c o m*/ */ public void onModuleLoad() { widget = new TreeWidget(searchService, eventBus); Style highlight = new Style("highlight"); highlight.setNodeStyle(new NodeStyle("#C2C2F5", Double.NaN, null)); highlight.setLabelStyle(new LabelStyle(null)); highlight.setGlyphStyle(new GlyphStyle(null, "#C2C2F5", Double.NaN)); highlight.setBranchStyle(new BranchStyle("#C2C2F5", Double.NaN)); RenderPreferences rp = new RenderPreferences(); rp.setHighlightStyle(highlight); widget.setRenderPreferences(rp); MenuBar fileMenu = new MenuBar(true); fileMenu.addItem("Open...", new Command() { @Override public void execute() { Phyloviewer.this.displayTrees(); } }); Command openURL = new Command() { @Override public void execute() { Window.open(widget.exportImageURL(), "_blank", ""); } }; fileMenu.addItem("Get image (opens in a popup window)", openURL); Command showSVG = new Command() { @Override public void execute() { String svg = getSVG(); String url = "data:image/svg+xml;charset=utf-8," + svg; Window.open(url, "_blank", ""); } }; fileMenu.addItem("Export to SVG", showSVG); MenuBar layoutMenu = new MenuBar(true); layoutMenu.addItem("Rectangular Cladogram", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_CLADOGRAM); layoutType = "LAYOUT_TYPE_CLADOGRAM"; loadTree(null, treeID, layoutType); } }); layoutMenu.addItem("Rectangular Phylogram", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_CLADOGRAM); layoutType = "LAYOUT_TYPE_PHYLOGRAM"; loadTree(null, treeID, layoutType); } }); layoutMenu.addItem("Circular", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_RADIAL); layoutType = "LAYOUT_TYPE_CLADOGRAM"; loadTree(null, treeID, layoutType); } }); MenuBar styleMenu = new MenuBar(true); final TextInputPopup styleTextPopup = new TextInputPopup(); styleTextPopup.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String style = event.getValue(); try { IStyleMap styleMap = StyleServiceClient.parseJSON(style); widget.getDocument().setStyleMap(styleMap); widget.render(); } catch (StyleServiceException e) { Window.alert( "Unable to parse style document. See https://pods.iplantcollaborative.org/wiki/display/iptol/Using+Phyloviewer+GWT+client+library#UsingPhyloviewerGWTclientlibrary-Addingstylingmarkuptoviewer for help."); } } }); styleTextPopup.setModal(true); styleMenu.addItem("Import Tree Styling", new Command() { @Override public void execute() { styleTextPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { int left = (Window.getClientWidth() - offsetWidth) / 3; int top = (Window.getClientHeight() - offsetHeight) / 3; styleTextPopup.setPopupPosition(left, top); } }); } }); // Make a search box final SuggestBox searchBox = new SuggestBox(searchService); searchBox.setLimit(10); // TODO make scrollable? searchBox.addSelectionHandler(new SelectionHandler<Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { Box2D box = ((RemoteNodeSuggestion) event.getSelectedItem()).getResult().layout.boundingBox; widget.show(box); } }); // create some styling widgets for the context menu NodeStyleWidget nodeStyleWidget = new NodeStyleWidget(widget.getDocument()); BranchStyleWidget branchStyleWidget = new BranchStyleWidget(widget.getDocument()); GlyphStyleWidget glyphStyleWidget = new GlyphStyleWidget(widget.getDocument()); LabelStyleWidget labelStyleWidget = new LabelStyleWidget(widget.getDocument()); // replace their default TextBoxes with ColorBoxes, which jscolor.js will add a color picker to nodeStyleWidget.setColorWidget(createColorBox()); branchStyleWidget.setStrokeColorWidget(createColorBox()); glyphStyleWidget.setStrokeColorWidget(createColorBox()); glyphStyleWidget.setFillColorWidget(createColorBox()); labelStyleWidget.setColorWidget(createColorBox()); // add the widgets to separate panels on the context menu final ContextMenu contextMenuPanel = new ContextMenu(widget); contextMenuPanel.add(new NodeTable(), "Node details", 3); contextMenuPanel.add(nodeStyleWidget, "Node", 3); contextMenuPanel.add(branchStyleWidget, "Branch", 3); contextMenuPanel.add(glyphStyleWidget, "Glyph", 3); contextMenuPanel.add(labelStyleWidget, "Label", 3); HorizontalPanel searchPanel = new HorizontalPanel(); searchPanel.add(new Label("Search:")); searchPanel.add(searchBox); // Make the UI. MenuBar menu = new MenuBar(); final DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.EM); mainPanel.addNorth(menu, 2); mainPanel.addSouth(searchPanel, 2); mainPanel.addWest(contextMenuPanel, 0); mainPanel.add(widget); RootLayoutPanel.get().add(mainPanel); MenuBar viewMenu = new MenuBar(true); viewMenu.addItem("Layout", layoutMenu); viewMenu.addItem("Style", styleMenu); contextMenuPanel.setVisible(false); viewMenu.addItem("Toggle Context Panel", new Command() { @Override public void execute() { if (contextMenuPanel.isVisible()) { contextMenuPanel.setVisible(false); mainPanel.setWidgetSize(contextMenuPanel, 0); mainPanel.forceLayout(); } else { contextMenuPanel.setVisible(true); mainPanel.setWidgetSize(contextMenuPanel, 20); mainPanel.forceLayout(); } } }); menu.addItem("File", fileMenu); menu.addItem("View", viewMenu); // Draw for the first time. RootLayoutPanel.get().forceLayout(); mainPanel.forceLayout(); widget.setViewType(ViewType.VIEW_TYPE_CLADOGRAM); widget.render(); initColorPicker(); String[] splitPath = Window.Location.getPath().split("/"); String treeIdString = null; for (int i = 0; i < splitPath.length; i++) { if (splitPath[i].equalsIgnoreCase("tree")) { treeIdString = splitPath[i + 1]; } } if (treeIdString != null && !treeIdString.equals("")) { try { final byte[] treeId = Hex.decodeHex(treeIdString.toCharArray()); this.loadTree(null, treeId, layoutType); } catch (Exception e) { Window.alert("Unable to parse tree ID string from URL"); } } else { // Present the user the dialog to load a tree. this.displayTrees(); } updateStyle(); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { updateStyle(); } }); }