1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-06 01:08:25 +01:00

Removed a handful of static methods delegates

This commit is contained in:
Federico Fissore 2015-05-28 15:25:44 +02:00
parent 8c83281a19
commit c84fb7fc90
10 changed files with 31 additions and 184 deletions

View File

@ -32,6 +32,7 @@
package cc.arduino.packages.formatter; package cc.arduino.packages.formatter;
import processing.app.Base; import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.Editor; import processing.app.Editor;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
import processing.app.syntax.SketchTextArea; import processing.app.syntax.SketchTextArea;
@ -53,7 +54,7 @@ public class AStyle implements Tool {
public AStyle() { public AStyle() {
this.aStyleInterface = new AStyleInterface(); this.aStyleInterface = new AStyleInterface();
File customFormatterConf = Base.getSettingsFile(FORMATTER_CONF); File customFormatterConf = BaseNoGui.getSettingsFile(FORMATTER_CONF);
File defaultFormatterConf = new File(Base.getContentFile("lib"), FORMATTER_CONF); File defaultFormatterConf = new File(Base.getContentFile("lib"), FORMATTER_CONF);
File formatterConf; File formatterConf;

View File

@ -29,10 +29,7 @@
package cc.arduino.view.preferences; package cc.arduino.view.preferences;
import processing.app.Base; import processing.app.*;
import processing.app.Editor;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
import processing.app.legacy.PApplet; import processing.app.legacy.PApplet;
@ -552,10 +549,10 @@ public class Preferences extends javax.swing.JDialog {
File file = Base.selectFolder(_("Select new sketchbook location"), dflt, this); File file = Base.selectFolder(_("Select new sketchbook location"), dflt, this);
if (file != null) { if (file != null) {
String path = file.getAbsolutePath(); String path = file.getAbsolutePath();
if (Base.getPortableFolder() != null) { if (BaseNoGui.getPortableFolder() != null) {
path = FileUtils.relativePath(Base.getPortableFolder().toString(), path); path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
if (path == null) { if (path == null) {
path = Base.getPortableSketchbookFolder(); path = BaseNoGui.getPortableSketchbookFolder();
} }
} }
sketchbookLocationField.setText(path); sketchbookLocationField.setText(path);
@ -626,10 +623,10 @@ public class Preferences extends javax.swing.JDialog {
String oldPath = PreferencesData.get("sketchbook.path"); String oldPath = PreferencesData.get("sketchbook.path");
String newPath = sketchbookLocationField.getText(); String newPath = sketchbookLocationField.getText();
if (newPath.isEmpty()) { if (newPath.isEmpty()) {
if (base.getPortableFolder() == null) { if (BaseNoGui.getPortableFolder() == null) {
newPath = base.getDefaultSketchbookFolderOrPromptForIt().toString(); newPath = base.getDefaultSketchbookFolderOrPromptForIt().toString();
} else { } else {
newPath = base.getPortableSketchbookFolder(); newPath = BaseNoGui.getPortableSketchbookFolder();
} }
} }
if (!newPath.equals(oldPath)) { if (!newPath.equals(oldPath)) {

View File

@ -217,7 +217,7 @@ public class Base {
} }
// Create a location for untitled sketches // Create a location for untitled sketches
untitledFolder = createTempFolder("untitled"); untitledFolder = BaseNoGui.createTempFolder("untitled");
DeleteFilesOnShutdown.add(untitledFolder); DeleteFilesOnShutdown.add(untitledFolder);
INSTANCE = new Base(args); INSTANCE = new Base(args);
@ -347,7 +347,7 @@ public class Base {
List<String> downloadedPackageIndexFiles = installer.updateIndex(); List<String> downloadedPackageIndexFiles = installer.updateIndex();
installer.deleteUnknownFiles(downloadedPackageIndexFiles); installer.deleteUnknownFiles(downloadedPackageIndexFiles);
indexer.parseIndex(); indexer.parseIndex();
indexer.syncWithFilesystem(getHardwareFolder()); indexer.syncWithFilesystem(BaseNoGui.getHardwareFolder());
String[] boardToInstallParts = parser.getBoardToInstall().split(":"); String[] boardToInstallParts = parser.getBoardToInstall().split(":");
@ -680,7 +680,7 @@ public class Base {
// In 0126, untitled sketches will begin in the temp folder, // In 0126, untitled sketches will begin in the temp folder,
// and then moved to a new location because Save will default to Save As. // and then moved to a new location because Save will default to Save As.
File sketchbookDir = getSketchbookFolder(); File sketchbookDir = BaseNoGui.getSketchbookFolder();
File newbieParentDir = untitledFolder; File newbieParentDir = untitledFolder;
// Use a generic name like sketch_031008a, the date plus a char // Use a generic name like sketch_031008a, the date plus a char
@ -805,7 +805,7 @@ public class Base {
public void handleOpenPrompt() throws Exception { public void handleOpenPrompt() throws Exception {
// get the frontmost window frame for placing file dialog // get the frontmost window frame for placing file dialog
FileDialog fd = new FileDialog(activeEditor, _("Open an Arduino sketch..."), FileDialog.LOAD); FileDialog fd = new FileDialog(activeEditor, _("Open an Arduino sketch..."), FileDialog.LOAD);
File lastFolder = new File(PreferencesData.get("last.folder", getSketchbookFolder().getAbsolutePath())); File lastFolder = new File(PreferencesData.get("last.folder", BaseNoGui.getSketchbookFolder().getAbsolutePath()));
if (lastFolder.exists() && lastFolder.isFile()) { if (lastFolder.exists() && lastFolder.isFile()) {
lastFolder = lastFolder.getParentFile(); lastFolder = lastFolder.getParentFile();
} }
@ -1037,7 +1037,7 @@ public class Base {
// Add a list of all sketches and subfolders // Add a list of all sketches and subfolders
try { try {
boolean sketches = addSketches(menu, getSketchbookFolder(), true); boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true);
if (sketches) menu.addSeparator(); if (sketches) menu.addSeparator();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -1058,7 +1058,7 @@ public class Base {
//new Exception().printStackTrace(); //new Exception().printStackTrace();
try { try {
menu.removeAll(); menu.removeAll();
addSketches(menu, getSketchbookFolder(), false); addSketches(menu, BaseNoGui.getSketchbookFolder(), false);
//addSketches(menu, getSketchbookFolder()); //addSketches(menu, getSketchbookFolder());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -1111,7 +1111,7 @@ public class Base {
importMenu.addSeparator(); importMenu.addSeparator();
// Split between user supplied libraries and IDE libraries // Split between user supplied libraries and IDE libraries
TargetPlatform targetPlatform = getTargetPlatform(); TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
if (targetPlatform != null) { if (targetPlatform != null) {
List<ContributedLibrary> libs = getSortedLibraries(); List<ContributedLibrary> libs = getSortedLibraries();
@ -1338,7 +1338,7 @@ public class Base {
@SuppressWarnings("serial") @SuppressWarnings("serial")
Action action = new AbstractAction(board.getName()) { Action action = new AbstractAction(board.getName()) {
public void actionPerformed(ActionEvent actionevent) { public void actionPerformed(ActionEvent actionevent) {
selectBoard((TargetBoard) getValue("b")); BaseNoGui.selectBoard((TargetBoard) getValue("b"));
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1); filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
onBoardOrPortChange(); onBoardOrPortChange();
@ -1461,15 +1461,6 @@ public class Base {
throw new IllegalStateException("Menu has no enabled items"); throw new IllegalStateException("Menu has no enabled items");
} }
private void selectBoard(TargetBoard targetBoard) {
BaseNoGui.selectBoard(targetBoard);
}
public static void selectSerialPort(String port) {
BaseNoGui.selectSerialPort(port);
}
public void rebuildProgrammerMenu(JMenu menu) { public void rebuildProgrammerMenu(JMenu menu) {
menu.removeAll(); menu.removeAll();
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
@ -1658,14 +1649,6 @@ public class Base {
return list; return list;
} }
protected void loadHardware(File folder) {
BaseNoGui.loadHardware(folder);
}
// .................................................................
/** /**
* Show the About box. * Show the About box.
*/ */
@ -1712,153 +1695,19 @@ public class Base {
dialog.setVisible(true); dialog.setVisible(true);
} }
/**
* Convenience method to get a File object for the specified filename inside
* the settings folder.
* For now, only used by Preferences to get the preferences.txt file.
*
* @param filename A file inside the settings folder.
* @return filename wrapped as a File object inside the settings folder
*/
static public File getSettingsFile(String filename) {
return BaseNoGui.getSettingsFile(filename);
}
static public File getBuildFolder() {
return BaseNoGui.getBuildFolder();
}
/**
* Get the path to the platform's temporary folder, by creating
* a temporary temporary file and getting its parent folder.
* <br/>
* Modified for revision 0094 to actually make the folder randomized
* to avoid conflicts in multi-user environments. (Bug 177)
*/
static public File createTempFolder(String name) {
return BaseNoGui.createTempFolder(name);
}
// XXX: Remove this method and make librariesIndexer non-static // XXX: Remove this method and make librariesIndexer non-static
static public LibraryList getLibraries() { static public LibraryList getLibraries() {
return BaseNoGui.librariesIndexer.getInstalledLibraries(); return BaseNoGui.librariesIndexer.getInstalledLibraries();
} }
static public String getExamplesPath() {
return BaseNoGui.getExamplesPath();
}
static public List<File> getLibrariesPath() {
return BaseNoGui.getLibrariesPath();
}
static public File getToolsFolder() {
return BaseNoGui.getToolsFolder();
}
static public String getToolsPath() {
return BaseNoGui.getToolsPath();
}
static public File getHardwareFolder() {
return BaseNoGui.getHardwareFolder();
}
//Get the core libraries
static public File getCoreLibraries(String path) {
return getContentFile(path);
}
static public String getHardwarePath() {
return BaseNoGui.getHardwarePath();
}
static public String getAvrBasePath() {
return BaseNoGui.getAvrBasePath();
}
/**
* Returns a specific TargetPackage
*
* @param packageName
* @return
*/
static public TargetPackage getTargetPackage(String packageName) {
return BaseNoGui.getTargetPackage(packageName);
}
/**
* Returns the currently selected TargetPlatform.
*
* @return
*/
static public TargetPlatform getTargetPlatform() {
return BaseNoGui.getTargetPlatform();
}
/**
* Returns a specific TargetPlatform searching Package/Platform
*
* @param packageName
* @param platformName
* @return
*/
static public TargetPlatform getTargetPlatform(String packageName,
String platformName) {
return BaseNoGui.getTargetPlatform(packageName, platformName);
}
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
return BaseNoGui.getCurrentTargetPlatformFromPackage(pack);
}
static public PreferencesMap getBoardPreferences() {
return BaseNoGui.getBoardPreferences();
}
public List<JMenu> getBoardsCustomMenus() { public List<JMenu> getBoardsCustomMenus() {
return boardsCustomMenus; return boardsCustomMenus;
} }
static public File getPortableFolder() {
return BaseNoGui.getPortableFolder();
}
static public String getPortableSketchbookFolder() {
return BaseNoGui.getPortableSketchbookFolder();
}
static public File getSketchbookFolder() {
return BaseNoGui.getSketchbookFolder();
}
static public File getSketchbookLibrariesFolder() {
return BaseNoGui.getSketchbookLibrariesFolder();
}
static public String getSketchbookLibrariesPath() { static public String getSketchbookLibrariesPath() {
return getSketchbookLibrariesFolder().getAbsolutePath(); return BaseNoGui.getSketchbookLibrariesFolder().getAbsolutePath();
} }
static public File getSketchbookHardwareFolder() {
return BaseNoGui.getSketchbookHardwareFolder();
}
public File getDefaultSketchbookFolderOrPromptForIt() { public File getDefaultSketchbookFolderOrPromptForIt() {
File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder(); File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder();
@ -2578,7 +2427,7 @@ public class Base {
} }
// copy folder // copy folder
File destinationFolder = new File(getSketchbookLibrariesFolder(), sourceFile.getName()); File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
if (!destinationFolder.mkdir()) { if (!destinationFolder.mkdir()) {
activeEditor.statusError(I18n.format(_("A library named {0} already exists"), sourceFile.getName())); activeEditor.statusError(I18n.format(_("A library named {0} already exists"), sourceFile.getName()));
return; return;

View File

@ -766,8 +766,8 @@ public class Editor extends JFrame implements RunnerListener {
}); });
toolsMenu.add(item); toolsMenu.add(item);
addTools(toolsMenu, Base.getToolsFolder()); addTools(toolsMenu, BaseNoGui.getToolsFolder());
File sketchbookTools = new File(Base.getSketchbookFolder(), "tools"); File sketchbookTools = new File(BaseNoGui.getSketchbookFolder(), "tools");
addTools(toolsMenu, sketchbookTools); addTools(toolsMenu, sketchbookTools);
toolsMenu.addSeparator(); toolsMenu.addSeparator();
@ -1108,7 +1108,7 @@ public class Editor extends JFrame implements RunnerListener {
} }
if (selection != null) selection.setState(true); if (selection != null) selection.setState(true);
//System.out.println(item.getLabel()); //System.out.println(item.getLabel());
Base.selectSerialPort(name); BaseNoGui.selectSerialPort(name);
if (serialMonitor != null) { if (serialMonitor != null) {
try { try {
serialMonitor.close(); serialMonitor.close();
@ -2891,7 +2891,7 @@ public class Editor extends JFrame implements RunnerListener {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
protected void onBoardOrPortChange() { protected void onBoardOrPortChange() {
Map<String, String> boardPreferences = Base.getBoardPreferences(); Map<String, String> boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) if (boardPreferences != null)
lineStatus.setBoardName(boardPreferences.get("name")); lineStatus.setBoardName(boardPreferences.get("name"));
else else

View File

@ -35,7 +35,7 @@ class EditorConsoleStream extends OutputStream {
// sister IDEs) might collide with the file causing permissions problems. // sister IDEs) might collide with the file causing permissions problems.
// The files and folders are not deleted on exit because they may be // The files and folders are not deleted on exit because they may be
// needed for debugging or bug reporting. // needed for debugging or bug reporting.
tempFolder = Base.createTempFolder("console"); tempFolder = BaseNoGui.createTempFolder("console");
DeleteFilesOnShutdown.add(tempFolder); DeleteFilesOnShutdown.add(tempFolder);
try { try {
String outFileName = PreferencesData.get("console.output.file"); String outFileName = PreferencesData.get("console.output.file");

View File

@ -91,7 +91,7 @@ public class EditorLineStatus extends JComponent {
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
if (name == "" && serialport == "") { if (name == "" && serialport == "") {
PreferencesMap boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
if (boardPreferences != null) if (boardPreferences != null)
setBoardName(boardPreferences.get("name")); setBoardName(boardPreferences.get("name"));
else else

View File

@ -465,7 +465,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String message = ""; String message = "";
message += _("Arduino: ") + BaseNoGui.VERSION_NAME_LONG + " (" + System.getProperty("os.name") + "), "; message += _("Arduino: ") + BaseNoGui.VERSION_NAME_LONG + " (" + System.getProperty("os.name") + "), ";
message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n\n"; message += _("Board: ") + "\"" + BaseNoGui.getBoardPreferences().get("name") + "\"\n\n";
message += editor.console.consoleTextPane.getText().trim(); message += editor.console.consoleTextPane.getText().trim();
if ((PreferencesData.getBoolean("build.verbose")) == false) { if ((PreferencesData.getBoolean("build.verbose")) == false) {
message += "\n\n"; message += "\n\n";

View File

@ -86,7 +86,7 @@ public class Sketch {
"the application to complete the repair.", null); "the application to complete the repair.", null);
} }
*/ */
tempBuildFolder = Base.getBuildFolder(); tempBuildFolder = BaseNoGui.getBuildFolder();
//Base.addBuildFolderToClassPath(); //Base.addBuildFolderToClassPath();
load(); load();
@ -643,7 +643,7 @@ public class Sketch {
FileDialog fd = new FileDialog(editor, _("Save sketch folder as..."), FileDialog.SAVE); FileDialog fd = new FileDialog(editor, _("Save sketch folder as..."), FileDialog.SAVE);
if (isReadOnly() || isUntitled()) { if (isReadOnly() || isUntitled()) {
// default to the sketchbook folder // default to the sketchbook folder
fd.setDirectory(Base.getSketchbookFolder().getAbsolutePath()); fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
} else { } else {
// default to the parent folder of where this was // default to the parent folder of where this was
// on macs a .getParentFile() method is required // on macs a .getParentFile() method is required
@ -1297,11 +1297,11 @@ public class Sketch {
*/ */
public boolean isReadOnly() { public boolean isReadOnly() {
String apath = data.getFolder().getAbsolutePath(); String apath = data.getFolder().getAbsolutePath();
for (File folder : Base.getLibrariesPath()) { for (File folder : BaseNoGui.getLibrariesPath()) {
if (apath.startsWith(folder.getAbsolutePath())) if (apath.startsWith(folder.getAbsolutePath()))
return true; return true;
} }
if (apath.startsWith(Base.getExamplesPath()) || if (apath.startsWith(BaseNoGui.getExamplesPath()) ||
apath.startsWith(Base.getSketchbookLibrariesPath())) { apath.startsWith(Base.getSketchbookLibrariesPath())) {
return true; return true;
} }

View File

@ -56,7 +56,7 @@ public abstract class AbstractGUITest {
JPopupMenu.setDefaultLightWeightPopupEnabled(false); JPopupMenu.setDefaultLightWeightPopupEnabled(false);
Theme.init(); Theme.init();
BaseNoGui.getPlatform().setLookAndFeel(); BaseNoGui.getPlatform().setLookAndFeel();
Base.untitledFolder = Base.createTempFolder("untitled"); Base.untitledFolder = BaseNoGui.createTempFolder("untitled");
DeleteFilesOnShutdown.add(Base.untitledFolder); DeleteFilesOnShutdown.add(Base.untitledFolder);
window = GuiActionRunner.execute(new GuiQuery<ArduinoFrameFixture>() { window = GuiActionRunner.execute(new GuiQuery<ArduinoFrameFixture>() {

View File

@ -44,7 +44,7 @@ public abstract class AbstractWithPreferencesTest {
BaseNoGui.initPackages(); BaseNoGui.initPackages();
Base.untitledFolder = Base.createTempFolder("untitled"); Base.untitledFolder = BaseNoGui.createTempFolder("untitled");
DeleteFilesOnShutdown.add(Base.untitledFolder); DeleteFilesOnShutdown.add(Base.untitledFolder);
} }