reformat
[fanfix.git] / src / be / nikiroo / fanfix_swing / Actions.java
index 5df9b2eb84f64894d15bc8c98aba84eed9096a63..10c79dd1d9cd82ff37ceffb8911f6105fc39cb18 100644 (file)
@@ -28,8 +28,8 @@ import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
 import be.nikiroo.utils.Progress;
 
 public class Actions {
-       static public void openExternal(final BasicLibrary lib, MetaData meta, final Container parent,
-                       final Runnable onDone) {
+       static public void openExternal(final BasicLibrary lib, MetaData meta,
+                       final Container parent, final Runnable onDone) {
                Container parentWindow = parent;
                while (!(parentWindow instanceof Window) && parentWindow != null) {
                        parentWindow = parentWindow.getParent();
@@ -82,7 +82,8 @@ public class Actions {
                                        openExternal(target, isImageDocument);
                                } catch (Exception e) {
                                        // TODO: i18n
-                                       UiHelper.error(parent, e.getLocalizedMessage(), "Cannot open the story", e);
+                                       UiHelper.error(parent, e.getLocalizedMessage(),
+                                                       "Cannot open the story", e);
                                }
 
                                synchronized (waitLock) {
@@ -102,21 +103,26 @@ public class Actions {
        }
 
        /**
-        * Open the {@link Story} with an external reader (the program will be passed
-        * the given target file).
+        * Open the {@link Story} with an external reader (the program will be
+        * passed the given target file).
         * 
-        * @param target          the target {@link File}
-        * @param isImageDocument TRUE for image documents, FALSE for not-images
-        *                        documents
+        * @param target
+        *            the target {@link File}
+        * @param isImageDocument
+        *            TRUE for image documents, FALSE for not-images documents
         * 
-        * @throws IOException in case of I/O error
+        * @throws IOException
+        *             in case of I/O error
         */
-       static public void openExternal(File target, boolean isImageDocument) throws IOException {
+       static public void openExternal(File target, boolean isImageDocument)
+                       throws IOException {
                String program = null;
                if (isImageDocument) {
-                       program = Instance.getInstance().getUiConfig().getString(UiConfig.IMAGES_DOCUMENT_READER);
+                       program = Instance.getInstance().getUiConfig()
+                                       .getString(UiConfig.IMAGES_DOCUMENT_READER);
                } else {
-                       program = Instance.getInstance().getUiConfig().getString(UiConfig.NON_IMAGES_DOCUMENT_READER);
+                       program = Instance.getInstance().getUiConfig()
+                                       .getString(UiConfig.NON_IMAGES_DOCUMENT_READER);
                }
 
                if (program != null && program.trim().isEmpty()) {
@@ -127,35 +133,46 @@ public class Actions {
        }
 
        /**
-        * Start a file and open it with the given program if given or the first default
-        * system starter we can find.
+        * Start a file and open it with the given program if given or the first
+        * default system starter we can find.
         * 
-        * @param target  the target to open
-        * @param program the program to use or NULL for the default system starter
-        * @param sync    execute the process synchronously (wait until it is terminated
-        *                before returning)
+        * @param target
+        *            the target to open
+        * @param program
+        *            the program to use or NULL for the default system starter
+        * @param sync
+        *            execute the process synchronously (wait until it is terminated
+        *            before returning)
         * 
-        * @throws IOException in case of I/O error
+        * @throws IOException
+        *             in case of I/O error
         */
-       static protected void start(File target, String program, boolean sync) throws IOException {
+       static protected void start(File target, String program, boolean sync)
+                       throws IOException {
                Process proc = null;
                if (program == null) {
                        boolean ok = false;
-                       for (String starter : new String[] { "xdg-open", "open", "see", "start", "run" }) {
+                       for (String starter : new String[] { "xdg-open", "open", "see",
+                                       "start", "run" }) {
                                try {
-                                       Instance.getInstance().getTraceHandler().trace("starting external program");
-                                       proc = Runtime.getRuntime().exec(new String[] { starter, target.getAbsolutePath() });
+                                       Instance.getInstance().getTraceHandler()
+                                                       .trace("starting external program");
+                                       proc = Runtime.getRuntime().exec(
+                                                       new String[] { starter, target.getAbsolutePath() });
                                        ok = true;
                                        break;
                                } catch (IOException e) {
                                }
                        }
                        if (!ok) {
-                               throw new IOException("Cannot find a program to start the file");
+                               throw new IOException(
+                                               "Cannot find a program to start the file");
                        }
                } else {
-                       Instance.getInstance().getTraceHandler().trace("starting external program");
-                       proc = Runtime.getRuntime().exec(new String[] { program, target.getAbsolutePath() });
+                       Instance.getInstance().getTraceHandler()
+                                       .trace("starting external program");
+                       proc = Runtime.getRuntime()
+                                       .exec(new String[] { program, target.getAbsolutePath() });
                }
 
                if (proc != null && sync) {
@@ -171,17 +188,20 @@ public class Actions {
         * <p>
         * Should be called inside the UI thread.
         * 
-        * @param askUrl TRUE for an {@link URL}, false for a {@link File}
+        * @param askUrl
+        *            TRUE for an {@link URL}, false for a {@link File}
         */
-       static public void imprt(final Container parent, boolean askUrl, final Runnable onSuccess) {
+       static public void imprt(final Container parent, boolean askUrl,
+                       final Runnable onSuccess) {
                JFileChooser fc = new JFileChooser();
 
                Object url;
                if (askUrl) {
                        String clipboard = "";
                        try {
-                               clipboard = ("" + Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor))
-                                               .trim();
+                               clipboard = ("" + Toolkit.getDefaultToolkit()
+                                               .getSystemClipboard().getData(DataFlavor.stringFlavor))
+                                                               .trim();
                        } catch (Exception e) {
                                // No data will be handled
                        }
@@ -192,8 +212,10 @@ public class Actions {
                        }
 
                        url = JOptionPane.showInputDialog(parent,
-                                       Instance.getInstance().getTransGui().getString(StringIdGui.SUBTITLE_IMPORT_URL),
-                                       Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_IMPORT_URL),
+                                       Instance.getInstance().getTransGui()
+                                                       .getString(StringIdGui.SUBTITLE_IMPORT_URL),
+                                       Instance.getInstance().getTransGui()
+                                                       .getString(StringIdGui.TITLE_IMPORT_URL),
                                        JOptionPane.QUESTION_MESSAGE, null, null, clipboard);
                } else if (fc.showOpenDialog(parent) != JFileChooser.CANCEL_OPTION) {
                        url = fc.getSelectedFile().getAbsolutePath();
@@ -211,12 +233,15 @@ public class Actions {
         * <p>
         * Should be called inside the UI thread.
         * 
-        * @param url             the {@link Story} to import by {@link URL}
-        * @param onSuccess       Action to execute on success
-        * @param onSuccessPgName the name to use for the onSuccess progress bar
+        * @param url
+        *            the {@link Story} to import by {@link URL}
+        * @param onSuccess
+        *            Action to execute on success
+        * @param onSuccessPgName
+        *            the name to use for the onSuccess progress bar
         */
-       static public void imprt(final Container parent, final String url, final Runnable onSuccess,
-                       String onSuccessPgName) {
+       static public void imprt(final Container parent, final String url,
+                       final Runnable onSuccess, String onSuccessPgName) {
                final Progress pg = new Progress();
                final Progress pgImprt = new Progress();
                final Progress pgOnSuccess = new Progress(onSuccessPgName);
@@ -229,7 +254,8 @@ public class Actions {
                                Exception ex = null;
                                MetaData meta = null;
                                try {
-                                       meta = Instance.getInstance().getLibrary().imprt(BasicReader.getUrl(url), pgImprt);
+                                       meta = Instance.getInstance().getLibrary()
+                                                       .imprt(BasicReader.getUrl(url), pgImprt);
                                } catch (IOException e) {
                                        e.printStackTrace();
                                        ex = e;
@@ -243,14 +269,20 @@ public class Actions {
                                if (!ok) {
                                        if (e instanceof UnknownHostException) {
                                                UiHelper.error(parent,
-                                                               Instance.getInstance().getTransGui().getString(StringIdGui.ERROR_URL_NOT_SUPPORTED,
+                                                               Instance.getInstance().getTransGui().getString(
+                                                                               StringIdGui.ERROR_URL_NOT_SUPPORTED,
                                                                                url),
-                                                               Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_ERROR), null);
+                                                               Instance.getInstance().getTransGui().getString(
+                                                                               StringIdGui.TITLE_ERROR),
+                                                               null);
                                        } else {
                                                UiHelper.error(parent,
-                                                               Instance.getInstance().getTransGui().getString(StringIdGui.ERROR_URL_IMPORT_FAILED, url,
-                                                                               e.getMessage()),
-                                                               Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_ERROR), e);
+                                                               Instance.getInstance().getTransGui().getString(
+                                                                               StringIdGui.ERROR_URL_IMPORT_FAILED,
+                                                                               url, e.getMessage()),
+                                                               Instance.getInstance().getTransGui()
+                                                                               .getString(StringIdGui.TITLE_ERROR),
+                                                               e);
                                        }
                                } else {
                                        if (onSuccess != null) {
@@ -258,7 +290,7 @@ public class Actions {
                                        }
                                }
                                pgOnSuccess.done();
-                               
+
                                return null;
                        }
                }.execute();