+ /**
+ * Show a dialog with the option to open and link (cDNA <-> protein) as a new
+ * alignment, either as a standalone alignment or in a split frame. Returns
+ * true if the new alignment was opened, false if not, because the user
+ * declined the offer.
+ *
+ * @param al
+ * @param title
+ */
+ protected boolean openLinkedAlignment(AlignmentI al, String title)
+ {
+ String[] options = new String[]
+ { MessageManager.getString("action.no"),
+ MessageManager.getString("label.split_window"),
+ MessageManager.getString("label.new_window"), };
+ final String question = JvSwingUtils.wrapTooltip(true,
+ MessageManager.getString("label.open_split_window?"));
+ int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
+ MessageManager.getString("label.open_split_window"),
+ JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
+ options, options[0]);
+
+ if (response != 1 && response != 2)
+ {
+ return false;
+ }
+ final boolean openSplitPane = (response == 1);
+ final boolean openInNewWindow = (response == 2);
+
+ /*
+ * Identify protein and dna alignments. Make a copy of this one if opening
+ * in a new split pane.
+ */
+ AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
+ : getAlignment();
+ AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
+ final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
+
+ /*
+ * Map sequences. At least one should get mapped as we have already passed
+ * the test for 'mappability'. Any mappings made will be added to the
+ * protein alignment. Note creating dataset sequences on the new alignment
+ * is a pre-requisite for building mappings.
+ */
+ al.setDataset(null);
+ AlignmentUtils.mapProteinToCdna(protein, cdna);
+
+ /*
+ * Create the AlignFrame for the added alignment. Note this will include the
+ * cDNA consensus annotation if it is protein (because the alignment holds
+ * mappings to nucleotide)
+ */
+ AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ newAlignFrame.setTitle(title);
+ newAlignFrame.statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_loaded_file", new Object[]
+ { title }));
+
+ // TODO if we want this (e.g. to enable reload of the alignment from file),
+ // we will need to add parameters to the stack.
+ // if (!protocol.equals(AppletFormatAdapter.PASTE))
+ // {
+ // alignFrame.setFileName(file, format);
+ // }
+
+ if (openInNewWindow)
+ {
+ Desktop.addInternalFrame(newAlignFrame, title,
+ AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ try
+ {
+ newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
+ "SHOW_FULLSCREEN",
+ false));
+ } catch (java.beans.PropertyVetoException ex)
+ {
+ }
+
+ if (openSplitPane)
+ {
+ al.alignAs(thisAlignment);
+ protein = openSplitFrame(newAlignFrame, thisAlignment,
+ protein.getCodonFrames());
+ }
+
+ /*
+ * Register the mappings (held on the protein alignment) with the
+ * StructureSelectionManager (for mouseover linking).
+ */
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addMappings(protein.getCodonFrames());
+
+ return true;