1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Preparing the ground for rewriting Preferences GUI code (and hopefully fixing the tiny-pref-window bug on macosx)

This commit is contained in:
Federico Fissore 2015-05-05 10:02:12 +02:00
parent 7e7a9d0fe8
commit 9b58812d1d
19 changed files with 149 additions and 206 deletions

View File

@ -45,7 +45,7 @@ import java.io.*;
public void show() {
String originalText = editor.textarea.getText();
int indentSize = Preferences.getInteger("editor.tabs.size");
int indentSize = PreferencesData.getInteger("editor.tabs.size");
//

View File

@ -78,7 +78,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
getContentPane().setLayout(new BorderLayout());
Font consoleFont = Theme.getFont("console.font");
Font editorFont = Preferences.getFont("editor.font");
Font editorFont = PreferencesData.getFont("editor.font");
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
textArea = new TextAreaFIFO(8000000);
@ -124,12 +124,12 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
lineEndings = new JComboBox(new String[]{_("No line ending"), _("Newline"), _("Carriage return"), _("Both NL & CR")});
lineEndings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Preferences.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
noLineEndingAlert.setForeground(pane.getBackground());
}
});
if (Preferences.get("serial.line_ending") != null) {
lineEndings.setSelectedIndex(Preferences.getInteger("serial.line_ending"));
if (PreferencesData.get("serial.line_ending") != null) {
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
}
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
@ -160,13 +160,13 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
pack();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (Preferences.get("last.screen.height") != null) {
if (PreferencesData.get("last.screen.height") != null) {
// if screen size has changed, the window coordinates no longer
// make sense, so don't use them unless they're identical
int screenW = Preferences.getInteger("last.screen.width");
int screenH = Preferences.getInteger("last.screen.height");
int screenW = PreferencesData.getInteger("last.screen.width");
int screenH = PreferencesData.getInteger("last.screen.height");
if ((screen.width == screenW) && (screen.height == screenH)) {
String locationStr = Preferences.get("last.serial.location");
String locationStr = PreferencesData.get("last.serial.location");
if (locationStr != null) {
int[] location = PApplet.parseInt(PApplet.split(locationStr, ','));
setPlacement(location);

View File

@ -143,7 +143,7 @@ public class Base {
BaseNoGui.initParameters(args);
System.setProperty("swing.aatext", Preferences.get("editor.antialias", "true"));
System.setProperty("swing.aatext", PreferencesData.get("editor.antialias", "true"));
BaseNoGui.initVersion();
@ -257,9 +257,9 @@ public class Base {
if (sketchbookPath == null) {
File defaultFolder = getDefaultSketchbookFolderOrPromptForIt();
if (BaseNoGui.getPortableFolder() != null)
Preferences.set("sketchbook.path", BaseNoGui.getPortableSketchbookFolder());
PreferencesData.set("sketchbook.path", BaseNoGui.getPortableSketchbookFolder());
else
Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath());
PreferencesData.set("sketchbook.path", defaultFolder.getAbsolutePath());
if (!defaultFolder.exists()) {
defaultFolder.mkdirs();
}
@ -293,7 +293,7 @@ public class Base {
boolean showEditor = parser.isGuiMode();
if (!parser.isForceSavePrefs())
Preferences.setDoSave(showEditor);
PreferencesData.setDoSave(showEditor);
if (handleOpen(file, nextEditorLocation(), showEditor) == null) {
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
// Open failure is fatal in upload/verify mode
@ -406,13 +406,13 @@ public class Base {
} else if (parser.isVerifyOrUploadMode()) {
splashScreenHelper.close();
// Set verbosity for command line build
Preferences.set("build.verbose", "" + parser.isDoVerboseBuild());
Preferences.set("upload.verbose", "" + parser.isDoVerboseUpload());
Preferences.set("runtime.preserve.temp.files", Boolean.toString(parser.isPreserveTempFiles()));
PreferencesData.set("build.verbose", "" + parser.isDoVerboseBuild());
PreferencesData.set("upload.verbose", "" + parser.isDoVerboseUpload());
PreferencesData.set("runtime.preserve.temp.files", Boolean.toString(parser.isPreserveTempFiles()));
// Make sure these verbosity preferences are only for the
// current session
Preferences.setDoSave(false);
PreferencesData.setDoSave(false);
Editor editor = editors.get(0);
@ -443,14 +443,14 @@ public class Base {
}
// Check for updates
if (Preferences.getBoolean("update.check")) {
if (PreferencesData.getBoolean("update.check")) {
new UpdateCheck(this);
}
} else if (parser.isNoOpMode()) {
// Do nothing (intended for only changing preferences)
System.exit(0);
} else if (parser.isGetPrefMode()) {
String value = Preferences.get(parser.getGetPref(), null);
String value = PreferencesData.get(parser.getGetPref(), null);
if (value != null) {
System.out.println(value);
System.exit(0);
@ -474,11 +474,11 @@ public class Base {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
boolean windowPositionValid = true;
if (Preferences.get("last.screen.height") != null) {
if (PreferencesData.get("last.screen.height") != null) {
// if screen size has changed, the window coordinates no longer
// make sense, so don't use them unless they're identical
int screenW = Preferences.getInteger("last.screen.width");
int screenH = Preferences.getInteger("last.screen.height");
int screenW = PreferencesData.getInteger("last.screen.width");
int screenH = PreferencesData.getInteger("last.screen.height");
if ((screen.width != screenW) || (screen.height != screenH)) {
windowPositionValid = false;
@ -499,10 +499,10 @@ public class Base {
// If !windowPositionValid, then ignore the coordinates found for each.
// Save the sketch path and window placement for each open sketch
int count = Preferences.getInteger("last.sketch.count");
int count = PreferencesData.getInteger("last.sketch.count");
int opened = 0;
for (int i = 0; i < count; i++) {
String path = Preferences.get("last.sketch" + i + ".path");
String path = PreferencesData.get("last.sketch" + i + ".path");
if (BaseNoGui.getPortableFolder() != null) {
File absolute = new File(BaseNoGui.getPortableFolder(), path);
try {
@ -513,7 +513,7 @@ public class Base {
}
int[] location;
if (windowPositionValid) {
String locationStr = Preferences.get("last.sketch" + i + ".location");
String locationStr = PreferencesData.get("last.sketch" + i + ".location");
location = PApplet.parseInt(PApplet.split(locationStr, ','));
} else {
location = nextEditorLocation();
@ -534,8 +534,8 @@ public class Base {
protected void storeSketches() {
// Save the width and height of the screen
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Preferences.setInteger("last.screen.width", screen.width);
Preferences.setInteger("last.screen.height", screen.height);
PreferencesData.setInteger("last.screen.width", screen.width);
PreferencesData.setInteger("last.screen.height", screen.height);
String untitledPath = untitledFolder.getAbsolutePath();
@ -554,14 +554,14 @@ public class Base {
if (path == null)
continue;
}
Preferences.set("last.sketch" + index + ".path", path);
PreferencesData.set("last.sketch" + index + ".path", path);
int[] location = editor.getPlacement();
String locationStr = PApplet.join(PApplet.str(location), ",");
Preferences.set("last.sketch" + index + ".location", locationStr);
PreferencesData.set("last.sketch" + index + ".location", locationStr);
index++;
}
Preferences.setInteger("last.sketch.count", index);
PreferencesData.setInteger("last.sketch.count", index);
}
@ -577,7 +577,7 @@ public class Base {
if (path == null)
path = "";
}
Preferences.set("last.sketch" + index + ".path", path);
PreferencesData.set("last.sketch" + index + ".path", path);
}
@ -616,8 +616,8 @@ public class Base {
protected int[] nextEditorLocation() {
int defaultWidth = Preferences.getInteger("editor.window.width.default");
int defaultHeight = Preferences.getInteger("editor.window.height.default");
int defaultWidth = PreferencesData.getInteger("editor.window.width.default");
int defaultHeight = PreferencesData.getInteger("editor.window.height.default");
if (activeEditor == null) {
Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
@ -808,7 +808,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(Preferences.get("last.folder", getSketchbookFolder().getAbsolutePath()));
File lastFolder = new File(PreferencesData.get("last.folder", getSketchbookFolder().getAbsolutePath()));
if (lastFolder.exists() && lastFolder.isFile()) {
lastFolder = lastFolder.getParentFile();
}
@ -832,7 +832,7 @@ public class Base {
File inputFile = new File(directory, filename);
Preferences.set("last.folder", inputFile.getAbsolutePath());
PreferencesData.set("last.folder", inputFile.getAbsolutePath());
handleOpen(inputFile);
}
@ -1378,9 +1378,9 @@ public class Base {
Map<String, ButtonGroup> buttonGroupsMap,
TargetBoard board, TargetPlatform targetPlatform, TargetPackage targetPackage)
throws Exception {
String selPackage = Preferences.get("target_package");
String selPlatform = Preferences.get("target_platform");
String selBoard = Preferences.get("board");
String selPackage = PreferencesData.get("target_package");
String selPlatform = PreferencesData.get("target_platform");
String selBoard = PreferencesData.get("board");
String boardId = board.getId();
String packageName = targetPackage.getId();
@ -1418,7 +1418,7 @@ public class Base {
@SuppressWarnings("serial")
Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) {
public void actionPerformed(ActionEvent e) {
Preferences.set("custom_" + menuId, ((TargetBoard) getValue("board")).getId() + "_" + getValue("custom_menu_option"));
PreferencesData.set("custom_" + menuId, ((TargetBoard) getValue("board")).getId() + "_" + getValue("custom_menu_option"));
onBoardOrPortChange();
}
};
@ -1433,7 +1433,7 @@ public class Base {
menu.add(subItem);
buttonGroupsMap.get(menuId).add(subItem);
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId);
String selectedCustomMenuEntry = PreferencesData.get("custom_" + menuId);
if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) {
menuItemsToClickAfterStartup.add(subItem);
}
@ -1534,12 +1534,12 @@ public class Base {
AbstractAction action = new AbstractAction(targetPlatform
.getProgrammer(programmer).get("name")) {
public void actionPerformed(ActionEvent actionevent) {
Preferences.set("programmer", "" + getValue("id"));
PreferencesData.set("programmer", "" + getValue("id"));
}
};
action.putValue("id", id);
JMenuItem item = new JRadioButtonMenuItem(action);
if (Preferences.get("programmer").equals(id))
if (PreferencesData.get("programmer").equals(id))
item.setSelected(true);
group.add(item);
menu.add(item);

View File

@ -24,9 +24,6 @@ package processing.app;
import cc.arduino.packages.MonitorFactory;
import cc.arduino.view.*;
import cc.arduino.view.Event;
import cc.arduino.view.EventListener;
import com.jcraft.jsch.JSchException;
import jssc.SerialPortException;
import processing.app.debug.*;
@ -280,7 +277,7 @@ public class Editor extends JFrame implements RunnerListener {
splitPane.setBorder(null);
// the default size on windows is too small and kinda ugly
int dividerSize = Preferences.getInteger("editor.divider.size");
int dividerSize = PreferencesData.getInteger("editor.divider.size");
if (dividerSize != 0) {
splitPane.setDividerSize(dividerSize);
}
@ -312,8 +309,8 @@ public class Editor extends JFrame implements RunnerListener {
// Set the minimum size for the editor window
setMinimumSize(new Dimension(Preferences.getInteger("editor.window.width.min"),
Preferences.getInteger("editor.window.height.min")));
setMinimumSize(new Dimension(PreferencesData.getInteger("editor.window.width.min"),
PreferencesData.getInteger("editor.window.height.min")));
// System.out.println("t3");
// Bring back the general options for the editor
@ -445,13 +442,13 @@ public class Editor extends JFrame implements RunnerListener {
protected void applyPreferences() {
// apply the setting for 'use external editor'
boolean external = Preferences.getBoolean("editor.external");
boolean external = PreferencesData.getBoolean("editor.external");
textarea.setEditable(!external);
saveMenuItem.setEnabled(!external);
saveAsMenuItem.setEnabled(!external);
textarea.setDisplayLineNumbers(Preferences.getBoolean("editor.linenumbers"));
textarea.setDisplayLineNumbers(PreferencesData.getBoolean("editor.linenumbers"));
TextAreaPainter painter = textarea.getPainter();
if (external) {
@ -464,14 +461,14 @@ public class Editor extends JFrame implements RunnerListener {
} else {
Color color = Theme.getColor("editor.bgcolor");
painter.setBackground(color);
boolean highlight = Preferences.getBoolean("editor.linehighlight");
boolean highlight = PreferencesData.getBoolean("editor.linehighlight");
painter.setLineHighlightEnabled(highlight);
textarea.setCaretVisible(true);
}
// apply changes to the font size for the editor
//TextAreaPainter painter = textarea.getPainter();
painter.setFont(Preferences.getFont("editor.font"));
painter.setFont(PreferencesData.getFont("editor.font"));
//Font font = painter.getFont();
//textarea.getPainter().setFont(new Font("Courier", Font.PLAIN, 36));
@ -1023,11 +1020,11 @@ public class Editor extends JFrame implements RunnerListener {
protected void populatePortMenu() {
serialMenu.removeAll();
String selectedPort = Preferences.get("serial.port");
String selectedPort = PreferencesData.get("serial.port");
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
ports = Base.getPlatform().filterPorts(ports, Preferences.getBoolean("serial.ports.showall"));
ports = Base.getPlatform().filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
Collections.sort(ports, new Comparator<BoardPort>() {
@Override
@ -1891,7 +1888,7 @@ public class Editor extends JFrame implements RunnerListener {
protected void handleIndentOutdent(boolean indent) {
int tabSize = Preferences.getInteger("editor.tabs.size");
int tabSize = PreferencesData.getInteger("editor.tabs.size");
String tabString = Editor.EMPTY.substring(0, tabSize);
startCompoundEdit();
@ -1994,7 +1991,7 @@ public class Editor extends JFrame implements RunnerListener {
*/
public void handleRun(final boolean verbose) {
internalCloseRunner();
if (Preferences.getBoolean("editor.save_on_verify")) {
if (PreferencesData.getBoolean("editor.save_on_verify")) {
if (sketch.isModified() && !sketch.isReadOnly()) {
handleSave(true);
}
@ -2007,7 +2004,7 @@ public class Editor extends JFrame implements RunnerListener {
for (int i = 0; i < 10; i++) System.out.println();
// clear the console on each run, unless the user doesn't want to
if (Preferences.getBoolean("console.auto_clear")) {
if (PreferencesData.getBoolean("console.auto_clear")) {
console.clear();
}
@ -2433,7 +2430,7 @@ public class Editor extends JFrame implements RunnerListener {
I18n.format(
_("Serial port {0} not found.\n" +
"Retry the upload with another serial port?"),
Preferences.get("serial.port")
PreferencesData.get("serial.port")
),
"Serial port not found",
JOptionPane.PLAIN_MESSAGE,
@ -2463,7 +2460,7 @@ public class Editor extends JFrame implements RunnerListener {
* hitting export twice, quickly, and horking things up.
*/
synchronized public void handleExport(final boolean usingProgrammer) {
if (Preferences.getBoolean("editor.save_on_verify")) {
if (PreferencesData.getBoolean("editor.save_on_verify")) {
if (sketch.isModified() && !sketch.isReadOnly()) {
handleSave(true);
}
@ -2606,10 +2603,10 @@ public class Editor extends JFrame implements RunnerListener {
}
}
BoardPort port = Base.getDiscoveryManager().find(Preferences.get("serial.port"));
BoardPort port = Base.getDiscoveryManager().find(PreferencesData.get("serial.port"));
if (port == null) {
statusError(I18n.format("Board at {0} is not available", Preferences.get("serial.port")));
statusError(I18n.format("Board at {0} is not available", PreferencesData.get("serial.port")));
return;
}
@ -2618,7 +2615,7 @@ public class Editor extends JFrame implements RunnerListener {
boolean success = false;
do {
if (serialMonitor.requiresAuthorization() && !Preferences.has(serialMonitor.getAuthorizationKey())) {
if (serialMonitor.requiresAuthorization() && !PreferencesData.has(serialMonitor.getAuthorizationKey())) {
PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(this, _("Type board password to access its console"));
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
@ -2628,7 +2625,7 @@ public class Editor extends JFrame implements RunnerListener {
return;
}
Preferences.set(serialMonitor.getAuthorizationKey(), dialog.getPassword());
PreferencesData.set(serialMonitor.getAuthorizationKey(), dialog.getPassword());
}
try {
@ -2649,7 +2646,7 @@ public class Editor extends JFrame implements RunnerListener {
statusError(e);
} finally {
if (serialMonitor.requiresAuthorization() && !success) {
Preferences.remove(serialMonitor.getAuthorizationKey());
PreferencesData.remove(serialMonitor.getAuthorizationKey());
}
}
@ -2829,7 +2826,7 @@ public class Editor extends JFrame implements RunnerListener {
lineStatus.setBoardName(boardPreferences.get("name"));
else
lineStatus.setBoardName("-");
lineStatus.setSerialPort(Preferences.get("serial.port"));
lineStatus.setSerialPort(PreferencesData.get("serial.port"));
lineStatus.repaint();
}

View File

@ -68,7 +68,7 @@ public class EditorConsole extends JScrollPane {
public EditorConsole(Editor _editor) {
editor = _editor;
int maxLineCount = Preferences.getInteger("console.length");
int maxLineCount = PreferencesData.getInteger("console.length");
consoleDoc = new BufferedStyledDocument(4000, maxLineCount);
consoleTextPane = new JTextPane(consoleDoc);
@ -84,7 +84,7 @@ public class EditorConsole extends JScrollPane {
Color fgColorOut = Theme.getColor("console.output.color");
Color fgColorErr = Theme.getColor("console.error.color");
Font consoleFont = Theme.getFont("console.font");
Font editorFont = Preferences.getFont("editor.font");
Font editorFont = PreferencesData.getFont("editor.font");
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
stdStyle = new SimpleAttributeSet();
@ -112,7 +112,7 @@ public class EditorConsole extends JScrollPane {
// and size window accordingly
FontMetrics metrics = getFontMetrics(font);
int height = metrics.getAscent() + metrics.getDescent();
int lines = Preferences.getInteger("console.lines");
int lines = PreferencesData.getInteger("console.lines");
int sizeFudge = 6; //10; // unclear why this is necessary, but it is
setPreferredSize(new Dimension(1024, (height * lines) + sizeFudge));
setMinimumSize(new Dimension(1024, (height * 4) + sizeFudge));

View File

@ -37,14 +37,14 @@ class EditorConsoleStream extends OutputStream {
tempFolder = Base.createTempFolder("console");
DeleteFilesOnShutdown.add(tempFolder);
try {
String outFileName = Preferences.get("console.output.file");
String outFileName = PreferencesData.get("console.output.file");
if (outFileName != null) {
outFile = new File(tempFolder, outFileName);
DeleteFilesOnShutdown.add(outFile);
stdoutFile = new FileOutputStream(outFile);
}
String errFileName = Preferences.get("console.error.file");
String errFileName = PreferencesData.get("console.error.file");
if (errFileName != null) {
errFile = new File(tempFolder, errFileName);
DeleteFilesOnShutdown.add(errFile);
@ -58,7 +58,7 @@ class EditorConsoleStream extends OutputStream {
consoleOut = new PrintStream(new EditorConsoleStream(false));
consoleErr = new PrintStream(new EditorConsoleStream(true));
if (Preferences.getBoolean("console")) {
if (PreferencesData.getBoolean("console")) {
try {
System.setOut(consoleOut);
System.setErr(consoleErr);

View File

@ -101,7 +101,7 @@ public class EditorLineStatus extends JComponent {
setBoardName(boardPreferences.get("name"));
else
setBoardName("-");
setSerialPort(Preferences.get("serial.port"));
setSerialPort(PreferencesData.get("serial.port"));
}
g.setColor(background);
Dimension size = getSize();

View File

@ -73,12 +73,12 @@ public class EditorListener {
public void applyPreferences() {
tabsExpand = Preferences.getBoolean("editor.tabs.expand");
tabsExpand = PreferencesData.getBoolean("editor.tabs.expand");
//tabsIndent = Preferences.getBoolean("editor.tabs.indent");
tabSize = Preferences.getInteger("editor.tabs.size");
tabSize = PreferencesData.getInteger("editor.tabs.size");
tabString = Editor.EMPTY.substring(0, tabSize);
autoIndent = Preferences.getBoolean("editor.indent");
externalEditor = Preferences.getBoolean("editor.external");
autoIndent = PreferencesData.getBoolean("editor.indent");
externalEditor = PreferencesData.getBoolean("editor.external");
}

View File

@ -219,7 +219,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
public void unprogress()
{
if (Preferences.getBoolean("editor.beep.compile")) {
if (PreferencesData.getBoolean("editor.beep.compile")) {
Toolkit.getDefaultToolkit().beep();
}
if (progressBar == null) return;
@ -467,7 +467,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
message += _("Arduino: ") + BaseNoGui.VERSION_NAME + " (" + System.getProperty("os.name") + "), ";
message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n\n";
message += editor.console.consoleTextPane.getText().trim();
if ((Preferences.getBoolean("build.verbose")) == false) {
if ((PreferencesData.getBoolean("build.verbose")) == false) {
message += "\n\n";
message += " " + _("This report would have more information with") + "\n";
message += " \"" + _("Show verbose output during compilation") + "\"\n";

View File

@ -24,7 +24,6 @@ package processing.app;
import processing.app.helpers.FileUtils;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesHelper;
import processing.app.helpers.PreferencesMap;
import processing.app.legacy.PApplet;
import javax.swing.*;
@ -353,7 +352,7 @@ public class Preferences {
pane.add(box);
d = box.getPreferredSize();
box.setBounds(left, top, d.width, d.height);
Font editorFont = Preferences.getFont("editor.font");
Font editorFont = PreferencesData.getFont("editor.font");
fontSizeField.setText(String.valueOf(editorFont.getSize()));
top += d.height + GUI_BETWEEN;
@ -786,22 +785,22 @@ public class Preferences {
WarningItem warningItem = (WarningItem) comboWarnings.getSelectedItem();
PreferencesData.set("compiler.warning_level", warningItem.getValue());
Preferences.set("proxy.http.server", proxyHTTPServer.getText());
PreferencesData.set("proxy.http.server", proxyHTTPServer.getText());
try {
Preferences.set("proxy.http.port", Integer.valueOf(proxyHTTPPort.getText()).toString());
PreferencesData.set("proxy.http.port", Integer.valueOf(proxyHTTPPort.getText()).toString());
} catch (NumberFormatException e) {
Preferences.remove("proxy.http.port");
PreferencesData.remove("proxy.http.port");
}
Preferences.set("proxy.https.server", proxyHTTPSServer.getText());
PreferencesData.set("proxy.https.server", proxyHTTPSServer.getText());
try {
Preferences.set("proxy.https.port", Integer.valueOf(proxyHTTPSPort.getText()).toString());
PreferencesData.set("proxy.https.port", Integer.valueOf(proxyHTTPSPort.getText()).toString());
} catch (NumberFormatException e) {
Preferences.remove("proxy.https.port");
PreferencesData.remove("proxy.https.port");
}
Preferences.set("proxy.user", proxyUser.getText());
Preferences.set("proxy.password", new String(proxyPassword.getPassword()));
PreferencesData.set("proxy.user", proxyUser.getText());
PreferencesData.set("proxy.password", new String(proxyPassword.getPassword()));
Preferences.set("boardsmanager.additional.urls", additionalBoardsManagerField.getText().replace("\r\n", "\n").replace("\r", "\n").replace("\n", ","));
PreferencesData.set("boardsmanager.additional.urls", additionalBoardsManagerField.getText().replace("\r\n", "\n").replace("\r", "\n").replace("\n", ","));
editor.applyPreferences();
}
@ -834,22 +833,22 @@ public class Preferences {
updateExtensionBox.setSelected(PreferencesData.get("editor.update_extension") == null || PreferencesData.getBoolean("editor.update_extension"));
proxyHTTPServer.setText(Preferences.get("proxy.http.server"));
proxyHTTPServer.setText(PreferencesData.get("proxy.http.server"));
try {
proxyHTTPPort.setText(Integer.toString(Preferences.getInteger("proxy.http.port", 8080)));
proxyHTTPPort.setText(Integer.toString(PreferencesData.getInteger("proxy.http.port", 8080)));
} catch (NumberFormatException e) {
proxyHTTPPort.setText("");
}
proxyHTTPSServer.setText(Preferences.get("proxy.https.server"));
proxyHTTPSServer.setText(PreferencesData.get("proxy.https.server"));
try {
proxyHTTPSPort.setText(Integer.toString(Preferences.getInteger("proxy.https.port", 8443)));
proxyHTTPSPort.setText(Integer.toString(PreferencesData.getInteger("proxy.https.port", 8443)));
} catch (NumberFormatException e) {
proxyHTTPSPort.setText("");
}
proxyUser.setText(Preferences.get("proxy.user"));
proxyPassword.setText(Preferences.get("proxy.password"));
proxyUser.setText(PreferencesData.get("proxy.user"));
proxyPassword.setText(PreferencesData.get("proxy.password"));
additionalBoardsManagerField.setText(Preferences.get("boardsmanager.additional.urls"));
additionalBoardsManagerField.setText(PreferencesData.get("boardsmanager.additional.urls"));
dialog.setLocationRelativeTo(editor);
dialog.setVisible(true);
@ -863,76 +862,4 @@ public class Preferences {
// .................................................................
static public String get(String attribute) {
return PreferencesData.get(attribute);
}
static public String get(String attribute, String defaultValue) {
return PreferencesData.get(attribute, defaultValue);
}
public static boolean has(String key) {
return PreferencesData.has(key);
}
public static void remove(String key) {
PreferencesData.remove(key);
}
static public void set(String attribute, String value) {
PreferencesData.set(attribute, value);
}
static public boolean getBoolean(String attribute) {
return PreferencesData.getBoolean(attribute);
}
static public void setBoolean(String attribute, boolean value) {
PreferencesData.setBoolean(attribute, value);
}
static public int getInteger(String attribute) {
return PreferencesData.getInteger(attribute);
}
static public int getInteger(String attribute, int defaultValue) {
if (PreferencesData.has(attribute)) {
return PreferencesData.getInteger(attribute);
}
return defaultValue;
}
static public void setInteger(String key, int value) {
PreferencesData.setInteger(key, value);
}
static public Font getFont(String attr) {
Font font = PreferencesHelper.getFont(PreferencesData.prefs, attr);
if (font == null) {
String value = PreferencesData.defaults.get(attr);
PreferencesData.prefs.put(attr, value);
font = PreferencesHelper.getFont(PreferencesData.prefs, attr);
}
return font;
}
// get a copy of the Preferences
static public PreferencesMap getMap()
{
return PreferencesData.getMap();
}
// Decide wether changed preferences will be saved. When value is
// false, Preferences.save becomes a no-op.
static public void setDoSave(boolean value)
{
PreferencesData.setDoSave(value);
}
}

View File

@ -74,14 +74,14 @@ public class PresentMode {
public void actionPerformed(ActionEvent e) {
int index = selector.getSelectedIndex();
//device = devices[index];
Preferences.setInteger("run.present.display", index + 1);
PreferencesData.setInteger("run.present.display", index + 1);
}
});
}
static public JComboBox getSelector() {
int deviceIndex = Preferences.getInteger("run.present.display") - 1;
int deviceIndex = PreferencesData.getInteger("run.present.display") - 1;
selector.setSelectedIndex(deviceIndex);
return selector;
}

View File

@ -39,14 +39,14 @@ public class SerialMonitor extends AbstractMonitor {
this.port = port.getAddress();
serialRate = Preferences.getInteger("serial.debug_rate");
serialRate = PreferencesData.getInteger("serial.debug_rate");
serialRates.setSelectedItem(serialRate + " " + _("baud"));
onSerialRateChange(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String wholeString = (String) serialRates.getSelectedItem();
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
serialRate = Integer.parseInt(rateString);
Preferences.set("serial.debug_rate", rateString);
PreferencesData.set("serial.debug_rate", rateString);
try {
close();
Thread.sleep(100); // Wait for serial port to properly close
@ -80,9 +80,9 @@ public class SerialMonitor extends AbstractMonitor {
s += "\r\n";
break;
}
if ("".equals(s) && lineEndings.getSelectedIndex() == 0 && !Preferences.has("runtime.line.ending.alert.notified")) {
if ("".equals(s) && lineEndings.getSelectedIndex() == 0 && !PreferencesData.has("runtime.line.ending.alert.notified")) {
noLineEndingAlert.setForeground(Color.RED);
Preferences.set("runtime.line.ending.alert.notified", "true");
PreferencesData.set("runtime.line.ending.alert.notified", "true");
}
serial.write(s);
}
@ -103,7 +103,7 @@ public class SerialMonitor extends AbstractMonitor {
if (serial != null) {
int[] location = getPlacement();
String locationStr = PApplet.join(PApplet.str(location), ",");
Preferences.set("last.serial.location", locationStr);
PreferencesData.set("last.serial.location", locationStr);
textArea.setText("");
serial.dispose();
serial = null;

View File

@ -575,7 +575,7 @@ public class Sketch {
});
if (pdeFiles != null && pdeFiles.length > 0) {
if (Preferences.get("editor.update_extension") == null) {
if (PreferencesData.get("editor.update_extension") == null) {
Object[] options = { _("OK"), _("Cancel") };
int result = JOptionPane.showOptionDialog(editor,
_("In Arduino 1.0, the default file extension has changed\n" +
@ -594,10 +594,10 @@ public class Sketch {
if (result != JOptionPane.OK_OPTION) return false; // save cancelled
Preferences.setBoolean("editor.update_extension", true);
PreferencesData.setBoolean("editor.update_extension", true);
}
if (Preferences.getBoolean("editor.update_extension")) {
if (PreferencesData.getBoolean("editor.update_extension")) {
// Do rename of all .pde files to new .ino extension
for (File pdeFile : pdeFiles)
renameCodeToInoExtension(pdeFile);
@ -801,7 +801,7 @@ public class Sketch {
if (result) {
editor.statusNotice(_("One file added to the sketch."));
Preferences.set("last.folder", sourceFile.getAbsolutePath());
PreferencesData.set("last.folder", sourceFile.getAbsolutePath());
}
}
@ -1059,7 +1059,7 @@ public class Sketch {
// if an external editor is being used, need to grab the
// latest version of the code from the file.
if (Preferences.getBoolean("editor.external")) {
if (PreferencesData.getBoolean("editor.external")) {
// history gets screwed by the open..
//String historySaved = history.lastRecorded;
//handleOpen(sketch);
@ -1202,7 +1202,7 @@ public class Sketch {
boolean success = false;
do {
if (uploader.requiresAuthorization() && !Preferences.has(uploader.getAuthorizationKey())) {
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(editor, _("Type board password to upload a new sketch"));
dialog.setLocationRelativeTo(editor);
dialog.setVisible(true);
@ -1212,7 +1212,7 @@ public class Sketch {
return false;
}
Preferences.set(uploader.getAuthorizationKey(), dialog.getPassword());
PreferencesData.set(uploader.getAuthorizationKey(), dialog.getPassword());
}
List<String> warningsAccumulator = new LinkedList<String>();
@ -1220,7 +1220,7 @@ public class Sketch {
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
} finally {
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
PreferencesData.remove(uploader.getAuthorizationKey());
}
}

View File

@ -69,11 +69,11 @@ public class UpdateCheck implements Runnable {
Random r = new Random();
long id = r.nextLong();
String idString = Preferences.get("update.id");
String idString = PreferencesData.get("update.id");
if (idString != null) {
id = Long.parseLong(idString);
} else {
Preferences.set("update.id", String.valueOf(id));
PreferencesData.set("update.id", String.valueOf(id));
}
try {
@ -88,7 +88,7 @@ public class UpdateCheck implements Runnable {
int latest = readInt(downloadURL + "?" + info);
String lastString = Preferences.get("update.last");
String lastString = PreferencesData.get("update.last");
long now = System.currentTimeMillis();
if (lastString != null) {
long when = Long.parseLong(lastString);
@ -97,7 +97,7 @@ public class UpdateCheck implements Runnable {
return;
}
}
Preferences.set("update.last", String.valueOf(now));
PreferencesData.set("update.last", String.valueOf(now));
String prompt =
_("A new version of Arduino is available,\n" +

View File

@ -44,7 +44,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
inputHandler.addKeyBinding("BACK_SPACE", InputHandler.BACKSPACE);
// for 0122, shift-backspace is delete, for 0176, it's now a preference,
// to prevent holy warriors from attacking me for it.
if (Preferences.getBoolean("editor.keys.shift_backspace_is_delete")) {
if (PreferencesData.getBoolean("editor.keys.shift_backspace_is_delete")) {
inputHandler.addKeyBinding("S+BACK_SPACE", InputHandler.DELETE);
} else {
inputHandler.addKeyBinding("S+BACK_SPACE", InputHandler.BACKSPACE);
@ -65,7 +65,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
// http://dev.processing.org/bugs/show_bug.cgi?id=162
// added for 0176, though the bindings do not appear relevant for osx
if (Preferences.getBoolean("editor.keys.alternative_cut_copy_paste")) {
if (PreferencesData.getBoolean("editor.keys.alternative_cut_copy_paste")) {
inputHandler.addKeyBinding("C+INSERT", InputHandler.CLIPBOARD_COPY);
inputHandler.addKeyBinding("S+INSERT", InputHandler.CLIPBOARD_PASTE);
inputHandler.addKeyBinding("S+DELETE", InputHandler.CLIPBOARD_CUT);
@ -78,7 +78,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
// HOME and END now mean the beginning/end of the document
// for 0176 changed this to a preference so that the Mac OS X people
// can get the "normal" behavior as well if they prefer.
if (Preferences.getBoolean("editor.keys.home_and_end_travel_far")) {
if (PreferencesData.getBoolean("editor.keys.home_and_end_travel_far")) {
inputHandler.addKeyBinding("HOME", InputHandler.DOCUMENT_HOME);
inputHandler.addKeyBinding("END", InputHandler.DOCUMENT_END);
inputHandler.addKeyBinding("S+HOME", InputHandler.SELECT_DOC_HOME);
@ -182,13 +182,13 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
// moved from TextAreaPainter
font = Preferences.getFont("editor.font");
font = PreferencesData.getFont("editor.font");
fgcolor = Theme.getColor("editor.fgcolor");
bgcolor = Theme.getColor("editor.bgcolor");
caretVisible = true;
caretBlinks = Preferences.getBoolean("editor.caret.blink");
caretBlinks = PreferencesData.getBoolean("editor.caret.blink");
caretColor = Theme.getColor("editor.caret.color");
selectionColor = Theme.getColor("editor.selection.color");

View File

@ -60,7 +60,7 @@ implements TabExpander, Printable
setForeground(defaults.fgcolor);
setBackground(defaults.bgcolor);
antialias = Preferences.getBoolean("editor.antialias");
antialias = PreferencesData.getBoolean("editor.antialias");
blockCaret = defaults.blockCaret;
styles = defaults.styles;

View File

@ -440,7 +440,7 @@ public class AutoFormat implements Tool {
// Adding an additional newline as a hack around other errors
String originalText = editor.getText() + "\n";
strOut = new StringBuffer();
indentValue = Preferences.getInteger("editor.tabs.size");
indentValue = PreferencesData.getInteger("editor.tabs.size");
indentChar = new String(" ");
lineNumber = 0;

View File

@ -43,18 +43,18 @@ public class DefaultTargetTest extends AbstractWithPreferencesTest {
@Before
public void saveBoardFromPreferences() throws Exception {
oldBoardID = Preferences.get("board");
oldBoardID = PreferencesData.get("board");
}
@After
public void restoreBoardIntoPreferences() throws Exception {
Preferences.set("board", oldBoardID);
Preferences.save();
PreferencesData.set("board", oldBoardID);
PreferencesData.save();
}
@Test
public void testDefaultTarget() throws Exception {
Preferences.set("board", "unreal_board");
PreferencesData.set("board", "unreal_board");
// should not raise an exception
new Base(new String[0]);

View File

@ -2,6 +2,7 @@ package processing.app;
import static processing.app.I18n._;
import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@ -12,6 +13,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.MissingResourceException;
import processing.app.helpers.PreferencesHelper;
import processing.app.helpers.PreferencesMap;
import processing.app.legacy.PApplet;
import processing.app.legacy.PConstants;
@ -179,6 +181,13 @@ public class PreferencesData {
return Integer.parseInt(get(attribute));
}
static public int getInteger(String attribute, int defaultValue) {
if (has(attribute)) {
return getInteger(attribute);
}
return defaultValue;
}
static public void setInteger(String key, int value) {
set(key, String.valueOf(value));
@ -203,4 +212,14 @@ public class PreferencesData {
{
doSave = value;
}
static public Font getFont(String attr) {
Font font = PreferencesHelper.getFont(prefs, attr);
if (font == null) {
String value = defaults.get(attr);
prefs.put(attr, value);
font = PreferencesHelper.getFont(prefs, attr);
}
return font;
}
}