JAL-1759 unused JmolPopup removed, code tidy for generics
[jalview.git] / src / jalview / gui / AppJmol.java
index ff9b0a7..a16ea68 100644 (file)
@@ -57,8 +57,8 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.Enumeration;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -313,36 +313,30 @@ public class AppJmol extends StructureViewerBase
         return;
       }
     }
-    // /////////////////////////////////
-    // Check if there are other Jmol views involving this alignment
-    // and prompt user about adding this molecule to one of them
-    Vector existingViews = getJmolsFor(ap);
-    if (existingViews.size() > 0)
+
+    /*
+     * Check if there are other Jmol views involving this alignment and prompt
+     * user about adding this molecule to one of them
+     */
+    for (AppJmol topJmol : getJmolsFor(ap))
     {
-      Enumeration jm = existingViews.elements();
-      while (jm.hasMoreElements())
+      // TODO: highlight topJmol in view somehow
+      int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+              MessageManager.formatMessage("label.add_pdbentry_to_view",
+                      new String[]
+                      { pdbentry.getId(), topJmol.getTitle() }),
+              MessageManager
+                      .getString("label.align_to_existing_structure_view"),
+              JOptionPane.YES_NO_CANCEL_OPTION);
+      if (option == JOptionPane.CANCEL_OPTION)
       {
-        AppJmol topJmol = (AppJmol) jm.nextElement();
-        // TODO: highlight topJmol in view somehow
-        int option = JOptionPane
-                .showInternalConfirmDialog(
-                        Desktop.desktop,
-                        MessageManager.formatMessage(
-                                "label.add_pdbentry_to_view", new String[]
-                                { pdbentry.getId(), topJmol.getTitle() }),
-                        MessageManager
-                                .getString("label.align_to_existing_structure_view"),
-                        JOptionPane.YES_NO_CANCEL_OPTION);
-        if (option == JOptionPane.CANCEL_OPTION)
-        {
-          return;
-        }
-        if (option == JOptionPane.YES_OPTION)
-        {
-          topJmol.useAlignmentPanelForSuperposition(ap);
-          topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
-          return;
-        }
+        return;
+      }
+      if (option == JOptionPane.YES_OPTION)
+      {
+        topJmol.useAlignmentPanelForSuperposition(ap);
+        topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
+        return;
       }
     }
     // /////////////////////////////////
@@ -458,18 +452,18 @@ public class AppJmol extends StructureViewerBase
     return;
   }
 
-  private Vector getJmolsFor(AlignmentPanel apanel)
+  private Vector<AppJmol> getJmolsFor(AlignmentPanel apanel)
   {
-    Vector result = new Vector();
+    Vector<AppJmol> result = new Vector<AppJmol>();
     JInternalFrame[] frames = Desktop.instance.getAllFrames();
 
     for (JInternalFrame frame : frames)
     {
       if (frame instanceof AppJmol)
       {
-        if (((StructureViewerBase) frame).isLinkedWith(apanel))
+        if (((AppJmol) frame).isLinkedWith(apanel))
         {
-          result.addElement(frame);
+          result.addElement((AppJmol) frame);
         }
       }
     }
@@ -493,10 +487,10 @@ public class AppJmol extends StructureViewerBase
       scriptWindow = new JPanel(bl);
       scriptWindow.setVisible(false);
     }
-    ;
+
     jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
             null);
-    jmb.newJmolPopup("Jmol");
+    // jmb.newJmolPopup("Jmol");
     if (command == null)
     {
       command = "";
@@ -505,7 +499,7 @@ public class AppJmol extends StructureViewerBase
     jmb.setFinishedInit(true);
   }
 
-  void setChainMenuItems(Vector chains)
+  void setChainMenuItems(Vector<String> chains)
   {
     chainMenu.removeAll();
     if (chains == null)
@@ -533,9 +527,9 @@ public class AppJmol extends StructureViewerBase
 
     chainMenu.add(menuItem);
 
-    for (int c = 0; c < chains.size(); c++)
+    for (String chain : chains)
     {
-      menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
+      menuItem = new JCheckBoxMenuItem(chain, true);
       menuItem.addItemListener(new ItemListener()
       {
         public void itemStateChanged(ItemEvent evt)
@@ -557,9 +551,7 @@ public class AppJmol extends StructureViewerBase
 
   void centerViewer()
   {
-    Vector toshow = new Vector();
-    String lbl;
-    int mlength, p, mnum;
+    Vector<String> toshow = new Vector<String>();
     for (int i = 0; i < chainMenu.getItemCount(); i++)
     {
       if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
@@ -732,7 +724,7 @@ public class AppJmol extends StructureViewerBase
 
       // need to wait around until script has finished
       while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
-              : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
+              : (!jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
                       .getPdbFile().length != jmb.getPdbCount()))
       {
         try
@@ -743,6 +735,7 @@ public class AppJmol extends StructureViewerBase
         {
         }
       }
+
       // refresh the sequence colours for the new structure(s)
       for (AlignmentPanel ap : _colourwith)
       {
@@ -782,10 +775,11 @@ public class AppJmol extends StructureViewerBase
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
+      BufferedReader in = null;
       try
       {
         // TODO: cope with multiple PDB files in view
-        BufferedReader in = new BufferedReader(new FileReader(
+        in = new BufferedReader(new FileReader(
                 jmb.getPdbFile()[0]));
         File outFile = chooser.getSelectedFile();
 
@@ -802,6 +796,18 @@ public class AppJmol extends StructureViewerBase
       } catch (Exception ex)
       {
         ex.printStackTrace();
+      } finally
+      {
+        if (in != null)
+        {
+          try
+          {
+            in.close();
+          } catch (IOException e)
+          {
+            // ignore
+          }
+        }
       }
     }
   }
@@ -904,7 +910,7 @@ public class AppJmol extends StructureViewerBase
       // Set the colour using the current view for the associated alignframe
       for (AlignmentPanel ap : _colourwith)
       {
-        jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+        jmb.colourBySequence(ap);
       }
     }
   }