From 13fc1804e5b1cb2265d7093026aae33ffebafcbc Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 20 Jun 2010 19:56:58 +0000 Subject: [PATCH] moving init to EDT, also minor cleanups while bug fixing --- app/src/processing/app/Base.java | 70 ++++--------------------- app/src/processing/app/Editor.java | 22 +------- app/src/processing/app/FindReplace.java | 21 +------- 3 files changed, 15 insertions(+), 98 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 37f5b4b3e..4ddc347aa 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -93,18 +93,21 @@ public class Base { // Location for untitled items static File untitledFolder; - // p5 icon for the window -// static Image icon; - -// int editorCount; -// Editor[] editors; java.util.List editors = Collections.synchronizedList(new ArrayList()); -// ArrayList editors = Collections.synchronizedList(new ArrayList()); Editor activeEditor; - static public void main(String args[]) { + static public void main(final String[] args) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + createAndShowGUI(args); + } + }); + } + + + static private void createAndShowGUI(String[] args) { try { File versionFile = getContentFile("lib/version.txt"); if (versionFile.exists()) { @@ -118,43 +121,8 @@ public class Base { e.printStackTrace(); } -// if (System.getProperty("mrj.version") != null) { -// //String jv = System.getProperty("java.version"); -// String ov = System.getProperty("os.version"); -// if (ov.startsWith("10.5")) { -// System.setProperty("apple.laf.useScreenMenuBar", "true"); -// } -// } - - /* - commandLine = false; - if (args.length >= 2) { - if (args[0].startsWith("--")) { - commandLine = true; - } - } - - if (PApplet.javaVersion < 1.5f) { - //System.err.println("no way man"); - Base.showError("Need to install Java 1.5", - "This version of Processing requires \n" + - "Java 1.5 or later to run properly.\n" + - "Please visit java.com to upgrade.", null); - } - */ - initPlatform(); -// // Set the look and feel before opening the window -// try { -// platform.setLookAndFeel(); -// } catch (Exception e) { -// System.err.println("Non-fatal error while setting the Look & Feel."); -// System.err.println("The error message follows, however Processing should run fine."); -// System.err.println(e.getMessage()); -// //e.printStackTrace(); -// } - // Use native popups so they don't look so crappy on osx JPopupMenu.setDefaultLightWeightPopupEnabled(false); @@ -719,28 +687,12 @@ public class Base { return null; // Just walk away quietly } -// if (editors == null) { -// editors = new Editor[5]; -// } -// if (editorCount == editors.length) { -// editors = (Editor[]) PApplet.expand(editors); -// } -// editors[editorCount++] = editor; editors.add(editor); -// if (markedForClose != null) { -// Point p = markedForClose.getLocation(); -// handleClose(markedForClose, false); -// // open the new window in -// editor.setLocation(p); -// } - // now that we're ready, show the window // (don't do earlier, cuz we might move it based on a window being closed) editor.setVisible(true); -// System.err.println("exiting handleOpen"); - return editor; } @@ -879,7 +831,7 @@ public class Base { protected void rebuildSketchbookMenus() { //System.out.println("async enter"); //new Exception().printStackTrace(); - SwingUtilities.invokeLater(new Runnable() { + EventQueue.invokeLater(new Runnable() { public void run() { //System.out.println("starting rebuild"); rebuildSketchbookMenu(Editor.sketchbookMenu); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index ae962857f..ae1d81edc 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -151,7 +151,7 @@ public class Editor extends JFrame implements RunnerListener { // When bringing a window to front, let the Base know addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { -// System.err.println("activate"); // not coming through +// EditorConsole.systemOut.println("editor window activated"); base.handleActivated(Editor.this); // re-add the sub-menus that are shared by all windows fileMenu.insert(sketchbookMenu, 2); @@ -162,16 +162,13 @@ public class Editor extends JFrame implements RunnerListener { // added for 1.0.5 // http://dev.processing.org/bugs/show_bug.cgi?id=1260 public void windowDeactivated(WindowEvent e) { -// System.err.println("deactivate"); // not coming through +// EditorConsole.systemErr.println("editor window deactivated"); fileMenu.remove(sketchbookMenu); fileMenu.remove(examplesMenu); sketchMenu.remove(importMenu); } }); - //PdeKeywords keywords = new PdeKeywords(); - //sketchbook = new Sketchbook(this); - buildMenuBar(); // For rev 0120, placing things inside a JPanel @@ -247,17 +244,12 @@ public class Editor extends JFrame implements RunnerListener { pain.setTransferHandler(new FileDropHandler()); -// System.out.println("t1"); - // Finish preparing Editor (formerly found in Base) pack(); -// System.out.println("t2"); - // Set the window bounds and the divider location before setting it visible setPlacement(location); - // If the window is resized too small this will resize it again to the // minimums. Adapted by Chris Lonnen from comments here: // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4320050 @@ -271,21 +263,12 @@ public class Editor extends JFrame implements RunnerListener { } }); -// System.out.println("t3"); - // Bring back the general options for the editor applyPreferences(); -// System.out.println("t4"); - // Open the document that was passed in boolean loaded = handleOpenInternal(path); if (!loaded) sketch = null; - -// System.out.println("t5"); - - // All set, now show the window - //setVisible(true); } @@ -1039,7 +1022,6 @@ public class Editor extends JFrame implements RunnerListener { } //new FindReplace(Editor.this).show(); find.setVisible(true); - //find.setVisible(true); } }); menu.add(item); diff --git a/app/src/processing/app/FindReplace.java b/app/src/processing/app/FindReplace.java index 112eca3ad..9cc0726d2 100644 --- a/app/src/processing/app/FindReplace.java +++ b/app/src/processing/app/FindReplace.java @@ -3,13 +3,12 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + 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. + the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,18 +29,6 @@ import javax.swing.*; /** * Find & Replace window for the Processing editor. - *

- * One major annoyance in this is that the window is re-created each time - * that "Find" is called. This is because Mac OS X has a strange focus - * issue with windows that are re-shown with setVisible() or show(). - * requestFocusInWindow() properly sets the focus to the find field, - * however, just a short moment later, the focus is set to null. Even - * trying to catch this scenario and request it again doesn't seem to work. - * Most likely this is some annoyance buried deep in one of Apple's docs, - * or in the doc for the focus stuff (I tend to think the former because - * Windows doesn't seem to be quite so beligerent). Filed as - * Bug 244 - * should anyone have clues about how to fix. */ public class FindReplace extends JFrame implements ActionListener { @@ -89,10 +76,7 @@ public class FindReplace extends JFrame implements ActionListener { if (findString != null) findField.setText(findString); if (replaceString != null) replaceField.setText(replaceString); - //System.out.println("setting find str to " + findString); - //findField.requestFocusInWindow(); - //pain.setDefault /* findField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { @@ -116,7 +100,6 @@ public class FindReplace extends JFrame implements ActionListener { replaceLabel.setBounds(BIG, BIG + d2.height + SMALL + yoff, d1.width, d1.height); - //ignoreCase = true; ignoreCaseBox = new JCheckBox("Ignore Case"); ignoreCaseBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {