X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FStructureViewerBase.java;h=e73ce07bcee5dddc98d8a078295d55de919061de;hb=42498abb930c08393b09fc7af2564b7f210ac294;hp=34ad659402361ea2c50394a9356a3117003b6e67;hpb=f831ddf7f52d6c4a1918e87d94877b22bd322648;p=jalview.git diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 34ad659..e73ce07 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -23,7 +23,7 @@ package jalview.gui; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.gui.StructureViewer.ViewerType; @@ -110,6 +110,8 @@ public abstract class StructureViewerBase extends GStructureViewer protected boolean allChainsSelected = false; + protected JMenu viewSelectionMenu; + /** * Default constructor */ @@ -744,17 +746,17 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void itemStateChanged(ItemEvent e) { - alignStructs.setEnabled(_alignwith.size() > 0); + alignStructs.setEnabled(!_alignwith.isEmpty()); alignStructs.setToolTipText(MessageManager.formatMessage( "label.align_structures_using_linked_alignment_views", - new String[] { String.valueOf(_alignwith.size()) })); + _alignwith.size())); } }; - JMenu alpanels = new ViewSelectionMenu( + viewSelectionMenu = new ViewSelectionMenu( MessageManager.getString("label.superpose_with"), this, _alignwith, handler); handler.itemStateChanged(null); - viewerActionMenu.add(alpanels); + viewerActionMenu.add(viewSelectionMenu, 0); viewerActionMenu.addMenuListener(new MenuListener() { @Override @@ -781,16 +783,24 @@ public abstract class StructureViewerBase extends GStructureViewer public void setJalviewColourScheme(ColourSchemeI cs) { getBinding().setJalviewColourScheme(cs); } + + /** + * Sends commands to the structure viewer to superimpose structures based on + * currently associated alignments. May optionally return an error message for + * the operation. + */ @Override - protected void alignStructs_actionPerformed(ActionEvent actionEvent) + protected String alignStructs_actionPerformed( + ActionEvent actionEvent) { - alignStructs_withAllAlignPanels(); + return alignStructs_withAllAlignPanels(); } - protected void alignStructs_withAllAlignPanels() + + protected String alignStructs_withAllAlignPanels() { if (getAlignmentPanel() == null) { - return; + return null; } if (_alignwith.size() == 0) @@ -798,10 +808,11 @@ public abstract class StructureViewerBase extends GStructureViewer _alignwith.add(getAlignmentPanel()); } + String reply = null; try { AlignmentI[] als = new Alignment[_alignwith.size()]; - ColumnSelection[] alc = new ColumnSelection[_alignwith.size()]; + HiddenColumns[] alc = new HiddenColumns[_alignwith.size()]; int[] alm = new int[_alignwith.size()]; int a = 0; @@ -809,9 +820,15 @@ public abstract class StructureViewerBase extends GStructureViewer { als[a] = ap.av.getAlignment(); alm[a] = -1; - alc[a++] = ap.av.getColumnSelection(); + alc[a++] = ap.av.getAlignment().getHiddenColumns(); + } + reply = getBinding().superposeStructures(als, alm, alc); + if (reply != null) + { + String text = MessageManager.formatMessage( + "error.superposition_failed", reply); + statusBar.setText(text); } - getBinding().superposeStructures(als, alm, alc); } catch (Exception e) { StringBuffer sp = new StringBuffer(); @@ -822,7 +839,9 @@ public abstract class StructureViewerBase extends GStructureViewer Cache.log.info("Couldn't align structures with the " + sp.toString() + "associated alignment panels.", e); } + return reply; } + @Override public void background_actionPerformed(ActionEvent actionEvent) { @@ -900,7 +919,7 @@ public abstract class StructureViewerBase extends GStructureViewer { // TODO: cope with multiple PDB files in view in = new BufferedReader( - new FileReader(getBinding().getPdbFile()[0])); + new FileReader(getBinding().getStructureFiles()[0])); File outFile = chooser.getSelectedFile(); PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); @@ -952,6 +971,10 @@ public abstract class StructureViewerBase extends GStructureViewer } protected abstract String getViewerName(); + + /** + * Configures the title and menu items of the viewer panel. + */ public void updateTitleAndMenus() { AAStructureBindingModel binding = getBinding(); @@ -963,10 +986,30 @@ public abstract class StructureViewerBase extends GStructureViewer setChainMenuItems(binding.getChainNames()); this.setTitle(binding.getViewerTitle(getViewerName(), true)); - if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1) + + /* + * enable 'Superpose with' if more than one mapped structure + */ + viewSelectionMenu.setEnabled(false); + if (getBinding().getStructureFiles().length > 1 + && getBinding().getSequence().length > 1) { - viewerActionMenu.setVisible(true); + viewSelectionMenu.setEnabled(true); } + + /* + * Show action menu if it has any enabled items + */ + viewerActionMenu.setVisible(false); + for (int i = 0; i < viewerActionMenu.getItemCount(); i++) + { + if (viewerActionMenu.getItem(i).isEnabled()) + { + viewerActionMenu.setVisible(true); + break; + } + } + if (!binding.isLoadingFromArchive()) { seqColour_actionPerformed(null);