1 package jalview.ext.archaeopteryx;
3 import jalview.datamodel.ColumnSelection;
4 import jalview.datamodel.HiddenColumns;
5 import jalview.datamodel.SequenceGroup;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.PaintRefresher;
8 import jalview.structure.SelectionSource;
9 import jalview.structure.StructureSelectionManager;
10 import jalview.viewmodel.AlignmentViewport;
12 import java.awt.event.ActionEvent;
13 import java.awt.event.InputEvent;
14 import java.awt.event.MouseEvent;
15 import java.util.HashSet;
18 import org.forester.archaeopteryx.MainFrame;
19 import org.forester.phylogeny.PhylogenyNode;
21 public class JalviewAptxBinding implements JalviewTreeViewerBindingI
23 org.forester.archaeopteryx.TreePanel treeView;
25 AlignmentViewport parentAvport;
27 final StructureSelectionManager ssm;
29 Map<SequenceI, PhylogenyNode> sequencesBoundToNodes;
31 Map<PhylogenyNode, SequenceI> nodesBoundToSequences;
33 public JalviewAptxBinding(final MainFrame archaeopteryx,
34 final AlignmentViewport jalviewAlignmentViewport,
35 final Map<SequenceI, PhylogenyNode> alignMappedToNodes,
36 final Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
38 parentAvport = jalviewAlignmentViewport;
39 sequencesBoundToNodes = alignMappedToNodes;
40 nodesBoundToSequences = nodesMappedToAlign;
41 treeView = archaeopteryx.getMainPanel().getCurrentTreePanel();
42 ssm = parentAvport.getStructureSelectionManager();
43 ssm.addSelectionListener(this);
44 treeView.addMouseListener(this);
45 PaintRefresher.Register(treeView, parentAvport.getSequenceSetId());
49 public void actionPerformed(ActionEvent e)
54 public void mouseClicked(MouseEvent e)
59 public void mousePressed(final MouseEvent e)
61 showNodeSelectionOnAlign(e);
65 public void mouseReleased(MouseEvent e)
70 public void mouseEntered(MouseEvent e)
75 public void mouseExited(MouseEvent e)
81 public void selection(final SequenceGroup seqsel,
82 final ColumnSelection colsel, final HiddenColumns hidden,
83 final SelectionSource source)
85 if (source == parentAvport) // check if source is alignment from where the
88 treeView.setFoundNodes0(
89 new HashSet<Long>(seqsel.getSequences().size()));
91 for (SequenceI selectedSequence : seqsel.getSequences())
93 PhylogenyNode matchingNode = sequencesBoundToNodes.get(selectedSequence);
94 if (matchingNode != null)
96 treeView.getFoundNodes0().add(matchingNode.getId());
100 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
108 * If a node is selected in the tree panel this method highlights the
109 * corresponding sequence in the Jalview alignment view.
112 public void showNodeSelectionOnAlign(final MouseEvent e)
114 final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
117 SequenceI matchingSequence = nodesBoundToSequences.get(node);
118 if (matchingSequence != null)
121 if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) // shift is pressed
122 // (so multiple nodes
130 parentAvport.setSelectionGroup(null); // reset selection if shift
135 treeSelectionChanged(matchingSequence);
136 parentAvport.sendSelection(); // not actually needed?
137 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
147 * Refactored from TreeCanvas
151 public void treeSelectionChanged(final SequenceI sequence)
153 SequenceGroup selected = parentAvport.getSelectionGroup();
155 if (selected == null)
157 selected = new SequenceGroup();
158 parentAvport.setSelectionGroup(selected);
161 selected.setEndRes(parentAvport.getAlignment().getWidth() - 1);
162 selected.addOrRemove(sequence, true);
166 public AlignmentViewport getParentAvport()
171 public void setParentAvport(final AlignmentViewport parentAvport)
173 this.parentAvport = parentAvport;