public synchronized void handleOpenApplication(com.apple.eawt.ApplicationEvent ev) { Application.debug("handleOpenApplication event, filename: " + ev.getFilename()); // open file String fileName = ev.getFilename(); if (fileName != null) { handleOpenFile(ev); } else { GeoGebraFrame wnd = getGGBInstance(); if (!wnd.isShowing()) wnd.setVisible(true); } }
/** * Gets active instance of GeoGebra window. This method waits until an active instance was created * by GeoGebra.main() * * @return */ private synchronized GeoGebraFrame getGGBInstance() { GeoGebraFrame wnd = null; while (wnd == null) { try { Thread.sleep(100); wnd = GeoGebraFrame.getActiveInstance(); } catch (Exception e) { Application.debug("MacApplicationListener.getGGBInstance(): " + e.getMessage()); wnd = null; } } return wnd; }
public synchronized void handleOpenFile(com.apple.eawt.ApplicationEvent ev) { Application.debug("handleOpenFile event, filename: " + ev.getFilename()); // open file String fileName = ev.getFilename(); if (fileName != null) { File openFile = new File(fileName); if (openFile.exists()) { // get application instance GeoGebraFrame ggb = getGGBInstance(); Application app = ggb.getApplication(); // open file File[] files = {openFile}; boolean openInThisWindow = app.getCurrentFile() == null; app.getGuiManager().doOpenFiles(files, openInThisWindow); // make sure window is visible if (openInThisWindow) ggb.setVisible(true); } } }