public SVGWindow addWindow(OMSVGSVGElement svg, ILoadRequest request) { String title = request.getTitle(); SVGModel model = SVGModel.newInstance(svg, title); SVGWindow window = new SVGWindow(model); window.setHeading(title); svgWindows.add(window); // To be notified when a window is activated in order to // keep track of the active window window.addListener( Events.Activate, new Listener<WindowEvent>() { @Override public void handleEvent(WindowEvent we) { SVGWindow svgWindow = (SVGWindow) we.getWindow(); GWT.log("VectomaticApp2.Activate(" + svgWindow.getHeading() + ")"); if (activeWindow != svgWindow) { if (activeWindow != null) { activeWindow.deactivate(); fireEvent(new DeactivateWindowEvent(activeWindow)); } activeWindow = svgWindow; activeWindow.activate(); fireEvent(new ActivateWindowEvent(activeWindow)); } } }); window.addListener( Events.BeforeHide, new Listener<WindowEvent>() { @Override public void handleEvent(WindowEvent we) { SVGWindow svgWindow = (SVGWindow) we.getWindow(); svgWindow.getSvgModel().getSelectionModel().deselectAll(); GWT.log("VectomaticApp2.BeforeHide(" + svgWindow.getHeading() + ")"); svgWindow.removeAllListeners(); svgWindow.deactivate(); fireEvent(new DeactivateWindowEvent(svgWindow)); svgWindows.remove(svgWindow); activeWindow = null; update(); } }); // Update the recent docs menu if (!(request instanceof NewDocRequest)) { List<Component> recentDocs = recentDocsMenu.getItems(); boolean alreadyInRecentDocs = false; for (Component item : recentDocs) { RecentDocMenuItem menuItem = (RecentDocMenuItem) item; if (request.equals(menuItem.getRequest())) { alreadyInRecentDocs = true; break; } } if (!alreadyInRecentDocs) { if (recentDocs.size() >= 8) { Component oldestItem = recentDocs.get(0); oldestItem.removeAllListeners(); recentDocsMenu.remove(oldestItem); } RecentDocMenuItem recentDocItem = new RecentDocMenuItem(request); recentDocsMenu.add(recentDocItem); } } int windowBarHeight = getWindowBarHeight(); windowY += windowBarHeight; window.setPagePosition(windowX, windowY); windowX += windowBarHeight; // window.show(); viewport.add(window); window.setVisible(true); update(); return window; }
public void onModuleLoad() { instance = this; GWT.setUncaughtExceptionHandler( new GWT.UncaughtExceptionHandler() { public void onUncaughtException(Throwable throwable) { GWT.log("Uncaught exception", throwable); if (!GWT.isScript()) { String text = "Uncaught exception: "; while (throwable != null) { StackTraceElement[] stackTraceElements = throwable.getStackTrace(); text += throwable.toString() + "\n"; for (int i = 0; i < stackTraceElements.length; i++) { text += " at " + stackTraceElements[i] + "\n"; } throwable = throwable.getCause(); if (throwable != null) { text += "Caused by: "; } } DialogBox dialogBox = new DialogBox(true); DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF"); System.err.print(text); text = text.replaceAll(" ", " "); dialogBox.setHTML("<pre>" + text + "</pre>"); dialogBox.center(); } } }); AppBundle.INSTANCE.css().ensureInjected(); // Create graphical context OMSVGDocument doc = OMSVGParser.currentDocument(); SVGElement element = doc.createSVGPathElement().getElement().cast(); element .getStyle() .setProperty(SVGConstants.CSS_FILL_PROPERTY, SVGConstants.CSS_LIGHTBLUE_VALUE); element.getStyle().setProperty(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_BLACK_VALUE); SVGNamedElementModel.createTitleDesc(element, AppConstants.INSTANCE.graphicalContext()); cssContext = new CssContextModel(element); svgWindows = new ArrayList<SVGWindow>(); viewport = new ViewportExt(); viewport.setLayout(new BorderLayout()); viewport.add(createMenuBar(), new BorderLayoutData(LayoutRegion.NORTH, getWindowBarHeight())); viewport.setStyleAttribute("background-color", SVGConstants.CSS_BEIGE_VALUE); commandToolBar = new CommandFactoryToolBar( CommandFactories.getAllFactoriesStore(), getCommandFactorySelector()); ContentPanel commandPanel = new ContentPanel(); commandPanel.setHeaderVisible(false); commandPanel.setBottomComponent(commandToolBar); viewport.add(commandPanel, new BorderLayoutData(LayoutRegion.SOUTH, getWindowBarHeight())); new InternalLoadRequest(AppBundle.INSTANCE.fish(), "fish.svg").load(); new InternalLoadRequest(AppBundle.INSTANCE.fries(), "fries.svg").load(); new InternalLoadRequest(AppBundle.INSTANCE.sample(), "sample.svg").load(); update(); fileUpload = new FileUploadExt(); Style style = fileUpload.getElement().getStyle(); style.setVisibility(Visibility.HIDDEN); style.setWidth(0, Unit.PX); style.setHeight(0, Unit.PX); fileUpload.addChangeHandler( new ChangeHandler() { @Override public void onChange(ChangeEvent event) { processFiles(fileUpload.getFiles()); } }); RootPanel.get().add(viewport); RootPanel.get().add(fileUpload); }