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

Merged 1.0.4 pre-release into 1.5

This commit is contained in:
Cristian Maglie 2012-12-17 17:06:20 +01:00
commit b56034e785
8 changed files with 104 additions and 38 deletions

View File

@ -113,6 +113,11 @@ public class Base {
static public void main(String args[]) throws Exception { static public void main(String args[]) throws Exception {
initPlatform();
// run static initialization that grabs all the prefs
Preferences.init(null);
try { try {
File versionFile = getContentFile("lib/version.txt"); File versionFile = getContentFile("lib/version.txt");
if (versionFile.exists()) { if (versionFile.exists()) {
@ -151,8 +156,6 @@ public class Base {
} }
*/ */
initPlatform();
// // Set the look and feel before opening the window // // Set the look and feel before opening the window
// try { // try {
// platform.setLookAndFeel(); // platform.setLookAndFeel();
@ -172,12 +175,6 @@ public class Base {
// Make sure a full JDK is installed // Make sure a full JDK is installed
//initRequirements(); //initRequirements();
// run static initialization that grabs all the prefs
Preferences.init(null);
// load the I18n module for internationalization
I18n.init(Preferences.get("editor.languages.current"));
// setup the theme coloring fun // setup the theme coloring fun
Theme.init(); Theme.init();

View File

@ -290,8 +290,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
protected void setup() { protected void setup() {
if (okButton == null) { if (okButton == null) {
cancelButton = new JButton(Preferences.PROMPT_CANCEL); cancelButton = new JButton(I18n.PROMPT_CANCEL);
okButton = new JButton(Preferences.PROMPT_OK); okButton = new JButton(I18n.PROMPT_OK);
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

View File

@ -19,15 +19,29 @@ import java.text.MessageFormat;
public class I18n { public class I18n {
// start using current locale but still allow using the dropdown list later // start using current locale but still allow using the dropdown list later
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources"); private static ResourceBundle i18n;
public static Locale locale;
// prompt text stuff
static String PROMPT_YES;
static String PROMPT_NO;
static String PROMPT_CANCEL;
static String PROMPT_OK;
static String PROMPT_BROWSE;
static protected void init (String language) { static protected void init (String language) {
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad // there might be a null pointer exception ... most likely will never happen but the jvm gets mad
try { try {
if (language == null || language.trim().length() == 0) locale = Locale.getDefault(); if (language != null && language.trim().length() > 0) {
else locale = new Locale(language); Locale.setDefault(new Locale(language));
i18n = ResourceBundle.getBundle("processing.app.Resources", locale); }
i18n = ResourceBundle.getBundle("processing.app.Resources", Locale.getDefault());
PROMPT_YES = _("Yes");
PROMPT_NO = _("No");
PROMPT_CANCEL = _("Cancel");
PROMPT_OK = _("OK");
PROMPT_BROWSE = _("Browse");
} catch (java.lang.NullPointerException e) { } catch (java.lang.NullPointerException e) {
} }
} }

View File

@ -29,6 +29,7 @@ import javax.swing.UIManager;
import com.sun.jna.Library; import com.sun.jna.Library;
import com.sun.jna.Native; import com.sun.jna.Native;
import processing.core.PConstants;
/** /**
@ -159,6 +160,10 @@ public class Platform {
return clib.unsetenv(variable); return clib.unsetenv(variable);
} }
public String getName() {
return PConstants.platformNames[PConstants.OTHER];
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

View File

@ -23,16 +23,17 @@
package processing.app; package processing.app;
import processing.app.syntax.SyntaxStyle;
import processing.core.PApplet;
import processing.core.PConstants;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import javax.swing.*;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
import processing.app.syntax.*;
import processing.core.*;
import static processing.app.I18n._; import static processing.app.I18n._;
@ -71,15 +72,6 @@ public class Preferences {
static final String PREFS_FILE = "preferences.txt"; static final String PREFS_FILE = "preferences.txt";
// prompt text stuff
static final String PROMPT_YES = _("Yes");
static final String PROMPT_NO = _("No");
static final String PROMPT_CANCEL = _("Cancel");
static final String PROMPT_OK = _("OK");
static final String PROMPT_BROWSE = _("Browse");
String[] languages = { String[] languages = {
_("System Default"), _("System Default"),
"العربية" + " (" + _("Arabic") + ")", "العربية" + " (" + _("Arabic") + ")",
@ -228,7 +220,7 @@ public class Preferences {
table.put("runtime.ide.version", "" + Base.REVISION); table.put("runtime.ide.version", "" + Base.REVISION);
// check for platform-specific properties in the defaults // check for platform-specific properties in the defaults
String platformExt = "." + PConstants.platformNames[PApplet.platform]; String platformExt = "." + Base.platform.getName();
int platformExtLength = platformExt.length(); int platformExtLength = platformExt.length();
Enumeration e = table.keys(); Enumeration e = table.keys();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
@ -244,9 +236,6 @@ public class Preferences {
// clone the hash table // clone the hash table
defaults = (Hashtable) table.clone(); defaults = (Hashtable) table.clone();
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
// Load a prefs file if specified on the command line // Load a prefs file if specified on the command line
if (commandLinePrefs != null) { if (commandLinePrefs != null) {
try { try {
@ -283,7 +272,13 @@ public class Preferences {
), ex); ), ex);
} }
} }
} }
// load the I18n module for internationalization
I18n.init(Preferences.get("editor.languages.current"));
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
} }
@ -322,7 +317,7 @@ public class Preferences {
pain.add(sketchbookLocationField); pain.add(sketchbookLocationField);
d = sketchbookLocationField.getPreferredSize(); d = sketchbookLocationField.getPreferredSize();
button = new JButton(PROMPT_BROWSE); button = new JButton(I18n.PROMPT_BROWSE);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
File dflt = new File(sketchbookLocationField.getText()); File dflt = new File(sketchbookLocationField.getText());
@ -486,7 +481,7 @@ public class Preferences {
// [ OK ] [ Cancel ] maybe these should be next to the message? // [ OK ] [ Cancel ] maybe these should be next to the message?
button = new JButton(PROMPT_OK); button = new JButton(I18n.PROMPT_OK);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
applyFrame(); applyFrame();
@ -501,7 +496,7 @@ public class Preferences {
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
h += BUTTON_WIDTH + GUI_SMALL; h += BUTTON_WIDTH + GUI_SMALL;
button = new JButton(PROMPT_CANCEL); button = new JButton(I18n.PROMPT_CANCEL);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
disposeFrame(); disposeFrame();
@ -682,8 +677,8 @@ public class Preferences {
load(input, table); load(input, table);
} }
static public void load(InputStream input, Map table) throws IOException { static public void load(InputStream input, Map table) throws IOException {
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8 String[] lines = loadStrings(input); // Reads as UTF-8
for (String line : lines) { for (String line : lines) {
if ((line.length() == 0) || if ((line.length() == 0) ||
(line.charAt(0) == '#')) continue; (line.charAt(0) == '#')) continue;
@ -698,6 +693,41 @@ public class Preferences {
} }
} }
static public String[] loadStrings(InputStream input) {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(input, "UTF-8"));
String lines[] = new String[100];
int lineCount = 0;
String line = null;
while ((line = reader.readLine()) != null) {
if (lineCount == lines.length) {
String temp[] = new String[lineCount << 1];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
}
lines[lineCount++] = line;
}
reader.close();
if (lineCount == lines.length) {
return lines;
}
// resize array to appropriate amount for these lines
String output[] = new String[lineCount];
System.arraycopy(lines, 0, output, 0, lineCount);
return output;
} catch (IOException e) {
e.printStackTrace();
//throw new RuntimeException("Error inside loadStrings()");
}
return null;
}
// ................................................................. // .................................................................

View File

@ -27,6 +27,7 @@ import java.io.File;
import javax.swing.UIManager; import javax.swing.UIManager;
import processing.app.Preferences; import processing.app.Preferences;
import processing.core.PConstants;
/** /**
@ -112,4 +113,9 @@ public class Platform extends processing.app.Platform {
file.getAbsolutePath()); file.getAbsolutePath());
} }
} }
@Override
public String getName() {
return PConstants.platformNames[PConstants.LINUX];
}
} }

View File

@ -34,6 +34,7 @@ import com.apple.eio.FileManager;
import processing.app.Base; import processing.app.Base;
import processing.core.PApplet; import processing.core.PApplet;
import processing.core.PConstants;
/** /**
@ -195,4 +196,10 @@ public class Platform extends processing.app.Platform {
protected String getDocumentsFolder() throws FileNotFoundException { protected String getDocumentsFolder() throws FileNotFoundException {
return FileManager.findFolder(kUserDomain, kDocumentsFolderType); return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
} }
@Override
public String getName() {
return PConstants.platformNames[PConstants.MACOSX];
}
} }

View File

@ -32,6 +32,7 @@ import processing.app.Base;
import processing.app.Preferences; import processing.app.Preferences;
import processing.app.windows.Registry.REGISTRY_ROOT_KEY; import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
import processing.core.PApplet; import processing.core.PApplet;
import processing.core.PConstants;
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html // http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
@ -302,4 +303,10 @@ public class Platform extends processing.app.Platform {
//return 0; //return 0;
return clib._putenv(variable + "="); return clib._putenv(variable + "=");
} }
@Override
public String getName() {
return PConstants.platformNames[PConstants.WINDOWS];
}
} }