+ } catch (Exception ex)
+ {
+ }
+ }
+ }
+ }
+
+ /**
+ * modify current selection according to a received message.
+ */
+ 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.
+ if (av != null
+ && (av == source || !av.followSelection || (source instanceof AlignViewport && ((AlignViewport) source)
+ .getSequenceSetId().equals(av.getSequenceSetId()))))
+ {
+ return;
+ }
+ // do we want to thread this ? (contention with seqsel and colsel locks, I
+ // suspect)
+ // rules are: colsel is copied if there is a real intersection between
+ // sequence selection
+ boolean repaint = false, copycolsel = true;
+ if (av.getSelectionGroup() == null || !av.isSelectionGroupChanged(true))
+ {
+ SequenceGroup sgroup = null;
+ if (seqsel != null && seqsel.getSize() > 0)
+ {
+ if (av.getAlignment() == null)
+ {
+ System.out
+ .println("Selection message: alignviewport av SeqSetId="
+ + av.getSequenceSetId() + " ViewId="
+ + av.getViewId()
+ + " 's alignment is NULL! returning immediatly.");
+ return;
+ }
+ sgroup = seqsel.intersect(av.getAlignment(),
+ (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
+ if ((sgroup == null || sgroup.getSize() == 0)
+ && (colsel == null || colsel.size() == 0))
+ {
+ // don't copy columns if the region didn't intersect.
+ copycolsel = false;
+ }
+ }
+ if (sgroup != null && sgroup.getSize() > 0)
+ {
+ av.setSelectionGroup(sgroup);
+ }
+ else
+ {
+ av.setSelectionGroup(null);
+ }
+ repaint = av.isSelectionGroupChanged(true);
+ }
+ if (copycolsel
+ && (av.getColumnSelection() == null || !av
+ .isColSelChanged(true)))
+ {
+ // the current selection is unset or from a previous message
+ // so import the new colsel.
+ if (colsel == null || colsel.size() == 0)
+ {
+ if (av.getColumnSelection() != null)
+ {
+ av.getColumnSelection().clear();
+ }
+ }
+ else
+ {
+ // TODO: shift colSel according to the intersecting sequences
+ if (av.getColumnSelection() == null)
+ {
+ av.setColumnSelection(new ColumnSelection(colsel));
+ }
+ else
+ {
+ av.getColumnSelection().setElementsFrom(colsel);