import java.awt.BorderLayout;
import java.awt.Component;
-import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.util.Set;
import java.util.Vector;
-import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JEditorPane;
import javax.swing.JInternalFrame;
-import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import jalview.datamodel.AlignmentOrder;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SeqCigar;
import jalview.datamodel.Sequence;
import jalview.schemes.TurnColourScheme;
import jalview.schemes.UserColourScheme;
import jalview.schemes.ZappoColourScheme;
+import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.jws1.Discoverer;
this(al, hiddenColumns, width, height, null);
}
+
/**
* Create alignment frame for al with hiddenColumns, a specific width and
* height, and specific sequenceId
init();
}
+ public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
+ ColumnSelection hiddenColumns, int width, int height)
+ {
+ setSize(width, height);
+
+ if (al.getDataset() == null)
+ {
+ al.setDataset(null);
+ }
+
+ viewport = new AlignViewport(al, hiddenColumns);
+
+ if (hiddenSeqs != null && hiddenSeqs.length > 0)
+ {
+ viewport.hideSequence(hiddenSeqs);
+ viewport.setHasHiddenRows(true);
+ }
+ alignPanel = new AlignmentPanel(this, viewport);
+ addAlignmentPanel(alignPanel, true);
+ init();
+ }
+
+
/**
* Make a new AlignFrame from existing alignmentPanels
*
*/
void init()
{
+ progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+
avc = new jalview.controller.AlignViewController(this, viewport,
alignPanel);
if (viewport.getAlignmentConservationAnnotation() == null)
final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
- ViewSelectionMenu vsel = new ViewSelectionMenu("Transfer colours from",
+ final String menuLabel = MessageManager
+ .getString("label.copy_format_from");
+ ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
new ViewSetProvider()
{
{
origview.clear();
origview.add(alignPanel);
- return Desktop.getAlignmentPanels(null);
+ // make an array of all alignment panels except for this one
+ List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
+ Arrays.asList(Desktop.getAlignmentPanels(null)));
+ aps.remove(AlignFrame.this.alignPanel);
+ return aps.toArray(new AlignmentPanel[aps.size()]);
}
}, selviews, new ItemListener()
{
{
if (origview.size() > 0)
{
+ final AlignmentPanel ap = origview.get(0);
+
+ /*
+ * Copy the ViewStyle of the selected panel to 'this one'.
+ * Don't change value of 'scaleProteinAsCdna' unless copying
+ * from a SplitFrame.
+ */
ViewStyleI vs = selviews.get(0).getAlignViewport()
.getViewStyle();
- origview.get(0).getAlignViewport().setViewStyle(vs);
- AlignViewportI complement = origview.get(0)
- .getAlignViewport().getCodingComplement();
- if (complement != null)
+ boolean fromSplitFrame = selviews.get(0)
+ .getAlignViewport().getCodingComplement() != null;
+ if (!fromSplitFrame)
+ {
+ vs.setScaleProteinAsCdna(ap.getAlignViewport()
+ .getViewStyle().isScaleProteinAsCdna());
+ }
+ ap.getAlignViewport().setViewStyle(vs);
+
+ /*
+ * Also rescale ViewStyle of SplitFrame complement if there is
+ * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
+ * the whole ViewStyle (allow cDNA protein to have different
+ * fonts)
+ */
+ AlignViewportI complement = ap.getAlignViewport()
+ .getCodingComplement();
+ if (complement != null && vs.isScaleProteinAsCdna())
{
AlignFrame af = Desktop.getAlignFrameFor(complement);
- if (complement.isNucleotide())
- {
- complement.setViewStyle(vs);
- vs.setCharWidth(vs.getCharWidth() / 3);
- }
- else
- {
- int rw = vs.getCharWidth();
- vs.setCharWidth(rw * 3);
- complement.setViewStyle(vs);
- vs.setCharWidth(rw);
- }
- af.alignPanel.updateLayout();
+ ((SplitFrame) af.getSplitViewContainer())
+ .adjustLayout();
af.setMenusForViewport();
}
- origview.get(0).updateLayout();
- origview.get(0).setSelected(true);
- origview.get(0).alignFrame.setMenusForViewport();
+
+ ap.updateLayout();
+ ap.setSelected(true);
+ ap.alignFrame.setMenusForViewport();
}
}
updateEditMenuBar();
}
- // methods for implementing IProgressIndicator
- // need to refactor to a reusable stub class
- Hashtable progressBars, progressBarHandlers;
+ private IProgressIndicator progressBar;
/*
* (non-Javadoc)
@Override
public void setProgressBar(String message, long id)
{
- if (progressBars == null)
- {
- progressBars = new Hashtable();
- progressBarHandlers = new Hashtable();
- }
-
- JPanel progressPanel;
- Long lId = new Long(id);
- GridLayout layout = (GridLayout) statusPanel.getLayout();
- if (progressBars.get(lId) != null)
- {
- progressPanel = (JPanel) progressBars.get(new Long(id));
- statusPanel.remove(progressPanel);
- progressBars.remove(lId);
- progressPanel = null;
- if (message != null)
- {
- statusBar.setText(message);
- }
- if (progressBarHandlers.contains(lId))
- {
- progressBarHandlers.remove(lId);
- }
- layout.setRows(layout.getRows() - 1);
- }
- else
- {
- progressPanel = new JPanel(new BorderLayout(10, 5));
-
- JProgressBar progressBar = new JProgressBar();
- progressBar.setIndeterminate(true);
-
- progressPanel.add(new JLabel(message), BorderLayout.WEST);
- progressPanel.add(progressBar, BorderLayout.CENTER);
-
- layout.setRows(layout.getRows() + 1);
- statusPanel.add(progressPanel);
-
- progressBars.put(lId, progressPanel);
- }
- // update GUI
- // setMenusForViewport();
- validate();
+ progressBar.setProgressBar(message, id);
}
@Override
public void registerHandler(final long id,
final IProgressIndicatorHandler handler)
{
- if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
- {
- throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
- }
- progressBarHandlers.put(new Long(id), handler);
- final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
- if (handler.canCancel())
- {
- JButton cancel = new JButton(
- MessageManager.getString("action.cancel"));
- final IProgressIndicator us = this;
- cancel.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- handler.cancelActivity(id);
- us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new Object[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
- }
- });
- progressPanel.add(cancel, BorderLayout.EAST);
- }
+ progressBar.registerHandler(id, handler);
}
/**
@Override
public boolean operationInProgress()
{
- if (progressBars != null && progressBars.size() > 0)
- {
- return true;
- }
- return false;
+ return progressBar.operationInProgress();
}
@Override
public void setStatus(String text)
{
statusBar.setText(text);
- };
+ }
/*
* Added so Castor Mapping file can obtain Jalview Version
.lastIndexOf(java.io.File.separatorChar) + 1);
}
- /*
- * First save any linked Chimera session.
- */
- Desktop.instance.saveChimeraSessions(file);
-
success = new Jalview2XML().saveAlignment(this, file, shortName);
statusBar.setText(MessageManager.formatMessage(
return false;
}
- String[] omitHidden = null;
-
- if (viewport.hasHiddenColumns())
- {
- int reply = JOptionPane
- .showInternalConfirmDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.alignment_contains_hidden_columns"),
- MessageManager
- .getString("action.save_omit_hidden_columns"),
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE);
-
- if (reply == JOptionPane.YES_OPTION)
- {
- omitHidden = viewport.getViewAsString(false);
- }
- }
- FormatAdapter f = new FormatAdapter();
+ ExportData exportData = getAlignmentForExport();
+ FormatAdapter f = new FormatAdapter(viewport);
String output = f.formatSequences(format,
- viewport.getAlignment(), // class cast exceptions will
+ exportData.getAlignment(), // class cast exceptions will
// occur in the distant future
- omitHidden, f.getCacheSuffixDefault(format),
+ exportData.getOmitHidden(), exportData.getStartEndPostions(),
+ f.getCacheSuffixDefault(format),
viewport.getColumnSelection());
if (output == null)
return success;
}
+
private void warningMessage(String warning, String title)
{
if (new jalview.util.Platform().isHeadless())
@Override
protected void outputText_actionPerformed(ActionEvent e)
{
+
+ ExportData exportData = getAlignmentForExport();
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ cap.setForInput(null);
+
+ try
+ {
+ cap.setText(new FormatAdapter(viewport).formatSequences(
+ e.getActionCommand(),
+ exportData.getAlignment(),
+ exportData.getOmitHidden(), exportData.getStartEndPostions(),
+ viewport.getColumnSelection()));
+ Desktop.addInternalFrame(cap, MessageManager.formatMessage(
+ "label.alignment_output_command", new Object[]
+ { e.getActionCommand() }), 600, 500);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
+ cap.dispose();
+ }
+
+ }
+
+ public ExportData getAlignmentForExport()
+ {
+ AlignmentI alignmentToExport = null;
String[] omitHidden = null;
+ int[] alignmentStartEnd = new int[2];
+ FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
+ viewport.setFeatureRenderer(fr);
+ HiddenSequences hiddenSeqs = viewport.getAlignment()
+ .getHiddenSequences();
- if (viewport.hasHiddenColumns())
+
+ alignmentToExport = viewport.getAlignment();
+ alignmentStartEnd = new int[]
+ { 0, alignmentToExport.getWidth() - 1 };
+
+ if (viewport.hasHiddenColumns() || hiddenSeqs.getSize() > 0)
{
int reply = JOptionPane
.showInternalConfirmDialog(
if (reply == JOptionPane.YES_OPTION)
{
+ // export only visible region
omitHidden = viewport.getViewAsString(false);
+ alignmentToExport = viewport.getAlignment();
+ alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
+ .getColumnSelection().getHiddenColumns());
+ viewport.setIncludeHiddenRegion(false);
+ }
+ else
+ {
+ // export all region including visible
+ alignmentToExport = hiddenSeqs.getFullAlignment();
+ viewport.setIncludeHiddenRegion(true);
}
}
- CutAndPasteTransfer cap = new CutAndPasteTransfer();
- cap.setForInput(null);
+ return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd);
+ }
- try
+ private static int[] getStartEnd(int[] aligmentStartEnd,
+ List<int[]> hiddenCols)
+ {
+ int startPos = aligmentStartEnd[0];
+ int endPos = aligmentStartEnd[1];
+
+ int[] lowestRange = new int[2];
+ int[] higestRange = new int[2];
+
+ for (int[] hiddenCol : hiddenCols)
{
- cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
- viewport.getAlignment(), omitHidden,
- viewport.getColumnSelection()));
- Desktop.addInternalFrame(cap, MessageManager.formatMessage(
- "label.alignment_output_command", new Object[]
- { e.getActionCommand() }), 600, 500);
- } catch (OutOfMemoryError oom)
+ // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
+
+ lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
+ higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
+ }
+ // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
+ // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
+
+ if (lowestRange[0] == 0 && lowestRange[1] == 0)
{
- new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
- cap.dispose();
+ startPos = aligmentStartEnd[0];
+ }
+ else
+ {
+ startPos = lowestRange[1] + 1;
+ }
+
+ if (higestRange[0] == 0 && higestRange[1] == 0)
+ {
+ endPos = aligmentStartEnd[1];
+ }
+ else
+ {
+ endPos = higestRange[0];
}
+ // System.out.println("Export range : " + minPos + " - " + maxPos);
+ return new int[]
+ { startPos, endPos };
+ }
+
+ public static void main(String[] args)
+ {
+ ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
+ hiddenCols.add(new int[]
+ { 0, 4 });
+ hiddenCols.add(new int[]
+ { 6, 9 });
+ hiddenCols.add(new int[]
+ { 11, 12 });
+ hiddenCols.add(new int[]
+ { 33, 33 });
+ hiddenCols.add(new int[]
+ { 45, 50 });
+
+ int[] x = getStartEnd(new int[]
+ { 0, 50 }, hiddenCols);
+ // System.out.println("Export range : " + x[0] + " - " + x[1]);
}
/**
@Override
public void bioJSMenuItem_actionPerformed(ActionEvent e)
{
- new BioJsHTMLOutput(alignPanel,
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel,
alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
+ bjs.exportJalviewAlignmentAsBioJsHtmlFile();
}
public void createImageMap(File file, String image)
{
}
String output = new FormatAdapter().formatSequences("Fasta", seqs,
- omitHidden);
+ omitHidden, null);
StringSelection ss = new StringSelection(output);
sprods[s].updatePDBIds();
}
Alignment al = new Alignment(sprods);
- Set<AlignedCodonFrame> cf = prods.getCodonFrames();
al.setDataset(ds);
+
+ /*
+ * Copy dna-to-protein mappings to new alignment
+ */
+ // TODO 1: no mappings are set up for EMBL product
+ // TODO 2: if they were, should add them to protein alignment, not
+ // dna
+ Set<AlignedCodonFrame> cf = prods.getCodonFrames();
for (AlignedCodonFrame acf : cf)
{
al.addCodonFrame(acf);
+ getTitle();
naf.setTitle(newtitle);
- // remove this flag once confirmed we want a split view
- boolean asSplitFrame = true;
+ // temporary flag until SplitFrame is released
+ boolean asSplitFrame = Cache.getDefault(
+ Preferences.ENABLE_SPLIT_FRAME, false);
if (asSplitFrame)
{
- final Alignment copyAlignment = new Alignment(new Alignment(
- AlignFrame.this.viewport.getSequenceSelection()));
+ /*
+ * Make a copy of this alignment (sharing the same dataset
+ * sequences). If we are DNA, drop introns and update mappings
+ */
+ AlignmentI copyAlignment = null;
+ final SequenceI[] sequenceSelection = AlignFrame.this.viewport
+ .getSequenceSelection();
+ if (dna)
+ {
+ copyAlignment = AlignmentUtils.makeExonAlignment(
+ sequenceSelection, cf);
+ al.getCodonFrames().clear();
+ al.getCodonFrames().addAll(cf);
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addMappings(cf);
+ }
+ else
+ {
+ copyAlignment = new Alignment(new Alignment(
+ sequenceSelection));
+ }
AlignFrame copyThis = new AlignFrame(copyAlignment,
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
copyThis.setTitle(AlignFrame.this.getTitle());
"label.translation_of_params", new Object[]
{ this.getTitle() });
af.setTitle(newTitle);
- final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
- viewport.openSplitFrame(af, new Alignment(seqs), al.getCodonFrames());
- // Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
+ {
+ final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
+ viewport.openSplitFrame(af, new Alignment(seqs),
+ al.getCodonFrames());
+ }
+ else
+ {
+ Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
+ DEFAULT_HEIGHT);
+ }
}
}
public void setShowSeqFeatures(boolean b)
{
- showSeqFeatures.setSelected(true);
- viewport.setShowSequenceFeatures(true);
+ showSeqFeatures.setSelected(b);
+ viewport.setShowSequenceFeatures(b);
}
/*
for (AlignmentAnnotation aa : alignPanel.getAlignment()
.getAlignmentAnnotation())
{
+ /*
+ * don't display non-positional annotations on an alignment
+ */
+ if (aa.annotations == null)
+ {
+ continue;
+ }
boolean apply = (aa.sequenceRef == null && forAlignment)
|| (aa.sequenceRef != null && forSequences);
if (apply)
sf.setComplementVisible(this, show);
}
}
+
+ public class ExportData
+ {
+ private AlignmentI alignment;
+
+ private String[] omitHidden;
+
+ private int[] startEnd;
+
+ public ExportData(AlignmentI align, String[] ommit, int[] startEnd)
+ {
+ this.alignment = align;
+ this.omitHidden = ommit;
+ this.startEnd = startEnd;
+ }
+
+ public AlignmentI getAlignment()
+ {
+ return alignment;
+ }
+
+ public void setAlignment(AlignmentI alignment)
+ {
+ this.alignment = alignment;
+ }
+
+ public String[] getOmitHidden()
+ {
+ return omitHidden;
+ }
+
+ public void setOmitHidden(String[] omitHidden)
+ {
+ this.omitHidden = omitHidden;
+ }
+
+ public int[] getStartEndPostions()
+ {
+ return startEnd;
+ }
+
+ public void setStartEndPostions(int[] startEnd)
+ {
+ this.startEnd = startEnd;
+ }
+ }
+
}
class PrintThread extends Thread