Skip to content

Commit 4c1b187

Browse files
bitroncmaglie
authored andcommitted
Moved platform (and related methods) from Base to BaseNoGui (work in progress).
1 parent 7776ffa commit 4c1b187

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void serviceResolved(ServiceEvent serviceEvent) {
140140

141141
String label = name + " at " + address;
142142
if (board != null) {
143-
String boardName = Base.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
143+
String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
144144
label += " (" + boardName + ")";
145145
}
146146

app/src/cc/arduino/packages/discoverers/SerialDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class SerialDiscovery implements Discovery {
4343

4444
@Override
4545
public List<BoardPort> discovery() {
46-
Platform os = Base.getPlatform();
46+
Platform os = BaseNoGui.getPlatform();
4747
String devicesListOutput = os.preListAllCandidateDevices();
4848

4949
List<BoardPort> res = new ArrayList<BoardPort>();

app/src/processing/app/Base.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public class Base {
6767
/** Set true if this a proper release rather than a numbered revision. */
6868
static public boolean RELEASE = BaseNoGui.RELEASE;
6969

70-
static Platform platform;
71-
7270
private static DiscoveryManager discoveryManager = new DiscoveryManager();
7371

7472
static private boolean commandLine;
@@ -212,7 +210,7 @@ static public void main(String args[]) throws Exception {
212210

213211
// Set the look and feel before opening the window
214212
try {
215-
platform.setLookAndFeel();
213+
BaseNoGui.getPlatform().setLookAndFeel();
216214
} catch (Exception e) {
217215
String mess = e.getMessage();
218216
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
@@ -241,21 +239,7 @@ static protected boolean isCommandLine() {
241239

242240

243241
static protected void initPlatform() {
244-
try {
245-
Class<?> platformClass = Class.forName("processing.app.Platform");
246-
if (OSUtils.isMacOS()) {
247-
platformClass = Class.forName("processing.app.macosx.Platform");
248-
} else if (OSUtils.isWindows()) {
249-
platformClass = Class.forName("processing.app.windows.Platform");
250-
} else if (OSUtils.isLinux()) {
251-
platformClass = Class.forName("processing.app.linux.Platform");
252-
}
253-
platform = (Platform) platformClass.newInstance();
254-
} catch (Exception e) {
255-
Base.showError(_("Problem Setting the Platform"),
256-
_("An unknown error occurred while trying to load\n" +
257-
"platform-specific code for your machine."), e);
258-
}
242+
BaseNoGui.initPlatform();
259243
}
260244

261245

@@ -282,7 +266,7 @@ static public File absoluteFile(String path) {
282266
protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
283267

284268
public Base(String[] args) throws Exception {
285-
platform.init(this);
269+
BaseNoGui.getPlatform().init(this);
286270

287271
// Get the sketchbook path, and make sure it's set properly
288272
String sketchbookPath = Preferences.get("sketchbook.path");
@@ -1919,7 +1903,7 @@ public void handlePrefs() {
19191903

19201904

19211905
static public Platform getPlatform() {
1922-
return platform;
1906+
return BaseNoGui.getPlatform();
19231907
}
19241908

19251909

@@ -1956,7 +1940,7 @@ static public File getSettingsFolder() {
19561940

19571941
} else {
19581942
try {
1959-
settingsFolder = platform.getSettingsFolder();
1943+
settingsFolder = BaseNoGui.getPlatform().getSettingsFolder();
19601944
} catch (Exception e) {
19611945
showError(_("Problem getting data folder"),
19621946
_("Error getting the Arduino data folder."), e);
@@ -2176,7 +2160,7 @@ protected File getDefaultSketchbookFolder() {
21762160

21772161
File sketchbookFolder = null;
21782162
try {
2179-
sketchbookFolder = platform.getDefaultSketchbookFolder();
2163+
sketchbookFolder = BaseNoGui.getPlatform().getDefaultSketchbookFolder();
21802164
} catch (Exception e) { }
21812165

21822166
if (sketchbookFolder == null) {
@@ -2232,7 +2216,7 @@ static protected File promptSketchbookLocation() {
22322216
*/
22332217
static public void openURL(String url) {
22342218
try {
2235-
platform.openURL(url);
2219+
BaseNoGui.getPlatform().openURL(url);
22362220

22372221
} catch (Exception e) {
22382222
showWarning(_("Problem Opening URL"),
@@ -2246,7 +2230,7 @@ static public void openURL(String url) {
22462230
* @return true If a means of opening a folder is known to be available.
22472231
*/
22482232
static protected boolean openFolderAvailable() {
2249-
return platform.openFolderAvailable();
2233+
return BaseNoGui.getPlatform().openFolderAvailable();
22502234
}
22512235

22522236

@@ -2256,7 +2240,7 @@ static protected boolean openFolderAvailable() {
22562240
*/
22572241
static public void openFolder(File file) {
22582242
try {
2259-
platform.openFolder(file);
2243+
BaseNoGui.getPlatform().openFolder(file);
22602244

22612245
} catch (Exception e) {
22622246
showWarning(_("Problem Opening Folder"),

app/src/processing/app/BaseNoGui.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class BaseNoGui {
2727

2828
static public Map<String, TargetPackage> packages;
2929

30+
static Platform platform;
31+
3032
static File portableFolder = null;
3133

3234
// Returns a File object for the given pathname. If the pathname
@@ -79,6 +81,10 @@ static public String getHardwarePath() {
7981
return getHardwareFolder().getAbsolutePath();
8082
}
8183

84+
static public Platform getPlatform() {
85+
return platform;
86+
}
87+
8288
static public File getPortableFolder() {
8389
return portableFolder;
8490
}
@@ -129,6 +135,24 @@ static public void initPackages() {
129135
}
130136
}
131137

138+
static protected void initPlatform() {
139+
try {
140+
Class<?> platformClass = Class.forName("processing.app.Platform");
141+
if (OSUtils.isMacOS()) {
142+
platformClass = Class.forName("processing.app.macosx.Platform");
143+
} else if (OSUtils.isWindows()) {
144+
platformClass = Class.forName("processing.app.windows.Platform");
145+
} else if (OSUtils.isLinux()) {
146+
platformClass = Class.forName("processing.app.linux.Platform");
147+
}
148+
platform = (Platform) platformClass.newInstance();
149+
} catch (Exception e) {
150+
Base.showError(_("Problem Setting the Platform"),
151+
_("An unknown error occurred while trying to load\n" +
152+
"platform-specific code for your machine."), e);
153+
}
154+
}
155+
132156
static public void initPortableFolder() {
133157
// Portable folder
134158
portableFolder = getContentFile("portable");

0 commit comments

Comments
 (0)