Skip to content

Commit 2e26a2d

Browse files
committed
Syncing with Processing 1.0.9 (revision 5766).
1 parent 7f58e22 commit 2e26a2d

38 files changed

+16809
-892
lines changed

app/src/processing/app/Base.java

+24-129
Original file line numberDiff line numberDiff line change
@@ -180,71 +180,7 @@ static public void main(String args[]) {
180180
// setup the theme coloring fun
181181
Theme.init();
182182

183-
if (Base.isMacOS()) {
184-
String properMenuBar = "apple.laf.useScreenMenuBar";
185-
String menubar = Preferences.get(properMenuBar);
186-
if (menubar != null) {
187-
// Get the current menu bar setting and use it
188-
System.setProperty(properMenuBar, menubar);
189-
190-
} else {
191-
// 10.4 is not affected, 10.5 (and prolly 10.6) are
192-
if (System.getProperty("os.version").startsWith("10.4")) {
193-
// Don't bother checking next time
194-
Preferences.set(properMenuBar, "true");
195-
// Also set the menubar now
196-
System.setProperty(properMenuBar, "true");
197-
198-
} else {
199-
// Running 10.5 or 10.6 or whatever, give 'em the business
200-
String warning =
201-
"<html>" +
202-
"<head> <style type=\"text/css\">"+
203-
"b { font: 13pt \"Lucida Grande\" }"+
204-
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
205-
"</style> </head> <body>" +
206-
"<b>Some menus have been disabled.</b>" +
207-
"<p>Due to an Apple bug, the Sketchbook and Example menus " +
208-
"are unusable. <br>" +
209-
"As a workaround, these items will be disabled from the " +
210-
"standard menu bar, <br>" +
211-
"but you can use the Open button on " +
212-
"the toolbar to access the same items. <br>" +
213-
"If this bug makes you sad, " +
214-
"please contact Apple via bugreporter.apple.com.</p>" +
215-
"</body> </html>";
216-
Object[] options = { "OK", "More Info" };
217-
int result = JOptionPane.showOptionDialog(new Frame(),
218-
warning,
219-
"Menu Bar Problem",
220-
JOptionPane.YES_NO_OPTION,
221-
JOptionPane.WARNING_MESSAGE,
222-
null,
223-
options,
224-
options[0]);
225-
if (result == -1) {
226-
// They hit ESC or closed the window, so just hide it for now
227-
// But don't bother setting the preference in the file
228-
} else {
229-
// Shut off in the preferences for next time
230-
//Preferences.set(properMenuBar, "false");
231-
// For 1.0.4, we'll stick with the Apple menu bar,
232-
// and just disable the sketchbook and examples sub-menus.
233-
Preferences.set(properMenuBar, "true");
234-
if (result == 1) { // More Info
235-
Base.openURL("http://dev.processing.org/bugs/show_bug.cgi?id=786");
236-
}
237-
}
238-
// Whether or not canceled, set to false (right now) if we're on 10.5
239-
//System.setProperty(properMenuBar, "false");
240-
// Changing this behavior for 1.0.4
241-
System.setProperty(properMenuBar, "true");
242-
}
243-
}
244-
}
245-
246183
// Set the look and feel before opening the window
247-
// For 0158, moving it lower so that the apple.laf.useScreenMenuBar stuff works
248184
try {
249185
platform.setLookAndFeel();
250186
} catch (Exception e) {
@@ -815,7 +751,8 @@ protected Editor handleOpen(String path, int[] location) {
815751
*/
816752
public boolean handleClose(Editor editor) {
817753
// Check if modified
818-
if (!editor.checkModified(false)) {
754+
boolean immediate = editors.size() == 1;
755+
if (!editor.checkModified(immediate)) {
819756
return false;
820757
}
821758

@@ -993,17 +930,9 @@ public void actionPerformed(ActionEvent e) {
993930
protected void rebuildSketchbookMenu(JMenu menu) {
994931
//System.out.println("rebuilding sketchbook menu");
995932
//new Exception().printStackTrace();
996-
//boolean nativeButBroken = Base.isMacOS() ?
997-
//Preferences.getBoolean("apple.laf.useScreenMenuBar") : false;
998-
boolean nativeButBroken = false;
999-
1000933
try {
1001-
if (nativeButBroken) { // osx workaround
1002-
menu.setEnabled(false);
1003-
} else {
1004934
menu.removeAll();
1005935
addSketches(menu, getSketchbookFolder(), false);
1006-
}
1007936
} catch (IOException e) {
1008937
e.printStackTrace();
1009938
}
@@ -1045,21 +974,13 @@ public void rebuildImportMenu(JMenu importMenu) {
1045974

1046975
public void rebuildExamplesMenu(JMenu menu) {
1047976
//System.out.println("rebuilding examples menu");
1048-
//boolean nativeButBroken = Base.isMacOS() ?
1049-
//Preferences.getBoolean("apple.laf.useScreenMenuBar") : false;
1050-
boolean nativeButBroken = false;
1051-
1052977
try {
1053-
if (nativeButBroken) { // osx workaround
1054-
menu.setEnabled(false);
1055-
} else {
1056-
menu.removeAll();
1057-
boolean found = addSketches(menu, examplesFolder, false);
1058-
if (found) menu.addSeparator();
1059-
found = addSketches(menu, getSketchbookLibrariesFolder(), false);
1060-
if (found) menu.addSeparator();
1061-
addSketches(menu, librariesFolder, false);
1062-
}
978+
menu.removeAll();
979+
boolean found = addSketches(menu, examplesFolder, false);
980+
if (found) menu.addSeparator();
981+
found = addSketches(menu, getSketchbookLibrariesFolder(), false);
982+
if (found) menu.addSeparator();
983+
addSketches(menu, librariesFolder, false);
1063984
} catch (IOException e) {
1064985
e.printStackTrace();
1065986
}
@@ -1965,56 +1886,30 @@ static public void copyFile(File sourceFile,
19651886
* Grab the contents of a file as a string.
19661887
*/
19671888
static public String loadFile(File file) throws IOException {
1968-
return PApplet.join(PApplet.loadStrings(file), "\n");
1969-
1970-
/*
1971-
// empty code file.. no worries, might be getting filled up later
1972-
if (file.length() == 0) return "";
1973-
1974-
//FileInputStream fis = new FileInputStream(file);
1975-
//InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
1976-
//BufferedReader reader = new BufferedReader(isr);
1977-
BufferedReader reader = PApplet.createReader(file);
1978-
1979-
StringBuffer buffer = new StringBuffer();
1980-
String line = null;
1981-
while ((line = reader.readLine()) != null) {
1982-
// char[] cc = line.toCharArray();
1983-
// for (int i = 0; i < cc.length; i++) {
1984-
// char c = cc[i];
1985-
// if (c < 32 || c > 126) System.out.println("found " + c + " " + ((int) c));
1986-
// }
1987-
//
1988-
buffer.append(line);
1989-
buffer.append('\n');
1889+
String[] contents = PApplet.loadStrings(file);
1890+
if (contents == null) return null;
1891+
return PApplet.join(contents, "\n");
19901892
}
1991-
reader.close();
1992-
return buffer.toString();
1993-
*/
1994-
}
19951893

19961894

19971895
/**
19981896
* Spew the contents of a String object out to a file.
19991897
*/
20001898
static public void saveFile(String str, File file) throws IOException {
2001-
PApplet.saveStrings(file, new String[] { str });
2002-
/*
2003-
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
2004-
InputStreamReader isr = new InputStreamReader(bis);
2005-
BufferedReader reader = new BufferedReader(isr);
2006-
2007-
FileOutputStream fos = new FileOutputStream(file);
2008-
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
2009-
PrintWriter writer = new PrintWriter(osw);
2010-
2011-
String line = null;
2012-
while ((line = reader.readLine()) != null) {
2013-
writer.println(line);
1899+
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
1900+
PApplet.saveStrings(temp, new String[] { str });
1901+
if (file.exists()) {
1902+
boolean result = file.delete();
1903+
if (!result) {
1904+
throw new IOException("Could not remove old version of " +
1905+
file.getAbsolutePath());
1906+
}
1907+
}
1908+
boolean result = temp.renameTo(file);
1909+
if (!result) {
1910+
throw new IOException("Could not replace " +
1911+
file.getAbsolutePath());
20141912
}
2015-
writer.flush();
2016-
writer.close();
2017-
*/
20181913
}
20191914

20201915

app/src/processing/app/Editor.java

+65
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public class Editor extends JFrame implements RunnerListener {
114114

115115
EditorLineStatus lineStatus;
116116

117+
boolean newEditor = true;
118+
JEditorPane editorPane;
119+
117120
JEditTextArea textarea;
118121
EditorListener listener;
119122

@@ -229,7 +232,22 @@ public void windowDeactivated(WindowEvent e) {
229232
lineStatus = new EditorLineStatus(textarea);
230233
consolePanel.add(lineStatus, BorderLayout.SOUTH);
231234

235+
// if (newEditor) {
236+
// try {
237+
// setupEditorPane();
238+
// upper.add(editorPane);
239+
// } catch (Exception e1) {
240+
// PrintWriter w = PApplet.createWriter(new File("/Users/fry/Desktop/blah.txt"));
241+
// w.println(e1.getMessage());
242+
// e1.printStackTrace(w);
243+
// w.flush();
244+
// w.close();
245+
//// e1.printStackTrace());
246+
//// e1.printStackTrace(System.out);
247+
// }
248+
// } else {
232249
upper.add(textarea);
250+
// }
233251
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
234252
upper, consolePanel);
235253

@@ -345,6 +363,46 @@ public boolean importData(JComponent src, Transferable transferable) {
345363
}
346364

347365

366+
/*
367+
// http://wiki.netbeans.org/DevFaqEditorCodeCompletionAnyJEditorPane
368+
void setupEditorPane() throws IOException {
369+
editorPane = new JEditorPane();
370+
371+
// This will find the Java editor kit and associate it with
372+
// our editor pane. But that does not give us code completion
373+
// just yet because we have no Java context (i.e. no class path, etc.).
374+
// However, this does give us syntax coloring.
375+
EditorKit kit = CloneableEditorSupport.getEditorKit("text/x-java");
376+
editorPane.setEditorKit(kit);
377+
378+
// You can specify any ".java" file.
379+
// If the file does not exist, it will be created.
380+
// The contents of the file does not matter.
381+
// The extension must be ".java", however.
382+
// String newSourcePath = "/Users/fry/Desktop/tmp.java";
383+
384+
// File tmpFile = new File(newSourcePath);
385+
// System.out.println(tmpFile.getParent() + " " + tmpFile.getName());
386+
// FileObject fob = FileUtil.createData(tmpFile);
387+
File tmpFile = File.createTempFile("temp", ".java");
388+
FileObject fob = FileUtil.toFileObject(FileUtil.normalizeFile(tmpFile));
389+
390+
DataObject dob = DataObject.find(fob);
391+
editorPane.getDocument().putProperty(Document.StreamDescriptionProperty, dob);
392+
393+
// This sets up a default class path for us so that
394+
// we can find all the JDK classes via code completion.
395+
DialogBinding.bindComponentToFile(fob, 0, 0, editorPane);
396+
397+
// Last but not least, we need to fill the editor pane with
398+
// some initial dummy code - as it seems somehow required to
399+
// kick-start code completion.
400+
// A simple dummy package declaration will do.
401+
editorPane.setText("package dummy;");
402+
}
403+
*/
404+
405+
348406
protected void setPlacement(int[] location) {
349407
setBounds(location[0], location[1], location[2], location[3]);
350408
if (location[4] != 0) {
@@ -859,6 +917,13 @@ protected JMenu addInternalTools(JMenu menu) {
859917
menu.add(createToolMenuItem("processing.app.tools.Archiver"));
860918
menu.add(createToolMenuItem("processing.app.tools.FixEncoding"));
861919

920+
/*
921+
//menu.add(createToolMenuItem("processing.app.tools.android.Build"));
922+
item = createToolMenuItem("processing.app.tools.android.Build");
923+
item.setAccelerator(KeyStroke.getKeyStroke('D', modifiers));
924+
menu.add(item);
925+
*/
926+
862927
return menu;
863928
}
864929

0 commit comments

Comments
 (0)