From c5a7bc3f03aef928f1b06e5e9ab53d06970aeb12 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 30 Jun 2015 17:37:56 +0100 Subject: [PATCH] JAL-1759 unused JmolPopup removed, code tidy for generics --- src/jalview/appletgui/AppletJmol.java | 29 ++++---- src/jalview/appletgui/AppletJmolBinding.java | 8 +-- src/jalview/ext/jmol/JalviewJmolBinding.java | 64 ++++++++---------- src/jalview/gui/AppJmol.java | 94 ++++++++++++++------------ src/jalview/gui/AppJmolBinding.java | 9 ++- 5 files changed, 100 insertions(+), 104 deletions(-) diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index b48070c..e889467 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -60,6 +60,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Hashtable; +import java.util.List; import java.util.Vector; public class AppletJmol extends EmbmenuFrame implements @@ -129,7 +130,8 @@ public class AppletJmol extends EmbmenuFrame implements AlignmentPanel ap; - ArrayList _aps = new ArrayList(); + List _aps = new ArrayList(); // remove? never + // added to String fileLoadingError; @@ -279,7 +281,7 @@ public class AppletJmol extends EmbmenuFrame implements dispose(); return; } - jmb.newJmolPopup(true, "Jmol", true); + // jmb.newJmolPopup(true, "Jmol", true); this.addWindowListener(new WindowAdapter() { @@ -369,7 +371,7 @@ public class AppletJmol extends EmbmenuFrame implements jmb.loadInline(string); } - void setChainMenuItems(Vector chains) + void setChainMenuItems(Vector chains) { chainMenu.removeAll(); @@ -379,10 +381,9 @@ public class AppletJmol extends EmbmenuFrame implements chainMenu.add(menuItem); CheckboxMenuItem menuItemCB; - for (int c = 0; c < chains.size(); c++) + for (String ch : chains) { - menuItemCB = new CheckboxMenuItem(chains.elementAt(c).toString(), - true); + menuItemCB = new CheckboxMenuItem(ch, true); menuItemCB.addItemListener(this); chainMenu.add(menuItemCB); } @@ -392,9 +393,7 @@ public class AppletJmol extends EmbmenuFrame implements void centerViewer() { - Vector toshow = new Vector(); - String lbl; - int mlength, p, mnum; + Vector toshow = new Vector(); for (int i = 0; i < chainMenu.getItemCount(); i++) { if (chainMenu.getItem(i) instanceof CheckboxMenuItem) @@ -546,7 +545,7 @@ public class AppletJmol extends EmbmenuFrame implements else if (evt.getSource() == seqColour) { setEnabled(seqColour); - jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap); + jmb.colourBySequence(ap); } else if (!allChainsSelected) { @@ -575,8 +574,8 @@ public class AppletJmol extends EmbmenuFrame implements public void updateColours(Object source) { - AlignmentPanel ap = (AlignmentPanel) source; - jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap); + AlignmentPanel panel = (AlignmentPanel) source; + jmb.colourBySequence(panel); } public void updateTitleAndMenus() @@ -587,7 +586,7 @@ public class AppletJmol extends EmbmenuFrame implements return; } setChainMenuItems(jmb.chainNames); - jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap); + jmb.colourBySequence(ap); setTitle(jmb.getViewerTitle()); } @@ -695,9 +694,9 @@ public class AppletJmol extends EmbmenuFrame implements { for (int i = 0; i < _aps.size(); i++) { - if (((AlignmentPanel) _aps.get(i)).av.getAlignment() == alignment) + if (_aps.get(i).av.getAlignment() == alignment) { - return ((AlignmentPanel) _aps.get(i)); + return (_aps.get(i)); } } return ap; diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 7844f57..7035058 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -34,7 +34,6 @@ import javajs.awt.Dimension; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.console.AppletConsole; import org.jmol.java.BS; -import org.jmol.popup.JmolAwtPopup; class AppletJmolBinding extends JalviewJmolBinding { @@ -117,7 +116,7 @@ class AppletJmolBinding extends JalviewJmolBinding public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; - colourBySequence(ap.av.isShowSequenceFeatures(), ap); + colourBySequence(ap); } public void showUrl(String url) @@ -134,9 +133,8 @@ class AppletJmolBinding extends JalviewJmolBinding public void newJmolPopup(boolean translateLocale, String menuName, boolean asPopup) { - jmolpopup = new JmolAwtPopup(); // is this used? - jmolpopup.jpiInitialize((viewer), menuName); - + // jmolpopup = new JmolAwtPopup(); // is this used? + // jmolpopup.jpiInitialize((viewer), menuName); } @Override diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index fc86e1c..ed0b950 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -55,7 +55,6 @@ import org.jmol.api.JmolSelectionListener; import org.jmol.api.JmolStatusListener; import org.jmol.api.JmolViewer; import org.jmol.c.CBK; -import org.jmol.popup.JmolGenericPopup; import org.jmol.script.T; import org.jmol.viewer.JC; import org.jmol.viewer.Viewer; @@ -77,13 +76,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ private boolean associateNewStructs = false; - Vector atomsPicked = new Vector(); + Vector atomsPicked = new Vector(); - public Vector chainNames; + public Vector chainNames; - Hashtable chainFile; - - StringBuffer eval = new StringBuffer(); + Hashtable chainFile; public String fileLoadingError; @@ -93,7 +90,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ int frameNo = 0; - protected JmolGenericPopup jmolpopup; + // protected JmolGenericPopup jmolpopup; // not used - remove? String lastCommand; @@ -152,15 +149,13 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * @param chainList * list of chains to make visible */ - public void centerViewer(Vector chainList) + public void centerViewer(Vector chainList) { - StringBuffer cmd = new StringBuffer(); - String lbl; + StringBuilder cmd = new StringBuilder(128); int mlength, p; - for (int i = 0, iSize = chainList.size(); i < iSize; i++) + for (String lbl : chainList) { mlength = 0; - lbl = (String) chainList.elementAt(i); do { p = mlength; @@ -168,7 +163,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } while (p < mlength && mlength < (lbl.length() - 2)); // TODO: lookup each pdb id and recover proper model number for it. cmd.append(":" + lbl.substring(mlength + 1) + " /" - + (1 + getModelNum((String) chainFile.get(lbl))) + " or "); + + (1 + getModelNum(chainFile.get(lbl))) + " or "); } if (cmd.length() > 0) { @@ -483,6 +478,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolHistory(false); if (lastCommand == null || !lastCommand.equals(command)) { + System.out.println(command); viewer.evalStringQuiet(command + "\n"); } jmolHistory(true); @@ -494,9 +490,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * using the getFeatureRenderer() and getSequenceRenderer() renderers but only * if colourBySequence is enabled. */ - public void colourBySequence(boolean showFeatures, - jalview.api.AlignmentViewPanel alignmentv) + public void colourBySequence(AlignmentViewPanel alignmentv) { + boolean showFeatures = alignmentv.getAlignViewport() + .isShowSequenceFeatures(); if (!colourBySequence || !isLoadingFinished()) { return; @@ -729,7 +726,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void handlePopupMenu(int x, int y) { // jmolpopup.show(x, y); - jmolpopup.jpiShow(x, y); + // jmolpopup.jpiShow(x, y); } /** @@ -759,12 +756,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // look up file model number for this pdbfile int mdlNum = 0; - String fn; // may need to adjust for URLencoding here - we don't worry about that yet. while (mdlNum < modelFileNames.length && !pdbfile.equals(modelFileNames[mdlNum])) { - // System.out.println("nomatch:"+pdbfile+"\nmodelfn:"+fn); mdlNum++; } if (mdlNum == modelFileNames.length) @@ -780,31 +775,31 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel viewer.evalStringQuiet(resetLastRes.toString()); } - eval.setLength(0); - eval.append("select " + pdbResNum); // +modelNum + StringBuilder cmd = new StringBuilder(64); + cmd.append("select " + pdbResNum); // +modelNum resetLastRes.setLength(0); resetLastRes.append("select " + pdbResNum); // +modelNum - eval.append(":"); + cmd.append(":"); resetLastRes.append(":"); if (!chain.equals(" ")) { - eval.append(chain); + cmd.append(chain); resetLastRes.append(chain); } { - eval.append(" /" + (mdlNum + 1)); + cmd.append(" /" + (mdlNum + 1)); resetLastRes.append("/" + (mdlNum + 1)); } - eval.append(";wireframe 100;" + eval.toString() + " and not hetero;"); + cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;"); resetLastRes.append(";wireframe 0;" + resetLastRes.toString() + " and not hetero; spacefill 0;"); - eval.append("spacefill 200;select none"); + cmd.append("spacefill 200;select none"); - viewer.evalStringQuiet(eval.toString()); + viewer.evalStringQuiet(cmd.toString()); jmolHistory(true); } @@ -1081,8 +1076,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel fileLoadingError = null; String[] oldmodels = modelFileNames; modelFileNames = null; - chainNames = new Vector(); - chainFile = new Hashtable(); + chainNames = new Vector(); + chainFile = new Hashtable(); boolean notifyLoaded = false; String[] modelfilenames = getPdbFile(); // first check if we've lost any structures @@ -1126,7 +1121,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel String fileName = modelfilenames[modelnum]; boolean foundEntry = false; MCview.PDBfile pdb = null; - String pdbfile = null, pdbfhash = null; + String pdbfile = null; // model was probably loaded inline - so check the pdb file hashcode if (loadedInline) { @@ -1135,7 +1130,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // 'best guess' pdbfile = viewer.getData("" + (1 + _modelFileNameMap[modelnum]) + ".0", "PDB"); - pdbfhash = "" + pdbfile.hashCode(); } // search pdbentries and sequences to find correct pdbentry for this // model @@ -1216,11 +1210,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } // FILE LOADED OK // so finally, update the jmol bits and pieces - if (jmolpopup != null) - { - // potential for deadlock here: - // jmolpopup.updateComputedMenus(); - } + // if (jmolpopup != null) + // { + // // potential for deadlock here: + // // jmolpopup.updateComputedMenus(); + // } if (!isLoadingFromArchive()) { viewer.evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off"); diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index ff9b0a7..a16ea68 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -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 getJmolsFor(AlignmentPanel apanel) { - Vector result = new Vector(); + Vector result = new Vector(); 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 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 toshow = new Vector(); 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); } } } diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 1283019..5c4346e 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -32,7 +32,6 @@ import java.util.Map; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.java.BS; -import org.jmol.popup.JmolAwtPopup; import org.openscience.jmol.app.jmolpanel.console.AppConsole; public class AppJmolBinding extends JalviewJmolBinding @@ -126,7 +125,7 @@ public class AppJmolBinding extends JalviewJmolBinding public void updateColours(Object source) { - AlignmentPanel ap = (AlignmentPanel) source, topap; + AlignmentPanel ap = (AlignmentPanel) source; // ignore events from panels not used to colour this view if (!appJmolWindow.isUsedforcolourby(ap)) { @@ -134,7 +133,7 @@ public class AppJmolBinding extends JalviewJmolBinding } if (!isLoadingFromArchive()) { - colourBySequence(ap.av.isShowSequenceFeatures(), ap); + colourBySequence(ap); } } @@ -154,8 +153,8 @@ public class AppJmolBinding extends JalviewJmolBinding public void newJmolPopup(String menuName) { - jmolpopup = new JmolAwtPopup(); - jmolpopup.jpiInitialize((viewer), menuName); + // jmolpopup = new JmolAwtPopup(); + // jmolpopup.jpiInitialize((viewer), menuName); } @Override -- 1.7.10.2