From 4c1b187313ed4755b73cbcc8b5ff90f037e2e789 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Thu, 21 Aug 2014 13:33:46 +0200 Subject: [PATCH] Moved platform (and related methods) from Base to BaseNoGui (work in progress). --- .../discoverers/NetworkDiscovery.java | 2 +- .../packages/discoverers/SerialDiscovery.java | 2 +- app/src/processing/app/Base.java | 34 +++++-------------- app/src/processing/app/BaseNoGui.java | 24 +++++++++++++ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java b/app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java index 2674a52ba..ae1c5aea4 100644 --- a/app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java +++ b/app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java @@ -140,7 +140,7 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino. String label = name + " at " + address; if (board != null) { - String boardName = Base.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board); + String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board); label += " (" + boardName + ")"; } diff --git a/app/src/cc/arduino/packages/discoverers/SerialDiscovery.java b/app/src/cc/arduino/packages/discoverers/SerialDiscovery.java index 9cec93e91..10eff401c 100644 --- a/app/src/cc/arduino/packages/discoverers/SerialDiscovery.java +++ b/app/src/cc/arduino/packages/discoverers/SerialDiscovery.java @@ -43,7 +43,7 @@ public class SerialDiscovery implements Discovery { @Override public List discovery() { - Platform os = Base.getPlatform(); + Platform os = BaseNoGui.getPlatform(); String devicesListOutput = os.preListAllCandidateDevices(); List res = new ArrayList(); diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 39b787305..20e14edee 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -67,8 +67,6 @@ public class Base { /** Set true if this a proper release rather than a numbered revision. */ static public boolean RELEASE = BaseNoGui.RELEASE; - static Platform platform; - private static DiscoveryManager discoveryManager = new DiscoveryManager(); static private boolean commandLine; @@ -212,7 +210,7 @@ public class Base { // Set the look and feel before opening the window try { - platform.setLookAndFeel(); + BaseNoGui.getPlatform().setLookAndFeel(); } catch (Exception e) { String mess = e.getMessage(); if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) { @@ -241,21 +239,7 @@ public class Base { static protected void initPlatform() { - try { - Class platformClass = Class.forName("processing.app.Platform"); - if (OSUtils.isMacOS()) { - platformClass = Class.forName("processing.app.macosx.Platform"); - } else if (OSUtils.isWindows()) { - platformClass = Class.forName("processing.app.windows.Platform"); - } else if (OSUtils.isLinux()) { - platformClass = Class.forName("processing.app.linux.Platform"); - } - platform = (Platform) platformClass.newInstance(); - } catch (Exception e) { - Base.showError(_("Problem Setting the Platform"), - _("An unknown error occurred while trying to load\n" + - "platform-specific code for your machine."), e); - } + BaseNoGui.initPlatform(); } @@ -282,7 +266,7 @@ public class Base { protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF }; public Base(String[] args) throws Exception { - platform.init(this); + BaseNoGui.getPlatform().init(this); // Get the sketchbook path, and make sure it's set properly String sketchbookPath = Preferences.get("sketchbook.path"); @@ -1919,7 +1903,7 @@ public class Base { static public Platform getPlatform() { - return platform; + return BaseNoGui.getPlatform(); } @@ -1956,7 +1940,7 @@ public class Base { } else { try { - settingsFolder = platform.getSettingsFolder(); + settingsFolder = BaseNoGui.getPlatform().getSettingsFolder(); } catch (Exception e) { showError(_("Problem getting data folder"), _("Error getting the Arduino data folder."), e); @@ -2176,7 +2160,7 @@ public class Base { File sketchbookFolder = null; try { - sketchbookFolder = platform.getDefaultSketchbookFolder(); + sketchbookFolder = BaseNoGui.getPlatform().getDefaultSketchbookFolder(); } catch (Exception e) { } if (sketchbookFolder == null) { @@ -2232,7 +2216,7 @@ public class Base { */ static public void openURL(String url) { try { - platform.openURL(url); + BaseNoGui.getPlatform().openURL(url); } catch (Exception e) { showWarning(_("Problem Opening URL"), @@ -2246,7 +2230,7 @@ public class Base { * @return true If a means of opening a folder is known to be available. */ static protected boolean openFolderAvailable() { - return platform.openFolderAvailable(); + return BaseNoGui.getPlatform().openFolderAvailable(); } @@ -2256,7 +2240,7 @@ public class Base { */ static public void openFolder(File file) { try { - platform.openFolder(file); + BaseNoGui.getPlatform().openFolder(file); } catch (Exception e) { showWarning(_("Problem Opening Folder"), diff --git a/app/src/processing/app/BaseNoGui.java b/app/src/processing/app/BaseNoGui.java index 6a4fd3257..fa4326641 100644 --- a/app/src/processing/app/BaseNoGui.java +++ b/app/src/processing/app/BaseNoGui.java @@ -27,6 +27,8 @@ public class BaseNoGui { static public Map packages; + static Platform platform; + static File portableFolder = null; // Returns a File object for the given pathname. If the pathname @@ -79,6 +81,10 @@ public class BaseNoGui { return getHardwareFolder().getAbsolutePath(); } + static public Platform getPlatform() { + return platform; + } + static public File getPortableFolder() { return portableFolder; } @@ -129,6 +135,24 @@ public class BaseNoGui { } } + static protected void initPlatform() { + try { + Class platformClass = Class.forName("processing.app.Platform"); + if (OSUtils.isMacOS()) { + platformClass = Class.forName("processing.app.macosx.Platform"); + } else if (OSUtils.isWindows()) { + platformClass = Class.forName("processing.app.windows.Platform"); + } else if (OSUtils.isLinux()) { + platformClass = Class.forName("processing.app.linux.Platform"); + } + platform = (Platform) platformClass.newInstance(); + } catch (Exception e) { + Base.showError(_("Problem Setting the Platform"), + _("An unknown error occurred while trying to load\n" + + "platform-specific code for your machine."), e); + } + } + static public void initPortableFolder() { // Portable folder portableFolder = getContentFile("portable");