use of processing.app.ui.Editor in project processing by processing.
the class LocalContribution method remove.
void remove(final Base base, final ContribProgressMonitor pm, final StatusPanel status, final ContributionListing contribListing) {
pm.startTask("Removing", ContribProgressMonitor.UNKNOWN);
boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove");
// if (getType().requiresRestart()) {
// if (!doBackup || (doBackup && backup(editor, false, status))) {
// if (setDeletionFlag(true)) {
// contribListing.replaceContribution(this, this);
// }
// }
// } else {
boolean success = false;
if (getType() == ContributionType.MODE) {
boolean isModeActive = false;
ModeContribution m = (ModeContribution) this;
Iterator<Editor> iter = base.getEditors().iterator();
while (iter.hasNext()) {
Editor e = iter.next();
if (e.getMode().equals(m.getMode())) {
isModeActive = true;
break;
}
}
if (!isModeActive) {
m.clearClassLoader(base);
} else {
pm.cancel();
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;
}
}
if (getType() == ContributionType.TOOL) {
/*
ToolContribution t = (ToolContribution) this;
Iterator<Editor> iter = editor.getBase().getEditors().iterator();
while (iter.hasNext()) {
Editor ed = iter.next();
ed.clearToolMenu();
}
t.clearClassLoader(editor.getBase());
*/
// menu will be rebuilt below with the refreshContribs() call
base.clearToolMenus();
((ToolContribution) this).clearClassLoader();
}
if (doBackup) {
success = backup(true, status);
} else {
success = Util.removeDir(getFolder(), false);
}
if (success) {
try {
// TODO: run this in SwingWorker done() [jv]
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
Contribution advertisedVersion = contribListing.getAvailableContribution(LocalContribution.this);
if (advertisedVersion == null) {
contribListing.removeContribution(LocalContribution.this);
} else {
contribListing.replaceContribution(LocalContribution.this, advertisedVersion);
}
base.refreshContribs(LocalContribution.this.getType());
base.setUpdatesAvailable(contribListing.countUpdates(base));
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
cause.printStackTrace();
}
}
} else {
// There was a failure backing up the folder
if (!doBackup || (doBackup && backup(false, status))) {
if (setDeletionFlag(true)) {
try {
// TODO: run this in SwingWorker done() [jv]
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
contribListing.replaceContribution(LocalContribution.this, LocalContribution.this);
base.refreshContribs(LocalContribution.this.getType());
base.setUpdatesAvailable(contribListing.countUpdates(base));
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
cause.printStackTrace();
}
}
}
} else {
status.setErrorMessage("Could not delete the contribution's files");
}
}
if (success) {
pm.finished();
} else {
pm.cancel();
}
}
use of processing.app.ui.Editor in project processing by processing.
the class CheckBoxList method build.
public void build() {
int fontsize = 0;
try {
fontsize = Integer.parseInt(sizeSelector.getText().trim());
} catch (NumberFormatException e) {
}
if (fontsize <= 0) {
JOptionPane.showMessageDialog(this, "Bad font size, try again.", "Badness", JOptionPane.WARNING_MESSAGE);
return;
}
String filename = filenameField.getText().trim();
if (filename.length() == 0) {
JOptionPane.showMessageDialog(this, "Enter a file name for the font.", "Lameness", JOptionPane.WARNING_MESSAGE);
return;
}
if (!filename.endsWith(".vlw")) {
filename += ".vlw";
}
try {
Font instance = table.get(list[selection]);
font = instance.deriveFont(Font.PLAIN, fontsize);
//PFont f = new PFont(font, smooth, all ? null : PFont.CHARSET);
PFont f = new PFont(font, smooth, charSelector.getCharacters());
// the editor may have changed while the window was open
Editor editor = base.getActiveEditor();
// make sure the 'data' folder exists
File folder = editor.getSketch().prepareDataFolder();
f.save(new FileOutputStream(new File(folder, filename)));
} catch (IOException e) {
JOptionPane.showMessageDialog(CreateFont.this, "An error occurred while creating font.", "No font for you", JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
}
setVisible(false);
}
use of processing.app.ui.Editor in project processing by processing.
the class InstallCommander method run.
public void run() {
try {
Editor editor = base.getActiveEditor();
final String primary = "Install processing-java for all users?";
final String secondary = "This will install the processing-java program, which is capable " + "of building and running Java Mode sketches from the command line. " + "Click “Yes” to install it for all users (an administrator password " + "is required), or “No” to place the program in your home directory. " + "If you rename or move Processing.app, " + "you'll need to reinstall the tool.";
int result = JOptionPane.showConfirmDialog(editor, "<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>", "Commander", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.CANCEL_OPTION) {
return;
}
File file = File.createTempFile("processing", "commander");
PrintWriter writer = PApplet.createWriter(file);
writer.print("#!/bin/sh\n\n");
writer.print("# Prevents processing-java from stealing focus, see:\n" + "# https://github.com/processing/processing/issues/3996.\n" + "OPTION_FOR_HEADLESS_RUN=\"\"\n" + "for ARG in \"$@\"\n" + "do\n" + " if [ \"$ARG\" = \"--build\" ]; then\n" + " OPTION_FOR_HEADLESS_RUN=\"-Djava.awt.headless=true\"\n" + " fi\n" + "done\n\n");
String javaRoot = Platform.getContentFile(".").getCanonicalPath();
StringList jarList = new StringList();
addJarList(jarList, new File(javaRoot));
addJarList(jarList, new File(javaRoot, "core/library"));
addJarList(jarList, new File(javaRoot, "modes/java/mode"));
String classPath = jarList.join(":").replaceAll(javaRoot + "\\/?", "");
writer.println("cd \"" + javaRoot + "\" && " + Platform.getJavaPath().replaceAll(" ", "\\\\ ") + " -Djna.nosys=true" + " $OPTION_FOR_HEADLESS_RUN" + " -cp \"" + classPath + "\"" + " processing.mode.java.Commander \"$@\"");
writer.flush();
writer.close();
file.setExecutable(true);
String sourcePath = file.getAbsolutePath();
if (result == JOptionPane.YES_OPTION) {
// Moving to /usr/local/bin instead of /usr/bin for compatibility
// with OS X 10.11 and its "System Integrity Protection"
// https://github.com/processing/processing/issues/3497
String targetPath = "/usr/local/bin/processing-java";
// Remove the old version in case it exists
// https://github.com/processing/processing/issues/3786
String oldPath = "/usr/bin/processing-java";
String shellScript = "/bin/rm -f " + oldPath + " && /bin/mkdir -p /usr/local/bin" + " && /bin/mv " + sourcePath + " " + targetPath;
String appleScript = "do shell script \"" + shellScript + "\" with administrator privileges";
PApplet.exec(new String[] { "osascript", "-e", appleScript });
} else if (result == JOptionPane.NO_OPTION) {
File targetFile = new File(System.getProperty("user.home"), "processing-java");
String targetPath = targetFile.getAbsolutePath();
if (targetFile.exists()) {
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 });
}
}
editor.statusNotice("Finished.");
} catch (IOException e) {
Messages.showWarning("Error while installing", "An error occurred and the tool was not installed.", e);
}
}
use of processing.app.ui.Editor in project processing by processing.
the class LocalContribution method copyAndLoad.
/*
// doesn't work with URLClassLoader, but works with the system CL
static void listClasses(ClassLoader loader) {
// loader = Thread.currentThread().getContextClassLoader();
try {
Field f = ClassLoader.class.getDeclaredField("classes");
f.setAccessible(true);
Vector<Class> classes = (Vector<Class>) f.get(loader);
for (Class c : classes) {
System.out.println(c.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
*/
// static protected boolean isCandidate(File potential, final ContributionType type) {
// return (potential.isDirectory() &&
// new File(potential, type.getFolderName()).exists());
// }
//
//
// /**
// * Return a list of directories that have the necessary subfolder for this
// * contribution type. For instance, a list of folders that have a 'mode'
// * subfolder if this is a ModeContribution.
// */
// static protected File[] listCandidates(File folder, final ContributionType type) {
// return folder.listFiles(new FileFilter() {
// public boolean accept(File potential) {
// return isCandidate(potential, type);
// }
// });
// }
//
//
// /**
// * Return the first directory that has the necessary subfolder for this
// * contribution type. For instance, the first folder that has a 'mode'
// * subfolder if this is a ModeContribution.
// */
// static protected File findCandidate(File folder, final ContributionType type) {
// File[] folders = listCandidates(folder, type);
//
// if (folders.length == 0) {
// return null;
//
// } else if (folders.length > 1) {
// Base.log("More than one " + type.toString() + " found inside " + folder.getAbsolutePath());
// }
// return folders[0];
// }
LocalContribution copyAndLoad(Base base, boolean confirmReplace, StatusPanel status) {
// NOTE: null status => function is called on startup when Editor objects, et al. aren't ready
String contribFolderName = getFolder().getName();
File contribTypeFolder = getType().getSketchbookFolder();
File contribFolder = new File(contribTypeFolder, contribFolderName);
if (status != null) {
// when status != null, install is not occurring on startup
Editor editor = base.getActiveEditor();
ArrayList<LocalContribution> oldContribs = getType().listContributions(editor);
// In case an update marker exists, and the user wants to install, delete the update marker
if (contribFolder.exists() && !contribFolder.isDirectory()) {
contribFolder.delete();
contribFolder = new File(contribTypeFolder, contribFolderName);
}
for (LocalContribution oldContrib : oldContribs) {
if ((oldContrib.getFolder().exists() && oldContrib.getFolder().equals(contribFolder)) || (oldContrib.getId() != null && oldContrib.getId().equals(getId()))) {
if (oldContrib.getType().requiresRestart()) {
// XXX: We can't replace stuff, soooooo.... do something different
if (!oldContrib.backup(false, status)) {
return null;
}
} else {
int result = 0;
boolean doBackup = Preferences.getBoolean("contribution.backup.on_install");
if (confirmReplace) {
if (doBackup) {
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>" + "will move the existing library to a backup folder<br>" + "in <i>libraries/old</i> before replacing it.");
if (result != JOptionPane.YES_OPTION || !oldContrib.backup(true, status)) {
return null;
}
} else {
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>" + "will permanently delete this library and all of its contents<br>" + "before replacing it.");
if (result != JOptionPane.YES_OPTION || !oldContrib.getFolder().delete()) {
return null;
}
}
} else {
if ((doBackup && !oldContrib.backup(true, status)) || (!doBackup && !oldContrib.getFolder().delete())) {
return null;
}
}
}
}
}
// At this point it should be safe to replace this fella
if (contribFolder.exists()) {
Util.removeDir(contribFolder);
}
} else {
// is to be called only when restarting on update
if (contribFolder.exists() && contribFolder.isDirectory()) {
Util.removeDir(contribFolder);
} else if (contribFolder.exists()) {
contribFolder.delete();
contribFolder = new File(contribTypeFolder, contribFolderName);
}
}
File oldFolder = getFolder();
try {
Util.copyDir(oldFolder, contribFolder);
} catch (IOException e) {
status.setErrorMessage("Could not copy " + getTypeName() + " \"" + getName() + "\" to the sketchbook.");
e.printStackTrace();
return null;
}
return getType().load(base, contribFolder);
}
use of processing.app.ui.Editor in project processing by processing.
the class ManagerFrame method makeAndShowTab.
void makeAndShowTab(boolean error, boolean loading) {
Editor editor = base.getActiveEditor();
librariesTab.showFrame(editor, error, loading);
modesTab.showFrame(editor, error, loading);
toolsTab.showFrame(editor, error, loading);
examplesTab.showFrame(editor, error, loading);
updatesTab.showFrame(editor, error, loading);
}
Aggregations