[Schmitzm-commits] r2144 - trunk/schmitzm-core/src/main/java/de/schmitzm/io
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sat Nov 17 19:34:30 CET 2012
Author: mojays
Date: 2012-11-17 19:34:30 +0100 (Sat, 17 Nov 2012)
New Revision: 2144
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
Log:
IOUtil: method to determiner application directory; method to open desktop file ignoring errors
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2012-11-13 20:06:10 UTC (rev 2143)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2012-11-17 18:34:30 UTC (rev 2144)
@@ -29,6 +29,7 @@
******************************************************************************/
package de.schmitzm.io;
+import java.awt.Desktop;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
@@ -2182,5 +2183,44 @@
return false;
}
+ /**
+ * Calls {@link Desktop#open(File)} if {@link Desktop} is available. Exceptions are ignored.
+ * @param file file or folder to open
+ */
+ public static boolean openDesktopFile(String filePath) {
+ return openDesktopFile(new File(filePath));
+ }
+
+ /**
+ * Calls {@link Desktop#open(File)} if {@link Desktop} is available. Exceptions are ignored.
+ * @param file file or folder to open
+ */
+ public static boolean openDesktopFile(File file) {
+ if ( file == null ) {
+ LOGGER.warn("null-File can not be opened via Desktop");
+ return false;
+ }
+ if ( !Desktop.isDesktopSupported() ) {
+ LOGGER.warn("Desktop not supprted. File/Folder "+file.getAbsolutePath()+" can not be opened.");
+ return false;
+ }
+ try {
+ Desktop.getDesktop().open(file);
+ return true;
+ } catch (Exception e) {
+ LOGGER.error("Error opening desktop file",e);
+ }
+ return false;
+ }
+
+ /**
+ * Returns the root folder the running application was started from.
+ */
+ public static File getApplicationDirectory() {
+ File file = new File("");
+ file = new File( file.getAbsolutePath() );
+ return file;
+ }
+
}
More information about the Schmitzm-commits
mailing list