1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-19 09:42:11 +03:00

Removed lots of calls to BaseNoGui.getPlatform(): static is evil

This commit is contained in:
Federico Fissore
2015-05-22 15:42:05 +02:00
parent 46e065b76d
commit ab7b7351f5
11 changed files with 84 additions and 136 deletions

View File

@ -37,6 +37,8 @@ import cc.arduino.contributions.ui.InstallerJDialogUncaughtExceptionHandler;
import cc.arduino.contributions.ui.*;
import cc.arduino.utils.Progress;
import com.google.common.base.Predicate;
import processing.app.BaseNoGui;
import processing.app.Platform;
import javax.swing.*;
import java.awt.*;
@ -49,8 +51,9 @@ import static processing.app.I18n._;
@SuppressWarnings("serial")
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
private LibrariesIndexer indexer;
private final JComboBox typeChooser;
private final Platform platform;
private LibrariesIndexer indexer;
private Predicate<ContributedLibrary> typeFilter;
@Override
@ -86,8 +89,9 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
};
}
public LibraryManagerUI(Frame parent) {
public LibraryManagerUI(Frame parent, Platform platform) {
super(parent, "Library Manager", Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
this.platform = platform;
filtersContainer.add(new JLabel(_("Topic")), 1);
filtersContainer.remove(2);
@ -177,7 +181,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
filterField.setEnabled(contribModel.getRowCount() > 0);
// Create LibrariesInstaller tied with the provided index
installer = new LibraryInstaller(indexer) {
installer = new LibraryInstaller(indexer, platform) {
@Override
public void onProgress(Progress progress) {
setProgress(progress);

View File

@ -34,7 +34,9 @@ import cc.arduino.contributions.packages.ContributionsIndexer;
import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.ui.*;
import cc.arduino.utils.Progress;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.Platform;
import javax.swing.*;
import java.awt.*;
@ -47,7 +49,7 @@ import static processing.app.I18n._;
@SuppressWarnings("serial")
public class ContributionManagerUI extends InstallerJDialog {
// private ContributedPlatformTableCell cellEditor;
private final Platform platform;
@Override
protected FilteredAbstractTableModel createContribModel() {
@ -82,8 +84,9 @@ public class ContributionManagerUI extends InstallerJDialog {
};
}
public ContributionManagerUI(Frame parent) {
public ContributionManagerUI(Frame parent, Platform platform) {
super(parent, _("Boards Manager"), Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
this.platform = platform;
}
public void setIndexer(ContributionsIndexer indexer) {
@ -113,7 +116,7 @@ public class ContributionManagerUI extends InstallerJDialog {
}
// Create ConstributionInstaller tied with the provided index
installer = new ContributionInstaller(indexer) {
installer = new ContributionInstaller(indexer, platform) {
@Override
public void onProgress(Progress progress) {
setProgress(progress);

View File

@ -145,9 +145,9 @@ public class Base {
BaseNoGui.notifier = new GUIUserNotifier();
initPlatform();
BaseNoGui.initPlatform();
getPlatform().init();
BaseNoGui.getPlatform().init();
BaseNoGui.initPortableFolder();
@ -206,7 +206,7 @@ public class Base {
// Set the look and feel before opening the window
try {
getPlatform().setLookAndFeel();
BaseNoGui.getPlatform().setLookAndFeel();
} catch (Exception e) {
String mess = e.getMessage();
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
@ -261,23 +261,6 @@ public class Base {
return commandLine;
}
static protected void initPlatform() {
BaseNoGui.initPlatform();
}
static protected void initRequirements() {
try {
Class.forName("com.sun.jdi.VirtualMachine");
} catch (ClassNotFoundException cnfe) {
showError(_("Please install JDK 1.5 or later"),
_("Arduino requires a full JDK (not just a JRE)\n" +
"to run. Please install JDK 1.5 or later.\n" +
"More information can be found in the reference."), cnfe);
}
}
// Returns a File object for the given pathname. If the pathname
// is not absolute, it is interpreted relative to the current
// directory when starting the IDE (which is not the same as the
@ -349,8 +332,8 @@ public class Base {
PreferencesData.save();
if (parser.isInstallBoard()) {
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
ContributionInstaller installer = new ContributionInstaller(indexer) {
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform()) {
private String lastStatus = "";
@Override
@ -396,8 +379,8 @@ public class Base {
System.exit(0);
} else if (parser.isInstallLibrary()) {
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder()));
LibraryInstaller installer = new LibraryInstaller(indexer) {
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform()));
LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()) {
private String lastStatus = "";
@Override
@ -929,7 +912,7 @@ public class Base {
// }
// System.err.println(" creating new editor");
Editor editor = new Editor(this, file, location);
Editor editor = new Editor(this, file, location, BaseNoGui.getPlatform());
// Editor editor = null;
// try {
// editor = new Editor(this, path, location);
@ -1302,7 +1285,7 @@ public class Base {
private void openManageLibrariesDialog() {
@SuppressWarnings("serial")
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor) {
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.getPlatform()) {
@Override
protected void onIndexesUpdated() throws Exception {
BaseNoGui.initPackages();
@ -1325,7 +1308,7 @@ public class Base {
private void openInstallBoardDialog(final String filterText) throws Exception {
// Create dialog for contribution manager
@SuppressWarnings("serial")
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.getPlatform()) {
@Override
protected void onIndexesUpdated() throws Exception {
BaseNoGui.initPackages();
@ -1829,65 +1812,6 @@ public class Base {
dialog.setVisible(true);
}
// ...................................................................
/**
* Get list of platform constants.
*/
// static public int[] getPlatforms() {
// return platforms;
// }
// static public int getPlatform() {
// String osname = System.getProperty("os.name");
//
// if (osname.indexOf("Mac") != -1) {
// return PConstants.MACOSX;
//
// } else if (osname.indexOf("Windows") != -1) {
// return PConstants.WINDOWS;
//
// } else if (osname.equals("Linux")) { // true for the ibm vm
// return PConstants.LINUX;
//
// } else {
// return PConstants.OTHER;
// }
// }
static public Platform getPlatform() {
return BaseNoGui.getPlatform();
}
static public String getPlatformName() {
String osname = System.getProperty("os.name");
if (osname.indexOf("Mac") != -1) {
return "macosx";
} else if (osname.indexOf("Windows") != -1) {
return "windows";
} else if (osname.equals("Linux")) { // true for the ibm vm
return "linux";
} else {
return "other";
}
}
// .................................................................
static public File getSettingsFolder() {
return BaseNoGui.getSettingsFolder();
}
/**
* Convenience method to get a File object for the specified filename inside
* the settings folder.
@ -2092,7 +2016,7 @@ public class Base {
*/
static public void openURL(String url) {
try {
getPlatform().openURL(url);
BaseNoGui.getPlatform().openURL(url);
} catch (Exception e) {
showWarning(_("Problem Opening URL"),

View File

@ -70,6 +70,8 @@ import cc.arduino.packages.uploaders.SerialUploader;
@SuppressWarnings("serial")
public class Editor extends JFrame implements RunnerListener {
private final Platform platform;
private static class ShouldSaveIfModified implements Predicate<Sketch> {
@Override
@ -184,9 +186,10 @@ public class Editor extends JFrame implements RunnerListener {
Runnable exportAppHandler;
public Editor(Base ibase, File file, int[] location) throws Exception {
public Editor(Base ibase, File file, int[] location, Platform platform) throws Exception {
super("Arduino");
this.base = ibase;
this.platform = platform;
Base.setIcon(this);
@ -992,7 +995,7 @@ public class Editor extends JFrame implements RunnerListener {
@Override
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
try {
base.getPlatform().openURL(hyperlinkEvent.getURL().toExternalForm());
platform.openURL(hyperlinkEvent.getURL().toExternalForm());
} catch (Exception e) {
Base.showWarning(e.getMessage(), e.getMessage(), e);
}
@ -1129,7 +1132,7 @@ public class Editor extends JFrame implements RunnerListener {
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
ports = Base.getPlatform().filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
Collections.sort(ports, new Comparator<BoardPort>() {
@Override

View File

@ -50,11 +50,11 @@ public abstract class AbstractGUITest {
FailOnThreadViolationRepaintManager.install();
Base.initPlatform();
BaseNoGui.initPlatform();
Preferences.init(null);
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
Theme.init();
Base.getPlatform().setLookAndFeel();
BaseNoGui.getPlatform().setLookAndFeel();
Base.untitledFolder = Base.createTempFolder("untitled");
DeleteFilesOnShutdown.add(Base.untitledFolder);

View File

@ -37,8 +37,8 @@ public abstract class AbstractWithPreferencesTest {
@Before
public void init() throws Exception {
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
Base.initPlatform();
Base.getPlatform().init();
BaseNoGui.initPlatform();
BaseNoGui.getPlatform().init();
Preferences.init(null);
Theme.init();