2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 * Jalview - A Sequence Alignment Editor and Viewer
23 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
41 import jalview.analysis.AlignmentUtils;
42 import jalview.analysis.AlignmentUtils.MappingResult;
43 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
44 import jalview.analysis.NJTree;
45 import jalview.api.AlignViewportI;
46 import jalview.bin.Cache;
47 import jalview.commands.CommandI;
48 import jalview.datamodel.Alignment;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.ColumnSelection;
51 import jalview.datamodel.PDBEntry;
52 import jalview.datamodel.Sequence;
53 import jalview.datamodel.SequenceGroup;
54 import jalview.datamodel.SequenceI;
55 import jalview.schemes.ColourSchemeProperty;
56 import jalview.schemes.UserColourScheme;
57 import jalview.structure.CommandListener;
58 import jalview.structure.SelectionSource;
59 import jalview.structure.StructureSelectionManager;
60 import jalview.structure.VamsasSource;
61 import jalview.util.MessageManager;
62 import jalview.viewmodel.AlignmentViewport;
63 import jalview.ws.params.AutoCalcSetting;
65 import java.awt.Color;
66 import java.awt.Container;
68 import java.awt.Rectangle;
69 import java.util.ArrayDeque;
70 import java.util.ArrayList;
71 import java.util.Deque;
72 import java.util.Hashtable;
74 import java.util.Vector;
76 import javax.swing.JInternalFrame;
77 import javax.swing.JOptionPane;
83 * @version $Revision: 1.141 $
85 public class AlignViewport extends AlignmentViewport implements
86 SelectionSource, VamsasSource, AlignViewportI, CommandListener
96 boolean showJVSuffix = true;
98 boolean showText = true;
100 boolean showColourText = false;
102 boolean showBoxes = true;
104 boolean wrapAlignment = false;
106 boolean renderGaps = true;
108 boolean showSequenceFeatures = false;
110 boolean showAnnotation = true;
112 SequenceAnnotationOrder sortAnnotationsBy = null;
118 boolean validCharWidth;
124 boolean seqNameItalics;
126 NJTree currentTree = null;
128 boolean scaleAboveWrapped = false;
130 boolean scaleLeftWrapped = true;
132 boolean scaleRightWrapped = true;
134 boolean showHiddenMarkers = true;
136 boolean cursorMode = false;
139 * Keys are the feature types which are currently visible. Note: Values are
142 Hashtable featuresDisplayed = null;
144 boolean antiAlias = false;
146 Rectangle explodedPosition;
150 boolean gatherViewsHere = false;
152 private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
154 private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
156 int thresholdTextColour = 0;
158 Color textColour = Color.black;
160 Color textColour2 = Color.white;
162 boolean rightAlignIds = false;
165 * Creates a new AlignViewport object.
170 public AlignViewport(AlignmentI al)
177 * Create a new AlignViewport object with a specific sequence set ID
181 * (may be null - but potential for ambiguous constructor exception)
183 public AlignViewport(AlignmentI al, String seqsetid)
185 this(al, seqsetid, null);
188 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
190 sequenceSetID = seqsetid;
192 // TODO remove these once 2.4.VAMSAS release finished
193 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
195 Cache.log.debug("Setting viewport's sequence set id : "
198 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
200 Cache.log.debug("Setting viewport's view id : " + viewId);
207 * Create a new AlignViewport with hidden regions
211 * @param hiddenColumns
214 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
217 if (hiddenColumns != null)
219 this.colSel = hiddenColumns;
220 if (hiddenColumns.getHiddenColumns() != null
221 && hiddenColumns.getHiddenColumns().size() > 0)
223 hasHiddenColumns = true;
227 hasHiddenColumns = false;
234 * New viewport with hidden columns and an existing sequence set id
237 * @param hiddenColumns
241 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
244 this(al, hiddenColumns, seqsetid, null);
248 * New viewport with hidden columns and an existing sequence set id and viewid
251 * @param hiddenColumns
257 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
258 String seqsetid, String viewid)
260 sequenceSetID = seqsetid;
262 // TODO remove these once 2.4.VAMSAS release finished
263 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
265 Cache.log.debug("Setting viewport's sequence set id : "
268 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
270 Cache.log.debug("Setting viewport's view id : " + viewId);
273 if (hiddenColumns != null)
275 this.colSel = hiddenColumns;
276 if (hiddenColumns.getHiddenColumns() != null
277 && hiddenColumns.getHiddenColumns().size() > 0)
279 hasHiddenColumns = true;
283 hasHiddenColumns = false;
292 this.endRes = alignment.getWidth() - 1;
294 this.endSeq = alignment.getHeight() - 1;
296 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
298 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
299 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
301 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
302 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
303 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
305 setPadGaps(Cache.getDefault("PAD_GAPS", true));
306 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
307 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
309 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
310 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
311 String fontSize = Cache.getDefault("FONT_SIZE", "10");
313 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
317 if (fontStyle.equals("bold"))
321 else if (fontStyle.equals("italic"))
326 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
329 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
331 // We must set conservation and consensus before setting colour,
332 // as Blosum and Clustal require this to be done
333 if (hconsensus == null && !isDataset)
335 if (!alignment.isNucleotide())
337 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
338 showQuality = Cache.getDefault("SHOW_QUALITY", true);
339 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
342 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
344 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
345 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
347 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
348 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
350 initAutoAnnotation();
351 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
353 globalColourScheme = ColourSchemeProperty.getColour(alignment,
354 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
356 if (globalColourScheme instanceof UserColourScheme)
358 globalColourScheme = UserDefinedColours.loadDefaultColours();
359 ((UserColourScheme) globalColourScheme).setThreshold(0,
360 getIgnoreGapsConsensus());
363 if (globalColourScheme != null)
365 globalColourScheme.setConsensus(hconsensus);
369 wrapAlignment = Cache.getDefault("WRAP_ALIGNMENT", false);
370 showUnconserved = Cache.getDefault("SHOW_UNCONSERVED", false);
371 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
372 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
373 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
374 Preferences.SORT_ANNOTATIONS,
375 SequenceAnnotationOrder.NONE.name()));
376 showAutocalculatedAbove = Cache.getDefault(
377 Preferences.SHOW_AUTOCALC_ABOVE, false);
384 * features are displayed if true
386 public void setShowSequenceFeatures(boolean b)
388 showSequenceFeatures = b;
391 public boolean getShowSequenceFeatures()
393 return showSequenceFeatures;
397 * centre columnar annotation labels in displayed alignment annotation TODO:
398 * add to jalviewXML and annotation display settings
400 boolean centreColumnLabels = false;
402 private boolean showdbrefs;
404 private boolean shownpfeats;
406 // --------END Structure Conservation
409 * get the consensus sequence as displayed under the PID consensus annotation
412 * @return consensus sequence as a new sequence object
414 public SequenceI getConsensusSeq()
416 if (consensus == null)
418 updateConsensus(null);
420 if (consensus == null)
424 StringBuffer seqs = new StringBuffer();
425 for (int i = 0; i < consensus.annotations.length; i++)
427 if (consensus.annotations[i] != null)
429 if (consensus.annotations[i].description.charAt(0) == '[')
431 seqs.append(consensus.annotations[i].description.charAt(1));
435 seqs.append(consensus.annotations[i].displayCharacter);
440 SequenceI sq = new Sequence("Consensus", seqs.toString());
441 sq.setDescription("Percentage Identity Consensus "
442 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
449 * @return DOCUMENT ME!
451 public int getStartRes()
459 * @return DOCUMENT ME!
461 public int getEndRes()
469 * @return DOCUMENT ME!
471 public int getStartSeq()
482 public void setStartRes(int res)
493 public void setStartSeq(int seq)
504 public void setEndRes(int res)
506 if (res > (alignment.getWidth() - 1))
508 // log.System.out.println(" Corrected res from " + res + " to maximum " +
509 // (alignment.getWidth()-1));
510 res = alignment.getWidth() - 1;
527 public void setEndSeq(int seq)
529 if (seq > alignment.getHeight())
531 seq = alignment.getHeight();
545 * @return DOCUMENT ME!
547 public int getEndSeq()
558 public void setFont(Font f)
562 Container c = new Container();
564 java.awt.FontMetrics fm = c.getFontMetrics(font);
565 setCharHeight(fm.getHeight());
566 setCharWidth(fm.charWidth('M'));
567 validCharWidth = true;
573 * @return DOCUMENT ME!
575 public Font getFont()
586 public void setCharWidth(int w)
594 * @return DOCUMENT ME!
596 public int getCharWidth()
607 public void setCharHeight(int h)
615 * @return DOCUMENT ME!
617 public int getCharHeight()
628 public void setWrappedWidth(int w)
630 this.wrappedWidth = w;
636 * @return DOCUMENT ME!
638 public int getWrappedWidth()
646 * @return DOCUMENT ME!
648 public AlignmentI getAlignment()
659 public void setAlignment(AlignmentI align)
661 if (alignment != null && alignment.getCodonFrames() != null)
663 StructureSelectionManager.getStructureSelectionManager(
664 Desktop.instance).removeMappings(alignment.getCodonFrames());
666 this.alignment = align;
667 if (alignment != null && alignment.getCodonFrames() != null)
669 StructureSelectionManager.getStructureSelectionManager(
670 Desktop.instance).addMappings(alignment.getCodonFrames());
680 public void setWrapAlignment(boolean state)
682 wrapAlignment = state;
691 public void setShowText(boolean state)
702 public void setRenderGaps(boolean state)
710 * @return DOCUMENT ME!
712 public boolean getColourText()
714 return showColourText;
723 public void setColourText(boolean state)
725 showColourText = state;
734 public void setShowBoxes(boolean state)
742 * @return DOCUMENT ME!
744 public boolean getWrapAlignment()
746 return wrapAlignment;
752 * @return DOCUMENT ME!
754 public boolean getShowText()
762 * @return DOCUMENT ME!
764 public boolean getShowBoxes()
772 * @return DOCUMENT ME!
774 public char getGapCharacter()
776 return getAlignment().getGapCharacter();
785 public void setGapCharacter(char gap)
787 if (getAlignment() != null)
789 getAlignment().setGapCharacter(gap);
796 * @return DOCUMENT ME!
798 public ColumnSelection getColumnSelection()
809 public void setCurrentTree(NJTree tree)
817 * @return DOCUMENT ME!
819 public NJTree getCurrentTree()
827 * @return DOCUMENT ME!
829 public boolean getShowJVSuffix()
840 public void setShowJVSuffix(boolean b)
848 * @return DOCUMENT ME!
850 public boolean getShowAnnotation()
852 return showAnnotation;
861 public void setShowAnnotation(boolean b)
869 * @return DOCUMENT ME!
871 public boolean getScaleAboveWrapped()
873 return scaleAboveWrapped;
879 * @return DOCUMENT ME!
881 public boolean getScaleLeftWrapped()
883 return scaleLeftWrapped;
889 * @return DOCUMENT ME!
891 public boolean getScaleRightWrapped()
893 return scaleRightWrapped;
902 public void setScaleAboveWrapped(boolean b)
904 scaleAboveWrapped = b;
913 public void setScaleLeftWrapped(boolean b)
915 scaleLeftWrapped = b;
924 public void setScaleRightWrapped(boolean b)
926 scaleRightWrapped = b;
929 public void setDataset(boolean b)
934 public boolean isDataset()
939 public boolean getShowHiddenMarkers()
941 return showHiddenMarkers;
944 public void setShowHiddenMarkers(boolean show)
946 showHiddenMarkers = show;
950 * returns the visible column regions of the alignment
952 * @param selectedRegionOnly
953 * true to just return the contigs intersecting with the selected
957 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
959 int[] viscontigs = null;
960 int start = 0, end = 0;
961 if (selectedRegionOnly && selectionGroup != null)
963 start = selectionGroup.getStartRes();
964 end = selectionGroup.getEndRes() + 1;
968 end = alignment.getWidth();
970 viscontigs = colSel.getVisibleContigs(start, end);
975 * get hash of undo and redo list for the alignment
977 * @return long[] { historyList.hashCode, redoList.hashCode };
979 public long[] getUndoRedoHash()
982 if (historyList == null || redoList == null)
988 { historyList.hashCode(), this.redoList.hashCode() };
992 * test if a particular set of hashcodes are different to the hashcodes for
993 * the undo and redo list.
996 * the stored set of hashcodes as returned by getUndoRedoHash
997 * @return true if the hashcodes differ (ie the alignment has been edited) or
998 * the stored hashcode array differs in size
1000 public boolean isUndoRedoHashModified(long[] undoredo)
1002 if (undoredo == null)
1006 long[] cstate = getUndoRedoHash();
1007 if (cstate.length != undoredo.length)
1012 for (int i = 0; i < cstate.length; i++)
1014 if (cstate[i] != undoredo[i])
1022 public boolean getCentreColumnLabels()
1024 return centreColumnLabels;
1027 public void setCentreColumnLabels(boolean centrecolumnlabels)
1029 centreColumnLabels = centrecolumnlabels;
1033 * enable or disable the display of Database Cross References in the sequence
1036 public void setShowDbRefs(boolean show)
1043 * @return true if Database References are to be displayed on tooltips.
1045 public boolean isShowDbRefs()
1052 * @return true if Non-positional features are to be displayed on tooltips.
1054 public boolean isShowNpFeats()
1060 * enable or disable the display of Non-Positional sequence features in the
1061 * sequence ID tooltip
1065 public void setShowNpFeats(boolean show)
1072 * @return true if view has hidden rows
1074 public boolean hasHiddenRows()
1076 return hasHiddenRows;
1081 * @return true if view has hidden columns
1083 public boolean hasHiddenColumns()
1085 return hasHiddenColumns;
1089 * when set, view will scroll to show the highlighted position
1091 public boolean followHighlight = true;
1094 * @return true if view should scroll to show the highlighted region of a
1098 public boolean getFollowHighlight()
1100 return followHighlight;
1103 public boolean followSelection = true;
1106 * @return true if view selection should always follow the selections
1107 * broadcast by other selection sources
1109 public boolean getFollowSelection()
1111 return followSelection;
1114 boolean showSeqFeaturesHeight;
1117 * Send the current selection to be broadcast to any selection listeners.
1119 public void sendSelection()
1121 jalview.structure.StructureSelectionManager
1122 .getStructureSelectionManager(Desktop.instance).sendSelection(
1123 new SequenceGroup(getSelectionGroup()),
1124 new ColumnSelection(getColumnSelection()), this);
1127 public void setShowSequenceFeaturesHeight(boolean selected)
1129 showSeqFeaturesHeight = selected;
1132 public boolean getShowSequenceFeaturesHeight()
1134 return showSeqFeaturesHeight;
1138 * return the alignPanel containing the given viewport. Use this to get the
1139 * components currently handling the given viewport.
1142 * @return null or an alignPanel guaranteed to have non-null alignFrame
1145 public AlignmentPanel getAlignPanel()
1147 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
1148 .getSequenceSetId());
1149 AlignmentPanel ap = null;
1150 for (int p = 0; aps != null && p < aps.length; p++)
1152 if (aps[p].av == this)
1160 public boolean getSortByTree()
1165 public void setSortByTree(boolean sort)
1171 * synthesize a column selection if none exists so it covers the given
1172 * selection group. if wholewidth is false, no column selection is made if the
1173 * selection group covers the whole alignment width.
1178 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
1182 && (sgs = sg.getStartRes()) >= 0
1183 && sg.getStartRes() <= (sge = sg.getEndRes())
1184 && (colSel == null || colSel.getSelected() == null || colSel
1185 .getSelected().size() == 0))
1187 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
1194 colSel = new ColumnSelection();
1196 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
1198 colSel.addElement(cspos);
1203 public StructureSelectionManager getStructureSelectionManager()
1205 return StructureSelectionManager
1206 .getStructureSelectionManager(Desktop.instance);
1212 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
1213 * sequence in the alignment holds a reference to it
1215 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
1217 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
1218 for (PDBEntry pdb : pdbEntries)
1220 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
1221 for (int i = 0; i < alignment.getHeight(); i++)
1223 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
1230 for (int p = 0; p < pdbs.size(); p++)
1232 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
1233 if (p1.getId().equals(pdb.getId()))
1235 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
1244 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
1246 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
1249 public boolean isNormaliseSequenceLogo()
1251 return normaliseSequenceLogo;
1254 public void setNormaliseSequenceLogo(boolean state)
1256 normaliseSequenceLogo = state;
1261 * @return true if alignment characters should be displayed
1263 public boolean isValidCharWidth()
1265 return validCharWidth;
1268 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
1270 private boolean showAutocalculatedAbove;
1272 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
1274 return calcIdParams.get(calcId);
1277 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
1278 boolean needsUpdate)
1280 calcIdParams.put(calcId, settings);
1281 // TODO: create a restart list to trigger any calculations that need to be
1282 // restarted after load
1283 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
1286 Cache.log.debug("trigger update for " + calcId);
1290 protected SequenceAnnotationOrder getSortAnnotationsBy()
1292 return sortAnnotationsBy;
1295 protected void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
1297 this.sortAnnotationsBy = sortAnnotationsBy;
1300 protected boolean isShowAutocalculatedAbove()
1302 return showAutocalculatedAbove;
1305 protected void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
1307 this.showAutocalculatedAbove = showAutocalculatedAbove;
1311 * Method called when another alignment's edit (or possibly other) command is
1312 * broadcast to here.
1314 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
1315 * 'unwind' the command on the source sequences (in simulation, not in fact),
1316 * and then for each edit in turn:
1318 * <li>compute the equivalent edit on the mapped sequences</li>
1319 * <li>apply the mapped edit</li>
1320 * <li>'apply' the source edit to the working copy of the source sequences</li>
1328 public void mirrorCommand(CommandI command, boolean undo,
1329 StructureSelectionManager ssm, VamsasSource source)
1332 * ...work in progress... do nothing unless we are a 'slave' of the source
1333 * May replace this with direct calls not via SSM.
1335 if (source instanceof AlignViewportI
1336 && ((AlignViewportI) source).getSlave() == this)
1345 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
1347 if (mappedCommand != null)
1349 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
1350 mappedCommand.doCommand(views);
1351 getAlignPanel().alignmentChanged();
1356 public VamsasSource getVamsasSource()
1362 * Add one command to the command history list.
1366 public void addToHistoryList(CommandI command)
1368 if (this.historyList != null)
1370 this.historyList.push(command);
1371 broadcastCommand(command, false);
1375 protected void broadcastCommand(CommandI command, boolean undo)
1377 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
1381 * Add one command to the command redo list.
1385 public void addToRedoList(CommandI command)
1387 if (this.redoList != null)
1389 this.redoList.push(command);
1391 broadcastCommand(command, true);
1395 * Clear the command redo list.
1397 public void clearRedoList()
1399 if (this.redoList != null)
1401 this.redoList.clear();
1405 public void setHistoryList(Deque<CommandI> list)
1407 this.historyList = list;
1410 public Deque<CommandI> getHistoryList()
1412 return this.historyList;
1415 public void setRedoList(Deque<CommandI> list)
1417 this.redoList = list;
1420 public Deque<CommandI> getRedoList()
1422 return this.redoList;
1426 * Add the sequences from the given alignment to this viewport. Optionally,
1427 * may give the user the option to open a new frame, or split panel, with cDNA
1428 * and protein linked.
1433 public void addAlignment(AlignmentI al, String title)
1435 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
1437 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
1439 // TODO: create undo object for this JAL-1101
1442 * If one alignment is protein and one nucleotide, with at least one
1443 * sequence name in common, offer to open a linked alignment.
1445 if (getAlignment().isNucleotide() != al.isNucleotide())
1447 final Set<String> sequenceNames = getAlignment().getSequenceNames();
1448 sequenceNames.retainAll(al.getSequenceNames());
1449 if (!sequenceNames.isEmpty()) // at least one sequence name in both
1451 if (openLinkedAlignment(al, title))
1458 for (int i = 0; i < al.getHeight(); i++)
1460 getAlignment().addSequence(al.getSequenceAt(i));
1462 // TODO this call was done by SequenceFetcher but not FileLoader or
1463 // CutAndPasteTransfer. Is it needed?
1464 setEndSeq(getAlignment().getHeight());
1465 firePropertyChange("alignment", null, getAlignment().getSequences());
1469 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
1470 * alignment. Returns true if the new alignment was opened, false if not,
1471 * because the user declined the offer.
1475 protected boolean openLinkedAlignment(AlignmentI al, String title)
1477 String[] options = new String[]
1478 { MessageManager.getString("action.no"),
1479 MessageManager.getString("label.split_window"),
1480 MessageManager.getString("label.new_window"), };
1481 final String question = JvSwingUtils.wrapTooltip(true,
1482 MessageManager.getString("label.open_linked_alignment?"));
1483 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
1484 MessageManager.getString("label.open_linked_alignment"),
1485 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
1486 options, options[0]);
1488 if (response != 1 && response != 2)
1492 final boolean openSplitPane = (response == 1);
1493 final boolean openInNewWindow = (response == 2);
1496 * Create the AlignFrame first (which creates the new alignment's datasets),
1497 * before attempting sequence mapping.
1499 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
1500 AlignFrame.DEFAULT_HEIGHT);
1503 * Identify protein and dna alignments. Make a copy of this one if opening
1504 * in a new split pane.
1506 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
1508 final AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
1509 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
1511 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1512 "label.successfully_loaded_file", new Object[]
1515 // TODO if we want this (e.g. to enable reload of the alignment from file),
1516 // we will need to add parameters to the stack.
1517 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1519 // alignFrame.setFileName(file, format);
1522 if (openInNewWindow)
1524 Desktop.addInternalFrame(newAlignFrame, title,
1525 AlignFrame.DEFAULT_WIDTH,
1526 AlignFrame.DEFAULT_HEIGHT);
1530 * Try to find mappings for at least one sequence.
1532 MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
1533 final StructureSelectionManager ssm = StructureSelectionManager
1534 .getStructureSelectionManager(Desktop.instance);
1535 if (mapped == MappingResult.Mapped)
1539 * Register the mappings (held on the protein alignment) with the
1540 * StructureSelectionManager (for mouseover linking).
1542 ssm.addMappings(protein.getCodonFrames());
1548 * No mapping possible - warn the user, but leave window open.
1550 final String msg = JvSwingUtils.wrapTooltip(true,
1551 MessageManager.getString("label.mapping_failed"));
1552 JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
1553 MessageManager.getString("label.no_mappings"),
1554 JOptionPane.WARNING_MESSAGE);
1559 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
1562 } catch (java.beans.PropertyVetoException ex)
1569 * Open in split pane. DNA sequence above, protein below.
1571 AlignFrame copyMe = new AlignFrame(thisAlignment,
1572 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1573 copyMe.setTitle(""); // TODO would like this AlignFrame.title here
1574 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
1576 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
1578 newAlignFrame.setTitle(title);
1580 cdnaFrame.setVisible(true);
1581 proteinFrame.setVisible(true);
1582 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
1583 Desktop.addInternalFrame(splitFrame, title, AlignFrame.DEFAULT_WIDTH,
1584 AlignFrame.DEFAULT_HEIGHT);
1587 * Set the cDNA to list for edits on the protein.
1589 ssm.addCommandListener(cdnaFrame.getViewport());
1592 * cDNA is 'slaved' to edits, selection, sorting, show/hide on protein
1594 proteinFrame.getViewport().setSlave(cdnaFrame.getViewport());