changes for Messages class

This commit is contained in:
Ben Fry
2015-08-13 22:08:08 -04:00
parent d683313e64
commit 231de54cd5
29 changed files with 652 additions and 624 deletions
+70 -383
View File
@@ -25,16 +25,13 @@ package processing.app;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
@@ -114,9 +111,9 @@ public class Base {
try {
createAndShowGUI(args);
} catch (Throwable t) {
showBadnessTrace("It was not meant to be",
"A serious problem happened during startup. Please report:\n" +
"http://github.com/processing/processing/issues/new", t, true);
Messages.showBadnessTrace("It was not meant to be",
"A serious problem happened during startup. Please report:\n" +
"http://github.com/processing/processing/issues/new", t, true);
}
}
});
@@ -159,7 +156,7 @@ public class Base {
try {
Platform.setLookAndFeel();
} catch (Exception e) {
loge("Could not set the Look & Feel", e); //$NON-NLS-1$
Messages.loge("Could not set the Look & Feel", e); //$NON-NLS-1$
}
boolean sketchbookPrompt = false;
@@ -192,12 +189,12 @@ public class Base {
untitledFolder = Util.createTempFolder("untitled", "sketches", null);
untitledFolder.deleteOnExit();
} catch (IOException e) {
Base.showError("Trouble without a name",
"Could not create a place to store untitled sketches.\n" +
"That's gonna prevent us from continuing.", e);
Messages.showError("Trouble without a name",
"Could not create a place to store untitled sketches.\n" +
"That's gonna prevent us from continuing.", e);
}
log("about to create base..."); //$NON-NLS-1$
Messages.log("about to create base..."); //$NON-NLS-1$
try {
final Base base = new Base(args);
// Prevent more than one copy of the PDE from running.
@@ -212,9 +209,9 @@ public class Base {
try {
new Welcome(base, prompt);
} catch (IOException e) {
Base.showBadnessTrace("Unwelcoming",
"Please report this error to\n" +
"https://github.com/processing/processing/issues", e, false);
Messages.showBadnessTrace("Unwelcoming",
"Please report this error to\n" +
"https://github.com/processing/processing/issues", e, false);
}
}
});
@@ -227,10 +224,10 @@ public class Base {
// show this one so that it's not truncated in the error window.
t = t.getCause();
}
showBadnessTrace("We're off on the wrong foot",
"An error occurred during startup.", t, true);
Messages.showBadnessTrace("We're off on the wrong foot",
"An error occurred during startup.", t, true);
}
log("done creating base..."); //$NON-NLS-1$
Messages.log("done creating base..."); //$NON-NLS-1$
}
}
@@ -283,17 +280,17 @@ public class Base {
String lastModeIdentifier = Preferences.get("mode.last"); //$NON-NLS-1$
if (lastModeIdentifier == null) {
nextMode = getDefaultMode();
log("Nothing set for last.sketch.mode, using default."); //$NON-NLS-1$
Messages.log("Nothing set for last.sketch.mode, using default."); //$NON-NLS-1$
} else {
for (Mode m : getModeList()) {
if (m.getIdentifier().equals(lastModeIdentifier)) {
logf("Setting next mode to %s.", lastModeIdentifier); //$NON-NLS-1$
Messages.logf("Setting next mode to %s.", lastModeIdentifier); //$NON-NLS-1$
nextMode = m;
}
}
if (nextMode == null) {
nextMode = getDefaultMode();
logf("Could not find mode %s, using default.", lastModeIdentifier); //$NON-NLS-1$
Messages.logf("Could not find mode %s, using default.", lastModeIdentifier); //$NON-NLS-1$
}
}
@@ -623,13 +620,14 @@ public class Base {
}
if (possibleModes.size() == 0) {
if (preferredMode == null) {
Base.showWarning("Modeless Dialog",
"I don't know how to open a sketch with the \""
Messages.showWarning("Modeless Dialog",
"I don't know how to open a sketch with the \""
+ extension
+ "\"\nfile extension. You'll have to install a different"
+ "\nProcessing mode for that.");
} else {
Base.showWarning("Modeless Dialog", "You'll have to install "
Messages.showWarning("Modeless Dialog",
"You'll have to install "
+ preferredMode.title + " Mode " + "\nin order to open that sketch.");
}
return null;
@@ -714,13 +712,13 @@ public class Base {
if (index == 26) {
// In 0159, avoid running past z by sending people outdoors.
if (!breakTime) {
Base.showWarning("Time for a Break",
"You've reached the limit for auto naming of new sketches\n" +
"for the day. How about going for a walk instead?", null);
Messages.showWarning("Time for a Break",
"You've reached the limit for auto naming of new sketches\n" +
"for the day. How about going for a walk instead?", null);
breakTime = true;
} else {
Base.showWarning("Sunshine",
"No really, time for some fresh air for you.", null);
Messages.showWarning("Sunshine",
"No really, time for some fresh air for you.", null);
}
return;
}
@@ -753,9 +751,9 @@ public class Base {
/*Editor editor =*/ handleOpen(path, true);
} catch (IOException e) {
Base.showWarning("That's new to me",
"A strange and unexplainable error occurred\n" +
"while trying to create a new sketch.", e);
Messages.showWarning("That's new to me",
"A strange and unexplainable error occurred\n" +
"while trying to create a new sketch.", e);
}
}
@@ -878,10 +876,10 @@ public class Base {
}
if (!Sketch.isSanitaryName(file.getName())) {
Base.showWarning("You're tricky, but not tricky enough",
file.getName() + " is not a valid name for a sketch.\n" +
"Better to stick to ASCII, no spaces, and make sure\n" +
"it doesn't start with a number.", null);
Messages.showWarning("You're tricky, but not tricky enough",
file.getName() + " is not a valid name for a sketch.\n" +
"Better to stick to ASCII, no spaces, and make sure\n" +
"it doesn't start with a number.", null);
return null;
}
@@ -909,22 +907,22 @@ public class Base {
} catch (EditorException ee) {
if (!ee.getMessage().equals("")) { // blank if the user canceled
Base.showWarning("Error opening sketch", ee.getMessage(), ee);
Messages.showWarning("Error opening sketch", ee.getMessage(), ee);
}
} catch (NoSuchMethodError nsme) {
Base.showWarning("Mode out of date",
nextMode.getTitle() + " is not compatible with this version of Processing.\n" +
"Try updating the Mode or contact its author for a new version.", nsme);
Messages.showWarning("Mode out of date",
nextMode.getTitle() + " is not compatible with this version of Processing.\n" +
"Try updating the Mode or contact its author for a new version.", nsme);
} catch (Throwable t) {
if (nextMode.equals(getDefaultMode())) {
showBadnessTrace("Serious Problem",
"An unexpected, unknown, and unrecoverable error occurred\n" +
"while opening a new editor window. Please report this.", t, true);
Messages.showBadnessTrace("Serious Problem",
"An unexpected, unknown, and unrecoverable error occurred\n" +
"while opening a new editor window. Please report this.", t, true);
} else {
showBadnessTrace("Mode Problems",
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
"It may not be compatible with this version of Processing.\n" +
"Try updating the Mode or contact its author for a new version.", t, false);
Messages.showBadnessTrace("Mode Problems",
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
"It may not be compatible with this version of Processing.\n" +
"Try updating the Mode or contact its author for a new version.", t, false);
}
}
/*
@@ -945,10 +943,10 @@ public class Base {
*/
} catch (Throwable t) {
showBadnessTrace("Terrible News",
"A serious error occurred while " +
"trying to create a new editor window.", t,
nextMode == getDefaultMode()); // quit if default
Messages.showBadnessTrace("Terrible News",
"A serious error occurred while " +
"trying to create a new editor window.", t,
nextMode == getDefaultMode()); // quit if default
nextMode = getDefaultMode();
}
return null;
@@ -1149,8 +1147,8 @@ public class Base {
try {
found = addSketches(menu, sketchbookFolder, false);
} catch (IOException e) {
Base.showWarning("Sketchbook Menu Error",
"An error occurred while trying to list the sketchbook.", e);
Messages.showWarning("Sketchbook Menu Error",
"An error occurred while trying to list the sketchbook.", e);
}
if (!found) {
JMenuItem empty = new JMenuItem(Language.text("menu.file.sketchbook.empty"));
@@ -1229,10 +1227,10 @@ public class Base {
handleOpen(path);
// }
} else {
showWarning("Sketch Disappeared",
"The selected sketch no longer exists.\n" +
"You may need to restart Processing to update\n" +
"the sketchbook menu.", null);
Messages.showWarning("Sketch Disappeared",
"The selected sketch no longer exists.\n" +
"You may need to restart Processing to update\n" +
"the sketchbook menu.", null);
}
}
};
@@ -1407,16 +1405,16 @@ public class Base {
try {
settingsFolder = Platform.getSettingsFolder();
} catch (Exception e) {
showError("Problem getting the settings folder",
"Error getting the Processing the settings folder.", e);
Messages.showError("Problem getting the settings folder",
"Error getting the Processing the settings folder.", e);
}
// create the folder if it doesn't exist already
if (!settingsFolder.exists()) {
if (!settingsFolder.mkdirs()) {
showError("Settings issues",
"Processing cannot run because it could not\n" +
"create a folder to store your settings.", null);
Messages.showError("Settings issues",
"Processing cannot run because it could not\n" +
"create a folder to store your settings.", null);
}
}
return settingsFolder;
@@ -1446,12 +1444,12 @@ public class Base {
if (sketchbookPath != null) {
sketchbookFolder = new File(sketchbookPath);
if (!sketchbookFolder.exists()) {
Base.showWarning("Sketchbook folder disappeared",
"The sketchbook folder no longer exists.\n" +
"Processing will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Processing will then stop talking\n" +
"about himself in the third person.", null);
Messages.showWarning("Sketchbook folder disappeared",
"The sketchbook folder no longer exists.\n" +
"Processing will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Processing will then stop talking\n" +
"about himself in the third person.", null);
sketchbookFolder = null;
}
}
@@ -1519,8 +1517,8 @@ public class Base {
} catch (Exception e) { }
if (sketchbookFolder == null) {
showError("No sketchbook",
"Problem while trying to get the sketchbook", null);
Messages.showError("No sketchbook",
"Problem while trying to get the sketchbook", null);
}
// create the folder if it doesn't exist already
@@ -1530,322 +1528,11 @@ public class Base {
}
if (!result) {
showError("You forgot your sketchbook",
"Processing cannot run because it could not\n" +
"create a folder to store your sketchbook.", null);
Messages.showError("You forgot your sketchbook",
"Processing cannot run because it could not\n" +
"create a folder to store your sketchbook.", null);
}
return sketchbookFolder;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
*/
static public void showMessage(String title, String message) {
if (title == null) title = "Message";
if (commandLine) {
System.out.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE);
}
}
/**
* Non-fatal error message.
*/
static public void showWarning(String title, String message) {
showWarning(title, message, null);
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarning(String title, String message, Throwable e) {
if (title == null) title = "Warning";
if (commandLine) {
System.out.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.WARNING_MESSAGE);
}
if (e != null) e.printStackTrace();
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarningTiered(String title,
String primary, String secondary,
Throwable e) {
if (title == null) title = "Warning";
final String message = primary + "\n" + secondary;
if (commandLine) {
System.out.println(title + ": " + message);
} else {
// JOptionPane.showMessageDialog(new Frame(), message,
// title, JOptionPane.WARNING_MESSAGE);
if (!Platform.isMacOS()) {
JOptionPane.showMessageDialog(new JFrame(),
"<html><body>" +
"<b>" + primary + "</b>" +
"<br>" + secondary, title,
JOptionPane.WARNING_MESSAGE);
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + primary + "</b>" +
"<p>" + secondary + "</p>",
JOptionPane.WARNING_MESSAGE);
// String[] options = new String[] {
// "Yes", "No"
// };
// pane.setOptions(options);
// highlight the safest option ala apple hig
// pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(new JFrame(), null);
dialog.setVisible(true);
// Object result = pane.getValue();
// if (result == options[0]) {
// return JOptionPane.YES_OPTION;
// } else if (result == options[1]) {
// return JOptionPane.NO_OPTION;
// } else {
// return JOptionPane.CLOSED_OPTION;
// }
}
}
if (e != null) e.printStackTrace();
}
/**
* Show an error message that's actually fatal to the program.
* This is an error that can't be recovered. Use showWarning()
* for errors that allow P5 to continue running.
*/
static public void showError(String title, String message, Throwable e) {
if (title == null) title = "Error";
if (commandLine) {
System.err.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.ERROR_MESSAGE);
}
if (e != null) e.printStackTrace();
System.exit(1);
}
/**
* Testing a new warning window that includes the stack trace.
*/
static private void showBadnessTrace(String title, String message,
Throwable t, boolean fatal) {
if (title == null) title = fatal ? "Error" : "Warning";
if (commandLine) {
System.err.println(title + ": " + message);
if (t != null) {
t.printStackTrace();
}
} else {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
// Necessary to replace \n with <br/> (even if pre) otherwise Java
// treats it as a closed tag and reverts to plain formatting.
message = ("<html>" + message +
"<br/><font size=2><br/>" +
sw + "</html>").replaceAll("\n", "<br/>");
JOptionPane.showMessageDialog(new Frame(), message, title,
fatal ?
JOptionPane.ERROR_MESSAGE :
JOptionPane.WARNING_MESSAGE);
if (fatal) {
System.exit(1);
}
}
}
// ...................................................................
// incomplete
static public int showYesNoCancelQuestion(Editor editor, String title,
String primary, String secondary) {
if (!Platform.isMacOS()) {
int result =
JOptionPane.showConfirmDialog(null, primary + "\n" + secondary, title,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
return result;
// if (result == JOptionPane.YES_OPTION) {
//
// } else if (result == JOptionPane.NO_OPTION) {
// return true; // ok to continue
//
// } else if (result == JOptionPane.CANCEL_OPTION) {
// return false;
//
// } else {
// throw new IllegalStateException();
// }
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + Language.text("save.title") + "</b>" +
"<p>" + Language.text("save.hint") + "</p>",
JOptionPane.QUESTION_MESSAGE);
String[] options = new String[] {
Language.text("save.btn.save"),
Language.text("prompt.cancel"),
Language.text("save.btn.dont_save")
};
pane.setOptions(options);
// highlight the safest option ala apple hig
pane.setInitialValue(options[0]);
// on macosx, setting the destructive property places this option
// away from the others at the lefthand side
pane.putClientProperty("Quaqua.OptionPane.destructiveOption",
Integer.valueOf(2));
JDialog dialog = pane.createDialog(editor, null);
dialog.setVisible(true);
Object result = pane.getValue();
if (result == options[0]) {
return JOptionPane.YES_OPTION;
} else if (result == options[1]) {
return JOptionPane.CANCEL_OPTION;
} else if (result == options[2]) {
return JOptionPane.NO_OPTION;
} else {
return JOptionPane.CLOSED_OPTION;
}
}
}
static public int showYesNoQuestion(Frame editor, String title,
String primary, String secondary) {
if (!Platform.isMacOS()) {
return JOptionPane.showConfirmDialog(editor,
"<html><body>" +
"<b>" + primary + "</b>" +
"<br>" + secondary, title,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + primary + "</b>" +
"<p>" + secondary + "</p>",
JOptionPane.QUESTION_MESSAGE);
String[] options = new String[] {
"Yes", "No"
};
pane.setOptions(options);
// highlight the safest option ala apple hig
pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(editor, null);
dialog.setVisible(true);
Object result = pane.getValue();
if (result == options[0]) {
return JOptionPane.YES_OPTION;
} else if (result == options[1]) {
return JOptionPane.NO_OPTION;
} else {
return JOptionPane.CLOSED_OPTION;
}
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static public void log(Object from, String message) {
if (DEBUG) {
System.out.println(from.getClass().getName() + ": " + message);
}
}
static public void log(String message) {
if (DEBUG) {
System.out.println(message);
}
}
static public void logf(String message, Object... args) {
if (DEBUG) {
System.out.println(String.format(message, args));
}
}
static public void loge(String message, Throwable e) {
if (DEBUG) {
System.err.println(message);
e.printStackTrace();
}
}
static public void loge(String message) {
if (DEBUG) {
System.out.println(message);
}
}
}
+1 -1
View File
@@ -480,7 +480,7 @@ public class Library extends LocalContribution {
+ "\" cannot be used.\n"
+ "Library names must contain only basic letters and numbers.\n"
+ "(ASCII only and no spaces, and it cannot start with a number)";
Base.showMessage("Ignoring bad library name", mess);
Messages.showMessage("Ignoring bad library name", mess);
continue;
}
}
+341
View File
@@ -0,0 +1,341 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2015 The Processing Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app;
import java.awt.Frame;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import processing.app.ui.Editor;
public class Messages {
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
*/
static public void showMessage(String title, String message) {
if (title == null) title = "Message";
if (Base.isCommandLine()) {
System.out.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE);
}
}
/**
* Non-fatal error message.
*/
static public void showWarning(String title, String message) {
showWarning(title, message, null);
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarning(String title, String message, Throwable e) {
if (title == null) title = "Warning";
if (Base.isCommandLine()) {
System.out.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.WARNING_MESSAGE);
}
if (e != null) e.printStackTrace();
}
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarningTiered(String title,
String primary, String secondary,
Throwable e) {
if (title == null) title = "Warning";
final String message = primary + "\n" + secondary;
if (Base.isCommandLine()) {
System.out.println(title + ": " + message);
} else {
// JOptionPane.showMessageDialog(new Frame(), message,
// title, JOptionPane.WARNING_MESSAGE);
if (!Platform.isMacOS()) {
JOptionPane.showMessageDialog(new JFrame(),
"<html><body>" +
"<b>" + primary + "</b>" +
"<br>" + secondary, title,
JOptionPane.WARNING_MESSAGE);
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + primary + "</b>" +
"<p>" + secondary + "</p>",
JOptionPane.WARNING_MESSAGE);
// String[] options = new String[] {
// "Yes", "No"
// };
// pane.setOptions(options);
// highlight the safest option ala apple hig
// pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(new JFrame(), null);
dialog.setVisible(true);
// Object result = pane.getValue();
// if (result == options[0]) {
// return JOptionPane.YES_OPTION;
// } else if (result == options[1]) {
// return JOptionPane.NO_OPTION;
// } else {
// return JOptionPane.CLOSED_OPTION;
// }
}
}
if (e != null) e.printStackTrace();
}
/**
* Show an error message that's actually fatal to the program.
* This is an error that can't be recovered. Use showWarning()
* for errors that allow P5 to continue running.
*/
static public void showError(String title, String message, Throwable e) {
if (title == null) title = "Error";
if (Base.isCommandLine()) {
System.err.println(title + ": " + message);
} else {
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.ERROR_MESSAGE);
}
if (e != null) e.printStackTrace();
System.exit(1);
}
/**
* Testing a new warning window that includes the stack trace.
*/
static void showBadnessTrace(String title, String message,
Throwable t, boolean fatal) {
if (title == null) title = fatal ? "Error" : "Warning";
if (Base.isCommandLine()) {
System.err.println(title + ": " + message);
if (t != null) {
t.printStackTrace();
}
} else {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
// Necessary to replace \n with <br/> (even if pre) otherwise Java
// treats it as a closed tag and reverts to plain formatting.
message = ("<html>" + message +
"<br/><font size=2><br/>" +
sw + "</html>").replaceAll("\n", "<br/>");
JOptionPane.showMessageDialog(new Frame(), message, title,
fatal ?
JOptionPane.ERROR_MESSAGE :
JOptionPane.WARNING_MESSAGE);
if (fatal) {
System.exit(1);
}
}
}
// ...................................................................
// incomplete
static public int showYesNoCancelQuestion(Editor editor, String title,
String primary, String secondary) {
if (!Platform.isMacOS()) {
int result =
JOptionPane.showConfirmDialog(null, primary + "\n" + secondary, title,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
return result;
// if (result == JOptionPane.YES_OPTION) {
//
// } else if (result == JOptionPane.NO_OPTION) {
// return true; // ok to continue
//
// } else if (result == JOptionPane.CANCEL_OPTION) {
// return false;
//
// } else {
// throw new IllegalStateException();
// }
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + Language.text("save.title") + "</b>" +
"<p>" + Language.text("save.hint") + "</p>",
JOptionPane.QUESTION_MESSAGE);
String[] options = new String[] {
Language.text("save.btn.save"),
Language.text("prompt.cancel"),
Language.text("save.btn.dont_save")
};
pane.setOptions(options);
// highlight the safest option ala apple hig
pane.setInitialValue(options[0]);
// on macosx, setting the destructive property places this option
// away from the others at the lefthand side
pane.putClientProperty("Quaqua.OptionPane.destructiveOption",
Integer.valueOf(2));
JDialog dialog = pane.createDialog(editor, null);
dialog.setVisible(true);
Object result = pane.getValue();
if (result == options[0]) {
return JOptionPane.YES_OPTION;
} else if (result == options[1]) {
return JOptionPane.CANCEL_OPTION;
} else if (result == options[2]) {
return JOptionPane.NO_OPTION;
} else {
return JOptionPane.CLOSED_OPTION;
}
}
}
static public int showYesNoQuestion(Frame editor, String title,
String primary, String secondary) {
if (!Platform.isMacOS()) {
return JOptionPane.showConfirmDialog(editor,
"<html><body>" +
"<b>" + primary + "</b>" +
"<br>" + secondary, title,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
} else {
// Pane formatting adapted from the Quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
"</style> </head>" +
"<b>" + primary + "</b>" +
"<p>" + secondary + "</p>",
JOptionPane.QUESTION_MESSAGE);
String[] options = new String[] {
"Yes", "No"
};
pane.setOptions(options);
// highlight the safest option ala apple hig
pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(editor, null);
dialog.setVisible(true);
Object result = pane.getValue();
if (result == options[0]) {
return JOptionPane.YES_OPTION;
} else if (result == options[1]) {
return JOptionPane.NO_OPTION;
} else {
return JOptionPane.CLOSED_OPTION;
}
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static public void log(Object from, String message) {
if (Base.DEBUG) {
System.out.println(from.getClass().getName() + ": " + message);
}
}
static public void log(String message) {
if (Base.DEBUG) {
System.out.println(message);
}
}
static public void logf(String message, Object... args) {
if (Base.DEBUG) {
System.out.println(String.format(message, args));
}
}
static public void loge(String message, Throwable e) {
if (Base.DEBUG) {
System.err.println(message);
e.printStackTrace();
}
}
static public void loge(String message) {
if (Base.DEBUG) {
System.out.println(message);
}
}
}
+5 -5
View File
@@ -120,8 +120,8 @@ public abstract class Mode {
loadKeywords(file);
}
} catch (IOException e) {
Base.showWarning("Problem loading keywords",
"Could not load keywords file for " + getTitle() + " mode.", e);
Messages.showWarning("Problem loading keywords",
"Could not load keywords file for " + getTitle() + " mode.", e);
}
}
@@ -212,8 +212,8 @@ public abstract class Mode {
// loadBackground();
} catch (IOException e) {
Base.showError("Problem loading theme.txt",
"Could not load theme.txt, please re-install Processing", e);
Messages.showError("Problem loading theme.txt",
"Could not load theme.txt, please re-install Processing", e);
}
}
@@ -347,7 +347,7 @@ public abstract class Mode {
secondary += "<b>" + library.getName() + "</b> (" + location + ")<br>";
}
secondary += "Extra libraries need to be removed before this sketch can be used.";
Base.showWarningTiered("Duplicate Library Problem", primary, secondary, null);
Messages.showWarningTiered("Duplicate Library Problem", primary, secondary, null);
throw new SketchException("Duplicate libraries found for " + pkgName + ".");
} else {
+70 -9
View File
@@ -29,6 +29,10 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.FileUtils;
import processing.app.platform.DefaultPlatform;
import processing.core.PApplet;
import processing.core.PConstants;
@@ -70,7 +74,7 @@ public class Platform {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static public void init() {
try {
@@ -84,9 +88,9 @@ public class Platform {
}
inst = (DefaultPlatform) platformClass.newInstance();
} catch (Exception e) {
Base.showError("Problem Setting the Platform",
"An unknown error occurred while trying to load\n" +
"platform-specific code for your machine.", e);
Messages.showError("Problem Setting the Platform",
"An unknown error occurred while trying to load\n" +
"platform-specific code for your machine.", e);
}
}
@@ -145,7 +149,7 @@ public class Platform {
inst.openURL(url);
} catch (Exception e) {
Base.showWarning("Problem Opening URL",
Messages.showWarning("Problem Opening URL",
"Could not open the URL\n" + url, e);
}
}
@@ -169,8 +173,8 @@ public class Platform {
inst.openFolder(file);
} catch (Exception e) {
Base.showWarning("Problem Opening Folder",
"Could not open the folder\n" + file.getAbsolutePath(), e);
Messages.showWarning("Problem Opening Folder",
"Could not open the folder\n" + file.getAbsolutePath(), e);
}
}
@@ -267,8 +271,8 @@ public class Platform {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static protected File processingRoot;
/**
@@ -343,4 +347,61 @@ public class Platform {
return javaFile.getAbsolutePath();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Attempts to move to the Trash on OS X, or the Recycle Bin on Windows.
* Also tries to find a suitable Trash location on Linux.
* If not possible, just deletes the file or folder instead.
* @param file the folder or file to be removed/deleted
* @return true if the folder was successfully removed
* @throws IOException
*/
static public boolean deleteFile(File file) throws IOException {
FileUtils fu = FileUtils.getInstance();
if (fu.hasTrash()) {
fu.moveToTrash(new File[] { file });
return true;
} else if (file.isDirectory()) {
Util.removeDir(file);
return true;
} else {
return file.delete();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
int setenv(String name, String value, int overwrite);
String getenv(String name);
int unsetenv(String name);
int putenv(String string);
}
static public void setenv(String variable, String value) {
CLibrary clib = CLibrary.INSTANCE;
clib.setenv(variable, value, 1);
}
static public String getenv(String variable) {
CLibrary clib = CLibrary.INSTANCE;
return clib.getenv(variable);
}
public int unsetenv(String variable) {
CLibrary clib = CLibrary.INSTANCE;
return clib.unsetenv(variable);
}
}
+7 -7
View File
@@ -67,7 +67,7 @@ public class Preferences {
// replacing the file after doing a search for "preferences.txt".
load(Base.getLibStream(DEFAULTS_FILE));
} catch (Exception e) {
Base.showError(null, "Could not read default settings.\n" +
Messages.showError(null, "Could not read default settings.\n" +
"You'll need to reinstall Processing.", e);
}
@@ -109,11 +109,11 @@ public class Preferences {
load(new FileInputStream(preferencesFile));
} catch (Exception ex) {
Base.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
Messages.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
}
}
@@ -385,7 +385,7 @@ public class Preferences {
} catch (Exception e) {
// Adding try/catch block because this may be where
// a lot of startup crashes are happening.
Base.log("Error with font " + get(attr) + " for attribute " + attr);
Messages.log("Error with font " + get(attr) + " for attribute " + attr);
}
return new Font("Dialog", Font.PLAIN, 12);
}
+1 -1
View File
@@ -225,7 +225,7 @@ public class Settings {
} catch (Exception e) {
// Adding try/catch block because this may be where
// a lot of startup crashes are happening.
Base.log("Error with font " + get(attr) + " for attribute " + attr);
Messages.log("Error with font " + get(attr) + " for attribute " + attr);
}
return new Font("Dialog", Font.PLAIN, 12);
}
+7 -7
View File
@@ -74,7 +74,7 @@ public class SingleInstance {
Socket s = ss.accept(); // blocks (sleeps) until connection
final BufferedReader reader = PApplet.createReader(s.getInputStream());
String receivedKey = reader.readLine();
Base.log(this, "key is " + key + ", received is " + receivedKey);
Messages.log(this, "key is " + key + ", received is " + receivedKey);
// Base.log(this, "platform base is " + platform.base);
// if (platform.base != null) {
@@ -82,20 +82,20 @@ public class SingleInstance {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Base.log(this, "about to read line");
Messages.log(this, "about to read line");
String path = reader.readLine();
if (path == null) {
// Because an attempt was made to launch the PDE again,
// throw the user a bone by at least opening a new
// Untitled window for them.
Base.log(this, "opening new empty sketch");
Messages.log(this, "opening new empty sketch");
// platform.base.handleNew();
base.handleNew();
} else {
// loop through the sketches that were passed in
do {
Base.log(this, "calling open with " + path);
Messages.log(this, "calling open with " + path);
// platform.base.handleOpen(filename);
base.handleOpen(path);
path = reader.readLine();
@@ -107,18 +107,18 @@ public class SingleInstance {
}
});
} else {
Base.log(this, "keys do not match");
Messages.log(this, "keys do not match");
}
// }
} catch (IOException e) {
Base.loge("SingleInstance error while listening", e);
Messages.loge("SingleInstance error while listening", e);
}
}
}
}, "SingleInstance Server").start();
} catch (IOException e) {
Base.loge("Could not create single instance server.", e);
Messages.loge("Could not create single instance server.", e);
}
}
+64 -74
View File
@@ -274,8 +274,8 @@ public class Sketch {
// if read-only, give an error
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(Language.text("new.messages.is_read_only"),
Language.text("new.messages.is_read_only.description"));
Messages.showMessage(Language.text("new.messages.is_read_only"),
Language.text("new.messages.is_read_only.description"));
return;
}
@@ -293,22 +293,22 @@ public class Sketch {
ensureExistence();
if (currentIndex == 0 && isUntitled()) {
Base.showMessage(Language.text("rename.messages.is_untitled"),
Language.text("rename.messages.is_untitled.description"));
Messages.showMessage(Language.text("rename.messages.is_untitled"),
Language.text("rename.messages.is_untitled.description"));
return;
}
if (isModified()) {
Base.showMessage(Language.text("menu.file.save"),
Language.text("rename.messages.is_modified"));
Messages.showMessage(Language.text("menu.file.save"),
Language.text("rename.messages.is_modified"));
return;
}
// if read-only, give an error
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(Language.text("rename.messages.is_read_only"),
Language.text("rename.messages.is_read_only.description"));
Messages.showMessage(Language.text("rename.messages.is_read_only"),
Language.text("rename.messages.is_read_only.description"));
return;
}
@@ -440,17 +440,17 @@ public class Sketch {
}
if (newName.startsWith(".")) {
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.text("name.messages.starts_with_dot.description"));
Messages.showWarning(Language.text("name.messages.problem_renaming"),
Language.text("name.messages.starts_with_dot.description"));
return;
}
int dot = newName.lastIndexOf('.');
String newExtension = newName.substring(dot+1).toLowerCase();
if (!mode.validExtension(newExtension)) {
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.invalid_extension.description",
newExtension));
Messages.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.invalid_extension.description",
newExtension));
return;
}
@@ -458,9 +458,9 @@ public class Sketch {
if (!mode.isDefaultExtension(newExtension)) {
if (renamingCode) { // If creating a new tab, don't show this error
if (current == code[0]) { // If this is the main tab, disallow
Base.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.main_java_extension.description",
newExtension));
Messages.showWarning(Language.text("name.messages.problem_renaming"),
Language.interpolate("name.messages.main_java_extension.description",
newExtension));
return;
}
}
@@ -484,9 +484,9 @@ public class Sketch {
// http://processing.org/bugs/bugzilla/543.html
for (SketchCode c : code) {
if (c != current && sanitaryName.equalsIgnoreCase(c.getPrettyName())) {
Base.showMessage(Language.text("name.messages.new_sketch_exists"),
Language.interpolate("name.messages.new_sketch_exists.description",
c.getFileName(), folder.getAbsolutePath()));
Messages.showMessage(Language.text("name.messages.new_sketch_exists"),
Language.interpolate("name.messages.new_sketch_exists.description",
c.getFileName(), folder.getAbsolutePath()));
return;
}
}
@@ -500,17 +500,17 @@ public class Sketch {
String folderName = newName.substring(0, newName.indexOf('.'));
File newFolder = new File(folder.getParentFile(), folderName);
if (newFolder.exists()) {
Base.showWarning(Language.text("name.messages.new_folder_exists"),
Language.interpolate("name.messages.new_folder_exists.description",
newName));
Messages.showWarning(Language.text("name.messages.new_folder_exists"),
Language.interpolate("name.messages.new_folder_exists.description",
newName));
return;
}
// renaming the containing sketch folder
boolean success = folder.renameTo(newFolder);
if (!success) {
Base.showWarning(Language.text("name.messages.error"),
Language.text("name.messages.no_rename_folder.description"));
Messages.showWarning(Language.text("name.messages.error"),
Language.text("name.messages.no_rename_folder.description"));
return;
}
// let this guy know where he's living (at least for a split second)
@@ -530,9 +530,9 @@ public class Sketch {
// This isn't changing folders, just changes the name
newFile = new File(newFolder, newName);
if (!current.renameTo(newFile, newExtension)) {
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
Messages.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
return;
}
@@ -562,9 +562,9 @@ public class Sketch {
} else { // else if something besides code[0]
if (!current.renameTo(newFile, newExtension)) {
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
Messages.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_rename_file.description",
current.getFileName(), newFile.getName()));
return;
}
}
@@ -576,10 +576,9 @@ public class Sketch {
throw new IOException("createNewFile() returned false");
}
} catch (IOException e) {
Base.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_create_file.description",
newFile, folder.getAbsolutePath()),
e);
Messages.showWarning(Language.text("name.messages.error"),
Language.interpolate("name.messages.no_create_file.description",
newFile, folder.getAbsolutePath()), e);
return;
}
SketchCode newCode = new SketchCode(newFile, newExtension);
@@ -608,15 +607,15 @@ public class Sketch {
// if read-only, give an error
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(Language.text("delete.messages.is_read_only"),
Language.text("delete.messages.is_read_only.description"));
Messages.showMessage(Language.text("delete.messages.is_read_only"),
Language.text("delete.messages.is_read_only.description"));
return;
}
// don't allow if untitled
if (currentIndex == 0 && isUntitled()) {
Base.showMessage(Language.text("delete.messages.cannot_delete"),
Language.text("delete.messages.cannot_delete.description"));
Messages.showMessage(Language.text("delete.messages.cannot_delete"),
Language.text("delete.messages.cannot_delete.description"));
return;
}
@@ -652,9 +651,9 @@ public class Sketch {
} else {
// delete the file
if (!current.deleteFile()) {
Base.showMessage(Language.text("delete.messages.cannot_delete.file"),
Language.text("delete.messages.cannot_delete.file.description")+" \"" +
current.getFileName() + "\".");
Messages.showMessage(Language.text("delete.messages.cannot_delete.file"),
Language.text("delete.messages.cannot_delete.file.description")+" \"" +
current.getFileName() + "\".");
return;
}
@@ -762,8 +761,8 @@ public class Sketch {
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(Language.text("save_file.messages.is_read_only"),
Language.text("save_file.messages.is_read_only.description"));
Messages.showMessage(Language.text("save_file.messages.is_read_only"),
Language.text("save_file.messages.is_read_only.description"));
// if the user cancels, give up on the save()
if (!saveAs()) return false;
}
@@ -838,9 +837,9 @@ public class Sketch {
String sanitaryName = Sketch.checkName(newName);
File newFolder = new File(newParentDir, sanitaryName);
if (!sanitaryName.equals(newName) && newFolder.exists()) {
Base.showMessage(Language.text("save_file.messages.sketch_exists"),
Language.interpolate("save_file.messages.sketch_exists.description",
sanitaryName));
Messages.showMessage(Language.text("save_file.messages.sketch_exists"),
Language.interpolate("save_file.messages.sketch_exists.description",
sanitaryName));
return false;
}
newName = sanitaryName;
@@ -857,9 +856,9 @@ public class Sketch {
// resaved (with the same name) to another location/folder.
for (int i = 1; i < codeCount; i++) {
if (newName.equalsIgnoreCase(code[i].getPrettyName())) {
Base.showMessage(Language.text("save_file.messages.tab_exists"),
Language.interpolate("save_file.messages.tab_exists.description",
newName));
Messages.showMessage(Language.text("save_file.messages.tab_exists"),
Language.interpolate("save_file.messages.tab_exists.description",
newName));
return false;
}
}
@@ -877,9 +876,8 @@ public class Sketch {
String oldPath = folder.getCanonicalPath() + File.separator;
if (newPath.indexOf(oldPath) == 0) {
Base.showWarning(Language.text("save_file.messages.recursive_save"),
Language.text("save_file.messages.recursive_save.description"),
null);
Messages.showWarning(Language.text("save_file.messages.recursive_save"),
Language.text("save_file.messages.recursive_save.description"));
return false;
}
} catch (IOException e) { }
@@ -1014,8 +1012,8 @@ public class Sketch {
// if read-only, give an error
if (isReadOnly()) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(Language.text("add_file.messages.is_read_only"),
Language.text("add_file.messages.is_read_only.description"));
Messages.showMessage(Language.text("add_file.messages.is_read_only"),
Language.text("add_file.messages.is_read_only.description"));
return;
}
@@ -1114,19 +1112,16 @@ public class Sketch {
if (replacement) {
boolean muchSuccess = destFile.delete();
if (!muchSuccess) {
Base.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_delete.description",
filename),
null);
Messages.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_delete.description", filename));
return false;
}
}
// make sure they aren't the same file
if ((codeExtension == null) && sourceFile.equals(destFile)) {
Base.showWarning(Language.text("add_file.messages.same_file"),
Language.text("add_file.messages.same_file.description"),
null);
Messages.showWarning(Language.text("add_file.messages.same_file"),
Language.text("add_file.messages.same_file.description"));
return false;
}
@@ -1140,10 +1135,8 @@ public class Sketch {
Util.copyFile(sourceFile, destFile);
} catch (IOException e) {
Base.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_add.description",
filename),
e);
Messages.showWarning(Language.text("add_file.messages.error_adding"),
Language.interpolate("add_file.messages.cannot_add.description", filename), e);
return false;
}
}
@@ -1236,9 +1229,8 @@ public class Sketch {
return Util.createTempFolder(name, "temp", null);
} catch (IOException e) {
Base.showWarning(Language.text("temp_dir.messages.bad_build_folder"),
Language.text("temp_dir.messages.bad_build_folder.description"),
e);
Messages.showWarning(Language.text("temp_dir.messages.bad_build_folder"),
Language.text("temp_dir.messages.bad_build_folder.description"), e);
}
return null;
}
@@ -1294,9 +1286,8 @@ public class Sketch {
public void ensureExistence() {
if (!folder.exists()) {
// Disaster recovery, try to salvage what's there already.
Base.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
Language.text("ensure_exist.messages.missing_sketch.description"),
null);
Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
Language.text("ensure_exist.messages.missing_sketch.description"));
try {
folder.mkdirs();
modified = true;
@@ -1307,9 +1298,8 @@ public class Sketch {
calcModified();
} catch (Exception e) {
Base.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
Language.text("ensure_exist.messages.unrecoverable.description"),
e);
Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
Language.text("ensure_exist.messages.unrecoverable.description"), e);
}
}
}
@@ -30,6 +30,7 @@ import javax.swing.SwingWorker;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Util;
import processing.app.ui.Editor;
import processing.core.PApplet;
@@ -661,18 +662,17 @@ public class ContributionManager {
static private void installOnStartUp(final Base base, final AvailableContribution availableContrib) {
if (availableContrib.link == null) {
Base.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contrib.unsupported_operating_system"));
return;
}
try {
URL downloadUrl = new URL(availableContrib.link);
Messages.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contrib.unsupported_operating_system"));
} else {
try {
URL downloadUrl = new URL(availableContrib.link);
ContributionManager.downloadAndInstallOnStartup(base, downloadUrl, availableContrib);
ContributionManager.downloadAndInstallOnStartup(base, downloadUrl, availableContrib);
} catch (MalformedURLException e) {
Base.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contrib.errors.malformed_url"), e);
} catch (MalformedURLException e) {
Messages.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
Language.text("contrib.errors.malformed_url"), e);
}
}
}
@@ -207,7 +207,7 @@ public class ContributionManagerDialog {
while (iter.hasNext()) {
Editor ed = iter.next();
if (ed.getSketch().isModified()) {
int option = Base.showYesNoQuestion(editor, title, Language
int option = Messages.showYesNoQuestion(editor, title, Language
.text("contrib.unsaved_changes"), Language
.text("contrib.unsaved_changes.prompt"));
@@ -42,6 +42,7 @@ import javax.swing.text.html.StyleSheet;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.ui.Editor;
import processing.app.ui.Toolkit;
@@ -635,8 +636,8 @@ class ContributionPanel extends JPanel {
listPanel.contributionTab.statusPanel);
} catch (MalformedURLException e) {
Base.showWarning(Language.text("contrib.errors.install_failed"),
Language.text("contrib.errors.malformed_url"), e);
Messages.showWarning(Language.text("contrib.errors.install_failed"),
Language.text("contrib.errors.malformed_url"), e);
// not sure why we'd re-enable the button if it had an error...
// installRemoveButton.setEnabled(true);
}
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import processing.app.Base;
import processing.app.Library;
import processing.app.Messages;
import processing.app.Util;
import processing.app.ui.Editor;
@@ -176,7 +177,7 @@ public enum ContributionType {
return null;
} else if (folders.length > 1) {
Base.log("More than one " + toString() + " found inside " + folder.getAbsolutePath());
Messages.log("More than one " + toString() + " found inside " + folder.getAbsolutePath());
}
return folders[0];
}
@@ -107,7 +107,7 @@ public abstract class LocalContribution extends Contribution {
}
} else {
Base.log("No properties file at " + propertiesFile.getAbsolutePath());
Messages.log("No properties file at " + propertiesFile.getAbsolutePath());
// We'll need this to be set at a minimum.
name = folder.getName();
categories = unknownCategoryList();
@@ -134,7 +134,7 @@ public abstract class LocalContribution extends Contribution {
public String initLoader(String className) throws Exception {
File modeDirectory = new File(folder, getTypeName());
if (modeDirectory.exists()) {
Base.log("checking mode folder regarding " + className);
Messages.log("checking mode folder regarding " + className);
// If no class name specified, search the main <modename>.jar for the
// full name package and mode name.
if (className == null) {
@@ -157,12 +157,12 @@ public abstract class LocalContribution extends Contribution {
if (archives != null && archives.length > 0) {
URL[] urlList = new URL[archives.length];
for (int j = 0; j < urlList.length; j++) {
Base.log("Found archive " + archives[j] + " for " + getName());
Messages.log("Found archive " + archives[j] + " for " + getName());
urlList[j] = archives[j].toURI().toURL();
}
// loader = new URLClassLoader(urlList, Thread.currentThread().getContextClassLoader());
loader = new URLClassLoader(urlList);
Base.log("loading above JARs with loader " + loader);
Messages.log("loading above JARs with loader " + loader);
// System.out.println("listing classes for loader " + loader);
// listClasses(loader);
}
@@ -269,7 +269,7 @@ public abstract class LocalContribution extends Contribution {
boolean doBackup = Preferences.getBoolean("contribution.backup.on_install");
if (confirmReplace) {
if (doBackup) {
result = Base.showYesNoQuestion(editor, "Replace",
result = Messages.showYesNoQuestion(editor, "Replace",
"Replace pre-existing \"" + oldContrib.getName() + "\" library?",
"A pre-existing copy of the \"" + oldContrib.getName() + "\" library<br>"+
"has been found in your sketchbook. Clicking “Yes”<br>"+
@@ -279,7 +279,7 @@ public abstract class LocalContribution extends Contribution {
return null;
}
} else {
result = Base.showYesNoQuestion(editor, "Replace",
result = Messages.showYesNoQuestion(editor, "Replace",
"Replace pre-existing \"" + oldContrib.getName() + "\" library?",
"A pre-existing copy of the \"" + oldContrib.getName() + "\" library<br>"+
"has been found in your sketchbook. Clicking “Yes”<br>"+
@@ -417,13 +417,13 @@ public abstract class LocalContribution extends Contribution {
break;
}
}
if (!isModeActive)
if (!isModeActive) {
m.clearClassLoader(editor.getBase());
else {
} else {
pm.cancel();
Base.showMessage("Mode Manager",
"Please save your Sketch and change the Mode of all Editor\nwindows that have "
+ this.name + " as the active Mode.");
Messages.showMessage("Mode Manager",
"Please save your Sketch and change the Mode of all Editor\n" +
"windows that have " + name + " as the active Mode.");
return;
}
}
@@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.Util;
@@ -51,7 +52,7 @@ public class ModeContribution extends LocalContribution {
return new ModeContribution(base, folder, searchName);
} catch (IgnorableException ig) {
Base.log(ig.getMessage());
Messages.log(ig.getMessage());
} catch (Throwable err) {
// Throwable to catch Exceptions or UnsupportedClassVersionError et al
@@ -65,7 +66,7 @@ public class ModeContribution extends LocalContribution {
// For the built-in modes, don't print the exception, just log it
// for debugging. This should be impossible for most users to reach,
// but it helps us load experimental mode when it's available.
Base.loge("ModeContribution.load() failed for " + searchName, err);
Messages.loge("ModeContribution.load() failed for " + searchName, err);
}
}
return null;
@@ -85,7 +86,7 @@ public class ModeContribution extends LocalContribution {
className = initLoader(base, className);
if (className != null) {
Class<?> modeClass = loader.loadClass(className);
Base.log("Got mode class " + modeClass);
Messages.log("Got mode class " + modeClass);
Constructor con = modeClass.getConstructor(Base.class, File.class);
mode = (Mode) con.newInstance(base, folder);
mode.setClassLoader(loader);
@@ -141,7 +142,7 @@ public class ModeContribution extends LocalContribution {
System.err.println(folder.getName() + " is not compatible with this version of Processing");
// System.err.println(ncdfe.getMessage());
} catch (IgnorableException ig) {
Base.log(ig.getMessage());
Messages.log(ig.getMessage());
} catch (Throwable e) {
e.printStackTrace();
}
@@ -184,7 +185,7 @@ public class ModeContribution extends LocalContribution {
File modeDirectory = new File(folder, getTypeName());
if (modeDirectory.exists()) {
Base.log("checking mode folder regarding " + className);
Messages.log("checking mode folder regarding " + className);
// If no class name specified, search the main <modename>.jar for the
// full name package and mode name.
if (className == null) {
@@ -215,7 +216,7 @@ public class ModeContribution extends LocalContribution {
for(String modeImport: imports){
if (installedModes.containsKey(modeImport)) {
Base.log("Found mode dependency " + modeImport);
Messages.log("Found mode dependency " + modeImport);
File modeFolder = installedModes.get(modeImport).getFolder();
File[] archives = Util.listJarFiles(new File(modeFolder, "mode"));
if (archives != null && archives.length > 0) {
@@ -244,12 +245,12 @@ public class ModeContribution extends LocalContribution {
}
for (int k = 0; k < archives.length; k++,j++) {
Base.log("Found archive " + archives[k] + " for " + getName());
Messages.log("Found archive " + archives[k] + " for " + getName());
urlList[j] = archives[k].toURI().toURL();
}
loader = new URLClassLoader(urlList);
Base.log("loading above JARs with loader " + loader);
Messages.log("loading above JARs with loader " + loader);
// System.out.println("listing classes for loader " + loader);
// listClasses(loader);
}
@@ -27,6 +27,7 @@ import java.net.URLClassLoader;
import java.util.*;
import processing.app.Base;
import processing.app.Messages;
//import processing.app.Base;
import processing.app.tools.Tool;
import processing.app.ui.Editor;
@@ -41,7 +42,7 @@ public class ToolContribution extends LocalContribution implements Tool {
try {
return new ToolContribution(folder);
} catch (IgnorableException ig) {
Base.log(ig.getMessage());
Messages.log(ig.getMessage());
} catch (VerifyError ve) { // incompatible
// avoid the excessive error spew that happens here
@@ -25,18 +25,12 @@ package processing.app.platform;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import javax.swing.UIManager;
import processing.app.Base;
import processing.app.Preferences;
import processing.app.Util;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.FileUtils;
/**
@@ -126,58 +120,4 @@ public class DefaultPlatform {
public void openFolder(File file) throws Exception {
Desktop.getDesktop().open(file);
}
/**
* Attempts to move to the Trash on OS X, or the Recycle Bin on Windows.
* Also tries to find a suitable Trash location on Linux.
* If not possible, just deletes the file or folder instead.
* @param file the folder or file to be removed/deleted
* @return true if the folder was successfully removed
* @throws IOException
*/
final public boolean deleteFile(File file) throws IOException {
FileUtils fu = FileUtils.getInstance();
if (fu.hasTrash()) {
fu.moveToTrash(new File[] { file });
return true;
} else if (file.isDirectory()) {
Util.removeDir(file);
return true;
} else {
return file.delete();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
int setenv(String name, String value, int overwrite);
String getenv(String name);
int unsetenv(String name);
int putenv(String string);
}
public void setenv(String variable, String value) {
CLibrary clib = CLibrary.INSTANCE;
clib.setenv(variable, value, 1);
}
public String getenv(String variable) {
CLibrary clib = CLibrary.INSTANCE;
return clib.getenv(variable);
}
public int unsetenv(String variable) {
CLibrary clib = CLibrary.INSTANCE;
return clib.unsetenv(variable);
}
}
@@ -26,6 +26,7 @@ import java.io.File;
import java.awt.Toolkit;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.app.platform.DefaultPlatform;
@@ -40,13 +41,13 @@ public class LinuxPlatform extends DefaultPlatform {
if (javaVendor == null ||
(!javaVendor.contains("Sun") && !javaVendor.contains("Oracle")) ||
javaVM == null || !javaVM.contains("Java")) {
Base.showWarning("Not fond of this Java VM",
"Processing requires Java 7 from Sun (i.e. the sun-java-jdk\n" +
"package on Ubuntu). Other versions such as OpenJDK, IcedTea,\n" +
"and GCJ are strongly discouraged. Among other things, you're\n" +
"likely to run into problems with sketch window size and\n" +
"placement. For more background, please read the wiki:\n" +
"https://github.com/processing/processing/wiki/Supported-Platforms#Linux", null);
Messages.showWarning("Not fond of this Java VM",
"Processing requires Java 8 from Sun (i.e. the sun-java-jdk\n" +
"package on Ubuntu). Other versions such as OpenJDK, IcedTea,\n" +
"and GCJ are strongly discouraged. Among other things, you're\n" +
"likely to run into problems with sketch window size and\n" +
"placement. For more background, please read the wiki:\n" +
"https://github.com/processing/processing/wiki/Supported-Platforms#Linux", null);
}
// Set x11 WM_CLASS property which is used as the application
@@ -29,6 +29,7 @@ import java.io.IOException;
import com.apple.eio.FileManager;
import processing.app.Base;
import processing.app.Messages;
import processing.app.platform.DefaultPlatform;
@@ -57,7 +58,7 @@ public class MacPlatform extends DefaultPlatform {
try {
Runtime.getRuntime().exec(cmdarray);
} catch (IOException e) {
Base.log("Error saving platform language: " + e.getMessage());
Messages.log("Error saving platform language: " + e.getMessage());
}
}
@@ -36,6 +36,7 @@ import com.sun.jna.platform.win32.WinError;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.app.platform.DefaultPlatform;
import processing.app.platform.WindowsRegistry.REGISTRY_ROOT_KEY;
@@ -215,7 +216,7 @@ public class WindowsPlatform extends DefaultPlatform {
// hooray!
} else {
Base.log("Could not associate files, turning off auto-associate pref.");
Messages.log("Could not associate files, turning off auto-associate pref.");
Preferences.setBoolean("platform.auto_file_type_associations", false);
}
}
@@ -2369,7 +2369,7 @@ public class JEditTextArea extends JComponent
try {
select(getMarkPosition(), xyToOffset(evt.getX(), evt.getY()));
} catch (ArrayIndexOutOfBoundsException e) {
Base.loge("xToOffset problem", e);
Messages.loge("xToOffset problem", e);
}
} else {
int line = yToLine(evt.getY());
+1 -3
View File
@@ -65,9 +65,7 @@ public class Archiver implements Tool {
Sketch sketch = editor.getSketch();
if (sketch.isModified()) {
Base.showWarning("Save",
"Please save the sketch before archiving.",
null);
Messages.showWarning("Save", "Please save the sketch before archiving.");
return;
}
@@ -28,8 +28,8 @@ import java.io.PrintWriter;
import javax.swing.JOptionPane;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.ui.Editor;
import processing.core.PApplet;
@@ -112,10 +112,10 @@ public class InstallCommander implements Tool {
File targetFile = new File(System.getProperty("user.home"), "processing-java");
String targetPath = targetFile.getAbsolutePath();
if (targetFile.exists()) {
Base.showWarning("File Already Exists",
"The processing-java program already exists at:\n" +
targetPath + "\n" +
"Please remove it and try again.", null);
Messages.showWarning("File Already Exists",
"The processing-java program already exists at:\n" +
targetPath + "\n" +
"Please remove it and try again.");
} else {
PApplet.exec(new String[] { "mv", sourcePath, targetPath });
}
@@ -123,8 +123,8 @@ public class InstallCommander implements Tool {
editor.statusNotice("Finished.");
} catch (IOException e) {
Base.showWarning("Error while installing",
"An error occurred and the tools were not installed.", e);
Messages.showWarning("Error while installing",
"An error occurred and the tools were not installed.", e);
}
}
@@ -10,7 +10,7 @@ import java.lang.reflect.InvocationTargetException;
import javax.swing.JOptionPane;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.app.Sketch;
import processing.app.SketchCode;
@@ -184,7 +184,7 @@ public class ChangeDetector implements WindowFocusListener {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Base.showError(title, message, e);
Messages.showError(title, message, e);
}
});
}
@@ -194,7 +194,7 @@ public class ChangeDetector implements WindowFocusListener {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Base.showWarning(title, message);
Messages.showWarning(title, message);
}
});
}
@@ -209,7 +209,7 @@ public class ChangeDetector implements WindowFocusListener {
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
result[0] = Base.showYesNoQuestion(editor, title, message1, message2);
result[0] = Messages.showYesNoQuestion(editor, title, message1, message2);
}
});
} catch (InvocationTargetException e) {
+8 -8
View File
@@ -26,6 +26,7 @@ package processing.app.ui;
import processing.app.Base;
import processing.app.Formatter;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.Platform;
import processing.app.Preferences;
@@ -524,8 +525,8 @@ public abstract class Editor extends JFrame implements RunnerListener {
}
}
} catch (Exception e) {
Base.showWarning("Drag & Drop Problem",
"An error occurred while trying to add files to the sketch.", e);
Messages.showWarning("Drag & Drop Problem",
"An error occurred while trying to add files to the sketch.", e);
return false;
}
statusNotice(Language.pluralize("editor.status.drag_and_drop.files_added", successful));
@@ -564,9 +565,8 @@ public abstract class Editor extends JFrame implements RunnerListener {
if (!sketch.isModified()) {
base.changeMode(m);
} else {
Base.showWarning("Save",
"Please save the sketch before changing the mode.",
null);
Messages.showWarning("Save",
"Please save the sketch before changing the mode.");
// Re-select the old checkbox, because it was automatically
// updated by Java, even though the Mode could not be changed.
@@ -1246,7 +1246,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
statusError("\"" + tool.getMenuTitle() + "\" is not" +
"compatible with this version of Processing");
//nsme.printStackTrace();
Base.loge("Incompatible tool found during tool.run()", nsme);
Messages.loge("Incompatible tool found during tool.run()", nsme);
item.setEnabled(false);
} catch (Exception ex) {
@@ -1284,13 +1284,13 @@ public abstract class Editor extends JFrame implements RunnerListener {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + nsme.getMessage() + " method no longer exists.");
Base.loge("Incompatible Tool found during tool.init()", nsme);
Messages.loge("Incompatible Tool found during tool.init()", nsme);
} catch (NoClassDefFoundError ncdfe) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + ncdfe.getMessage() + " class is no longer available.");
Base.loge("Incompatible Tool found during tool.init()", ncdfe);
Messages.loge("Incompatible Tool found during tool.init()", ncdfe);
} catch (AbstractMethodError ame) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
+3 -3
View File
@@ -31,8 +31,8 @@ import java.util.Arrays;
import javax.swing.*;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.Platform;
import processing.app.Sketch;
@@ -477,8 +477,8 @@ public class EditorHeader extends JComponent {
if (!Platform.isMacOS() && // ok on OS X
editor.base.getEditors().size() == 1 && // mmm! accessor
sketch.getCurrentCodeIndex() == 0) {
Base.showWarning(Language.text("editor.header.delete.warning.title"),
Language.text("editor.header.delete.warning.text"), null);
Messages.showWarning(Language.text("editor.header.delete.warning.title"),
Language.text("editor.header.delete.warning.text"));
} else {
editor.getSketch().handleDeleteCode();
}
@@ -34,6 +34,7 @@ import javax.swing.event.*;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.ui.ColorChooser;
@@ -624,7 +625,7 @@ public class PreferencesFrame {
Preferences.set("editor.font.size", String.valueOf(selection));
} catch (NumberFormatException e) {
Base.log("Ignoring invalid font size " + fontSizeField); //$NON-NLS-1$
Messages.log("Ignoring invalid font size " + fontSizeField); //$NON-NLS-1$
fontSizeField.setSelectedItem(Preferences.getInteger("editor.font.size"));
}
@@ -637,7 +638,7 @@ public class PreferencesFrame {
Preferences.set("console.font.size", String.valueOf(selection));
} catch (NumberFormatException e) {
Base.log("Ignoring invalid font size " + consoleFontSizeField); //$NON-NLS-1$
Messages.log("Ignoring invalid font size " + consoleFontSizeField); //$NON-NLS-1$
consoleFontSizeField.setSelectedItem(Preferences.getInteger("console.font.size"));
}
+4 -1
View File
@@ -36,11 +36,14 @@ import javax.swing.JMenuItem;
import processing.app.Base;
import processing.app.Language;
import processing.app.Library;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.Preferences;
import processing.core.PApplet;
// TODO this isn't pretty... probably better to do an internal instance fancy thing
// dealing with renaming
// before sketch save/rename, remove it from the recent list
// after sketch save/rename add it to the list
@@ -88,7 +91,7 @@ public class Recent {
if (new File(line).exists()) { // don't add ghost entries
records.add(new Record(line));
} else {
Base.log("ghost file: " + line);
Messages.log("ghost file: " + line);
}
}
}
+4 -4
View File
@@ -66,8 +66,8 @@ import javax.swing.JPopupMenu;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.Preferences;
@@ -828,7 +828,7 @@ public class Toolkit {
}
}
} catch (Exception e) {
Base.loge("Could not load mono font", e);
Messages.loge("Could not load mono font", e);
monoFont = new Font("Monospaced", Font.PLAIN, size);
monoBoldFont = new Font("Monospaced", Font.BOLD, size);
}
@@ -864,7 +864,7 @@ public class Toolkit {
}
}
} catch (Exception e) {
Base.loge("Could not load sans font", e);
Messages.loge("Could not load sans font", e);
sansFont = new Font("SansSerif", Font.PLAIN, size);
sansBoldFont = new Font("SansSerif", Font.BOLD, size);
}
@@ -914,7 +914,7 @@ public class Toolkit {
} else {
msg += "Please reinstall Processing.";
}
Base.showError("Font Sadness", msg, null);
Messages.showError("Font Sadness", msg, null);
}
BufferedInputStream input = new BufferedInputStream(new FileInputStream(fontFile));