Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tagging release 0004.

  • Loading branch information...
commit 1a7d1836b18688e0e6b3904df8508f7a1525c903 2 parents 5381e71 + f636b93
@damellis damellis authored
Showing with 41,070 additions and 33,587 deletions.
  1. +170 −47 app/Base.java
  2. +69 −43 app/Compiler.java
  3. +588 −383 app/Editor.java
  4. +110 −37 app/EditorButtons.java
  5. +148 −64 app/EditorConsole.java
  6. +6 −3 app/EditorHeader.java
  7. +420 −28 app/EditorListener.java
  8. +1 −1  app/EditorStatus.java
  9. +89 −43 app/FindReplace.java
  10. +576 −0 app/Library.java
  11. +243 −0 app/LibraryManager.java
  12. +66 −65 app/Preferences.java
  13. +95 −0 app/Sizer.java
  14. +169 −49 app/Sketch.java
  15. +33 −10 app/Sketchbook.java
  16. +75 −59 app/Uploader.java
  17. +46 −25 app/preproc/PdePreprocessor.java
  18. +143 −143 app/preproc/STDCTokenTypes.java
  19. +139 −139 app/preproc/STDCTokenTypes.txt
  20. +2,667 −2,667 app/preproc/StdCLexer.java
  21. +5,774 −5,774 app/preproc/StdCParser.java
  22. +6,339 −6,339 app/preproc/WEmitter.java
  23. +155 −155 app/preproc/WEmitterTokenTypes.java
  24. +151 −151 app/preproc/WEmitterTokenTypes.txt
  25. +2,703 −2,703 app/preproc/WLexer.java
  26. +161 −161 app/preproc/WLexerTokenTypes.java
  27. +157 −157 app/preproc/WLexerTokenTypes.txt
  28. +6,605 −6,605 app/preproc/WParser.java
  29. +155 −155 app/preproc/WTokenTypes.java
  30. +151 −151 app/preproc/WTokenTypes.txt
  31. +5,494 −5,494 app/preproc/WTreeParser.java
  32. +155 −155 app/preproc/WTreeParserTokenTypes.java
  33. +151 −151 app/preproc/WTreeParserTokenTypes.txt
  34. +182 −182 app/preproc/expandedWEmitter.g
  35. +479 −479 app/preproc/expandedWParser.g
  36. +1 −1  app/syntax/JEditTextArea.java
  37. +12 −1 app/syntax/PdeKeywords.java
  38. +36 −0 app/syntax/TextAreaPainter.java
  39. +156 −0 app/tools/Archiver.java
  40. +352 −420 app/tools/AutoFormat.java
  41. +120 −0 app/tools/ExportFolder.java
  42. +25 −0 build/fetch.sh
  43. BIN  build/linux/dist/librxtxSerial.so
  44. +131 −42 build/macosx/Arduino.xcodeproj/project.pbxproj
  45. BIN  build/macosx/dist/librxtxSerial.jnilib
  46. +7 −4 build/macosx/dist/macosx_setup.command
  47. BIN  build/macosx/dist/tools.zip
  48. +4 −3 build/macosx/make.sh
  49. BIN  build/shared/dist/examples.zip
  50. +31 −0 build/shared/dist/examples/digital IO/digital_read/digital_read.pde
  51. +24 −0 build/shared/dist/examples/digital IO/digital_read_and_blink/digital_read_and_blink.pde
  52. +110 −0 build/shared/dist/examples/lcd/lcd_8bits/lcd_8bits.pde
  53. +28 −0 build/shared/dist/examples/led_blink/led_blink.pde
  54. +86 −0 build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde
  55. +46 −0 build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde
  56. +51 −0 build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde
  57. +195 −0 build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde
  58. +79 −0 build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde
  59. +35 −0 build/shared/dist/examples/motors/dc_motor/dc_motor.pde
  60. +127 −0 build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde
  61. +57 −0 build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde
  62. +73 −0 build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde
  63. +42 −0 build/shared/dist/examples/processing/processing_send_potentiometer/processing_send_potentiometer.pde
  64. +29 −0 build/shared/dist/examples/program_template/program_template.pde
  65. +71 −0 build/shared/dist/examples/puredata/PD_inputs_to_PD/PD_inputs_to_PD.pde
  66. +37 −0 build/shared/dist/examples/puredata/PD_send_potentiometer/PD_send_potentiometer.pde
  67. +31 −0 build/shared/dist/examples/puredata/PD_two_potentiometers/PD_two_potentiometers.pde
  68. +60 −0 build/shared/dist/examples/pwm_sound/keyboard_serial/keyboard_serial.pde
  69. +62 −0 build/shared/dist/examples/pwm_sound/keyboard_serial_faded_volume/keyboard_serial_faded_volume.pde
  70. +67 −0 build/shared/dist/examples/pwm_sound/play_melody/play_melody.pde
  71. +67 −0 build/shared/dist/examples/pwm_sound/play_melody_2/play_melody_2.pde
  72. +69 −0 build/shared/dist/examples/pwm_sound/play_melody_faded_volume/play_melody_faded_volume.pde
  73. +91 −0 build/shared/dist/examples/sensors_complex/accelerometer_memsic2125/accelerometer_memsic2125.pde
  74. +73 −0 build/shared/dist/examples/sensors_complex/ultrasound_PING/ultrasound_PING.pde
  75. +29 −0 build/shared/dist/examples/sensors_resistive/analog_read_led/analog_read_led.pde
  76. +37 −0 build/shared/dist/examples/sensors_resistive/knock_sensor/knock_sensor.pde
  77. +54 −0 build/shared/dist/examples/sensors_resistive/read_joystick/read_joystick.pde
  78. +32 −0 build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde
  79. +37 −0 build/shared/dist/examples/serial_comm/double_counter/double_counter.pde
  80. +86 −0 build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde
  81. +43 −0 build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde
  82. +35 −0 build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde
  83. +40 −0 build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde
  84. BIN  build/shared/lib/RXTXcomm.jar
  85. +10 −0 build/shared/lib/keywords.txt
  86. +10 −0 build/shared/lib/preferences.txt
  87. BIN  build/shared/reference.zip
  88. +0 −34 build/shared/run.bat
  89. +6 −0 build/windows/dist.sh
  90. BIN  build/windows/dist/avr_tools.zip
  91. +6 −4 build/windows/dist/bootloader/burn.bat
  92. +18 −0 build/windows/dist/bootloader/burnpara.bat
  93. BIN  build/windows/dist/cygiconv-2.dll
  94. BIN  build/windows/dist/cygwin1.dll
  95. +0 −16 build/windows/dist/run-expert.bat
  96. +22 −4 build/windows/dist/run.bat
  97. BIN  build/windows/dist/rxtxSerial.dll
  98. +33 −0 build/windows/launcher/Makefile.win
  99. BIN  build/windows/launcher/arduino.exe
  100. +68 −0 build/windows/launcher/launcher.dev
  101. +15 −19 build/windows/make.sh
  102. +69 −18 readme.txt
  103. +172 −0 targets/arduino/HardwareSerial.cpp
  104. +62 −0 targets/arduino/HardwareSerial.h
  105. +45 −0 targets/arduino/Serial.c
  106. +32 −0 targets/arduino/Serial.h
  107. +1 −0  targets/arduino/WConstants.h
  108. +6 −3 targets/arduino/WProgram.h
  109. +4 −4 targets/arduino/pins_arduino.c
  110. +132 −36 targets/arduino/wiring.c
  111. +37 −16 targets/arduino/wiring.h
  112. +35 −0 targets/libraries/Foo/Foo.cpp
  113. +33 −0 targets/libraries/Foo/Foo.h
  114. +225 −0 targets/libraries/Matrix/Matrix.cpp
  115. +54 −0 targets/libraries/Matrix/Matrix.h
  116. +39 −0 targets/libraries/Matrix/examples/hello_matrix/hello_matrix.pde
  117. +45 −0 targets/libraries/Matrix/examples/sprite_animation/sprite_animation.pde
  118. +22 −0 targets/libraries/Matrix/keywords.txt
  119. +91 −0 targets/libraries/Sprite/Sprite.cpp
  120. +48 −0 targets/libraries/Sprite/Sprite.h
  121. +515 −0 targets/libraries/Sprite/binary.h
  122. +534 −0 targets/libraries/Sprite/keywords.txt
  123. +516 −0 targets/wiring/Binary.h
  124. +47 −0 targets/wiring/Encoder.h
  125. BIN  targets/wiring/Encoder.o
  126. +60 −0 targets/wiring/HardwareSerial.h
  127. BIN  targets/wiring/HardwareSerial.o
  128. +67 −0 targets/wiring/LiquidCrystal.h
  129. BIN  targets/wiring/LiquidCrystal.o
  130. +34 −30 targets/wiring/Matrix.h
  131. BIN  targets/wiring/Matrix.o
  132. +50 −0 targets/wiring/QSlide.h
  133. BIN  targets/wiring/QSlide.o
  134. +13 −17 targets/wiring/Servo.h
  135. BIN  targets/wiring/Servo.o
  136. +49 −0 targets/wiring/Sprite.h
  137. BIN  targets/wiring/Sprite.o
  138. +67 −0 targets/wiring/TwoWire.h
  139. BIN  targets/wiring/TwoWire.o
  140. BIN  targets/wiring/WApplet.o
  141. +88 −158 targets/wiring/WConstants.h
  142. BIN  targets/wiring/WCounter.o
  143. BIN  targets/wiring/WDisplay.o
  144. BIN  targets/wiring/WEncoder.o
  145. BIN  targets/wiring/WInterrupts.o
  146. +9 −56 targets/wiring/WProgram.h
  147. BIN  targets/wiring/WRandom.o
  148. BIN  targets/wiring/WSerial.o
  149. BIN  targets/wiring/WTimer.o
  150. +0 −83 targets/wiring/Wire.h
  151. BIN  targets/wiring/Wire.o
  152. +41 −0 targets/wiring/buffer.h
  153. BIN  targets/wiring/buffer.o
  154. +57 −0 targets/wiring/twi.h
  155. BIN  targets/wiring/twi.o
  156. +40 −0 targets/wiring/uart.h
  157. BIN  targets/wiring/uart.o
View
217 app/Base.java
@@ -52,30 +52,63 @@
* files and images, etc) that comes from that.
*/
public class Base {
- static final int VERSION = 1;
+ static final int VERSION = 3;
static final String VERSION_NAME = "0004 Alpha";
- static public int platform;
-
- // platform IDs for platform
+ // platform IDs for PApplet.platform
static final int WINDOWS = 1;
static final int MACOS9 = 2;
static final int MACOSX = 3;
static final int LINUX = 4;
static final int OTHER = 0;
-
-
- // moved from PApplet
- // in preperation of detaching the IDE from the
- // Arduino core classes
-
- /**
+
+ // used by split, all the standard whitespace chars
+ // (uncludes unicode nbsp, that little bostage)
+
+ static final String WHITESPACE = " \t\n\r\f\u00A0";
+
+ /**
+ * Path of filename opened on the command line,
+ * or via the MRJ open document handler.
+ */
+ static String openedAtStartup;
+
+ Editor editor;
+
+ /**
+ * "1.3" or "1.1" or whatever (just the first three chars)
+ */
+ public static final String javaVersionName =
+ System.getProperty("java.version").substring(0,3);
+
+ /**
+ * Version of Java that's in use, whether 1.1 or 1.3 or whatever,
+ * stored as a float.
+ * <P>
+ * Note that because this is stored as a float, the values may
+ * not be <EM>exactly</EM> 1.3 or 1.4. Instead, make sure you're
+ * comparing against 1.3f or 1.4f, which will have the same amount
+ * of error (i.e. 1.40000001). This could just be a double, but
+ * since Processing only uses floats, it's safer to do this,
+ * because there's no good way to specify a double with the preproc.
+ */
+ public static final float javaVersion =
+ new Float(javaVersionName).floatValue();
+
+ /**
+ * Current platform in use, one of the
+ * PConstants WINDOWS, MACOSX, MACOS9, LINUX or OTHER.
+ */
+ static public int platform;
+
+ /**
* Current platform in use.
* <P>
* Equivalent to System.getProperty("os.name"), just used internally.
*/
- static public String platformName = System.getProperty("os.name");
+ static public String platformName =
+ System.getProperty("os.name");
static {
// figure out which operating system
@@ -105,23 +138,6 @@
}
}
- // used by split, all the standard whitespace chars
- // (uncludes unicode nbsp, that little bostage)
-
- static final String WHITESPACE = " \t\n\r\f\u00A0";
-
-
-
-
- /**
- * Path of filename opened on the command line,
- * or via the MRJ open document handler.
- */
- static String openedAtStartup;
-
- Editor editor;
-
-
static public void main(String args[]) {
// make sure that this is running on java 1.4
@@ -179,6 +195,9 @@ public Base() {
e.printStackTrace();
}
+ // use native popups so they don't look so crappy on osx
+ JPopupMenu.setDefaultLightWeightPopupEnabled(false);
+
// build the editor object
editor = new Editor();
@@ -191,6 +210,9 @@ public Base() {
// show the window
editor.show();
+ // attempt to build libraries
+ editor.prepareLibraries();
+
// check for updates
if (Preferences.getBoolean("update.check")) {
new UpdateCheck(editor);
@@ -214,7 +236,6 @@ static public boolean isMacOS() {
* returns true if running on windows.
*/
static public boolean isWindows() {
-
return platform == WINDOWS;
}
@@ -223,7 +244,6 @@ static public boolean isWindows() {
* true if running on linux.
*/
static public boolean isLinux() {
-
return platform == LINUX;
}
@@ -363,26 +383,40 @@ static public File getSettingsFile(String filename) {
}
+ static File buildFolder;
+
static public File getBuildFolder() {
- String buildPath = Preferences.get("build.path");
- if (buildPath != null) return new File(buildPath);
+ if (buildFolder == null) {
+ String buildPath = Preferences.get("build.path");
+ if (buildPath != null) {
+ buildFolder = new File(buildPath);
- File folder = new File(getTempFolder(), "build");
- if (!folder.exists()) folder.mkdirs();
- return folder;
+ } else {
+ //File folder = new File(getTempFolder(), "build");
+ //if (!folder.exists()) folder.mkdirs();
+ buildFolder = createTempFolder("build");
+ buildFolder.deleteOnExit();
+ }
+ }
+ return buildFolder;
}
/**
* 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 getTempFolder() {
+ static public File createTempFolder(String name) {
try {
- File ignored = File.createTempFile("ignored", null);
- String tempPath = ignored.getParent();
- ignored.delete();
- return new File(tempPath);
+ 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();
@@ -548,6 +582,55 @@ static public String cleanKey(String what) {
// .................................................................
+ // someone needs to be slapped
+ //static KeyStroke closeWindowKeyStroke;
+
+ /**
+ * Return true if the key event was a Ctrl-W or an ESC,
+ * both indicators to close the window.
+ * Use as part of a keyPressed() event handler for frames.
+ */
+ /*
+ static public boolean isCloseWindowEvent(KeyEvent e) {
+ if (closeWindowKeyStroke == null) {
+ int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+ closeWindowKeyStroke = KeyStroke.getKeyStroke('W', modifiers);
+ }
+ return ((e.getKeyCode() == KeyEvent.VK_ESCAPE) ||
+ KeyStroke.getKeyStrokeForEvent(e).equals(closeWindowKeyStroke));
+ }
+ */
+
+
+ /**
+ * Registers key events for a Ctrl-W and ESC with an ActionListener
+ * that will take care of disposing the window.
+ */
+ static public void registerWindowCloseKeys(JRootPane root, //Window window,
+ ActionListener disposer) {
+ /*
+ JRootPane root = null;
+ if (window instanceof JFrame) {
+ root = ((JFrame)window).getRootPane();
+ } else if (window instanceof JDialog) {
+ root = ((JDialog)window).getRootPane();
+ }
+ */
+
+ KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
+ root.registerKeyboardAction(disposer, stroke,
+ JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+ int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+ stroke = KeyStroke.getKeyStroke('W', modifiers);
+ root.registerKeyboardAction(disposer, stroke,
+ JComponent.WHEN_IN_FOCUSED_WINDOW);
+ }
+
+
+ // .................................................................
+
+
/**
* Given the reference filename from the keywords list,
* builds a URL and passes it to openURL.
@@ -858,7 +941,9 @@ static public void copyDir(File sourceDir,
static public void removeDir(File dir) {
if (dir.exists()) {
removeDescendants(dir);
- dir.delete();
+ if (!dir.delete()) {
+ System.err.println("Could not delete " + dir);
+ }
}
}
@@ -918,6 +1003,46 @@ static public int calcFolderSize(File folder) {
/**
+ * Gets a list of all files within the specified folder,
+ * and returns a list of their relative paths.
+ * Ignores any files/folders prefixed with a dot.
+ */
+ static public String[] listFiles(String path, boolean relative) {
+ return listFiles(new File(path), relative);
+ }
+
+ static public String[] listFiles(File folder, boolean relative) {
+ String path = folder.getAbsolutePath();
+ Vector vector = new Vector();
+ listFiles(relative ? (path + File.separator) : "", path, vector);
+ String outgoing[] = new String[vector.size()];
+ vector.copyInto(outgoing);
+ return outgoing;
+ }
+
+ static protected void listFiles(String basePath,
+ String path, Vector vector) {
+ File folder = new File(path);
+ String list[] = folder.list();
+ if (list == null) return;
+
+ for (int i = 0; i < list.length; i++) {
+ if (list[i].charAt(0) == '.') continue;
+
+ File file = new File(path, list[i]);
+ String newPath = file.getAbsolutePath();
+ if (newPath.startsWith(basePath)) {
+ newPath = newPath.substring(basePath.length());
+ }
+ vector.add(newPath);
+ if (file.isDirectory()) {
+ listFiles(basePath, newPath, vector);
+ }
+ }
+ }
+
+
+ /**
* Equivalent to the one in PApplet, but static (die() is removed)
*/
static public String[] loadStrings(File file) {
@@ -953,8 +1078,9 @@ static public int calcFolderSize(File folder) {
}
return null;
}
-
- //////////////////////////////////////////////////////////////
+
+
+ //////////////////////////////////////////////////////////////
// STRINGS
@@ -1107,7 +1233,4 @@ static public String join(String str[], String separator) {
return splits;
}
-
-
-
}
View
112 app/Compiler.java
@@ -75,8 +75,16 @@ public boolean compile(Sketch sketch, String buildPath, Target target)
MessageStream pms = new MessageStream(this);
String userdir = System.getProperty("user.dir") + File.separator;
-
- String baseCommandCompiler[] = new String[] {
+
+// LibraryManager libraryManager;
+//
+// try {
+// libraryManager = new LibraryManager();
+// } catch (IOException e) {
+// throw new RunnerException(e.getMessage());
+// }
+
+ String preCommandCompiler[] = new String[] {
((!Base.isMacOS()) ? "tools/avr/bin/avr-gcc" :
userdir + "tools/avr/bin/avr-gcc"),
"-c", // compile, don't link
@@ -86,11 +94,23 @@ public boolean compile(Sketch sketch, String buildPath, Target target)
"-w", // surpress all warnings
"-mmcu=" + Preferences.get("build.mcu"),
"-DF_CPU=" + Preferences.get("build.f_cpu"),
- " ",
- " "
};
- String baseCommandCompilerCPP[] = new String[] {
+ // use lib directories as include paths
+ //String[] libDirs = libraryManager.getFolderPaths();
+ String[] libDirs = new String[sketch.importedLibraries.size()];
+
+ for (int i = 0; i < sketch.importedLibraries.size(); i++)
+ libDirs[i] = ((Library) sketch.importedLibraries.get(i)).getFolder().getPath();
+
+ // Last two arguments will specify the file being compiled and the output file.
+ String[] baseCommandCompiler = new String[preCommandCompiler.length + libDirs.length + 2];
+ System.arraycopy(preCommandCompiler, 0, baseCommandCompiler, 0, preCommandCompiler.length);
+ for (int i = 0; i < libDirs.length; ++i) {
+ baseCommandCompiler[preCommandCompiler.length + i] = "-I" + libDirs[i];
+ }
+
+ String preCommandCompilerCPP[] = new String[] {
((!Base.isMacOS()) ? "tools/avr/bin/avr-g++" :
userdir + "tools/avr/bin/avr-g++"),
"-c", // compile, don't link
@@ -101,46 +121,46 @@ public boolean compile(Sketch sketch, String buildPath, Target target)
"-fno-exceptions",
"-mmcu=" + Preferences.get("build.mcu"),
"-DF_CPU=" + Preferences.get("build.f_cpu"),
- " ",
- " "
};
- String baseCommandLinker[] = new String[] {
+ // use lib directories as include paths
+ // Last two arguments will specify the file being compiled and the output file.
+ String[] baseCommandCompilerCPP = new String[preCommandCompilerCPP.length + libDirs.length + 2];
+ System.arraycopy(preCommandCompilerCPP, 0, baseCommandCompilerCPP, 0, preCommandCompilerCPP.length);
+ for (int i = 0; i < libDirs.length; ++i) {
+ baseCommandCompilerCPP[preCommandCompilerCPP.length + i] = "-I" + libDirs[i];
+ }
+
+ String preCommandLinker[] = new String[] {
((!Base.isMacOS()) ? "tools/avr/bin/avr-gcc" :
userdir + "tools/avr/bin/avr-gcc"),
" ",
"-mmcu=" + Preferences.get("build.mcu"),
"-o",
" ",
-// ((!Base.isMacOS()) ? "" : userdir) + "lib/uart.o",
-// ((!Base.isMacOS()) ? "" : userdir) + "lib/buffer.o",
-// ((!Base.isMacOS()) ? "" : userdir) + "lib/timer.o",
-// ((!Base.isMacOS()) ? "" : userdir) + "lib/wiring.o",
-// ((!Base.isMacOS()) ? "" : userdir) + "lib/pins_arduino.o",
- //((!Base.isMacOS()) ? "lib/WApplet.o" :
- //userdir + "lib/WApplet.o"),
- //((!Base.isMacOS()) ? "lib/WSerial.o" :
- //userdir + "lib/WSerial.o"),
- //((!Base.isMacOS()) ? "lib/WTimer.o" :
- //userdir + "lib/WTimer.o"),
- //((!Base.isMacOS()) ? "lib/Servo.o" :
- //userdir + "lib/Servo.o"),
- ////((!Base.isMacOS()) ? "lib/Wire.o" :
- //// userdir + "lib/Wire.o"),
- ////((!Base.isMacOS()) ? "lib/WServo.o" :
- //// userdir + "lib/WServo.o"),
- //((!Base.isMacOS()) ? "lib/WDisplay.o" :
- //userdir + "lib/WDisplay.o"),
- //((!Base.isMacOS()) ? "lib/WEncoder.o" :
- //userdir + "lib/WEncoder.o"),
- //((!Base.isMacOS()) ? "lib/WInterrupts.o" :
- //userdir + "lib/WInterrupts.o"),
- //((!Base.isMacOS()) ? "lib/WCounter.o" :
- //userdir + "lib/WCounter.o"),
- //((!Base.isMacOS()) ? "tools/avr/avr/lib/libm.a" :
- //userdir + "tools/avr/avr/lib/libm.a")
};
+ // use lib object files during include
+ //String[] libObjectFiles = libraryManager.getObjectFiles();
+
+ Vector libObjectFilesVec = new Vector();
+
+ for (Iterator i = sketch.importedLibraries.iterator(); i.hasNext(); ) {
+ Library library = (Library) i.next();
+ File[] objectFiles = library.getObjectFiles();
+ for (int j = 0; j < objectFiles.length; j++)
+ libObjectFilesVec.add(objectFiles[j].getPath());
+ }
+
+ String[] libObjectFiles = new String[libObjectFilesVec.size()];
+ libObjectFiles = (String[]) libObjectFilesVec.toArray(libObjectFiles);
+
+ String[] baseCommandLinker = new String[preCommandLinker.length + libObjectFiles.length];
+ System.arraycopy(preCommandLinker, 0, baseCommandLinker, 0, preCommandLinker.length);
+ for (int i = 0; i < libObjectFiles.length; ++i) {
+ baseCommandLinker[preCommandLinker.length + i] = libObjectFiles[i];
+ }
+
String baseCommandObjcopy[] = new String[] {
((!Base.isMacOS()) ? "tools/avr/bin/avr-objcopy" :
userdir + "tools/avr/bin/avr-objcopy"),
@@ -295,8 +315,8 @@ public boolean compile(Sketch sketch, String buildPath, Target target)
Process process;
boolean compiling = true;
for(int i = 0; i < fileCount; i++) {
- baseCommandCompiler[8] = sourceNames[i];
- baseCommandCompiler[9] = "-o"+ objectNames[i];
+ baseCommandCompiler[baseCommandCompiler.length - 2] = sourceNames[i];
+ baseCommandCompiler[baseCommandCompiler.length - 1] = "-o"+ objectNames[i];
//System.arraycopy(baseCommandCompiler.length
//for(int j = 0; j < baseCommandCompiler.length; j++) {
// System.out.println(baseCommandCompiler[j]);
@@ -325,8 +345,8 @@ public boolean compile(Sketch sketch, String buildPath, Target target)
}
for(int i = 0; i < fileCountCPP; i++) {
- baseCommandCompilerCPP[9] = sourceNamesCPP[i];
- baseCommandCompilerCPP[10] = "-o"+ objectNamesCPP[i];
+ baseCommandCompilerCPP[baseCommandCompilerCPP.length - 2] = sourceNamesCPP[i];
+ baseCommandCompilerCPP[baseCommandCompilerCPP.length - 1] = "-o"+ objectNamesCPP[i];
//for(int j = 0; j < baseCommandCompilerCPP.length; j++) {
// System.out.println(baseCommandCompilerCPP[j]);
//}
@@ -526,15 +546,21 @@ public void message(String s) {
String s1 = s.substring(partialStartIndex +
partialTempPath.length() + 1);
//System.out.println(s1);
- if (s1.indexOf("In function")!= -1) {
+ int colon = s1.indexOf(':');
+
+ if (s1.indexOf("In function") != -1 || colon == -1) {
System.err.print(s1);
//firstErrorFound = true;
return;
}
- int colon = s1.indexOf(':');
-
- int lineNumber = Integer.parseInt(s1.substring(0, colon));
+ int lineNumber;
+ try {
+ lineNumber = Integer.parseInt(s1.substring(0, colon));
+ } catch (NumberFormatException e) {
+ System.err.print(s1);
+ return;
+ }
// the "1" corresponds to the amount of lines written to the main code
// file by PdePreprocessor's writeHeader() routine before prototypes
View
971 app/Editor.java
@@ -30,6 +30,8 @@
import processing.app.tools.*;
import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.lang.reflect.*;
@@ -46,10 +48,8 @@
import com.oroinc.text.regex.*;
import com.apple.mrj.*;
-
import gnu.io.*;
-
public class Editor extends JFrame
implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler,
MRJOpenDocumentHandler //, MRJOpenApplicationHandler
@@ -101,27 +101,27 @@
//Point presentLocation;
//Window presentationWindow;
RunButtonWatcher watcher;
- Runner runtime;
+ //Runner runtime;
JMenuItem exportAppItem;
JMenuItem saveMenuItem;
JMenuItem saveAsMenuItem;
-
- //ButtonGroup serialGroup;
- JMenu serialSubMenu;
- JMenu serialRateSubMenu;
+ JMenu serialMenu;
+ JMenu serialRateMenu;
SerialMenuListener serialMenuListener;
- //
- boolean debugging;
boolean running;
boolean presenting;
+ boolean debugging;
// undo fellers
JMenuItem undoItem, redoItem;
protected UndoAction undoAction;
protected RedoAction redoAction;
UndoManager undo;
+ // used internally, and only briefly
+ CompoundEdit compoundEdit;
+
//static public UndoManager undo = new UndoManager(); // editor needs this guy
//
@@ -129,7 +129,7 @@
//SketchHistory history; // TODO re-enable history
Sketchbook sketchbook;
//Preferences preferences;
- FindReplace find;
+ //FindReplace find;
//static Properties keywords; // keyword -> reference html lookup
@@ -175,7 +175,7 @@ public void windowClosing(WindowEvent e) {
setJMenuBar(menubar);
// doesn't matter when this is created, just make it happen at some point
- find = new FindReplace(Editor.this);
+ //find = new FindReplace(Editor.this);
Container pain = getContentPane();
pain.setLayout(new BorderLayout());
@@ -240,28 +240,87 @@ public void windowClosing(WindowEvent e) {
listener = new EditorListener(this, textarea);
pain.add(box);
- /*
- // set the undo stuff for this feller
- Document document = textarea.getDocument();
- //document.addUndoableEditListener(new PdeUndoableEditListener());
- document.addUndoableEditListener(new UndoableEditListener() {
- public void undoableEditHappened(UndoableEditEvent e) {
- if (undo != null) {
- //System.out.println(e.getEdit());
- undo.addEdit(e.getEdit());
- undoAction.updateUndoState();
- redoAction.updateRedoState();
+ DropTarget dt = new DropTarget(this, new DropTargetListener() {
+
+ public void dragEnter(DropTargetDragEvent event) {
+ // debug messages for diagnostics
+ //System.out.println("dragEnter " + event);
+ event.acceptDrag(DnDConstants.ACTION_COPY);
+ }
+
+ public void dragExit(DropTargetEvent event) {
+ //System.out.println("dragExit " + event);
+ }
+
+ public void dragOver(DropTargetDragEvent event) {
+ //System.out.println("dragOver " + event);
+ event.acceptDrag(DnDConstants.ACTION_COPY);
+ }
+
+ public void dropActionChanged(DropTargetDragEvent event) {
+ //System.out.println("dropActionChanged " + event);
+ }
+
+ public void drop(DropTargetDropEvent event) {
+ //System.out.println("drop " + event);
+ event.acceptDrop(DnDConstants.ACTION_COPY);
+
+ Transferable transferable = event.getTransferable();
+ DataFlavor flavors[] = transferable.getTransferDataFlavors();
+ int successful = 0;
+
+ for (int i = 0; i < flavors.length; i++) {
+ try {
+ //System.out.println(flavors[i]);
+ //System.out.println(transferable.getTransferData(flavors[i]));
+ java.util.List list =
+ (java.util.List) transferable.getTransferData(flavors[i]);
+ for (int j = 0; j < list.size(); j++) {
+ Object item = list.get(j);
+ if (item instanceof File) {
+ File file = (File) item;
+
+ // see if this is a .pde file to be opened
+ String filename = file.getName();
+ if (filename.endsWith(".pde")) {
+ String name = filename.substring(0, filename.length() - 4);
+ File parent = file.getParentFile();
+ if (name.equals(parent.getName())) {
+ handleOpenFile(file);
+ return;
+ }
+ }
+
+ if (sketch.addFile(file)) {
+ successful++;
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (successful == 0) {
+ error("No files were added to the sketch.");
+
+ } else if (successful == 1) {
+ message("One file added to the sketch.");
+
+ } else {
+ message(successful + " files added to the sketch.");
}
}
});
- */
}
/**
- * Hack for #@#)$(* Mac OS X.
- * This appears to only be required on OS X 10.2, and this code
- * isn't even being hit on OS X 10.3 or Windows.
+ * Hack for #@#)$(* Mac OS X 10.2.
+ * <p/>
+ * This appears to only be required on OS X 10.2, and is not
+ * even being called on later versions of OS X or Windows.
*/
public Dimension getMinimumSize() {
//System.out.println("getting minimum size");
@@ -271,6 +330,29 @@ public Dimension getMinimumSize() {
// ...................................................................
+ /**
+ * Builds any unbuilt buildable libraries
+ * Adds syntax coloring from those libraries (if exists)
+ * Rebuilds sketchbook menu with library examples (if they exist)
+ */
+ public void prepareLibraries() {
+ // build any unbuilt libraries
+ try {
+ LibraryManager libraryManager = new LibraryManager();
+ libraryManager.buildAllUnbuilt();
+ // update syntax coloring table
+ libraryManager.addSyntaxColoring(new PdeKeywords());
+ } catch (RunnerException re) {
+ message("Error compiling library ...");
+ error(re);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ // update sketchbook menu, this adds examples of any built libs
+ sketchbook.rebuildMenus();
+ }
+
+ // ...................................................................
/**
* Post-constructor setup for the editor area. Loads the last
@@ -435,47 +517,19 @@ protected JMenu buildFileMenu() {
JMenuItem item;
JMenu menu = new JMenu("File");
- /*
- menu.add(item = new JMenuItem("do the editor thing"));
+ item = newJMenuItem("New", 'N');
item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textarea.getPainter().setFont(new Font("Courier", Font.PLAIN, 36));
- }
- });
- */
-
- if (!Preferences.getBoolean("export.library")) {
- item = newJMenuItem("New", 'N');
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleNew(false);
- }
- });
- menu.add(item);
-
- } else {
- item = newJMenuItem("New Sketch", 'N');
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleNew(false);
- }
- });
- menu.add(item);
-
- item = new JMenuItem("New Library");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleNewLibrary();
- }
- });
- menu.add(item);
- }
+ public void actionPerformed(ActionEvent e) {
+ handleNew(false);
+ }
+ });
+ menu.add(item);
menu.add(sketchbook.getOpenMenu());
saveMenuItem = newJMenuItem("Save", 'S');
saveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- handleSave();
+ handleSave(false);
}
});
menu.add(saveMenuItem);
@@ -488,7 +542,7 @@ public void actionPerformed(ActionEvent e) {
});
menu.add(saveAsMenuItem);
- item = newJMenuItem("Export", 'E');
+ item = newJMenuItem("Upload to I/O Board", 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport();
@@ -496,14 +550,18 @@ public void actionPerformed(ActionEvent e) {
});
menu.add(item);
- exportAppItem = newJMenuItem("Export Application", 'E', true);
+ /*exportAppItem = newJMenuItem("Export Application", 'E', true);
exportAppItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- handleExportApp();
+ //buttons.activate(EditorButtons.EXPORT);
+ //SwingUtilities.invokeLater(new Runnable() {
+ //public void run() {
+ handleExportApplication();
+ //}});
}
});
menu.add(exportAppItem);
-
+ */
menu.addSeparator();
item = newJMenuItem("Page Setup", 'P', true);
@@ -544,7 +602,7 @@ protected JMenu buildSketchMenu() {
JMenuItem item;
JMenu menu = new JMenu("Sketch");
- item = newJMenuItem("Run", 'R');
+ item = newJMenuItem("Verify/Compile", 'R');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleRun(false);
@@ -552,14 +610,14 @@ public void actionPerformed(ActionEvent e) {
});
menu.add(item);
- //item = newJMenuItem("Present", 'R', true);
- //item.addActionListener(new ActionListener() {
- // public void actionPerformed(ActionEvent e) {
- // handleRun(true);
- // }
- // });
- //menu.add(item);
-
+ /*item = newJMenuItem("Present", 'R', true);
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ handleRun(true);
+ }
+ });
+ menu.add(item);
+ */
item = new JMenuItem("Stop");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -578,12 +636,12 @@ public void actionPerformed(ActionEvent e) {
});
menu.add(item);
- //menu.add(sketchbook.getImportMenu());
+ menu.add(sketchbook.getImportMenu());
if (Base.isWindows() || Base.isMacOS()) {
// no way to do an 'open in file browser' on other platforms
// since there isn't any sort of standard
- item = new JMenuItem("Show Sketch Folder");
+ item = newJMenuItem("Show Sketch Folder", 'K', false);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Base.openFolder(sketchDir);
@@ -599,187 +657,226 @@ public void actionPerformed(ActionEvent e) {
}
- // taken from an ancient version of processing
- class SerialMenuListener implements ActionListener {
-
- SerialMenuListener() {}
-
- public void actionPerformed(ActionEvent actionevent) {
- int count = serialSubMenu.getItemCount();
- Object to;
-
- for (int i = 0; i < count; i++) {
- to = serialSubMenu.getItem(i);
- if ( to instanceof JCheckBoxMenuItem) ((JCheckBoxMenuItem)serialSubMenu.getItem(i)).setState(false);
- }
-
- JCheckBoxMenuItem item = (JCheckBoxMenuItem)actionevent.getSource();
- item.setState(true);
- String name = item.getLabel();
-
- Preferences.set("serial.port", name);
- //System.out.println("port set to " + name);
- }
-
-
- }
-
- // manages the serial port speed menu
- class SerialRateMenuListener implements ActionListener {
-
- SerialRateMenuListener() {}
-
- public void actionPerformed(ActionEvent actionevent) {
- int count = serialRateSubMenu.getItemCount();
- Object to;
-
- for (int i = 0; i < count; i++) {
- to = serialRateSubMenu.getItem(i);
- if ( to instanceof JCheckBoxMenuItem) ((JCheckBoxMenuItem)serialRateSubMenu.getItem(i)).setState(false);
- }
-
- JCheckBoxMenuItem item = (JCheckBoxMenuItem)actionevent.getSource();
- item.setState(true);
- String name = item.getLabel();
-
- Preferences.set("serial.download_rate", name);
- //System.out.println("serial port speed set to " + name);
- }
-
-
- }
-
-
-
-
protected JMenu buildToolsMenu() {
- JMenuItem item;
- JMenuItem rbMenuItem;
- JMenuItem cbMenuItem;
- SerialRateMenuListener srml = new SerialRateMenuListener();
- // Enumeration portRates = {"9600","19200","38400","57600","115200"};
+ JMenuItem item;
+ JMenuItem rbMenuItem;
+ JMenuItem cbMenuItem;
+ SerialRateMenuListener srml = new SerialRateMenuListener();
+ String[] portRates = {
+ "300","1200","2400","4800","9600","14400",
+ "19200","28800","38400","57600","115200"
+ };
- serialMenuListener = new SerialMenuListener();
+ serialMenuListener = new SerialMenuListener();
JMenu menu = new JMenu("Tools");
item = newJMenuItem("Auto Format", 'T', false);
item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ synchronized public void actionPerformed(ActionEvent e) {
new AutoFormat(Editor.this).show();
-
+ //handleBeautify();
+ }
+ });
+ menu.add(item);
+
+ /*item = new JMenuItem("Create Font...");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ //new CreateFont().show(sketch.dataFolder);
+ new CreateFont(Editor.this).show();
+ }
+ });
+ menu.add(item);
+ */
+ item = new JMenuItem("Archive Sketch");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ new Archiver(Editor.this).show();
+ //Archiver archiver = new Archiver();
+ //archiver.setup(Editor.this);
+ //archiver.show();
}
});
menu.add(item);
- menu.addSeparator();
-
- // The serial options
-
- serialSubMenu = new JMenu("Serial port");
-
-// item = newJMenuItem("Update List", 'E', false);
-// item.addActionListener(new ActionListener() {
-// public void actionPerformed(ActionEvent e) {
-// // if (debug) displayResult("Serial Port List Updated");
-// //updateSerial();
-// }
-// });
-
- //serialGroup = new ButtonGroup();
- populateSerialMenu();
- menu.add(serialSubMenu);
-
- // End of The serial options
- // menu.addSeparator();
+ item = new JMenuItem("Export Folder...");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ new ExportFolder(Editor.this).show();
+ }
+ });
+ menu.add(item);
+ menu.addSeparator();
- // add the serial speed submenu
+ serialMenu = new JMenu("Serial Port");
+ populateSerialMenu();
+ menu.add(serialMenu);
- serialRateSubMenu = new JMenu("Serial port speed");
-
- //serialSubMenu.add(item);
- //serialSubMenu.addSeparator();
- ButtonGroup group = new ButtonGroup();
-
- int curr_rate = Preferences.getInteger("serial.download_rate");
-
- rbMenuItem = new JCheckBoxMenuItem("9600", 9600 == curr_rate);
- rbMenuItem.addActionListener(srml);
- group.add(rbMenuItem);
- serialRateSubMenu.add(rbMenuItem);
-
- rbMenuItem = new JCheckBoxMenuItem("19200", 19200 == curr_rate);
- rbMenuItem.addActionListener(srml);
- group.add(rbMenuItem);
- serialRateSubMenu.add(rbMenuItem);
-
- rbMenuItem = new JCheckBoxMenuItem("115200", 115200 == curr_rate);
- rbMenuItem.addActionListener(srml);
- group.add(rbMenuItem);
- serialRateSubMenu.add(rbMenuItem);
-
- menu.add(serialRateSubMenu);
+ serialRateMenu = new JMenu("Serial Monitor Baud Rate");
+
+ ButtonGroup group = new ButtonGroup();
+
+ String curr_rate = Preferences.get("serial.debug_rate");
+
+ for (int i = 0; i < portRates.length; i++) {
+ rbMenuItem = new JCheckBoxMenuItem(portRates[i], portRates[i].equals(curr_rate));
+ rbMenuItem.addActionListener(srml);
+ group.add(rbMenuItem);
+ serialRateMenu.add(rbMenuItem);
+ }
+
+ menu.add(serialRateMenu);
+
+ menu.addSeparator();
+
+ item = new JMenuItem("Burn Bootloader");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ handleBurnBootloader(false);
+ }
+ });
+ menu.add(item);
+
+ if (!Base.isMacOS()) {
+ item = new JMenuItem("Burn Bootloader (parallel port)");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ handleBurnBootloader(true);
+ }
+ });
+ menu.add(item);
+ }
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent e) {}
public void menuDeselected(MenuEvent e) {}
public void menuSelected(MenuEvent e) {
+ //System.out.println("Tools menu selected.");
populateSerialMenu();
}
});
return menu;
}
+
+ class SerialMenuListener implements ActionListener {
+ //public SerialMenuListener() { }
+
+ public void actionPerformed(ActionEvent e) {
+ if(serialMenu == null) {
+ System.out.println("serialMenu is null");
+ return;
+ }
+ int count = serialMenu.getItemCount();
+ for (int i = 0; i < count; i++) {
+ ((JCheckBoxMenuItem)serialMenu.getItem(i)).setState(false);
+ }
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem)e.getSource();
+ item.setState(true);
+ String name = item.getLabel();
+ //System.out.println(item.getLabel());
+ Preferences.set("serial.port", name);
+ //System.out.println("set to " + get("serial.port"));
+ }
+
+ /*
+ public void actionPerformed(ActionEvent e) {
+ System.out.println(e.getSource());
+ String name = e.getActionCommand();
+ PdeBase.properties.put("serial.port", name);
+ System.out.println("set to " + get("serial.port"));
+ //editor.skOpen(path + File.separator + name, name);
+ // need to push "serial.port" into PdeBase.properties
+ }
+ */
+ }
+
+ // manages the serial port speed menu
+ class SerialRateMenuListener implements ActionListener {
+
+ SerialRateMenuListener() {}
+
+ public void actionPerformed(ActionEvent actionevent) {
+ int count = serialRateMenu.getItemCount();
+ Object to;
+
+ for (int i = 0; i < count; i++) {
+ to = serialRateMenu.getItem(i);
+ if ( to instanceof JCheckBoxMenuItem) ((JCheckBoxMenuItem)serialRateMenu.getItem(i)).setState(false);
+ }
+
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem)actionevent.getSource();
+ item.setState(true);
+ String name = item.getLabel();
+
+ Preferences.set("serial.debug_rate", name);
+ //System.out.println("serial port speed set to " + name);
+ }
+
+
+ }
protected void populateSerialMenu() {
- // getting list of ports
+ // getting list of ports
JMenuItem rbMenuItem;
- serialSubMenu.removeAll();
-
- try
- {
- for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
- {
- CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
- if (commportidentifier.getPortType() == CommPortIdentifier.PORT_SERIAL)
- {
- String curr_port = commportidentifier.getName();
- rbMenuItem = new JCheckBoxMenuItem(curr_port, curr_port.equals(Preferences.get("serial.port")));
- rbMenuItem.addActionListener(serialMenuListener);
- //serialGroup.add(rbMenuItem);
- serialSubMenu.add(rbMenuItem);
- }
- }
-
- }
-
- catch (Exception exception)
- {
- System.out.println("error retrieving port list");
- exception.printStackTrace();
- }
+ //System.out.println("Clearing serial port menu.");
+
+ serialMenu.removeAll();
+
+ try
+ {
+ for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
+ {
+ CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
+ //System.out.println("Found communication port: " + commportidentifier);
+ if (commportidentifier.getPortType() == CommPortIdentifier.PORT_SERIAL)
+ {
+ //System.out.println("Adding port to serial port menu: " + commportidentifier);
+ String curr_port = commportidentifier.getName();
+ rbMenuItem = new JCheckBoxMenuItem(curr_port, curr_port.equals(Preferences.get("serial.port")));
+ rbMenuItem.addActionListener(serialMenuListener);
+ //serialGroup.add(rbMenuItem);
+ serialMenu.add(rbMenuItem);
+ }
+ }
+
+ }
+
+ catch (Exception exception)
+ {
+ System.out.println("error retrieving port list");
+ exception.printStackTrace();
+ }
- if (serialSubMenu.getItemCount() == 0) {
- serialSubMenu.setEnabled(false);
- }
+ if (serialMenu.getItemCount() == 0) {
+ serialMenu.setEnabled(false);
+ }
- //serialSubMenu.addSeparator();
- //serialSubMenu.add(item);
+ //serialMenu.addSeparator();
+ //serialMenu.add(item);
}
-
protected JMenu buildHelpMenu() {
JMenu menu = new JMenu("Help");
JMenuItem item;
+ item = new JMenuItem("Howto");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ Base.openURL(System.getProperty("user.dir") + File.separator +
+ "reference" + File.separator + "howto.html");
+ }
+ });
+ menu.add(item);
+
item = new JMenuItem("Environment");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.openURL(System.getProperty("user.dir") + File.separator +
- "reference" + File.separator + "environment" +
- File.separator + "index.html");
+ "reference" + File.separator + "environment.html");
}
});
menu.add(item);
@@ -793,31 +890,40 @@ public void actionPerformed(ActionEvent e) {
});
menu.add(item);
- item = newJMenuItem("Find in Reference", 'F', true);
+ item = new JMenuItem("Frequently Asked Questions");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- if (textarea.isSelectionActive()) {
- String text = textarea.getSelectedText();
- if (text.length() == 0) {
- message("First select a word to find in the reference.");
-
- } else {
- String referenceFile = PdeKeywords.getReference(text);
- if (referenceFile == null) {
- message("No reference available for \"" + text + "\"");
- } else {
- Base.showReference(referenceFile);
- }
- }
- }
+ Base.openURL(System.getProperty("user.dir") + File.separator +
+ "reference" + File.separator + "FAQ.html");
}
});
menu.add(item);
- item = newJMenuItem("Visit arduino.berlios.de", '5');
+// item = newJMenuItem("Find in Reference", 'F', true);
+// item.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// if (textarea.isSelectionActive()) {
+// String text = textarea.getSelectedText();
+// if (text.length() == 0) {
+// message("First select a word to find in the reference.");
+//
+// } else {
+// String referenceFile = PdeKeywords.getReference(text);
+// if (referenceFile == null) {
+// message("No reference available for \"" + text + "\"");
+// } else {
+// Base.showReference(referenceFile);
+// }
+// }
+// }
+// }
+// });
+// menu.add(item);
+
+ item = newJMenuItem("Visit www.arduino.cc", '5');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- Base.openURL("http://arduino.berlios.de/");
+ Base.openURL("http://www.arduino.cc/");
}
});
menu.add(item);
@@ -858,7 +964,7 @@ public JMenu buildEditMenu() {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textarea.cut();
- sketch.setModified();
+ sketch.setModified(true);
}
});
menu.add(item);
@@ -875,7 +981,7 @@ public void actionPerformed(ActionEvent e) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textarea.paste();
- sketch.setModified();
+ sketch.setModified(true);
}
});
menu.add(item);
@@ -893,7 +999,9 @@ public void actionPerformed(ActionEvent e) {
item = newJMenuItem("Find...", 'F');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- find.show();
+ new FindReplace(Editor.this).show();
+ //find.show();
+ //find.setVisible(true);
}
});
menu.add(item);
@@ -903,6 +1011,8 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
// TODO find next should only be enabled after a
// search has actually taken place
+ //find.find(true);
+ FindReplace find = new FindReplace(Editor.this); //.show();
find.find(true);
}
});
@@ -962,11 +1072,17 @@ protected void updateUndoState() {
undoItem.setEnabled(true);
undoItem.setText(undo.getUndoPresentationName());
putValue(Action.NAME, undo.getUndoPresentationName());
+ if (sketch != null) {
+ sketch.setModified(true); // 0107
+ }
} else {
this.setEnabled(false);
undoItem.setEnabled(false);
undoItem.setText("Undo");
putValue(Action.NAME, "Undo");
+ if (sketch != null) {
+ sketch.setModified(false); // 0107
+ }
}
}
}
@@ -991,7 +1107,7 @@ public void actionPerformed(ActionEvent e) {
protected void updateRedoState() {
if (undo.canRedo()) {
- this.setEnabled(true);
+ //this.setEnabled(true);
redoItem.setEnabled(true);
redoItem.setText(undo.getRedoPresentationName());
putValue(Action.NAME, undo.getRedoPresentationName());
@@ -1075,60 +1191,20 @@ public String getText() {
* Called to update the text but not switch to a different
* set of code (which would affect the undo manager).
*/
- //public void setText(String what) { //, boolean discardUndo) {
- //setText(what, 0, 0);
- //}
-
-
- /**
- * Called to update the text but not switch to a different
- * set of code (which would affect the undo manager).
- */
public void setText(String what, int selectionStart, int selectionEnd) {
+ beginCompoundEdit();
textarea.setText(what);
- textarea.select(selectionStart, selectionEnd);
- textarea.requestFocus(); // get the caret blinking
- }
+ endCompoundEdit();
-
- /**
- * Called by Sketch when the tab is changed or a new set of files are opened.
- */
- /*
- public void setText(String currentProgram,
- int selectionStart, int selectionEnd,
- UndoManager currentUndo) {
- //System.out.println("setting text, changing undo");
- this.undo = null;
-
- //if (discardUndo) undo.discardAllEdits();
-
- // don't set the undo object yet otherwise gets hokey
- textarea.setText(currentProgram);
+ // make sure that a tool isn't asking for a bad location
+ selectionStart =
+ Math.max(0, Math.min(selectionStart, textarea.getDocumentLength()));
+ selectionEnd =
+ Math.max(0, Math.min(selectionStart, textarea.getDocumentLength()));
textarea.select(selectionStart, selectionEnd);
- textarea.requestFocus(); // get the caret blinking
-
- this.undo = currentUndo;
- undoAction.updateUndoState();
- redoAction.updateRedoState();
- }
- */
-
- /*
- public void setDocument(SyntaxDocument document,
- int selectionStart, int selectionStop,
- int scrollPosition, UndoManager undo) {
-
- textarea.setDocument(document, selectionStart, selectionStop,
- scrollPosition);
textarea.requestFocus(); // get the caret blinking
-
- this.undo = undo;
- undoAction.updateUndoState();
- redoAction.updateRedoState();
}
- */
/**
@@ -1155,7 +1231,10 @@ public void setCode(SketchCode code) {
// connect the undo listener to the editor
code.document.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
- if (undo != null) {
+ if (compoundEdit != null) {
+ compoundEdit.addEdit(e.getEdit());
+
+ } else if (undo != null) {
undo.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
@@ -1176,12 +1255,24 @@ public void undoableEditHappened(UndoableEditEvent e) {
redoAction.updateRedoState();
}
+ public void beginCompoundEdit() {
+ compoundEdit = new CompoundEdit();
+ }
+
+ public void endCompoundEdit() {
+ compoundEdit.end();
+ undo.addEdit(compoundEdit);
+ undoAction.updateUndoState();
+ redoAction.updateRedoState();
+ compoundEdit = null;
+ }
+
public void handleRun(boolean present) {
doClose();
running = true;
- buttons.run();
+ buttons.activate(EditorButtons.RUN);
message("Compiling...");
// do this for the terminal window / dos prompt / etc
for (int i = 0; i < 10; i++) System.out.println();
@@ -1267,17 +1358,15 @@ public RunButtonWatcher() {
}
public void run() {
- /*
while (Thread.currentThread() == thread) {
- if (runtime == null) {
+ /*if (runtime == null) {
stop();
} else {
- // FIXME remove dependance from core libs
- //if (runtime.applet != null) {
- // if (runtime.applet.finished) {
- // stop();
- //}
+ if (runtime.applet != null) {
+ if (runtime.applet.finished) {
+ stop();
+ }
//buttons.running(!runtime.applet.finished);
} else if (runtime.process != null) {
@@ -1286,13 +1375,12 @@ public void run() {
} else {
stop();
}
- }
+ }*/
try {
Thread.sleep(250);
} catch (InterruptedException e) { }
//System.out.println("still inside runner thread");
}
- */
}
public void stop() {
@@ -1305,6 +1393,7 @@ public void stop() {
public void handleSerial() {
if (!debugging) {
console.clear();
+ buttons.activate(EditorButtons.SERIAL);
serialPort = new Serial(true);
debugging = true;
} else {
@@ -1319,6 +1408,7 @@ public void handleStop() { // called by menu or buttons
} else {
doStop();
}
+ buttons.clear();
}
@@ -1326,11 +1416,11 @@ public void handleStop() { // called by menu or buttons
* Stop the applet but don't kill its window.
*/
public void doStop() {
+ //if (runtime != null) runtime.stop();
if (debugging) {
serialPort.dispose();
debugging = false;
}
- if (runtime != null) runtime.stop();
if (watcher != null) watcher.stop();
message(EMPTY);
@@ -1347,32 +1437,31 @@ public void doStop() {
* mode, this will always be called instead of doStop().
*/
public void doClose() {
- /*
//if (presenting) {
//presentationWindow.hide();
//} else {
- try {
+ //try {
// the window will also be null the process was running
// externally. so don't even try setting if window is null
// since Runner will set the appletLocation when an
// external process is in use.
- //if (runtime.window != null) {
- appletLocation = runtime.window.getLocation();
- }
- } catch (NullPointerException e) { }
+// if (runtime.window != null) {
+// appletLocation = runtime.window.getLocation();
+// }
+ //} catch (NullPointerException e) { }
//}
//if (running) doStop();
doStop(); // need to stop if runtime error
- try {
- if (runtime != null) {
+ //try {
+ /*if (runtime != null) {
runtime.close(); // kills the window
runtime = null; // will this help?
- }
- } catch (Exception e) { }
+ }*/
+ //} catch (Exception e) { }
//buttons.clear(); // done by doStop
- */
+
sketch.cleanup();
// [toxi 030903]
@@ -1426,7 +1515,7 @@ protected void checkModified(int checkModifiedMode) {
options[0]);
if (result == JOptionPane.YES_OPTION) {
- handleSave();
+ handleSave(true);
checkModified2();
} else if (result == JOptionPane.NO_OPTION) {
@@ -1456,15 +1545,20 @@ public void checkModified2() {
/**
* New was called (by buttons or by menu), first check modified
* and if things work out ok, handleNew2() will be called.
- *
+ * <p/>
* If shift is pressed when clicking the toolbar button, then
* force the opposite behavior from sketchbook.prompt's setting
*/
- public void handleNew(boolean shift) {
- doStop();
- handleNewShift = shift;
- handleNewLibrary = false;
- checkModified(HANDLE_NEW);
+ public void handleNew(final boolean shift) {
+ buttons.activate(EditorButtons.NEW);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ doStop();
+ handleNewShift = shift;
+ handleNewLibrary = false;
+ checkModified(HANDLE_NEW);
+ }});
}
@@ -1515,6 +1609,7 @@ protected void handleNew2(boolean noPrompt) {
"An error occurred while creating\n" +
"a new sketch. Arduino must now quit.", e);
}
+ buttons.clear();
}
@@ -1532,15 +1627,22 @@ public void handleOpenFile(File file) {
* Open a sketch given the full path to the .pde file.
* Pass in 'null' to prompt the user for the name of the sketch.
*/
- public void handleOpen(String path) {
- if (path == null) { // "open..." selected from the menu
- path = sketchbook.handleOpen();
- if (path == null) return;
- }
- doClose();
- //doStop();
- handleOpenPath = path;
- checkModified(HANDLE_OPEN);
+ public void handleOpen(final String ipath) {
+ // haven't run across a case where i can verify that this works
+ // because open is usually very fast.
+ buttons.activate(EditorButtons.OPEN);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ String path = ipath;
+ if (path == null) { // "open..." selected from the menu
+ path = sketchbook.handleOpen();
+ if (path == null) return;
+ }
+ doClose();
+ handleOpenPath = path;
+ checkModified(HANDLE_OPEN);
+ }});
}
@@ -1653,7 +1755,7 @@ protected void handleOpen2(String path) {
sketch = new Sketch(this, path);
// TODO re-enable this once export application works
- exportAppItem.setEnabled(false);
+ //exportAppItem.setEnabled(false);
//exportAppItem.setEnabled(false && !sketch.isLibrary());
//buttons.disableRun(sketch.isLibrary());
header.rebuild();
@@ -1668,7 +1770,32 @@ protected void handleOpen2(String path) {
// there is no handleSave1 since there's never a need to prompt
- public void handleSave() {
+ /**
+ * Actually handle the save command. If 'force' is set to false,
+ * this will happen in another thread so that the message area
+ * will update and the save button will stay highlighted while the
+ * save is happening. If 'force' is true, then it will happen
+ * immediately. This is used during a quit, because invokeLater()
+ * won't run properly while a quit is happening. This fixes
+ * <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=276">Bug 276</A>.
+ */
+ public void handleSave(boolean force) {
+ doStop();
+ buttons.activate(EditorButtons.SAVE);
+
+ if (force) {
+ handleSave2();
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ handleSave2();
+ }
+ });
+ }
+ }
+
+
+ public void handleSave2() {
message("Saving...");
try {
if (sketch.save()) {
@@ -1694,21 +1821,24 @@ public void handleSave() {
public void handleSaveAs() {
doStop();
+ buttons.activate(EditorButtons.SAVE);
- message("Saving...");
- try {
- if (sketch.saveAs()) {
- message("Done Saving.");
- sketchbook.rebuildMenus();
- } else {
- message("Save Cancelled.");
- }
-
- } catch (Exception e) {
- // show the error as a message in the window
- error(e);
- }
- buttons.clear();
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ message("Saving...");
+ try {
+ if (sketch.saveAs()) {
+ message("Done Saving.");
+ sketchbook.rebuildMenus();
+ } else {
+ message("Save Cancelled.");
+ }
+ } catch (Exception e) {
+ // show the error as a message in the window
+ error(e);
+ }
+ buttons.clear();
+ }});
}
@@ -1722,37 +1852,87 @@ public void handleSaveAs() {
synchronized public void handleExport() {
if(debugging)
doStop();
+ buttons.activate(EditorButtons.EXPORT);
console.clear();
//String what = sketch.isLibrary() ? "Applet" : "Library";
//message("Exporting " + what + "...");
message("Uploading to I/O Board...");
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ //boolean success = sketch.isLibrary() ?
+ //sketch.exportLibrary() : sketch.exportApplet();
+ boolean success = sketch.exportApplet(new Target(
+ System.getProperty("user.dir") + File.separator + "lib" +
+ File.separator + "targets", Preferences.get("build.target")));
+ if (success) {
+ message("Done uploading.");
+ } else {
+ // error message will already be visible
+ }
+ } catch (RunnerException e) {
+ message("Error during upload.");
+ //e.printStackTrace();
+ error(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ buttons.clear();
+ }});
+ }
+
+
+ synchronized public void handleExportApp() {
+ message("Exporting application...");
try {
- //boolean success = sketch.isLibrary() ?
- //sketch.exportLibrary() : sketch.exportApplet();
- boolean success = sketch.exportApplet(new Target(
- System.getProperty("user.dir") + File.separator + "lib" +
- File.separator + "targets", Preferences.get("build.target")));
- if (success) {
- message("Done uploading.");
+ if (sketch.exportApplication()) {
+ message("Done exporting.");
} else {
// error message will already be visible
}
- } catch (RunnerException e) {
- message("Error during upload.");
- //e.printStackTrace();
- error(e);
} catch (Exception e) {
+ message("Error during export.");
e.printStackTrace();
}
buttons.clear();
}
- synchronized public void handleExportApp() {
- message("Arduino - Export - app");
- }
+ /**
+ * Checks to see if the sketch has been modified, and if so,
+ * asks the user to save the sketch or cancel the export.
+ * This prevents issues where an incomplete version of the sketch
+ * would be exported, and is a fix for
+ * <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=157">Bug 157</A>
+ */
+ public boolean handleExportCheckModified() {
+ if (!sketch.modified) return true;
+
+ Object[] options = { "OK", "Cancel" };
+ int result = JOptionPane.showOptionDialog(this,
+ "Save changes before export?",
+ "Save",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ options,
+ options[0]);
+ if (result == JOptionPane.OK_OPTION) {
+ handleSave(true);
+ } else {
+ // why it's not CANCEL_OPTION is beyond me (at least on the mac)
+ // but f-- it.. let's get this shite done..
+ //} else if (result == JOptionPane.CANCEL_OPTION) {
+ message("Export canceled, changes must first be saved.");
+ buttons.clear();
+ return false;
+ }
+ return true;
+ }
+
/**
* Quit, but first ask user if it's ok. Also store preferences
* to disk just in case they want to quit. Final exit() happens
@@ -1775,11 +1955,41 @@ protected void handleQuit2() {
Preferences.save();
sketchbook.clean();
+ console.handleQuit();
//System.out.println("exiting here");
System.exit(0);
}
+ protected void handleBurnBootloader(boolean parallel) {
+ if(debugging)
+ doStop();
+ console.clear();
+ //String what = sketch.isLibrary() ? "Applet" : "Library";
+ //message("Exporting " + what + "...");
+ message("Burning bootloader to I/O Board...");
+ try {
+ //boolean success = sketch.isLibrary() ?
+ //sketch.exportLibrary() : sketch.exportApplet();
+ Uploader uploader = new Uploader();
+ boolean success = parallel ?
+ uploader.burnBootloaderParallel() :
+ uploader.burnBootloaderAVRISP();
+
+ if (success) {
+ message("Done burning bootloader.");
+ } else {
+ // error message will already be visible
+ }
+ } catch (RunnerException e) {
+ message("Error while burning bootloader.");
+ //e.printStackTrace();
+ error(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ buttons.clear();
+ }
public void highlightLine(int lnum) {
if (lnum < 0) {
@@ -1834,6 +2044,14 @@ else if (lc == lnum+1) {
// ...................................................................
+ /**
+ * Show an error int the status bar.
+ */
+ public void error(String what) {
+ status.error(what);
+ }
+
+
public void error(Exception e) {
if (e == null) {
System.err.println("Editor.error() was passed a null exception.");
@@ -1852,7 +2070,7 @@ public void error(Exception e) {
if (mess.indexOf(javaLang) == 0) {
mess = mess.substring(javaLang.length());
}
- status.error(mess);
+ error(mess);
}
e.printStackTrace();
}
@@ -1870,37 +2088,23 @@ public void error(RunnerException e) {
String rxString = "RuntimeException: ";
if (mess.indexOf(rxString) == 0) {
mess = mess.substring(rxString.length());
+ //System.out.println("MESS3: " + mess);
}
String javaLang = "java.lang.";
if (mess.indexOf(javaLang) == 0) {
mess = mess.substring(javaLang.length());
}
- status.error(mess);
-
- buttons.clearRun();
+ error(mess);
+ buttons.clear();
}
- /*
- public void finished() {
- running = false;
- buttons.clearRun();
- message("Done.");
- }
- */
-
public void message(String msg) {
status.notice(msg);
}
- /*
- public void messageClear(String msg) {
- status.unnotice(msg);
- }
- */
-
// ...................................................................
@@ -1909,7 +2113,6 @@ public void messageClear(String msg) {
* Returns the edit popup menu.
*/
class TextAreaPopup extends JPopupMenu {
- //protected ReferenceKeys referenceItems = new ReferenceKeys();
String currentDir = System.getProperty("user.dir");
String referenceFile = null;
@@ -1924,6 +2127,7 @@ public TextAreaPopup() {
cutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textarea.cut();
+ sketch.setModified(true);
}
});
this.add(cutItem);
@@ -1940,6 +2144,7 @@ public void actionPerformed(ActionEvent e) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textarea.paste();
+ sketch.setModified(true);
}
});
this.add(item);
@@ -1954,13 +2159,13 @@ public void actionPerformed(ActionEvent e) {
this.addSeparator();
- referenceItem = new JMenuItem("Find in Reference");
- referenceItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Base.showReference(referenceFile);
- }
- });
- this.add(referenceItem);
+// referenceItem = new JMenuItem("Find in Reference");
+// referenceItem.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// Base.showReference(referenceFile);
+// }
+// });
+// this.add(referenceItem);
}
// if no text is selected, disable copy and cut menu items
@@ -1969,14 +2174,14 @@ public void show(Component component, int x, int y) {
cutItem.setEnabled(true);
copyItem.setEnabled(true);
- referenceFile = PdeKeywords.getReference(textarea.getSelectedText());
- if (referenceFile != null) {
- referenceItem.setEnabled(true);
- }
+ //referenceFile = PdeKeywords.getReference(textarea.getSelectedText());
+ //if (referenceFile != null) {
+ //referenceItem.setEnabled(true);
+ //}
} else {
cutItem.setEnabled(false);
copyItem.setEnabled(false);
- referenceItem.setEnabled(false);
+ //referenceItem.setEnabled(false);
}
super.show(component, x, y);
}
View
147 app/EditorButtons.java
@@ -37,13 +37,15 @@
public class EditorButtons extends JComponent implements MouseInputListener {
static final String title[] = {
- "Compile", "Stop", "New", "Open", "Save", "Export", "Serial Monitor"
+ "Verify", "Stop", "New", "Open", "Save", "Upload to I/O Board", "Serial Monitor"
};
static final int BUTTON_COUNT = title.length;
- static final int BUTTON_WIDTH = 27; //Preferences.GRID_SIZE;
- static final int BUTTON_HEIGHT = 32; //Preferences.GRID_SIZE;
- static final int BUTTON_GAP = 15; //BUTTON_WIDTH / 2;
+ /// height, width of the toolbar buttons
+ static final int BUTTON_WIDTH = 27;
+ static final int BUTTON_HEIGHT = 32;
+ /// amount of space between groups of buttons on the toolbar
+ static final int BUTTON_GAP = 15;
static final int RUN = 0;
static final int STOP = 1;
@@ -59,7 +61,7 @@
static final int ACTIVE = 2;
Editor editor;
- boolean disableRun;
+ //boolean disableRun;
//Label