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)
55 public void mouseClicked(MouseEvent e)
61 public void mousePressed(MouseEvent e)
63 showNodeSelectionOnAlign(e);
68 public void mouseReleased(MouseEvent e)
73 public void mouseEntered(MouseEvent e)
79 public void mouseExited(MouseEvent e)
85 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
86 HiddenColumns hidden, SelectionSource source)
88 if (source == parentAvport) // check if source is alignment from where the
91 treeView.setFoundNodes0(
92 new HashSet<Long>(seqsel.getSequences().size()));
94 for (SequenceI sequence : seqsel.getSequences())
96 PhylogenyNode matchingNode = sequencesBoundToNodes.get(sequence);
97 if (matchingNode != null)
99 treeView.getFoundNodes0().add(matchingNode.getId());
103 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
111 public void showNodeSelectionOnAlign(MouseEvent e)
113 final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
114 if (node != null && node.isExternal())
116 SequenceI matchingSequence = nodesBoundToSequences.get(node);
118 if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) // shift is pressed
119 // (so multiple nodes
126 parentAvport.setSelectionGroup(null); // reset selection if shift isn't
130 treeSelectionChanged(matchingSequence);
131 parentAvport.sendSelection(); // not actually needed?
133 PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
139 * Refactored from TreeCanvas
143 public void treeSelectionChanged(SequenceI sequence)
145 SequenceGroup selected = parentAvport.getSelectionGroup();
147 if (selected == null)
149 selected = new SequenceGroup();
150 parentAvport.setSelectionGroup(selected);
153 selected.setEndRes(parentAvport.getAlignment().getWidth() - 1);
154 selected.addOrRemove(sequence, true);
158 public AlignmentViewport getParentAvport()
163 public void setParentAvport(AlignmentViewport parentAvport)
165 this.parentAvport = parentAvport;