js-mode cleanups

This commit is contained in:
fjenett
2011-06-07 06:13:02 +00:00
parent 2cf49ff26c
commit c2c56a7f1b
4 changed files with 40 additions and 56 deletions

View File

@@ -30,7 +30,7 @@ public class DirectivesEditor
{
JavaScriptEditor editor;
static JFrame frame;
JFrame frame;
JCheckBox crispBox;
JTextField fontField;
JCheckBox globalKeyEventsBox;
@@ -72,8 +72,9 @@ public class DirectivesEditor
{
if ( editor.getSketch().isModified())
{
Base.showWarning( "Directives Editor", "Please save your sketch before changing the directives.", null);
//editor.statusError("Please save your sketch before changing the directives.");
Base.showWarning( "Directives Editor",
"Please save your sketch before changing "+
"the directives.", null);
return;
}
@@ -85,7 +86,8 @@ public class DirectivesEditor
private void resetInterface ()
{
for ( JCheckBox b : new JCheckBox[]{ crispBox, globalKeyEventsBox, pauseOnBlurBox, transparentBox } )
for ( JCheckBox b : new JCheckBox[] {
crispBox, globalKeyEventsBox, pauseOnBlurBox, transparentBox } )
{
b.setSelected(false);
}

View File

@@ -131,7 +131,7 @@ public class JavaScriptBuild
* @param bin the output folder for the built sketch
* @return boolean whether the build was successful
*/
public boolean build ( File bin )
public boolean build ( File bin ) throws IOException, SketchException
{
// make sure the user isn't playing "hide-the-sketch-folder" again
sketch.ensureExistence();
@@ -144,20 +144,8 @@ public class JavaScriptBuild
} //else will be created during preprocesss
// pass through preprocessor to catch syntax errors
try
{
preprocess(bin);
} catch ( IOException ioe ) {
final String msg = "A problem occured while writing to the output folder.";
Base.showWarning("Could not build the sketch", msg, ioe);
return false;
} catch ( SketchException se ) {
final String msg = "The preprocessor found a problem in your code.";
Base.showWarning("Could not build the sketch", msg, se);
return false;
}
// .. exceptions bubble up.
preprocess(bin);
// move the data files, copies contents of sketch/data/ to applet_js/
if (sketch.hasDataFolder())
@@ -528,19 +516,9 @@ public class JavaScriptBuild
* Export the sketch to the default applet_js folder.
* @return success of the operation
*/
public boolean export() throws IOException
public boolean export() throws IOException, SketchException
{
File applet_js = new File(sketch.getFolder(), EXPORTED_FOLDER_NAME);
return exportToFolder( applet_js );
}
/**
* Export the sketch to the provided folder
* @return success of the operation
*/
public boolean exportToFolder( File exportFolder ) throws IOException
{
return build( exportFolder );
return build( applet_js );
}
}

View File

@@ -3,6 +3,7 @@ package processing.mode.javascript;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
@@ -12,6 +13,7 @@ import processing.app.Base;
import processing.app.Editor;
import processing.app.EditorToolbar;
import processing.app.Sketch;
import processing.app.SketchException;
import processing.app.Formatter;
import processing.app.Mode;
import processing.mode.java.AutoFormat;
@@ -90,19 +92,21 @@ public class JavaScriptEditor extends Editor
}
});
JMenuItem showDirectivesWindow = new JMenuItem("Directives");
JMenuItem showDirectivesWindow = new JMenuItem("Playback settings");
showDirectivesWindow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleShowDirectivesEditor();
}
});
JMenuItem copyTemplate = new JMenuItem("Copy template to sketch");
JMenuItem copyTemplate = new JMenuItem("Start custom template");
copyTemplate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Sketch sketch = getSketch();
File ajs = sketch.getMode().getContentFile(JavaScriptBuild.EXPORTED_FOLDER_NAME);
File tjs = new File( sketch.getFolder(), JavaScriptBuild.TEMPLATE_FOLDER_NAME );
File ajs = sketch.getMode().
getContentFile(JavaScriptBuild.EXPORTED_FOLDER_NAME);
File tjs = new File( sketch.getFolder(),
JavaScriptBuild.TEMPLATE_FOLDER_NAME );
if ( !tjs.exists() )
{
try {
@@ -281,13 +285,14 @@ public class JavaScriptEditor extends Editor
public void handleStartServer ()
{
statusEmpty();
boolean success = handleExport( false );
if ( !success ) return;
if ( !handleExport( false ) ) return;
File serverRoot = new File(sketch.getFolder(), JavaScriptBuild.EXPORTED_FOLDER_NAME);
File serverRoot = new File( sketch.getFolder(),
JavaScriptBuild.EXPORTED_FOLDER_NAME );
// if server hung or something else went wrong .. stop it.
if ( jsServer != null && (!jsServer.isRunning() || !jsServer.getRoot().equals(serverRoot)) )
if ( jsServer != null &&
(!jsServer.isRunning() || !jsServer.getRoot().equals(serverRoot)) )
{
jsServer.shutDown();
jsServer = null;
@@ -303,24 +308,14 @@ public class JavaScriptEditor extends Editor
String location = localDomain + ":" + jsServer.getPort() + "/";
statusNotice( "Server started: " + location );
//if ( !System.getProperty("os.name").startsWith("Mac OS") )
Base.openURL( location );
/*else
{
try {
String scpt = "osascript -e "+
"\"tell application \\\"Finder\\\" to open location \\\"" + location + "\\\"\"";
String[] cmd = { "/bin/bash", "-c", scpt };
Process process = new ProcessBuilder( cmd ).start();
} catch ( Exception e ) {
Base.openURL( location );
}
}*/
Base.openURL( location );
}
else if ( jsServer.isRunning() )
{
statusNotice( "Server running ("+localDomain + ":" + jsServer.getPort() +"), reload your browser window." );
statusNotice( "Server running (" +
localDomain + ":" + jsServer.getPort() +
"), reload your browser window." );
}
toolbar.activate(JavaScriptToolbar.RUN);
}
@@ -349,7 +344,8 @@ public class JavaScriptEditor extends Editor
boolean success = jsMode.handleExport(sketch);
if ( success && openFolder )
{
File appletJSFolder = new File(sketch.getFolder(), JavaScriptBuild.EXPORTED_FOLDER_NAME );
File appletJSFolder = new File( sketch.getFolder(),
JavaScriptBuild.EXPORTED_FOLDER_NAME );
Base.openFolder(appletJSFolder);
statusNotice("Finished exporting.");
@@ -359,6 +355,8 @@ public class JavaScriptEditor extends Editor
}
} catch (Exception e) {
statusError(e);
toolbar.deactivate(JavaScriptToolbar.EXPORT);
return false;
}
toolbar.deactivate(JavaScriptToolbar.EXPORT);
}
@@ -451,6 +449,11 @@ public class JavaScriptEditor extends Editor
public void internalCloseRunner()
{
handleStopServer();
if ( directivesEditor != null )
{
directivesEditor.hide();
directivesEditor = null;
}
}
public void deactivateRun ()

View File

@@ -12,6 +12,7 @@ import processing.app.Base;
import processing.app.Editor;
import processing.app.Mode;
import processing.app.Sketch;
import processing.app.SketchException;
import processing.app.syntax.PdeKeywords;
import processing.core.PApplet;
@@ -137,7 +138,7 @@ public class JavaScriptMode extends Mode
// ------------------------------------------------
public boolean handleExport(Sketch sketch) throws IOException
public boolean handleExport(Sketch sketch) throws IOException, SketchException
{
JavaScriptBuild build = new JavaScriptBuild(sketch);
return build.export();