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.util.StringUtils;
63 import jalview.viewmodel.AlignmentViewport;
64 import jalview.ws.params.AutoCalcSetting;
66 import java.awt.Color;
67 import java.awt.Container;
69 import java.awt.Rectangle;
70 import java.util.ArrayDeque;
71 import java.util.ArrayList;
72 import java.util.Deque;
73 import java.util.Hashtable;
75 import java.util.Vector;
77 import javax.swing.JInternalFrame;
78 import javax.swing.JOptionPane;
84 * @version $Revision: 1.141 $
86 public class AlignViewport extends AlignmentViewport implements
87 SelectionSource, VamsasSource, AlignViewportI, CommandListener
97 boolean showJVSuffix = true;
99 boolean showText = true;
101 boolean showColourText = false;
103 boolean showBoxes = true;
105 boolean wrapAlignment = false;
107 boolean renderGaps = true;
109 boolean showSequenceFeatures = false;
111 boolean showAnnotation = true;
113 SequenceAnnotationOrder sortAnnotationsBy = null;
119 boolean validCharWidth;
125 boolean seqNameItalics;
127 NJTree currentTree = null;
129 boolean scaleAboveWrapped = false;
131 boolean scaleLeftWrapped = true;
133 boolean scaleRightWrapped = true;
135 boolean showHiddenMarkers = true;
137 boolean cursorMode = false;
140 * Keys are the feature types which are currently visible. Note: Values are
143 Hashtable featuresDisplayed = null;
145 boolean antiAlias = false;
147 Rectangle explodedPosition;
151 boolean gatherViewsHere = false;
153 private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
155 private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
157 int thresholdTextColour = 0;
159 Color textColour = Color.black;
161 Color textColour2 = Color.white;
163 boolean rightAlignIds = false;
166 * Creates a new AlignViewport object.
171 public AlignViewport(AlignmentI al)
178 * Create a new AlignViewport object with a specific sequence set ID
182 * (may be null - but potential for ambiguous constructor exception)
184 public AlignViewport(AlignmentI al, String seqsetid)
186 this(al, seqsetid, null);
189 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
191 sequenceSetID = seqsetid;
193 // TODO remove these once 2.4.VAMSAS release finished
194 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
196 Cache.log.debug("Setting viewport's sequence set id : "
199 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
201 Cache.log.debug("Setting viewport's view id : " + viewId);
208 * Create a new AlignViewport with hidden regions
212 * @param hiddenColumns
215 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
218 if (hiddenColumns != null)
220 this.colSel = hiddenColumns;
221 if (hiddenColumns.getHiddenColumns() != null
222 && hiddenColumns.getHiddenColumns().size() > 0)
224 hasHiddenColumns = true;
228 hasHiddenColumns = false;
235 * New viewport with hidden columns and an existing sequence set id
238 * @param hiddenColumns
242 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
245 this(al, hiddenColumns, seqsetid, null);
249 * New viewport with hidden columns and an existing sequence set id and viewid
252 * @param hiddenColumns
258 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
259 String seqsetid, String viewid)
261 sequenceSetID = seqsetid;
263 // TODO remove these once 2.4.VAMSAS release finished
264 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
266 Cache.log.debug("Setting viewport's sequence set id : "
269 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
271 Cache.log.debug("Setting viewport's view id : " + viewId);
274 if (hiddenColumns != null)
276 this.colSel = hiddenColumns;
277 if (hiddenColumns.getHiddenColumns() != null
278 && hiddenColumns.getHiddenColumns().size() > 0)
280 hasHiddenColumns = true;
284 hasHiddenColumns = false;
293 this.endRes = alignment.getWidth() - 1;
295 this.endSeq = alignment.getHeight() - 1;
297 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
299 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
300 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
302 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
303 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
304 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
306 setPadGaps(Cache.getDefault("PAD_GAPS", true));
307 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
308 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
310 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
311 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
312 String fontSize = Cache.getDefault("FONT_SIZE", "10");
314 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
318 if (fontStyle.equals("bold"))
322 else if (fontStyle.equals("italic"))
327 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
330 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
332 // We must set conservation and consensus before setting colour,
333 // as Blosum and Clustal require this to be done
334 if (hconsensus == null && !isDataset)
336 if (!alignment.isNucleotide())
338 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
339 showQuality = Cache.getDefault("SHOW_QUALITY", true);
340 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
343 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
345 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
346 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
348 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
349 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
351 initAutoAnnotation();
352 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
354 globalColourScheme = ColourSchemeProperty.getColour(alignment,
355 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
357 if (globalColourScheme instanceof UserColourScheme)
359 globalColourScheme = UserDefinedColours.loadDefaultColours();
360 ((UserColourScheme) globalColourScheme).setThreshold(0,
361 getIgnoreGapsConsensus());
364 if (globalColourScheme != null)
366 globalColourScheme.setConsensus(hconsensus);
370 wrapAlignment = Cache.getDefault("WRAP_ALIGNMENT", false);
371 showUnconserved = Cache.getDefault("SHOW_UNCONSERVED", false);
372 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
373 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
374 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
375 Preferences.SORT_ANNOTATIONS,
376 SequenceAnnotationOrder.NONE.name()));
377 showAutocalculatedAbove = Cache.getDefault(
378 Preferences.SHOW_AUTOCALC_ABOVE, false);
385 * features are displayed if true
387 public void setShowSequenceFeatures(boolean b)
389 showSequenceFeatures = b;
392 public boolean getShowSequenceFeatures()
394 return showSequenceFeatures;
398 * centre columnar annotation labels in displayed alignment annotation TODO:
399 * add to jalviewXML and annotation display settings
401 boolean centreColumnLabels = false;
403 private boolean showdbrefs;
405 private boolean shownpfeats;
407 // --------END Structure Conservation
410 * get the consensus sequence as displayed under the PID consensus annotation
413 * @return consensus sequence as a new sequence object
415 public SequenceI getConsensusSeq()
417 if (consensus == null)
419 updateConsensus(null);
421 if (consensus == null)
425 StringBuffer seqs = new StringBuffer();
426 for (int i = 0; i < consensus.annotations.length; i++)
428 if (consensus.annotations[i] != null)
430 if (consensus.annotations[i].description.charAt(0) == '[')
432 seqs.append(consensus.annotations[i].description.charAt(1));
436 seqs.append(consensus.annotations[i].displayCharacter);
441 SequenceI sq = new Sequence("Consensus", seqs.toString());
442 sq.setDescription("Percentage Identity Consensus "
443 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
450 * @return DOCUMENT ME!
452 public int getStartRes()
460 * @return DOCUMENT ME!
462 public int getEndRes()
470 * @return DOCUMENT ME!
472 public int getStartSeq()
483 public void setStartRes(int res)
494 public void setStartSeq(int seq)
505 public void setEndRes(int res)
507 if (res > (alignment.getWidth() - 1))
509 // log.System.out.println(" Corrected res from " + res + " to maximum " +
510 // (alignment.getWidth()-1));
511 res = alignment.getWidth() - 1;
528 public void setEndSeq(int seq)
530 if (seq > alignment.getHeight())
532 seq = alignment.getHeight();
546 * @return DOCUMENT ME!
548 public int getEndSeq()
559 public void setFont(Font f)
563 Container c = new Container();
565 java.awt.FontMetrics fm = c.getFontMetrics(font);
566 setCharHeight(fm.getHeight());
567 setCharWidth(fm.charWidth('M'));
568 validCharWidth = true;
574 * @return DOCUMENT ME!
576 public Font getFont()
587 public void setCharWidth(int w)
595 * @return DOCUMENT ME!
597 public int getCharWidth()
608 public void setCharHeight(int h)
616 * @return DOCUMENT ME!
618 public int getCharHeight()
629 public void setWrappedWidth(int w)
631 this.wrappedWidth = w;
637 * @return DOCUMENT ME!
639 public int getWrappedWidth()
647 * @return DOCUMENT ME!
649 public AlignmentI getAlignment()
660 public void setAlignment(AlignmentI align)
662 if (alignment != null && alignment.getCodonFrames() != null)
664 StructureSelectionManager.getStructureSelectionManager(
665 Desktop.instance).removeMappings(alignment.getCodonFrames());
667 this.alignment = align;
668 if (alignment != null && alignment.getCodonFrames() != null)
670 StructureSelectionManager.getStructureSelectionManager(
671 Desktop.instance).addMappings(alignment.getCodonFrames());
681 public void setWrapAlignment(boolean state)
683 wrapAlignment = state;
692 public void setShowText(boolean state)
703 public void setRenderGaps(boolean state)
711 * @return DOCUMENT ME!
713 public boolean getColourText()
715 return showColourText;
724 public void setColourText(boolean state)
726 showColourText = state;
735 public void setShowBoxes(boolean state)
743 * @return DOCUMENT ME!
745 public boolean getWrapAlignment()
747 return wrapAlignment;
753 * @return DOCUMENT ME!
755 public boolean getShowText()
763 * @return DOCUMENT ME!
765 public boolean getShowBoxes()
773 * @return DOCUMENT ME!
775 public char getGapCharacter()
777 return getAlignment().getGapCharacter();
786 public void setGapCharacter(char gap)
788 if (getAlignment() != null)
790 getAlignment().setGapCharacter(gap);
797 * @return DOCUMENT ME!
799 public ColumnSelection getColumnSelection()
810 public void setCurrentTree(NJTree tree)
818 * @return DOCUMENT ME!
820 public NJTree getCurrentTree()
828 * @return DOCUMENT ME!
830 public boolean getShowJVSuffix()
841 public void setShowJVSuffix(boolean b)
849 * @return DOCUMENT ME!
851 public boolean getShowAnnotation()
853 return showAnnotation;
862 public void setShowAnnotation(boolean b)
870 * @return DOCUMENT ME!
872 public boolean getScaleAboveWrapped()
874 return scaleAboveWrapped;
880 * @return DOCUMENT ME!
882 public boolean getScaleLeftWrapped()
884 return scaleLeftWrapped;
890 * @return DOCUMENT ME!
892 public boolean getScaleRightWrapped()
894 return scaleRightWrapped;
903 public void setScaleAboveWrapped(boolean b)
905 scaleAboveWrapped = b;
914 public void setScaleLeftWrapped(boolean b)
916 scaleLeftWrapped = b;
925 public void setScaleRightWrapped(boolean b)
927 scaleRightWrapped = b;
930 public void setDataset(boolean b)
935 public boolean isDataset()
940 public boolean getShowHiddenMarkers()
942 return showHiddenMarkers;
945 public void setShowHiddenMarkers(boolean show)
947 showHiddenMarkers = show;
951 * returns the visible column regions of the alignment
953 * @param selectedRegionOnly
954 * true to just return the contigs intersecting with the selected
958 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
960 int[] viscontigs = null;
961 int start = 0, end = 0;
962 if (selectedRegionOnly && selectionGroup != null)
964 start = selectionGroup.getStartRes();
965 end = selectionGroup.getEndRes() + 1;
969 end = alignment.getWidth();
971 viscontigs = colSel.getVisibleContigs(start, end);
976 * get hash of undo and redo list for the alignment
978 * @return long[] { historyList.hashCode, redoList.hashCode };
980 public long[] getUndoRedoHash()
983 if (historyList == null || redoList == null)
989 { historyList.hashCode(), this.redoList.hashCode() };
993 * test if a particular set of hashcodes are different to the hashcodes for
994 * the undo and redo list.
997 * the stored set of hashcodes as returned by getUndoRedoHash
998 * @return true if the hashcodes differ (ie the alignment has been edited) or
999 * the stored hashcode array differs in size
1001 public boolean isUndoRedoHashModified(long[] undoredo)
1003 if (undoredo == null)
1007 long[] cstate = getUndoRedoHash();
1008 if (cstate.length != undoredo.length)
1013 for (int i = 0; i < cstate.length; i++)
1015 if (cstate[i] != undoredo[i])
1023 public boolean getCentreColumnLabels()
1025 return centreColumnLabels;
1028 public void setCentreColumnLabels(boolean centrecolumnlabels)
1030 centreColumnLabels = centrecolumnlabels;
1034 * enable or disable the display of Database Cross References in the sequence
1037 public void setShowDbRefs(boolean show)
1044 * @return true if Database References are to be displayed on tooltips.
1046 public boolean isShowDbRefs()
1053 * @return true if Non-positional features are to be displayed on tooltips.
1055 public boolean isShowNpFeats()
1061 * enable or disable the display of Non-Positional sequence features in the
1062 * sequence ID tooltip
1066 public void setShowNpFeats(boolean show)
1073 * @return true if view has hidden rows
1075 public boolean hasHiddenRows()
1077 return hasHiddenRows;
1082 * @return true if view has hidden columns
1084 public boolean hasHiddenColumns()
1086 return hasHiddenColumns;
1090 * when set, view will scroll to show the highlighted position
1092 public boolean followHighlight = true;
1095 * @return true if view should scroll to show the highlighted region of a
1099 public boolean getFollowHighlight()
1101 return followHighlight;
1104 public boolean followSelection = true;
1107 * @return true if view selection should always follow the selections
1108 * broadcast by other selection sources
1110 public boolean getFollowSelection()
1112 return followSelection;
1115 boolean showSeqFeaturesHeight;
1118 * Send the current selection to be broadcast to any selection listeners.
1120 public void sendSelection()
1122 jalview.structure.StructureSelectionManager
1123 .getStructureSelectionManager(Desktop.instance).sendSelection(
1124 new SequenceGroup(getSelectionGroup()),
1125 new ColumnSelection(getColumnSelection()), this);
1128 public void setShowSequenceFeaturesHeight(boolean selected)
1130 showSeqFeaturesHeight = selected;
1133 public boolean getShowSequenceFeaturesHeight()
1135 return showSeqFeaturesHeight;
1139 * return the alignPanel containing the given viewport. Use this to get the
1140 * components currently handling the given viewport.
1143 * @return null or an alignPanel guaranteed to have non-null alignFrame
1146 public AlignmentPanel getAlignPanel()
1148 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
1149 .getSequenceSetId());
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 'complement' of the
1333 * source May replace this with direct calls not via SSM.
1335 if (source instanceof AlignViewportI
1336 && ((AlignViewportI) source).getCodingComplement() == 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);
1501 newAlignFrame.setTitle(title);
1504 * Identify protein and dna alignments. Make a copy of this one if opening
1505 * in a new split pane.
1507 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
1509 final AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
1510 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
1512 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1513 "label.successfully_loaded_file", new Object[]
1516 // TODO if we want this (e.g. to enable reload of the alignment from file),
1517 // we will need to add parameters to the stack.
1518 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1520 // alignFrame.setFileName(file, format);
1523 if (openInNewWindow)
1525 Desktop.addInternalFrame(newAlignFrame, title,
1526 AlignFrame.DEFAULT_WIDTH,
1527 AlignFrame.DEFAULT_HEIGHT);
1531 * Try to find mappings for at least one sequence.
1533 MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
1534 final StructureSelectionManager ssm = StructureSelectionManager
1535 .getStructureSelectionManager(Desktop.instance);
1536 if (mapped == MappingResult.Mapped)
1540 * Register the mappings (held on the protein alignment) with the
1541 * StructureSelectionManager (for mouseover linking).
1543 ssm.addMappings(protein.getCodonFrames());
1549 * No mapping possible - warn the user, but leave window open.
1551 final String msg = JvSwingUtils.wrapTooltip(true,
1552 MessageManager.getString("label.mapping_failed"));
1553 JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
1554 MessageManager.getString("label.no_mappings"),
1555 JOptionPane.WARNING_MESSAGE);
1560 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
1563 } catch (java.beans.PropertyVetoException ex)
1570 * Open in split pane. DNA sequence above, protein below.
1572 AlignFrame copyMe = new AlignFrame(thisAlignment,
1573 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
1574 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
1575 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
1577 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
1580 cdnaFrame.setVisible(true);
1581 proteinFrame.setVisible(true);
1582 String proteinShortName = StringUtils.getLastToken(
1583 proteinFrame.getTitle(), "/");
1584 String dnaShortName = StringUtils.getLastToken(cdnaFrame.getTitle(),
1586 String linkedTitle = MessageManager.formatMessage(
1587 "label.linked_view_title", dnaShortName, proteinShortName);
1588 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
1589 Desktop.addInternalFrame(splitFrame, linkedTitle,
1590 AlignFrame.DEFAULT_WIDTH,
1591 AlignFrame.DEFAULT_HEIGHT);
1594 * Set the frames to listen for each other's edit and sort commands.
1596 ssm.addCommandListener(cdnaFrame.getViewport());
1597 ssm.addCommandListener(proteinFrame.getViewport());
1600 * 'Coding complement' (dna/protein) views will mirror each others' edits,
1601 * selections, sorting etc as decided from time to time by the relevant
1604 proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());