From a65993fd311b1a53617c5df3c84abfb78740a900 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 22 Apr 2011 11:41:41 +0000 Subject: [PATCH] JAL-823 and JAL-824 - seqColour no longer the default colouring state unless PDB file opened from alignment window --- src/jalview/gui/AppJmol.java | 134 ++++++++++++++++++++++++------- src/jalview/gui/AppJmolBinding.java | 2 +- src/jalview/jbgui/GStructureViewer.java | 23 +++++- 3 files changed, 129 insertions(+), 30 deletions(-) diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index fd7e297..9d68c1b 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -79,7 +79,7 @@ public class AppJmol extends GStructureViewer implements Runnable, this(new String[] { file }, new String[] { id }, new SequenceI[][] - { seq }, ap, true,true, loadStatus, bounds, viewid); + { seq }, ap, true, true, loadStatus, bounds, viewid); } ViewSelectionMenu seqColourBy; @@ -90,15 +90,19 @@ public class AppJmol extends GStructureViewer implements Runnable, * @param ids * @param seqs * @param ap - * @param usetoColour - add the alignment panel to the list used for colouring these structures - * @param useToAlign - add the alignment panel to the list used for aligning these structures + * @param usetoColour + * - add the alignment panel to the list used for colouring these + * structures + * @param useToAlign + * - add the alignment panel to the list used for aligning these + * structures * @param loadStatus * @param bounds * @param viewid */ public AppJmol(String[] files, String[] ids, SequenceI[][] seqs, - AlignmentPanel ap, boolean usetoColour,boolean useToAlign, String loadStatus, Rectangle bounds, - String viewid) + AlignmentPanel ap, boolean usetoColour, boolean useToAlign, + String loadStatus, Rectangle bounds, String viewid) { PDBEntry[] pdbentrys = new PDBEntry[files.length]; for (int i = 0; i < pdbentrys.length; i++) @@ -121,10 +125,14 @@ public class AppJmol extends GStructureViewer implements Runnable, if (usetoColour) { useAlignmentPanelForColourbyseq(ap); + jmb.setColourBySequence(true); + seqColour.setSelected(true); + } else { + jmb.setColourBySequence(false); + seqColour.setSelected(false); + jmolColour.setSelected(true); } this.setBounds(bounds); - jmb.setColourBySequence(false); - seqColour.setSelected(false); initMenus(); viewId = viewid; // jalview.gui.Desktop.addInternalFrame(this, "Loading File", @@ -140,7 +148,11 @@ public class AppJmol extends GStructureViewer implements Runnable, initJmol(loadStatus); // pdbentry, seq, JBPCHECK! } - private void initMenus() { + + private void initMenus() + { + seqColour.setSelected(jmb.isColourBySequence()); + jmolColour.setSelected(!jmb.isColourBySequence()); seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith, new ItemListener() { @@ -162,7 +174,7 @@ public class AppJmol extends GStructureViewer implements Runnable, viewMenu.add(seqColourBy); final ItemListener handler; JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this, - _alignwith, handler=new ItemListener() + _alignwith, handler = new ItemListener() { @Override @@ -177,29 +189,51 @@ public class AppJmol extends GStructureViewer implements Runnable, jmolActionMenu.add(alpanels); jmolActionMenu.addMenuListener(new MenuListener() { - + @Override public void menuSelected(MenuEvent e) { handler.itemStateChanged(null); } - + @Override public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub - + } - + @Override public void menuCanceled(MenuEvent e) { // TODO Auto-generated method stub + + } + }); + colourMenu.addMenuListener(new MenuListener() + { + + @Override + public void menuSelected(MenuEvent arg0) + { + handlingGuiEvents=true; + } + + @Override + public void menuDeselected(MenuEvent arg0) + { + handlingGuiEvents=false; + } + + @Override + public void menuCanceled(MenuEvent arg0) + { + handlingGuiEvents=false; } }); - } + IProgressIndicator progressBar = null; public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, @@ -288,9 +322,11 @@ public class AppJmol extends GStructureViewer implements Runnable, { pdbentry }, new SequenceI[][] { seq }, null, null); addAlignmentPanel(ap); + useAlignmentPanelForColourbyseq(ap); + jmb.setColourBySequence(true); setSize(400, 400); // probably should be a configurable/dynamic default here initMenus(); - + if (pdbentry.getFile() != null) { initJmol("load \"" + pdbentry.getFile() + "\""); @@ -533,6 +569,10 @@ public class AppJmol extends GStructureViewer implements Runnable, jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow, null); jmb.newJmolPopup(true, "Jmol", true); + if (command==null) + { + command=""; + } jmb.evalStateCommand(command); jmb.setFinishedInit(true); } @@ -618,6 +658,13 @@ public class AppJmol extends GStructureViewer implements Runnable, */ private boolean _started = false; + /** + * state flag indicating if the GUI is active when a particular button event + * takes place (e.g. when a stateChange occurs on a checkbox - this could be + * programmatic or due to the user doing something) + */ + private boolean handlingGuiEvents=false; + public void run() { _started = true; @@ -895,17 +942,34 @@ public class AppJmol extends GStructureViewer implements Runnable, im.writeImage(); } } - + public void jmolColour_actionPerformed(ActionEvent actionEvent) + { + if (jmolColour.isSelected()) { + // disable automatic sequence colouring. + jmb.setColourBySequence(false); + } + } public void seqColour_actionPerformed(ActionEvent actionEvent) { jmb.setColourBySequence(seqColour.isSelected()); - if (_colourwith==null) { _colourwith=new ArrayList();}; - if (_colourwith.size()==0){ _colourwith.add(ap); }; - - // Set the colour using the current view for the associated alignframe - for (AlignmentPanel ap : _colourwith) + if (_colourwith == null) + { + _colourwith = new ArrayList(); + } + if (jmb.isColourBySequence()) { - jmb.colourBySequence(ap.av.showSequenceFeatures, ap); + if (!jmb.isLoadingFromArchive() && handlingGuiEvents) + { + if (ap!=null) { + // Make the currently displayed alignment panel the associated view + _colourwith.add(ap.alignFrame.alignPanel); + } + } + // Set the colour using the current view for the associated alignframe + for (AlignmentPanel ap : _colourwith) + { + jmb.colourBySequence(ap.av.showSequenceFeatures, ap); + } } } @@ -1099,15 +1163,23 @@ public class AppJmol extends GStructureViewer implements Runnable, { jmolActionMenu.setVisible(true); } - if (!jmb.isLoadingFromArchive()) { + if (!jmb.isLoadingFromArchive()) + { seqColour_actionPerformed(null); } } protected void buildJmolActionMenu() { - if (_alignwith==null) { _alignwith=new ArrayList();} - if (_alignwith.size()==0 && ap!=null) { _alignwith.add(ap);}; + if (_alignwith == null) + { + _alignwith = new ArrayList(); + } + if (_alignwith.size() == 0 && ap != null) + { + _alignwith.add(ap); + } + ; for (Component c : jmolActionMenu.getMenuComponents()) { if (c != alignStructs) @@ -1133,8 +1205,16 @@ public class AppJmol extends GStructureViewer implements Runnable, private void alignStructs_withAllAlignPanels() { - if (ap==null) { return; }; - if (_alignwith.size()==0) { _alignwith.add(ap);}; + if (ap == null) + { + return; + } + ; + if (_alignwith.size() == 0) + { + _alignwith.add(ap); + } + ; try { AlignmentI[] als = new Alignment[_alignwith.size()]; diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index c8d9ae3..22202e5 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -127,7 +127,7 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding { AlignmentPanel ap = (AlignmentPanel) source,topap; // ignore events from unrelated or non-user interactive frames - if ((topap=appJmolWindow.getAlignmentPanelFor(ap.av.getAlignment()))==null || topap.alignFrame.getCurrentView() != ap.av || appJmolWindow.isUsedforcolourby(ap)) + if ((topap=appJmolWindow.getAlignmentPanelFor(ap.av.getAlignment()))==null || topap.alignFrame.getCurrentView() != ap.av || !appJmolWindow.isUsedforcolourby(ap)) return; if (!isLoadingFromArchive()) { colourBySequence(ap.av.getShowSequenceFeatures(), ap); diff --git a/src/jalview/jbgui/GStructureViewer.java b/src/jalview/jbgui/GStructureViewer.java index f8c18d9..8116d82 100644 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@ -83,7 +83,7 @@ public class GStructureViewer extends JInternalFrame backGround_actionPerformed(actionEvent); } }); - seqColour.setSelected(true); + seqColour.setSelected(false); seqColour.setText("By Sequence"); seqColour.addActionListener(new ActionListener() { @@ -172,6 +172,17 @@ public class GStructureViewer extends JInternalFrame userColour_actionPerformed(actionEvent); } }); + jmolColour.setSelected(false); + jmolColour.setText("Colour with Jmol"); + jmolColour.setToolTipText("Let Jmol manage structure colours."); + jmolColour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent actionEvent) + { + jmolColour_actionPerformed(actionEvent); + } + } + ); helpMenu.setText("Help"); jmolHelp.setText("Jmol Help"); jmolHelp.addActionListener(new ActionListener() @@ -214,6 +225,7 @@ public class GStructureViewer extends JInternalFrame colourMenu.add(turnColour); colourMenu.add(buriedColour); colourMenu.add(userColour); + colourMenu.add(jmolColour); colourMenu.add(backGround); colourButtons.add(seqColour); @@ -227,11 +239,16 @@ public class GStructureViewer extends JInternalFrame colourButtons.add(turnColour); colourButtons.add(buriedColour); colourButtons.add(userColour); + colourButtons.add(jmolColour); helpMenu.add(jmolHelp); jmolActionMenu.add(alignStructs); } + protected void jmolColour_actionPerformed(ActionEvent actionEvent) + { + } + protected void alignStructs_actionPerformed(ActionEvent actionEvent) { } @@ -256,7 +273,7 @@ public class GStructureViewer extends JInternalFrame JMenu jMenu1 = new JMenu(); - JMenu colourMenu = new JMenu(); + protected JMenu colourMenu = new JMenu(); protected JMenu jmolActionMenu = new JMenu(); @@ -286,6 +303,8 @@ public class GStructureViewer extends JInternalFrame protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem jmolColour = new JRadioButtonMenuItem(); + protected ButtonGroup colourButtons = new ButtonGroup(); JMenu helpMenu = new JMenu(); -- 1.7.10.2