From 51645012289574f937ecf67c4eed235854d6d601 Mon Sep 17 00:00:00 2001 From: bancika Date: Mon, 7 Sep 2020 08:47:50 +0200 Subject: [PATCH] patch for mac-specific file handler --- diylc/diylc-swing/.classpath | 1 + .../src/org/diylc/DIYLCStarter.java | 83 ++++++++++--------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/diylc/diylc-swing/.classpath b/diylc/diylc-swing/.classpath index 77c36058..6e8ce35a 100644 --- a/diylc/diylc-swing/.classpath +++ b/diylc/diylc-swing/.classpath @@ -14,6 +14,7 @@ + diff --git a/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java b/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java index febab7cd..341dff19 100644 --- a/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java +++ b/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java @@ -35,6 +35,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.PropertyInjector; +import org.diylc.appframework.miscutils.Utils; import org.diylc.common.IPlugInPort; import org.diylc.core.IView; import org.diylc.lang.LangUtil; @@ -63,19 +64,19 @@ public class DIYLCStarter { /** * @param args - * @throws InvalidActivityException + * @throws InvalidActivityException */ public static void main(String[] args) { // Initialize splash screen - DIYLCSplash splash = null; - Exception splashException = null; - - try { - splash = new DIYLCSplash(); - } catch (Exception e) { - System.out.println("Splash screen could not be initialized: " + e.getMessage()); - splashException = e; - } + DIYLCSplash splash = null; + Exception splashException = null; + + try { + splash = new DIYLCSplash(); + } catch (Exception e) { + System.out.println("Splash screen could not be initialized: " + e.getMessage()); + splashException = e; + } URL url = DIYLCStarter.class.getResource("log4j.properties"); Properties properties = new Properties(); @@ -87,12 +88,12 @@ public class DIYLCStarter { } ConfigurationManager.initialize("diylc"); - + // disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false); - + LOG.info("Loading languages..."); - + LangUtil.configure(); LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by " @@ -106,20 +107,22 @@ public class DIYLCStarter { } catch (Exception e) { LOG.error("Could not set Look&Feel", e); } - + Thread fontThread = new Thread(new Runnable() { @Override - public void run() { + public void run() { LOG.debug("Starting font pre-loading"); - + File[] fonts = ResourceLoader.getFiles("fonts"); if (fonts != null) for (int i = 0; i < fonts.length; i++) { try { LOG.info("Dynamically loading font: " + fonts[i].getName()); - Font customFont = Font.createFont(Font.TRUETYPE_FONT, new File(fonts[i].getAbsolutePath())).deriveFont(12f); + Font customFont = + Font.createFont(Font.TRUETYPE_FONT, new File(fonts[i].getAbsolutePath())) + .deriveFont(12f); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // register the font ge.registerFont(customFont); @@ -129,7 +132,7 @@ public class DIYLCStarter { LOG.error("Font format error", e); } } - + FontChooserComboBox box = new FontChooserComboBox(); box.getPreferredSize(); JPanel p = new JPanel(); @@ -141,11 +144,11 @@ public class DIYLCStarter { String val = System.getProperty(SCRIPT_RUN); if (!"true".equals(val)) { - int response = - JOptionPane.showConfirmDialog(null, "It is not recommended to run DIYLC by clicking on the diylc.jar file.\n" + int response = JOptionPane.showConfirmDialog(null, + "It is not recommended to run DIYLC by clicking on the diylc.jar file.\n" + "Please use diylc.exe on Windows or run.sh on OSX/Linux to ensure the best\n" - + "performance and reliability. Do you want to continue?", "DIYLC", JOptionPane.YES_NO_OPTION, - JOptionPane.WARNING_MESSAGE); + + "performance and reliability. Do you want to continue?", + "DIYLC", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response != JOptionPane.YES_OPTION) { System.exit(0); } @@ -153,33 +156,37 @@ public class DIYLCStarter { MainFrame mainFrame = new MainFrame(); Presenter presenter = mainFrame.getPresenter(); -// mainFrame.setLocationRelativeTo(null); - + // mainFrame.setLocationRelativeTo(null); + if (splash == null) { LOG.warn("Splash screen could not be initialized", splashException); } else { splash.setVisible(false); splash.dispose(); } - + mainFrame.setVisible(true); - - SwingUtilities.invokeLater(() -> { - Application.getApplication().setOpenFileHandler((AppEvent.OpenFilesEvent ofe) -> { - List files = ofe.getFiles(); - if (files != null && files.size() > 0) { - String filePath = files.get(0).getAbsolutePath(); - if (presenter.allowFileAction()) { - presenter.loadProjectFromFile(filePath); + + // assign open file handler for Mac + if (Utils.isMac()) { + SwingUtilities.invokeLater(() -> { + Application.getApplication().setOpenFileHandler((AppEvent.OpenFilesEvent ofe) -> { + List files = ofe.getFiles(); + if (files != null && files.size() > 0) { + String filePath = files.get(0).getAbsolutePath(); + if (presenter.allowFileAction()) { + presenter.loadProjectFromFile(filePath); + } } - } + }); }); - }); + } if (args.length > 0) { presenter.loadProjectFromFile(args[0]); } else { - boolean showTemplates = ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false); + boolean showTemplates = + ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false); if (showTemplates) { TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter()); if (!templateDialog.getFiles().isEmpty()) { @@ -199,12 +206,12 @@ public class DIYLCStarter { } catch (Exception e) { LOG.error("Could not read config.properties file", e); } - + if (ConfigurationManager.getInstance().isFileWithErrors()) mainFrame.showMessage("" + "There was an error reading the configuration file and it was replaced by a default configuration.
" + "The backup file is created and placed in user directory under '.diylc' sub-directory with '~' at the end.
" - + "This can happen when running two versions of DIYLC on the same machine at the same time.
" + + "This can happen when running two versions of DIYLC on the same machine at the same time.
" + "Replace the main 'config.xml' file with the backup when running the latest version of DIYLC." + "", "Warning", IView.WARNING_MESSAGE); }