+ } catch (Exception ex)
+ {
+ }
+ }
+ }
+ }
+
+ /**
+ * modify current selection according to a received message.
+ */
+ @Override
+ public void selection(SequenceGroup seqsel, ColumnSelection colsel,
+ SelectionSource source)
+ {
+ // TODO: fix this hack - source of messages is align viewport, but SeqPanel
+ // handles selection messages...
+ // TODO: extend config options to allow user to control if selections may be
+ // shared between viewports.
+ boolean iSentTheSelection = (av == source || (source instanceof AlignViewport && ((AlignmentViewport) source)
+ .getSequenceSetId().equals(av.getSequenceSetId())));
+ if (iSentTheSelection || !av.followSelection)
+ {
+ return;
+ }
+
+ /*
+ * Ignore the selection if there is one of our own pending.
+ */
+ if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
+ {
+ return;
+ }
+
+ /*
+ * Check for selection in a view of which this one is a dna/protein
+ * complement.
+ */
+ if (selectionFromTranslation(seqsel, colsel, source))
+ {
+ return;
+ }
+
+ // do we want to thread this ? (contention with seqsel and colsel locks, I
+ // suspect)
+ /*
+ * only copy colsel if there is a real intersection between
+ * sequence selection and this panel's alignment
+ */
+ boolean repaint = false;
+ boolean copycolsel = false;
+
+ SequenceGroup sgroup = null;
+ if (seqsel != null && seqsel.getSize() > 0)
+ {
+ if (av.getAlignment() == null)
+ {
+ Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
+ + " ViewId=" + av.getViewId()
+ + " 's alignment is NULL! returning immediately.");
+ return;
+ }
+ sgroup = seqsel.intersect(av.getAlignment(),
+ (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
+ if ((sgroup != null && sgroup.getSize() > 0))
+ {
+ copycolsel = true;
+ }
+ }
+ if (sgroup != null && sgroup.getSize() > 0)
+ {
+ av.setSelectionGroup(sgroup);
+ }
+ else
+ {
+ av.setSelectionGroup(null);
+ }
+ av.isSelectionGroupChanged(true);
+ repaint = true;
+
+ if (copycolsel)
+ {
+ // the current selection is unset or from a previous message
+ // so import the new colsel.
+ if (colsel == null || colsel.isEmpty())
+ {
+ if (av.getColumnSelection() != null)
+ {
+ av.getColumnSelection().clear();
+ repaint = true;
+ }
+ }
+ else
+ {
+ // TODO: shift colSel according to the intersecting sequences
+ if (av.getColumnSelection() == null)
+ {
+ av.setColumnSelection(new ColumnSelection(colsel));