+ if (importDs)
+ {
+ newDs.addElement(null);
+ }
+ SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
+ // paste
+ if (importDs && ds != null)
+ {
+ if (!newDs.contains(ds))
+ {
+ newDs.setElementAt(ds, i);
+ ds = new Sequence(ds);
+ // update with new dataset sequence
+ sequences[i].setDatasetSequence(ds);
+ }
+ else
+ {
+ ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
+ }
+ }
+ else
+ {
+ // copy and derive new dataset sequence
+ sequences[i] = sequences[i].deriveSequence();
+ alignment.getDataset().addSequence(
+ sequences[i].getDatasetSequence());
+ // TODO: avoid creation of duplicate dataset sequences with a
+ // 'contains' method using SequenceI.equals()/SequenceI.contains()
+ }
+ alignment.addSequence(sequences[i]); // merges dataset
+ }
+ if (newDs != null)
+ {
+ newDs.clear(); // tidy up
+ }
+ if (pastedal.getAlignmentAnnotation() != null)
+ {
+ // Add any annotation attached to alignment.
+ AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
+ for (int i = 0; i < alann.length; i++)
+ {
+ annotationAdded = true;
+ if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
+ {
+ AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
+ newann.padAnnotation(alwidth);
+ alignment.addAnnotation(newann);
+ }
+ }
+ }
+ }
+ if (!newAlignment)
+ {
+ // /////
+ // ADD HISTORY ITEM
+ //
+ addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
+ sequences, 0, alignment.getWidth(), alignment));
+ }
+ // Add any annotations attached to sequences
+ for (int i = 0; i < sequences.length; i++)
+ {
+ if (sequences[i].getAnnotation() != null)
+ {
+ for (int a = 0; a < sequences[i].getAnnotation().length; a++)
+ {
+ annotationAdded = true;
+ sequences[i].getAnnotation()[a].adjustForAlignment();
+ sequences[i].getAnnotation()[a].padAnnotation(alwidth);
+ alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
+ // was
+ // duplicated
+ // earlier
+ alignment
+ .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
+ }
+ }
+ }
+ if (!newAlignment)
+ {