X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FStructureViewerBase.java;h=c8854a768edd89a559dfb7f3938a7c5e8d611f56;hb=106a3890f956e2aa7780b2985f4326655912a558;hp=808150fa1cbbdf746644e0a995b808b858ddabbc;hpb=20bb45279db7745e7d0062c1084f97644c60db19;p=jalview.git diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 808150f..c8854a7 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; @@ -83,18 +83,18 @@ public abstract class StructureViewerBase extends GStructureViewer /** * list of sequenceSet ids associated with the view */ - protected List _aps = new ArrayList(); + protected List _aps = new ArrayList<>(); /** * list of alignment panels to use for superposition */ - protected Vector _alignwith = new Vector(); + protected Vector _alignwith = new Vector<>(); /** * list of alignment panels that are used for colouring structures by aligned * sequences */ - protected Vector _colourwith = new Vector(); + protected Vector _colourwith = new Vector<>(); private String viewId = null; @@ -119,6 +119,7 @@ public abstract class StructureViewerBase extends GStructureViewer { super(); } + /** * * @param ap2 @@ -169,7 +170,7 @@ public abstract class StructureViewerBase extends GStructureViewer { if (_alignwith == null) { - _alignwith = new Vector(); + _alignwith = new Vector<>(); } if (_alignwith.size() == 0 && ap != null) { @@ -355,7 +356,8 @@ public abstract class StructureViewerBase extends GStructureViewer } // otherwise, start adding the structure. getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry }, - new SequenceI[][] { seqs }, new String[][] { chains }); + new SequenceI[][] + { seqs }, new String[][] { chains }); addingStructures = true; _started = false; alignAddedStructures = align; @@ -377,7 +379,8 @@ public abstract class StructureViewerBase extends GStructureViewer { int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, MessageManager.formatMessage("label.add_pdbentry_to_view", - new Object[] { pdbId, view.getTitle() }), + new Object[] + { pdbId, view.getTitle() }), MessageManager .getString("label.align_to_existing_structure_view"), JvOptionPane.YES_NO_CANCEL_OPTION); @@ -465,7 +468,9 @@ public abstract class StructureViewerBase extends GStructureViewer if (apanel.getSeqPanel().seqCanvas.fr != null) { apanel.getSeqPanel().seqCanvas.fr.featuresAdded(); - apanel.paintAlignment(true); + // note - we don't do a refresh for structure here because we do it + // explicitly for all panels later on + apanel.paintAlignment(true, false); } /* @@ -488,8 +493,8 @@ public abstract class StructureViewerBase extends GStructureViewer */ viewer.useAlignmentPanelForColourbyseq(apanel); viewer.buildActionMenu(); - apanel.getStructureSelectionManager().sequenceColoursChanged( - apanel); + apanel.getStructureSelectionManager() + .sequenceColoursChanged(apanel); break; } } @@ -520,11 +525,11 @@ public abstract class StructureViewerBase extends GStructureViewer */ int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, MessageManager.formatMessage( - "label.pdb_entry_is_already_displayed", - new Object[] { pdbId }), MessageManager - .formatMessage( - "label.map_sequences_to_visible_window", - new Object[] { pdbId }), + "label.pdb_entry_is_already_displayed", new Object[] + { pdbId }), + MessageManager.formatMessage( + "label.map_sequences_to_visible_window", new Object[] + { pdbId }), JvOptionPane.YES_NO_CANCEL_OPTION); if (option == JvOptionPane.CANCEL_OPTION) { @@ -596,8 +601,8 @@ public abstract class StructureViewerBase extends GStructureViewer public void changeColour_actionPerformed(String colourSchemeName) { AlignmentI al = getAlignmentPanel().av.getAlignment(); - ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme( - colourSchemeName, al, null); + ColourSchemeI cs = ColourSchemes.getInstance() + .getColourScheme(colourSchemeName, al, null); getBinding().setJalviewColourScheme(cs); } @@ -714,11 +719,11 @@ public abstract class StructureViewerBase extends GStructureViewer if (_colourwith == null) { - _colourwith = new Vector(); + _colourwith = new Vector<>(); } if (_alignwith == null) { - _alignwith = new Vector(); + _alignwith = new Vector<>(); } ViewSelectionMenu seqColourBy = new ViewSelectionMenu( @@ -749,14 +754,14 @@ public abstract class StructureViewerBase extends GStructureViewer alignStructs.setEnabled(!_alignwith.isEmpty()); alignStructs.setToolTipText(MessageManager.formatMessage( "label.align_structures_using_linked_alignment_views", - new String[] { String.valueOf(_alignwith.size()) })); + _alignwith.size())); } }; viewSelectionMenu = new ViewSelectionMenu( MessageManager.getString("label.superpose_with"), this, _alignwith, handler); handler.itemStateChanged(null); - viewerActionMenu.add(viewSelectionMenu); + viewerActionMenu.add(viewSelectionMenu, 0); viewerActionMenu.addMenuListener(new MenuListener() { @Override @@ -780,40 +785,55 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void setJalviewColourScheme(ColourSchemeI cs) { + 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) { _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; - + for (AlignmentPanel ap : _alignwith) { 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(); @@ -824,7 +844,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) { @@ -836,6 +858,7 @@ public abstract class StructureViewerBase extends GStructureViewer getBinding().setBackgroundColour(col); } } + @Override public void viewerColour_actionPerformed(ActionEvent actionEvent) { @@ -845,18 +868,21 @@ public abstract class StructureViewerBase extends GStructureViewer getBinding().setColourBySequence(false); } } + @Override public void chainColour_actionPerformed(ActionEvent actionEvent) { chainColour.setSelected(true); getBinding().colourByChain(); } + @Override public void chargeColour_actionPerformed(ActionEvent actionEvent) { chargeColour.setSelected(true); getBinding().colourByCharge(); } + @Override public void seqColour_actionPerformed(ActionEvent actionEvent) { @@ -864,7 +890,7 @@ public abstract class StructureViewerBase extends GStructureViewer binding.setColourBySequence(seqColour.isSelected()); if (_colourwith == null) { - _colourwith = new Vector(); + _colourwith = new Vector<>(); } if (binding.isColourBySequence()) { @@ -883,18 +909,19 @@ public abstract class StructureViewerBase extends GStructureViewer } } } + @Override public void pdbFile_actionPerformed(ActionEvent actionEvent) { JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY")); - + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file")); chooser.setToolTipText(MessageManager.getString("action.save")); - + int value = chooser.showSaveDialog(this); - + if (value == JalviewFileChooser.APPROVE_OPTION) { BufferedReader in = null; @@ -902,9 +929,9 @@ 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)); String data; while ((data = in.readLine()) != null) @@ -933,6 +960,7 @@ public abstract class StructureViewerBase extends GStructureViewer } } } + @Override public void viewMapping_actionPerformed(ActionEvent actionEvent) { @@ -954,6 +982,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,12 +995,32 @@ public abstract class StructureViewerBase extends GStructureViewer return; } 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);