caching of DnD files dropped
[jalview.git] / src / jalview / gui / Desktop.java
index 89499c1..cd8330a 100644 (file)
@@ -346,10 +346,11 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   public Desktop()
   {
-         super();
+    super();
     /**
-     * A note to implementors. It is ESSENTIAL that any activities that might block
-     * are spawned off as threads rather than waited for during this constructor.
+     * A note to implementors. It is ESSENTIAL that any activities that might
+     * block are spawned off as threads rather than waited for during this
+     * constructor.
      */
     instance = this;
     if (!Platform.isJS())
@@ -365,8 +366,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE",
             false);
     desktop = new MyDesktopPane(selmemusage);
-    
-    
+
     showMemusage.setSelected(selmemusage);
     desktop.setBackground(Color.white);
     getContentPane().setLayout(new BorderLayout());
@@ -374,16 +374,16 @@ public class Desktop extends jalview.jbgui.GDesktop
     // JScrollPane sp = new JScrollPane();
     // sp.getViewport().setView(desktop);
     // getContentPane().add(sp, BorderLayout.CENTER);
-    
-    // BH 2018 - just an experiment to try unclipped JInternalFrames. 
-       if (Platform.isJS()) 
-       {
-         getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
-       }
-    
+
+    // BH 2018 - just an experiment to try unclipped JInternalFrames.
+    if (Platform.isJS())
+    {
+      getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
+    }
+
     getContentPane().add(desktop, BorderLayout.CENTER);
     desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
-    
+
     // This line prevents Windows Look&Feel resizing all new windows to maximum
     // if previous window was maximised
     desktop.setDesktopManager(new MyDesktopManager(
@@ -405,11 +405,15 @@ public class Desktop extends jalview.jbgui.GDesktop
       int yPos = Math.max(5, (screenSize.height - 650) / 2);
       setBounds(xPos, yPos, 900, 650);
     }
-    
-    boolean doFullLoad = /** @j2sNative ! */true;
-    
-    if (doFullLoad) {
-      
+
+    if (!Platform.isJS())
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
+    {
+
       jconsole = new Console(this, showjconsole);
       // add essential build information
       jconsole.setHeader("Jalview Version: "
@@ -444,7 +448,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       });
 
-      // Thread off a new instance of the file chooser - this reduces the time it
+      // Thread off a new instance of the file chooser - this reduces the time
+      // it
       // takes to open it later on.
       new Thread(new Runnable()
       {
@@ -473,7 +478,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
               });
 
-    } 
+    }
 
     this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
 
@@ -884,8 +889,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     frame.setResizable(resizable);
     frame.setMaximizable(resizable);
     frame.setIconifiable(resizable);
-    frame.setOpaque(/** @j2sNative true || */
-            false);
+    frame.setOpaque(Platform.isJS());
 
     if (frame.getX() < 1 && frame.getY() < 1)
     {
@@ -1092,7 +1096,10 @@ public class Desktop extends jalview.jbgui.GDesktop
           {
             format = new IdentifyFile().identify(file, protocol);
           }
-
+          if (file instanceof File)
+          {
+            Platform.cacheFileData((File) file);
+          }
           new FileLoader().LoadFile(null, file, protocol, format);
 
         }
@@ -1172,7 +1179,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     JPanel panel = new JPanel(new GridLayout(2, 1));
     panel.add(label);
-    
+
     /*
      * the URL to fetch is
      * Java: an editable combobox with history
@@ -1185,6 +1192,11 @@ public class Desktop extends jalview.jbgui.GDesktop
       history = new JTextField(urlBase, 35);
     }
     else
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
     {
       JComboBox<String> asCombo = new JComboBox<>();
       asCombo.setPreferredSize(new Dimension(400, 20));
@@ -1204,13 +1216,16 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     Object[] options = new Object[] { MessageManager.getString("action.ok"),
         MessageManager.getString("action.cancel") };
-    Runnable action = new Runnable() {
+    Runnable action = new Runnable()
+    {
       @Override
       public void run()
       {
-        String url = Platform.isJS() ? ((JTextField) history).getText()
+        @SuppressWarnings("unchecked")
+        String url = (history instanceof JTextField
+                ? ((JTextField) history).getText()
                 : ((JComboBox<String>) history).getSelectedItem()
-                        .toString();
+                        .toString());
 
         if (url.toLowerCase().endsWith(".jar"))
         {
@@ -1239,7 +1254,8 @@ public class Desktop extends jalview.jbgui.GDesktop
 
           if (format == null)
           {
-            String msg = MessageManager.formatMessage("label.couldnt_locate", url);
+            String msg = MessageManager
+                    .formatMessage("label.couldnt_locate", url);
             JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
                     MessageManager.getString("label.url_not_found"),
                     JvOptionPane.WARNING_MESSAGE);
@@ -1257,7 +1273,8 @@ public class Desktop extends jalview.jbgui.GDesktop
             new FileLoader().LoadFile(url, DataSourceType.URL, format);
           }
         }
-      }};
+      }
+    };
     String dialogOption = MessageManager
             .getString("label.input_alignment_from_url");
     JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
@@ -1438,6 +1455,11 @@ public class Desktop extends jalview.jbgui.GDesktop
         BrowserLauncher.openURL("http://www.jalview.org/help.html");
       }
       else
+      /**
+       * Java only
+       * 
+       * @j2sIgnore
+       */
       {
         Help.showHelpWindow();
       }
@@ -1705,12 +1727,16 @@ public class Desktop extends jalview.jbgui.GDesktop
           // TODO prevent user from messing with the Desktop whilst we're saving
           try
           {
-            BackupFiles backupfiles = new BackupFiles(chosenFile);
+               boolean doBackup = BackupFiles.getEnabled();
+            BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null;
 
-            new Jalview2XML().saveState(backupfiles.getTempFile());
+            new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile);
 
-            backupfiles.setWriteSuccess(true);
-            backupfiles.rollBackupsAndRenameTempFile();
+            if (doBackup)
+            {
+              backupfiles.setWriteSuccess(true);
+              backupfiles.rollBackupsAndRenameTempFile();
+            }
           } catch (OutOfMemoryError oom)
           {
             new OOMWarning("Whilst saving current state to "