Merge remote-tracking branch 'origin/master-issue1170'

This commit is contained in:
Cristian Maglie 2012-12-17 16:58:52 +01:00
commit ce1ccb43ba
8 changed files with 104 additions and 38 deletions

View File

@ -107,6 +107,11 @@ public class Base {
static public void main(String args[]) {
initPlatform();
// run static initialization that grabs all the prefs
Preferences.init(null);
try {
File versionFile = getContentFile("lib/version.txt");
if (versionFile.exists()) {
@ -145,8 +150,6 @@ public class Base {
}
*/
initPlatform();
// // Set the look and feel before opening the window
// try {
// platform.setLookAndFeel();
@ -166,12 +169,6 @@ public class Base {
// Make sure a full JDK is installed
//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
Theme.init();

View File

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

View File

@ -19,15 +19,29 @@ import java.text.MessageFormat;
public class I18n {
// start using current locale but still allow using the dropdown list later
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
public static Locale locale;
private static ResourceBundle i18n;
// 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) {
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
try {
if (language == null || language.trim().length() == 0) locale = Locale.getDefault();
else locale = new Locale(language);
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
if (language != null && language.trim().length() > 0) {
Locale.setDefault(new Locale(language));
}
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) {
}
}

View File

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

View File

@ -23,15 +23,16 @@
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.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import processing.app.syntax.*;
import processing.core.*;
import static processing.app.I18n._;
@ -70,15 +71,6 @@ public class Preferences {
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 = {
_("System Default"),
"العربية" + " (" + _("Arabic") + ")",
@ -220,7 +212,7 @@ public class Preferences {
}
// check for platform-specific properties in the defaults
String platformExt = "." + PConstants.platformNames[PApplet.platform];
String platformExt = "." + Base.platform.getName();
int platformExtLength = platformExt.length();
Enumeration e = table.keys();
while (e.hasMoreElements()) {
@ -236,9 +228,6 @@ public class Preferences {
// clone the hash table
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
if (commandLinePrefs != null) {
try {
@ -275,7 +264,13 @@ public class Preferences {
), 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);
}
@ -314,7 +309,7 @@ public class Preferences {
pain.add(sketchbookLocationField);
d = sketchbookLocationField.getPreferredSize();
button = new JButton(PROMPT_BROWSE);
button = new JButton(I18n.PROMPT_BROWSE);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File dflt = new File(sketchbookLocationField.getText());
@ -478,7 +473,7 @@ public class Preferences {
// [ 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() {
public void actionPerformed(ActionEvent e) {
applyFrame();
@ -493,7 +488,7 @@ public class Preferences {
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
h += BUTTON_WIDTH + GUI_SMALL;
button = new JButton(PROMPT_CANCEL);
button = new JButton(I18n.PROMPT_CANCEL);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
disposeFrame();
@ -674,8 +669,8 @@ public class Preferences {
load(input, table);
}
static public void load(InputStream input, Map table) throws IOException {
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
static public void load(InputStream input, Map table) throws IOException {
String[] lines = loadStrings(input); // Reads as UTF-8
for (String line : lines) {
if ((line.length() == 0) ||
(line.charAt(0) == '#')) continue;
@ -690,6 +685,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 processing.app.Preferences;
import processing.core.PConstants;
/**
@ -112,4 +113,9 @@ public class Platform extends processing.app.Platform {
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.core.PApplet;
import processing.core.PConstants;
/**
@ -195,4 +196,10 @@ public class Platform extends processing.app.Platform {
protected String getDocumentsFolder() throws FileNotFoundException {
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.windows.Registry.REGISTRY_ROOT_KEY;
import processing.core.PApplet;
import processing.core.PConstants;
// 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 clib._putenv(variable + "=");
}
@Override
public String getName() {
return PConstants.platformNames[PConstants.WINDOWS];
}
}