JAL-1476 JAL-1016 avoid NPE messiness if structures fail to align for some reason
[jalview.git] / src / jalview / gui / AppJmol.java
index 80bfcf3..81b88ac 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -14,6 +14,7 @@
  * PURPOSE.  See the GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.gui;
 
@@ -26,15 +27,14 @@ import java.awt.event.*;
 import java.io.*;
 
 import jalview.jbgui.GStructureViewer;
-import jalview.api.AlignmentViewPanel;
 import jalview.api.SequenceStructureBinding;
 import jalview.bin.Cache;
 import jalview.datamodel.*;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
-import jalview.structure.*;
 import jalview.datamodel.PDBEntry;
 import jalview.io.*;
 import jalview.schemes.*;
+import jalview.util.MessageManager;
 import jalview.util.Platform;
 
 public class AppJmol extends GStructureViewer implements Runnable,
@@ -200,8 +200,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
               public void itemStateChanged(ItemEvent e)
               {
                 alignStructs.setEnabled(_alignwith.size() > 0);
-                alignStructs.setToolTipText("Align structures using "
-                        + _alignwith.size() + " linked alignment views");
+                alignStructs.setToolTipText(MessageManager.formatMessage("label.align_structures_using_linked_alignment_views", new String[] {new Integer(_alignwith.size()).toString()}));\r
               }
             });
     handler.itemStateChanged(null);
@@ -253,9 +252,8 @@ public class AppJmol extends GStructureViewer implements Runnable,
     if (alreadyMapped != null)
     {
       int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
-              pdbentry.getId() + " is already displayed."
-                      + "\nDo you want to re-use this viewer ?",
-              "Map Sequences to Visible Window: " + pdbentry.getId(),
+                 MessageManager.formatMessage("label.pdb_entry_is_already_displayed",  new String[]{pdbentry.getId()}),
+              MessageManager.formatMessage("label.map_sequences_to_visible_window", new String[]{pdbentry.getId()}),
               JOptionPane.YES_NO_OPTION);
 
       if (option == JOptionPane.YES_OPTION)
@@ -312,9 +310,8 @@ public class AppJmol extends GStructureViewer implements Runnable,
         AppJmol topJmol = (AppJmol) jm.nextElement();
         // TODO: highlight topJmol in view somehow
         int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
-                "Do you want to add " + pdbentry.getId()
-                        + " to the view called\n'" + topJmol.getTitle()
-                        + "'\n", "Align to existing structure view",
+                       MessageManager.formatMessage("label.add_pdbentry_to_view", new String[]{pdbentry.getId(),topJmol.getTitle()}),
+                       MessageManager.getString("label.align_to_existing_structure_view"),
                 JOptionPane.YES_NO_OPTION);
         if (option == JOptionPane.YES_OPTION)
         {
@@ -620,7 +617,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       return;
     }
-    JMenuItem menuItem = new JMenuItem("All");
+    JMenuItem menuItem = new JMenuItem(MessageManager.getString("label.all"));\r
     menuItem.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent evt)
@@ -783,10 +780,8 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
 
       JOptionPane.showInternalMessageDialog(Desktop.desktop,
-              "The following pdb entries could not be retrieved from the PDB:\n"
-                      + errormsgs.toString()
-                      + "\nPlease try downloading them manually.",
-              "Couldn't load file", JOptionPane.ERROR_MESSAGE);
+                 MessageManager.formatMessage("label.pdb_entries_couldnt_be_retrieved", new String[]{errormsgs.toString()}),
+              MessageManager.getString("label.couldnt_load_file"), JOptionPane.ERROR_MESSAGE);
 
     }
     long lastnotify = jmb.getLoadNotifiesHandled();
@@ -834,7 +829,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
       // need to wait around until script has finished
       while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
-              : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
+              : (jmb.isFinishedInit() && jmb.getPdbFile()!=null && jmb.getPdbFile().length != jmb.pdbentry.length))
       {
         try
         {
@@ -876,7 +871,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle("Save PDB File");
-    chooser.setToolTipText("Save");
+    chooser.setToolTipText(MessageManager.getString("action.save"));\r
 
     int value = chooser.showSaveDialog(this);
 
@@ -924,7 +919,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
       cap.dispose();
       return;
     }
-    jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
+    jalview.gui.Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"),\r
             550, 600);
   }
 
@@ -1147,7 +1142,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
         g.fillRect(0, 0, currentSize.width, currentSize.height);
         g.setColor(Color.white);
         g.setFont(new Font("Verdana", Font.BOLD, 14));
-        g.drawString("Error loading file...", 20, currentSize.height / 2);
+        g.drawString(MessageManager.getString("label.error_loading_file") + "...", 20, currentSize.height / 2);
         StringBuffer sb = new StringBuffer();
         int lines = 0;
         for (int e = 0; e < jmb.pdbentry.length; e++)
@@ -1172,7 +1167,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
         g.fillRect(0, 0, currentSize.width, currentSize.height);
         g.setColor(Color.white);
         g.setFont(new Font("Verdana", Font.BOLD, 14));
-        g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
+        g.drawString(MessageManager.getString("label.retrieving_pdb_data"), 20, currentSize.height / 2);
       }
       else
       {