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.commands.EditCommand;
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;
73 import java.util.List;
75 import java.util.Vector;
77 import javax.swing.JInternalFrame;
78 import javax.swing.JOptionPane;
79 import javax.swing.JSplitPane;
85 * @version $Revision: 1.141 $
87 public class AlignViewport extends AlignmentViewport implements
88 SelectionSource, VamsasSource, AlignViewportI, CommandListener
98 boolean showJVSuffix = true;
100 boolean showText = true;
102 boolean showColourText = false;
104 boolean showBoxes = true;
106 boolean wrapAlignment = false;
108 boolean renderGaps = true;
110 boolean showSequenceFeatures = false;
112 boolean showAnnotation = true;
114 SequenceAnnotationOrder sortAnnotationsBy = null;
120 boolean validCharWidth;
126 boolean seqNameItalics;
128 NJTree currentTree = null;
130 boolean scaleAboveWrapped = false;
132 boolean scaleLeftWrapped = true;
134 boolean scaleRightWrapped = true;
136 boolean showHiddenMarkers = true;
138 boolean cursorMode = false;
141 * Keys are the feature types which are currently visible. Note: Values are
144 Hashtable featuresDisplayed = null;
146 boolean antiAlias = false;
148 Rectangle explodedPosition;
152 boolean gatherViewsHere = false;
154 private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
156 private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
158 int thresholdTextColour = 0;
160 Color textColour = Color.black;
162 Color textColour2 = Color.white;
164 boolean rightAlignIds = false;
167 * Creates a new AlignViewport object.
172 public AlignViewport(AlignmentI al)
179 * Create a new AlignViewport object with a specific sequence set ID
183 * (may be null - but potential for ambiguous constructor exception)
185 public AlignViewport(AlignmentI al, String seqsetid)
187 this(al, seqsetid, null);
190 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
192 sequenceSetID = seqsetid;
194 // TODO remove these once 2.4.VAMSAS release finished
195 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
197 Cache.log.debug("Setting viewport's sequence set id : "
200 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
202 Cache.log.debug("Setting viewport's view id : " + viewId);
209 * Create a new AlignViewport with hidden regions
213 * @param hiddenColumns
216 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
219 if (hiddenColumns != null)
221 this.colSel = hiddenColumns;
222 if (hiddenColumns.getHiddenColumns() != null
223 && hiddenColumns.getHiddenColumns().size() > 0)
225 hasHiddenColumns = true;
229 hasHiddenColumns = false;
236 * New viewport with hidden columns and an existing sequence set id
239 * @param hiddenColumns
243 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
246 this(al, hiddenColumns, seqsetid, null);
250 * New viewport with hidden columns and an existing sequence set id and viewid
253 * @param hiddenColumns
259 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
260 String seqsetid, String viewid)
262 sequenceSetID = seqsetid;
264 // TODO remove these once 2.4.VAMSAS release finished
265 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
267 Cache.log.debug("Setting viewport's sequence set id : "
270 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
272 Cache.log.debug("Setting viewport's view id : " + viewId);
275 if (hiddenColumns != null)
277 this.colSel = hiddenColumns;
278 if (hiddenColumns.getHiddenColumns() != null
279 && hiddenColumns.getHiddenColumns().size() > 0)
281 hasHiddenColumns = true;
285 hasHiddenColumns = false;
294 this.endRes = alignment.getWidth() - 1;
296 this.endSeq = alignment.getHeight() - 1;
298 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
300 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
301 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
303 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
304 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
305 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
307 setPadGaps(Cache.getDefault("PAD_GAPS", true));
308 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
309 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
311 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
312 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
313 String fontSize = Cache.getDefault("FONT_SIZE", "10");
315 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
319 if (fontStyle.equals("bold"))
323 else if (fontStyle.equals("italic"))
328 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
331 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
333 // We must set conservation and consensus before setting colour,
334 // as Blosum and Clustal require this to be done
335 if (hconsensus == null && !isDataset)
337 if (!alignment.isNucleotide())
339 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
340 showQuality = Cache.getDefault("SHOW_QUALITY", true);
341 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
344 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
346 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
347 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
349 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
350 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
352 initAutoAnnotation();
353 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
355 globalColourScheme = ColourSchemeProperty.getColour(alignment,
356 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
358 if (globalColourScheme instanceof UserColourScheme)
360 globalColourScheme = UserDefinedColours.loadDefaultColours();
361 ((UserColourScheme) globalColourScheme).setThreshold(0,
362 getIgnoreGapsConsensus());
365 if (globalColourScheme != null)
367 globalColourScheme.setConsensus(hconsensus);
371 wrapAlignment = Cache.getDefault("WRAP_ALIGNMENT", false);
372 showUnconserved = Cache.getDefault("SHOW_UNCONSERVED", false);
373 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
374 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
375 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
376 Preferences.SORT_ANNOTATIONS,
377 SequenceAnnotationOrder.NONE.name()));
378 showAutocalculatedAbove = Cache.getDefault(
379 Preferences.SHOW_AUTOCALC_ABOVE, false);
386 * features are displayed if true
388 public void setShowSequenceFeatures(boolean b)
390 showSequenceFeatures = b;
393 public boolean getShowSequenceFeatures()
395 return showSequenceFeatures;
399 * centre columnar annotation labels in displayed alignment annotation TODO:
400 * add to jalviewXML and annotation display settings
402 boolean centreColumnLabels = false;
404 private boolean showdbrefs;
406 private boolean shownpfeats;
408 // --------END Structure Conservation
411 * get the consensus sequence as displayed under the PID consensus annotation
414 * @return consensus sequence as a new sequence object
416 public SequenceI getConsensusSeq()
418 if (consensus == null)
420 updateConsensus(null);
422 if (consensus == null)
426 StringBuffer seqs = new StringBuffer();
427 for (int i = 0; i < consensus.annotations.length; i++)
429 if (consensus.annotations[i] != null)
431 if (consensus.annotations[i].description.charAt(0) == '[')
433 seqs.append(consensus.annotations[i].description.charAt(1));
437 seqs.append(consensus.annotations[i].displayCharacter);
442 SequenceI sq = new Sequence("Consensus", seqs.toString());
443 sq.setDescription("Percentage Identity Consensus "
444 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
451 * @return DOCUMENT ME!
453 public int getStartRes()
461 * @return DOCUMENT ME!
463 public int getEndRes()
471 * @return DOCUMENT ME!
473 public int getStartSeq()
484 public void setStartRes(int res)
495 public void setStartSeq(int seq)
506 public void setEndRes(int res)
508 if (res > (alignment.getWidth() - 1))
510 // log.System.out.println(" Corrected res from " + res + " to maximum " +
511 // (alignment.getWidth()-1));
512 res = alignment.getWidth() - 1;
529 public void setEndSeq(int seq)
531 if (seq > alignment.getHeight())
533 seq = alignment.getHeight();
547 * @return DOCUMENT ME!
549 public int getEndSeq()
560 public void setFont(Font f)
564 Container c = new Container();
566 java.awt.FontMetrics fm = c.getFontMetrics(font);
567 setCharHeight(fm.getHeight());
568 setCharWidth(fm.charWidth('M'));
569 validCharWidth = true;
575 * @return DOCUMENT ME!
577 public Font getFont()
588 public void setCharWidth(int w)
596 * @return DOCUMENT ME!
598 public int getCharWidth()
609 public void setCharHeight(int h)
617 * @return DOCUMENT ME!
619 public int getCharHeight()
630 public void setWrappedWidth(int w)
632 this.wrappedWidth = w;
638 * @return DOCUMENT ME!
640 public int getWrappedWidth()
648 * @return DOCUMENT ME!
650 public AlignmentI getAlignment()
661 public void setAlignment(AlignmentI align)
663 if (alignment != null && alignment.getCodonFrames() != null)
665 StructureSelectionManager.getStructureSelectionManager(
666 Desktop.instance).removeMappings(alignment.getCodonFrames());
668 this.alignment = align;
669 if (alignment != null && alignment.getCodonFrames() != null)
671 StructureSelectionManager.getStructureSelectionManager(
672 Desktop.instance).addMappings(alignment.getCodonFrames());
682 public void setWrapAlignment(boolean state)
684 wrapAlignment = state;
693 public void setShowText(boolean state)
704 public void setRenderGaps(boolean state)
712 * @return DOCUMENT ME!
714 public boolean getColourText()
716 return showColourText;
725 public void setColourText(boolean state)
727 showColourText = state;
736 public void setShowBoxes(boolean state)
744 * @return DOCUMENT ME!
746 public boolean getWrapAlignment()
748 return wrapAlignment;
754 * @return DOCUMENT ME!
756 public boolean getShowText()
764 * @return DOCUMENT ME!
766 public boolean getShowBoxes()
774 * @return DOCUMENT ME!
776 public char getGapCharacter()
778 return getAlignment().getGapCharacter();
787 public void setGapCharacter(char gap)
789 if (getAlignment() != null)
791 getAlignment().setGapCharacter(gap);
798 * @return DOCUMENT ME!
800 public ColumnSelection getColumnSelection()
811 public void setCurrentTree(NJTree tree)
819 * @return DOCUMENT ME!
821 public NJTree getCurrentTree()
829 * @return DOCUMENT ME!
831 public boolean getShowJVSuffix()
842 public void setShowJVSuffix(boolean b)
850 * @return DOCUMENT ME!
852 public boolean getShowAnnotation()
854 return showAnnotation;
863 public void setShowAnnotation(boolean b)
871 * @return DOCUMENT ME!
873 public boolean getScaleAboveWrapped()
875 return scaleAboveWrapped;
881 * @return DOCUMENT ME!
883 public boolean getScaleLeftWrapped()
885 return scaleLeftWrapped;
891 * @return DOCUMENT ME!
893 public boolean getScaleRightWrapped()
895 return scaleRightWrapped;
904 public void setScaleAboveWrapped(boolean b)
906 scaleAboveWrapped = b;
915 public void setScaleLeftWrapped(boolean b)
917 scaleLeftWrapped = b;
926 public void setScaleRightWrapped(boolean b)
928 scaleRightWrapped = b;
931 public void setDataset(boolean b)
936 public boolean isDataset()
941 public boolean getShowHiddenMarkers()
943 return showHiddenMarkers;
946 public void setShowHiddenMarkers(boolean show)
948 showHiddenMarkers = show;
952 * returns the visible column regions of the alignment
954 * @param selectedRegionOnly
955 * true to just return the contigs intersecting with the selected
959 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
961 int[] viscontigs = null;
962 int start = 0, end = 0;
963 if (selectedRegionOnly && selectionGroup != null)
965 start = selectionGroup.getStartRes();
966 end = selectionGroup.getEndRes() + 1;
970 end = alignment.getWidth();
972 viscontigs = colSel.getVisibleContigs(start, end);
977 * get hash of undo and redo list for the alignment
979 * @return long[] { historyList.hashCode, redoList.hashCode };
981 public long[] getUndoRedoHash()
984 if (historyList == null || redoList == null)
990 { historyList.hashCode(), this.redoList.hashCode() };
994 * test if a particular set of hashcodes are different to the hashcodes for
995 * the undo and redo list.
998 * the stored set of hashcodes as returned by getUndoRedoHash
999 * @return true if the hashcodes differ (ie the alignment has been edited) or
1000 * the stored hashcode array differs in size
1002 public boolean isUndoRedoHashModified(long[] undoredo)
1004 if (undoredo == null)
1008 long[] cstate = getUndoRedoHash();
1009 if (cstate.length != undoredo.length)
1014 for (int i = 0; i < cstate.length; i++)
1016 if (cstate[i] != undoredo[i])
1024 public boolean getCentreColumnLabels()
1026 return centreColumnLabels;
1029 public void setCentreColumnLabels(boolean centrecolumnlabels)
1031 centreColumnLabels = centrecolumnlabels;
1035 * enable or disable the display of Database Cross References in the sequence
1038 public void setShowDbRefs(boolean show)
1045 * @return true if Database References are to be displayed on tooltips.
1047 public boolean isShowDbRefs()
1054 * @return true if Non-positional features are to be displayed on tooltips.
1056 public boolean isShowNpFeats()
1062 * enable or disable the display of Non-Positional sequence features in the
1063 * sequence ID tooltip
1067 public void setShowNpFeats(boolean show)
1074 * @return true if view has hidden rows
1076 public boolean hasHiddenRows()
1078 return hasHiddenRows;
1083 * @return true if view has hidden columns
1085 public boolean hasHiddenColumns()
1087 return hasHiddenColumns;
1091 * when set, view will scroll to show the highlighted position
1093 public boolean followHighlight = true;
1096 * @return true if view should scroll to show the highlighted region of a
1100 public boolean getFollowHighlight()
1102 return followHighlight;
1105 public boolean followSelection = true;
1108 * @return true if view selection should always follow the selections
1109 * broadcast by other selection sources
1111 public boolean getFollowSelection()
1113 return followSelection;
1116 boolean showSeqFeaturesHeight;
1118 public void sendSelection()
1120 jalview.structure.StructureSelectionManager
1121 .getStructureSelectionManager(Desktop.instance).sendSelection(
1122 new SequenceGroup(getSelectionGroup()),
1123 new ColumnSelection(getColumnSelection()), this);
1126 public void setShowSequenceFeaturesHeight(boolean selected)
1128 showSeqFeaturesHeight = selected;
1131 public boolean getShowSequenceFeaturesHeight()
1133 return showSeqFeaturesHeight;
1137 * return the alignPanel containing the given viewport. Use this to get the
1138 * components currently handling the given viewport.
1141 * @return null or an alignPanel guaranteed to have non-null alignFrame
1144 public AlignmentPanel getAlignPanel()
1146 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
1147 .getSequenceSetId());
1148 AlignmentPanel ap = null;
1149 for (int p = 0; aps != null && p < aps.length; p++)
1151 if (aps[p].av == this)
1159 public boolean getSortByTree()
1164 public void setSortByTree(boolean sort)
1170 * synthesize a column selection if none exists so it covers the given
1171 * selection group. if wholewidth is false, no column selection is made if the
1172 * selection group covers the whole alignment width.
1177 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
1181 && (sgs = sg.getStartRes()) >= 0
1182 && sg.getStartRes() <= (sge = sg.getEndRes())
1183 && (colSel == null || colSel.getSelected() == null || colSel
1184 .getSelected().size() == 0))
1186 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
1193 colSel = new ColumnSelection();
1195 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
1197 colSel.addElement(cspos);
1202 public StructureSelectionManager getStructureSelectionManager()
1204 return StructureSelectionManager
1205 .getStructureSelectionManager(Desktop.instance);
1211 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
1212 * sequence in the alignment holds a reference to it
1214 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
1216 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
1217 for (PDBEntry pdb : pdbEntries)
1219 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
1220 for (int i = 0; i < alignment.getHeight(); i++)
1222 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
1229 for (int p = 0; p < pdbs.size(); p++)
1231 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
1232 if (p1.getId().equals(pdb.getId()))
1234 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
1243 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
1245 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
1248 public boolean isNormaliseSequenceLogo()
1250 return normaliseSequenceLogo;
1253 public void setNormaliseSequenceLogo(boolean state)
1255 normaliseSequenceLogo = state;
1260 * @return true if alignment characters should be displayed
1262 public boolean isValidCharWidth()
1264 return validCharWidth;
1267 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
1269 private boolean showAutocalculatedAbove;
1271 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
1273 return calcIdParams.get(calcId);
1276 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
1277 boolean needsUpdate)
1279 calcIdParams.put(calcId, settings);
1280 // TODO: create a restart list to trigger any calculations that need to be
1281 // restarted after load
1282 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
1285 Cache.log.debug("trigger update for " + calcId);
1289 protected SequenceAnnotationOrder getSortAnnotationsBy()
1291 return sortAnnotationsBy;
1294 protected void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
1296 this.sortAnnotationsBy = sortAnnotationsBy;
1299 protected boolean isShowAutocalculatedAbove()
1301 return showAutocalculatedAbove;
1304 protected void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
1306 this.showAutocalculatedAbove = showAutocalculatedAbove;
1310 * Method called when another alignment's edit (or possibly other) command is
1311 * broadcast to here.
1313 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
1314 * 'unwind' the command on the source sequences (in simulation, not in fact),
1315 * and then for each edit in turn:
1317 * <li>compute the equivalent edit on the mapped sequences</li>
1318 * <li>apply the mapped edit</li>
1319 * <li>'apply' the source edit to the working copy of the source sequences</li>
1327 public void mirrorCommand(CommandI command, boolean undo,
1328 StructureSelectionManager ssm)
1331 * Only EditCommand is currently handled by listeners.
1333 if (!(command instanceof EditCommand))
1337 EditCommand edit = (EditCommand) command;
1339 List<SequenceI> seqs = getAlignment().getSequences();
1340 EditCommand mappedCommand = ssm.mapEditCommand(edit, undo, seqs,
1342 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
1343 mappedCommand.performEdit(0, views);
1344 getAlignPanel().alignmentChanged();
1348 public VamsasSource getVamsasSource()
1354 * Add one command to the command history list.
1358 public void addToHistoryList(CommandI command)
1360 if (this.historyList != null)
1362 this.historyList.push(command);
1363 broadcastCommand(command, false);
1367 protected void broadcastCommand(CommandI command, boolean undo)
1369 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
1373 * Add one command to the command redo list.
1377 public void addToRedoList(CommandI command)
1379 if (this.redoList != null)
1381 this.redoList.push(command);
1383 broadcastCommand(command, true);
1387 * Clear the command redo list.
1389 public void clearRedoList()
1391 if (this.redoList != null)
1393 this.redoList.clear();
1397 public void setHistoryList(Deque<CommandI> list)
1399 this.historyList = list;
1402 public Deque<CommandI> getHistoryList()
1404 return this.historyList;
1407 public void setRedoList(Deque<CommandI> list)
1409 this.redoList = list;
1412 public Deque<CommandI> getRedoList()
1414 return this.redoList;
1418 * Add the sequences from the given alignment to this viewport. Optionally,
1419 * may give the user the option to open a new frame or panel linking cDNA and
1425 public void addAlignment(AlignmentI al, String title)
1427 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
1429 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
1431 // TODO: create undo object for this JAL-1101
1434 * If one alignment is protein and one nucleotide, with at least one
1435 * sequence name in common, offer to open a linked alignment.
1437 if (getAlignment().isNucleotide() != al.isNucleotide())
1439 final Set<String> sequenceNames = getAlignment().getSequenceNames();
1440 sequenceNames.retainAll(al.getSequenceNames());
1441 if (!sequenceNames.isEmpty()) // at least one sequence name in both
1443 if (openLinkedAlignment(al, title))
1450 for (int i = 0; i < al.getHeight(); i++)
1452 getAlignment().addSequence(al.getSequenceAt(i));
1454 // TODO this call was done by SequenceFetcher but not FileLoader or
1455 // CutAndPasteTransfer. Is it needed?
1456 setEndSeq(getAlignment().getHeight());
1457 firePropertyChange("alignment", null, getAlignment().getSequences());
1461 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
1462 * alignment. Returns true if the new alignment was opened, false if not -
1463 * either because the user declined the offer, or because no mapping could be
1468 protected boolean openLinkedAlignment(AlignmentI al, String title)
1470 String[] options = new String[]
1471 { MessageManager.getString("action.no"),
1472 MessageManager.getString("label.split_window"),
1473 MessageManager.getString("label.new_window"), };
1474 final String question = JvSwingUtils.wrapTooltip(true,
1475 MessageManager.getString("label.open_linked_alignment?"));
1476 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
1477 MessageManager.getString("label.open_linked_alignment"),
1478 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
1479 options, options[0]);
1480 // int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
1482 // MessageManager.getString("label.open_linked_alignment"),
1483 // JOptionPane.YES_NO_OPTION,
1484 // JOptionPane.QUESTION_MESSAGE);
1486 if (response != 1 && response != 2)
1490 final boolean openSplitPane = (response == 1);
1491 final boolean openInNewWindow = (response == 2);
1494 * Create the AlignFrame first (which creates the new alignment's datasets),
1495 * before attempting sequence mapping.
1497 AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
1498 AlignFrame.DEFAULT_HEIGHT);
1500 final AlignmentI protein = al.isNucleotide() ? getAlignment() : al;
1501 final AlignmentI cdna = al.isNucleotide() ? al : getAlignment();
1503 alignFrame.statusBar.setText(MessageManager.formatMessage(
1504 "label.successfully_loaded_file", new Object[]
1507 // TODO if we want this (e.g. to enable reload of the alignment from file),
1508 // we will need to add parameters to the stack.
1509 // if (!protocol.equals(AppletFormatAdapter.PASTE))
1511 // alignFrame.setFileName(file, format);
1513 if (openInNewWindow)
1516 * open in new window
1518 Desktop.addInternalFrame(alignFrame, title, AlignFrame.DEFAULT_WIDTH,
1519 AlignFrame.DEFAULT_HEIGHT);
1523 * Try to find mappings for at least one sequence.
1525 MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
1526 if (mapped == MappingResult.Mapped)
1530 * Register the mappings (held on the protein alignment) with the
1531 * StructureSelectionManager (for mouseover linking).
1533 final StructureSelectionManager ssm = StructureSelectionManager
1534 .getStructureSelectionManager(Desktop.instance);
1535 ssm.addMappings(protein.getCodonFrames());
1538 * Set the cDNA to listen for edits on the protein.
1540 ssm.addCommandListener(al.isNucleotide() ? alignFrame.getViewport()
1547 * No mapping possible - warn the user, but leave window open.
1549 final String msg = JvSwingUtils.wrapTooltip(true,
1550 MessageManager.getString("label.mapping_failed"));
1551 JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
1552 MessageManager.getString("label.no_mappings"),
1553 JOptionPane.WARNING_MESSAGE);
1558 alignFrame.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
1560 } catch (java.beans.PropertyVetoException ex)
1567 * Open in split pane. Original sequence above, new one below.
1569 JInternalFrame splitFrame = new JInternalFrame();
1570 splitFrame.setSize(AlignFrame.DEFAULT_WIDTH,
1571 AlignFrame.DEFAULT_HEIGHT);
1572 // TODO not quite right to 'move' AlignPanel from 'this' to the split
1574 // TODO probably want linked editing set up here
1575 JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
1576 getAlignPanel(), alignFrame.alignPanel);
1577 splitPane.setDividerLocation(0.5d);
1578 splitFrame.setSize(AlignFrame.DEFAULT_WIDTH,
1579 AlignFrame.DEFAULT_HEIGHT);
1580 splitFrame.add(splitPane);
1581 Desktop.addInternalFrame(splitFrame, title, AlignFrame.DEFAULT_WIDTH,
1582 AlignFrame.DEFAULT_HEIGHT);