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 StructureSelectionManager ssm;
29 Map<SequenceI, PhylogenyNode> sequencesBoundToNodes;
31 Map<PhylogenyNode, SequenceI> nodesBoundToSequences;
33 public JalviewAptxBinding(MainFrame archaeopteryx,
34 AlignmentViewport jalviewAlignmentViewport,
35 Map<SequenceI, PhylogenyNode> alignMappedToNodes,
36 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(MouseEvent e)
61 showNodeSelectionOnAlign(e);
65 public void mouseReleased(MouseEvent e)
70 public void mouseEntered(MouseEvent e)
75 public void mouseExited(MouseEvent e)
80 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
81 HiddenColumns hidden, SelectionSource source)
83 if (source == parentAvport) // check if source is alignment from where the
86 treeView.setFoundNodes0(
87 new HashSet<Long>(seqsel.getSequences().size()));
89 for (SequenceI selectedSequence : seqsel.getSequences())
91 PhylogenyNode matchingNode = sequencesBoundToNodes.get(selectedSequence);
92 if (matchingNode != null)
94 treeView.getFoundNodes0().add(matchingNode.getId());
98 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
106 * Note that this currently only checks external nodes
109 public void showNodeSelectionOnAlign(MouseEvent e)
111 final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
114 SequenceI matchingSequence = nodesBoundToSequences.get(node);
115 if (matchingSequence != null)
118 if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) // shift is pressed
119 // (so multiple nodes
127 parentAvport.setSelectionGroup(null); // reset selection if shift
132 treeSelectionChanged(matchingSequence);
133 parentAvport.sendSelection(); // not actually needed?
135 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
142 * Refactored from TreeCanvas
146 public void treeSelectionChanged(SequenceI sequence)
148 SequenceGroup selected = parentAvport.getSelectionGroup();
150 if (selected == null)
152 selected = new SequenceGroup();
153 parentAvport.setSelectionGroup(selected);
156 selected.setEndRes(parentAvport.getAlignment().getWidth() - 1);
157 selected.addOrRemove(sequence, true);
161 public AlignmentViewport getParentAvport()
166 public void setParentAvport(AlignmentViewport parentAvport)
168 this.parentAvport = parentAvport;