mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Merge branch 'master' into esp8266
* master: (148 commits)
Update revision log
Cherry picked fix from 87865ac19d
Updated revision log
Added dependencies for AStylej.dll
Updated translations
Update revision log
Temporary fix for pulseIn() regression.
Added README.adoc for the library manager project
Fixed some libraries metadata.
Temporary disabled DefaultTargetTest under certain conditions
Updated translation from transifex
Updated some translation strings
Fixed test
sam: Fixed initialization of UART/USART mode register
update revision log
Fixed NPE when import menu are empty
Fixed NPE when currently selected platform is no more installed.
Optimized FileUtils.recursiveDelete(File) function
Fixed a bunch of simple warnings in java code
Removed unused classes Commander.java and Webserver.java
...
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
<classpathentry excluding="processing/app/tools/format/|processing/app/tools/format/src/|processing/app/Trace.java|processing/app/RunnerClassLoader.java" kind="src" path="app/src"/>
|
||||
<classpathentry kind="src" path="app/test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
|
||||
<classpathentry kind="lib" path="app/lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/ecj.jar"/>
|
||||
@ -21,5 +20,6 @@
|
||||
<classpathentry kind="lib" path="app/lib/jmdns-3.4.1.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/jsch-0.1.50.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/jssc-2.8.0.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
|
||||
<classpathentry kind="output" path="app/bin"/>
|
||||
</classpath>
|
||||
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,8 +1,8 @@
|
||||
app/bin/
|
||||
app/pde.jar
|
||||
build/macosx/work/
|
||||
core/bin/
|
||||
core/core.jar
|
||||
arduino-core/bin/
|
||||
arduino-core/arduino-core.jar
|
||||
hardware/arduino/bootloaders/caterina_LUFA/Descriptors.o
|
||||
hardware/arduino/bootloaders/caterina_LUFA/Descriptors.lst
|
||||
hardware/arduino/bootloaders/caterina_LUFA/Caterina.sym
|
||||
@ -15,15 +15,18 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
|
||||
hardware/arduino/bootloaders/caterina_LUFA/.dep/
|
||||
build/libastylej-*.zip
|
||||
build/windows/work/
|
||||
build/windows/jre.zip
|
||||
build/windows/*.zip
|
||||
build/windows/*.tgz
|
||||
build/windows/libastylej*
|
||||
build/windows/arduino-*.zip
|
||||
build/windows/dist/gcc-*.tar.gz
|
||||
build/windows/dist/*.tar.gz
|
||||
build/windows/dist/*.tar.bz2
|
||||
build/windows/launch4j-*
|
||||
build/windows/launcher/launch4j
|
||||
build/windows/WinAVR-*.zip
|
||||
build/macosx/arduino-*.zip
|
||||
build/macosx/dist/gcc-*.tar.gz
|
||||
build/macosx/dist/*.tar.gz
|
||||
build/macosx/dist/*.tar.bz2
|
||||
build/macosx/libastylej*
|
||||
build/macosx/appbundler*.jar
|
||||
build/linux/work/
|
||||
@ -36,6 +39,7 @@ test-bin
|
||||
*.iml
|
||||
.idea
|
||||
.DS_Store
|
||||
.directory
|
||||
build/windows/launch4j-*
|
||||
build/windows/launcher/launch4j
|
||||
build/windows/WinAVR-*.zip
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="processing/app/tools/format/" kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ecj.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
|
||||
<classpathentry kind="lib" path="lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/>
|
||||
@ -14,5 +14,12 @@
|
||||
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
|
||||
<classpathentry kind="lib" path="test-lib/junit-4.11.jar"/>
|
||||
<classpathentry kind="lib" path="test-lib/fest-assert-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="test-lib/fest-reflect-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="test-lib/fest-swing-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="test-lib/fest-util-1.1.2.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
|
||||
<classpathentry kind="lib" path="test-lib/jcip-annotations-1.0.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
<pathelement path="${env.JAVA_HOME}/lib/tools.jar"/>
|
||||
<pathelement path="../core/core.jar"/>
|
||||
<pathelement path="../arduino-core/arduino-core.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="class.path.test">
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
<target name="compile" description="Compile sources">
|
||||
<condition property="core-built">
|
||||
<available file="../core/core.jar" />
|
||||
<available file="../arduino-core/arduino-core.jar" />
|
||||
</condition>
|
||||
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../core/core.jar" />
|
||||
<fail unless="core-built" message="Please build the Arduino-core library first and make sure it sits in ../arduino-core/arduino-core.jar" />
|
||||
|
||||
<mkdir dir="bin" />
|
||||
|
||||
@ -80,9 +80,6 @@
|
||||
includeAntRuntime="false"
|
||||
debug="true"
|
||||
classpathref="class.path" />
|
||||
<copy todir="bin" overwrite="true" verbose="true">
|
||||
<fileset dir="src" includes="**/*.properties" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile" description="Runs the test">
|
||||
|
17
app/src/cc/arduino/packages/MonitorFactory.java
Normal file
17
app/src/cc/arduino/packages/MonitorFactory.java
Normal file
@ -0,0 +1,17 @@
|
||||
package cc.arduino.packages;
|
||||
|
||||
import processing.app.AbstractMonitor;
|
||||
import processing.app.NetworkMonitor;
|
||||
import processing.app.SerialMonitor;
|
||||
|
||||
public class MonitorFactory {
|
||||
|
||||
public AbstractMonitor newMonitor(BoardPort port) {
|
||||
if ("network".equals(port.getProtocol())) {
|
||||
return new NetworkMonitor(port);
|
||||
}
|
||||
|
||||
return new SerialMonitor(port);
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +1,43 @@
|
||||
package processing.app;
|
||||
|
||||
import processing.app.debug.MessageConsumer;
|
||||
import processing.core.PApplet;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
|
||||
public abstract class AbstractMonitor extends JFrame implements MessageConsumer {
|
||||
import processing.app.debug.TextAreaFIFO;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
|
||||
protected final JLabel noLineEndingAlert;
|
||||
protected JTextArea textArea;
|
||||
protected TextAreaFIFO textArea;
|
||||
protected JScrollPane scrollPane;
|
||||
protected JTextField textField;
|
||||
protected JButton sendButton;
|
||||
@ -25,6 +45,9 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
|
||||
protected JComboBox lineEndings;
|
||||
protected JComboBox serialRates;
|
||||
|
||||
private Timer updateTimer;
|
||||
private StringBuffer updateBuffer;
|
||||
|
||||
public AbstractMonitor(String title) {
|
||||
super(title);
|
||||
|
||||
@ -58,7 +81,9 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
|
||||
Font editorFont = Preferences.getFont("editor.font");
|
||||
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
|
||||
|
||||
textArea = new JTextArea(16, 40);
|
||||
textArea = new TextAreaFIFO(8000000);
|
||||
textArea.setRows(16);
|
||||
textArea.setColumns(40);
|
||||
textArea.setEditable(false);
|
||||
textArea.setFont(font);
|
||||
|
||||
@ -110,7 +135,7 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
|
||||
|
||||
String[] serialRateStrings = {
|
||||
"300", "1200", "2400", "4800", "9600",
|
||||
"19200", "57600", "115200"
|
||||
"19200", "38400", "57600", "115200"
|
||||
};
|
||||
|
||||
serialRates = new JComboBox();
|
||||
@ -148,6 +173,10 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateBuffer = new StringBuffer(1048576);
|
||||
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
|
||||
updateTimer.start();
|
||||
}
|
||||
|
||||
public void onSerialRateChange(ActionListener listener) {
|
||||
@ -198,4 +227,28 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
|
||||
public abstract void open() throws Exception;
|
||||
|
||||
public abstract void close() throws Exception;
|
||||
|
||||
public synchronized void addToUpdateBuffer(char buff[], int n) {
|
||||
updateBuffer.append(buff, 0, n);
|
||||
}
|
||||
|
||||
private synchronized String consumeUpdateBuffer() {
|
||||
String s = updateBuffer.toString();
|
||||
updateBuffer.setLength(0);
|
||||
return s;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String s = consumeUpdateBuffer();
|
||||
if (s.length() > 0) {
|
||||
//System.out.println("gui append " + s.length());
|
||||
if (autoscrollBox.isSelected()) {
|
||||
textArea.appendTrim(s);
|
||||
textArea.setCaretPosition(textArea.getDocument().getLength());
|
||||
} else {
|
||||
textArea.appendNoTrim(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,297 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2008 Ben Fry and Casey Reas
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import processing.core.PApplet;
|
||||
|
||||
import processing.app.debug.*;
|
||||
|
||||
|
||||
/**
|
||||
* Class to handle running Processing from the command line.
|
||||
* <PRE>
|
||||
* --help Show the help text.
|
||||
*
|
||||
* --sketch=<name&rt; Specify the sketch folder (required)
|
||||
* --output=<name&rt; Specify the output folder (required and
|
||||
* cannot be the same as the sketch folder.)
|
||||
*
|
||||
* --preprocess Preprocess a sketch into .java files.
|
||||
* --build Preprocess and compile a sketch into .class files.
|
||||
* --run Preprocess, compile, and run a sketch.
|
||||
* --present Preprocess, compile, and run a sketch full screen.
|
||||
*
|
||||
* --export-applet Export an applet.
|
||||
* --export-application Export an application.
|
||||
* --platform Specify the platform (export to application only).
|
||||
* Should be one of 'windows', 'macosx', or 'linux'.
|
||||
*
|
||||
* --preferences=<file&rt; Specify a preferences file to use (optional).
|
||||
* </PRE>
|
||||
*
|
||||
* To build the command line version, first build for your platform,
|
||||
* then cd to processing/build/cmd and type 'dist.sh'. This will create a
|
||||
* usable installation plus a zip file of the same.
|
||||
*
|
||||
* @author fry
|
||||
*/
|
||||
public class Commander implements RunnerListener {
|
||||
static final String helpArg = "--help";
|
||||
static final String preprocArg = "--preprocess";
|
||||
static final String buildArg = "--build";
|
||||
static final String runArg = "--run";
|
||||
static final String presentArg = "--present";
|
||||
static final String sketchArg = "--sketch=";
|
||||
static final String outputArg = "--output=";
|
||||
static final String exportAppletArg = "--export-applet";
|
||||
static final String exportApplicationArg = "--export-application";
|
||||
static final String platformArg = "--platform=";
|
||||
static final String preferencesArg = "--preferences=";
|
||||
|
||||
static final int HELP = -1;
|
||||
static final int PREPROCESS = 0;
|
||||
static final int BUILD = 1;
|
||||
static final int RUN = 2;
|
||||
static final int PRESENT = 3;
|
||||
static final int EXPORT_APPLET = 4;
|
||||
static final int EXPORT_APPLICATION = 5;
|
||||
|
||||
Sketch sketch;
|
||||
|
||||
|
||||
static public void main(String[] args) {
|
||||
// init the platform so that prefs and other native code is ready to go
|
||||
Base.initPlatform();
|
||||
// make sure a full JDK is installed
|
||||
Base.initRequirements();
|
||||
// run static initialization that grabs all the prefs
|
||||
//Preferences.init(null);
|
||||
// launch command line handler
|
||||
new Commander(args);
|
||||
}
|
||||
|
||||
|
||||
public Commander(String[] args) {
|
||||
String sketchFolder = null;
|
||||
String pdePath = null; // path to the .pde file
|
||||
String outputPath = null;
|
||||
String preferencesPath = null;
|
||||
int platformIndex = PApplet.platform; // default to this platform
|
||||
int mode = HELP;
|
||||
|
||||
for (String arg : args) {
|
||||
if (arg.length() == 0) {
|
||||
// ignore it, just the crappy shell script
|
||||
|
||||
} else if (arg.equals(helpArg)) {
|
||||
// mode already set to HELP
|
||||
|
||||
} else if (arg.equals(buildArg)) {
|
||||
mode = BUILD;
|
||||
|
||||
} else if (arg.equals(runArg)) {
|
||||
mode = RUN;
|
||||
|
||||
} else if (arg.equals(presentArg)) {
|
||||
mode = PRESENT;
|
||||
|
||||
} else if (arg.equals(preprocArg)) {
|
||||
mode = PREPROCESS;
|
||||
|
||||
} else if (arg.equals(exportAppletArg)) {
|
||||
mode = EXPORT_APPLET;
|
||||
|
||||
} else if (arg.equals(exportApplicationArg)) {
|
||||
mode = EXPORT_APPLICATION;
|
||||
|
||||
} else if (arg.startsWith(platformArg)) {
|
||||
String platformStr = arg.substring(platformArg.length());
|
||||
platformIndex = Base.getPlatformIndex(platformStr);
|
||||
if (platformIndex == -1) {
|
||||
complainAndQuit(platformStr + " should instead be " +
|
||||
"'windows', 'macosx', or 'linux'.");
|
||||
}
|
||||
} else if (arg.startsWith(sketchArg)) {
|
||||
sketchFolder = arg.substring(sketchArg.length());
|
||||
File sketchy = new File(sketchFolder);
|
||||
File pdeFile = new File(sketchy, sketchy.getName() + ".pde");
|
||||
pdePath = pdeFile.getAbsolutePath();
|
||||
|
||||
} else if (arg.startsWith(outputArg)) {
|
||||
outputPath = arg.substring(outputArg.length());
|
||||
|
||||
} else {
|
||||
complainAndQuit("I don't know anything about " + arg + ".");
|
||||
}
|
||||
}
|
||||
|
||||
if ((outputPath == null) &&
|
||||
(mode == PREPROCESS || mode == BUILD ||
|
||||
mode == RUN || mode == PRESENT)) {
|
||||
complainAndQuit("An output path must be specified when using " +
|
||||
preprocArg + ", " + buildArg + ", " +
|
||||
runArg + ", or " + presentArg + ".");
|
||||
}
|
||||
|
||||
if (mode == HELP) {
|
||||
printCommandLine(System.out);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// --present --platform=windows "--sketch=/Applications/Processing 0148/examples/Basics/Arrays/Array" --output=test-build
|
||||
|
||||
File outputFolder = new File(outputPath);
|
||||
if (!outputFolder.exists()) {
|
||||
if (!outputFolder.mkdirs()) {
|
||||
complainAndQuit("Could not create the output folder.");
|
||||
}
|
||||
}
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
// (also pass in a prefs path if that was specified)
|
||||
Preferences.init(preferencesPath);
|
||||
|
||||
if (sketchFolder == null) {
|
||||
complainAndQuit("No sketch path specified.");
|
||||
|
||||
} else if (outputPath.equals(pdePath)) {
|
||||
complainAndQuit("The sketch path and output path cannot be identical.");
|
||||
|
||||
} else if (!pdePath.toLowerCase().endsWith(".pde")) {
|
||||
complainAndQuit("Sketch path must point to the main .pde file.");
|
||||
|
||||
} else {
|
||||
//Sketch sketch = null;
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
sketch = new Sketch(null, pdePath);
|
||||
if (mode == PREPROCESS) {
|
||||
success = sketch.preprocess(outputPath) != null;
|
||||
|
||||
} else if (mode == BUILD) {
|
||||
success = sketch.build(outputPath) != null;
|
||||
|
||||
} else if (mode == RUN || mode == PRESENT) {
|
||||
String className = sketch.build(outputPath);
|
||||
if (className != null) {
|
||||
success = true;
|
||||
Runner runner =
|
||||
new Runner(sketch, className, mode == PRESENT, this);
|
||||
runner.launch();
|
||||
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
|
||||
} else if (mode == EXPORT_APPLET) {
|
||||
if (outputPath != null) {
|
||||
success = sketch.exportApplet(outputPath);
|
||||
} else {
|
||||
String target = sketchFolder + File.separatorChar + "applet";
|
||||
success = sketch.exportApplet(target);
|
||||
}
|
||||
} else if (mode == EXPORT_APPLICATION) {
|
||||
if (outputPath != null) {
|
||||
success = sketch.exportApplication(outputPath, platformIndex);
|
||||
} else {
|
||||
//String sketchFolder =
|
||||
// pdePath.substring(0, pdePath.lastIndexOf(File.separatorChar));
|
||||
outputPath =
|
||||
sketchFolder + File.separatorChar +
|
||||
"application." + Base.getPlatformName(platformIndex);
|
||||
success = sketch.exportApplication(outputPath, platformIndex);
|
||||
}
|
||||
}
|
||||
System.exit(success ? 0 : 1);
|
||||
|
||||
} catch (RunnerException re) {
|
||||
statusError(re);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void statusError(String message) {
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
|
||||
public void statusError(Exception exception) {
|
||||
if (exception instanceof RunnerException) {
|
||||
RunnerException re = (RunnerException) exception;
|
||||
|
||||
// format the runner exception like emacs
|
||||
//blah.java:2:10:2:13: Syntax Error: This is a big error message
|
||||
String filename = sketch.getCode(re.getCodeIndex()).getFileName();
|
||||
int line = re.getCodeLine();
|
||||
int column = re.getCodeColumn();
|
||||
if (column == -1) column = 0;
|
||||
// TODO if column not specified, should just select the whole line.
|
||||
System.err.println(filename + ":" +
|
||||
line + ":" + column + ":" +
|
||||
line + ":" + column + ":" + " " + re.getMessage());
|
||||
} else {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void complainAndQuit(String lastWords) {
|
||||
printCommandLine(System.err);
|
||||
System.err.println(lastWords);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
static void printCommandLine(PrintStream out) {
|
||||
out.println("Processing " + Base.VERSION_NAME + " rocks the console.");
|
||||
out.println();
|
||||
out.println("--help Show this help text.");
|
||||
out.println();
|
||||
out.println("--sketch=<name> Specify the sketch folder (required)");
|
||||
out.println("--output=<name> Specify the output folder (required and");
|
||||
out.println(" cannot be the same as the sketch folder.)");
|
||||
out.println();
|
||||
out.println("--preprocess Preprocess a sketch into .java files.");
|
||||
out.println("--build Preprocess and compile a sketch into .class files.");
|
||||
out.println("--run Preprocess, compile, and run a sketch.");
|
||||
out.println("--present Preprocess, compile, and run a sketch full screen.");
|
||||
out.println();
|
||||
out.println("--export-applet Export an applet.");
|
||||
out.println("--export-application Export an application.");
|
||||
out.println("--platform Specify the platform (export to application only).");
|
||||
out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
|
||||
out.println();
|
||||
out.println("--preferences=<file> Specify a preferences file to use (optional).");
|
||||
}
|
||||
}
|
@ -22,14 +22,17 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.packages.UploaderAndMonitorFactory;
|
||||
import cc.arduino.packages.MonitorFactory;
|
||||
|
||||
import com.jcraft.jsch.JSchException;
|
||||
|
||||
import processing.app.debug.*;
|
||||
import processing.app.forms.PasswordAuthorizationDialog;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMapException;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.syntax.*;
|
||||
import processing.app.tools.*;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
@ -339,10 +342,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
new DataFlavor("text/uri-list;class=java.lang.String");
|
||||
|
||||
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
java.util.List list = (java.util.List)
|
||||
List<File> list = (List<File>)
|
||||
transferable.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
File file = (File) list.get(i);
|
||||
for (File file : list) {
|
||||
if (sketch.addFile(file)) {
|
||||
successful++;
|
||||
}
|
||||
@ -590,7 +592,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
fileMenu.add(item);
|
||||
|
||||
// macosx already has its own preferences and quit menu
|
||||
if (!Base.isMacOS()) {
|
||||
if (!OSUtils.isMacOS()) {
|
||||
fileMenu.addSeparator();
|
||||
|
||||
item = newJMenuItem(_("Preferences"), ',');
|
||||
@ -853,8 +855,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
// Class file to search for
|
||||
String classFileName = "/" + base + ".class";
|
||||
|
||||
ZipFile zipFile = null;
|
||||
try {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
zipFile = new ZipFile(file);
|
||||
Enumeration<?> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
@ -874,6 +877,12 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
} catch (IOException e) {
|
||||
//System.err.println("Ignoring " + filename + " (" + e.getMessage() + ")");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (zipFile != null)
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1102,7 +1111,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
menu.add(item);
|
||||
|
||||
// macosx already has its own about menu
|
||||
if (!Base.isMacOS()) {
|
||||
if (!OSUtils.isMacOS()) {
|
||||
menu.addSeparator();
|
||||
item = new JMenuItem(_("About Arduino"));
|
||||
item.addActionListener(new ActionListener() {
|
||||
@ -1127,7 +1136,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
undoItem.addActionListener(undoAction = new UndoAction());
|
||||
menu.add(undoItem);
|
||||
|
||||
if (!Base.isMacOS()) {
|
||||
if (!OSUtils.isMacOS()) {
|
||||
redoItem = newJMenuItem(_("Redo"), 'Y');
|
||||
} else {
|
||||
redoItem = newJMenuItemShift(_("Redo"), 'Z');
|
||||
@ -1417,8 +1426,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
|
||||
public void resetHandlers() {
|
||||
runHandler = new DefaultRunHandler();
|
||||
presentHandler = new DefaultPresentHandler();
|
||||
runHandler = new BuildHandler();
|
||||
presentHandler = new BuildHandler(true);
|
||||
stopHandler = new DefaultStopHandler();
|
||||
exportHandler = new DefaultExportHandler();
|
||||
exportAppHandler = new DefaultExportAppHandler();
|
||||
@ -1631,19 +1640,19 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
* Switch between tabs, this swaps out the Document object
|
||||
* that's currently being manipulated.
|
||||
*/
|
||||
protected void setCode(SketchCode code) {
|
||||
SyntaxDocument document = (SyntaxDocument) code.getDocument();
|
||||
protected void setCode(SketchCodeDocument codeDoc) {
|
||||
SyntaxDocument document = (SyntaxDocument) codeDoc.getDocument();
|
||||
|
||||
if (document == null) { // this document not yet inited
|
||||
document = new SyntaxDocument();
|
||||
code.setDocument(document);
|
||||
|
||||
codeDoc.setDocument(document);
|
||||
|
||||
// turn on syntax highlighting
|
||||
document.setTokenMarker(new PdeKeywords());
|
||||
|
||||
// insert the program text into the document object
|
||||
try {
|
||||
document.insertString(0, code.getProgram(), null);
|
||||
document.insertString(0, codeDoc.getCode().getProgram(), null);
|
||||
} catch (BadLocationException bl) {
|
||||
bl.printStackTrace();
|
||||
}
|
||||
@ -1653,27 +1662,27 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
// connect the undo listener to the editor
|
||||
document.addUndoableEditListener(new UndoableEditListener() {
|
||||
public void undoableEditHappened(UndoableEditEvent e) {
|
||||
if (compoundEdit != null) {
|
||||
compoundEdit.addEdit(e.getEdit());
|
||||
public void undoableEditHappened(UndoableEditEvent e) {
|
||||
if (compoundEdit != null) {
|
||||
compoundEdit.addEdit(e.getEdit());
|
||||
|
||||
} else if (undo != null) {
|
||||
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
} else if (undo != null) {
|
||||
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// update the document object that's in use
|
||||
textarea.setDocument(document,
|
||||
code.getSelectionStart(), code.getSelectionStop(),
|
||||
code.getScrollPosition());
|
||||
codeDoc.getSelectionStart(), codeDoc.getSelectionStop(),
|
||||
codeDoc.getScrollPosition());
|
||||
|
||||
textarea.requestFocus(); // get the caret blinking
|
||||
|
||||
this.undo = code.getUndo();
|
||||
this.undo = codeDoc.getUndo();
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
@ -1861,9 +1870,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
} catch (BadLocationException bl) {
|
||||
bl.printStackTrace();
|
||||
} finally {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
protected void handleFindReference() {
|
||||
@ -1909,30 +1917,28 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
new Thread(verbose ? presentHandler : runHandler).start();
|
||||
}
|
||||
|
||||
// DAM: in Arduino, this is compile
|
||||
class DefaultRunHandler implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
sketch.prepare();
|
||||
sketch.build(false);
|
||||
statusNotice(_("Done compiling."));
|
||||
} catch (Exception e) {
|
||||
status.unprogress();
|
||||
statusError(e);
|
||||
}
|
||||
class BuildHandler implements Runnable {
|
||||
|
||||
status.unprogress();
|
||||
toolbar.deactivate(EditorToolbar.RUN);
|
||||
private final boolean verbose;
|
||||
|
||||
public BuildHandler() {
|
||||
this(false);
|
||||
}
|
||||
}
|
||||
|
||||
// DAM: in Arduino, this is compile (with verbose output)
|
||||
class DefaultPresentHandler implements Runnable {
|
||||
public BuildHandler(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sketch.prepare();
|
||||
sketch.build(true);
|
||||
sketch.build(verbose);
|
||||
statusNotice(_("Done compiling."));
|
||||
} catch (PreferencesMapException e) {
|
||||
statusError(I18n.format(
|
||||
_("Error while compiling: missing '{0}' configuration parameter"),
|
||||
e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
status.unprogress();
|
||||
statusError(e);
|
||||
@ -1945,11 +1951,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
class DefaultStopHandler implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
// DAM: we should try to kill the compilation or upload process here.
|
||||
} catch (Exception e) {
|
||||
statusError(e);
|
||||
}
|
||||
// TODO
|
||||
// DAM: we should try to kill the compilation or upload process here.
|
||||
}
|
||||
}
|
||||
|
||||
@ -2024,7 +2027,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
String prompt = I18n.format(_("Save changes to \"{0}\"? "), sketch.getName());
|
||||
|
||||
if (!Base.isMacOS()) {
|
||||
if (!OSUtils.isMacOS()) {
|
||||
int result =
|
||||
JOptionPane.showConfirmDialog(this, prompt, _("Close"),
|
||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
@ -2116,89 +2119,79 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
* Second stage of open, occurs after having checked to see if the
|
||||
* modifications (if any) to the previous sketch need to be saved.
|
||||
*/
|
||||
protected boolean handleOpenInternal(File file) {
|
||||
protected boolean handleOpenInternal(File sketchFile) {
|
||||
// check to make sure that this .pde file is
|
||||
// in a folder of the same name
|
||||
String fileName = file.getName();
|
||||
File parent = file.getParentFile();
|
||||
String parentName = parent.getName();
|
||||
String pdeName = parentName + ".pde";
|
||||
File altPdeFile = new File(parent, pdeName);
|
||||
String inoName = parentName + ".ino";
|
||||
File altInoFile = new File(parent, inoName);
|
||||
String fileName = sketchFile.getName();
|
||||
|
||||
if (pdeName.equals(fileName) || inoName.equals(fileName)) {
|
||||
// no beef with this guy
|
||||
File file = SketchData.checkSketchFile(sketchFile);
|
||||
|
||||
} else if (altPdeFile.exists()) {
|
||||
// user selected a .java from the same sketch, but open the .pde instead
|
||||
file = altPdeFile;
|
||||
} else if (altInoFile.exists()) {
|
||||
file = altInoFile;
|
||||
} else if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
|
||||
Base.showWarning(_("Bad file selected"),
|
||||
_("Arduino can only open its own sketches\n" +
|
||||
"and other files ending in .ino or .pde"), null);
|
||||
return false;
|
||||
if (file == null)
|
||||
{
|
||||
if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
|
||||
|
||||
} else {
|
||||
String properParent =
|
||||
fileName.substring(0, fileName.length() - 4);
|
||||
|
||||
Object[] options = { _("OK"), _("Cancel") };
|
||||
String prompt = I18n.format(
|
||||
_("The file \"{0}\" needs to be inside\n" +
|
||||
"a sketch folder named \"{1}\".\n" +
|
||||
"Create this folder, move the file, and continue?"),
|
||||
fileName,
|
||||
properParent
|
||||
);
|
||||
|
||||
int result = JOptionPane.showOptionDialog(this,
|
||||
prompt,
|
||||
_("Moving"),
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
// create properly named folder
|
||||
File properFolder = new File(file.getParent(), properParent);
|
||||
if (properFolder.exists()) {
|
||||
Base.showWarning(_("Error"),
|
||||
I18n.format(
|
||||
_("A folder named \"{0}\" already exists. " +
|
||||
"Can't open sketch."),
|
||||
properParent
|
||||
),
|
||||
null);
|
||||
return false;
|
||||
}
|
||||
if (!properFolder.mkdirs()) {
|
||||
//throw new IOException("Couldn't create sketch folder");
|
||||
Base.showWarning(_("Error"),
|
||||
_("Could not create the sketch folder."), null);
|
||||
return false;
|
||||
}
|
||||
// copy the sketch inside
|
||||
File properPdeFile = new File(properFolder, file.getName());
|
||||
try {
|
||||
Base.copyFile(file, properPdeFile);
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(_("Error"), _("Could not copy to a proper location."), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the original file, so user doesn't get confused
|
||||
file.delete();
|
||||
|
||||
// update with the new path
|
||||
file = properPdeFile;
|
||||
|
||||
} else if (result == JOptionPane.NO_OPTION) {
|
||||
Base.showWarning(_("Bad file selected"),
|
||||
_("Arduino can only open its own sketches\n" +
|
||||
"and other files ending in .ino or .pde"), null);
|
||||
return false;
|
||||
|
||||
} else {
|
||||
String properParent =
|
||||
fileName.substring(0, fileName.length() - 4);
|
||||
|
||||
Object[] options = { _("OK"), _("Cancel") };
|
||||
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" +
|
||||
"a sketch folder named \"{1}\".\n" +
|
||||
"Create this folder, move the file, and continue?"),
|
||||
fileName,
|
||||
properParent);
|
||||
|
||||
int result = JOptionPane.showOptionDialog(this,
|
||||
prompt,
|
||||
_("Moving"),
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
// create properly named folder
|
||||
File properFolder = new File(sketchFile.getParent(), properParent);
|
||||
if (properFolder.exists()) {
|
||||
Base.showWarning(_("Error"),
|
||||
I18n.format(
|
||||
_("A folder named \"{0}\" already exists. " +
|
||||
"Can't open sketch."),
|
||||
properParent
|
||||
),
|
||||
null);
|
||||
return false;
|
||||
}
|
||||
if (!properFolder.mkdirs()) {
|
||||
//throw new IOException("Couldn't create sketch folder");
|
||||
Base.showWarning(_("Error"),
|
||||
_("Could not create the sketch folder."), null);
|
||||
return false;
|
||||
}
|
||||
// copy the sketch inside
|
||||
File properPdeFile = new File(properFolder, sketchFile.getName());
|
||||
try {
|
||||
Base.copyFile(file, properPdeFile);
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(_("Error"), _("Could not copy to a proper location."), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the original file, so user doesn't get confused
|
||||
sketchFile.delete();
|
||||
|
||||
// update with the new path
|
||||
file = properPdeFile;
|
||||
|
||||
} else if (result == JOptionPane.NO_OPTION) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2210,13 +2203,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
}
|
||||
header.rebuild();
|
||||
// Set the title of the window to "sketch_070752a - Processing 0126"
|
||||
setTitle(
|
||||
I18n.format(
|
||||
_("{0} | Arduino {1}"),
|
||||
sketch.getName(),
|
||||
Base.VERSION_NAME
|
||||
)
|
||||
);
|
||||
setTitle(I18n.format(_("{0} | Arduino {1}"), sketch.getName(),
|
||||
BaseNoGui.VERSION_NAME));
|
||||
// Disable untitled setting from previous document, if any
|
||||
untitled = false;
|
||||
|
||||
@ -2524,7 +2512,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
return;
|
||||
}
|
||||
|
||||
serialMonitor = new UploaderAndMonitorFactory().newMonitor(port, base);
|
||||
serialMonitor = new MonitorFactory().newMonitor(port);
|
||||
serialMonitor.setIconImage(getIconImage());
|
||||
|
||||
boolean success = false;
|
||||
@ -2580,7 +2568,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
statusError(I18n.format(
|
||||
_("Error while burning bootloader: missing '{0}' configuration parameter"),
|
||||
e.getMessage()));
|
||||
//statusError(e);
|
||||
} catch (RunnerException e) {
|
||||
statusError(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
statusError(_("Error while burning bootloader."));
|
||||
e.printStackTrace();
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
@ -22,15 +20,28 @@
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.*;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DefaultStyledDocument;
|
||||
import javax.swing.text.Element;
|
||||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.StyleConstants;
|
||||
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,50 +51,33 @@ import java.util.*;
|
||||
* don't take over System.err, and debug while watching just System.out
|
||||
* or just write println() or whatever directly to systemOut or systemErr.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EditorConsole extends JScrollPane {
|
||||
Editor editor;
|
||||
|
||||
JTextPane consoleTextPane;
|
||||
BufferedStyledDocument consoleDoc;
|
||||
|
||||
MutableAttributeSet stdStyle;
|
||||
MutableAttributeSet errStyle;
|
||||
|
||||
int maxLineCount;
|
||||
|
||||
static File errFile;
|
||||
static File outFile;
|
||||
static File tempFolder;
|
||||
SimpleAttributeSet stdStyle;
|
||||
SimpleAttributeSet errStyle;
|
||||
|
||||
// Single static instance shared because there's only one real System.out.
|
||||
// Within the input handlers, the currentConsole variable will be used to
|
||||
// echo things to the correct location.
|
||||
|
||||
static public PrintStream systemOut;
|
||||
static public PrintStream systemErr;
|
||||
public EditorConsole(Editor _editor) {
|
||||
editor = _editor;
|
||||
|
||||
static PrintStream consoleOut;
|
||||
static PrintStream consoleErr;
|
||||
int maxLineCount = Preferences.getInteger("console.length");
|
||||
|
||||
static OutputStream stdoutFile;
|
||||
static OutputStream stderrFile;
|
||||
|
||||
static EditorConsole currentConsole;
|
||||
|
||||
|
||||
public EditorConsole(Editor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
maxLineCount = Preferences.getInteger("console.length");
|
||||
|
||||
consoleDoc = new BufferedStyledDocument(10000, maxLineCount);
|
||||
consoleDoc = new BufferedStyledDocument(4000, maxLineCount);
|
||||
consoleTextPane = new JTextPane(consoleDoc);
|
||||
consoleTextPane.setEditable(false);
|
||||
|
||||
// necessary?
|
||||
MutableAttributeSet standard = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(standard, StyleConstants.ALIGN_LEFT);
|
||||
consoleDoc.setParagraphAttributes(0, 0, standard, true);
|
||||
SimpleAttributeSet leftAlignAttr = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(leftAlignAttr, StyleConstants.ALIGN_LEFT);
|
||||
consoleDoc.setParagraphAttributes(0, 0, leftAlignAttr, true);
|
||||
|
||||
// build styles for different types of console output
|
||||
Color bgColor = Theme.getColor("console.color");
|
||||
@ -112,74 +106,34 @@ public class EditorConsole extends JScrollPane {
|
||||
consoleTextPane.setBackground(bgColor);
|
||||
|
||||
// add the jtextpane to this scrollpane
|
||||
this.setViewportView(consoleTextPane);
|
||||
setViewportView(consoleTextPane);
|
||||
|
||||
// calculate height of a line of text in pixels
|
||||
// and size window accordingly
|
||||
FontMetrics metrics = this.getFontMetrics(font);
|
||||
FontMetrics metrics = getFontMetrics(font);
|
||||
int height = metrics.getAscent() + metrics.getDescent();
|
||||
int lines = Preferences.getInteger("console.lines"); //, 4);
|
||||
int lines = Preferences.getInteger("console.lines");
|
||||
int sizeFudge = 6; //10; // unclear why this is necessary, but it is
|
||||
setPreferredSize(new Dimension(1024, (height * lines) + sizeFudge));
|
||||
setMinimumSize(new Dimension(1024, (height * 4) + sizeFudge));
|
||||
|
||||
if (systemOut == null) {
|
||||
systemOut = System.out;
|
||||
systemErr = System.err;
|
||||
|
||||
// Create a temporary folder which will have a randomized name. Has to
|
||||
// be randomized otherwise another instance of Processing (or one of its
|
||||
// sister IDEs) might collide with the file causing permissions problems.
|
||||
// The files and folders are not deleted on exit because they may be
|
||||
// needed for debugging or bug reporting.
|
||||
tempFolder = Base.createTempFolder("console");
|
||||
tempFolder.deleteOnExit();
|
||||
try {
|
||||
String outFileName = Preferences.get("console.output.file");
|
||||
if (outFileName != null) {
|
||||
outFile = new File(tempFolder, outFileName);
|
||||
outFile.deleteOnExit();
|
||||
stdoutFile = new FileOutputStream(outFile);
|
||||
}
|
||||
|
||||
String errFileName = Preferences.get("console.error.file");
|
||||
if (errFileName != null) {
|
||||
errFile = new File(tempFolder, errFileName);
|
||||
errFile.deleteOnExit();
|
||||
stderrFile = new FileOutputStream(errFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(_("Console Error"),
|
||||
_("A problem occurred while trying to open the\nfiles used to store the console output."), e);
|
||||
}
|
||||
consoleOut = new PrintStream(new EditorConsoleStream(false));
|
||||
consoleErr = new PrintStream(new EditorConsoleStream(true));
|
||||
|
||||
if (Preferences.getBoolean("console")) {
|
||||
try {
|
||||
System.setOut(consoleOut);
|
||||
System.setErr(consoleErr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(systemOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorConsoleStream.init();
|
||||
|
||||
// to fix ugliness.. normally macosx java 1.3 puts an
|
||||
// ugly white border around this object, so turn it off.
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
setBorder(null);
|
||||
}
|
||||
|
||||
// periodically post buffered messages to the console
|
||||
// should the interval come from the preferences file?
|
||||
new javax.swing.Timer(250, new ActionListener() {
|
||||
new Timer(250, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// only if new text has been added
|
||||
if (consoleDoc.hasAppendage) {
|
||||
if (consoleDoc.isChanged()) {
|
||||
// insert the text that's been added in the meantime
|
||||
consoleDoc.insertAll();
|
||||
// always move to the end of the text as it's added
|
||||
@ -191,75 +145,6 @@ public class EditorConsole extends JScrollPane {
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
static public void setEditor(Editor editor) {
|
||||
currentConsole = editor.console;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the streams so that the temporary files can be deleted.
|
||||
* <p/>
|
||||
* File.deleteOnExit() cannot be used because the stdout and stderr
|
||||
* files are inside a folder, and have to be deleted before the
|
||||
* folder itself is deleted, which can't be guaranteed when using
|
||||
* the deleteOnExit() method.
|
||||
*/
|
||||
public void handleQuit() {
|
||||
// replace original streams to remove references to console's streams
|
||||
System.setOut(systemOut);
|
||||
System.setErr(systemErr);
|
||||
|
||||
// close the PrintStream
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
|
||||
// also have to close the original FileOutputStream
|
||||
// otherwise it won't be shut down completely
|
||||
try {
|
||||
stdoutFile.close();
|
||||
stderrFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(systemOut);
|
||||
}
|
||||
|
||||
outFile.delete();
|
||||
errFile.delete();
|
||||
tempFolder.delete();
|
||||
}
|
||||
|
||||
|
||||
public void write(byte b[], int offset, int length, boolean err) {
|
||||
// we could do some cross platform CR/LF mangling here before outputting
|
||||
// add text to output document
|
||||
message(new String(b, offset, length), err, false);
|
||||
}
|
||||
|
||||
|
||||
// added sync for 0091.. not sure if it helps or hinders
|
||||
synchronized public void message(String what, boolean err, boolean advance) {
|
||||
if (err) {
|
||||
systemErr.print(what);
|
||||
//systemErr.print("CE" + what);
|
||||
} else {
|
||||
systemOut.print(what);
|
||||
//systemOut.print("CO" + what);
|
||||
}
|
||||
|
||||
if (advance) {
|
||||
appendText("\n", err);
|
||||
if (err) {
|
||||
systemErr.println();
|
||||
} else {
|
||||
systemOut.println();
|
||||
}
|
||||
}
|
||||
|
||||
// to console display
|
||||
appendText(what, err);
|
||||
// moved down here since something is punting
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a piece of text to the console.
|
||||
@ -273,7 +158,7 @@ public class EditorConsole extends JScrollPane {
|
||||
* Updates are buffered to the console and displayed at regular
|
||||
* intervals on Swing's event-dispatching thread. (patch by David Mellis)
|
||||
*/
|
||||
synchronized private void appendText(String txt, boolean e) {
|
||||
synchronized void appendText(String txt, boolean e) {
|
||||
consoleDoc.appendString(txt, e ? errStyle : stdStyle);
|
||||
}
|
||||
|
||||
@ -286,93 +171,6 @@ public class EditorConsole extends JScrollPane {
|
||||
// maybe not a good idea in the long run?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
private static class EditorConsoleStream extends OutputStream {
|
||||
//static EditorConsole current;
|
||||
final boolean err; // whether stderr or stdout
|
||||
final byte single[] = new byte[1];
|
||||
|
||||
public EditorConsoleStream(boolean err) {
|
||||
this.err = err;
|
||||
}
|
||||
|
||||
public void close() { }
|
||||
|
||||
public void flush() { }
|
||||
|
||||
public void write(byte b[]) { // appears never to be used
|
||||
if (currentConsole != null) {
|
||||
currentConsole.write(b, 0, b.length, err);
|
||||
} else {
|
||||
try {
|
||||
if (err) {
|
||||
systemErr.write(b);
|
||||
} else {
|
||||
systemOut.write(b);
|
||||
}
|
||||
} catch (IOException e) { } // just ignore, where would we write?
|
||||
}
|
||||
|
||||
OutputStream echo = err ? stderrFile : stdoutFile;
|
||||
if (echo != null) {
|
||||
try {
|
||||
echo.write(b);
|
||||
echo.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
echo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte b[], int offset, int length) {
|
||||
if (currentConsole != null) {
|
||||
currentConsole.write(b, offset, length, err);
|
||||
} else {
|
||||
if (err) {
|
||||
systemErr.write(b, offset, length);
|
||||
} else {
|
||||
systemOut.write(b, offset, length);
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream echo = err ? stderrFile : stdoutFile;
|
||||
if (echo != null) {
|
||||
try {
|
||||
echo.write(b, offset, length);
|
||||
echo.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
echo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int b) {
|
||||
single[0] = (byte)b;
|
||||
if (currentConsole != null) {
|
||||
currentConsole.write(single, 0, 1, err);
|
||||
} else {
|
||||
// redirect for all the extra handling above
|
||||
write(new byte[] { (byte) b }, 0, 1);
|
||||
}
|
||||
|
||||
OutputStream echo = err ? stderrFile : stdoutFile;
|
||||
if (echo != null) {
|
||||
try {
|
||||
echo.write(b);
|
||||
echo.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
echo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -386,78 +184,73 @@ public class EditorConsole extends JScrollPane {
|
||||
* appendString() is called from multiple threads, and insertAll from the
|
||||
* swing event thread, so they need to be synchronized
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class BufferedStyledDocument extends DefaultStyledDocument {
|
||||
ArrayList<ElementSpec> elements = new ArrayList<ElementSpec>();
|
||||
int maxLineLength, maxLineCount;
|
||||
int currentLineLength = 0;
|
||||
boolean needLineBreak = false;
|
||||
boolean hasAppendage = false;
|
||||
private List<ElementSpec> elements = new ArrayList<ElementSpec>();
|
||||
private int maxLineLength, maxLineCount;
|
||||
private int currentLineLength = 0;
|
||||
private boolean changed = false;
|
||||
|
||||
public BufferedStyledDocument(int maxLineLength, int maxLineCount) {
|
||||
this.maxLineLength = maxLineLength;
|
||||
this.maxLineCount = maxLineCount;
|
||||
public BufferedStyledDocument(int _maxLineLength, int _maxLineCount) {
|
||||
maxLineLength = _maxLineLength;
|
||||
maxLineCount = _maxLineCount;
|
||||
}
|
||||
|
||||
/** buffer a string for insertion at the end of the DefaultStyledDocument */
|
||||
public synchronized void appendString(String str, AttributeSet a) {
|
||||
// do this so that it's only updated when needed (otherwise console
|
||||
// updates every 250 ms when an app isn't even running.. see bug 180)
|
||||
hasAppendage = true;
|
||||
|
||||
// process each line of the string
|
||||
while (str.length() > 0) {
|
||||
// newlines within an element have (almost) no effect, so we need to
|
||||
// replace them with proper paragraph breaks (start and end tags)
|
||||
if (needLineBreak || currentLineLength > maxLineLength) {
|
||||
public synchronized void appendString(String text, AttributeSet a) {
|
||||
changed = true;
|
||||
char[] chars = text.toCharArray();
|
||||
int start = 0;
|
||||
int stop = 0;
|
||||
while (stop < chars.length) {
|
||||
char c = chars[stop];
|
||||
stop++;
|
||||
currentLineLength++;
|
||||
if (c == '\n' || c == '\r' || currentLineLength > maxLineLength) {
|
||||
elements.add(new ElementSpec(a, ElementSpec.ContentType, chars, start,
|
||||
stop - start));
|
||||
elements.add(new ElementSpec(a, ElementSpec.EndTagType));
|
||||
elements.add(new ElementSpec(a, ElementSpec.StartTagType));
|
||||
currentLineLength = 0;
|
||||
}
|
||||
|
||||
if (str.indexOf('\n') == -1) {
|
||||
elements.add(new ElementSpec(a, ElementSpec.ContentType,
|
||||
str.toCharArray(), 0, str.length()));
|
||||
currentLineLength += str.length();
|
||||
needLineBreak = false;
|
||||
str = str.substring(str.length()); // eat the string
|
||||
} else {
|
||||
elements.add(new ElementSpec(a, ElementSpec.ContentType,
|
||||
str.toCharArray(), 0, str.indexOf('\n') + 1));
|
||||
needLineBreak = true;
|
||||
str = str.substring(str.indexOf('\n') + 1); // eat the line
|
||||
start = stop;
|
||||
}
|
||||
}
|
||||
elements.add(new ElementSpec(a, ElementSpec.ContentType, chars, start,
|
||||
stop - start));
|
||||
}
|
||||
|
||||
/** insert the buffered strings */
|
||||
public synchronized void insertAll() {
|
||||
ElementSpec[] elementArray = new ElementSpec[elements.size()];
|
||||
elements.toArray(elementArray);
|
||||
|
||||
try {
|
||||
// check how many lines have been used so far
|
||||
// Insert new elements at the bottom
|
||||
ElementSpec[] elementArray = elements.toArray(new ElementSpec[0]);
|
||||
insert(getLength(), elementArray);
|
||||
|
||||
// check how many lines have been used
|
||||
// if too many, shave off a few lines from the beginning
|
||||
Element element = super.getDefaultRootElement();
|
||||
int lineCount = element.getElementCount();
|
||||
Element root = getDefaultRootElement();
|
||||
int lineCount = root.getElementCount();
|
||||
int overage = lineCount - maxLineCount;
|
||||
if (overage > 0) {
|
||||
// if 1200 lines, and 1000 lines is max,
|
||||
// find the position of the end of the 200th line
|
||||
//systemOut.println("overage is " + overage);
|
||||
Element lineElement = element.getElement(overage);
|
||||
if (lineElement == null) return; // do nuthin
|
||||
Element lineElement = root.getElement(overage);
|
||||
if (lineElement == null)
|
||||
return; // do nuthin
|
||||
|
||||
int endOffset = lineElement.getEndOffset();
|
||||
// remove to the end of the 200th line
|
||||
super.remove(0, endOffset);
|
||||
int endOffset = lineElement.getEndOffset();
|
||||
remove(0, endOffset);
|
||||
}
|
||||
super.insert(super.getLength(), elementArray);
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
// ignore the error otherwise this will cause an infinite loop
|
||||
// maybe not a good idea in the long run?
|
||||
}
|
||||
elements.clear();
|
||||
hasAppendage = false;
|
||||
changed = false;
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
150
app/src/processing/app/EditorConsoleStream.java
Normal file
150
app/src/processing/app/EditorConsoleStream.java
Normal file
@ -0,0 +1,150 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
class EditorConsoleStream extends OutputStream {
|
||||
static File tempFolder;
|
||||
static File outFile;
|
||||
static File errFile;
|
||||
|
||||
static EditorConsole currentConsole;
|
||||
|
||||
static OutputStream stderrFile;
|
||||
static OutputStream stdoutFile;
|
||||
static PrintStream consoleErr;
|
||||
static PrintStream consoleOut;
|
||||
static public PrintStream systemErr;
|
||||
static public PrintStream systemOut;
|
||||
|
||||
public static void init() {
|
||||
if (systemOut == null) {
|
||||
systemOut = System.out;
|
||||
systemErr = System.err;
|
||||
|
||||
// Create a temporary folder which will have a randomized name. Has to
|
||||
// be randomized otherwise another instance of Processing (or one of its
|
||||
// sister IDEs) might collide with the file causing permissions problems.
|
||||
// The files and folders are not deleted on exit because they may be
|
||||
// needed for debugging or bug reporting.
|
||||
tempFolder = Base.createTempFolder("console");
|
||||
tempFolder.deleteOnExit();
|
||||
try {
|
||||
String outFileName = Preferences.get("console.output.file");
|
||||
if (outFileName != null) {
|
||||
outFile = new File(tempFolder, outFileName);
|
||||
outFile.deleteOnExit();
|
||||
stdoutFile = new FileOutputStream(outFile);
|
||||
}
|
||||
|
||||
String errFileName = Preferences.get("console.error.file");
|
||||
if (errFileName != null) {
|
||||
errFile = new File(tempFolder, errFileName);
|
||||
errFile.deleteOnExit();
|
||||
stderrFile = new FileOutputStream(errFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(_("Console Error"),
|
||||
_("A problem occurred while trying to open the\nfiles used to store the console output."),
|
||||
e);
|
||||
}
|
||||
consoleOut = new PrintStream(new EditorConsoleStream(false));
|
||||
consoleErr = new PrintStream(new EditorConsoleStream(true));
|
||||
|
||||
if (Preferences.getBoolean("console")) {
|
||||
try {
|
||||
System.setOut(consoleOut);
|
||||
System.setErr(consoleErr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(systemOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the streams so that the temporary files can be deleted.
|
||||
* <p/>
|
||||
* File.deleteOnExit() cannot be used because the stdout and stderr files are
|
||||
* inside a folder, and have to be deleted before the folder itself is
|
||||
* deleted, which can't be guaranteed when using the deleteOnExit() method.
|
||||
*/
|
||||
public static void quit() {
|
||||
// replace original streams to remove references to console's streams
|
||||
System.setOut(systemOut);
|
||||
System.setErr(systemErr);
|
||||
|
||||
// close the PrintStream
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
|
||||
// also have to close the original FileOutputStream
|
||||
// otherwise it won't be shut down completely
|
||||
try {
|
||||
stdoutFile.close();
|
||||
stderrFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
outFile.delete();
|
||||
errFile.delete();
|
||||
tempFolder.delete();
|
||||
}
|
||||
|
||||
final boolean err; // whether stderr or stdout
|
||||
PrintStream system;
|
||||
OutputStream file;
|
||||
|
||||
public EditorConsoleStream(boolean _err) {
|
||||
err = _err;
|
||||
if (err) {
|
||||
system = systemErr;
|
||||
file = stderrFile;
|
||||
} else {
|
||||
system = systemOut;
|
||||
file = stdoutFile;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
public void write(int b) {
|
||||
write(new byte[] { (byte) b });
|
||||
}
|
||||
|
||||
public void write(byte b[]) { // appears never to be used
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte b[], int offset, int length) {
|
||||
if (currentConsole != null)
|
||||
currentConsole.appendText(new String(b, offset, length), err);
|
||||
|
||||
system.write(b, offset, length);
|
||||
|
||||
if (file != null) {
|
||||
try {
|
||||
file.write(b, offset, length);
|
||||
file.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
file = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void setCurrent(EditorConsole console) {
|
||||
currentConsole = console;
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.tools.MenuScroller;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -34,6 +35,7 @@ import javax.swing.*;
|
||||
/**
|
||||
* Sketch tabs at the top of the editor window.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EditorHeader extends JComponent {
|
||||
static Color backgroundColor;
|
||||
static Color textColor[] = new Color[2];
|
||||
@ -176,7 +178,7 @@ public class EditorHeader extends JComponent {
|
||||
for (int i = 0; i < sketch.getCodeCount(); i++) {
|
||||
SketchCode code = sketch.getCode(i);
|
||||
|
||||
String codeName = sketch.hideExtension(code.getExtension()) ?
|
||||
String codeName = code.isExtension(sketch.getHiddenExtensions()) ?
|
||||
code.getPrettyName() : code.getFileName();
|
||||
|
||||
// if modified, add the li'l glyph next to the name
|
||||
@ -326,30 +328,27 @@ public class EditorHeader extends JComponent {
|
||||
// KeyEvent.VK_LEFT and VK_RIGHT will make Windows beep
|
||||
|
||||
item = new JMenuItem(_("Previous Tab"));
|
||||
KeyStroke ctrlAltLeft =
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Editor.SHORTCUT_ALT_KEY_MASK);
|
||||
KeyStroke ctrlAltLeft = KeyStroke
|
||||
.getKeyStroke(KeyEvent.VK_LEFT, Editor.SHORTCUT_ALT_KEY_MASK);
|
||||
item.setAccelerator(ctrlAltLeft);
|
||||
// this didn't want to work consistently
|
||||
/*
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.sketch.prevCode();
|
||||
}
|
||||
});
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.sketch.handlePrevCode();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
item = new JMenuItem(_("Next Tab"));
|
||||
KeyStroke ctrlAltRight =
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Editor.SHORTCUT_ALT_KEY_MASK);
|
||||
KeyStroke ctrlAltRight = KeyStroke
|
||||
.getKeyStroke(KeyEvent.VK_RIGHT, Editor.SHORTCUT_ALT_KEY_MASK);
|
||||
item.setAccelerator(ctrlAltRight);
|
||||
/*
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.sketch.nextCode();
|
||||
}
|
||||
});
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.sketch.handleNextCode();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
Sketch sketch = editor.getSketch();
|
||||
@ -361,7 +360,7 @@ public class EditorHeader extends JComponent {
|
||||
editor.getSketch().setCurrentCode(e.getActionCommand());
|
||||
}
|
||||
};
|
||||
for (SketchCode code : sketch.getCode()) {
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
|
||||
code.getPrettyName() : code.getFileName());
|
||||
item.setActionCommand(code.getFileName());
|
||||
@ -383,7 +382,7 @@ public class EditorHeader extends JComponent {
|
||||
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
return new Dimension(300, Preferences.GRID_SIZE);
|
||||
}
|
||||
return new Dimension(300, Preferences.GRID_SIZE - 1);
|
||||
@ -391,7 +390,7 @@ public class EditorHeader extends JComponent {
|
||||
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
return new Dimension(3000, Preferences.GRID_SIZE);
|
||||
}
|
||||
return new Dimension(3000, Preferences.GRID_SIZE - 1);
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
@ -22,18 +20,24 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import processing.app.syntax.*;
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
|
||||
/**
|
||||
* Li'l status bar fella that shows the line number.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EditorLineStatus extends JComponent {
|
||||
JEditTextArea textarea;
|
||||
int start = -1, stop;
|
||||
@ -51,7 +55,6 @@ public class EditorLineStatus extends JComponent {
|
||||
String name = "";
|
||||
String serialport = "";
|
||||
|
||||
|
||||
public EditorLineStatus(JEditTextArea textarea) {
|
||||
this.textarea = textarea;
|
||||
textarea.editorLineStatus = this;
|
||||
@ -61,7 +64,7 @@ public class EditorLineStatus extends JComponent {
|
||||
foreground = Theme.getColor("linestatus.color");
|
||||
high = Theme.getInteger("linestatus.height");
|
||||
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
resize = Base.getThemeImage("resize.gif", this);
|
||||
}
|
||||
//linestatus.bgcolor = #000000
|
||||
@ -69,7 +72,6 @@ public class EditorLineStatus extends JComponent {
|
||||
//linestatus.color = #FFFFFF
|
||||
}
|
||||
|
||||
|
||||
public void set(int newStart, int newStop) {
|
||||
if ((newStart == start) && (newStop == stop)) return;
|
||||
|
||||
@ -92,11 +94,10 @@ public class EditorLineStatus extends JComponent {
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (name=="" && serialport=="") {
|
||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||
if (boardPreferences!=null)
|
||||
if (name == "" && serialport == "") {
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
if (boardPreferences != null)
|
||||
setBoardName(boardPreferences.get("name"));
|
||||
else
|
||||
setBoardName("-");
|
||||
@ -118,13 +119,18 @@ public class EditorLineStatus extends JComponent {
|
||||
|
||||
g.drawString(tmp, size.width - (int) bounds.getWidth() -20 , baseline);
|
||||
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
g.drawImage(resize, size.width - 20, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBoardName(String name) { this.name = name; }
|
||||
public void setSerialPort(String serialport) { this.serialport = serialport; }
|
||||
public void setBoardName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setSerialPort(String serialport) {
|
||||
this.serialport = serialport;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(300, high);
|
||||
|
@ -25,9 +25,13 @@ package processing.app;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
import java.awt.datatransfer.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
@ -331,7 +335,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
|
||||
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
|
||||
// os9 seems to work if bg of component is set, but x still a bastard
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
//yesButton.setBackground(bgcolor[EDIT]);
|
||||
//noButton.setBackground(bgcolor[EDIT]);
|
||||
cancelButton.setBackground(bgcolor[EDIT]);
|
||||
@ -444,7 +448,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
|
||||
progressBar = new JProgressBar(JScrollBar.HORIZONTAL);
|
||||
progressBar.setIndeterminate(false);
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
//progressBar.setBackground(bgcolor[PROGRESS]);
|
||||
//progressBar.putClientProperty("JProgressBar.style", "circular");
|
||||
}
|
||||
@ -460,7 +464,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
copyErrorButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String message = "";
|
||||
message += _("Arduino: ") + Base.VERSION_NAME + " (" + System.getProperty("os.name") + "), ";
|
||||
message += _("Arduino: ") + BaseNoGui.VERSION_NAME + " (" + System.getProperty("os.name") + "), ";
|
||||
message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n\n";
|
||||
message += editor.console.consoleTextPane.getText().trim();
|
||||
if ((Preferences.getBoolean("build.verbose")) == false) {
|
||||
|
@ -26,7 +26,11 @@ import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
|
||||
/**
|
||||
@ -47,239 +51,205 @@ import javax.swing.*;
|
||||
@SuppressWarnings("serial")
|
||||
public class FindReplace extends JFrame implements ActionListener {
|
||||
|
||||
static final int EDGE = Base.isMacOS() ? 20 : 13;
|
||||
static final int SMALL = 6;
|
||||
static final int BUTTONGAP = 12; // 12 is correct for Mac, other numbers may be required for other platofrms
|
||||
private Editor editor;
|
||||
|
||||
Editor editor;
|
||||
private JTextField findField;
|
||||
private JTextField replaceField;
|
||||
private static String findString;
|
||||
private static String replaceString;
|
||||
|
||||
JTextField findField;
|
||||
JTextField replaceField;
|
||||
static String findString;
|
||||
static String replaceString;
|
||||
private JButton replaceButton;
|
||||
private JButton replaceAllButton;
|
||||
private JButton replaceFindButton;
|
||||
private JButton previousButton;
|
||||
private JButton findButton;
|
||||
|
||||
JButton replaceButton;
|
||||
JButton replaceAllButton;
|
||||
JButton replaceFindButton;
|
||||
JButton previousButton;
|
||||
JButton findButton;
|
||||
private JCheckBox ignoreCaseBox;
|
||||
private static boolean ignoreCase = true;
|
||||
|
||||
JCheckBox ignoreCaseBox;
|
||||
static boolean ignoreCase = true;
|
||||
private JCheckBox wrapAroundBox;
|
||||
private static boolean wrapAround = true;
|
||||
|
||||
JCheckBox wrapAroundBox;
|
||||
static boolean wrapAround = true;
|
||||
|
||||
JCheckBox searchAllFilesBox;
|
||||
static boolean searchAllFiles = false;
|
||||
private JCheckBox searchAllFilesBox;
|
||||
private static boolean searchAllFiles = false;
|
||||
|
||||
public FindReplace(Editor editor) {
|
||||
super("Find");
|
||||
setResizable(false);
|
||||
super(_("Find"));
|
||||
this.editor = editor;
|
||||
|
||||
FlowLayout searchLayout = new FlowLayout(FlowLayout.RIGHT,5,0);
|
||||
Container pane = getContentPane();
|
||||
pane.setLayout(searchLayout);
|
||||
|
||||
JPanel contentPanel = new JPanel();
|
||||
Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);
|
||||
contentPanel.setBorder(padding);
|
||||
setContentPane(contentPanel);
|
||||
|
||||
JLabel findLabel = new JLabel(_("Find:"));
|
||||
findField = new JTextField(20);
|
||||
JLabel replaceLabel = new JLabel(_("Replace with:"));
|
||||
Dimension labelDimension = replaceLabel.getPreferredSize();
|
||||
|
||||
JPanel find = new JPanel();
|
||||
find.add(findLabel);
|
||||
find.add(findField = new JTextField(20));
|
||||
pane.add(find);
|
||||
|
||||
JPanel replace = new JPanel();
|
||||
replace.add(replaceLabel);
|
||||
replace.add(replaceField = new JTextField(20));
|
||||
pane.add(replace);
|
||||
|
||||
int fieldHeight = findField.getPreferredSize().height;
|
||||
replaceField = new JTextField(20);
|
||||
|
||||
JPanel checkbox = new JPanel();
|
||||
|
||||
// Fill the findString with selected text if no previous value
|
||||
if (editor.getSelectedText() != null &&
|
||||
editor.getSelectedText().length() > 0)
|
||||
if (editor.getSelectedText() != null
|
||||
&& editor.getSelectedText().length() > 0)
|
||||
findString = editor.getSelectedText();
|
||||
|
||||
if (findString != null) findField.setText(findString);
|
||||
if (replaceString != null) replaceField.setText(replaceString);
|
||||
//System.out.println("setting find str to " + findString);
|
||||
//findField.requestFocusInWindow();
|
||||
if (findString != null)
|
||||
findField.setText(findString);
|
||||
if (replaceString != null)
|
||||
replaceField.setText(replaceString);
|
||||
|
||||
ignoreCaseBox = new JCheckBox(_("Ignore Case"));
|
||||
ignoreCaseBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ignoreCase = ignoreCaseBox.isSelected();
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ignoreCase = ignoreCaseBox.isSelected();
|
||||
}
|
||||
});
|
||||
ignoreCaseBox.setSelected(ignoreCase);
|
||||
checkbox.add(ignoreCaseBox);
|
||||
|
||||
wrapAroundBox = new JCheckBox(_("Wrap Around"));
|
||||
wrapAroundBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
wrapAround = wrapAroundBox.isSelected();
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
wrapAround = wrapAroundBox.isSelected();
|
||||
}
|
||||
});
|
||||
wrapAroundBox.setSelected(wrapAround);
|
||||
checkbox.add(wrapAroundBox);
|
||||
|
||||
|
||||
searchAllFilesBox = new JCheckBox(_("Search all Sketch Tabs"));
|
||||
searchAllFilesBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
searchAllFiles = searchAllFilesBox.isSelected();
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
searchAllFiles = searchAllFilesBox.isSelected();
|
||||
}
|
||||
});
|
||||
searchAllFilesBox.setSelected(searchAllFiles);
|
||||
checkbox.add(searchAllFilesBox);
|
||||
|
||||
pane.add(checkbox);
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
buttons.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONGAP, 0));
|
||||
JPanel checkboxPanel = new JPanel();
|
||||
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.PAGE_AXIS));
|
||||
checkboxPanel.add(ignoreCaseBox);
|
||||
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
checkboxPanel.add(wrapAroundBox);
|
||||
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
checkboxPanel.add(searchAllFilesBox);
|
||||
|
||||
// ordering is different on mac versus pc
|
||||
if (Base.isMacOS()) {
|
||||
buttons.add(replaceAllButton = new JButton(_("Replace All")));
|
||||
buttons.add(replaceButton = new JButton(_("Replace")));
|
||||
buttons.add(replaceFindButton = new JButton(_("Replace & Find")));
|
||||
buttons.add(previousButton = new JButton(_("Previous")));
|
||||
buttons.add(findButton = new JButton(_("Find")));
|
||||
replaceAllButton = new JButton(_("Replace All"));
|
||||
replaceAllButton.addActionListener(this);
|
||||
replaceButton = new JButton(_("Replace"));
|
||||
replaceButton.addActionListener(this);
|
||||
replaceFindButton = new JButton(_("Replace & Find"));
|
||||
replaceFindButton.addActionListener(this);
|
||||
previousButton = new JButton(_("Previous"));
|
||||
previousButton.addActionListener(this);
|
||||
findButton = new JButton(_("Find"));
|
||||
findButton.addActionListener(this);
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
||||
|
||||
// ordering of buttons is different on mac versus pc
|
||||
if (OSUtils.isMacOS()) {
|
||||
buttonPanel.add(replaceAllButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceFindButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(previousButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(findButton);
|
||||
|
||||
} else {
|
||||
buttons.add(findButton = new JButton(_("Find")));
|
||||
buttons.add(previousButton = new JButton(_("Previous"))); // is this the right position for non-Mac?
|
||||
buttons.add(replaceFindButton = new JButton(_("Replace & Find")));
|
||||
buttons.add(replaceButton = new JButton(_("Replace")));
|
||||
buttons.add(replaceAllButton = new JButton(_("Replace All")));
|
||||
buttonPanel.add(findButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(previousButton); // is this the right position for
|
||||
// non-Mac?
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceFindButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceAllButton);
|
||||
}
|
||||
pane.add(buttons);
|
||||
|
||||
// to fix ugliness.. normally macosx java 1.3 puts an
|
||||
// ugly white border around this object, so turn it off.
|
||||
if (Base.isMacOS()) {
|
||||
buttons.setBorder(null);
|
||||
if (OSUtils.isMacOS()) {
|
||||
buttonPanel.setBorder(null);
|
||||
}
|
||||
|
||||
/*
|
||||
findField.addFocusListener(new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
System.out.println("Focus gained " + e.getOppositeComponent());
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
System.out.println("Focus lost "); // + e.getOppositeComponent());
|
||||
if (e.getOppositeComponent() == null) {
|
||||
requestFocusInWindow();
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Dimension buttonsDimension = buttons.getPreferredSize();
|
||||
int visibleButtonWidth = buttonsDimension.width - 2 * BUTTONGAP;
|
||||
int fieldWidth = visibleButtonWidth - (labelDimension.width + SMALL);
|
||||
|
||||
// +1 since it's better to tend downwards
|
||||
int yoff = (1 + fieldHeight - labelDimension.height) / 2;
|
||||
|
||||
int ypos = EDGE;
|
||||
// Put all components onto the dialog window
|
||||
GridBagLayout searchLayout = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
Container pane = getContentPane();
|
||||
pane.setLayout(searchLayout);
|
||||
|
||||
int labelWidth = findLabel.getPreferredSize().width;
|
||||
findLabel.setBounds(EDGE + (labelDimension.width-labelWidth), ypos + yoff, // + yoff was added to the wrong field
|
||||
labelWidth, labelDimension.height);
|
||||
findField.setBounds(EDGE + labelDimension.width + SMALL, ypos,
|
||||
fieldWidth, fieldHeight);
|
||||
|
||||
ypos += fieldHeight + SMALL;
|
||||
|
||||
labelWidth = replaceLabel.getPreferredSize().width;
|
||||
replaceLabel.setBounds(EDGE + (labelDimension.width-labelWidth), ypos + yoff,
|
||||
labelWidth, labelDimension.height);
|
||||
replaceField.setBounds(EDGE + labelDimension.width + SMALL, ypos,
|
||||
fieldWidth, fieldHeight);
|
||||
|
||||
ypos += fieldHeight + SMALL;
|
||||
|
||||
ignoreCaseBox.setBounds(EDGE + labelDimension.width + SMALL,
|
||||
ypos,
|
||||
(fieldWidth-SMALL)/4, fieldHeight);
|
||||
|
||||
wrapAroundBox.setBounds(EDGE + labelDimension.width + SMALL + (fieldWidth-SMALL)/4 + SMALL,
|
||||
ypos,
|
||||
(fieldWidth-SMALL)/4, fieldHeight);
|
||||
|
||||
searchAllFilesBox.setBounds(EDGE + labelDimension.width + SMALL + (int)((fieldWidth-SMALL)/1.9) + SMALL,
|
||||
ypos,
|
||||
(fieldWidth-SMALL)/2, fieldHeight);
|
||||
|
||||
ypos += fieldHeight + SMALL;
|
||||
|
||||
buttons.setBounds(EDGE-BUTTONGAP, ypos,
|
||||
buttonsDimension.width, buttonsDimension.height);
|
||||
|
||||
ypos += buttonsDimension.height;
|
||||
|
||||
// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
int wide = visibleButtonWidth + EDGE*2;
|
||||
int high = ypos; // butt.y + butt.height + EDGE*2 + SMALL;
|
||||
gbc.insets = new Insets(4, 4, 4, 4);
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 0.0;
|
||||
gbc.weighty = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_END;
|
||||
pane.add(findLabel, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
pane.add(findField, gbc);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_END;
|
||||
pane.add(replaceLabel, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
pane.add(replaceField, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 2;
|
||||
gbc.weighty = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
pane.add(checkboxPanel, gbc);
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 3;
|
||||
gbc.insets = new Insets(12, 4, 4, 4);
|
||||
pane.add(buttonPanel, gbc);
|
||||
|
||||
pack();
|
||||
Insets insets = getInsets();
|
||||
//System.out.println("Insets = " + insets);
|
||||
setSize(wide + insets.left + insets.right,high + insets.top + insets.bottom);
|
||||
|
||||
setLocationRelativeTo( null ); // center
|
||||
// setBounds((screen.width - wide) / 2, (screen.height - high) / 2, wide, high);
|
||||
|
||||
replaceButton.addActionListener(this);
|
||||
replaceAllButton.addActionListener(this);
|
||||
replaceFindButton.addActionListener(this);
|
||||
findButton.addActionListener(this);
|
||||
previousButton.addActionListener(this);
|
||||
|
||||
// you mustn't replace what you haven't found, my son
|
||||
// semantics of replace are "replace the current selection with the replace field"
|
||||
// so whether we have found before or not is irrelevent
|
||||
// replaceButton.setEnabled(false);
|
||||
// replaceFindButton.setEnabled(false);
|
||||
setResizable(false);
|
||||
// centers the dialog on thew screen
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// make the find button the blinky default
|
||||
getRootPane().setDefaultButton(findButton);
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
public void windowClosing(WindowEvent e) {
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
//hide();
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
// hide();
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
Base.setIcon(this);
|
||||
|
||||
// hack to to get first field to focus properly on osx
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
//System.out.println("activating");
|
||||
/*boolean ok =*/ findField.requestFocusInWindow();
|
||||
//System.out.println("got " + ok);
|
||||
findField.selectAll();
|
||||
}
|
||||
});
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// System.out.println("activating");
|
||||
/* boolean ok = */findField.requestFocusInWindow();
|
||||
// System.out.println("got " + ok);
|
||||
findField.selectAll();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void handleClose() {
|
||||
//System.out.println("handling close now");
|
||||
// System.out.println("handling close now");
|
||||
findString = findField.getText();
|
||||
replaceString = replaceField.getText();
|
||||
|
||||
@ -287,7 +257,6 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void show() {
|
||||
findField.requestFocusInWindow();
|
||||
@ -318,17 +287,18 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// look for the next instance of the find string to be found
|
||||
// once found, select it (and go to that line)
|
||||
|
||||
private boolean find(boolean wrap,boolean backwards,boolean searchTabs,int originTab) {
|
||||
//System.out.println("Find: " + originTab);
|
||||
boolean wrapNeeded = false;
|
||||
private boolean find(boolean wrap, boolean backwards, boolean searchTabs,
|
||||
int originTab) {
|
||||
// System.out.println("Find: " + originTab);
|
||||
boolean wrapNeeded = false;
|
||||
String search = findField.getText();
|
||||
//System.out.println("finding for " + search + " " + findString);
|
||||
// System.out.println("finding for " + search + " " + findString);
|
||||
// this will catch "find next" being called when no search yet
|
||||
if (search.length() == 0) return false;
|
||||
if (search.length() == 0)
|
||||
return false;
|
||||
|
||||
String text = editor.getText();
|
||||
|
||||
@ -339,7 +309,7 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
|
||||
int nextIndex;
|
||||
if (!backwards) {
|
||||
//int selectionStart = editor.textarea.getSelectionStart();
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionEnd = editor.getSelectionStop();
|
||||
|
||||
nextIndex = text.indexOf(search, selectionEnd);
|
||||
@ -348,10 +318,10 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
wrapNeeded = true;
|
||||
}
|
||||
} else {
|
||||
//int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionStart = editor.getSelectionStart()-1;
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionStart = editor.getSelectionStart() - 1;
|
||||
|
||||
if ( selectionStart >= 0 ) {
|
||||
if (selectionStart >= 0) {
|
||||
nextIndex = text.lastIndexOf(search, selectionStart);
|
||||
} else {
|
||||
nextIndex = -1;
|
||||
@ -375,8 +345,8 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
originTab = realCurrentTab;
|
||||
|
||||
if (!wrap)
|
||||
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) ||
|
||||
(backwards && realCurrentTab - 1 < 0))
|
||||
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount())
|
||||
|| (backwards && realCurrentTab - 1 < 0))
|
||||
return false; // Can't continue without wrap
|
||||
|
||||
if (backwards) {
|
||||
@ -394,23 +364,23 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (wrapNeeded)
|
||||
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
|
||||
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search,
|
||||
0);
|
||||
}
|
||||
|
||||
if (nextIndex != -1) {
|
||||
|
||||
if (nextIndex != -1) {
|
||||
editor.setSelection(nextIndex, nextIndex + search.length());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the
|
||||
* replacement text field.
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field.
|
||||
*/
|
||||
public void replace() {
|
||||
if (findField.getText().length() == 0)
|
||||
@ -436,8 +406,8 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the
|
||||
* replacement text field, and then find the next match
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field, and then find the next match
|
||||
*/
|
||||
public void replaceAndFindNext() {
|
||||
replace();
|
||||
@ -445,8 +415,8 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace everything that matches by doing find and replace
|
||||
* alternately until nothing more found.
|
||||
* Replace everything that matches by doing find and replace alternately until
|
||||
* nothing more found.
|
||||
*/
|
||||
public void replaceAll() {
|
||||
if (findField.getText().length() == 0)
|
||||
@ -468,20 +438,20 @@ public class FindReplace extends JFrame implements ActionListener {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFindText( String t ) {
|
||||
findField.setText( t );
|
||||
|
||||
public void setFindText(String t) {
|
||||
findField.setText(t);
|
||||
findString = t;
|
||||
}
|
||||
|
||||
public void findNext() {
|
||||
if ( !find( wrapAround, false, searchAllFiles,-1 ) ) {
|
||||
if (!find(wrapAround, false, searchAllFiles, -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void findPrevious() {
|
||||
if ( !find( wrapAround, true, searchAllFiles,-1 ) ) {
|
||||
if (!find(wrapAround, true, searchAllFiles, -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import javax.swing.undo.CannotUndoException;
|
||||
import javax.swing.undo.UndoManager;
|
||||
import javax.swing.undo.UndoableEdit;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LastUndoableEditAwareUndoManager extends UndoManager {
|
||||
|
||||
private UndoableEdit lastUndoableEdit;
|
||||
|
@ -5,10 +5,14 @@ import cc.arduino.packages.ssh.NoInteractionUserInfo;
|
||||
import cc.arduino.packages.ssh.SSHClientSetupChainRing;
|
||||
import cc.arduino.packages.ssh.SSHConfigFileSetup;
|
||||
import cc.arduino.packages.ssh.SSHPwdSetup;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
|
||||
import processing.app.debug.MessageConsumer;
|
||||
import processing.app.debug.MessageSiphon;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
@ -18,7 +22,7 @@ import java.io.OutputStream;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class NetworkMonitor extends AbstractMonitor {
|
||||
public class NetworkMonitor extends AbstractMonitor implements MessageConsumer {
|
||||
|
||||
private static final int MAX_CONNECTION_ATTEMPTS = 5;
|
||||
|
||||
@ -28,10 +32,9 @@ public class NetworkMonitor extends AbstractMonitor {
|
||||
private MessageSiphon inputConsumer;
|
||||
private Session session;
|
||||
private Channel channel;
|
||||
private MessageSiphon errorConsumer;
|
||||
private int connectionAttempts;
|
||||
|
||||
public NetworkMonitor(BoardPort port, Base base) {
|
||||
public NetworkMonitor(BoardPort port) {
|
||||
super(port.getLabel());
|
||||
this.port = port;
|
||||
this.ipAddress = port.getAddress();
|
||||
@ -69,7 +72,7 @@ public class NetworkMonitor extends AbstractMonitor {
|
||||
SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup());
|
||||
session = sshClientSetupChain.setup(port, jSch);
|
||||
|
||||
session.setUserInfo(new NoInteractionUserInfo(Preferences.get(getAuthorizationKey())));
|
||||
session.setUserInfo(new NoInteractionUserInfo(PreferencesData.get(getAuthorizationKey())));
|
||||
session.connect(30000);
|
||||
|
||||
tryConnect();
|
||||
@ -98,7 +101,7 @@ public class NetworkMonitor extends AbstractMonitor {
|
||||
channel.connect();
|
||||
|
||||
inputConsumer = new MessageSiphon(inputStream, this);
|
||||
errorConsumer = new MessageSiphon(errStream, this);
|
||||
new MessageSiphon(errStream, this);
|
||||
|
||||
if (connectionAttempts > 1) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
@ -23,21 +21,39 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.syntax.SyntaxStyle;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
|
||||
/**
|
||||
@ -69,9 +85,7 @@ import static processing.app.I18n._;
|
||||
*/
|
||||
public class Preferences {
|
||||
|
||||
// what to call the feller
|
||||
|
||||
static final String PREFS_FILE = "preferences.txt";
|
||||
static final String PREFS_FILE = PreferencesData.PREFS_FILE;
|
||||
|
||||
class Language {
|
||||
Language(String _name, String _originalName, String _isoCode) {
|
||||
@ -216,85 +230,12 @@ public class Preferences {
|
||||
Editor editor;
|
||||
|
||||
|
||||
// data model
|
||||
|
||||
static Hashtable<String, String> defaults;
|
||||
static Hashtable<String, String> table = new Hashtable<String, String>();
|
||||
static File preferencesFile;
|
||||
static boolean doSave = true;
|
||||
|
||||
|
||||
static protected void init(File file) {
|
||||
if (file != null)
|
||||
preferencesFile = file;
|
||||
else
|
||||
preferencesFile = Base.getSettingsFile(Preferences.PREFS_FILE);
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
try {
|
||||
load(Base.getLibStream("preferences.txt"));
|
||||
} catch (Exception e) {
|
||||
Base.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = Base.getHardwareFolder();
|
||||
table.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
table.put("runtime.ide.version", "" + Base.REVISION);
|
||||
|
||||
// check for platform-specific properties in the defaults
|
||||
String platformExt = "." + Base.platform.getName();
|
||||
int platformExtLength = platformExt.length();
|
||||
Set<String> keySet = new HashSet<String>(table.keySet());
|
||||
for (String key : keySet) {
|
||||
if (key.endsWith(platformExt)) {
|
||||
// this is a key specific to a particular platform
|
||||
String actualKey = key.substring(0, key.length() - platformExtLength);
|
||||
String value = get(key);
|
||||
table.put(actualKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
// clone the hash table
|
||||
defaults = new Hashtable<String, String>(table);
|
||||
|
||||
if (preferencesFile.exists()) {
|
||||
// load the previous preferences file
|
||||
try {
|
||||
load(new FileInputStream(preferencesFile));
|
||||
} catch (Exception ex) {
|
||||
Base.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
// load the I18n module for internationalization
|
||||
try {
|
||||
I18n.init(Preferences.get("editor.languages.current"));
|
||||
} catch (MissingResourceException e) {
|
||||
I18n.init("en");
|
||||
Preferences.set("editor.languages.current", "en");
|
||||
}
|
||||
|
||||
// set some other runtime constants (not saved on preferences file)
|
||||
table.put("runtime.os", PConstants.platformNames[PApplet.platform]);
|
||||
PreferencesData.init(file);
|
||||
|
||||
// other things that have to be set explicitly for the defaults
|
||||
setColor("run.window.bgcolor", SystemColor.control);
|
||||
|
||||
fixPreferences();
|
||||
}
|
||||
|
||||
private static void fixPreferences() {
|
||||
String baud = get("serial.debug_rate");
|
||||
if ("14400".equals(baud) || "28800".equals(baud) || "38400".equals(baud)) {
|
||||
set("serial.debug_rate", "9600");
|
||||
}
|
||||
PreferencesHelper.putColor(PreferencesData.prefs, "run.window.bgcolor", SystemColor.control);
|
||||
}
|
||||
|
||||
|
||||
@ -371,7 +312,7 @@ public class Preferences {
|
||||
label = new JLabel(_("Editor language: "));
|
||||
box.add(label);
|
||||
comboLanguage = new JComboBox(languages);
|
||||
String currentLanguage = Preferences.get("editor.languages.current");
|
||||
String currentLanguage = PreferencesData.get("editor.languages.current");
|
||||
for (Language language : languages) {
|
||||
if (language.isoCode.equals(currentLanguage))
|
||||
comboLanguage.setSelectedItem(language);
|
||||
@ -465,7 +406,7 @@ public class Preferences {
|
||||
|
||||
// [ ] Automatically associate .pde files with Processing
|
||||
|
||||
if (Base.isWindows()) {
|
||||
if (OSUtils.isWindows()) {
|
||||
autoAssociateBox =
|
||||
new JCheckBox(_("Automatically associate .ino files with Arduino"));
|
||||
pain.add(autoAssociateBox);
|
||||
@ -498,11 +439,11 @@ public class Preferences {
|
||||
right = Math.max(right, left + d.width);
|
||||
top += d.height; // + GUI_SMALL;
|
||||
|
||||
label = new JLabel(preferencesFile.getAbsolutePath());
|
||||
label = new JLabel(PreferencesData.preferencesFile.getAbsolutePath());
|
||||
final JLabel clickable = label;
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Base.openFolder(preferencesFile.getParentFile());
|
||||
Base.openFolder(PreferencesData.preferencesFile.getParentFile());
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
@ -604,11 +545,6 @@ public class Preferences {
|
||||
}
|
||||
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(wide, high);
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
@ -626,34 +562,34 @@ public class Preferences {
|
||||
*/
|
||||
protected void applyFrame() {
|
||||
// put each of the settings into the table
|
||||
setBoolean("build.verbose", verboseCompilationBox.isSelected());
|
||||
setBoolean("upload.verbose", verboseUploadBox.isSelected());
|
||||
setBoolean("editor.linenumbers", displayLineNumbersBox.isSelected());
|
||||
setBoolean("upload.verify", verifyUploadBox.isSelected());
|
||||
setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
|
||||
|
||||
PreferencesData.setBoolean("build.verbose", verboseCompilationBox.isSelected());
|
||||
PreferencesData.setBoolean("upload.verbose", verboseUploadBox.isSelected());
|
||||
PreferencesData.setBoolean("editor.linenumbers", displayLineNumbersBox.isSelected());
|
||||
PreferencesData.setBoolean("upload.verify", verifyUploadBox.isSelected());
|
||||
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
|
||||
|
||||
// setBoolean("sketchbook.closing_last_window_quits",
|
||||
// closingLastQuitsBox.isSelected());
|
||||
//setBoolean("sketchbook.prompt", sketchPromptBox.isSelected());
|
||||
//setBoolean("sketchbook.auto_clean", sketchCleanBox.isSelected());
|
||||
|
||||
// if the sketchbook path has changed, rebuild the menus
|
||||
String oldPath = get("sketchbook.path");
|
||||
String oldPath = PreferencesData.get("sketchbook.path");
|
||||
String newPath = sketchbookLocationField.getText();
|
||||
if (newPath.isEmpty()) {
|
||||
if (Base.getPortableFolder() == null)
|
||||
newPath = editor.base.getDefaultSketchbookFolder().toString();
|
||||
newPath = editor.base.getDefaultSketchbookFolderOrPromptForIt().toString();
|
||||
else
|
||||
newPath = Base.getPortableSketchbookFolder();
|
||||
}
|
||||
if (!newPath.equals(oldPath)) {
|
||||
editor.base.rebuildSketchbookMenus();
|
||||
set("sketchbook.path", newPath);
|
||||
PreferencesData.set("sketchbook.path", newPath);
|
||||
}
|
||||
|
||||
setBoolean("editor.external", externalEditorBox.isSelected());
|
||||
setBoolean("update.check", checkUpdatesBox.isSelected());
|
||||
setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
|
||||
PreferencesData.setBoolean("editor.external", externalEditorBox.isSelected());
|
||||
PreferencesData.setBoolean("update.check", checkUpdatesBox.isSelected());
|
||||
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
|
||||
|
||||
/*
|
||||
// was gonna use this to check memory settings,
|
||||
@ -670,24 +606,24 @@ public class Preferences {
|
||||
String newSizeText = fontSizeField.getText();
|
||||
try {
|
||||
int newSize = Integer.parseInt(newSizeText.trim());
|
||||
String pieces[] = PApplet.split(get("editor.font"), ',');
|
||||
String pieces[] = PApplet.split(PreferencesData.get("editor.font"), ',');
|
||||
pieces[2] = String.valueOf(newSize);
|
||||
set("editor.font", PApplet.join(pieces, ','));
|
||||
PreferencesData.set("editor.font", PApplet.join(pieces, ','));
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(I18n.format(_("ignoring invalid font size {0}"), newSizeText));
|
||||
}
|
||||
|
||||
if (autoAssociateBox != null) {
|
||||
setBoolean("platform.auto_file_type_associations",
|
||||
PreferencesData.setBoolean("platform.auto_file_type_associations",
|
||||
autoAssociateBox.isSelected());
|
||||
}
|
||||
|
||||
setBoolean("editor.update_extension", updateExtensionBox.isSelected());
|
||||
PreferencesData.setBoolean("editor.update_extension", updateExtensionBox.isSelected());
|
||||
|
||||
// adds the selected language to the preferences file
|
||||
Language newLanguage = (Language) comboLanguage.getSelectedItem();
|
||||
set("editor.languages.current", newLanguage.isoCode);
|
||||
PreferencesData.set("editor.languages.current", newLanguage.isoCode);
|
||||
|
||||
editor.applyPreferences();
|
||||
}
|
||||
@ -697,10 +633,10 @@ public class Preferences {
|
||||
this.editor = editor;
|
||||
|
||||
// set all settings entry boxes to their actual status
|
||||
verboseCompilationBox.setSelected(getBoolean("build.verbose"));
|
||||
verboseUploadBox.setSelected(getBoolean("upload.verbose"));
|
||||
displayLineNumbersBox.setSelected(getBoolean("editor.linenumbers"));
|
||||
verifyUploadBox.setSelected(getBoolean("upload.verify"));
|
||||
verboseCompilationBox.setSelected(PreferencesData.getBoolean("build.verbose"));
|
||||
verboseUploadBox.setSelected(PreferencesData.getBoolean("upload.verbose"));
|
||||
displayLineNumbersBox.setSelected(PreferencesData.getBoolean("editor.linenumbers"));
|
||||
verifyUploadBox.setSelected(PreferencesData.getBoolean("upload.verify"));
|
||||
|
||||
//closingLastQuitsBox.
|
||||
// setSelected(getBoolean("sketchbook.closing_last_window_quits"));
|
||||
@ -710,294 +646,95 @@ public class Preferences {
|
||||
// setSelected(getBoolean("sketchbook.auto_clean"));
|
||||
|
||||
sketchbookLocationField.
|
||||
setText(get("sketchbook.path"));
|
||||
setText(PreferencesData.get("sketchbook.path"));
|
||||
externalEditorBox.
|
||||
setSelected(getBoolean("editor.external"));
|
||||
setSelected(PreferencesData.getBoolean("editor.external"));
|
||||
checkUpdatesBox.
|
||||
setSelected(getBoolean("update.check"));
|
||||
setSelected(PreferencesData.getBoolean("update.check"));
|
||||
saveVerifyUploadBox.
|
||||
setSelected(getBoolean("editor.save_on_verify"));
|
||||
setSelected(PreferencesData.getBoolean("editor.save_on_verify"));
|
||||
|
||||
if (autoAssociateBox != null) {
|
||||
autoAssociateBox.
|
||||
setSelected(getBoolean("platform.auto_file_type_associations"));
|
||||
setSelected(PreferencesData.getBoolean("platform.auto_file_type_associations"));
|
||||
}
|
||||
|
||||
updateExtensionBox.setSelected(get("editor.update_extension") == null ||
|
||||
getBoolean("editor.update_extension"));
|
||||
updateExtensionBox.setSelected(PreferencesData.get("editor.update_extension") == null ||
|
||||
PreferencesData.getBoolean("editor.update_extension"));
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
static protected void load(InputStream input) throws IOException {
|
||||
load(input, table);
|
||||
}
|
||||
|
||||
static public void load(InputStream input, Map<String, String> table) throws IOException {
|
||||
String[] lines = loadStrings(input); // Reads as UTF-8
|
||||
for (String line : lines) {
|
||||
if ((line.length() == 0) ||
|
||||
(line.charAt(0) == '#')) continue;
|
||||
|
||||
// this won't properly handle = signs being in the text
|
||||
int equals = line.indexOf('=');
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
table.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public String[] loadStrings(InputStream input) {
|
||||
try {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(input, "UTF-8"));
|
||||
|
||||
String lines[] = new String[100];
|
||||
int lineCount = 0;
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (lineCount == lines.length) {
|
||||
String temp[] = new String[lineCount << 1];
|
||||
System.arraycopy(lines, 0, temp, 0, lineCount);
|
||||
lines = temp;
|
||||
}
|
||||
lines[lineCount++] = line;
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (lineCount == lines.length) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// resize array to appropriate amount for these lines
|
||||
String output[] = new String[lineCount];
|
||||
System.arraycopy(lines, 0, output, 0, lineCount);
|
||||
return output;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
static protected void save() {
|
||||
if (!doSave) return;
|
||||
// try {
|
||||
// on startup, don't worry about it
|
||||
// this is trying to update the prefs for who is open
|
||||
// before Preferences.init() has been called.
|
||||
if (preferencesFile == null) return;
|
||||
|
||||
// Fix for 0163 to properly use Unicode when writing preferences.txt
|
||||
PrintWriter writer = PApplet.createWriter(preferencesFile);
|
||||
|
||||
String[] keys = table.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keys);
|
||||
for (String key: keys) {
|
||||
if (key.startsWith("runtime."))
|
||||
continue;
|
||||
writer.println(key + "=" + table.get(key));
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
// } catch (Exception ex) {
|
||||
// Base.showWarning(null, "Error while saving the settings file", ex);
|
||||
// }
|
||||
PreferencesData.save();
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
// all the information from preferences.txt
|
||||
|
||||
//static public String get(String attribute) {
|
||||
//return get(attribute, null);
|
||||
//}
|
||||
|
||||
static public String get(String attribute) {
|
||||
return table.get(attribute);
|
||||
return PreferencesData.get(attribute);
|
||||
}
|
||||
|
||||
static public String get(String attribute, String defaultValue) {
|
||||
String value = get(attribute);
|
||||
|
||||
return (value == null) ? defaultValue : value;
|
||||
return PreferencesData.get(attribute, defaultValue);
|
||||
}
|
||||
|
||||
public static boolean has(String key) {
|
||||
return table.containsKey(key);
|
||||
return PreferencesData.has(key);
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
table.remove(key);
|
||||
}
|
||||
|
||||
static public String getDefault(String attribute) {
|
||||
return defaults.get(attribute);
|
||||
PreferencesData.remove(key);
|
||||
}
|
||||
|
||||
|
||||
static public void set(String attribute, String value) {
|
||||
table.put(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public void unset(String attribute) {
|
||||
table.remove(attribute);
|
||||
PreferencesData.set(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public boolean getBoolean(String attribute) {
|
||||
String value = get(attribute); //, null);
|
||||
return (new Boolean(value)).booleanValue();
|
||||
|
||||
/*
|
||||
supposedly not needed, because anything besides 'true'
|
||||
(ignoring case) will just be false.. so if malformed -> false
|
||||
if (value == null) return defaultValue;
|
||||
|
||||
try {
|
||||
return (new Boolean(value)).booleanValue();
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("expecting an integer: " + attribute + " = " + value);
|
||||
}
|
||||
return defaultValue;
|
||||
*/
|
||||
return PreferencesData.getBoolean(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void setBoolean(String attribute, boolean value) {
|
||||
set(attribute, value ? "true" : "false");
|
||||
PreferencesData.setBoolean(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public int getInteger(String attribute /*, int defaultValue*/) {
|
||||
return Integer.parseInt(get(attribute));
|
||||
|
||||
/*
|
||||
String value = get(attribute, null);
|
||||
if (value == null) return defaultValue;
|
||||
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
// ignored will just fall through to returning the default
|
||||
System.err.println("expecting an integer: " + attribute + " = " + value);
|
||||
}
|
||||
return defaultValue;
|
||||
//if (value == null) return defaultValue;
|
||||
//return (value == null) ? defaultValue :
|
||||
//Integer.parseInt(value);
|
||||
*/
|
||||
static public int getInteger(String attribute) {
|
||||
return PreferencesData.getInteger(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void setInteger(String key, int value) {
|
||||
set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
|
||||
static public Color getColor(String name) {
|
||||
Color parsed = Color.GRAY; // set a default
|
||||
String s = get(name);
|
||||
if ((s != null) && (s.indexOf("#") == 0)) {
|
||||
try {
|
||||
parsed = new Color(Integer.parseInt(s.substring(1), 16));
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
static public void setColor(String attr, Color what) {
|
||||
set(attr, "#" + PApplet.hex(what.getRGB() & 0xffffff, 6));
|
||||
PreferencesData.setInteger(key, value);
|
||||
}
|
||||
|
||||
|
||||
static public Font getFont(String attr) {
|
||||
boolean replace = false;
|
||||
String value = get(attr);
|
||||
if (value == null) {
|
||||
//System.out.println("reset 1");
|
||||
value = getDefault(attr);
|
||||
replace = true;
|
||||
Font font = PreferencesHelper.getFont(PreferencesData.prefs, attr);
|
||||
if (font == null) {
|
||||
String value = PreferencesData.defaults.get(attr);
|
||||
PreferencesData.prefs.put(attr, value);
|
||||
font = PreferencesHelper.getFont(PreferencesData.prefs, attr);
|
||||
}
|
||||
|
||||
String[] pieces = PApplet.split(value, ',');
|
||||
if (pieces.length != 3) {
|
||||
value = getDefault(attr);
|
||||
//System.out.println("reset 2 for " + attr);
|
||||
pieces = PApplet.split(value, ',');
|
||||
//PApplet.println(pieces);
|
||||
replace = true;
|
||||
}
|
||||
|
||||
String name = pieces[0];
|
||||
int style = Font.PLAIN; // equals zero
|
||||
if (pieces[1].indexOf("bold") != -1) {
|
||||
style |= Font.BOLD;
|
||||
}
|
||||
if (pieces[1].indexOf("italic") != -1) {
|
||||
style |= Font.ITALIC;
|
||||
}
|
||||
int size = PApplet.parseInt(pieces[2], 12);
|
||||
Font font = new Font(name, style, size);
|
||||
|
||||
// replace bad font with the default
|
||||
if (replace) {
|
||||
set(attr, value);
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
static public SyntaxStyle getStyle(String what /*, String dflt*/) {
|
||||
String str = get("editor." + what + ".style"); //, dflt);
|
||||
|
||||
StringTokenizer st = new StringTokenizer(str, ",");
|
||||
|
||||
String s = st.nextToken();
|
||||
if (s.indexOf("#") == 0) s = s.substring(1);
|
||||
Color color = Color.DARK_GRAY;
|
||||
try {
|
||||
color = new Color(Integer.parseInt(s, 16));
|
||||
} catch (Exception e) { }
|
||||
|
||||
s = st.nextToken();
|
||||
boolean bold = (s.indexOf("bold") != -1);
|
||||
boolean italic = (s.indexOf("italic") != -1);
|
||||
boolean underlined = (s.indexOf("underlined") != -1);
|
||||
//System.out.println(what + " = " + str + " " + bold + " " + italic);
|
||||
|
||||
return new SyntaxStyle(color, italic, bold, underlined);
|
||||
}
|
||||
|
||||
// get a copy of the Preferences
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
return new PreferencesMap(table);
|
||||
return PreferencesData.getMap();
|
||||
}
|
||||
|
||||
// Decide wether changed preferences will be saved. When value is
|
||||
// false, Preferences.save becomes a no-op.
|
||||
static public void setDoSave(boolean value)
|
||||
{
|
||||
doSave = value;
|
||||
PreferencesData.setDoSave(value);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import processing.core.PApplet;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@ -27,6 +27,7 @@ import java.awt.event.ActionListener;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialMonitor extends AbstractMonitor {
|
||||
|
||||
private final String port;
|
||||
@ -90,8 +91,12 @@ public class SerialMonitor extends AbstractMonitor {
|
||||
public void open() throws Exception {
|
||||
if (serial != null) return;
|
||||
|
||||
serial = new Serial(port, serialRate);
|
||||
serial.addListener(this);
|
||||
serial = new Serial(port, serialRate) {
|
||||
@Override
|
||||
protected void message(char buff[], int n) {
|
||||
addToUpdateBuffer(buff, n);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
@ -104,4 +109,5 @@ public class SerialMonitor extends AbstractMonitor {
|
||||
serial = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
79
app/src/processing/app/SketchCodeDocument.java
Normal file
79
app/src/processing/app/SketchCodeDocument.java
Normal file
@ -0,0 +1,79 @@
|
||||
package processing.app;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.text.Document;
|
||||
|
||||
public class SketchCodeDocument{
|
||||
|
||||
private SketchCode code;
|
||||
private Document document;
|
||||
|
||||
// Undo Manager for this tab, each tab keeps track of their own Editor.undo
|
||||
// will be set to this object when this code is the tab that's currently the
|
||||
// front.
|
||||
private LastUndoableEditAwareUndoManager undo = new LastUndoableEditAwareUndoManager();
|
||||
|
||||
// saved positions from last time this tab was used
|
||||
private int selectionStart;
|
||||
private int selectionStop;
|
||||
private int scrollPosition;
|
||||
|
||||
public SketchCodeDocument(SketchCode code) {
|
||||
this.code = code;
|
||||
this.code.setMetadata(this);
|
||||
}
|
||||
|
||||
public SketchCodeDocument(File file) {
|
||||
this.code = new SketchCode(file, this);
|
||||
}
|
||||
|
||||
public LastUndoableEditAwareUndoManager getUndo() {
|
||||
return undo;
|
||||
}
|
||||
|
||||
public void setUndo(LastUndoableEditAwareUndoManager undo) {
|
||||
this.undo = undo;
|
||||
}
|
||||
|
||||
public int getSelectionStart() {
|
||||
return selectionStart;
|
||||
}
|
||||
|
||||
public void setSelectionStart(int selectionStart) {
|
||||
this.selectionStart = selectionStart;
|
||||
}
|
||||
|
||||
public int getSelectionStop() {
|
||||
return selectionStop;
|
||||
}
|
||||
|
||||
public void setSelectionStop(int selectionStop) {
|
||||
this.selectionStop = selectionStop;
|
||||
}
|
||||
|
||||
public int getScrollPosition() {
|
||||
return scrollPosition;
|
||||
}
|
||||
|
||||
public void setScrollPosition(int scrollPosition) {
|
||||
this.scrollPosition = scrollPosition;
|
||||
}
|
||||
|
||||
public SketchCode getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(SketchCode code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Document getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
public void setDocument(Document document) {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
@ -23,14 +21,15 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import processing.app.syntax.*;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.SystemColor;
|
||||
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.syntax.SyntaxStyle;
|
||||
|
||||
/**
|
||||
* Storage class for theme settings. This was separated from the Preferences
|
||||
@ -40,164 +39,80 @@ import static processing.app.I18n._;
|
||||
public class Theme {
|
||||
|
||||
/** Copy of the defaults in case the user mangles a preference. */
|
||||
static HashMap<String,String> defaults;
|
||||
static PreferencesMap defaults;
|
||||
/** Table of attributes/values for the theme. */
|
||||
static HashMap<String,String> table = new HashMap<String,String>();;
|
||||
|
||||
static PreferencesMap table = new PreferencesMap();
|
||||
|
||||
static protected void init() {
|
||||
try {
|
||||
load(Base.getLibStream("theme/theme.txt"));
|
||||
table.load(Base.getLibStream("theme/theme.txt"));
|
||||
} catch (Exception te) {
|
||||
Base.showError(null, _("Could not read color theme settings.\n" +
|
||||
"You'll need to reinstall Arduino."), te);
|
||||
}
|
||||
|
||||
// check for platform-specific properties in the defaults
|
||||
String platformExt = "." + Base.getPlatformName();
|
||||
int platformExtLength = platformExt.length();
|
||||
for (String key : table.keySet()) {
|
||||
if (key.endsWith(platformExt)) {
|
||||
// this is a key specific to a particular platform
|
||||
String actualKey = key.substring(0, key.length() - platformExtLength);
|
||||
String value = get(key);
|
||||
table.put(actualKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
// other things that have to be set explicitly for the defaults
|
||||
setColor("run.window.bgcolor", SystemColor.control);
|
||||
|
||||
// clone the hash table
|
||||
defaults = (HashMap<String, String>) table.clone();
|
||||
defaults = new PreferencesMap(table);
|
||||
}
|
||||
|
||||
|
||||
static protected void load(InputStream input) throws IOException {
|
||||
String[] lines = PApplet.loadStrings(input);
|
||||
for (String line : lines) {
|
||||
if ((line.length() == 0) ||
|
||||
(line.charAt(0) == '#')) continue;
|
||||
|
||||
// this won't properly handle = signs being in the text
|
||||
int equals = line.indexOf('=');
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
table.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public String get(String attribute) {
|
||||
return (String) table.get(attribute);
|
||||
return table.get(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public String getDefault(String attribute) {
|
||||
return (String) defaults.get(attribute);
|
||||
return defaults.get(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void set(String attribute, String value) {
|
||||
table.put(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public boolean getBoolean(String attribute) {
|
||||
String value = get(attribute);
|
||||
return (new Boolean(value)).booleanValue();
|
||||
return table.getBoolean(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void setBoolean(String attribute, boolean value) {
|
||||
set(attribute, value ? "true" : "false");
|
||||
table.putBoolean(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public int getInteger(String attribute) {
|
||||
return Integer.parseInt(get(attribute));
|
||||
}
|
||||
|
||||
|
||||
static public void setInteger(String key, int value) {
|
||||
set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
|
||||
static public Color getColor(String name) {
|
||||
Color parsed = null;
|
||||
String s = get(name);
|
||||
if ((s != null) && (s.indexOf("#") == 0)) {
|
||||
try {
|
||||
int v = Integer.parseInt(s.substring(1), 16);
|
||||
parsed = new Color(v);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
return PreferencesHelper.parseColor(get(name));
|
||||
}
|
||||
|
||||
|
||||
static public void setColor(String attr, Color what) {
|
||||
set(attr, "#" + PApplet.hex(what.getRGB() & 0xffffff, 6));
|
||||
static public void setColor(String attr, Color color) {
|
||||
PreferencesHelper.putColor(table, attr, color);
|
||||
}
|
||||
|
||||
|
||||
static public Font getFont(String attr) {
|
||||
boolean replace = false;
|
||||
String value = get(attr);
|
||||
if (value == null) {
|
||||
//System.out.println("reset 1");
|
||||
value = getDefault(attr);
|
||||
replace = true;
|
||||
}
|
||||
|
||||
String[] pieces = PApplet.split(value, ',');
|
||||
if (pieces.length != 3) {
|
||||
value = getDefault(attr);
|
||||
//System.out.println("reset 2 for " + attr);
|
||||
pieces = PApplet.split(value, ',');
|
||||
//PApplet.println(pieces);
|
||||
replace = true;
|
||||
}
|
||||
|
||||
String name = pieces[0];
|
||||
int style = Font.PLAIN; // equals zero
|
||||
if (pieces[1].indexOf("bold") != -1) {
|
||||
style |= Font.BOLD;
|
||||
}
|
||||
if (pieces[1].indexOf("italic") != -1) {
|
||||
style |= Font.ITALIC;
|
||||
}
|
||||
int size = PApplet.parseInt(pieces[2], 12);
|
||||
Font font = new Font(name, style, size);
|
||||
|
||||
// replace bad font with the default
|
||||
if (replace) {
|
||||
//System.out.println(attr + " > " + value);
|
||||
//setString(attr, font.getName() + ",plain," + font.getSize());
|
||||
Font font = PreferencesHelper.getFont(table, attr);
|
||||
if (font == null) {
|
||||
String value = getDefault(attr);
|
||||
set(attr, value);
|
||||
font = PreferencesHelper.getFont(table, attr);
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
static public SyntaxStyle getStyle(String what) {
|
||||
String str = get("editor." + what + ".style");
|
||||
String split[] = get("editor." + what + ".style").split(",");
|
||||
|
||||
StringTokenizer st = new StringTokenizer(str, ",");
|
||||
Color color = PreferencesHelper.parseColor(split[0]);
|
||||
|
||||
String s = st.nextToken();
|
||||
if (s.indexOf("#") == 0) s = s.substring(1);
|
||||
Color color = new Color(Integer.parseInt(s, 16));
|
||||
|
||||
s = st.nextToken();
|
||||
boolean bold = (s.indexOf("bold") != -1);
|
||||
boolean italic = (s.indexOf("italic") != -1);
|
||||
boolean underlined = (s.indexOf("underlined") != -1);
|
||||
String style = split[1];
|
||||
boolean bold = style.contains("bold");
|
||||
boolean italic = style.contains("italic");
|
||||
boolean underlined = style.contains("underlined");
|
||||
|
||||
return new SyntaxStyle(color, italic, bold, underlined);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import java.util.Random;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.core.PApplet;
|
||||
import processing.app.legacy.PApplet;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ public class UpdateCheck implements Runnable {
|
||||
try {
|
||||
String info;
|
||||
info = URLEncoder.encode(id + "\t" +
|
||||
PApplet.nf(Base.REVISION, 4) + "\t" +
|
||||
PApplet.nf(BaseNoGui.REVISION, 4) + "\t" +
|
||||
System.getProperty("java.version") + "\t" +
|
||||
System.getProperty("java.vendor") + "\t" +
|
||||
System.getProperty("os.name") + "\t" +
|
||||
@ -104,7 +104,7 @@ public class UpdateCheck implements Runnable {
|
||||
"would you like to visit the Arduino download page?");
|
||||
|
||||
if (base.activeEditor != null) {
|
||||
if (latest > Base.REVISION) {
|
||||
if (latest > BaseNoGui.REVISION) {
|
||||
Object[] options = { _("Yes"), _("No") };
|
||||
int result = JOptionPane.showOptionDialog(base.activeEditor,
|
||||
prompt,
|
||||
|
@ -1,573 +0,0 @@
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
|
||||
//import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* This code is placed here in anticipation of running the reference from an
|
||||
* internal web server that reads the docs from a zip file, instead of using
|
||||
* thousands of .html files on the disk, which is really inefficient.
|
||||
* <p/>
|
||||
* This is a very simple, multi-threaded HTTP server, originally based on
|
||||
* <a href="http://j.mp/6BQwpI">this</a> article on java.sun.com.
|
||||
*/
|
||||
public class WebServer implements HttpConstants {
|
||||
|
||||
/* Where worker threads stand idle */
|
||||
static Vector threads = new Vector();
|
||||
|
||||
/* the web server's virtual root */
|
||||
//static File root;
|
||||
|
||||
/* timeout on client connections */
|
||||
static int timeout = 10000;
|
||||
|
||||
/* max # worker threads */
|
||||
static int workers = 5;
|
||||
|
||||
// static PrintStream log = System.out;
|
||||
|
||||
|
||||
/*
|
||||
static void loadProps() throws IOException {
|
||||
File f = new File
|
||||
(System.getProperty("java.home")+File.separator+
|
||||
"lib"+File.separator+"www-server.properties");
|
||||
if (f.exists()) {
|
||||
InputStream is =new BufferedInputStream(new
|
||||
FileInputStream(f));
|
||||
props.load(is);
|
||||
is.close();
|
||||
String r = props.getProperty("root");
|
||||
if (r != null) {
|
||||
root = new File(r);
|
||||
if (!root.exists()) {
|
||||
throw new Error(root + " doesn't exist as server root");
|
||||
}
|
||||
}
|
||||
r = props.getProperty("timeout");
|
||||
if (r != null) {
|
||||
timeout = Integer.parseInt(r);
|
||||
}
|
||||
r = props.getProperty("workers");
|
||||
if (r != null) {
|
||||
workers = Integer.parseInt(r);
|
||||
}
|
||||
r = props.getProperty("log");
|
||||
if (r != null) {
|
||||
p("opening log file: " + r);
|
||||
log = new PrintStream(new BufferedOutputStream(
|
||||
new FileOutputStream(r)));
|
||||
}
|
||||
}
|
||||
|
||||
// if no properties were specified, choose defaults
|
||||
if (root == null) {
|
||||
root = new File(System.getProperty("user.dir"));
|
||||
}
|
||||
if (timeout <= 1000) {
|
||||
timeout = 5000;
|
||||
}
|
||||
if (workers < 25) {
|
||||
workers = 5;
|
||||
}
|
||||
if (log == null) {
|
||||
p("logging to stdout");
|
||||
log = System.out;
|
||||
}
|
||||
}
|
||||
|
||||
static void printProps() {
|
||||
p("root="+root);
|
||||
p("timeout="+timeout);
|
||||
p("workers="+workers);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/* print to stdout */
|
||||
// protected static void p(String s) {
|
||||
// System.out.println(s);
|
||||
// }
|
||||
|
||||
/* print to the log file */
|
||||
protected static void log(String s) {
|
||||
if (false) {
|
||||
System.out.println(s);
|
||||
}
|
||||
// synchronized (log) {
|
||||
// log.println(s);
|
||||
// log.flush();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//public static void main(String[] a) throws Exception {
|
||||
static public int launch(String zipPath) throws IOException {
|
||||
final ZipFile zip = new ZipFile(zipPath);
|
||||
final HashMap<String, ZipEntry> entries = new HashMap();
|
||||
Enumeration en = zip.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) en.nextElement();
|
||||
entries.put(entry.getName(), entry);
|
||||
}
|
||||
|
||||
// if (a.length > 0) {
|
||||
// port = Integer.parseInt(a[0]);
|
||||
// }
|
||||
// loadProps();
|
||||
// printProps();
|
||||
// start worker threads
|
||||
for (int i = 0; i < workers; ++i) {
|
||||
WebServerWorker w = new WebServerWorker(zip, entries);
|
||||
Thread t = new Thread(w, "Web Server Worker #" + i);
|
||||
t.start();
|
||||
threads.addElement(w);
|
||||
}
|
||||
|
||||
final int port = 8080;
|
||||
|
||||
//SwingUtilities.invokeLater(new Runnable() {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
ServerSocket ss = new ServerSocket(port);
|
||||
while (true) {
|
||||
Socket s = ss.accept();
|
||||
WebServerWorker w = null;
|
||||
synchronized (threads) {
|
||||
if (threads.isEmpty()) {
|
||||
WebServerWorker ws = new WebServerWorker(zip, entries);
|
||||
ws.setSocket(s);
|
||||
(new Thread(ws, "additional worker")).start();
|
||||
} else {
|
||||
w = (WebServerWorker) threads.elementAt(0);
|
||||
threads.removeElementAt(0);
|
||||
w.setSocket(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
new Thread(r).start();
|
||||
// });
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class WebServerWorker /*extends WebServer*/ implements HttpConstants, Runnable {
|
||||
ZipFile zip;
|
||||
HashMap<String, ZipEntry> entries;
|
||||
|
||||
final static int BUF_SIZE = 2048;
|
||||
|
||||
static final byte[] EOL = { (byte)'\r', (byte)'\n' };
|
||||
|
||||
/* buffer to use for requests */
|
||||
byte[] buf;
|
||||
/* Socket to client we're handling */
|
||||
private Socket s;
|
||||
|
||||
WebServerWorker(ZipFile zip, HashMap entries) {
|
||||
this.entries = entries;
|
||||
this.zip = zip;
|
||||
|
||||
buf = new byte[BUF_SIZE];
|
||||
s = null;
|
||||
}
|
||||
|
||||
// Worker() {
|
||||
// buf = new byte[BUF_SIZE];
|
||||
// s = null;
|
||||
// }
|
||||
//
|
||||
synchronized void setSocket(Socket s) {
|
||||
this.s = s;
|
||||
notify();
|
||||
}
|
||||
|
||||
public synchronized void run() {
|
||||
while(true) {
|
||||
if (s == null) {
|
||||
/* nothing to do */
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
/* should not happen */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
handleClient();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/* go back in wait queue if there's fewer
|
||||
* than numHandler connections.
|
||||
*/
|
||||
s = null;
|
||||
Vector pool = WebServer.threads;
|
||||
synchronized (pool) {
|
||||
if (pool.size() >= WebServer.workers) {
|
||||
/* too many threads, exit this one */
|
||||
return;
|
||||
} else {
|
||||
pool.addElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handleClient() throws IOException {
|
||||
InputStream is = new BufferedInputStream(s.getInputStream());
|
||||
PrintStream ps = new PrintStream(s.getOutputStream());
|
||||
// we will only block in read for this many milliseconds
|
||||
// before we fail with java.io.InterruptedIOException,
|
||||
// at which point we will abandon the connection.
|
||||
s.setSoTimeout(WebServer.timeout);
|
||||
s.setTcpNoDelay(true);
|
||||
// zero out the buffer from last time
|
||||
for (int i = 0; i < BUF_SIZE; i++) {
|
||||
buf[i] = 0;
|
||||
}
|
||||
try {
|
||||
// We only support HTTP GET/HEAD, and don't support any fancy HTTP
|
||||
// options, so we're only interested really in the first line.
|
||||
int nread = 0, r = 0;
|
||||
|
||||
outerloop:
|
||||
while (nread < BUF_SIZE) {
|
||||
r = is.read(buf, nread, BUF_SIZE - nread);
|
||||
if (r == -1) {
|
||||
return; // EOF
|
||||
}
|
||||
int i = nread;
|
||||
nread += r;
|
||||
for (; i < nread; i++) {
|
||||
if (buf[i] == (byte)'\n' || buf[i] == (byte)'\r') {
|
||||
break outerloop; // read one line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* are we doing a GET or just a HEAD */
|
||||
boolean doingGet;
|
||||
/* beginning of file name */
|
||||
int index;
|
||||
if (buf[0] == (byte)'G' &&
|
||||
buf[1] == (byte)'E' &&
|
||||
buf[2] == (byte)'T' &&
|
||||
buf[3] == (byte)' ') {
|
||||
doingGet = true;
|
||||
index = 4;
|
||||
} else if (buf[0] == (byte)'H' &&
|
||||
buf[1] == (byte)'E' &&
|
||||
buf[2] == (byte)'A' &&
|
||||
buf[3] == (byte)'D' &&
|
||||
buf[4] == (byte)' ') {
|
||||
doingGet = false;
|
||||
index = 5;
|
||||
} else {
|
||||
/* we don't support this method */
|
||||
ps.print("HTTP/1.0 " + HTTP_BAD_METHOD +
|
||||
" unsupported method type: ");
|
||||
ps.write(buf, 0, 5);
|
||||
ps.write(EOL);
|
||||
ps.flush();
|
||||
s.close();
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
/* find the file name, from:
|
||||
* GET /foo/bar.html HTTP/1.0
|
||||
* extract "/foo/bar.html"
|
||||
*/
|
||||
for (i = index; i < nread; i++) {
|
||||
if (buf[i] == (byte)' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String fname = new String(buf, index, i-index);
|
||||
// get the zip entry, remove the front slash
|
||||
ZipEntry entry = entries.get(fname.substring(1));
|
||||
//System.out.println(fname + " " + entry);
|
||||
boolean ok = printHeaders(entry, ps);
|
||||
if (entry != null) {
|
||||
InputStream stream = zip.getInputStream(entry);
|
||||
if (doingGet && ok) {
|
||||
sendFile(stream, ps);
|
||||
}
|
||||
} else {
|
||||
send404(ps);
|
||||
}
|
||||
/*
|
||||
String fname =
|
||||
(new String(buf, 0, index, i-index)).replace('/', File.separatorChar);
|
||||
if (fname.startsWith(File.separator)) {
|
||||
fname = fname.substring(1);
|
||||
}
|
||||
File targ = new File(WebServer.root, fname);
|
||||
if (targ.isDirectory()) {
|
||||
File ind = new File(targ, "index.html");
|
||||
if (ind.exists()) {
|
||||
targ = ind;
|
||||
}
|
||||
}
|
||||
boolean OK = printHeaders(targ, ps);
|
||||
if (doingGet) {
|
||||
if (OK) {
|
||||
sendFile(targ, ps);
|
||||
} else {
|
||||
send404(targ, ps);
|
||||
}
|
||||
}
|
||||
*/
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean printHeaders(ZipEntry targ, PrintStream ps) throws IOException {
|
||||
boolean ret = false;
|
||||
int rCode = 0;
|
||||
if (targ == null) {
|
||||
rCode = HTTP_NOT_FOUND;
|
||||
ps.print("HTTP/1.0 " + HTTP_NOT_FOUND + " Not Found");
|
||||
ps.write(EOL);
|
||||
ret = false;
|
||||
} else {
|
||||
rCode = HTTP_OK;
|
||||
ps.print("HTTP/1.0 " + HTTP_OK + " OK");
|
||||
ps.write(EOL);
|
||||
ret = true;
|
||||
}
|
||||
if (targ != null) {
|
||||
WebServer.log("From " +s.getInetAddress().getHostAddress()+": GET " + targ.getName()+" --> "+rCode);
|
||||
}
|
||||
ps.print("Server: Processing Documentation Server");
|
||||
ps.write(EOL);
|
||||
ps.print("Date: " + (new Date()));
|
||||
ps.write(EOL);
|
||||
if (ret) {
|
||||
if (!targ.isDirectory()) {
|
||||
ps.print("Content-length: " + targ.getSize());
|
||||
ps.write(EOL);
|
||||
ps.print("Last Modified: " + new Date(targ.getTime()));
|
||||
ps.write(EOL);
|
||||
String name = targ.getName();
|
||||
int ind = name.lastIndexOf('.');
|
||||
String ct = null;
|
||||
if (ind > 0) {
|
||||
ct = (String) map.get(name.substring(ind));
|
||||
}
|
||||
if (ct == null) {
|
||||
//System.err.println("unknown content type " + name.substring(ind));
|
||||
ct = "application/x-unknown-content-type";
|
||||
}
|
||||
ps.print("Content-type: " + ct);
|
||||
ps.write(EOL);
|
||||
} else {
|
||||
ps.print("Content-type: text/html");
|
||||
ps.write(EOL);
|
||||
}
|
||||
}
|
||||
ps.write(EOL); // adding another newline here [fry]
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
boolean printHeaders(File targ, PrintStream ps) throws IOException {
|
||||
boolean ret = false;
|
||||
int rCode = 0;
|
||||
if (!targ.exists()) {
|
||||
rCode = HTTP_NOT_FOUND;
|
||||
ps.print("HTTP/1.0 " + HTTP_NOT_FOUND + " Not Found");
|
||||
ps.write(EOL);
|
||||
ret = false;
|
||||
} else {
|
||||
rCode = HTTP_OK;
|
||||
ps.print("HTTP/1.0 " + HTTP_OK+" OK");
|
||||
ps.write(EOL);
|
||||
ret = true;
|
||||
}
|
||||
WebServer.log("From " +s.getInetAddress().getHostAddress()+": GET " + targ.getAbsolutePath()+"-->"+rCode);
|
||||
ps.print("Server: Simple java");
|
||||
ps.write(EOL);
|
||||
ps.print("Date: " + (new Date()));
|
||||
ps.write(EOL);
|
||||
if (ret) {
|
||||
if (!targ.isDirectory()) {
|
||||
ps.print("Content-length: " + targ.length());
|
||||
ps.write(EOL);
|
||||
ps.print("Last Modified: " + new Date(targ.lastModified()));
|
||||
ps.write(EOL);
|
||||
String name = targ.getName();
|
||||
int ind = name.lastIndexOf('.');
|
||||
String ct = null;
|
||||
if (ind > 0) {
|
||||
ct = (String) map.get(name.substring(ind));
|
||||
}
|
||||
if (ct == null) {
|
||||
ct = "unknown/unknown";
|
||||
}
|
||||
ps.print("Content-type: " + ct);
|
||||
ps.write(EOL);
|
||||
} else {
|
||||
ps.print("Content-type: text/html");
|
||||
ps.write(EOL);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void send404(PrintStream ps) throws IOException {
|
||||
ps.write(EOL);
|
||||
ps.write(EOL);
|
||||
ps.print("<html><body><h1>404 Not Found</h1>"+
|
||||
"The requested resource was not found.</body></html>");
|
||||
ps.write(EOL);
|
||||
ps.write(EOL);
|
||||
}
|
||||
|
||||
|
||||
void sendFile(File targ, PrintStream ps) throws IOException {
|
||||
InputStream is = null;
|
||||
ps.write(EOL);
|
||||
if (targ.isDirectory()) {
|
||||
listDirectory(targ, ps);
|
||||
return;
|
||||
} else {
|
||||
is = new FileInputStream(targ.getAbsolutePath());
|
||||
}
|
||||
sendFile(is, ps);
|
||||
}
|
||||
|
||||
|
||||
void sendFile(InputStream is, PrintStream ps) throws IOException {
|
||||
try {
|
||||
int n;
|
||||
while ((n = is.read(buf)) > 0) {
|
||||
ps.write(buf, 0, n);
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
/* mapping of file extensions to content-types */
|
||||
static java.util.Hashtable map = new java.util.Hashtable();
|
||||
|
||||
static {
|
||||
fillMap();
|
||||
}
|
||||
static void setSuffix(String k, String v) {
|
||||
map.put(k, v);
|
||||
}
|
||||
|
||||
static void fillMap() {
|
||||
setSuffix("", "content/unknown");
|
||||
|
||||
setSuffix(".uu", "application/octet-stream");
|
||||
setSuffix(".exe", "application/octet-stream");
|
||||
setSuffix(".ps", "application/postscript");
|
||||
setSuffix(".zip", "application/zip");
|
||||
setSuffix(".sh", "application/x-shar");
|
||||
setSuffix(".tar", "application/x-tar");
|
||||
setSuffix(".snd", "audio/basic");
|
||||
setSuffix(".au", "audio/basic");
|
||||
setSuffix(".wav", "audio/x-wav");
|
||||
|
||||
setSuffix(".gif", "image/gif");
|
||||
setSuffix(".jpg", "image/jpeg");
|
||||
setSuffix(".jpeg", "image/jpeg");
|
||||
|
||||
setSuffix(".htm", "text/html");
|
||||
setSuffix(".html", "text/html");
|
||||
setSuffix(".css", "text/css");
|
||||
setSuffix(".java", "text/javascript");
|
||||
|
||||
setSuffix(".txt", "text/plain");
|
||||
setSuffix(".java", "text/plain");
|
||||
|
||||
setSuffix(".c", "text/plain");
|
||||
setSuffix(".cc", "text/plain");
|
||||
setSuffix(".c++", "text/plain");
|
||||
setSuffix(".h", "text/plain");
|
||||
setSuffix(".pl", "text/plain");
|
||||
}
|
||||
|
||||
void listDirectory(File dir, PrintStream ps) throws IOException {
|
||||
ps.println("<TITLE>Directory listing</TITLE><P>\n");
|
||||
ps.println("<A HREF=\"..\">Parent Directory</A><BR>\n");
|
||||
String[] list = dir.list();
|
||||
for (int i = 0; list != null && i < list.length; i++) {
|
||||
File f = new File(dir, list[i]);
|
||||
if (f.isDirectory()) {
|
||||
ps.println("<A HREF=\""+list[i]+"/\">"+list[i]+"/</A><BR>");
|
||||
} else {
|
||||
ps.println("<A HREF=\""+list[i]+"\">"+list[i]+"</A><BR");
|
||||
}
|
||||
}
|
||||
ps.println("<P><HR><BR><I>" + (new Date()) + "</I>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
interface HttpConstants {
|
||||
/** 2XX: generally "OK" */
|
||||
public static final int HTTP_OK = 200;
|
||||
public static final int HTTP_CREATED = 201;
|
||||
public static final int HTTP_ACCEPTED = 202;
|
||||
public static final int HTTP_NOT_AUTHORITATIVE = 203;
|
||||
public static final int HTTP_NO_CONTENT = 204;
|
||||
public static final int HTTP_RESET = 205;
|
||||
public static final int HTTP_PARTIAL = 206;
|
||||
|
||||
/** 3XX: relocation/redirect */
|
||||
public static final int HTTP_MULT_CHOICE = 300;
|
||||
public static final int HTTP_MOVED_PERM = 301;
|
||||
public static final int HTTP_MOVED_TEMP = 302;
|
||||
public static final int HTTP_SEE_OTHER = 303;
|
||||
public static final int HTTP_NOT_MODIFIED = 304;
|
||||
public static final int HTTP_USE_PROXY = 305;
|
||||
|
||||
/** 4XX: client error */
|
||||
public static final int HTTP_BAD_REQUEST = 400;
|
||||
public static final int HTTP_UNAUTHORIZED = 401;
|
||||
public static final int HTTP_PAYMENT_REQUIRED = 402;
|
||||
public static final int HTTP_FORBIDDEN = 403;
|
||||
public static final int HTTP_NOT_FOUND = 404;
|
||||
public static final int HTTP_BAD_METHOD = 405;
|
||||
public static final int HTTP_NOT_ACCEPTABLE = 406;
|
||||
public static final int HTTP_PROXY_AUTH = 407;
|
||||
public static final int HTTP_CLIENT_TIMEOUT = 408;
|
||||
public static final int HTTP_CONFLICT = 409;
|
||||
public static final int HTTP_GONE = 410;
|
||||
public static final int HTTP_LENGTH_REQUIRED = 411;
|
||||
public static final int HTTP_PRECON_FAILED = 412;
|
||||
public static final int HTTP_ENTITY_TOO_LARGE = 413;
|
||||
public static final int HTTP_REQ_TOO_LONG = 414;
|
||||
public static final int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
|
||||
/** 5XX: server error */
|
||||
public static final int HTTP_SERVER_ERROR = 500;
|
||||
public static final int HTTP_INTERNAL_ERROR = 501;
|
||||
public static final int HTTP_BAD_GATEWAY = 502;
|
||||
public static final int HTTP_UNAVAILABLE = 503;
|
||||
public static final int HTTP_GATEWAY_TIMEOUT = 504;
|
||||
public static final int HTTP_VERSION = 505;
|
||||
}
|
92
app/src/processing/app/debug/TextAreaFIFO.java
Normal file
92
app/src/processing/app/debug/TextAreaFIFO.java
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright (c) 2014 Paul Stoffregen <paul@pjrc.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
// adapted from https://community.oracle.com/thread/1479784
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
public class TextAreaFIFO extends JTextArea implements DocumentListener {
|
||||
private int maxChars;
|
||||
private int trimMaxChars;
|
||||
|
||||
private int updateCount; // limit how often we trim the document
|
||||
|
||||
private boolean doTrim;
|
||||
|
||||
public TextAreaFIFO(int max) {
|
||||
maxChars = max;
|
||||
trimMaxChars = max / 2;
|
||||
updateCount = 0;
|
||||
doTrim = true;
|
||||
getDocument().addDocumentListener(this);
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (++updateCount > 150 && doTrim) {
|
||||
updateCount = 0;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
trimDocument();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
}
|
||||
|
||||
public void trimDocument() {
|
||||
int len = 0;
|
||||
len = getDocument().getLength();
|
||||
if (len > trimMaxChars) {
|
||||
int n = len - trimMaxChars;
|
||||
//System.out.println("trimDocument: remove " + n + " chars");
|
||||
try {
|
||||
getDocument().remove(0, n);
|
||||
} catch (BadLocationException ble) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void appendNoTrim(String s) {
|
||||
int free = maxChars - getDocument().getLength();
|
||||
if (free <= 0)
|
||||
return;
|
||||
if (s.length() > free)
|
||||
append(s.substring(0, free));
|
||||
else
|
||||
append(s);
|
||||
doTrim = false;
|
||||
}
|
||||
|
||||
public void appendTrim(String str) {
|
||||
append(str);
|
||||
doTrim = true;
|
||||
}
|
||||
}
|
49
app/src/processing/app/helpers/GUIUserNotifier.java
Normal file
49
app/src/processing/app/helpers/GUIUserNotifier.java
Normal file
@ -0,0 +1,49 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.Frame;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class GUIUserNotifier extends UserNotifier {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
if (title == null) title = _("Error");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
System.exit(exit_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* "No cookie for you" type messages. Nothing fatal or all that
|
||||
* much of a bummer, but something to notify the user about.
|
||||
*/
|
||||
public void showMessage(String title, String message) {
|
||||
if (title == null) title = _("Message");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-fatal error message with optional stack trace side dish.
|
||||
*/
|
||||
public void showWarning(String title, String message, Exception e) {
|
||||
if (title == null) title = _("Warning");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -50,7 +50,7 @@ public class ThinkDifferent implements ApplicationListener {
|
||||
private Base base;
|
||||
|
||||
|
||||
static protected void init(Base base) {
|
||||
static public void init(Base base) {
|
||||
if (application == null) {
|
||||
//application = new com.apple.eawt.Application();
|
||||
application = com.apple.eawt.Application.getApplication();
|
||||
|
@ -25,6 +25,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.packages.Library;
|
||||
|
||||
import java.io.*;
|
||||
@ -84,7 +85,7 @@ public class PdeKeywords extends CTokenMarker {
|
||||
// in case there's any garbage on the line
|
||||
//if (line.trim().length() == 0) continue;
|
||||
|
||||
String pieces[] = processing.core.PApplet.split(line, '\t');
|
||||
String pieces[] = PApplet.split(line, '\t');
|
||||
if (pieces.length >= 2) {
|
||||
//int tab = line.indexOf('\t');
|
||||
// any line with no tab is ignored
|
||||
|
@ -25,6 +25,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
|
||||
public class PdeTextAreaDefaults extends TextAreaDefaults {
|
||||
@ -35,7 +36,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
|
||||
//inputHandler.addDefaultKeyBindings(); // 0122
|
||||
|
||||
// use option on mac for text edit controls that are ctrl on windows/linux
|
||||
String mod = Base.isMacOS() ? "A" : "C";
|
||||
String mod = OSUtils.isMacOS() ? "A" : "C";
|
||||
|
||||
// right now, ctrl-up/down is select up/down, but mod should be
|
||||
// used instead, because the mac expects it to be option(alt)
|
||||
@ -94,7 +95,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
|
||||
inputHandler.addKeyBinding("CS+END", InputHandler.SELECT_DOC_END);
|
||||
}
|
||||
|
||||
if (Base.isMacOS()) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
inputHandler.addKeyBinding("M+LEFT", InputHandler.HOME);
|
||||
inputHandler.addKeyBinding("M+RIGHT", InputHandler.END);
|
||||
inputHandler.addKeyBinding("MS+LEFT", InputHandler.SELECT_HOME); // 0122
|
||||
|
@ -131,7 +131,6 @@ public class SyntaxUtilities
|
||||
Font defaultFont = gfx.getFont();
|
||||
Color defaultColor = gfx.getColor();
|
||||
|
||||
int offset = 0;
|
||||
for(;;)
|
||||
{
|
||||
byte id = tokens.id;
|
||||
@ -155,7 +154,6 @@ public class SyntaxUtilities
|
||||
else
|
||||
x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0);
|
||||
line.offset += length;
|
||||
offset += length;
|
||||
|
||||
tokens = tokens.next;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
package processing.app.tools;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.core.PApplet;
|
||||
import processing.app.legacy.PApplet;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.*;
|
||||
@ -639,7 +639,6 @@ public class AutoFormat implements Tool {
|
||||
case '\'':
|
||||
string[j++] = c;
|
||||
cc = getchr();
|
||||
int count = 0;
|
||||
while(cc != c && EOF == 0)
|
||||
{
|
||||
// max. length of line should be 256
|
||||
|
@ -1,609 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2006-08 Ben Fry and Casey Reas
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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.tools;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.core.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.text.*;
|
||||
|
||||
|
||||
/**
|
||||
* Color selector tool for the Tools menu.
|
||||
* <p/>
|
||||
* Using the keyboard shortcuts, you can copy/paste the values for the
|
||||
* colors and paste them into your program. We didn't do any sort of
|
||||
* auto-insert of colorMode() or fill() or stroke() code cuz we couldn't
|
||||
* decide on a good way to do this.. your contributions welcome).
|
||||
*/
|
||||
public class ColorSelector implements Tool, DocumentListener {
|
||||
|
||||
Editor editor;
|
||||
JFrame frame;
|
||||
|
||||
int hue, saturation, brightness; // range 360, 100, 100
|
||||
int red, green, blue; // range 256, 256, 256
|
||||
|
||||
ColorRange range;
|
||||
ColorSlider slider;
|
||||
|
||||
JTextField hueField, saturationField, brightnessField;
|
||||
JTextField redField, greenField, blueField;
|
||||
|
||||
JTextField hexField;
|
||||
|
||||
JPanel colorPanel;
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Color Selector";
|
||||
}
|
||||
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
frame = new JFrame("Color Selector");
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
|
||||
Box box = Box.createHorizontalBox();
|
||||
box.setBorder(new EmptyBorder(12, 12, 12, 12));
|
||||
|
||||
range = new ColorRange();
|
||||
range.init();
|
||||
Box rangeBox = new Box(BoxLayout.Y_AXIS);
|
||||
rangeBox.setAlignmentY(0);
|
||||
rangeBox.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
||||
rangeBox.add(range);
|
||||
box.add(rangeBox);
|
||||
box.add(Box.createHorizontalStrut(10));
|
||||
|
||||
slider = new ColorSlider();
|
||||
slider.init();
|
||||
Box sliderBox = new Box(BoxLayout.Y_AXIS);
|
||||
sliderBox.setAlignmentY(0);
|
||||
sliderBox.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
||||
sliderBox.add(slider);
|
||||
box.add(sliderBox);
|
||||
box.add(Box.createHorizontalStrut(10));
|
||||
|
||||
box.add(createColorFields());
|
||||
box.add(Box.createHorizontalStrut(10));
|
||||
|
||||
frame.getContentPane().add(box, BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setResizable(false);
|
||||
|
||||
// these don't help either.. they fix the component size but
|
||||
// leave a gap where the component is located
|
||||
//range.setSize(256, 256);
|
||||
//slider.setSize(256, 20);
|
||||
|
||||
Dimension size = frame.getSize();
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
frame.setLocation((screen.width - size.width) / 2,
|
||||
(screen.height - size.height) / 2);
|
||||
|
||||
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
frame.setVisible(false);
|
||||
}
|
||||
});
|
||||
Base.registerWindowCloseKeys(frame.getRootPane(), new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
frame.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
Base.setIcon(frame);
|
||||
|
||||
hueField.getDocument().addDocumentListener(this);
|
||||
saturationField.getDocument().addDocumentListener(this);
|
||||
brightnessField.getDocument().addDocumentListener(this);
|
||||
redField.getDocument().addDocumentListener(this);
|
||||
greenField.getDocument().addDocumentListener(this);
|
||||
blueField.getDocument().addDocumentListener(this);
|
||||
hexField.getDocument().addDocumentListener(this);
|
||||
|
||||
hexField.setText("FFFFFF");
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
// You've got to be f--ing kidding me.. why did the following line
|
||||
// get deprecated for the pile of s-- that follows it?
|
||||
//frame.setCursor(Cursor.CROSSHAIR_CURSOR);
|
||||
frame.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
}
|
||||
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
//System.out.println("changed");
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
//System.out.println("remove");
|
||||
}
|
||||
|
||||
|
||||
boolean updating;
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (updating) return; // don't update forever recursively
|
||||
updating = true;
|
||||
|
||||
Document doc = e.getDocument();
|
||||
if (doc == hueField.getDocument()) {
|
||||
hue = bounded(hue, hueField, 359);
|
||||
updateRGB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == saturationField.getDocument()) {
|
||||
saturation = bounded(saturation, saturationField, 99);
|
||||
updateRGB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == brightnessField.getDocument()) {
|
||||
brightness = bounded(brightness, brightnessField, 99);
|
||||
updateRGB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == redField.getDocument()) {
|
||||
red = bounded(red, redField, 255);
|
||||
updateHSB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == greenField.getDocument()) {
|
||||
green = bounded(green, greenField, 255);
|
||||
updateHSB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == blueField.getDocument()) {
|
||||
blue = bounded(blue, blueField, 255);
|
||||
updateHSB();
|
||||
updateHex();
|
||||
|
||||
} else if (doc == hexField.getDocument()) {
|
||||
String str = hexField.getText();
|
||||
while (str.length() < 6) {
|
||||
str += "0";
|
||||
}
|
||||
if (str.length() > 6) {
|
||||
str = str.substring(0, 6);
|
||||
}
|
||||
updateRGB2(Integer.parseInt(str, 16));
|
||||
updateHSB();
|
||||
}
|
||||
range.redraw();
|
||||
slider.redraw();
|
||||
colorPanel.repaint();
|
||||
updating = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the RGB values based on the current HSB values.
|
||||
*/
|
||||
protected void updateRGB() {
|
||||
int rgb = Color.HSBtoRGB((float)hue / 359f,
|
||||
(float)saturation / 99f,
|
||||
(float)brightness / 99f);
|
||||
updateRGB2(rgb);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the RGB values based on a calculated ARGB int.
|
||||
* Used by both updateRGB() to set the color from the HSB values,
|
||||
* and by updateHex(), to unpack the hex colors and assign them.
|
||||
*/
|
||||
protected void updateRGB2(int rgb) {
|
||||
red = (rgb >> 16) & 0xff;
|
||||
green = (rgb >> 8) & 0xff;
|
||||
blue = rgb & 0xff;
|
||||
|
||||
redField.setText(String.valueOf(red));
|
||||
greenField.setText(String.valueOf(green));
|
||||
blueField.setText(String.valueOf(blue));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the HSB values based on the current RGB values.
|
||||
*/
|
||||
protected void updateHSB() {
|
||||
float hsb[] = new float[3];
|
||||
Color.RGBtoHSB(red, green, blue, hsb);
|
||||
|
||||
hue = (int) (hsb[0] * 359.0f);
|
||||
saturation = (int) (hsb[1] * 99.0f);
|
||||
brightness = (int) (hsb[2] * 99.0f);
|
||||
|
||||
hueField.setText(String.valueOf(hue));
|
||||
saturationField.setText(String.valueOf(saturation));
|
||||
brightnessField.setText(String.valueOf(brightness));
|
||||
}
|
||||
|
||||
|
||||
protected void updateHex() {
|
||||
hexField.setText(PApplet.hex(red, 2) +
|
||||
PApplet.hex(green, 2) +
|
||||
PApplet.hex(blue, 2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the bounded value for a specific range. If the value is outside
|
||||
* the max, you can't edit right away, so just act as if it's already
|
||||
* been bounded and return the bounded value, then fire an event to set
|
||||
* it to the value that was just returned.
|
||||
*/
|
||||
protected int bounded(int current, final JTextField field, final int max) {
|
||||
String text = field.getText();
|
||||
if (text.length() == 0) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
int value = Integer.parseInt(text);
|
||||
if (value > max) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
field.setText(String.valueOf(max));
|
||||
}
|
||||
});
|
||||
return max;
|
||||
}
|
||||
return value;
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
return current; // should not be reachable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Container createColorFields() {
|
||||
Box box = Box.createVerticalBox();
|
||||
box.setAlignmentY(0);
|
||||
|
||||
colorPanel = new JPanel() {
|
||||
public void paintComponent(Graphics g) {
|
||||
g.setColor(new Color(red, green, blue));
|
||||
Dimension size = getSize();
|
||||
g.fillRect(0, 0, size.width, size.height);
|
||||
}
|
||||
};
|
||||
colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
||||
Dimension dim = new Dimension(60, 40);
|
||||
colorPanel.setMinimumSize(dim);
|
||||
//colorPanel.setMaximumSize(dim);
|
||||
//colorPanel.setPreferredSize(dim);
|
||||
box.add(colorPanel);
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
|
||||
Box row;
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("H:"));
|
||||
row.add(hueField = new NumberField(4, false));
|
||||
row.add(new JLabel(" \u00B0")); // degree symbol
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(5));
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("S:"));
|
||||
row.add(saturationField = new NumberField(4, false));
|
||||
row.add(new JLabel(" %"));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(5));
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("B:"));
|
||||
row.add(brightnessField = new NumberField(4, false));
|
||||
row.add(new JLabel(" %"));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
|
||||
//
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("R:"));
|
||||
row.add(redField = new NumberField(4, false));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(5));
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("G:"));
|
||||
row.add(greenField = new NumberField(4, false));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(5));
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("B:"));
|
||||
row.add(blueField = new NumberField(4, false));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
|
||||
//
|
||||
|
||||
row = Box.createHorizontalBox();
|
||||
row.add(createFixedLabel("#"));
|
||||
row.add(hexField = new NumberField(5, true));
|
||||
row.add(Box.createHorizontalGlue());
|
||||
box.add(row);
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
|
||||
box.add(Box.createVerticalGlue());
|
||||
return box;
|
||||
}
|
||||
|
||||
|
||||
int labelH;
|
||||
|
||||
/**
|
||||
* return a label of a fixed width
|
||||
*/
|
||||
protected JLabel createFixedLabel(String title) {
|
||||
JLabel label = new JLabel(title);
|
||||
if (labelH == 0) {
|
||||
labelH = label.getPreferredSize().height;
|
||||
}
|
||||
Dimension dim = new Dimension(20, labelH);
|
||||
label.setPreferredSize(dim);
|
||||
label.setMinimumSize(dim);
|
||||
label.setMaximumSize(dim);
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
public class ColorRange extends PApplet {
|
||||
|
||||
static final int WIDE = 256;
|
||||
static final int HIGH = 256;
|
||||
|
||||
int lastX, lastY;
|
||||
|
||||
|
||||
public void setup() {
|
||||
size(WIDE, HIGH, P3D);
|
||||
noLoop();
|
||||
|
||||
colorMode(HSB, 360, 256, 256);
|
||||
noFill();
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if ((g == null) || (g.pixels == null)) return;
|
||||
if ((width != WIDE) || (height < HIGH)) {
|
||||
//System.out.println("bad size " + width + " " + height);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (int j = 0; j < 256; j++) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
g.pixels[index++] = color(hue, i, 255 - j);
|
||||
}
|
||||
}
|
||||
|
||||
stroke((brightness > 50) ? 0 : 255);
|
||||
rect(lastX, lastY, 9, 9);
|
||||
}
|
||||
|
||||
public void mousePressed() {
|
||||
updateMouse();
|
||||
}
|
||||
|
||||
public void mouseDragged() {
|
||||
updateMouse();
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
if ((mouseX >= 0) && (mouseX < 256) &&
|
||||
(mouseY >= 0) && (mouseY < 256)) {
|
||||
int nsaturation = (int) (100 * (mouseX / 255.0f));
|
||||
int nbrightness = 100 - ((int) (100 * (mouseY / 255.0f)));
|
||||
saturationField.setText(String.valueOf(nsaturation));
|
||||
brightnessField.setText(String.valueOf(nbrightness));
|
||||
|
||||
lastX = mouseX;
|
||||
lastY = mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public void keyPressed() {
|
||||
if (key == ESC) {
|
||||
ColorSelector.this.frame.setVisible(false);
|
||||
// don't quit out of processing
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1006
|
||||
key = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ColorSlider extends PApplet {
|
||||
|
||||
static final int WIDE = 20;
|
||||
static final int HIGH = 256;
|
||||
|
||||
public void setup() {
|
||||
size(WIDE, HIGH, P3D);
|
||||
colorMode(HSB, 255, 100, 100);
|
||||
noLoop();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if ((g == null) || (g.pixels == null)) return;
|
||||
if ((width != WIDE) || (height < HIGH)) {
|
||||
//System.out.println("bad size " + width + " " + height);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
int sel = 255 - (int) (255 * (hue / 359f));
|
||||
for (int j = 0; j < 256; j++) {
|
||||
int c = color(255 - j, 100, 100);
|
||||
if (j == sel) c = 0xFF000000;
|
||||
for (int i = 0; i < WIDE; i++) {
|
||||
g.pixels[index++] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed() {
|
||||
updateMouse();
|
||||
}
|
||||
|
||||
public void mouseDragged() {
|
||||
updateMouse();
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
if ((mouseX >= 0) && (mouseX < 256) &&
|
||||
(mouseY >= 0) && (mouseY < 256)) {
|
||||
int nhue = 359 - (int) (359 * (mouseY / 255.0f));
|
||||
hueField.setText(String.valueOf(nhue));
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(WIDE, HIGH);
|
||||
}
|
||||
|
||||
public void keyPressed() {
|
||||
if (key == ESC) {
|
||||
ColorSelector.this.frame.setVisible(false);
|
||||
// don't quit out of processing
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1006
|
||||
key = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extension of JTextField that only allows numbers
|
||||
*/
|
||||
class NumberField extends JTextField {
|
||||
|
||||
public boolean allowHex;
|
||||
|
||||
public NumberField(int cols, boolean allowHex) {
|
||||
super(cols);
|
||||
this.allowHex = allowHex;
|
||||
}
|
||||
|
||||
protected Document createDefaultModel() {
|
||||
return new NumberDocument(this);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
if (!allowHex) {
|
||||
return new Dimension(45, super.getPreferredSize().height);
|
||||
}
|
||||
return super.getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Document model to go with JTextField that only allows numbers.
|
||||
*/
|
||||
class NumberDocument extends PlainDocument {
|
||||
|
||||
NumberField parentField;
|
||||
|
||||
public NumberDocument(NumberField parentField) {
|
||||
this.parentField = parentField;
|
||||
//System.out.println("setting parent to " + parentSelector);
|
||||
}
|
||||
|
||||
public void insertString(int offs, String str, AttributeSet a)
|
||||
throws BadLocationException {
|
||||
|
||||
if (str == null) return;
|
||||
|
||||
char chars[] = str.toCharArray();
|
||||
int charCount = 0;
|
||||
// remove any non-digit chars
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
boolean ok = Character.isDigit(chars[i]);
|
||||
if (parentField.allowHex) {
|
||||
if ((chars[i] >= 'A') && (chars[i] <= 'F')) ok = true;
|
||||
if ((chars[i] >= 'a') && (chars[i] <= 'f')) ok = true;
|
||||
}
|
||||
if (ok) {
|
||||
if (charCount != i) { // shift if necessary
|
||||
chars[charCount] = chars[i];
|
||||
}
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
super.insertString(offs, new String(chars, 0, charCount), a);
|
||||
// can't call any sort of methods on the enclosing class here
|
||||
// seems to have something to do with how Document objects are set up
|
||||
}
|
||||
}
|
||||
}
|
@ -1,813 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-10 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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.tools;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.core.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
|
||||
/**
|
||||
* GUI tool for font creation heaven/hell.
|
||||
*/
|
||||
public class CreateFont extends JFrame implements Tool {
|
||||
Editor editor;
|
||||
//Sketch sketch;
|
||||
|
||||
Dimension windowSize;
|
||||
|
||||
JList fontSelector;
|
||||
JTextField sizeSelector;
|
||||
JButton charsetButton;
|
||||
JCheckBox smoothBox;
|
||||
JComponent sample;
|
||||
JButton okButton;
|
||||
JTextField filenameField;
|
||||
|
||||
HashMap<String,Font> table;
|
||||
boolean smooth = true;
|
||||
|
||||
Font font;
|
||||
|
||||
String[] list;
|
||||
int selection = -1;
|
||||
|
||||
CharacterSelector charSelector;
|
||||
|
||||
|
||||
public CreateFont() {
|
||||
super("Create Font");
|
||||
}
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Create Font...";
|
||||
}
|
||||
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
Container paine = getContentPane();
|
||||
paine.setLayout(new BorderLayout()); //10, 10));
|
||||
|
||||
JPanel pain = new JPanel();
|
||||
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
|
||||
paine.add(pain, BorderLayout.CENTER);
|
||||
|
||||
pain.setLayout(new BoxLayout(pain, BoxLayout.Y_AXIS));
|
||||
|
||||
String labelText =
|
||||
"Use this tool to create bitmap fonts for your program.\n" +
|
||||
"Select a font and size, and click 'OK' to generate the font.\n" +
|
||||
"It will be added to the data folder of the current sketch.";
|
||||
|
||||
JTextArea textarea = new JTextArea(labelText);
|
||||
textarea.setBorder(new EmptyBorder(10, 10, 20, 10));
|
||||
textarea.setBackground(null);
|
||||
textarea.setEditable(false);
|
||||
textarea.setHighlighter(null);
|
||||
textarea.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
pain.add(textarea);
|
||||
|
||||
// don't care about families starting with . or #
|
||||
// also ignore dialog, dialoginput, monospaced, serif, sansserif
|
||||
|
||||
// getFontList is deprecated in 1.4, so this has to be used
|
||||
GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
|
||||
Font fonts[] = ge.getAllFonts();
|
||||
|
||||
String flist[] = new String[fonts.length];
|
||||
table = new HashMap<String,Font>();
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i < fonts.length; i++) {
|
||||
//String psname = fonts[i].getPSName();
|
||||
//if (psname == null) System.err.println("ps name is null");
|
||||
|
||||
flist[index++] = fonts[i].getPSName();
|
||||
table.put(fonts[i].getPSName(), fonts[i]);
|
||||
}
|
||||
|
||||
list = new String[index];
|
||||
System.arraycopy(flist, 0, list, 0, index);
|
||||
|
||||
fontSelector = new JList(list);
|
||||
fontSelector.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (e.getValueIsAdjusting() == false) {
|
||||
selection = fontSelector.getSelectedIndex();
|
||||
okButton.setEnabled(true);
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fontSelector.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
fontSelector.setVisibleRowCount(12);
|
||||
JScrollPane fontScroller = new JScrollPane(fontSelector);
|
||||
pain.add(fontScroller);
|
||||
|
||||
Dimension d1 = new Dimension(13, 13);
|
||||
pain.add(new Box.Filler(d1, d1, d1));
|
||||
|
||||
sample = new SampleComponent(this);
|
||||
|
||||
// Seems that in some instances, no default font is set
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=777
|
||||
sample.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
|
||||
pain.add(sample);
|
||||
|
||||
Dimension d2 = new Dimension(6, 6);
|
||||
pain.add(new Box.Filler(d2, d2, d2));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.add(new JLabel("Size:"));
|
||||
sizeSelector = new JTextField(" 48 ");
|
||||
sizeSelector.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void insertUpdate(DocumentEvent e) { update(); }
|
||||
public void removeUpdate(DocumentEvent e) { update(); }
|
||||
public void changedUpdate(DocumentEvent e) { }
|
||||
});
|
||||
panel.add(sizeSelector);
|
||||
|
||||
smoothBox = new JCheckBox("Smooth");
|
||||
smoothBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
smooth = smoothBox.isSelected();
|
||||
update();
|
||||
}
|
||||
});
|
||||
smoothBox.setSelected(smooth);
|
||||
panel.add(smoothBox);
|
||||
|
||||
// allBox = new JCheckBox("All Characters");
|
||||
// allBox.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// all = allBox.isSelected();
|
||||
// }
|
||||
// });
|
||||
// allBox.setSelected(all);
|
||||
// panel.add(allBox);
|
||||
charsetButton = new JButton("Characters...");
|
||||
charsetButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//showCharacterList();
|
||||
charSelector.setVisible(true);
|
||||
}
|
||||
});
|
||||
panel.add(charsetButton);
|
||||
|
||||
pain.add(panel);
|
||||
|
||||
JPanel filestuff = new JPanel();
|
||||
filestuff.add(new JLabel("Filename:"));
|
||||
filestuff.add(filenameField = new JTextField(20));
|
||||
filestuff.add(new JLabel(".vlw"));
|
||||
pain.add(filestuff);
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
build();
|
||||
}
|
||||
});
|
||||
okButton.setEnabled(false);
|
||||
|
||||
buttons.add(cancelButton);
|
||||
buttons.add(okButton);
|
||||
pain.add(buttons);
|
||||
|
||||
JRootPane root = getRootPane();
|
||||
root.setDefaultButton(okButton);
|
||||
ActionListener disposer = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
setVisible(false);
|
||||
}
|
||||
};
|
||||
Base.registerWindowCloseKeys(root, disposer);
|
||||
Base.setIcon(this);
|
||||
|
||||
setResizable(false);
|
||||
pack();
|
||||
|
||||
// do this after pack so it doesn't affect layout
|
||||
sample.setFont(new Font(list[0], Font.PLAIN, 48));
|
||||
|
||||
fontSelector.setSelectedIndex(0);
|
||||
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
windowSize = getSize();
|
||||
|
||||
setLocation((screen.width - windowSize.width) / 2,
|
||||
(screen.height - windowSize.height) / 2);
|
||||
|
||||
// create this behind the scenes
|
||||
charSelector = new CharacterSelector();
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public void update() {
|
||||
int fontsize = 0;
|
||||
try {
|
||||
fontsize = Integer.parseInt(sizeSelector.getText().trim());
|
||||
//System.out.println("'" + sizeSelector.getText() + "'");
|
||||
} catch (NumberFormatException e2) { }
|
||||
|
||||
// if a deselect occurred, selection will be -1
|
||||
if ((fontsize > 0) && (fontsize < 256) && (selection != -1)) {
|
||||
//font = new Font(list[selection], Font.PLAIN, fontsize);
|
||||
Font instance = (Font) table.get(list[selection]);
|
||||
font = instance.deriveFont(Font.PLAIN, fontsize);
|
||||
//System.out.println("setting font to " + font);
|
||||
sample.setFont(font);
|
||||
|
||||
String filenameSuggestion = list[selection].replace(' ', '_');
|
||||
filenameSuggestion += "-" + fontsize;
|
||||
filenameField.setText(filenameSuggestion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
// Please implement me properly. The schematic is below, but not debugged.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1464
|
||||
|
||||
// final String filename2 = filename;
|
||||
// final int fontsize2 = fontsize;
|
||||
// SwingUtilities.invokeLater(new Runnable() {
|
||||
// public void run() {
|
||||
try {
|
||||
Font instance = (Font) 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());
|
||||
|
||||
// PFont f = new PFont(font, smooth, null);
|
||||
// char[] charset = charSelector.getCharacters();
|
||||
// ProgressMonitor progressMonitor = new ProgressMonitor(CreateFont.this,
|
||||
// "Creating font", "", 0, charset.length);
|
||||
// progressMonitor.setProgress(0);
|
||||
// for (int i = 0; i < charset.length; i++) {
|
||||
// System.out.println(charset[i]);
|
||||
// f.index(charset[i]); // load this char
|
||||
// progressMonitor.setProgress(i+1);
|
||||
// }
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make the window vertically resizable
|
||||
*/
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(windowSize.width, 2000);
|
||||
}
|
||||
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return windowSize;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void show(File targetFolder) {
|
||||
this.targetFolder = targetFolder;
|
||||
show();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Component that draws the sample text. This is its own subclassed component
|
||||
* because Mac OS X controls seem to reset the RenderingHints for smoothing
|
||||
* so that they cannot be overridden properly for JLabel or JTextArea.
|
||||
* @author fry
|
||||
*/
|
||||
class SampleComponent extends JComponent {
|
||||
// see http://rinkworks.com/words/pangrams.shtml
|
||||
String text =
|
||||
"Forsaking monastic tradition, twelve jovial friars gave up their " +
|
||||
"vocation for a questionable existence on the flying trapeze.";
|
||||
int high = 80;
|
||||
|
||||
CreateFont parent;
|
||||
|
||||
public SampleComponent(CreateFont p) {
|
||||
this.parent = p;
|
||||
|
||||
// and yet, we still need an inner class to handle the basics.
|
||||
// or no, maybe i'll refactor this as a separate class!
|
||||
// maybe a few getters and setters? mmm?
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
String input =
|
||||
(String) JOptionPane.showInputDialog(parent,
|
||||
"Enter new sample text:",
|
||||
"Sample Text",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null, // icon
|
||||
null, // choices
|
||||
text);
|
||||
if (input != null) {
|
||||
text = input;
|
||||
parent.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
// System.out.println("smoothing set to " + smooth);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.WHITE);
|
||||
Dimension dim = getSize();
|
||||
g2.fillRect(0, 0, dim.width, dim.height);
|
||||
g2.setColor(Color.BLACK);
|
||||
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
parent.smooth ?
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
// add this one as well (after 1.0.9)
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
parent.smooth ?
|
||||
RenderingHints.VALUE_ANTIALIAS_ON :
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
//super.paintComponent(g2);
|
||||
Font font = getFont();
|
||||
int ascent = g2.getFontMetrics().getAscent();
|
||||
// System.out.println(f.getName());
|
||||
g2.setFont(font);
|
||||
g2.drawString(text, 5, dim.height - (dim.height - ascent) / 2);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(400, high);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(10000, high);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(100, high);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Frame for selecting which characters will be included with the font.
|
||||
*/
|
||||
class CharacterSelector extends JFrame {
|
||||
JRadioButton defaultCharsButton;
|
||||
JRadioButton allCharsButton;
|
||||
JRadioButton unicodeCharsButton;
|
||||
JScrollPane unicodeBlockScroller;
|
||||
JList charsetList;
|
||||
|
||||
|
||||
public CharacterSelector() {
|
||||
super("Character Selector");
|
||||
|
||||
charsetList = new CheckBoxList();
|
||||
DefaultListModel model = new DefaultListModel();
|
||||
charsetList.setModel(model);
|
||||
for (String item : blockNames) {
|
||||
model.addElement(new JCheckBox(item));
|
||||
}
|
||||
|
||||
unicodeBlockScroller =
|
||||
new JScrollPane(charsetList,
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
Container outer = getContentPane();
|
||||
outer.setLayout(new BorderLayout());
|
||||
|
||||
JPanel pain = new JPanel();
|
||||
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
|
||||
outer.add(pain, BorderLayout.CENTER);
|
||||
|
||||
pain.setLayout(new BoxLayout(pain, BoxLayout.Y_AXIS));
|
||||
|
||||
String labelText =
|
||||
"Default characters will include most bitmaps for Mac OS\n" +
|
||||
"and Windows Latin scripts. Including all characters may\n" +
|
||||
"require large amounts of memory for all of the bitmaps.\n" +
|
||||
"For greater control, you can select specific Unicode blocks.";
|
||||
JTextArea textarea = new JTextArea(labelText);
|
||||
textarea.setBorder(new EmptyBorder(13, 8, 13, 8));
|
||||
textarea.setBackground(null);
|
||||
textarea.setEditable(false);
|
||||
textarea.setHighlighter(null);
|
||||
textarea.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
pain.add(textarea);
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//System.out.println("action " + unicodeCharsButton.isSelected());
|
||||
//unicodeBlockScroller.setEnabled(unicodeCharsButton.isSelected());
|
||||
charsetList.setEnabled(unicodeCharsButton.isSelected());
|
||||
}
|
||||
};
|
||||
defaultCharsButton = new JRadioButton("Default Characters");
|
||||
allCharsButton = new JRadioButton("All Characters");
|
||||
unicodeCharsButton = new JRadioButton("Specific Unicode Blocks");
|
||||
|
||||
defaultCharsButton.addActionListener(listener);
|
||||
allCharsButton.addActionListener(listener);
|
||||
unicodeCharsButton.addActionListener(listener);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(defaultCharsButton);
|
||||
group.add(allCharsButton);
|
||||
group.add(unicodeCharsButton);
|
||||
|
||||
JPanel radioPanel = new JPanel();
|
||||
//radioPanel.setBackground(Color.red);
|
||||
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
|
||||
radioPanel.add(defaultCharsButton);
|
||||
radioPanel.add(allCharsButton);
|
||||
radioPanel.add(unicodeCharsButton);
|
||||
|
||||
JPanel rightStuff = new JPanel();
|
||||
rightStuff.setLayout(new BoxLayout(rightStuff, BoxLayout.X_AXIS));
|
||||
rightStuff.add(radioPanel);
|
||||
rightStuff.add(Box.createHorizontalGlue());
|
||||
pain.add(rightStuff);
|
||||
pain.add(Box.createVerticalStrut(13));
|
||||
|
||||
// pain.add(radioPanel);
|
||||
|
||||
// pain.add(defaultCharsButton);
|
||||
// pain.add(allCharsButton);
|
||||
// pain.add(unicodeCharsButton);
|
||||
|
||||
defaultCharsButton.setSelected(true);
|
||||
charsetList.setEnabled(false);
|
||||
|
||||
//frame.getContentPane().add(scroller);
|
||||
pain.add(unicodeBlockScroller);
|
||||
pain.add(Box.createVerticalStrut(8));
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton.setEnabled(true);
|
||||
buttons.add(okButton);
|
||||
pain.add(buttons);
|
||||
|
||||
JRootPane root = getRootPane();
|
||||
root.setDefaultButton(okButton);
|
||||
ActionListener disposer = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
setVisible(false);
|
||||
}
|
||||
};
|
||||
Base.registerWindowCloseKeys(root, disposer);
|
||||
Base.setIcon(this);
|
||||
|
||||
pack();
|
||||
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
Dimension windowSize = getSize();
|
||||
|
||||
setLocation((screen.width - windowSize.width) / 2,
|
||||
(screen.height - windowSize.height) / 2);
|
||||
}
|
||||
|
||||
|
||||
protected char[] getCharacters() {
|
||||
if (defaultCharsButton.isSelected()) {
|
||||
return PFont.CHARSET;
|
||||
}
|
||||
|
||||
char[] charset = new char[65536];
|
||||
if (allCharsButton.isSelected()) {
|
||||
for (int i = 0; i < 0xFFFF; i++) {
|
||||
charset[i] = (char) i;
|
||||
}
|
||||
} else {
|
||||
DefaultListModel model = (DefaultListModel) charsetList.getModel();
|
||||
int index = 0;
|
||||
for (int i = 0; i < BLOCKS.length; i++) {
|
||||
if (((JCheckBox) model.get(i)).isSelected()) {
|
||||
for (int j = blockStart[i]; j <= blockStop[i]; j++) {
|
||||
charset[index++] = (char) j;
|
||||
}
|
||||
}
|
||||
}
|
||||
charset = PApplet.subset(charset, 0, index);
|
||||
}
|
||||
//System.out.println("Creating font with " + charset.length + " characters.");
|
||||
return charset;
|
||||
}
|
||||
|
||||
|
||||
// http://www.unicode.org/Public/UNIDATA/Blocks.txt
|
||||
static final String[] BLOCKS = {
|
||||
"0000..007F; Basic Latin",
|
||||
"0080..00FF; Latin-1 Supplement",
|
||||
"0100..017F; Latin Extended-A",
|
||||
"0180..024F; Latin Extended-B",
|
||||
"0250..02AF; IPA Extensions",
|
||||
"02B0..02FF; Spacing Modifier Letters",
|
||||
"0300..036F; Combining Diacritical Marks",
|
||||
"0370..03FF; Greek and Coptic",
|
||||
"0400..04FF; Cyrillic",
|
||||
"0500..052F; Cyrillic Supplement",
|
||||
"0530..058F; Armenian",
|
||||
"0590..05FF; Hebrew",
|
||||
"0600..06FF; Arabic",
|
||||
"0700..074F; Syriac",
|
||||
"0750..077F; Arabic Supplement",
|
||||
"0780..07BF; Thaana",
|
||||
"07C0..07FF; NKo",
|
||||
"0800..083F; Samaritan",
|
||||
"0900..097F; Devanagari",
|
||||
"0980..09FF; Bengali",
|
||||
"0A00..0A7F; Gurmukhi",
|
||||
"0A80..0AFF; Gujarati",
|
||||
"0B00..0B7F; Oriya",
|
||||
"0B80..0BFF; Tamil",
|
||||
"0C00..0C7F; Telugu",
|
||||
"0C80..0CFF; Kannada",
|
||||
"0D00..0D7F; Malayalam",
|
||||
"0D80..0DFF; Sinhala",
|
||||
"0E00..0E7F; Thai",
|
||||
"0E80..0EFF; Lao",
|
||||
"0F00..0FFF; Tibetan",
|
||||
"1000..109F; Myanmar",
|
||||
"10A0..10FF; Georgian",
|
||||
"1100..11FF; Hangul Jamo",
|
||||
"1200..137F; Ethiopic",
|
||||
"1380..139F; Ethiopic Supplement",
|
||||
"13A0..13FF; Cherokee",
|
||||
"1400..167F; Unified Canadian Aboriginal Syllabics",
|
||||
"1680..169F; Ogham",
|
||||
"16A0..16FF; Runic",
|
||||
"1700..171F; Tagalog",
|
||||
"1720..173F; Hanunoo",
|
||||
"1740..175F; Buhid",
|
||||
"1760..177F; Tagbanwa",
|
||||
"1780..17FF; Khmer",
|
||||
"1800..18AF; Mongolian",
|
||||
"18B0..18FF; Unified Canadian Aboriginal Syllabics Extended",
|
||||
"1900..194F; Limbu",
|
||||
"1950..197F; Tai Le",
|
||||
"1980..19DF; New Tai Lue",
|
||||
"19E0..19FF; Khmer Symbols",
|
||||
"1A00..1A1F; Buginese",
|
||||
"1A20..1AAF; Tai Tham",
|
||||
"1B00..1B7F; Balinese",
|
||||
"1B80..1BBF; Sundanese",
|
||||
"1C00..1C4F; Lepcha",
|
||||
"1C50..1C7F; Ol Chiki",
|
||||
"1CD0..1CFF; Vedic Extensions",
|
||||
"1D00..1D7F; Phonetic Extensions",
|
||||
"1D80..1DBF; Phonetic Extensions Supplement",
|
||||
"1DC0..1DFF; Combining Diacritical Marks Supplement",
|
||||
"1E00..1EFF; Latin Extended Additional",
|
||||
"1F00..1FFF; Greek Extended",
|
||||
"2000..206F; General Punctuation",
|
||||
"2070..209F; Superscripts and Subscripts",
|
||||
"20A0..20CF; Currency Symbols",
|
||||
"20D0..20FF; Combining Diacritical Marks for Symbols",
|
||||
"2100..214F; Letterlike Symbols",
|
||||
"2150..218F; Number Forms",
|
||||
"2190..21FF; Arrows",
|
||||
"2200..22FF; Mathematical Operators",
|
||||
"2300..23FF; Miscellaneous Technical",
|
||||
"2400..243F; Control Pictures",
|
||||
"2440..245F; Optical Character Recognition",
|
||||
"2460..24FF; Enclosed Alphanumerics",
|
||||
"2500..257F; Box Drawing",
|
||||
"2580..259F; Block Elements",
|
||||
"25A0..25FF; Geometric Shapes",
|
||||
"2600..26FF; Miscellaneous Symbols",
|
||||
"2700..27BF; Dingbats",
|
||||
"27C0..27EF; Miscellaneous Mathematical Symbols-A",
|
||||
"27F0..27FF; Supplemental Arrows-A",
|
||||
"2800..28FF; Braille Patterns",
|
||||
"2900..297F; Supplemental Arrows-B",
|
||||
"2980..29FF; Miscellaneous Mathematical Symbols-B",
|
||||
"2A00..2AFF; Supplemental Mathematical Operators",
|
||||
"2B00..2BFF; Miscellaneous Symbols and Arrows",
|
||||
"2C00..2C5F; Glagolitic",
|
||||
"2C60..2C7F; Latin Extended-C",
|
||||
"2C80..2CFF; Coptic",
|
||||
"2D00..2D2F; Georgian Supplement",
|
||||
"2D30..2D7F; Tifinagh",
|
||||
"2D80..2DDF; Ethiopic Extended",
|
||||
"2DE0..2DFF; Cyrillic Extended-A",
|
||||
"2E00..2E7F; Supplemental Punctuation",
|
||||
"2E80..2EFF; CJK Radicals Supplement",
|
||||
"2F00..2FDF; Kangxi Radicals",
|
||||
"2FF0..2FFF; Ideographic Description Characters",
|
||||
"3000..303F; CJK Symbols and Punctuation",
|
||||
"3040..309F; Hiragana",
|
||||
"30A0..30FF; Katakana",
|
||||
"3100..312F; Bopomofo",
|
||||
"3130..318F; Hangul Compatibility Jamo",
|
||||
"3190..319F; Kanbun",
|
||||
"31A0..31BF; Bopomofo Extended",
|
||||
"31C0..31EF; CJK Strokes",
|
||||
"31F0..31FF; Katakana Phonetic Extensions",
|
||||
"3200..32FF; Enclosed CJK Letters and Months",
|
||||
"3300..33FF; CJK Compatibility",
|
||||
"3400..4DBF; CJK Unified Ideographs Extension A",
|
||||
"4DC0..4DFF; Yijing Hexagram Symbols",
|
||||
"4E00..9FFF; CJK Unified Ideographs",
|
||||
"A000..A48F; Yi Syllables",
|
||||
"A490..A4CF; Yi Radicals",
|
||||
"A4D0..A4FF; Lisu",
|
||||
"A500..A63F; Vai",
|
||||
"A640..A69F; Cyrillic Extended-B",
|
||||
"A6A0..A6FF; Bamum",
|
||||
"A700..A71F; Modifier Tone Letters",
|
||||
"A720..A7FF; Latin Extended-D",
|
||||
"A800..A82F; Syloti Nagri",
|
||||
"A830..A83F; Common Indic Number Forms",
|
||||
"A840..A87F; Phags-pa",
|
||||
"A880..A8DF; Saurashtra",
|
||||
"A8E0..A8FF; Devanagari Extended",
|
||||
"A900..A92F; Kayah Li",
|
||||
"A930..A95F; Rejang",
|
||||
"A960..A97F; Hangul Jamo Extended-A",
|
||||
"A980..A9DF; Javanese",
|
||||
"AA00..AA5F; Cham",
|
||||
"AA60..AA7F; Myanmar Extended-A",
|
||||
"AA80..AADF; Tai Viet",
|
||||
"ABC0..ABFF; Meetei Mayek",
|
||||
"AC00..D7AF; Hangul Syllables",
|
||||
"D7B0..D7FF; Hangul Jamo Extended-B",
|
||||
"D800..DB7F; High Surrogates",
|
||||
"DB80..DBFF; High Private Use Surrogates",
|
||||
"DC00..DFFF; Low Surrogates",
|
||||
"E000..F8FF; Private Use Area",
|
||||
"F900..FAFF; CJK Compatibility Ideographs",
|
||||
"FB00..FB4F; Alphabetic Presentation Forms",
|
||||
"FB50..FDFF; Arabic Presentation Forms-A",
|
||||
"FE00..FE0F; Variation Selectors",
|
||||
"FE10..FE1F; Vertical Forms",
|
||||
"FE20..FE2F; Combining Half Marks",
|
||||
"FE30..FE4F; CJK Compatibility Forms",
|
||||
"FE50..FE6F; Small Form Variants",
|
||||
"FE70..FEFF; Arabic Presentation Forms-B",
|
||||
"FF00..FFEF; Halfwidth and Fullwidth Forms",
|
||||
"FFF0..FFFF; Specials"
|
||||
};
|
||||
|
||||
static String[] blockNames;
|
||||
static int[] blockStart;
|
||||
static int[] blockStop;
|
||||
static {
|
||||
int count = BLOCKS.length;
|
||||
blockNames = new String[count];
|
||||
blockStart = new int[count];
|
||||
blockStop = new int[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
String line = BLOCKS[i];
|
||||
blockStart[i] = PApplet.unhex(line.substring(0, 4));
|
||||
blockStop[i] = PApplet.unhex(line.substring(6, 10));
|
||||
blockNames[i] = line.substring(12);
|
||||
}
|
||||
// PApplet.println(codePointStop);
|
||||
// PApplet.println(codePoints);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Code for this CheckBoxList class found on the net, though I've lost the
|
||||
// link. If you run across the original version, please let me know so that
|
||||
// the original author can be credited properly. It was from a snippet
|
||||
// collection, but it seems to have been picked up so many places with others
|
||||
// placing their copyright on it, that I haven't been able to determine the
|
||||
// original author. [fry 20100216]
|
||||
class CheckBoxList extends JList {
|
||||
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
|
||||
|
||||
public CheckBoxList() {
|
||||
setCellRenderer(new CellRenderer());
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (isEnabled()) {
|
||||
int index = locationToIndex(e.getPoint());
|
||||
|
||||
if (index != -1) {
|
||||
JCheckBox checkbox = (JCheckBox)
|
||||
getModel().getElementAt(index);
|
||||
checkbox.setSelected(!checkbox.isSelected());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
|
||||
protected class CellRenderer implements ListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
JCheckBox checkbox = (JCheckBox) value;
|
||||
checkbox.setBackground(isSelected ? getSelectionBackground() : getBackground());
|
||||
checkbox.setForeground(isSelected ? getSelectionForeground() : getForeground());
|
||||
//checkbox.setEnabled(isEnabled());
|
||||
checkbox.setEnabled(list.isEnabled());
|
||||
checkbox.setFont(getFont());
|
||||
checkbox.setFocusPainted(false);
|
||||
checkbox.setBorderPainted(true);
|
||||
checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
|
||||
return checkbox;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ import javax.swing.text.Segment;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.syntax.*;
|
||||
import processing.core.PApplet;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
/**
|
||||
* Format for Discourse Tool
|
||||
|
@ -3,7 +3,6 @@
|
||||
*/
|
||||
package processing.app.tools;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
|
@ -21,7 +21,7 @@ public abstract class AbstractGUITest {
|
||||
Preferences.init(null);
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
Theme.init();
|
||||
Base.platform.setLookAndFeel();
|
||||
Base.getPlatform().setLookAndFeel();
|
||||
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||
Base.untitledFolder.deleteOnExit();
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
package processing.app;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.debug.TargetBoard;
|
||||
|
||||
import processing.app.debug.TargetBoard;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
||||
@ -29,7 +30,10 @@ public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
||||
// should not raise an exception
|
||||
new Base(new String[0]);
|
||||
|
||||
TargetBoard targetBoard = Base.getTargetBoard();
|
||||
// skip test if no target platforms are available
|
||||
Assume.assumeNotNull(BaseNoGui.getTargetPlatform());
|
||||
|
||||
TargetBoard targetBoard = BaseNoGui.getTargetBoard();
|
||||
assertNotEquals("unreal_board", targetBoard.getId());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package processing.app;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
@ -40,7 +41,12 @@ public class I18NTest {
|
||||
return properties;
|
||||
}
|
||||
|
||||
// XXX: I18NTest.class.getResource(".").getFile() no longer works, because
|
||||
// the class is now into the arudino-core package. This test should be refactored
|
||||
// in order to use ResourceBundles to load translations to be checked.
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void ensureEveryTranslationIsComplete() throws Exception {
|
||||
Set<String> keys = loadReferenceI18NKeys();
|
||||
|
||||
|
@ -3,7 +3,6 @@ package processing.app;
|
||||
import org.fest.swing.fixture.JMenuItemFixture;
|
||||
import org.junit.Test;
|
||||
import processing.app.helpers.JEditTextAreaFixture;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package processing.app.debug;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.packages.UploaderAndMonitorFactory;
|
||||
import cc.arduino.packages.UploaderFactory;
|
||||
import cc.arduino.packages.uploaders.SSHUploader;
|
||||
import cc.arduino.packages.uploaders.SerialUploader;
|
||||
import org.junit.Before;
|
||||
@ -29,7 +29,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("yun");
|
||||
boardPort.setAddress("192.168.0.1");
|
||||
boardPort.setProtocol("network");
|
||||
Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SSHUploader);
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("myyun");
|
||||
boardPort.setAddress("192.168.0.1");
|
||||
boardPort.setProtocol("network");
|
||||
Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SerialUploader);
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("Arduino Leonardo");
|
||||
boardPort.setAddress("/dev/ttyACM0");
|
||||
boardPort.setProtocol("serial");
|
||||
Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SerialUploader);
|
||||
}
|
||||
|
8
arduino-builder/.classpath
Normal file
8
arduino-builder/.classpath
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
|
||||
<classpathentry kind="lib" path="/arduino-core/arduino-core.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>processing-core</name>
|
||||
<name>arduino-builder</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
11
arduino-builder/.settings/org.eclipse.jdt.core.prefs
Normal file
11
arduino-builder/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
BIN
arduino-builder/bin/cc/arduino/builder/ArduinoBuilder.class
Normal file
BIN
arduino-builder/bin/cc/arduino/builder/ArduinoBuilder.class
Normal file
Binary file not shown.
11
arduino-builder/src/cc/arduino/builder/ArduinoBuilder.java
Normal file
11
arduino-builder/src/cc/arduino/builder/ArduinoBuilder.java
Normal file
@ -0,0 +1,11 @@
|
||||
package cc.arduino.builder;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
|
||||
public class ArduinoBuilder {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BaseNoGui.main(args);
|
||||
}
|
||||
|
||||
}
|
13
arduino-core/.classpath
Normal file
13
arduino-core/.classpath
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
1
arduino-core/.gitignore
vendored
Normal file
1
arduino-core/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin/
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>preproc</name>
|
||||
<name>arduino-core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
52
arduino-core/build.xml
Normal file
52
arduino-core/build.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="Arduino IDE Core" default="build">
|
||||
|
||||
<path id="class.path">
|
||||
<fileset dir="lib">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
<pathelement path="${env.JAVA_HOME}/lib/tools.jar"/>
|
||||
</path>
|
||||
|
||||
<target name="clean" description="Clean out the build directories">
|
||||
<delete dir="bin" />
|
||||
<delete file="arduino-core.jar" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile">
|
||||
<!--
|
||||
<taskdef name="methods"
|
||||
classname="PAppletMethods"
|
||||
classpath="methods/methods.jar" />
|
||||
<methods dir="${basedir}/src/processing/core" />
|
||||
-->
|
||||
<mkdir dir="bin" />
|
||||
|
||||
<!-- ant seems to nuke ${java.home} for some reason, pointing at the JRE
|
||||
subfolder instead of the actual JDK found at JAVA_HOME.
|
||||
To avoid this, we grab the actual JAVA_HOME environment variable
|
||||
and use that to specify the location of tools.jar. -->
|
||||
|
||||
<!-- if someone is better with ant please help clean this up -->
|
||||
<property environment="env" />
|
||||
<property name="java_home" value="${env.JAVA_HOME}" />
|
||||
|
||||
<javac source="1.6"
|
||||
target="1.6"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false"
|
||||
srcdir="src"
|
||||
classpathref="class.path"
|
||||
destdir="bin">
|
||||
</javac>
|
||||
|
||||
<copy todir="bin" overwrite="true" verbose="true">
|
||||
<fileset dir="src" includes="**/*.properties" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile" description="Build core library">
|
||||
<jar basedir="bin" destfile="arduino-core.jar" />
|
||||
</target>
|
||||
|
||||
</project>
|
1
arduino-core/lib/apple.LICENSE.BSD-like.txt
Normal file
1
arduino-core/lib/apple.LICENSE.BSD-like.txt
Normal file
@ -0,0 +1 @@
|
||||
http://developer.apple.com/library/mac/#/legacy/library/samplecode/AppleJavaExtensions/Listings/README_txt.html#//apple_ref/doc/uid/DTS10000677-README_txt-DontLinkElementID_3
|
BIN
arduino-core/lib/apple.jar
Normal file
BIN
arduino-core/lib/apple.jar
Normal file
Binary file not shown.
BIN
arduino-core/lib/commons-exec-1.1.jar
Normal file
BIN
arduino-core/lib/commons-exec-1.1.jar
Normal file
Binary file not shown.
202
arduino-core/lib/commons-exec.LICENSE.ASL-2.0.txt
Normal file
202
arduino-core/lib/commons-exec.LICENSE.ASL-2.0.txt
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
BIN
arduino-core/lib/commons-logging-1.0.4.jar
Normal file
BIN
arduino-core/lib/commons-logging-1.0.4.jar
Normal file
Binary file not shown.
202
arduino-core/lib/commons-logging.LICENSE.ASL-2.0.txt
Normal file
202
arduino-core/lib/commons-logging.LICENSE.ASL-2.0.txt
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
BIN
arduino-core/lib/jmdns-3.4.1.jar
Normal file
BIN
arduino-core/lib/jmdns-3.4.1.jar
Normal file
Binary file not shown.
2
arduino-core/lib/jmdns.LICENSE.ASL-2.0-LGPL-2.1.txt
Normal file
2
arduino-core/lib/jmdns.LICENSE.ASL-2.0-LGPL-2.1.txt
Normal file
@ -0,0 +1,2 @@
|
||||
https://jmdns.svn.sourceforge.net/svnroot/jmdns/tags/jmdns-3.4.1/LICENSE-LGPL.txt
|
||||
https://jmdns.svn.sourceforge.net/svnroot/jmdns/tags/jmdns-3.4.1/LICENSE
|
1
arduino-core/lib/jna.LICENSE.LGPL-2.1.txt
Normal file
1
arduino-core/lib/jna.LICENSE.LGPL-2.1.txt
Normal file
@ -0,0 +1 @@
|
||||
https://github.com/twall/jna/blob/master/LICENSE
|
BIN
arduino-core/lib/jna.jar
Normal file
BIN
arduino-core/lib/jna.jar
Normal file
Binary file not shown.
BIN
arduino-core/lib/jsch-0.1.50.jar
Normal file
BIN
arduino-core/lib/jsch-0.1.50.jar
Normal file
Binary file not shown.
1
arduino-core/lib/jsch.LICENSE.BSD.txt
Normal file
1
arduino-core/lib/jsch.LICENSE.BSD.txt
Normal file
@ -0,0 +1 @@
|
||||
http://www.jcraft.com/jsch/LICENSE.txt
|
BIN
arduino-core/lib/jssc-2.8.0.jar
Normal file
BIN
arduino-core/lib/jssc-2.8.0.jar
Normal file
Binary file not shown.
674
arduino-core/lib/jssc.LICENSE.GPL.txt
Normal file
674
arduino-core/lib/jssc.LICENSE.GPL.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
165
arduino-core/lib/jssc.LICENSE.LGPL.txt
Normal file
165
arduino-core/lib/jssc.LICENSE.LGPL.txt
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
@ -25,7 +25,7 @@
|
||||
package cc.arduino.packages;
|
||||
|
||||
import processing.app.I18n;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.debug.MessageConsumer;
|
||||
import processing.app.debug.MessageSiphon;
|
||||
import processing.app.debug.RunnerException;
|
||||
@ -64,11 +64,22 @@ public abstract class Uploader implements MessageConsumer {
|
||||
|
||||
private String error;
|
||||
protected boolean notFoundError;
|
||||
protected boolean noUploadPort;
|
||||
|
||||
protected Uploader() {
|
||||
this.verbose = PreferencesData.getBoolean("upload.verbose");
|
||||
init(false);
|
||||
}
|
||||
|
||||
protected Uploader(boolean nup) {
|
||||
this.verbose = PreferencesData.getBoolean("upload.verbose");
|
||||
init(nup);
|
||||
}
|
||||
|
||||
private void init(boolean nup) {
|
||||
this.error = null;
|
||||
this.verbose = Preferences.getBoolean("upload.verbose");
|
||||
this.notFoundError = false;
|
||||
this.noUploadPort = nup;
|
||||
}
|
||||
|
||||
public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception;
|
@ -31,15 +31,14 @@ package cc.arduino.packages;
|
||||
|
||||
import cc.arduino.packages.uploaders.SSHUploader;
|
||||
import cc.arduino.packages.uploaders.SerialUploader;
|
||||
import processing.app.AbstractMonitor;
|
||||
import processing.app.Base;
|
||||
import processing.app.NetworkMonitor;
|
||||
import processing.app.SerialMonitor;
|
||||
import processing.app.debug.TargetBoard;
|
||||
|
||||
public class UploaderAndMonitorFactory {
|
||||
public class UploaderFactory {
|
||||
|
||||
public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) {
|
||||
if (noUploadPort)
|
||||
return new SerialUploader(noUploadPort);
|
||||
|
||||
public Uploader newUploader(TargetBoard board, BoardPort port) {
|
||||
if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) {
|
||||
return new SSHUploader(port);
|
||||
}
|
||||
@ -47,12 +46,4 @@ public class UploaderAndMonitorFactory {
|
||||
return new SerialUploader();
|
||||
}
|
||||
|
||||
public AbstractMonitor newMonitor(BoardPort port, Base base) {
|
||||
if ("network".equals(port.getProtocol())) {
|
||||
return new NetworkMonitor(port, base);
|
||||
}
|
||||
|
||||
return new SerialMonitor(port);
|
||||
}
|
||||
|
||||
}
|
@ -31,8 +31,8 @@ package cc.arduino.packages.discoverers;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Discovery;
|
||||
import cc.arduino.packages.discoverers.network.*;
|
||||
import processing.app.Base;
|
||||
import cc.arduino.packages.discoverers.network.NetworkChecker;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.helpers.NetUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
|
||||
@ -140,8 +140,10 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
||||
|
||||
String label = name + " at " + address;
|
||||
if (board != null) {
|
||||
String boardName = Base.getPlatform().resolveDeviceByBoardID(Base.packages, board);
|
||||
label += " (" + boardName + ")";
|
||||
String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
|
||||
if (boardName != null) {
|
||||
label += " (" + boardName + ")";
|
||||
}
|
||||
}
|
||||
|
||||
BoardPort port = new BoardPort();
|
@ -32,7 +32,7 @@ package cc.arduino.packages.discoverers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.Platform;
|
||||
import processing.app.Serial;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
@ -43,7 +43,7 @@ public class SerialDiscovery implements Discovery {
|
||||
|
||||
@Override
|
||||
public List<BoardPort> discovery() {
|
||||
Platform os = Base.getPlatform();
|
||||
Platform os = BaseNoGui.getPlatform();
|
||||
String devicesListOutput = os.preListAllCandidateDevices();
|
||||
|
||||
List<BoardPort> res = new ArrayList<BoardPort>();
|
||||
@ -51,7 +51,7 @@ public class SerialDiscovery implements Discovery {
|
||||
List<String> ports = Serial.list();
|
||||
|
||||
for (String port : ports) {
|
||||
String boardName = os.resolveDeviceAttachedTo(port, Base.packages, devicesListOutput);
|
||||
String boardName = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
|
||||
String label = port;
|
||||
if (boardName != null)
|
||||
label += " (" + boardName + ")";
|
@ -4,7 +4,7 @@ import cc.arduino.packages.BoardPort;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.PreferencesData;
|
||||
|
||||
public class SSHPwdSetup implements SSHClientSetupChainRing {
|
||||
|
||||
@ -13,7 +13,7 @@ public class SSHPwdSetup implements SSHClientSetupChainRing {
|
||||
String ipAddress = port.getAddress();
|
||||
|
||||
Session session = jSch.getSession("root", ipAddress, 22);
|
||||
session.setPassword(Preferences.get("runtime.pwd." + ipAddress));
|
||||
session.setPassword(PreferencesData.get("runtime.pwd." + ipAddress));
|
||||
|
||||
return session;
|
||||
}
|
@ -35,9 +35,9 @@ import cc.arduino.packages.ssh.*;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.debug.RunnerException;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
@ -82,7 +82,7 @@ public class SSHUploader extends Uploader {
|
||||
SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup());
|
||||
session = sshClientSetupChain.setup(port, jSch);
|
||||
|
||||
session.setUserInfo(new NoInteractionUserInfo(Preferences.get("runtime.pwd." + port.getAddress())));
|
||||
session.setUserInfo(new NoInteractionUserInfo(PreferencesData.get("runtime.pwd." + port.getAddress())));
|
||||
session.connect(30000);
|
||||
|
||||
scp = new SCP(session);
|
||||
@ -117,9 +117,9 @@ public class SSHUploader extends Uploader {
|
||||
}
|
||||
|
||||
private boolean runAVRDude(SSH ssh) throws IOException, JSchException {
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
PreferencesMap prefs = Preferences.getMap();
|
||||
prefs.putAll(Base.getBoardPreferences());
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
prefs.putAll(BaseNoGui.getBoardPreferences());
|
||||
prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool")));
|
||||
|
||||
String additionalParams = verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet");
|
@ -32,28 +32,39 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.Serial;
|
||||
import processing.app.SerialException;
|
||||
import processing.app.debug.RunnerException;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
import cc.arduino.packages.Uploader;
|
||||
|
||||
public class SerialUploader extends Uploader {
|
||||
|
||||
public SerialUploader()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public SerialUploader(boolean noUploadPort)
|
||||
{
|
||||
super(noUploadPort);
|
||||
}
|
||||
|
||||
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||
// FIXME: Preferences should be reorganized
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
PreferencesMap prefs = Preferences.getMap();
|
||||
prefs.putAll(Base.getBoardPreferences());
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
prefs.putAll(BaseNoGui.getBoardPreferences());
|
||||
String tool = prefs.getOrExcept("upload.tool");
|
||||
if (tool.contains(":")) {
|
||||
String[] split = tool.split(":", 2);
|
||||
targetPlatform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
tool = split[1];
|
||||
}
|
||||
prefs.putAll(targetPlatform.getTool(tool));
|
||||
@ -64,6 +75,26 @@ public class SerialUploader extends Uploader {
|
||||
return uploadUsingProgrammer(buildPath, className);
|
||||
}
|
||||
|
||||
if (noUploadPort)
|
||||
{
|
||||
prefs.put("build.path", buildPath);
|
||||
prefs.put("build.project_name", className);
|
||||
if (verbose)
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
|
||||
else
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
|
||||
|
||||
boolean uploadResult;
|
||||
try {
|
||||
String pattern = prefs.getOrExcept("upload.pattern");
|
||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
uploadResult = executeUploadCommand(cmd);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
// need to do a little dance for Leonardo and derivatives:
|
||||
// open then close the port at the magic baudrate (usually 1200 bps) first
|
||||
// to signal to the sketch that it should reset into bootloader. after doing
|
||||
@ -83,7 +114,8 @@ public class SerialUploader extends Uploader {
|
||||
List<String> before = Serial.list();
|
||||
if (before.contains(uploadPort)) {
|
||||
if (verbose)
|
||||
System.out.println(_("Forcing reset using 1200bps open/close on port ") + uploadPort);
|
||||
System.out.println(
|
||||
I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), uploadPort));
|
||||
Serial.touchPort(uploadPort, 1200);
|
||||
}
|
||||
Thread.sleep(400);
|
||||
@ -131,7 +163,7 @@ public class SerialUploader extends Uploader {
|
||||
|
||||
try {
|
||||
if (uploadResult && doTouch) {
|
||||
String uploadPort = Preferences.get("serial.port");
|
||||
String uploadPort = PreferencesData.get("serial.port");
|
||||
if (waitForUploadPort) {
|
||||
// For Due/Leonardo wait until the bootloader serial port disconnects and the
|
||||
// sketch serial port reconnects (or timeout after a few seconds if the
|
||||
@ -188,7 +220,7 @@ public class SerialUploader extends Uploader {
|
||||
// come back, so use a longer time out before assuming that the
|
||||
// selected
|
||||
// port is the bootloader (not the sketch).
|
||||
if (((!Base.isWindows() && elapsed >= 500) || elapsed >= 5000) && now.contains(uploadPort)) {
|
||||
if (((!OSUtils.isWindows() && elapsed >= 500) || elapsed >= 5000) && now.contains(uploadPort)) {
|
||||
if (verbose)
|
||||
System.out.println("Uploading using selected port: " + uploadPort);
|
||||
return uploadPort;
|
||||
@ -201,16 +233,16 @@ public class SerialUploader extends Uploader {
|
||||
|
||||
public boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
|
||||
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
String programmer = Preferences.get("programmer");
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
String programmer = PreferencesData.get("programmer");
|
||||
if (programmer.contains(":")) {
|
||||
String[] split = programmer.split(":", 2);
|
||||
targetPlatform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
programmer = split[1];
|
||||
}
|
||||
|
||||
PreferencesMap prefs = Preferences.getMap();
|
||||
prefs.putAll(Base.getBoardPreferences());
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
prefs.putAll(BaseNoGui.getBoardPreferences());
|
||||
PreferencesMap programmerPrefs = targetPlatform.getProgrammer(programmer);
|
||||
if (programmerPrefs == null)
|
||||
throw new RunnerException(
|
||||
@ -244,14 +276,14 @@ public class SerialUploader extends Uploader {
|
||||
}
|
||||
|
||||
public boolean burnBootloader() throws Exception {
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
|
||||
// Find preferences for the selected programmer
|
||||
PreferencesMap programmerPrefs;
|
||||
String programmer = Preferences.get("programmer");
|
||||
String programmer = PreferencesData.get("programmer");
|
||||
if (programmer.contains(":")) {
|
||||
String[] split = programmer.split(":", 2);
|
||||
TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
programmer = split[1];
|
||||
programmerPrefs = platform.getProgrammer(programmer);
|
||||
} else {
|
||||
@ -262,8 +294,8 @@ public class SerialUploader extends Uploader {
|
||||
_("Please select a programmer from Tools->Programmer menu"));
|
||||
|
||||
// Build configuration for the current programmer
|
||||
PreferencesMap prefs = Preferences.getMap();
|
||||
prefs.putAll(Base.getBoardPreferences());
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
prefs.putAll(BaseNoGui.getBoardPreferences());
|
||||
prefs.putAll(programmerPrefs);
|
||||
|
||||
// Create configuration for bootloader tool
|
||||
@ -271,7 +303,7 @@ public class SerialUploader extends Uploader {
|
||||
String tool = prefs.getOrExcept("bootloader.tool");
|
||||
if (tool.contains(":")) {
|
||||
String[] split = tool.split(":", 2);
|
||||
TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||
tool = split[1];
|
||||
toolPrefs.putAll(platform.getTool(tool));
|
||||
if (toolPrefs.size() == 0)
|
||||
@ -291,19 +323,13 @@ public class SerialUploader extends Uploader {
|
||||
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet"));
|
||||
}
|
||||
|
||||
try {
|
||||
String pattern = prefs.getOrExcept("erase.pattern");
|
||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
if (!executeUploadCommand(cmd))
|
||||
return false;
|
||||
String pattern = prefs.getOrExcept("erase.pattern");
|
||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
if (!executeUploadCommand(cmd))
|
||||
return false;
|
||||
|
||||
pattern = prefs.getOrExcept("bootloader.pattern");
|
||||
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
return executeUploadCommand(cmd);
|
||||
} catch (RunnerException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
pattern = prefs.getOrExcept("bootloader.pattern");
|
||||
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
return executeUploadCommand(cmd);
|
||||
}
|
||||
}
|
967
arduino-core/src/processing/app/BaseNoGui.java
Normal file
967
arduino-core/src/processing/app/BaseNoGui.java
Normal file
@ -0,0 +1,967 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||
import org.apache.commons.logging.impl.NoOpLog;
|
||||
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
|
||||
import processing.app.debug.Compiler;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
import processing.app.helpers.BasicUserNotifier;
|
||||
import processing.app.helpers.CommandlineParser;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.UserNotifier;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.packages.Library;
|
||||
import processing.app.packages.LibraryList;
|
||||
|
||||
public class BaseNoGui {
|
||||
|
||||
/** Version string to be used for build */
|
||||
public static final int REVISION = 10600;
|
||||
/** Extended version string displayed on GUI */
|
||||
static String VERSION_NAME = "1.6.0";
|
||||
|
||||
static File buildFolder;
|
||||
|
||||
// Current directory to use for relative paths specified on the
|
||||
// commandline
|
||||
static String currentDirectory = System.getProperty("user.dir");
|
||||
|
||||
private static DiscoveryManager discoveryManager = new DiscoveryManager();
|
||||
|
||||
// these are static because they're used by Sketch
|
||||
static private File examplesFolder;
|
||||
static private File toolsFolder;
|
||||
|
||||
// maps #included files to their library folder
|
||||
public static Map<String, Library> importToLibraryTable;
|
||||
|
||||
// maps library name to their library folder
|
||||
static private LibraryList libraries;
|
||||
|
||||
static private List<File> librariesFolders;
|
||||
|
||||
static UserNotifier notifier = new BasicUserNotifier();
|
||||
|
||||
static public Map<String, TargetPackage> packages;
|
||||
|
||||
static Platform platform;
|
||||
|
||||
static File portableFolder = null;
|
||||
|
||||
static final String portableSketchbookFolder = "sketchbook";
|
||||
|
||||
// Returns a File object for the given pathname. If the pathname
|
||||
// is not absolute, it is interpreted relative to the current
|
||||
// directory when starting the IDE (which is not the same as the
|
||||
// current working directory!).
|
||||
static public File absoluteFile(String path) {
|
||||
if (path == null) return null;
|
||||
|
||||
File file = new File(path);
|
||||
if (!file.isAbsolute()) {
|
||||
file = new File(currentDirectory, path);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of lines in a file by counting the number of newline
|
||||
* characters inside a String (and adding 1).
|
||||
*/
|
||||
static public int countLines(String what) {
|
||||
int count = 1;
|
||||
for (char c : what.toCharArray()) {
|
||||
if (c == '\n') count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the platform's temporary folder, by creating
|
||||
* a temporary temporary file and getting its parent folder.
|
||||
* <br/>
|
||||
* Modified for revision 0094 to actually make the folder randomized
|
||||
* to avoid conflicts in multi-user environments. (Bug 177)
|
||||
*/
|
||||
static public File createTempFolder(String name) {
|
||||
try {
|
||||
File folder = File.createTempFile(name, null);
|
||||
//String tempPath = ignored.getParent();
|
||||
//return new File(tempPath);
|
||||
folder.delete();
|
||||
folder.mkdirs();
|
||||
return folder;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static public String getAvrBasePath() {
|
||||
String path = getHardwarePath() + File.separator + "tools" +
|
||||
File.separator + "avr" + File.separator + "bin" + File.separator;
|
||||
if (OSUtils.isLinux() && !(new File(path)).exists()) {
|
||||
return ""; // use distribution provided avr tools if bundled tools missing
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
static public File getBuildFolder() {
|
||||
if (buildFolder == null) {
|
||||
String buildPath = PreferencesData.get("build.path");
|
||||
if (buildPath != null) {
|
||||
buildFolder = absoluteFile(buildPath);
|
||||
if (!buildFolder.exists())
|
||||
buildFolder.mkdirs();
|
||||
} else {
|
||||
//File folder = new File(getTempFolder(), "build");
|
||||
//if (!folder.exists()) folder.mkdirs();
|
||||
buildFolder = createTempFolder("build");
|
||||
buildFolder.deleteOnExit();
|
||||
}
|
||||
}
|
||||
return buildFolder;
|
||||
}
|
||||
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
TargetBoard board = getTargetBoard();
|
||||
if (board == null)
|
||||
return null;
|
||||
|
||||
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
||||
for (String menuId : board.getMenuIds()) {
|
||||
String entry = PreferencesData.get("custom_" + menuId);
|
||||
if (board.hasMenu(menuId) && entry != null &&
|
||||
entry.startsWith(board.getId())) {
|
||||
String selectionId = entry.substring(entry.indexOf("_") + 1);
|
||||
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
|
||||
prefs.put("name", prefs.get("name") + ", " +
|
||||
board.getMenuLabel(menuId, selectionId));
|
||||
}
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
|
||||
static public File getContentFile(String name) {
|
||||
String path = System.getProperty("user.dir");
|
||||
|
||||
// Get a path to somewhere inside the .app folder
|
||||
if (OSUtils.isMacOS()) {
|
||||
// <key>javaroot</key>
|
||||
// <string>$JAVAROOT</string>
|
||||
String javaroot = System.getProperty("javaroot");
|
||||
if (javaroot != null) {
|
||||
path = javaroot;
|
||||
}
|
||||
}
|
||||
File working = new File(path);
|
||||
return new File(working, name);
|
||||
}
|
||||
|
||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
||||
return getTargetPlatform(pack, PreferencesData.get("target_platform"));
|
||||
}
|
||||
|
||||
static public File getDefaultSketchbookFolder() {
|
||||
if (getPortableFolder() != null)
|
||||
return new File(getPortableFolder(), getPortableSketchbookFolder());
|
||||
|
||||
File sketchbookFolder = null;
|
||||
try {
|
||||
sketchbookFolder = getPlatform().getDefaultSketchbookFolder();
|
||||
} catch (Exception e) { }
|
||||
|
||||
return sketchbookFolder;
|
||||
}
|
||||
|
||||
public static DiscoveryManager getDiscoveryManager() {
|
||||
return discoveryManager;
|
||||
}
|
||||
|
||||
static public File getExamplesFolder() {
|
||||
return examplesFolder;
|
||||
}
|
||||
|
||||
static public String getExamplesPath() {
|
||||
return examplesFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
static public File getHardwareFolder() {
|
||||
// calculate on the fly because it's needed by Preferences.init() to find
|
||||
// the boards.txt and programmers.txt preferences files (which happens
|
||||
// before the other folders / paths get cached).
|
||||
return getContentFile("hardware");
|
||||
}
|
||||
|
||||
static public String getHardwarePath() {
|
||||
return getHardwareFolder().getAbsolutePath();
|
||||
}
|
||||
|
||||
static public LibraryList getLibraries() {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
static public List<File> getLibrariesPath() {
|
||||
return librariesFolders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an InputStream for a file inside the Processing lib folder.
|
||||
*/
|
||||
static public InputStream getLibStream(String filename) throws IOException {
|
||||
return new FileInputStream(new File(getContentFile("lib"), filename));
|
||||
}
|
||||
|
||||
static public Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
static public File getPortableFolder() {
|
||||
return portableFolder;
|
||||
}
|
||||
|
||||
static public String getPortableSketchbookFolder() {
|
||||
return portableSketchbookFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get a File object for the specified filename inside
|
||||
* the settings folder.
|
||||
* For now, only used by Preferences to get the preferences.txt file.
|
||||
* @param filename A file inside the settings folder.
|
||||
* @return filename wrapped as a File object inside the settings folder
|
||||
*/
|
||||
static public File getSettingsFile(String filename) {
|
||||
return new File(getSettingsFolder(), filename);
|
||||
}
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
if (getPortableFolder() != null)
|
||||
return getPortableFolder();
|
||||
|
||||
File settingsFolder = null;
|
||||
|
||||
String preferencesPath = PreferencesData.get("settings.path");
|
||||
if (preferencesPath != null) {
|
||||
settingsFolder = absoluteFile(preferencesPath);
|
||||
|
||||
} else {
|
||||
try {
|
||||
settingsFolder = getPlatform().getSettingsFolder();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem getting data folder"),
|
||||
_("Error getting the Arduino data folder."), e);
|
||||
}
|
||||
}
|
||||
|
||||
// create the folder if it doesn't exist already
|
||||
if (!settingsFolder.exists()) {
|
||||
if (!settingsFolder.mkdirs()) {
|
||||
showError(_("Settings issues"),
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
}
|
||||
}
|
||||
return settingsFolder;
|
||||
}
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
if (portableFolder != null)
|
||||
return new File(portableFolder, PreferencesData.get("sketchbook.path"));
|
||||
return absoluteFile(PreferencesData.get("sketchbook.path"));
|
||||
}
|
||||
|
||||
static public File getSketchbookHardwareFolder() {
|
||||
return new File(getSketchbookFolder(), "hardware");
|
||||
}
|
||||
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||
if (!libdir.exists()) {
|
||||
try {
|
||||
libdir.mkdirs();
|
||||
File readme = new File(libdir, "readme.txt");
|
||||
FileWriter freadme = new FileWriter(readme);
|
||||
freadme.write(_("For information on installing libraries, see: " +
|
||||
"http://arduino.cc/en/Guide/Libraries\n"));
|
||||
freadme.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return libdir;
|
||||
}
|
||||
|
||||
static public String getSketchbookPath() {
|
||||
// Get the sketchbook path, and make sure it's set properly
|
||||
String sketchbookPath = PreferencesData.get("sketchbook.path");
|
||||
|
||||
// If a value is at least set, first check to see if the folder exists.
|
||||
// If it doesn't, warn the user that the sketchbook folder is being reset.
|
||||
if (sketchbookPath != null) {
|
||||
File sketchbookFolder;
|
||||
if (getPortableFolder() != null)
|
||||
sketchbookFolder = new File(getPortableFolder(), sketchbookPath);
|
||||
else
|
||||
sketchbookFolder = absoluteFile(sketchbookPath);
|
||||
if (!sketchbookFolder.exists()) {
|
||||
showWarning(_("Sketchbook folder disappeared"),
|
||||
_("The sketchbook folder no longer exists.\n" +
|
||||
"Arduino will switch to the default sketchbook\n" +
|
||||
"location, and create a new sketchbook folder if\n" +
|
||||
"necessary. Arduino will then stop talking about\n" +
|
||||
"himself in the third person."), null);
|
||||
sketchbookPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
return sketchbookPath;
|
||||
}
|
||||
|
||||
public static TargetBoard getTargetBoard() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
return null;
|
||||
String boardId = PreferencesData.get("board");
|
||||
return targetPlatform.getBoard(boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPackage
|
||||
*
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPackage getTargetPackage(String packageName) {
|
||||
return packages.get(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected TargetPlatform.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform() {
|
||||
String packageName = PreferencesData.get("target_package");
|
||||
String platformName = PreferencesData.get("target_platform");
|
||||
return getTargetPlatform(packageName, platformName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPlatform searching Package/Platform
|
||||
*
|
||||
* @param packageName
|
||||
* @param platformName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform(String packageName,
|
||||
String platformName) {
|
||||
TargetPackage p = packages.get(packageName);
|
||||
if (p == null)
|
||||
return null;
|
||||
return p.get(platformName);
|
||||
}
|
||||
|
||||
static public File getToolsFolder() {
|
||||
return toolsFolder;
|
||||
}
|
||||
|
||||
static public String getToolsPath() {
|
||||
return toolsFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
static public LibraryList getUserLibs() {
|
||||
if (libraries == null)
|
||||
return new LibraryList();
|
||||
return libraries.filterLibrariesInSubfolder(getSketchbookFolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a folder, return a list of the header files in that folder (but not
|
||||
* the header files in its sub-folders, as those should be included from
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(File path) throws IOException {
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h"));
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static public void init(String[] args) {
|
||||
getPlatform().init();
|
||||
|
||||
String sketchbookPath = getSketchbookPath();
|
||||
|
||||
// If no path is set, get the default sketchbook folder for this platform
|
||||
if (sketchbookPath == null) {
|
||||
if (BaseNoGui.getPortableFolder() != null)
|
||||
PreferencesData.set("sketchbook.path", getPortableSketchbookFolder());
|
||||
else
|
||||
showError(_("No sketchbook"), _("Sketchbook path not defined"), null);
|
||||
}
|
||||
|
||||
BaseNoGui.initPackages();
|
||||
|
||||
// Setup board-dependent variables.
|
||||
onBoardOrPortChange();
|
||||
|
||||
CommandlineParser parser = CommandlineParser.newCommandlineParser(args);
|
||||
|
||||
for (String path: parser.getFilenames()) {
|
||||
// Correctly resolve relative paths
|
||||
File file = absoluteFile(path);
|
||||
|
||||
// Fix a problem with systems that use a non-ASCII languages. Paths are
|
||||
// being passed in with 8.3 syntax, which makes the sketch loader code
|
||||
// unhappy, since the sketch folder naming doesn't match up correctly.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1089
|
||||
if (OSUtils.isWindows()) {
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!parser.isVerifyOrUploadMode() && !parser.isGetPrefMode())
|
||||
showError(_("Mode not supported"), _("Only --verify, --upload or --get-pref are supported"), null);
|
||||
|
||||
if (!parser.isForceSavePrefs())
|
||||
PreferencesData.setDoSave(false);
|
||||
if (!file.exists()) {
|
||||
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
|
||||
// Open failure is fatal in upload/verify mode
|
||||
showError(null, mess, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the preferences. For GUI mode, this happens in the quit
|
||||
// handler, but for other modes we should also make sure to save
|
||||
// them.
|
||||
PreferencesData.save();
|
||||
|
||||
if (parser.isVerifyOrUploadMode()) {
|
||||
// Set verbosity for command line build
|
||||
PreferencesData.set("build.verbose", "" + parser.isDoVerboseBuild());
|
||||
PreferencesData.set("upload.verbose", "" + parser.isDoVerboseUpload());
|
||||
|
||||
// Make sure these verbosity preferences are only for the
|
||||
// current session
|
||||
PreferencesData.setDoSave(false);
|
||||
|
||||
if (parser.isUploadMode()) {
|
||||
|
||||
if (parser.getFilenames().size() != 1)
|
||||
{
|
||||
showError(_("Multiple files not supported"), _("The --upload option supports only one file at a time"), null);
|
||||
}
|
||||
|
||||
List<String> warningsAccumulator = new LinkedList<String>();
|
||||
boolean success = false;
|
||||
try {
|
||||
// Editor constructor loads the sketch with handleOpenInternal() that
|
||||
// creates a new Sketch that, in trun, calls load() inside its constructor
|
||||
// This translates here as:
|
||||
// SketchData data = new SketchData(file);
|
||||
// File tempBuildFolder = getBuildFolder();
|
||||
// data.load();
|
||||
SketchData data = new SketchData(absoluteFile(parser.getFilenames().get(0)));
|
||||
File tempBuildFolder = getBuildFolder();
|
||||
data.load();
|
||||
|
||||
// Sketch.exportApplet()
|
||||
// - calls Sketch.prepare() that calls Sketch.ensureExistence()
|
||||
// - calls Sketch.build(verbose=false) that calls Sketch.ensureExistence(), set progressListener and calls Compiler.build()
|
||||
// - calls Sketch.upload() (see later...)
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
|
||||
// - chiama Sketch.upload() ... to be continued ...
|
||||
Uploader uploader = Compiler.getUploaderByPreferences(parser.isNoUploadPort());
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) showError("...", "...", null);
|
||||
try {
|
||||
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, parser.isDoUseProgrammer(), parser.isNoUploadPort(), warningsAccumulator);
|
||||
showMessage(_("Done uploading"), _("Done uploading"));
|
||||
} finally {
|
||||
if (uploader.requiresAuthorization() && !success) {
|
||||
PreferencesData.remove(uploader.getAuthorizationKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
showError(_("Error while verifying/uploading"), _("An error occurred while verifying/uploading the sketch"), e);
|
||||
}
|
||||
for (String warning : warningsAccumulator) {
|
||||
System.out.print(_("Warning"));
|
||||
System.out.print(": ");
|
||||
System.out.println(warning);
|
||||
}
|
||||
if (!success) showError(_("Error while uploading"), _("An error occurred while uploading the sketch"), null);
|
||||
} else {
|
||||
|
||||
for (String path : parser.getFilenames())
|
||||
{
|
||||
try {
|
||||
// Editor constructor loads sketch with handleOpenInternal() that
|
||||
// creates a new Sketch that calls load() in its constructor
|
||||
// This translates here as:
|
||||
// SketchData data = new SketchData(file);
|
||||
// File tempBuildFolder = getBuildFolder();
|
||||
// data.load();
|
||||
SketchData data = new SketchData(absoluteFile(path));
|
||||
File tempBuildFolder = getBuildFolder();
|
||||
data.load();
|
||||
|
||||
// Sketch.prepare() calls Sketch.ensureExistence()
|
||||
// Sketch.build(verbose) calls Sketch.ensureExistence() and set progressListener and, finally, calls Compiler.build()
|
||||
// This translates here as:
|
||||
// if (!data.getFolder().exists()) showError(...);
|
||||
// String ... = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, verbose);
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
} catch (Exception e) {
|
||||
showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No errors exit gracefully
|
||||
System.exit(0);
|
||||
}
|
||||
else if (parser.isGetPrefMode()) {
|
||||
String value = PreferencesData.get(parser.getGetPref(), null);
|
||||
if (value != null) {
|
||||
System.out.println(value);
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.exit(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void initLogger() {
|
||||
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
|
||||
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
|
||||
}
|
||||
|
||||
static public void initPackages() {
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
if (packages.size() == 0) {
|
||||
System.out.println(_("No valid configured cores found! Exiting..."));
|
||||
System.exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
static protected void initPlatform() {
|
||||
try {
|
||||
Class<?> platformClass = Class.forName("processing.app.Platform");
|
||||
if (OSUtils.isMacOS()) {
|
||||
platformClass = Class.forName("processing.app.macosx.Platform");
|
||||
} else if (OSUtils.isWindows()) {
|
||||
platformClass = Class.forName("processing.app.windows.Platform");
|
||||
} else if (OSUtils.isLinux()) {
|
||||
platformClass = Class.forName("processing.app.linux.Platform");
|
||||
}
|
||||
platform = (Platform) platformClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem Setting the Platform"),
|
||||
_("An unknown error occurred while trying to load\n" +
|
||||
"platform-specific code for your machine."), e);
|
||||
}
|
||||
}
|
||||
|
||||
static public void initPortableFolder() {
|
||||
// Portable folder
|
||||
portableFolder = getContentFile("portable");
|
||||
if (!portableFolder.exists())
|
||||
portableFolder = null;
|
||||
}
|
||||
|
||||
static public void initVersion() {
|
||||
// help 3rd party installers find the correct hardware path
|
||||
PreferencesData.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
|
||||
PreferencesData.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the name is valid for a Processing sketch.
|
||||
*/
|
||||
static public boolean isSanitaryName(String name) {
|
||||
return sanitizeName(name).equals(name);
|
||||
}
|
||||
|
||||
static protected void loadHardware(File folder) {
|
||||
if (!folder.isDirectory()) return;
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null) return;
|
||||
|
||||
// alphabetize list, since it's not always alpha order
|
||||
// replaced hella slow bubble sort with this feller for 0093
|
||||
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (String target : list) {
|
||||
// Skip reserved 'tools' folder.
|
||||
if (target.equals("tools"))
|
||||
continue;
|
||||
File subfolder = new File(folder, target);
|
||||
|
||||
try {
|
||||
packages.put(target, new TargetPackage(target, subfolder));
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println("WARNING: Error loading hardware folder " + target);
|
||||
System.out.println(" " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the contents of a file as a string.
|
||||
*/
|
||||
static public String loadFile(File file) throws IOException {
|
||||
String[] contents = PApplet.loadStrings(file);
|
||||
if (contents == null) return null;
|
||||
return PApplet.join(contents, "\n");
|
||||
}
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
if (args.length == 0)
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
|
||||
initPlatform();
|
||||
|
||||
initPortableFolder();
|
||||
|
||||
initParameters(args);
|
||||
|
||||
init(args);
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
librariesFolders = new ArrayList<File>();
|
||||
librariesFolders.add(getContentFile("libraries"));
|
||||
|
||||
// Add library folder for the current selected platform
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform != null) {
|
||||
String core = getBoardPreferences().get("build.core");
|
||||
if (core.contains(":")) {
|
||||
String referencedCore = core.split(":")[0];
|
||||
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
|
||||
if (referencedPlatform != null) {
|
||||
File referencedPlatformFolder = referencedPlatform.getFolder();
|
||||
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
|
||||
}
|
||||
}
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
librariesFolders.add(new File(platformFolder, "libraries"));
|
||||
librariesFolders.add(getSketchbookLibrariesFolder());
|
||||
}
|
||||
|
||||
// Scan for libraries in each library folder.
|
||||
// Libraries located in the latest folders on the list can override
|
||||
// other libraries with the same name.
|
||||
try {
|
||||
scanAndUpdateLibraries(librariesFolders);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), _("Error loading libraries"), e);
|
||||
}
|
||||
|
||||
populateImportToLibraryTable();
|
||||
}
|
||||
|
||||
static public void populateImportToLibraryTable() {
|
||||
// Populate importToLibraryTable
|
||||
importToLibraryTable = new HashMap<String, Library>();
|
||||
for (Library lib : getLibraries()) {
|
||||
try {
|
||||
String headers[] = headerListFromIncludePath(lib.getSrcFolder());
|
||||
for (String header : headers) {
|
||||
Library old = importToLibraryTable.get(header);
|
||||
if (old != null) {
|
||||
// If a library was already found with this header, keep
|
||||
// it if the library's name matches the header name.
|
||||
String name = header.substring(0, header.length() - 2);
|
||||
if (old.getFolder().getPath().endsWith(name))
|
||||
continue;
|
||||
}
|
||||
importToLibraryTable.put(header, lib);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n
|
||||
.format("Unable to list header files in {0}", lib.getSrcFolder()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void initParameters(String args[]) {
|
||||
String preferencesFile = null;
|
||||
|
||||
// Do a first pass over the commandline arguments, the rest of them
|
||||
// will be processed by the Base constructor. Note that this loop
|
||||
// does not look at the last element of args, to prevent crashing
|
||||
// when no parameter was specified to an option. Later, Base() will
|
||||
// then show an error for these.
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
if (args[i].equals("--preferences-file")) {
|
||||
++i;
|
||||
preferencesFile = args[i];
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--curdir")) {
|
||||
i++;
|
||||
currentDirectory = args[i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
PreferencesData.init(absoluteFile(preferencesFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively remove all files within a directory,
|
||||
* used with removeDir(), or when the contents of a dir
|
||||
* should be removed, but not the directory itself.
|
||||
* (i.e. when cleaning temp files from lib/build)
|
||||
*/
|
||||
static public void removeDescendants(File dir) {
|
||||
if (!dir.exists()) return;
|
||||
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
File dead = new File(dir, files[i]);
|
||||
if (!dead.isDirectory()) {
|
||||
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
|
||||
if (!dead.delete()) {
|
||||
// temporarily disabled
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
removeDir(dead);
|
||||
//dead.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all files in a directory and the directory itself.
|
||||
*/
|
||||
static public void removeDir(File dir) {
|
||||
if (dir.exists()) {
|
||||
removeDescendants(dir);
|
||||
if (!dir.delete()) {
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a sanitized name that fits our standards for likely to work.
|
||||
* <p/>
|
||||
* Java classes have a wider range of names that are technically allowed
|
||||
* (supposedly any Unicode name) than what we support. The reason for
|
||||
* going more narrow is to avoid situations with text encodings and
|
||||
* converting during the process of moving files between operating
|
||||
* systems, i.e. uploading from a Windows machine to a Linux server,
|
||||
* or reading a FAT32 partition in OS X and using a thumb drive.
|
||||
* <p/>
|
||||
* This helper function replaces everything but A-Z, a-z, and 0-9 with
|
||||
* underscores. Also disallows starting the sketch name with a digit.
|
||||
*/
|
||||
static public String sanitizeName(String origName) {
|
||||
char c[] = origName.toCharArray();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
// can't lead with a digit, so start with an underscore
|
||||
if ((c[0] >= '0') && (c[0] <= '9')) {
|
||||
buffer.append('_');
|
||||
}
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (((c[i] >= '0') && (c[i] <= '9')) ||
|
||||
((c[i] >= 'a') && (c[i] <= 'z')) ||
|
||||
((c[i] >= 'A') && (c[i] <= 'Z')) ||
|
||||
((i > 0) && (c[i] == '-')) ||
|
||||
((i > 0) && (c[i] == '.'))) {
|
||||
buffer.append(c[i]);
|
||||
} else {
|
||||
buffer.append('_');
|
||||
}
|
||||
}
|
||||
// let's not be ridiculous about the length of filenames.
|
||||
// in fact, Mac OS 9 can handle 255 chars, though it can't really
|
||||
// deal with filenames longer than 31 chars in the Finder.
|
||||
// but limiting to that for sketches would mean setting the
|
||||
// upper-bound on the character limit here to 25 characters
|
||||
// (to handle the base name + ".class")
|
||||
if (buffer.length() > 63) {
|
||||
buffer.setLength(63);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Spew the contents of a String object out to a file.
|
||||
*/
|
||||
static public void saveFile(String str, File file) throws IOException {
|
||||
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
|
||||
PApplet.saveStrings(temp, new String[] { str });
|
||||
if (file.exists()) {
|
||||
boolean result = file.delete();
|
||||
if (!result) {
|
||||
throw new IOException(
|
||||
I18n.format(
|
||||
_("Could not remove old version of {0}"),
|
||||
file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
boolean result = temp.renameTo(file);
|
||||
if (!result) {
|
||||
throw new IOException(
|
||||
I18n.format(
|
||||
_("Could not replace {0}"),
|
||||
file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
static public void scanAndUpdateLibraries(List<File> folders) throws IOException {
|
||||
libraries = scanLibraries(folders);
|
||||
}
|
||||
|
||||
static public LibraryList scanLibraries(List<File> folders) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
for (File folder : folders)
|
||||
res.addOrReplaceAll(scanLibraries(folder));
|
||||
return res;
|
||||
}
|
||||
|
||||
static public LibraryList scanLibraries(File folder) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null)
|
||||
return res;
|
||||
|
||||
for (String libName : list) {
|
||||
File subfolder = new File(folder, libName);
|
||||
if (!isSanitaryName(libName)) {
|
||||
String mess = I18n.format(_("The library \"{0}\" 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)"),
|
||||
libName);
|
||||
showMessage(_("Ignoring bad library name"), mess);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Library lib = Library.create(subfolder);
|
||||
// (also replace previously found libs with the same name)
|
||||
if (lib != null)
|
||||
res.addOrReplace(lib);
|
||||
} catch (IOException e) {
|
||||
System.out.println(I18n.format(_("Invalid library found in {0}: {1}"),
|
||||
subfolder, e.getMessage()));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static public void selectBoard(TargetBoard targetBoard) {
|
||||
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
|
||||
TargetPackage targetPackage = targetPlatform.getContainerPackage();
|
||||
|
||||
PreferencesData.set("target_package", targetPackage.getId());
|
||||
PreferencesData.set("target_platform", targetPlatform.getId());
|
||||
PreferencesData.set("board", targetBoard.getId());
|
||||
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
PreferencesData.set("runtime.platform.path", platformFolder.getAbsolutePath());
|
||||
PreferencesData.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
public static void selectSerialPort(String port) {
|
||||
PreferencesData.set("serial.port", port);
|
||||
if (port.startsWith("/dev/"))
|
||||
PreferencesData.set("serial.port.file", port.substring(5));
|
||||
else
|
||||
PreferencesData.set("serial.port.file", port);
|
||||
}
|
||||
|
||||
public static void setBuildFolder(File newBuildFolder) {
|
||||
buildFolder = newBuildFolder;
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, int exit_code) {
|
||||
showError(title, message, null, exit_code);
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, Throwable e) {
|
||||
notifier.showError(title, message, e, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, int exit_code) {
|
||||
notifier.showError(title, message, e, exit_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* "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) {
|
||||
notifier.showMessage(title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-fatal error message with optional stack trace side dish.
|
||||
*/
|
||||
static public void showWarning(String title, String message, Exception e) {
|
||||
notifier.showWarning(title, message, e);
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ import com.sun.jna.Native;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.core.PConstants;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
|
||||
/**
|
||||
@ -54,7 +54,6 @@ import processing.core.PConstants;
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
Base base;
|
||||
|
||||
|
||||
/**
|
||||
@ -74,8 +73,7 @@ public class Platform {
|
||||
}
|
||||
|
||||
|
||||
public void init(Base base) {
|
||||
this.base = base;
|
||||
public void init() {
|
||||
}
|
||||
|
||||
|
||||
@ -112,7 +110,7 @@ public class Platform {
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
String launcher = Preferences.get("launcher");
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
Runtime.getRuntime().exec(new String[] { launcher, url });
|
||||
} else {
|
||||
@ -122,12 +120,12 @@ public class Platform {
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
return Preferences.get("launcher") != null;
|
||||
return PreferencesData.get("launcher") != null;
|
||||
}
|
||||
|
||||
|
||||
public void openFolder(File file) throws Exception {
|
||||
String launcher = Preferences.get("launcher");
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
String folder = file.getAbsolutePath();
|
||||
Runtime.getRuntime().exec(new String[] { launcher, folder });
|
||||
@ -215,8 +213,8 @@ public class Platform {
|
||||
|
||||
|
||||
protected void showLauncherWarning() {
|
||||
Base.showWarning(_("No launcher available"),
|
||||
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
||||
null);
|
||||
BaseNoGui.showWarning(_("No launcher available"),
|
||||
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
||||
null);
|
||||
}
|
||||
}
|
214
arduino-core/src/processing/app/PreferencesData.java
Normal file
214
arduino-core/src/processing/app/PreferencesData.java
Normal file
@ -0,0 +1,214 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
|
||||
public class PreferencesData {
|
||||
|
||||
static final String PREFS_FILE = "preferences.txt";
|
||||
|
||||
// data model
|
||||
|
||||
static PreferencesMap defaults;
|
||||
static PreferencesMap prefs = new PreferencesMap();
|
||||
static File preferencesFile;
|
||||
static boolean doSave = true;
|
||||
|
||||
|
||||
static public void init(File file) {
|
||||
if (file != null)
|
||||
preferencesFile = file;
|
||||
else
|
||||
preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE);
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
try {
|
||||
prefs.load(BaseNoGui.getLibStream("preferences.txt"));
|
||||
} catch (IOException e) {
|
||||
BaseNoGui.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = BaseNoGui.getHardwareFolder();
|
||||
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);
|
||||
|
||||
// clone the hash table
|
||||
defaults = new PreferencesMap(prefs);
|
||||
|
||||
if (preferencesFile.exists()) {
|
||||
// load the previous preferences file
|
||||
try {
|
||||
prefs.load(preferencesFile);
|
||||
} catch (IOException ex) {
|
||||
BaseNoGui.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
// load the I18n module for internationalization
|
||||
try {
|
||||
I18n.init(get("editor.languages.current"));
|
||||
} catch (MissingResourceException e) {
|
||||
I18n.init("en");
|
||||
set("editor.languages.current", "en");
|
||||
}
|
||||
|
||||
// set some other runtime constants (not saved on preferences file)
|
||||
set("runtime.os", PConstants.platformNames[PApplet.platform]);
|
||||
|
||||
fixPreferences();
|
||||
}
|
||||
|
||||
private static void fixPreferences() {
|
||||
String baud = get("serial.debug_rate");
|
||||
if ("14400".equals(baud) || "28800".equals(baud)) {
|
||||
set("serial.debug_rate", "9600");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public String[] loadStrings(InputStream input) {
|
||||
try {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(input, "UTF-8"));
|
||||
|
||||
String lines[] = new String[100];
|
||||
int lineCount = 0;
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (lineCount == lines.length) {
|
||||
String temp[] = new String[lineCount << 1];
|
||||
System.arraycopy(lines, 0, temp, 0, lineCount);
|
||||
lines = temp;
|
||||
}
|
||||
lines[lineCount++] = line;
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (lineCount == lines.length) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// resize array to appropriate amount for these lines
|
||||
String output[] = new String[lineCount];
|
||||
System.arraycopy(lines, 0, output, 0, lineCount);
|
||||
return output;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static protected void save() {
|
||||
if (!doSave)
|
||||
return;
|
||||
|
||||
// on startup, don't worry about it
|
||||
// this is trying to update the prefs for who is open
|
||||
// before Preferences.init() has been called.
|
||||
if (preferencesFile == null) return;
|
||||
|
||||
// Fix for 0163 to properly use Unicode when writing preferences.txt
|
||||
PrintWriter writer = PApplet.createWriter(preferencesFile);
|
||||
|
||||
String[] keys = prefs.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keys);
|
||||
for (String key: keys) {
|
||||
if (key.startsWith("runtime."))
|
||||
continue;
|
||||
writer.println(key + "=" + prefs.get(key));
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
static public String get(String attribute) {
|
||||
return prefs.get(attribute);
|
||||
}
|
||||
|
||||
static public String get(String attribute, String defaultValue) {
|
||||
String value = get(attribute);
|
||||
return (value == null) ? defaultValue : value;
|
||||
}
|
||||
|
||||
public static boolean has(String key) {
|
||||
return prefs.containsKey(key);
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
prefs.remove(key);
|
||||
}
|
||||
|
||||
static public String getDefault(String attribute) {
|
||||
return defaults.get(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void set(String attribute, String value) {
|
||||
prefs.put(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public void unset(String attribute) {
|
||||
prefs.remove(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public boolean getBoolean(String attribute) {
|
||||
return prefs.getBoolean(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void setBoolean(String attribute, boolean value) {
|
||||
prefs.putBoolean(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public int getInteger(String attribute) {
|
||||
return Integer.parseInt(get(attribute));
|
||||
}
|
||||
|
||||
|
||||
static public void setInteger(String key, int value) {
|
||||
set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
// get a copy of the Preferences
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
return new PreferencesMap(prefs);
|
||||
}
|
||||
|
||||
// Decide wether changed preferences will be saved. When value is
|
||||
// false, Preferences.save becomes a no-op.
|
||||
static public void setDoSave(boolean value)
|
||||
{
|
||||
doSave = value;
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
PSerial - class for serial port goodness
|
||||
Part of the Processing project - http://processing.org
|
||||
@ -34,7 +32,6 @@ import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
import processing.app.debug.MessageConsumer;
|
||||
|
||||
|
||||
public class Serial implements SerialPortEventListener {
|
||||
@ -54,49 +51,33 @@ public class Serial implements SerialPortEventListener {
|
||||
int parity;
|
||||
int databits;
|
||||
int stopbits;
|
||||
boolean monitor = false;
|
||||
|
||||
byte buffer[] = new byte[32768];
|
||||
int bufferIndex;
|
||||
int bufferLast;
|
||||
|
||||
MessageConsumer consumer;
|
||||
|
||||
public Serial(boolean monitor) throws SerialException {
|
||||
this(Preferences.get("serial.port"),
|
||||
Preferences.getInteger("serial.debug_rate"),
|
||||
Preferences.get("serial.parity").charAt(0),
|
||||
Preferences.getInteger("serial.databits"),
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
public Serial() throws SerialException {
|
||||
this(Preferences.get("serial.port"),
|
||||
Preferences.getInteger("serial.debug_rate"),
|
||||
Preferences.get("serial.parity").charAt(0),
|
||||
Preferences.getInteger("serial.databits"),
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
this(PreferencesData.get("serial.port"),
|
||||
PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(int irate) throws SerialException {
|
||||
this(Preferences.get("serial.port"), irate,
|
||||
Preferences.get("serial.parity").charAt(0),
|
||||
Preferences.getInteger("serial.databits"),
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
this(PreferencesData.get("serial.port"), irate,
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate) throws SerialException {
|
||||
this(iname, irate, Preferences.get("serial.parity").charAt(0),
|
||||
Preferences.getInteger("serial.databits"),
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(String iname) throws SerialException {
|
||||
this(iname, Preferences.getInteger("serial.debug_rate"),
|
||||
Preferences.get("serial.parity").charAt(0),
|
||||
Preferences.getInteger("serial.databits"),
|
||||
new Float(Preferences.get("serial.stopbits")).floatValue());
|
||||
this(iname, PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public static boolean touchPort(String iname, int irate) throws SerialException {
|
||||
@ -168,26 +149,14 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(MessageConsumer consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public synchronized void serialEvent(SerialPortEvent serialEvent) {
|
||||
if (serialEvent.isRXCHAR()) {
|
||||
try {
|
||||
byte[] buf = port.readBytes(serialEvent.getEventValue());
|
||||
if (buf.length > 0) {
|
||||
if (bufferLast == buffer.length) {
|
||||
byte temp[] = new byte[bufferLast << 1];
|
||||
System.arraycopy(buffer, 0, temp, 0, bufferLast);
|
||||
buffer = temp;
|
||||
}
|
||||
if (monitor) {
|
||||
System.out.print(new String(buf));
|
||||
}
|
||||
if (this.consumer != null) {
|
||||
this.consumer.message(new String(buf));
|
||||
}
|
||||
String msg = new String(buf);
|
||||
char[] chars = msg.toCharArray();
|
||||
message(chars, chars.length);
|
||||
}
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("serialEvent", e);
|
||||
@ -195,199 +164,15 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that have been read from serial
|
||||
* and are waiting to be dealt with by the user.
|
||||
* This method is intented to be extended to receive messages
|
||||
* coming from serial port.
|
||||
*
|
||||
* @param chars
|
||||
* @param length
|
||||
*/
|
||||
public synchronized int available() {
|
||||
return (bufferLast - bufferIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ignore all the bytes read so far and empty the buffer.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
bufferLast = 0;
|
||||
bufferIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a number between 0 and 255 for the next byte that's
|
||||
* waiting in the buffer.
|
||||
* Returns -1 if there was no byte (although the user should
|
||||
* first check available() to see if things are ready to avoid this)
|
||||
*/
|
||||
public synchronized int read() {
|
||||
if (bufferIndex == bufferLast) return -1;
|
||||
|
||||
int outgoing = buffer[bufferIndex++] & 0xff;
|
||||
if (bufferIndex == bufferLast) { // rewind
|
||||
bufferIndex = 0;
|
||||
bufferLast = 0;
|
||||
}
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next byte in the buffer as a char.
|
||||
* Returns -1, or 0xffff, if nothing is there.
|
||||
*/
|
||||
public synchronized char readChar() {
|
||||
if (bufferIndex == bufferLast) return (char) (-1);
|
||||
return (char) read();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a byte array of anything that's in the serial buffer.
|
||||
* Not particularly memory/speed efficient, because it creates
|
||||
* a byte array on each read, but it's easier to use than
|
||||
* readBytes(byte b[]) (see below).
|
||||
*/
|
||||
public synchronized byte[] readBytes() {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
|
||||
int length = bufferLast - bufferIndex;
|
||||
byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab whatever is in the serial buffer, and stuff it into a
|
||||
* byte buffer passed in by the user. This is more memory/time
|
||||
* efficient than readBytes() returning a byte[] array.
|
||||
* <p/>
|
||||
* Returns an int for how many bytes were read. If more bytes
|
||||
* are available than can fit into the byte array, only those
|
||||
* that will fit are read.
|
||||
*/
|
||||
public synchronized int readBytes(byte outgoing[]) {
|
||||
if (bufferIndex == bufferLast) return 0;
|
||||
|
||||
int length = bufferLast - bufferIndex;
|
||||
if (length > outgoing.length) length = outgoing.length;
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex += length;
|
||||
if (bufferIndex == bufferLast) {
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads from the serial port into a buffer of bytes up to and
|
||||
* including a particular character. If the character isn't in
|
||||
* the serial buffer, then 'null' is returned.
|
||||
*/
|
||||
public synchronized byte[] readBytesUntil(int interesting) {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
byte what = (byte) interesting;
|
||||
|
||||
int found = -1;
|
||||
for (int k = bufferIndex; k < bufferLast; k++) {
|
||||
if (buffer[k] == what) {
|
||||
found = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == -1) return null;
|
||||
|
||||
int length = found - bufferIndex + 1;
|
||||
byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads from the serial port into a buffer of bytes until a
|
||||
* particular character. If the character isn't in the serial
|
||||
* buffer, then 'null' is returned.
|
||||
* <p/>
|
||||
* If outgoing[] is not big enough, then -1 is returned,
|
||||
* and an error message is printed on the console.
|
||||
* If nothing is in the buffer, zero is returned.
|
||||
* If 'interesting' byte is not in the buffer, then 0 is returned.
|
||||
*/
|
||||
public synchronized int readBytesUntil(int interesting, byte outgoing[]) {
|
||||
if (bufferIndex == bufferLast) return 0;
|
||||
byte what = (byte) interesting;
|
||||
|
||||
int found = -1;
|
||||
for (int k = bufferIndex; k < bufferLast; k++) {
|
||||
if (buffer[k] == what) {
|
||||
found = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == -1) return 0;
|
||||
|
||||
int length = found - bufferIndex + 1;
|
||||
if (length > outgoing.length) {
|
||||
System.err.println(
|
||||
I18n.format(
|
||||
_("readBytesUntil() byte buffer is too small for the {0}" +
|
||||
" bytes up to and including char {1}"),
|
||||
length,
|
||||
interesting
|
||||
)
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
//byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex += length;
|
||||
if (bufferIndex == bufferLast) {
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whatever has been read from the serial port so far
|
||||
* as a String. It assumes that the incoming characters are ASCII.
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*/
|
||||
public synchronized String readString() {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
return new String(readBytes());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combination of readBytesUntil and readString. See caveats in
|
||||
* each function. Returns null if it still hasn't found what
|
||||
* you're looking for.
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*/
|
||||
public synchronized String readStringUntil(int interesting) {
|
||||
byte b[] = readBytesUntil(interesting);
|
||||
if (b == null) return null;
|
||||
return new String(b);
|
||||
protected void message(char[] chars, int length) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ package processing.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialException extends IOException {
|
||||
public SerialException() {
|
||||
super();
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Copyright (c) 2007 David A. Mellis
|
||||
|
||||
@ -20,6 +18,7 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialNotFoundException extends SerialException {
|
||||
public SerialNotFoundException() {
|
||||
super();
|
@ -1,5 +1,3 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
SketchCode - data class for a single file inside a sketch
|
||||
Part of the Processing project - http://processing.org
|
||||
@ -25,54 +23,44 @@
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import javax.swing.text.Document;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
/**
|
||||
* Represents a single tab of a sketch.
|
||||
*/
|
||||
public class SketchCode {
|
||||
|
||||
/** Pretty name (no extension), not the full file name */
|
||||
private String prettyName;
|
||||
|
||||
/** File object for where this code is located */
|
||||
private File file;
|
||||
|
||||
/** Extension for this file (no dots, and in lowercase). */
|
||||
private String extension;
|
||||
|
||||
/** Text of the program text for this tab */
|
||||
private String program;
|
||||
|
||||
/** Document object for this tab. Currently this is a SyntaxDocument. */
|
||||
private Document document;
|
||||
|
||||
/**
|
||||
* Undo Manager for this tab, each tab keeps track of their own
|
||||
* Editor.undo will be set to this object when this code is the tab
|
||||
* that's currently the front.
|
||||
*/
|
||||
private LastUndoableEditAwareUndoManager undo = new LastUndoableEditAwareUndoManager();
|
||||
|
||||
// saved positions from last time this tab was used
|
||||
private int selectionStart;
|
||||
private int selectionStop;
|
||||
private int scrollPosition;
|
||||
|
||||
private boolean modified;
|
||||
|
||||
/** name of .java file after preproc */
|
||||
// private String preprocName;
|
||||
/** where this code starts relative to the concat'd code */
|
||||
private int preprocOffset;
|
||||
|
||||
private Object metadata;
|
||||
|
||||
public SketchCode(File file, String extension) {
|
||||
public SketchCode(File file) {
|
||||
init(file, null);
|
||||
}
|
||||
|
||||
public SketchCode(File file, Object metadata) {
|
||||
init(file, metadata);
|
||||
}
|
||||
|
||||
private void init(File file, Object metadata) {
|
||||
this.file = file;
|
||||
this.extension = extension;
|
||||
this.metadata = metadata;
|
||||
|
||||
makePrettyName();
|
||||
|
||||
@ -125,11 +113,10 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected boolean renameTo(File what, String ext) {
|
||||
protected boolean renameTo(File what) {
|
||||
boolean success = file.renameTo(what);
|
||||
if (success) {
|
||||
file = what;
|
||||
extension = ext;
|
||||
makePrettyName();
|
||||
}
|
||||
return success;
|
||||
@ -137,7 +124,7 @@ public class SketchCode {
|
||||
|
||||
|
||||
protected void copyTo(File dest) throws IOException {
|
||||
Base.saveFile(program, dest);
|
||||
BaseNoGui.saveFile(program, dest);
|
||||
}
|
||||
|
||||
|
||||
@ -151,13 +138,12 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
public String getExtension() {
|
||||
return extension;
|
||||
public boolean isExtension(String... extensions) {
|
||||
return isExtension(Arrays.asList(extensions));
|
||||
}
|
||||
|
||||
|
||||
public boolean isExtension(String what) {
|
||||
return extension.equals(what);
|
||||
|
||||
public boolean isExtension(List<String> extensions) {
|
||||
return FileUtils.hasExtension(file, extensions);
|
||||
}
|
||||
|
||||
|
||||
@ -172,7 +158,7 @@ public class SketchCode {
|
||||
|
||||
|
||||
public int getLineCount() {
|
||||
return Base.countLines(program);
|
||||
return BaseNoGui.countLines(program);
|
||||
}
|
||||
|
||||
|
||||
@ -186,16 +172,6 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
// public void setPreprocName(String preprocName) {
|
||||
// this.preprocName = preprocName;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public String getPreprocName() {
|
||||
// return preprocName;
|
||||
// }
|
||||
|
||||
|
||||
public void setPreprocOffset(int preprocOffset) {
|
||||
this.preprocOffset = preprocOffset;
|
||||
}
|
||||
@ -211,51 +187,6 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
public Document getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
|
||||
public void setDocument(Document d) {
|
||||
document = d;
|
||||
}
|
||||
|
||||
|
||||
public LastUndoableEditAwareUndoManager getUndo() {
|
||||
return undo;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
// TODO these could probably be handled better, since it's a general state
|
||||
// issue that's read/write from only one location in Editor (on tab switch.)
|
||||
|
||||
|
||||
public int getSelectionStart() {
|
||||
return selectionStart;
|
||||
}
|
||||
|
||||
|
||||
public int getSelectionStop() {
|
||||
return selectionStop;
|
||||
}
|
||||
|
||||
|
||||
public int getScrollPosition() {
|
||||
return scrollPosition;
|
||||
}
|
||||
|
||||
|
||||
protected void setState(String p, int start, int stop, int pos) {
|
||||
program = p;
|
||||
selectionStart = start;
|
||||
selectionStop = stop;
|
||||
scrollPosition = pos;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
@ -263,7 +194,7 @@ public class SketchCode {
|
||||
* Load this piece of code from a file.
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
program = Base.loadFile(file);
|
||||
program = BaseNoGui.loadFile(file);
|
||||
|
||||
if (program.indexOf('\uFFFD') != -1) {
|
||||
System.err.println(
|
||||
@ -291,7 +222,7 @@ public class SketchCode {
|
||||
// TODO re-enable history
|
||||
//history.record(s, SketchHistory.SAVE);
|
||||
|
||||
Base.saveFile(program, file);
|
||||
BaseNoGui.saveFile(program, file);
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
@ -300,6 +231,16 @@ public class SketchCode {
|
||||
* Save this file to another location, used by Sketch.saveAs()
|
||||
*/
|
||||
public void saveAs(File newFile) throws IOException {
|
||||
Base.saveFile(program, newFile);
|
||||
BaseNoGui.saveFile(program, newFile);
|
||||
}
|
||||
|
||||
|
||||
public Object getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
public void setMetadata(Object metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
266
arduino-core/src/processing/app/SketchData.java
Normal file
266
arduino-core/src/processing/app/SketchData.java
Normal file
@ -0,0 +1,266 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SketchData {
|
||||
|
||||
/** main pde file for this sketch. */
|
||||
private File primaryFile;
|
||||
|
||||
/** folder that contains this sketch */
|
||||
private File folder;
|
||||
|
||||
/** data folder location for this sketch (may not exist yet) */
|
||||
private File dataFolder;
|
||||
|
||||
/** code folder location for this sketch (may not exist yet) */
|
||||
private File codeFolder;
|
||||
|
||||
/**
|
||||
* Name of sketch, which is the name of main file (without .pde or .java
|
||||
* extension)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private List<SketchCode> codes = new ArrayList<SketchCode>();
|
||||
|
||||
private static final Comparator<SketchCode> CODE_DOCS_COMPARATOR = new Comparator<SketchCode>() {
|
||||
@Override
|
||||
public int compare(SketchCode x, SketchCode y) {
|
||||
return x.getFileName().compareTo(y.getFileName());
|
||||
}
|
||||
};
|
||||
|
||||
SketchData(File file) {
|
||||
primaryFile = file;
|
||||
|
||||
// get the name of the sketch by chopping .pde or .java
|
||||
// off of the main file name
|
||||
String mainFilename = primaryFile.getName();
|
||||
int suffixLength = getDefaultExtension().length() + 1;
|
||||
name = mainFilename.substring(0, mainFilename.length() - suffixLength);
|
||||
|
||||
folder = new File(file.getParent());
|
||||
//System.out.println("sketch dir is " + folder);
|
||||
}
|
||||
|
||||
static public File checkSketchFile(File file) {
|
||||
// check to make sure that this .pde file is
|
||||
// in a folder of the same name
|
||||
String fileName = file.getName();
|
||||
File parent = file.getParentFile();
|
||||
String parentName = parent.getName();
|
||||
String pdeName = parentName + ".pde";
|
||||
File altPdeFile = new File(parent, pdeName);
|
||||
String inoName = parentName + ".ino";
|
||||
File altInoFile = new File(parent, inoName);
|
||||
|
||||
if (pdeName.equals(fileName) || inoName.equals(fileName))
|
||||
return file;
|
||||
|
||||
if (altPdeFile.exists())
|
||||
return altPdeFile;
|
||||
|
||||
if (altInoFile.exists())
|
||||
return altInoFile;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the list of files.
|
||||
* <P>
|
||||
* Generally this is only done once, rather than
|
||||
* each time a change is made, because otherwise it gets to be
|
||||
* a nightmare to keep track of what files went where, because
|
||||
* not all the data will be saved to disk.
|
||||
* <P>
|
||||
* This also gets called when the main sketch file is renamed,
|
||||
* because the sketch has to be reloaded from a different folder.
|
||||
* <P>
|
||||
* Another exception is when an external editor is in use,
|
||||
* in which case the load happens each time "run" is hit.
|
||||
*/
|
||||
protected void load() throws IOException {
|
||||
codeFolder = new File(folder, "code");
|
||||
dataFolder = new File(folder, "data");
|
||||
|
||||
// get list of files in the sketch folder
|
||||
String list[] = folder.list();
|
||||
|
||||
// reset these because load() may be called after an
|
||||
// external editor event. (fix for 0099)
|
||||
// codeDocs = new SketchCodeDoc[list.length];
|
||||
clearCodeDocs();
|
||||
// data.setCodeDocs(codeDocs);
|
||||
|
||||
List<String> extensions = getExtensions();
|
||||
|
||||
for (String filename : list) {
|
||||
// Ignoring the dot prefix files is especially important to avoid files
|
||||
// with the ._ prefix on Mac OS X. (You'll see this with Mac files on
|
||||
// non-HFS drives, i.e. a thumb drive formatted FAT32.)
|
||||
if (filename.startsWith(".")) continue;
|
||||
|
||||
// Don't let some wacko name a directory blah.pde or bling.java.
|
||||
if (new File(folder, filename).isDirectory()) continue;
|
||||
|
||||
// figure out the name without any extension
|
||||
String base = filename;
|
||||
// now strip off the .pde and .java extensions
|
||||
for (String extension : extensions) {
|
||||
if (base.toLowerCase().endsWith("." + extension)) {
|
||||
base = base.substring(0, base.length() - (extension.length() + 1));
|
||||
|
||||
// Don't allow people to use files with invalid names, since on load,
|
||||
// it would be otherwise possible to sneak in nasty filenames. [0116]
|
||||
if (BaseNoGui.isSanitaryName(base)) {
|
||||
addCode(new SketchCode(new File(folder, filename)));
|
||||
} else {
|
||||
System.err.println(I18n.format("File name {0} is invalid: ignored", filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getCodeCount() == 0)
|
||||
throw new IOException(_("No valid code files found"));
|
||||
|
||||
// move the main class to the first tab
|
||||
// start at 1, if it's at zero, don't bother
|
||||
for (SketchCode code : getCodes()) {
|
||||
//if (code[i].file.getName().equals(mainFilename)) {
|
||||
if (code.getFile().equals(primaryFile)) {
|
||||
moveCodeToFront(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// sort the entries at the top
|
||||
sortCode();
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
for (SketchCode code : getCodes()) {
|
||||
if (code.isModified())
|
||||
code.save();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCodeCount() {
|
||||
return codes.size();
|
||||
}
|
||||
|
||||
public SketchCode[] getCodes() {
|
||||
return codes.toArray(new SketchCode[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default extension for this editor setup.
|
||||
*/
|
||||
public String getDefaultExtension() {
|
||||
return "ino";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String[] array of proper extensions.
|
||||
*/
|
||||
public List<String> getExtensions() {
|
||||
return Arrays.asList("ino", "pde", "c", "cpp", "h");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file object for the primary .pde of this sketch.
|
||||
*/
|
||||
public File getPrimaryFile() {
|
||||
return primaryFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path to the main .pde file for this sketch.
|
||||
*/
|
||||
public String getMainFilePath() {
|
||||
return primaryFile.getAbsolutePath();
|
||||
//return code[0].file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public void addCode(SketchCode sketchCode) {
|
||||
codes.add(sketchCode);
|
||||
}
|
||||
|
||||
public void moveCodeToFront(SketchCode codeDoc) {
|
||||
codes.remove(codeDoc);
|
||||
codes.add(0, codeDoc);
|
||||
}
|
||||
|
||||
protected void replaceCode(SketchCode newCode) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code.getFileName().equals(newCode.getFileName())) {
|
||||
codes.set(codes.indexOf(code), newCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void sortCode() {
|
||||
if (codes.size() < 2)
|
||||
return;
|
||||
SketchCode first = codes.remove(0);
|
||||
Collections.sort(codes, CODE_DOCS_COMPARATOR);
|
||||
codes.add(0, first);
|
||||
}
|
||||
|
||||
public SketchCode getCode(int i) {
|
||||
return codes.get(i);
|
||||
}
|
||||
|
||||
protected void removeCode(SketchCode which) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code == which) {
|
||||
codes.remove(code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.err.println("removeCode: internal error.. could not find code");
|
||||
}
|
||||
|
||||
public int indexOfCode(SketchCode who) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code == who)
|
||||
return codes.indexOf(code);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void clearCodeDocs() {
|
||||
codes.clear();
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public File getCodeFolder() {
|
||||
return codeFolder;
|
||||
}
|
||||
}
|
@ -27,69 +27,333 @@ import static processing.app.I18n._;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import processing.app.Base;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.packages.UploaderFactory;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.ProcessUtils;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
import processing.app.SketchData;
|
||||
import processing.app.helpers.*;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.packages.Library;
|
||||
import processing.core.PApplet;
|
||||
import processing.app.packages.LibraryList;
|
||||
import processing.app.preproc.PdePreprocessor;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
public class Compiler implements MessageConsumer {
|
||||
|
||||
private Sketch sketch;
|
||||
/**
|
||||
* File inside the build directory that contains the build options
|
||||
* used for the last build.
|
||||
*/
|
||||
static final public String BUILD_PREFS_FILE = "buildprefs.txt";
|
||||
|
||||
private SketchData sketch;
|
||||
private PreferencesMap prefs;
|
||||
private boolean verbose;
|
||||
|
||||
private List<File> objectFiles;
|
||||
|
||||
private PreferencesMap prefs;
|
||||
private boolean verbose;
|
||||
private boolean sketchIsCompiled;
|
||||
private String targetArch;
|
||||
|
||||
private RunnerException exception;
|
||||
|
||||
/**
|
||||
* Listener interface for progress update on the GUI
|
||||
*/
|
||||
public interface ProgressListener {
|
||||
public void progress(int percent);
|
||||
}
|
||||
|
||||
private ProgressListener progressListener;
|
||||
|
||||
static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException, PreferencesMapException {
|
||||
if (SketchData.checkSketchFile(data.getPrimaryFile()) == null)
|
||||
BaseNoGui.showError(_("Bad file selected"),
|
||||
_("Bad sketch primary file or bad sketch directory structure"), null);
|
||||
|
||||
String primaryClassName = data.getName() + ".cpp";
|
||||
Compiler compiler = new Compiler(data, buildPath, primaryClassName);
|
||||
File buildPrefsFile = new File(buildPath, BUILD_PREFS_FILE);
|
||||
String newBuildPrefs = compiler.buildPrefsString();
|
||||
|
||||
// Do a forced cleanup (throw everything away) if the previous
|
||||
// build settings do not match the previous ones
|
||||
boolean prefsChanged = compiler.buildPreferencesChanged(buildPrefsFile, newBuildPrefs);
|
||||
compiler.cleanup(prefsChanged, tempBuildFolder);
|
||||
|
||||
if (prefsChanged) {
|
||||
try {
|
||||
PrintWriter out = new PrintWriter(buildPrefsFile);
|
||||
out.print(newBuildPrefs);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(_("Could not write build preferences file"));
|
||||
}
|
||||
}
|
||||
|
||||
compiler.setProgressListener(progListener);
|
||||
|
||||
// compile the program. errors will happen as a RunnerException
|
||||
// that will bubble up to whomever called build().
|
||||
if (compiler.compile(verbose)) {
|
||||
compiler.size(compiler.getBuildPreferences());
|
||||
return primaryClassName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static public Uploader getUploaderByPreferences(boolean noUploadPort) {
|
||||
TargetPlatform target = BaseNoGui.getTargetPlatform();
|
||||
String board = PreferencesData.get("board");
|
||||
|
||||
if (noUploadPort)
|
||||
{
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), null, noUploadPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, boolean noUploadPort, List<String> warningsAccumulator) throws Exception {
|
||||
|
||||
if (uploader == null)
|
||||
uploader = getUploaderByPreferences(noUploadPort);
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
|
||||
BaseNoGui.showError(_("Authorization required"),
|
||||
_("No athorization data found"), null);
|
||||
}
|
||||
|
||||
boolean useNewWarningsAccumulator = false;
|
||||
if (warningsAccumulator == null) {
|
||||
warningsAccumulator = new LinkedList<String>();
|
||||
useNewWarningsAccumulator = true;
|
||||
}
|
||||
|
||||
try {
|
||||
success = uploader.uploadUsingPreferences(data.getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
|
||||
} finally {
|
||||
if (uploader.requiresAuthorization() && !success) {
|
||||
PreferencesData.remove(uploader.getAuthorizationKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (useNewWarningsAccumulator) {
|
||||
for (String warning : warningsAccumulator) {
|
||||
System.out.print(_("Warning"));
|
||||
System.out.print(": ");
|
||||
System.out.println(warning);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Compiler
|
||||
* @param _sketch Sketch object to be compiled.
|
||||
* @param _buildPath Where the temporary files live and will be built from.
|
||||
* @param _primaryClassName the name of the combined sketch file w/ extension
|
||||
*/
|
||||
public Compiler(Sketch _sketch, String _buildPath, String _primaryClassName)
|
||||
public Compiler(SketchData _sketch, String _buildPath, String _primaryClassName)
|
||||
throws RunnerException {
|
||||
sketch = _sketch;
|
||||
prefs = createBuildPreferences(_buildPath, _primaryClassName);
|
||||
|
||||
// Start with an empty progress listener
|
||||
progressListener = new ProgressListener() {
|
||||
@Override
|
||||
public void progress(int percent) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the build preferences used on the previous build in
|
||||
* buildPath match the ones given.
|
||||
*/
|
||||
protected boolean buildPreferencesChanged(File buildPrefsFile, String newBuildPrefs) {
|
||||
// No previous build, so no match
|
||||
if (!buildPrefsFile.exists())
|
||||
return true;
|
||||
|
||||
String previousPrefs;
|
||||
try {
|
||||
previousPrefs = FileUtils.readFileToString(buildPrefsFile);
|
||||
} catch (IOException e) {
|
||||
System.err.println(_("Could not read prevous build preferences file, rebuilding all"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!previousPrefs.equals(newBuildPrefs)) {
|
||||
System.out.println(_("Build options changed, rebuilding all"));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the build preferences of the given compiler as a string.
|
||||
* Only includes build-specific preferences, to make sure unrelated
|
||||
* preferences don't cause a rebuild (in particular preferences that
|
||||
* change on every start, like last.ide.xxx.daterun). */
|
||||
protected String buildPrefsString() {
|
||||
PreferencesMap buildPrefs = getBuildPreferences();
|
||||
String res = "";
|
||||
SortedSet<String> treeSet = new TreeSet<String>(buildPrefs.keySet());
|
||||
for (String k : treeSet) {
|
||||
if (k.startsWith("build.") || k.startsWith("compiler.") || k.startsWith("recipes."))
|
||||
res += k + " = " + buildPrefs.get(k) + "\n";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void setProgressListener(ProgressListener _progressListener) {
|
||||
progressListener = (_progressListener == null ?
|
||||
new ProgressListener() {
|
||||
@Override
|
||||
public void progress(int percent) {
|
||||
}
|
||||
} : _progressListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup temporary files used during a build/run.
|
||||
*/
|
||||
protected void cleanup(boolean force, File tempBuildFolder) {
|
||||
// if the java runtime is holding onto any files in the build dir, we
|
||||
// won't be able to delete them, so we need to force a gc here
|
||||
System.gc();
|
||||
|
||||
if (force) {
|
||||
// delete the entire directory and all contents
|
||||
// when we know something changed and all objects
|
||||
// need to be recompiled, or if the board does not
|
||||
// use setting build.dependency
|
||||
//Base.removeDir(tempBuildFolder);
|
||||
|
||||
// note that we can't remove the builddir itself, otherwise
|
||||
// the next time we start up, internal runs using Runner won't
|
||||
// work because the build dir won't exist at startup, so the classloader
|
||||
// will ignore the fact that that dir is in the CLASSPATH in run.sh
|
||||
BaseNoGui.removeDescendants(tempBuildFolder);
|
||||
} else {
|
||||
// delete only stale source files, from the previously
|
||||
// compiled sketch. This allows multiple windows to be
|
||||
// used. Keep everything else, which might be reusable
|
||||
if (tempBuildFolder.exists()) {
|
||||
String files[] = tempBuildFolder.list();
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
|
||||
File deleteMe = new File(tempBuildFolder, file);
|
||||
if (!deleteMe.delete()) {
|
||||
System.err.println("Could not delete " + deleteMe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a fresh applet folder (needed before preproc is run below)
|
||||
//tempBuildFolder.mkdirs();
|
||||
}
|
||||
|
||||
protected void size(PreferencesMap prefs) throws RunnerException {
|
||||
String maxTextSizeString = prefs.get("upload.maximum_size");
|
||||
String maxDataSizeString = prefs.get("upload.maximum_data_size");
|
||||
if (maxTextSizeString == null)
|
||||
return;
|
||||
long maxTextSize = Integer.parseInt(maxTextSizeString);
|
||||
long maxDataSize = -1;
|
||||
if (maxDataSizeString != null)
|
||||
maxDataSize = Integer.parseInt(maxDataSizeString);
|
||||
Sizer sizer = new Sizer(prefs);
|
||||
long[] sizes;
|
||||
try {
|
||||
sizes = sizer.computeSize();
|
||||
} catch (RunnerException e) {
|
||||
System.err.println(I18n.format(_("Couldn't determine program size: {0}"),
|
||||
e.getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
long textSize = sizes[0];
|
||||
long dataSize = sizes[1];
|
||||
System.out.println();
|
||||
System.out.println(I18n
|
||||
.format(_("Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes."),
|
||||
textSize, maxTextSize, textSize * 100 / maxTextSize));
|
||||
if (dataSize >= 0) {
|
||||
if (maxDataSize > 0) {
|
||||
System.out
|
||||
.println(I18n
|
||||
.format(
|
||||
_("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."),
|
||||
dataSize, maxDataSize, dataSize * 100 / maxDataSize,
|
||||
maxDataSize - dataSize));
|
||||
} else {
|
||||
System.out.println(I18n
|
||||
.format(_("Global variables use {0} bytes of dynamic memory."), dataSize));
|
||||
}
|
||||
}
|
||||
|
||||
if (textSize > maxTextSize)
|
||||
throw new RunnerException(
|
||||
_("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."));
|
||||
|
||||
if (maxDataSize > 0 && dataSize > maxDataSize)
|
||||
throw new RunnerException(
|
||||
_("Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint."));
|
||||
|
||||
int warnDataPercentage = Integer.parseInt(prefs.get("build.warn_data_percentage"));
|
||||
if (maxDataSize > 0 && dataSize > maxDataSize*warnDataPercentage/100)
|
||||
System.err.println(_("Low memory available, stability problems may occur."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile sketch.
|
||||
* @param _verbose
|
||||
*
|
||||
* @return true if successful.
|
||||
* @throws RunnerException Only if there's a problem. Only then.
|
||||
*/
|
||||
public boolean compile(boolean _verbose) throws RunnerException {
|
||||
verbose = _verbose || Preferences.getBoolean("build.verbose");
|
||||
public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapException {
|
||||
preprocess(prefs.get("build.path"));
|
||||
|
||||
verbose = _verbose || PreferencesData.getBoolean("build.verbose");
|
||||
sketchIsCompiled = false;
|
||||
objectFiles = new ArrayList<File>();
|
||||
|
||||
// 0. include paths for core + all libraries
|
||||
sketch.setCompilingProgress(20);
|
||||
progressListener.progress(20);
|
||||
List<File> includeFolders = new ArrayList<File>();
|
||||
includeFolders.add(prefs.getFile("build.core.path"));
|
||||
if (prefs.getFile("build.variant.path") != null)
|
||||
includeFolders.add(prefs.getFile("build.variant.path"));
|
||||
for (Library lib : sketch.getImportedLibraries()) {
|
||||
for (Library lib : importedLibraries) {
|
||||
if (verbose)
|
||||
System.out.println(I18n
|
||||
.format(_("Using library {0} in folder: {1} {2}"), lib.getName(),
|
||||
@ -100,12 +364,12 @@ public class Compiler implements MessageConsumer {
|
||||
System.out.println();
|
||||
|
||||
List<String> archs = new ArrayList<String>();
|
||||
archs.add(Base.getTargetPlatform().getId());
|
||||
archs.add(BaseNoGui.getTargetPlatform().getId());
|
||||
if (prefs.containsKey("architecture.override_check")) {
|
||||
String[] overrides = prefs.get("architecture.override_check").split(",");
|
||||
archs.addAll(Arrays.asList(overrides));
|
||||
}
|
||||
for (Library lib : sketch.getImportedLibraries()) {
|
||||
for (Library lib : importedLibraries) {
|
||||
if (!lib.supportsArchitecture(archs)) {
|
||||
System.err.println(I18n
|
||||
.format(_("WARNING: library {0} claims to run on {1} "
|
||||
@ -117,33 +381,33 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
sketch.setCompilingProgress(30);
|
||||
progressListener.progress(30);
|
||||
compileSketch(includeFolders);
|
||||
sketchIsCompiled = true;
|
||||
|
||||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
||||
// Doesn't really use configPreferences
|
||||
sketch.setCompilingProgress(40);
|
||||
progressListener.progress(40);
|
||||
compileLibraries(includeFolders);
|
||||
|
||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||
// collecting them into the core.a library file.
|
||||
sketch.setCompilingProgress(50);
|
||||
progressListener.progress(50);
|
||||
compileCore();
|
||||
|
||||
// 4. link it all together into the .elf file
|
||||
sketch.setCompilingProgress(60);
|
||||
progressListener.progress(60);
|
||||
compileLink();
|
||||
|
||||
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
|
||||
sketch.setCompilingProgress(70);
|
||||
compileEep();
|
||||
progressListener.progress(70);
|
||||
runRecipe("recipe.objcopy.eep.pattern");
|
||||
|
||||
// 6. build the .hex file
|
||||
sketch.setCompilingProgress(80);
|
||||
compileHex();
|
||||
progressListener.progress(80);
|
||||
runRecipe("recipe.objcopy.hex.pattern");
|
||||
|
||||
sketch.setCompilingProgress(90);
|
||||
progressListener.progress(90);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -151,7 +415,7 @@ public class Compiler implements MessageConsumer {
|
||||
String _primaryClassName)
|
||||
throws RunnerException {
|
||||
|
||||
if (Base.getBoardPreferences() == null) {
|
||||
if (BaseNoGui.getBoardPreferences() == null) {
|
||||
RunnerException re = new RunnerException(
|
||||
_("No board selected; please choose a board from the Tools > Board menu."));
|
||||
re.hideStackTrace();
|
||||
@ -159,14 +423,14 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
// Check if the board needs a platform from another package
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
TargetPlatform corePlatform = null;
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||
String core = boardPreferences.get("build.core");
|
||||
if (core.contains(":")) {
|
||||
String[] split = core.split(":");
|
||||
core = split[1];
|
||||
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
|
||||
corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
|
||||
if (corePlatform == null) {
|
||||
RunnerException re = new RunnerException(I18n
|
||||
.format(_("Selected board depends on '{0}' core (not installed)."),
|
||||
@ -178,11 +442,11 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
// Merge all the global preference configuration in order of priority
|
||||
PreferencesMap p = new PreferencesMap();
|
||||
p.putAll(Preferences.getMap());
|
||||
p.putAll(PreferencesData.getMap());
|
||||
if (corePlatform != null)
|
||||
p.putAll(corePlatform.getPreferences());
|
||||
p.putAll(targetPlatform.getPreferences());
|
||||
p.putAll(Base.getBoardPreferences());
|
||||
p.putAll(BaseNoGui.getBoardPreferences());
|
||||
for (String k : p.keySet()) {
|
||||
if (p.get(k) == null)
|
||||
p.put(k, "");
|
||||
@ -190,8 +454,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
p.put("build.path", _buildPath);
|
||||
p.put("build.project_name", _primaryClassName);
|
||||
targetArch = targetPlatform.getId();
|
||||
p.put("build.arch", targetArch.toUpperCase());
|
||||
p.put("build.arch", targetPlatform.getId().toUpperCase());
|
||||
|
||||
// Platform.txt should define its own compiler.path. For
|
||||
// compatibility with earlier 1.5 versions, we define a (ugly,
|
||||
@ -199,7 +462,7 @@ public class Compiler implements MessageConsumer {
|
||||
// point.
|
||||
if (!p.containsKey("compiler.path")) {
|
||||
System.err.println(_("Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer."));
|
||||
p.put("compiler.path", Base.getAvrBasePath());
|
||||
p.put("compiler.path", BaseNoGui.getAvrBasePath());
|
||||
}
|
||||
|
||||
// Core folder
|
||||
@ -224,7 +487,7 @@ public class Compiler implements MessageConsumer {
|
||||
t = targetPlatform;
|
||||
} else {
|
||||
String[] split = variant.split(":", 2);
|
||||
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
|
||||
t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
|
||||
variant = split[1];
|
||||
}
|
||||
File variantFolder = new File(t.getFolder(), "variants");
|
||||
@ -239,7 +502,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
private List<File> compileFiles(File outputPath, File sourcePath,
|
||||
boolean recurse, List<File> includeFolders)
|
||||
throws RunnerException {
|
||||
throws RunnerException, PreferencesMapException {
|
||||
List<File> sSources = findFilesInFolder(sourcePath, "S", recurse);
|
||||
List<File> cSources = findFilesInFolder(sourcePath, "c", recurse);
|
||||
List<File> cppSources = findFilesInFolder(sourcePath, "cpp", recurse);
|
||||
@ -248,7 +511,7 @@ public class Compiler implements MessageConsumer {
|
||||
for (File file : sSources) {
|
||||
File objectFile = new File(outputPath, file.getName() + ".o");
|
||||
objectPaths.add(objectFile);
|
||||
String[] cmd = getCommandCompilerS(includeFolders, file, objectFile);
|
||||
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.S.o.pattern");
|
||||
execAsynchronously(cmd);
|
||||
}
|
||||
|
||||
@ -258,7 +521,7 @@ public class Compiler implements MessageConsumer {
|
||||
objectPaths.add(objectFile);
|
||||
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
|
||||
continue;
|
||||
String[] cmd = getCommandCompilerC(includeFolders, file, objectFile);
|
||||
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.c.o.pattern");
|
||||
execAsynchronously(cmd);
|
||||
}
|
||||
|
||||
@ -268,7 +531,7 @@ public class Compiler implements MessageConsumer {
|
||||
objectPaths.add(objectFile);
|
||||
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
|
||||
continue;
|
||||
String[] cmd = getCommandCompilerCPP(includeFolders, file, objectFile);
|
||||
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.cpp.o.pattern");
|
||||
execAsynchronously(cmd);
|
||||
}
|
||||
|
||||
@ -279,7 +542,7 @@ public class Compiler implements MessageConsumer {
|
||||
* Strip escape sequences used in makefile dependency files (.d)
|
||||
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
|
||||
*
|
||||
* @param dep
|
||||
* @param line
|
||||
* @return
|
||||
*/
|
||||
protected static String unescapeDepFile(String line) {
|
||||
@ -356,8 +619,6 @@ public class Compiler implements MessageConsumer {
|
||||
return ret;
|
||||
}
|
||||
|
||||
boolean firstErrorFound;
|
||||
boolean secondErrorFound;
|
||||
|
||||
/**
|
||||
* Either succeeds or throws a RunnerException fit for public consumption.
|
||||
@ -382,9 +643,6 @@ public class Compiler implements MessageConsumer {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
firstErrorFound = false; // haven't found any errors yet
|
||||
secondErrorFound = false;
|
||||
|
||||
Process process;
|
||||
try {
|
||||
process = ProcessUtils.exec(command);
|
||||
@ -520,7 +778,7 @@ public class Compiler implements MessageConsumer {
|
||||
if (!sketchIsCompiled) {
|
||||
// Place errors when compiling the sketch, but never while compiling libraries
|
||||
// or the core. The user's sketch might contain the same filename!
|
||||
e = sketch.placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
|
||||
e = placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
|
||||
}
|
||||
|
||||
// replace full file path with the name of the sketch tab (unless we're
|
||||
@ -553,55 +811,15 @@ public class Compiler implements MessageConsumer {
|
||||
System.err.print(s);
|
||||
}
|
||||
|
||||
private String[] getCommandCompilerS(List<File> includeFolders,
|
||||
File sourceFile, File objectFile)
|
||||
throws RunnerException {
|
||||
private String[] getCommandCompilerByRecipe(List<File> includeFolders, File sourceFile, File objectFile, String recipe) throws PreferencesMapException, RunnerException {
|
||||
String includes = prepareIncludes(includeFolders);
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
dict.put("includes", includes);
|
||||
dict.put("source_file", sourceFile.getAbsolutePath());
|
||||
dict.put("object_file", objectFile.getAbsolutePath());
|
||||
|
||||
try {
|
||||
String cmd = prefs.get("recipe.S.o.pattern");
|
||||
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getCommandCompilerC(List<File> includeFolders,
|
||||
File sourceFile, File objectFile)
|
||||
throws RunnerException {
|
||||
String includes = prepareIncludes(includeFolders);
|
||||
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("includes", includes);
|
||||
dict.put("source_file", sourceFile.getAbsolutePath());
|
||||
dict.put("object_file", objectFile.getAbsolutePath());
|
||||
|
||||
String cmd = prefs.get("recipe.c.o.pattern");
|
||||
try {
|
||||
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getCommandCompilerCPP(List<File> includeFolders,
|
||||
File sourceFile, File objectFile)
|
||||
throws RunnerException {
|
||||
String includes = prepareIncludes(includeFolders);
|
||||
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("includes", includes);
|
||||
dict.put("source_file", sourceFile.getAbsolutePath());
|
||||
dict.put("object_file", objectFile.getAbsolutePath());
|
||||
|
||||
String cmd = prefs.get("recipe.cpp.o.pattern");
|
||||
String cmd = prefs.getOrExcept(recipe);
|
||||
try {
|
||||
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
@ -648,21 +866,21 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
void compileSketch(List<File> includeFolders) throws RunnerException {
|
||||
void compileSketch(List<File> includeFolders) throws RunnerException, PreferencesMapException {
|
||||
File buildPath = prefs.getFile("build.path");
|
||||
objectFiles.addAll(compileFiles(buildPath, buildPath, false, includeFolders));
|
||||
}
|
||||
|
||||
// 2. compile the libraries, outputting .o files to:
|
||||
// <buildPath>/<library>/
|
||||
void compileLibraries(List<File> includeFolders) throws RunnerException {
|
||||
for (Library lib : sketch.getImportedLibraries()) {
|
||||
void compileLibraries(List<File> includeFolders) throws RunnerException, PreferencesMapException {
|
||||
for (Library lib : importedLibraries) {
|
||||
compileLibrary(lib, includeFolders);
|
||||
}
|
||||
}
|
||||
|
||||
private void compileLibrary(Library lib, List<File> includeFolders)
|
||||
throws RunnerException {
|
||||
throws RunnerException, PreferencesMapException {
|
||||
File libFolder = lib.getSrcFolder();
|
||||
File libBuildFolder = prefs.getFile(("build.path"), lib.getName());
|
||||
|
||||
@ -688,7 +906,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<File> includeFolders) throws RunnerException {
|
||||
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<File> includeFolders) throws RunnerException, PreferencesMapException {
|
||||
compileFilesInFolder(srcBuildFolder, srcFolder, includeFolders);
|
||||
for (File subFolder : srcFolder.listFiles(new OnlyDirs())) {
|
||||
File subBuildFolder = new File(srcBuildFolder, subFolder.getName());
|
||||
@ -696,7 +914,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> includeFolders) throws RunnerException {
|
||||
private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> includeFolders) throws RunnerException, PreferencesMapException {
|
||||
createFolder(buildFolder);
|
||||
List<File> objects = compileFiles(buildFolder, srcFolder, false, includeFolders);
|
||||
objectFiles.addAll(objects);
|
||||
@ -707,7 +925,7 @@ public class Compiler implements MessageConsumer {
|
||||
// Also compiles the variant (if it supplies actual source files),
|
||||
// which are included in the link directly (not through core.a)
|
||||
void compileCore()
|
||||
throws RunnerException {
|
||||
throws RunnerException, PreferencesMapException {
|
||||
|
||||
File coreFolder = prefs.getFile("build.core.path");
|
||||
File variantFolder = prefs.getFile("build.variant.path");
|
||||
@ -758,13 +976,13 @@ public class Compiler implements MessageConsumer {
|
||||
for (File file : coreObjectFiles) {
|
||||
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
dict.put("archive_file", afile.getName());
|
||||
dict.put("object_file", file.getAbsolutePath());
|
||||
|
||||
String[] cmdArray;
|
||||
String cmd = prefs.getOrExcept("recipe.ar.pattern");
|
||||
try {
|
||||
String cmd = prefs.get("recipe.ar.pattern");
|
||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
@ -779,7 +997,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
// 4. link it all together into the .elf file
|
||||
void compileLink()
|
||||
throws RunnerException {
|
||||
throws RunnerException, PreferencesMapException {
|
||||
|
||||
// TODO: Make the --relax thing in configuration files.
|
||||
|
||||
@ -799,11 +1017,11 @@ public class Compiler implements MessageConsumer {
|
||||
dict.put("compiler.c.elf.flags", flags);
|
||||
dict.put("archive_file", "core.a");
|
||||
dict.put("object_files", objectFileList);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
|
||||
String[] cmdArray;
|
||||
String cmd = prefs.getOrExcept("recipe.c.combine.pattern");
|
||||
try {
|
||||
String cmd = prefs.get("recipe.c.combine.pattern");
|
||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
@ -811,29 +1029,13 @@ public class Compiler implements MessageConsumer {
|
||||
execAsynchronously(cmdArray);
|
||||
}
|
||||
|
||||
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
|
||||
void compileEep() throws RunnerException {
|
||||
void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
|
||||
String[] cmdArray;
|
||||
String cmd = prefs.getOrExcept(recipe);
|
||||
try {
|
||||
String cmd = prefs.get("recipe.objcopy.eep.pattern");
|
||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
execAsynchronously(cmdArray);
|
||||
}
|
||||
|
||||
// 6. build the .hex file
|
||||
void compileHex() throws RunnerException {
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + Base.REVISION);
|
||||
|
||||
String[] cmdArray;
|
||||
try {
|
||||
String cmd = prefs.get("recipe.objcopy.hex.pattern");
|
||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
@ -853,4 +1055,141 @@ public class Compiler implements MessageConsumer {
|
||||
public PreferencesMap getBuildPreferences() {
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all the code for this sketch.
|
||||
*
|
||||
* In an advanced program, the returned class name could be different,
|
||||
* which is why the className is set based on the return value.
|
||||
* A compilation error will burp up a RunnerException.
|
||||
*
|
||||
* Setting purty to 'true' will cause exception line numbers to be incorrect.
|
||||
* Unless you know the code compiles, you should first run the preprocessor
|
||||
* with purty set to false to make sure there are no errors, then once
|
||||
* successful, re-export with purty set to true.
|
||||
*
|
||||
* @param buildPath Location to copy all the .java files
|
||||
* @return null if compilation failed, main class name if not
|
||||
*/
|
||||
public void preprocess(String buildPath) throws RunnerException {
|
||||
preprocess(buildPath, new PdePreprocessor());
|
||||
}
|
||||
|
||||
public void preprocess(String buildPath, PdePreprocessor preprocessor) throws RunnerException {
|
||||
|
||||
// 1. concatenate all .pde files to the 'main' pde
|
||||
// store line number for starting point of each code bit
|
||||
|
||||
StringBuffer bigCode = new StringBuffer();
|
||||
int bigCount = 0;
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
||||
sc.setPreprocOffset(bigCount);
|
||||
// These #line directives help the compiler report errors with
|
||||
// correct the filename and line number (issue 281 & 907)
|
||||
bigCode.append("#line 1 \"" + sc.getFileName() + "\"\n");
|
||||
bigCode.append(sc.getProgram());
|
||||
bigCode.append('\n');
|
||||
bigCount += sc.getLineCount();
|
||||
}
|
||||
}
|
||||
|
||||
// Note that the headerOffset isn't applied until compile and run, because
|
||||
// it only applies to the code after it's been written to the .java file.
|
||||
int headerOffset = 0;
|
||||
try {
|
||||
headerOffset = preprocessor.writePrefix(bigCode.toString());
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
String msg = _("Build folder disappeared or could not be written");
|
||||
throw new RunnerException(msg);
|
||||
}
|
||||
|
||||
// 2. run preproc on that code using the sugg class name
|
||||
// to create a single .java file and write to buildpath
|
||||
|
||||
try {
|
||||
// Output file
|
||||
File streamFile = new File(buildPath, sketch.getName() + ".cpp");
|
||||
FileOutputStream outputStream = new FileOutputStream(streamFile);
|
||||
preprocessor.write(outputStream);
|
||||
outputStream.close();
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
String msg = _("Build folder disappeared or could not be written");
|
||||
throw new RunnerException(msg);
|
||||
} catch (RunnerException pe) {
|
||||
// RunnerExceptions are caught here and re-thrown, so that they don't
|
||||
// get lost in the more general "Exception" handler below.
|
||||
throw pe;
|
||||
|
||||
} catch (Exception ex) {
|
||||
// TODO better method for handling this?
|
||||
System.err.println(I18n.format(_("Uncaught exception type: {0}"), ex.getClass()));
|
||||
ex.printStackTrace();
|
||||
throw new RunnerException(ex.toString());
|
||||
}
|
||||
|
||||
// grab the imports from the code just preproc'd
|
||||
|
||||
importedLibraries = new LibraryList();
|
||||
for (String item : preprocessor.getExtraImports()) {
|
||||
Library lib = BaseNoGui.importToLibraryTable.get(item);
|
||||
if (lib != null && !importedLibraries.contains(lib)) {
|
||||
importedLibraries.add(lib);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. then loop over the code[] and save each .java file
|
||||
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
|
||||
// no pre-processing services necessary for java files
|
||||
// just write the the contents of 'program' to a .java file
|
||||
// into the build directory. uses byte stream and reader/writer
|
||||
// shtuff so that unicode bunk is properly handled
|
||||
String filename = sc.getFileName(); //code[i].name + ".java";
|
||||
try {
|
||||
BaseNoGui.saveFile(sc.getProgram(), new File(buildPath, filename));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));
|
||||
}
|
||||
|
||||
} else if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
||||
// The compiler and runner will need this to have a proper offset
|
||||
sc.addPreprocOffset(headerOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List of library folders.
|
||||
*/
|
||||
private LibraryList importedLibraries;
|
||||
|
||||
/**
|
||||
* Map an error from a set of processed .java files back to its location
|
||||
* in the actual sketch.
|
||||
* @param message The error message.
|
||||
* @param dotJavaFilename The .java file where the exception was found.
|
||||
* @param dotJavaLine Line number of the .java file for the exception (0-indexed!)
|
||||
* @return A RunnerException to be sent to the editor, or null if it wasn't
|
||||
* possible to place the exception to the sketch code.
|
||||
*/
|
||||
public RunnerException placeException(String message,
|
||||
String dotJavaFilename,
|
||||
int dotJavaLine) {
|
||||
// Placing errors is simple, because we inserted #line directives
|
||||
// into the preprocessed source. The compiler gives us correct
|
||||
// the file name and line number. :-)
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (dotJavaFilename.equals(code.getFileName())) {
|
||||
return new RunnerException(message, sketch.indexOfCode(code), dotJavaLine);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user