1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-29 18:52:13 +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;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.Editor;
import processing.app.helpers.FileUtils;
import processing.app.syntax.SketchTextArea;
@ -53,7 +54,7 @@ public class AStyle implements Tool {
public AStyle() {
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 formatterConf;

View File

@ -29,10 +29,7 @@
package cc.arduino.view.preferences;
import processing.app.Base;
import processing.app.Editor;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.*;
import processing.app.helpers.FileUtils;
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);
if (file != null) {
String path = file.getAbsolutePath();
if (Base.getPortableFolder() != null) {
path = FileUtils.relativePath(Base.getPortableFolder().toString(), path);
if (BaseNoGui.getPortableFolder() != null) {
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
if (path == null) {
path = Base.getPortableSketchbookFolder();
path = BaseNoGui.getPortableSketchbookFolder();
}
}
sketchbookLocationField.setText(path);
@ -626,10 +623,10 @@ public class Preferences extends javax.swing.JDialog {
String oldPath = PreferencesData.get("sketchbook.path");
String newPath = sketchbookLocationField.getText();
if (newPath.isEmpty()) {
if (base.getPortableFolder() == null) {
if (BaseNoGui.getPortableFolder() == null) {
newPath = base.getDefaultSketchbookFolderOrPromptForIt().toString();
} else {
newPath = base.getPortableSketchbookFolder();
newPath = BaseNoGui.getPortableSketchbookFolder();
}
}
if (!newPath.equals(oldPath)) {

View File

@ -217,7 +217,7 @@ public class Base {
}
// Create a location for untitled sketches
untitledFolder = createTempFolder("untitled");
untitledFolder = BaseNoGui.createTempFolder("untitled");
DeleteFilesOnShutdown.add(untitledFolder);
INSTANCE = new Base(args);
@ -347,7 +347,7 @@ public class Base {
List<String> downloadedPackageIndexFiles = installer.updateIndex();
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
indexer.parseIndex();
indexer.syncWithFilesystem(getHardwareFolder());
indexer.syncWithFilesystem(BaseNoGui.getHardwareFolder());
String[] boardToInstallParts = parser.getBoardToInstall().split(":");
@ -680,7 +680,7 @@ public class Base {
// In 0126, untitled sketches will begin in the temp folder,
// and then moved to a new location because Save will default to Save As.
File sketchbookDir = getSketchbookFolder();
File sketchbookDir = BaseNoGui.getSketchbookFolder();
File newbieParentDir = untitledFolder;
// Use a generic name like sketch_031008a, the date plus a char
@ -805,7 +805,7 @@ public class Base {
public void handleOpenPrompt() throws Exception {
// get the frontmost window frame for placing file dialog
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()) {
lastFolder = lastFolder.getParentFile();
}
@ -1037,7 +1037,7 @@ public class Base {
// Add a list of all sketches and subfolders
try {
boolean sketches = addSketches(menu, getSketchbookFolder(), true);
boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true);
if (sketches) menu.addSeparator();
} catch (IOException e) {
e.printStackTrace();
@ -1058,7 +1058,7 @@ public class Base {
//new Exception().printStackTrace();
try {
menu.removeAll();
addSketches(menu, getSketchbookFolder(), false);
addSketches(menu, BaseNoGui.getSketchbookFolder(), false);
//addSketches(menu, getSketchbookFolder());
} catch (IOException e) {
e.printStackTrace();
@ -1111,7 +1111,7 @@ public class Base {
importMenu.addSeparator();
// Split between user supplied libraries and IDE libraries
TargetPlatform targetPlatform = getTargetPlatform();
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
if (targetPlatform != null) {
List<ContributedLibrary> libs = getSortedLibraries();
@ -1338,7 +1338,7 @@ public class Base {
@SuppressWarnings("serial")
Action action = new AbstractAction(board.getName()) {
public void actionPerformed(ActionEvent actionevent) {
selectBoard((TargetBoard) getValue("b"));
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
onBoardOrPortChange();
@ -1461,15 +1461,6 @@ public class Base {
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) {
menu.removeAll();
ButtonGroup group = new ButtonGroup();
@ -1658,14 +1649,6 @@ public class Base {
return list;
}
protected void loadHardware(File folder) {
BaseNoGui.loadHardware(folder);
}
// .................................................................
/**
* Show the About box.
*/
@ -1712,153 +1695,19 @@ public class Base {
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
static public LibraryList getLibraries() {
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() {
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() {
return getSketchbookLibrariesFolder().getAbsolutePath();
return BaseNoGui.getSketchbookLibrariesFolder().getAbsolutePath();
}
static public File getSketchbookHardwareFolder() {
return BaseNoGui.getSketchbookHardwareFolder();
}
public File getDefaultSketchbookFolderOrPromptForIt() {
File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder();
@ -2578,7 +2427,7 @@ public class Base {
}
// copy folder
File destinationFolder = new File(getSketchbookLibrariesFolder(), sourceFile.getName());
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
if (!destinationFolder.mkdir()) {
activeEditor.statusError(I18n.format(_("A library named {0} already exists"), sourceFile.getName()));
return;

View File

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

View File

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

View File

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

View File

@ -465,7 +465,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
public void actionPerformed(ActionEvent e) {
String message = "";
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();
if ((PreferencesData.getBoolean("build.verbose")) == false) {
message += "\n\n";

View File

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

View File

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

View File

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