use of processing.data.StringList in project processing by processing.
the class Toolkit method getMonoFontFamilies.
public static String[] getMonoFontFamilies() {
StringList families = new StringList();
for (Font font : getMonoFontList()) {
families.appendUnique(font.getFamily());
}
families.sort();
return families.array();
}
use of processing.data.StringList in project processing by processing.
the class Base method handleOpenPrompt.
/**
* Prompt for a sketch to open, and open it in a new window.
*/
public void handleOpenPrompt() {
final StringList extensions = new StringList();
for (Mode mode : getModeList()) {
extensions.append(mode.getDefaultExtension());
}
final String prompt = Language.text("open");
// don't use native dialogs on Linux (or anyone else w/ override)
if (Preferences.getBoolean("chooser.files.native")) {
//$NON-NLS-1$
// use the front-most window frame for placing file dialog
FileDialog openDialog = new FileDialog(activeEditor, prompt, FileDialog.LOAD);
// Only show .pde files as eligible bachelors
openDialog.setFilenameFilter(new FilenameFilter() {
public boolean accept(File dir, String name) {
// confirmed to be working properly [fry 110128]
for (String ext : extensions) {
if (name.toLowerCase().endsWith("." + ext)) {
//$NON-NLS-1$
return true;
}
}
return false;
}
});
openDialog.setVisible(true);
String directory = openDialog.getDirectory();
String filename = openDialog.getFile();
if (filename != null) {
File inputFile = new File(directory, filename);
handleOpen(inputFile.getAbsolutePath());
}
} else {
if (openChooser == null) {
openChooser = new JFileChooser();
}
openChooser.setDialogTitle(prompt);
openChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
public boolean accept(File file) {
// http://code.google.com/p/processing/issues/detail?id=1151
if (file.isDirectory()) {
return true;
}
for (String ext : extensions) {
if (file.getName().toLowerCase().endsWith("." + ext)) {
//$NON-NLS-1$
return true;
}
}
return false;
}
public String getDescription() {
return "Processing Sketch";
}
});
if (openChooser.showOpenDialog(activeEditor) == JFileChooser.APPROVE_OPTION) {
handleOpen(openChooser.getSelectedFile().getAbsolutePath());
}
}
}
use of processing.data.StringList in project processing by processing.
the class Runner method launchVirtualMachine.
public boolean launchVirtualMachine(boolean present, String[] args) {
StringList vmParams = getMachineParams();
StringList sketchParams = getSketchParams(present, args);
// PApplet.printArray(sketchParams);
int port = 8000 + (int) (Math.random() * 1000);
String portStr = String.valueOf(port);
// Added 'quiet=y' for 3.0.2 to prevent command line parsing problems
// https://github.com/processing/processing/issues/4098
String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y,quiet=y";
// Everyone works the same under Java 7 (also on OS X)
StringList commandArgs = new StringList();
commandArgs.append(Platform.getJavaPath());
commandArgs.append(jdwpArg);
commandArgs.append(vmParams);
commandArgs.append(sketchParams);
// the next chance to cancel will be after connecting to the VM
if (cancelled) {
return false;
}
launchJava(commandArgs.array());
AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
//PApplet.println(connector); // gets the defaults
Map<String, Argument> arguments = connector.defaultArguments();
// Connector.Argument addressArg =
// (Connector.Argument)arguments.get("address");
// addressArg.setValue(addr);
Connector.Argument portArg = arguments.get("port");
portArg.setValue(portStr);
try {
// while (!available) {
while (true) {
try {
Messages.log(getClass().getName() + " attempting to attach to VM");
synchronized (cancelLock) {
vm = connector.attach(arguments);
if (cancelled && vm != null) {
// cancelled and connected to the VM, handle closing now
Messages.log(getClass().getName() + " aborting, launch cancelled");
close();
return false;
}
}
// vm = connector.attach(arguments);
if (vm != null) {
Messages.log(getClass().getName() + " attached to the VM");
// available = true;
return true;
}
} catch (ConnectException ce) {
// This will fire ConnectException (socket not available) until
// the VM finishes starting up and opens its socket for us.
Messages.log(getClass().getName() + " socket for VM not ready");
// e.printStackTrace();
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
Messages.loge(getClass().getName() + " interrupted", ie);
// ie.printStackTrace(sketchErr);
}
} catch (IOException e) {
Messages.loge(getClass().getName() + " while attaching to VM", e);
}
}
// } catch (IOException exc) {
// throw new Error("Unable to launch target VM: " + exc);
} catch (IllegalConnectorArgumentsException exc) {
throw new Error("Internal error: " + exc);
}
}
use of processing.data.StringList in project processing by processing.
the class PdePreprocessor method parseSketchSize.
/**
* Parse a chunk of code and extract the size() command and its contents.
* Also goes after fullScreen(), smooth(), and noSmooth().
* @param code The code from the main tab in the sketch
* @param fussy true if it should show an error message if bad size()
* @return null if there was an error, otherwise an array (might contain some/all nulls)
*/
public static SurfaceInfo parseSketchSize(String code, boolean fussy) throws SketchException {
// This matches against any uses of the size() function, whether numbers
// or variables or whatever. This way, no warning is shown if size() isn't
// actually used in the applet, which is the case especially for anyone
// who is cutting/pasting from the reference.
// String scrubbed = scrubComments(sketch.getCode(0).getProgram());
// String[] matches = PApplet.match(scrubbed, SIZE_REGEX);
// String[] matches = PApplet.match(scrubComments(code), SIZE_REGEX);
/*
1. no size() or fullScreen() method at all
will use the non-overridden settings() method in PApplet
2. size() or fullScreen() found inside setup() (static mode sketch or otherwise)
make sure that it uses numbers (or displayWidth/Height), copy into settings
3. size() or fullScreen() already in settings()
don't mess with the sketch, don't insert any defaults
really only need to deal with situation #2.. nothing to be done for 1 and 3
*/
// if static mode sketch, all we need is regex
// easy proxy for static in this case is whether [^\s]void\s is present
String uncommented = scrubComments(code);
Mode mode = parseMode(uncommented);
String searchArea = null;
switch(mode) {
case JAVA:
// it's up to the user
searchArea = null;
break;
case ACTIVE:
// active mode, limit scope to setup
// Find setup() in global scope
MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented);
if (setupMatch != null) {
int start = uncommented.indexOf("{", setupMatch.end());
if (start >= 0) {
// Find a closing brace
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
if (match != null) {
searchArea = uncommented.substring(start + 1, match.end() - 1);
} else {
throw new SketchException("Found a { that's missing a matching }", false);
}
}
}
break;
case STATIC:
// static mode, look everywhere
searchArea = uncommented;
break;
}
if (searchArea == null) {
return new SurfaceInfo();
}
StringList extraStatements = new StringList();
// First look for noSmooth() or smooth(N) so we can hoist it into settings.
String[] smoothContents = matchMethod("smooth", searchArea);
if (smoothContents != null) {
extraStatements.append(smoothContents[0]);
}
String[] noContents = matchMethod("noSmooth", searchArea);
if (noContents != null) {
if (extraStatements.size() != 0) {
throw new SketchException("smooth() and noSmooth() cannot be used in the same sketch");
} else {
extraStatements.append(noContents[0]);
}
}
String[] pixelDensityContents = matchMethod("pixelDensity", searchArea);
if (pixelDensityContents != null) {
extraStatements.append(pixelDensityContents[0]);
} else {
pixelDensityContents = matchDensityMess(searchArea);
if (pixelDensityContents != null) {
extraStatements.append(pixelDensityContents[0]);
}
}
String[] sizeContents = matchMethod("size", searchArea);
String[] fullContents = matchMethod("fullScreen", searchArea);
// throw a confusing state exception error that one "can't be used here".
if (sizeContents != null && fullContents != null) {
throw new SketchException("size() and fullScreen() cannot be used in the same sketch", false);
}
//String[] contents = PApplet.match(searchArea, SIZE_CONTENTS_REGEX);
if (sizeContents != null) {
StringList args = breakCommas(sizeContents[1]);
SurfaceInfo info = new SurfaceInfo();
// info.statement = sizeContents[0];
info.addStatement(sizeContents[0]);
info.width = args.get(0).trim();
info.height = args.get(1).trim();
info.renderer = (args.size() >= 3) ? args.get(2).trim() : null;
info.path = (args.size() >= 4) ? args.get(3).trim() : null;
if (info.hasOldSyntax()) {
// return null;
throw new SketchException("Please update your code to continue.", false);
}
if (info.hasBadSize() && fussy) {
// found a reference to size, but it didn't seem to contain numbers
final String message = "The size of this sketch could not be determined from your code.\n" + "Use only numbers (not variables) for the size() command.\n" + "Read the size() reference for more details.";
Messages.showWarning("Could not find sketch size", message, null);
// return null;
throw new SketchException("Please fix the size() line to continue.", false);
}
info.addStatements(extraStatements);
info.checkEmpty();
return info;
//return new String[] { contents[0], width, height, renderer, path };
}
//contents = PApplet.match(searchArea, FULL_SCREEN_CONTENTS_REGEX);
if (fullContents != null) {
SurfaceInfo info = new SurfaceInfo();
// info.statement = fullContents[0];
info.addStatement(fullContents[0]);
StringList args = breakCommas(fullContents[1]);
if (args.size() > 0) {
// might have no args
String args0 = args.get(0).trim();
if (args.size() == 1) {
// could be either fullScreen(1) or fullScreen(P2D), figure out which
if (args0.equals("SPAN") || PApplet.parseInt(args0, -1) != -1) {
// it's the display parameter, not the renderer
info.display = args0;
} else {
info.renderer = args0;
}
} else if (args.size() == 2) {
info.renderer = args0;
info.display = args.get(1).trim();
} else {
throw new SketchException("That's too many parameters for fullScreen()");
}
}
info.width = "displayWidth";
info.height = "displayHeight";
// if (extraStatements.size() != 0) {
// info.statement += extraStatements.join(" ");
// }
info.addStatements(extraStatements);
info.checkEmpty();
return info;
}
// need to pull out the noSmooth() and smooth(N) methods.
if (extraStatements.size() != 0) {
SurfaceInfo info = new SurfaceInfo();
// info.statement = extraStatements.join(" ");
info.addStatements(extraStatements);
return info;
}
//return new String[] { null, null, null, null, null };
return new SurfaceInfo();
}
use of processing.data.StringList in project processing by processing.
the class PdePreprocessor method breakCommas.
/**
* Break on commas, except those inside quotes,
* e.g.: size(300, 200, PDF, "output,weirdname.pdf");
* No special handling implemented for escaped (\") quotes.
*/
private static StringList breakCommas(String contents) {
StringList outgoing = new StringList();
boolean insideQuote = false;
// The current word being read
StringBuilder current = new StringBuilder();
char[] chars = contents.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (insideQuote) {
current.append(c);
if (c == '\"') {
insideQuote = false;
}
} else {
if (c == ',') {
if (current.length() != 0) {
outgoing.append(current.toString());
current.setLength(0);
}
} else {
current.append(c);
if (c == '\"') {
insideQuote = true;
}
}
}
}
if (current.length() != 0) {
outgoing.append(current.toString());
}
return outgoing;
}
Aggregations