bringing android mode up to date, tweaking java mode

This commit is contained in:
benfry
2011-01-22 18:40:19 +00:00
parent cefdea6522
commit bb59356978
12 changed files with 228 additions and 77 deletions

View File

@@ -50,7 +50,7 @@ public class Compiler {
// String primaryClassName,
// String sketchClassPath,
// String bootClassPath) throws RunnerException {
static public boolean compile(Build build) throws SketchException {
static public boolean compile(JavaBuild build) throws SketchException {
// This will be filled in if anyone gets angry
SketchException exception = null;

View File

@@ -33,7 +33,7 @@ import processing.mode.java.preproc.*;
// Would you believe there's a java.lang.Compiler class? I wouldn't.
public class Build {
public class JavaBuild {
/**
* Regular expression for parsing the size() method. This should match
* against any uses of the size() function, whether numbers or variables
@@ -81,7 +81,7 @@ public class Build {
// this.sketch = editor.getSketch();
// }
public Build(Sketch sketch) {
public JavaBuild(Sketch sketch) {
this.sketch = sketch;
}

View File

@@ -57,17 +57,19 @@ public class JavaEditor extends Editor {
public JMenu buildFileMenu() {
JMenuItem exportApplet = Base.newJMenuItem("Export Applet", 'E');
String appletTitle = JavaToolbar.getTitle(JavaToolbar.EXPORT, false);
JMenuItem exportApplet = Base.newJMenuItem(appletTitle, 'E');
exportApplet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExportApplet();
handleExportProject();
}
});
JMenuItem exportApplication = Base.newJMenuItemShift("Export Application", 'E');
String appTitle = JavaToolbar.getTitle(JavaToolbar.EXPORT, true);
JMenuItem exportApplication = Base.newJMenuItemShift(appTitle, 'E');
exportApplication.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExportApplication();
handleExportPackage();
}
});
return buildFileMenu(new JMenuItem[] { exportApplet, exportApplication });
@@ -75,21 +77,21 @@ public class JavaEditor extends Editor {
public JMenu buildSketchMenu() {
JMenuItem runItem = Base.newJMenuItem("Run", 'R');
JMenuItem runItem = Base.newJMenuItem(JavaToolbar.getTitle(JavaToolbar.RUN, false), 'R');
runItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleRun();
}
});
JMenuItem presentItem = Base.newJMenuItemShift("Present", 'R');
JMenuItem presentItem = Base.newJMenuItemShift(JavaToolbar.getTitle(JavaToolbar.RUN, true), 'R');
presentItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handlePresent();
}
});
JMenuItem stopItem = new JMenuItem("Stop");
JMenuItem stopItem = new JMenuItem(JavaToolbar.getTitle(JavaToolbar.STOP, false));
stopItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleStop();
@@ -118,7 +120,7 @@ public class JavaEditor extends Editor {
* Made synchronized to (hopefully) avoid problems of people
* hitting export twice, quickly, and horking things up.
*/
public void handleExportApplet() {
public void handleExportProject() {
if (handleExportCheckModified()) {
toolbar.activate(JavaToolbar.EXPORT);
try {
@@ -153,7 +155,7 @@ public class JavaEditor extends Editor {
/**
* Handler for Sketch → Export Application
*/
public void handleExportApplication() {
public void handleExportPackage() {
toolbar.activate(JavaToolbar.EXPORT);
if (handleExportCheckModified()) {

View File

@@ -176,7 +176,7 @@ public class JavaMode extends Mode {
* @throws SketchException
*/
public void handleRun(Sketch sketch, RunnerListener listener) throws SketchException {
Build build = new Build(sketch);
JavaBuild build = new JavaBuild(sketch);
String appletClassName = build.build();
if (appletClassName != null) {
runtime = new Runner(build, listener);
@@ -186,7 +186,7 @@ public class JavaMode extends Mode {
public void handlePresent(Sketch sketch, RunnerListener listener) throws SketchException {
Build build = new Build(sketch);
JavaBuild build = new JavaBuild(sketch);
String appletClassName = build.build();
if (appletClassName != null) {
runtime = new Runner(build, listener);
@@ -204,13 +204,13 @@ public class JavaMode extends Mode {
public boolean handleExportApplet(Sketch sketch) throws SketchException, IOException {
Build build = new Build(sketch);
JavaBuild build = new JavaBuild(sketch);
return build.exportApplet();
}
public boolean handleExportApplication(Sketch sketch) throws SketchException, IOException {
Build build = new Build(sketch);
JavaBuild build = new JavaBuild(sketch);
return build.exportApplication();
}
}

View File

@@ -31,22 +31,22 @@ import processing.app.EditorToolbar;
public class JavaToolbar extends EditorToolbar {
/** Rollover titles for each button. */
static final String title[] = {
"Run", "Stop", "New", "Open", "Save", "Export"
};
// static final String title[] = {
// "Run", "Stop", "New", "Open", "Save", "Export"
// };
/** Titles for each button when the shift key is pressed. */
static final String titleShift[] = {
"Present", "Stop", "New Editor Window", "Open in Another Window", "Save", "Export to Application"
};
static final int RUN = 0;
static final int STOP = 1;
// static final String titleShift[] = {
// "Present", "Stop", "New Editor Window", "Open in Another Window", "Save", "Export to Application"
// };
static final int NEW = 2;
static final int OPEN = 3;
static final int SAVE = 4;
static final int EXPORT = 5;
static protected final int RUN = 0;
static protected final int STOP = 1;
static protected final int NEW = 2;
static protected final int OPEN = 3;
static protected final int SAVE = 4;
static protected final int EXPORT = 5;
// JPopupMenu popup;
// JMenu menu;
@@ -57,9 +57,22 @@ public class JavaToolbar extends EditorToolbar {
Image[][] images = loadImages();
for (int i = 0; i < 6; i++) {
addButton(title[i], titleShift[i], images[i], i == NEW);
addButton(getTitle(i, false), getTitle(i, true), images[i], i == NEW);
}
}
static public String getTitle(int index, boolean shift) {
switch (index) {
case RUN: return shift ? "Run" : "Present";
case STOP: return "Stop";
case NEW: return shift ? "New" : "New Editor Window";
case OPEN: return shift ? "Open" : "Open in Another Window";
case SAVE: return "Save";
case EXPORT: return shift ? "Export Applet" : "Export Application";
}
return null;
}
public void handlePressed(MouseEvent e, int sel) {
@@ -100,9 +113,9 @@ public class JavaToolbar extends EditorToolbar {
case EXPORT:
if (shift) {
jeditor.handleExportApplication();
jeditor.handleExportPackage();
} else {
jeditor.handleExportApplet();
jeditor.handleExportProject();
}
break;
}

View File

@@ -26,7 +26,7 @@ package processing.mode.java.runner;
import processing.app.*;
import processing.app.exec.StreamRedirectThread;
import processing.core.*;
import processing.mode.java.Build;
import processing.mode.java.JavaBuild;
import java.awt.Point;
import java.io.*;
@@ -80,11 +80,11 @@ public class Runner implements MessageConsumer {
protected Editor editor;
// protected Sketch sketch;
protected Build build;
protected JavaBuild build;
// private String appletClassName;
public Runner(Build build, RunnerListener listener) {
public Runner(JavaBuild build, RunnerListener listener) {
this.listener = listener;
// this.sketch = sketch;
this.build = build;