From 029fab7227028faac694e3c30b6432e12824e8af Mon Sep 17 00:00:00 2001 From: benfry Date: Wed, 2 Dec 2009 16:57:25 +0000 Subject: [PATCH] deal with some warnings, minor cleanups --- .classpath | 2 + app/src/processing/app/Base.java | 6 +- app/src/processing/app/Editor.java | 135 ++++++++++++---------- app/src/processing/app/EditorConsole.java | 3 +- app/src/processing/app/debug/Runner.java | 2 +- 5 files changed, 79 insertions(+), 69 deletions(-) diff --git a/.classpath b/.classpath index cdee87054..9bb0d6af0 100644 --- a/.classpath +++ b/.classpath @@ -7,5 +7,7 @@ + + diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 1bfb9103c..ef2b1d6fe 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -193,7 +193,7 @@ public class Base { static protected void initPlatform() { try { - Class platformClass = Class.forName("processing.app.Platform"); + Class platformClass = Class.forName("processing.app.Platform"); if (Base.isMacOS()) { platformClass = Class.forName("processing.app.macosx.Platform"); } else if (Base.isWindows()) { @@ -2075,7 +2075,7 @@ public class Base { static public String[] listFiles(File folder, boolean relative) { String path = folder.getAbsolutePath(); - Vector vector = new Vector(); + Vector vector = new Vector(); listFiles(relative ? (path + File.separator) : "", path, vector); String outgoing[] = new String[vector.size()]; vector.copyInto(outgoing); @@ -2084,7 +2084,7 @@ public class Base { static protected void listFiles(String basePath, - String path, Vector vector) { + String path, Vector vector) { File folder = new File(path); String list[] = folder.list(); if (list == null) return; diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 8f25f1239..8c5c0aa17 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -22,7 +22,6 @@ package processing.app; - import processing.app.debug.*; import processing.app.syntax.*; import processing.app.tools.*; @@ -248,64 +247,7 @@ public class Editor extends JFrame implements RunnerListener { listener = new EditorListener(this, textarea); pain.add(box); - pain.setTransferHandler(new TransferHandler() { - - public boolean canImport(JComponent dest, DataFlavor[] flavors) { - return true; - } - - public boolean importData(JComponent src, Transferable transferable) { - int successful = 0; - - try { - DataFlavor uriListFlavor = - new DataFlavor("text/uri-list;class=java.lang.String"); - - if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { - java.util.List list = (java.util.List) - transferable.getTransferData(DataFlavor.javaFileListFlavor); - for (int i = 0; i < list.size(); i++) { - File file = (File) list.get(i); - if (sketch.addFile(file)) { - successful++; - } - } - } else if (transferable.isDataFlavorSupported(uriListFlavor)) { - //System.out.println("uri list"); - String data = (String)transferable.getTransferData(uriListFlavor); - String[] pieces = PApplet.splitTokens(data, "\r\n"); - //PApplet.println(pieces); - for (int i = 0; i < pieces.length; i++) { - if (pieces[i].startsWith("#")) continue; - - String path = null; - if (pieces[i].startsWith("file:///")) { - path = pieces[i].substring(7); - } else if (pieces[i].startsWith("file:/")) { - path = pieces[i].substring(5); - } - if (sketch.addFile(new File(path))) { - successful++; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - if (successful == 0) { - statusError("No files were added to the sketch."); - - } else if (successful == 1) { - statusNotice("One file added to the sketch."); - - } else { - statusNotice(successful + " files added to the sketch."); - } - return true; - } - }); + pain.setTransferHandler(new FileDropHandler()); // System.out.println("t1"); @@ -333,6 +275,71 @@ public class Editor extends JFrame implements RunnerListener { // All set, now show the window //setVisible(true); } + + + /** + * Handles files dragged & dropped from the desktop and into the editor + * window. Dragging files into the editor window is the same as using + * "Sketch → Add File" for each file. + */ + class FileDropHandler extends TransferHandler { + public boolean canImport(JComponent dest, DataFlavor[] flavors) { + return true; + } + + @SuppressWarnings("unchecked") + public boolean importData(JComponent src, Transferable transferable) { + int successful = 0; + + try { + DataFlavor uriListFlavor = + new DataFlavor("text/uri-list;class=java.lang.String"); + + if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + java.util.List list = (java.util.List) + transferable.getTransferData(DataFlavor.javaFileListFlavor); + for (int i = 0; i < list.size(); i++) { + File file = (File) list.get(i); + if (sketch.addFile(file)) { + successful++; + } + } + } else if (transferable.isDataFlavorSupported(uriListFlavor)) { + // Some platforms (Mac OS X and Linux, when this began) preferred + // this method of moving files. + String data = (String)transferable.getTransferData(uriListFlavor); + String[] pieces = PApplet.splitTokens(data, "\r\n"); + for (int i = 0; i < pieces.length; i++) { + if (pieces[i].startsWith("#")) continue; + + String path = null; + if (pieces[i].startsWith("file:///")) { + path = pieces[i].substring(7); + } else if (pieces[i].startsWith("file:/")) { + path = pieces[i].substring(5); + } + if (sketch.addFile(new File(path))) { + successful++; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + if (successful == 0) { + statusError("No files were added to the sketch."); + + } else if (successful == 1) { + statusNotice("One file added to the sketch."); + + } else { + statusNotice(successful + " files added to the sketch."); + } + return true; + } + } protected void setPlacement(int[] location) { @@ -627,7 +634,7 @@ public class Editor extends JFrame implements RunnerListener { protected void addTools(JMenu menu, File sourceFolder) { - HashMap toolItems = new HashMap(); + HashMap toolItems = new HashMap(); File[] folders = sourceFolder.listFiles(new FileFilter() { public boolean accept(File folder) { @@ -697,7 +704,7 @@ public class Editor extends JFrame implements RunnerListener { // If no class name found, just move on. if (className == null) continue; - Class toolClass = Class.forName(className, true, loader); + Class toolClass = Class.forName(className, true, loader); final Tool tool = (Tool) toolClass.newInstance(); tool.init(Editor.this); @@ -717,7 +724,7 @@ public class Editor extends JFrame implements RunnerListener { e.printStackTrace(); } } - ArrayList toolList = new ArrayList(toolItems.keySet()); + ArrayList toolList = new ArrayList(toolItems.keySet()); if (toolList.size() == 0) return; menu.addSeparator(); @@ -734,7 +741,7 @@ public class Editor extends JFrame implements RunnerListener { try { ZipFile zipFile = new ZipFile(file); - Enumeration entries = zipFile.entries(); + Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); @@ -760,7 +767,7 @@ public class Editor extends JFrame implements RunnerListener { protected JMenuItem createToolMenuItem(String className) { try { - Class toolClass = Class.forName(className); + Class toolClass = Class.forName(className); final Tool tool = (Tool) toolClass.newInstance(); JMenuItem item = new JMenuItem(tool.getMenuTitle()); diff --git a/app/src/processing/app/EditorConsole.java b/app/src/processing/app/EditorConsole.java index 002fb3edd..b040a75e2 100644 --- a/app/src/processing/app/EditorConsole.java +++ b/app/src/processing/app/EditorConsole.java @@ -28,6 +28,7 @@ import java.awt.event.*; import java.io.*; import javax.swing.*; import javax.swing.text.*; + import java.util.*; @@ -389,7 +390,7 @@ public class EditorConsole extends JScrollPane { * swing event thread, so they need to be synchronized */ class BufferedStyledDocument extends DefaultStyledDocument { - ArrayList elements = new ArrayList(); + ArrayList elements = new ArrayList(); int maxLineLength, maxLineCount; int currentLineLength = 0; boolean needLineBreak = false; diff --git a/app/src/processing/app/debug/Runner.java b/app/src/processing/app/debug/Runner.java index f9c33ae40..e2b8f3149 100644 --- a/app/src/processing/app/debug/Runner.java +++ b/app/src/processing/app/debug/Runner.java @@ -126,7 +126,7 @@ public class Runner implements MessageConsumer { protected String[] getMachineParams() { - ArrayList params = new ArrayList(); + ArrayList params = new ArrayList(); //params.add("-Xint"); // interpreted mode //params.add("-Xprof"); // profiler