[Schmitzm-commits] r1904 - in trunk/schmitzm-core/src/main: java/de/schmitzm/swing resources/de/schmitzm/swing/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 20 19:46:36 CET 2012


Author: mojays
Date: 2012-03-20 19:46:36 +0100 (Tue, 20 Mar 2012)
New Revision: 1904

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
SwingUtil:  openDesktopFile(.) moved from WIME to SCHMITZM

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2012-03-15 10:57:18 UTC (rev 1903)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2012-03-20 18:46:36 UTC (rev 1904)
@@ -51,9 +51,11 @@
 import java.awt.event.MouseWheelListener;
 import java.awt.image.BufferedImage;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.net.URL;
 import java.text.DecimalFormat;
 import java.text.Format;
 import java.text.NumberFormat;
@@ -114,6 +116,7 @@
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.log4j.Appender;
@@ -2175,5 +2178,37 @@
         SwingUtilities.invokeLater(work);
       }
     }
+    
+    
+    /**
+     * Oeffnet eine Datei aus dem Classpath ueber {@link Desktop#open(File)}. Hierzu wird die Datei ein lokales
+     * Verzeichnis kopiert.
+     * @param baseResourceClass
+     *            Resource relativ zu der die {@code resourceURL} interpretiert wird (i.d.R. die Main-Class)
+     * @param resourceURL
+     *            Pfad der Datei im Classpath
+     * @param localFolder
+     *            lokaler Pfad in den die Datei kopiert wird
+     */
+    public static void openDesktopFile(Class baseResourceClass, String resourceURL, File localFolder) throws Exception {
+        if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.OPEN))
+            throw new UnsupportedOperationException(R("SwingUtil.openDesktopFile.not.supported"));
 
+        URL fileURL = baseResourceClass.getResource(resourceURL);
+        if (fileURL == null)
+            throw new FileNotFoundException(R("SwingUtil.openDesktopFile.file.not.found.general"));
+
+        // Datei in lokales Verzeichnis kopieren
+        File localFile = new File(localFolder, IOUtil.getFilename(fileURL));
+        FileUtils.copyURLToFile(fileURL, localFile);
+        LOGGER.debug("Help file URL = " + fileURL);
+        LOGGER.debug("Help file = " + localFile);
+        if (localFile == null || !localFile.exists())
+            throw new FileNotFoundException(R("SwingUtil.openDesktopFile.file.not.found",fileURL));
+
+        // Datei oeffnen
+        Desktop.getDesktop().open(localFile);
+    }
+
+
 }

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-03-15 10:57:18 UTC (rev 1903)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-03-20 18:46:36 UTC (rev 1904)
@@ -280,3 +280,6 @@
 FilesSelectionTable.Files=Files
 FilesSelectionTable.Dirs=Directories
 
+SwingUtil.openDesktopFile.not.supported=Your operating system does not support opening files!
+SwingUtil.openDesktopFile.file.not.found.general=The file can not be found.
+SwingUtil.openDesktopFile.file.not.found=The file can not be found: ${0}

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-03-15 10:57:18 UTC (rev 1903)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-03-20 18:46:36 UTC (rev 1904)
@@ -252,3 +252,7 @@
 
 FilesSelectionTable.Files=Dateien
 FilesSelectionTable.Dirs=Verzeichnisse
+
+SwingUtil.openDesktopFile.not.supported=Das Öffnen einer Datei wird von Ihrem Betriebssystem nicht unterstützt.
+SwingUtil.openDesktopFile.file.not.found.general=Die Datei ist nicht vorhanden.
+SwingUtil.openDesktopFile.file.not.found=Die Datei ist nicht vorhanden: ${0}



More information about the Schmitzm-commits mailing list