2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Softwarechang
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import java.awt.datatransfer.*;
27 import java.awt.dnd.*;
28 import java.awt.event.*;
29 import java.awt.print.*;
32 import jalview.analysis.*;
33 import jalview.commands.*;
34 import jalview.datamodel.*;
36 import jalview.jbgui.*;
37 import jalview.schemes.*;
46 public class AlignFrame
47 extends GAlignFrame implements DropTargetListener
50 public static final int DEFAULT_WIDTH = 700;
53 public static final int DEFAULT_HEIGHT = 500;
54 public AlignmentPanel alignPanel;
56 AlignViewport viewport;
58 Vector alignPanels = new Vector();
61 String currentFileFormat = null;
63 String fileName = null;
66 * Creates a new AlignFrame object.
68 * @param al DOCUMENT ME!
70 public AlignFrame(AlignmentI al, int width, int height)
72 this(al, null, width, height);
76 * new alignment window with hidden columns
77 * @param al AlignmentI
78 * @param hiddenColumns ColumnSelection or null
80 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
81 int width, int height)
83 this.setSize(width, height);
84 viewport = new AlignViewport(al, hiddenColumns);
86 alignPanel = new AlignmentPanel(this, viewport);
88 if (al.getDataset() == null)
93 addAlignmentPanel(alignPanel, true);
98 * Make a new AlignFrame from exisiting alignmentPanels
99 * @param ap AlignmentPanel
100 * @param av AlignViewport
102 public AlignFrame(AlignmentPanel ap)
106 addAlignmentPanel(ap, false);
112 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
114 if (viewport.conservation == null)
116 BLOSUM62Colour.setEnabled(false);
117 conservationMenuItem.setEnabled(false);
118 modifyConservation.setEnabled(false);
119 // PIDColour.setEnabled(false);
120 // abovePIDThreshold.setEnabled(false);
121 // modifyPID.setEnabled(false);
124 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
126 if (sortby.equals("Id"))
128 sortIDMenuItem_actionPerformed(null);
130 else if (sortby.equals("Pairwise Identity"))
132 sortPairwiseMenuItem_actionPerformed(null);
135 if (Desktop.desktop != null)
137 addServiceListeners();
138 setGUINucleotide(viewport.alignment.isNucleotide());
141 setMenusFromViewport(viewport);
143 if (viewport.wrapAlignment)
145 wrapMenuItem_actionPerformed(null);
148 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
150 this.overviewMenuItem_actionPerformed(null);
157 public void setFileName(String file, String format)
160 currentFileFormat = format;
161 reload.setEnabled(true);
164 void addKeyListener()
166 addKeyListener(new KeyAdapter()
168 public void keyPressed(KeyEvent evt)
170 if (viewport.cursorMode
171 && evt.getKeyCode() >= KeyEvent.VK_0
172 && evt.getKeyCode() <= KeyEvent.VK_9)
174 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
177 switch (evt.getKeyCode())
180 case 27: // escape key
181 deselectAllSequenceMenuItem_actionPerformed(null);
185 case KeyEvent.VK_DOWN:
186 if (viewport.cursorMode)
188 alignPanel.seqPanel.moveCursor(0, 1);
192 moveSelectedSequences(false);
197 if (viewport.cursorMode)
199 alignPanel.seqPanel.moveCursor(0, -1);
203 moveSelectedSequences(true);
207 case KeyEvent.VK_LEFT:
208 if (viewport.cursorMode)
210 alignPanel.seqPanel.moveCursor( -1, 0);
214 case KeyEvent.VK_RIGHT:
215 if (viewport.cursorMode)
217 alignPanel.seqPanel.moveCursor(1, 0);
221 case KeyEvent.VK_SPACE:
222 if (viewport.cursorMode)
224 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
230 case KeyEvent.VK_DELETE:
231 case KeyEvent.VK_BACK_SPACE:
232 if (!viewport.cursorMode)
234 cut_actionPerformed(null);
238 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
246 if (viewport.cursorMode)
248 alignPanel.seqPanel.setCursorRow();
252 if (viewport.cursorMode && !evt.isControlDown())
254 alignPanel.seqPanel.setCursorColumn();
258 if (viewport.cursorMode)
260 alignPanel.seqPanel.setCursorPosition();
264 case KeyEvent.VK_ENTER:
265 case KeyEvent.VK_COMMA:
266 if (viewport.cursorMode)
268 alignPanel.seqPanel.setCursorRowAndColumn();
273 if (viewport.cursorMode)
275 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
279 if (viewport.cursorMode)
281 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
286 viewport.cursorMode = !viewport.cursorMode;
287 statusBar.setText("Keyboard editing mode is " +
288 (viewport.cursorMode ? "on" : "off"));
289 if (viewport.cursorMode)
291 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
292 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
294 alignPanel.seqPanel.seqCanvas.repaint();
300 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
301 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
302 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
304 javax.help.HelpBroker hb = hs.createHelpBroker();
305 hb.setCurrentID("home");
306 hb.setDisplayed(true);
310 ex.printStackTrace();
316 boolean toggleSeqs = !evt.isControlDown();
317 boolean toggleCols = !evt.isShiftDown();
319 boolean hide = false;
321 SequenceGroup sg = viewport.getSelectionGroup();
324 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
326 hideSelSequences_actionPerformed(null);
329 else if (! (toggleCols &&
330 viewport.colSel.getSelected().size() > 0))
332 showAllSeqs_actionPerformed(null);
338 if (viewport.colSel.getSelected().size() > 0)
340 hideSelColumns_actionPerformed(null);
343 viewport.selectionGroup = sg;
348 showAllColumns_actionPerformed(null);
353 case KeyEvent.VK_PAGE_UP:
354 if (viewport.wrapAlignment)
356 alignPanel.scrollUp(true);
360 alignPanel.setScrollValues(viewport.startRes,
362 - viewport.endSeq + viewport.startSeq);
365 case KeyEvent.VK_PAGE_DOWN:
366 if (viewport.wrapAlignment)
368 alignPanel.scrollUp(false);
372 alignPanel.setScrollValues(viewport.startRes,
374 + viewport.endSeq - viewport.startSeq);
382 public void addAlignmentPanel(final AlignmentPanel ap,
385 ap.alignFrame = this;
387 alignPanels.addElement(ap);
389 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
391 int aSize = alignPanels.size();
393 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
395 if (aSize == 1 && ap.av.viewName == null)
397 this.getContentPane().add(ap, BorderLayout.CENTER);
403 setInitialTabVisible();
406 expandViews.setEnabled(true);
407 gatherViews.setEnabled(true);
408 tabbedPane.addTab(ap.av.viewName, ap);
410 ap.setVisible(false);
417 ap.av.alignment.padGaps();
419 ap.av.updateConservation(ap);
420 ap.av.updateConsensus(ap);
424 public void setInitialTabVisible()
426 expandViews.setEnabled(true);
427 gatherViews.setEnabled(true);
428 tabbedPane.setVisible(true);
429 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
430 tabbedPane.addTab(first.av.viewName, first);
431 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
434 public AlignViewport getViewport()
439 /* Set up intrinsic listeners for dynamically generated GUI bits. */
440 private void addServiceListeners()
442 final java.beans.PropertyChangeListener thisListener;
443 // Do this once to get current state
444 BuildWebServiceMenu();
445 Desktop.discoverer.addPropertyChangeListener(
446 thisListener = new java.beans.PropertyChangeListener()
448 public void propertyChange(PropertyChangeEvent evt)
450 // System.out.println("Discoverer property change.");
451 if (evt.getPropertyName().equals("services"))
453 // System.out.println("Rebuilding web service menu");
454 BuildWebServiceMenu();
459 addInternalFrameListener(new javax.swing.event.
460 InternalFrameAdapter()
462 public void internalFrameClosed(
463 javax.swing.event.InternalFrameEvent evt)
465 // System.out.println("deregistering discoverer listener");
466 Desktop.discoverer.removePropertyChangeListener(thisListener);
467 closeMenuItem_actionPerformed(true);
473 public void setGUINucleotide(boolean nucleotide)
475 showTranslation.setVisible(nucleotide);
476 conservationMenuItem.setEnabled(!nucleotide);
477 modifyConservation.setEnabled(!nucleotide);
479 //Remember AlignFrame always starts as protein
482 calculateMenu.remove(calculateMenu.getItemCount() - 2);
487 * Need to call this method when tabs are selected for multiple views,
488 * or when loading from Jalview2XML.java
489 * @param av AlignViewport
491 void setMenusFromViewport(AlignViewport av)
493 padGapsMenuitem.setSelected(av.padGaps);
494 colourTextMenuItem.setSelected(av.showColourText);
495 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
496 conservationMenuItem.setSelected(av.getConservationSelected());
497 seqLimits.setSelected(av.getShowJVSuffix());
498 idRightAlign.setSelected(av.rightAlignIds);
499 renderGapsMenuItem.setSelected(av.renderGaps);
500 wrapMenuItem.setSelected(av.wrapAlignment);
501 scaleAbove.setVisible(av.wrapAlignment);
502 scaleLeft.setVisible(av.wrapAlignment);
503 scaleRight.setVisible(av.wrapAlignment);
504 annotationPanelMenuItem.setState(av.showAnnotation);
505 viewBoxesMenuItem.setSelected(av.showBoxes);
506 viewTextMenuItem.setSelected(av.showText);
508 setColourSelected(ColourSchemeProperty.
509 getColourName(av.getGlobalColourScheme()));
511 showSeqFeatures.setSelected(av.showSequenceFeatures);
512 hiddenMarkers.setState(av.showHiddenMarkers);
513 applyToAllGroups.setState(av.colourAppliesToAllGroups);
518 Hashtable progressBars;
519 public void setProgressBar(String message, long id)
521 if (progressBars == null)
523 progressBars = new Hashtable();
526 JPanel progressPanel;
527 GridLayout layout = (GridLayout) statusPanel.getLayout();
528 if (progressBars.get(new Long(id)) != null)
530 progressPanel = (JPanel) progressBars.get(new Long(id));
531 statusPanel.remove(progressPanel);
532 progressBars.remove(progressPanel);
533 progressPanel = null;
536 statusBar.setText(message);
539 layout.setRows(layout.getRows() - 1);
543 progressPanel = new JPanel(new BorderLayout(10, 5));
545 JProgressBar progressBar = new JProgressBar();
546 progressBar.setIndeterminate(true);
548 progressPanel.add(new JLabel(message), BorderLayout.WEST);
549 progressPanel.add(progressBar, BorderLayout.CENTER);
551 layout.setRows(layout.getRows() + 1);
552 statusPanel.add(progressPanel);
554 progressBars.put(new Long(id), progressPanel);
561 Added so Castor Mapping file can obtain Jalview Version
563 public String getVersion()
565 return jalview.bin.Cache.getProperty("VERSION");
568 public FeatureRenderer getFeatureRenderer()
570 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
573 public void fetchSequence_actionPerformed(ActionEvent e)
575 new SequenceFetcher(this);
578 public void addFromFile_actionPerformed(ActionEvent e)
580 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
583 public void reload_actionPerformed(ActionEvent e)
585 if (fileName != null)
587 if (currentFileFormat.equals("Jalview"))
589 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
590 for (int i = 0; i < frames.length; i++)
592 if (frames[i] instanceof AlignFrame
594 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
598 frames[i].setSelected(true);
599 Desktop.instance.closeAssociatedWindows();
601 catch (java.beans.PropertyVetoException ex)
606 Desktop.instance.closeAssociatedWindows();
611 Rectangle bounds = this.getBounds();
613 FileLoader loader = new FileLoader();
614 String protocol = fileName.startsWith("http:") ? "URL" : "File";
615 AlignFrame newframe =
616 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
618 newframe.setBounds(bounds);
620 this.closeMenuItem_actionPerformed(true);
625 public void addFromText_actionPerformed(ActionEvent e)
627 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
630 public void addFromURL_actionPerformed(ActionEvent e)
632 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
635 public void save_actionPerformed(ActionEvent e)
638 || currentFileFormat == null
639 || fileName.startsWith("http")
642 saveAs_actionPerformed(null);
646 saveAlignment(fileName, currentFileFormat);
653 * @param e DOCUMENT ME!
655 public void saveAs_actionPerformed(ActionEvent e)
657 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
658 getProperty("LAST_DIRECTORY"),
660 {"fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar"},
662 {"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"},
666 chooser.setFileView(new JalviewFileView());
667 chooser.setDialogTitle("Save Alignment to file");
668 chooser.setToolTipText("Save");
670 int value = chooser.showSaveDialog(this);
672 if (value == JalviewFileChooser.APPROVE_OPTION)
674 currentFileFormat = chooser.getSelectedFormat();
675 if (currentFileFormat == null)
677 JOptionPane.showInternalMessageDialog(Desktop.desktop,
678 "You must select a file format before saving!",
679 "File format not specified",
680 JOptionPane.WARNING_MESSAGE);
681 value = chooser.showSaveDialog(this);
685 fileName = chooser.getSelectedFile().getPath();
687 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
690 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
692 saveAlignment(fileName, currentFileFormat);
696 public boolean saveAlignment(String file, String format)
698 boolean success = true;
700 if (format.equalsIgnoreCase("Jalview"))
702 String shortName = title;
704 if (shortName.indexOf(java.io.File.separatorChar) > -1)
706 shortName = shortName.substring(shortName.lastIndexOf(
707 java.io.File.separatorChar) + 1);
710 success = new Jalview2XML().SaveAlignment(this, file, shortName);
712 statusBar.setText("Successfully saved to file: "
714 + format + " format.");
720 String[] omitHidden = null;
722 if (viewport.hasHiddenColumns)
724 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
725 "The Alignment contains hidden columns."
726 + "\nDo you want to save only the visible alignment?",
727 "Save / Omit Hidden Columns",
728 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
730 if (reply == JOptionPane.YES_OPTION)
732 omitHidden = viewport.getViewAsString(false);
736 String output = new FormatAdapter().formatSequences(
738 viewport.alignment.getSequencesArray(),
749 java.io.PrintWriter out = new java.io.PrintWriter(
750 new java.io.FileWriter(file));
755 statusBar.setText("Successfully saved to file: "
757 + format + " format.");
762 ex.printStackTrace();
769 JOptionPane.showInternalMessageDialog(
770 this, "Couldn't save file: " + fileName,
772 JOptionPane.WARNING_MESSAGE);
781 * @param e DOCUMENT ME!
783 protected void outputText_actionPerformed(ActionEvent e)
785 String[] omitHidden = null;
787 if (viewport.hasHiddenColumns)
789 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
790 "The Alignment contains hidden columns."
791 + "\nDo you want to output only the visible alignment?",
792 "Save / Omit Hidden Columns",
793 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
795 if (reply == JOptionPane.YES_OPTION)
797 omitHidden = viewport.getViewAsString(false);
801 CutAndPasteTransfer cap = new CutAndPasteTransfer();
802 cap.setForInput(null);
803 Desktop.addInternalFrame(cap,
804 "Alignment output - " + e.getActionCommand(), 600,
807 cap.setText(new FormatAdapter().formatSequences(
808 e.getActionCommand(),
809 viewport.alignment.getSequencesArray(),
816 * @param e DOCUMENT ME!
818 protected void htmlMenuItem_actionPerformed(ActionEvent e)
820 new HTMLOutput(viewport,
821 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
822 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
825 public void createImageMap(File file, String image)
827 alignPanel.makePNGImageMap(file, image);
833 * @param e DOCUMENT ME!
835 public void createPNG(File f)
837 alignPanel.makePNG(f);
843 * @param e DOCUMENT ME!
845 public void createEPS(File f)
847 alignPanel.makeEPS(f);
850 public void pageSetup_actionPerformed(ActionEvent e)
852 PrinterJob printJob = PrinterJob.getPrinterJob();
853 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
859 * @param e DOCUMENT ME!
861 public void printMenuItem_actionPerformed(ActionEvent e)
863 //Putting in a thread avoids Swing painting problems
864 PrintThread thread = new PrintThread(alignPanel);
868 public void exportFeatures_actionPerformed(ActionEvent e)
870 new AnnotationExporter().exportFeatures(alignPanel);
873 public void exportAnnotations_actionPerformed(ActionEvent e)
875 new AnnotationExporter().exportAnnotations(
877 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
878 viewport.alignment.getGroups()
882 public void associatedData_actionPerformed(ActionEvent e)
884 // Pick the tree file
885 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
888 chooser.setFileView(new JalviewFileView());
889 chooser.setDialogTitle("Load Jalview Annotations or Features File");
890 chooser.setToolTipText("Load Jalview Annotations / Features file");
892 int value = chooser.showOpenDialog(null);
894 if (value == JalviewFileChooser.APPROVE_OPTION)
896 String choice = chooser.getSelectedFile().getPath();
897 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
898 loadJalviewDataFile(choice);
906 * @param e DOCUMENT ME!
908 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
910 if (alignPanels != null && alignPanels.size() < 2)
917 if (alignPanels != null)
921 for (int i = 0; i < alignPanels.size(); i++)
923 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
924 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
925 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
926 PaintRefresher.RemoveComponent(ap);
931 int index = tabbedPane.getSelectedIndex();
933 alignPanels.removeElement(alignPanel);
934 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
935 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
936 PaintRefresher.RemoveComponent(alignPanel);
940 tabbedPane.removeTabAt(index);
941 tabbedPane.validate();
943 if (index == tabbedPane.getTabCount())
948 this.tabSelectionChanged(index);
954 this.setClosed(true);
959 ex.printStackTrace();
966 void updateEditMenuBar()
969 if (viewport.historyList.size() > 0)
971 undoMenuItem.setEnabled(true);
972 CommandI command = (CommandI) viewport.historyList.peek();
973 undoMenuItem.setText("Undo " + command.getDescription());
977 undoMenuItem.setEnabled(false);
978 undoMenuItem.setText("Undo");
981 if (viewport.redoList.size() > 0)
983 redoMenuItem.setEnabled(true);
985 CommandI command = (CommandI) viewport.redoList.peek();
986 redoMenuItem.setText("Redo " + command.getDescription());
990 redoMenuItem.setEnabled(false);
991 redoMenuItem.setText("Redo");
995 public void addHistoryItem(CommandI command)
997 if (command.getSize() > 0)
999 viewport.historyList.push(command);
1000 viewport.redoList.clear();
1001 updateEditMenuBar();
1002 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1009 * @param e DOCUMENT ME!
1011 protected void undoMenuItem_actionPerformed(ActionEvent e)
1013 CommandI command = (CommandI) viewport.historyList.pop();
1014 viewport.redoList.push(command);
1015 command.undoCommand();
1017 AlignViewport originalSource = getOriginatingSource(command);
1018 updateEditMenuBar();
1020 if (originalSource != null)
1022 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1023 originalSource.firePropertyChange("alignment",
1025 originalSource.alignment.getSequences());
1032 * @param e DOCUMENT ME!
1034 protected void redoMenuItem_actionPerformed(ActionEvent e)
1036 if (viewport.redoList.size() < 1)
1041 CommandI command = (CommandI) viewport.redoList.pop();
1042 viewport.historyList.push(command);
1043 command.doCommand();
1045 AlignViewport originalSource = getOriginatingSource(command);
1046 updateEditMenuBar();
1048 if (originalSource != null)
1050 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1051 originalSource.firePropertyChange("alignment",
1053 originalSource.alignment.getSequences());
1057 AlignViewport getOriginatingSource(CommandI command)
1059 AlignViewport originalSource = null;
1060 //For sequence removal and addition, we need to fire
1061 //the property change event FROM the viewport where the
1062 //original alignment was altered
1063 AlignmentI al = null;
1064 if (command instanceof EditCommand)
1066 EditCommand editCommand = (EditCommand) command;
1067 al = editCommand.getAlignment();
1068 Vector comps = (Vector) PaintRefresher.components
1069 .get(viewport.getSequenceSetId());
1071 for (int i = 0; i < comps.size(); i++)
1073 if (comps.elementAt(i) instanceof AlignmentPanel)
1075 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1077 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1084 if (originalSource == null)
1086 //The original view is closed, we must validate
1087 //the current view against the closed view first
1090 PaintRefresher.validateSequences(al, viewport.alignment);
1093 originalSource = viewport;
1096 return originalSource;
1102 * @param up DOCUMENT ME!
1104 public void moveSelectedSequences(boolean up)
1106 SequenceGroup sg = viewport.getSelectionGroup();
1115 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1117 SequenceI seq = viewport.alignment.getSequenceAt(i);
1119 if (!sg.getSequences(null).contains(seq))
1124 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1126 if (sg.getSequences(null).contains(temp))
1131 viewport.alignment.getSequences().setElementAt(temp, i);
1132 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1137 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1139 SequenceI seq = viewport.alignment.getSequenceAt(i);
1141 if (!sg.getSequences(null).contains(seq))
1146 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1148 if (sg.getSequences(null).contains(temp))
1153 viewport.alignment.getSequences().setElementAt(temp, i);
1154 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1158 alignPanel.repaint();
1164 * @param e DOCUMENT ME!
1166 protected void copy_actionPerformed(ActionEvent e)
1169 if (viewport.getSelectionGroup() == null)
1174 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1175 String[] omitHidden = null;
1177 if (viewport.hasHiddenColumns)
1179 omitHidden = viewport.getViewAsString(true);
1182 String output = new FormatAdapter().formatSequences(
1187 StringSelection ss = new StringSelection(output);
1191 jalview.gui.Desktop.internalCopy = true;
1192 //Its really worth setting the clipboard contents
1193 //to empty before setting the large StringSelection!!
1194 Toolkit.getDefaultToolkit().getSystemClipboard()
1195 .setContents(new StringSelection(""), null);
1197 Toolkit.getDefaultToolkit().getSystemClipboard()
1198 .setContents(ss, Desktop.instance);
1200 catch (OutOfMemoryError er)
1202 er.printStackTrace();
1203 javax.swing.SwingUtilities.invokeLater(new Runnable()
1207 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1208 "Out of memory copying region!!"
1210 "\nSee help files for increasing Java Virtual Machine memory."
1212 javax.swing.JOptionPane.WARNING_MESSAGE);
1219 Vector hiddenColumns = null;
1220 if (viewport.hasHiddenColumns)
1222 hiddenColumns = new Vector();
1223 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1224 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1227 int[] region = (int[])
1228 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1230 hiddenColumns.addElement(new int[]
1231 {region[0] - hiddenOffset,
1232 region[1] - hiddenOffset});
1236 Desktop.jalviewClipboard = new Object[]
1239 viewport.alignment.getDataset(),
1241 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1247 * @param e DOCUMENT ME!
1249 protected void pasteNew_actionPerformed(ActionEvent e)
1257 * @param e DOCUMENT ME!
1259 protected void pasteThis_actionPerformed(ActionEvent e)
1267 * @param newAlignment DOCUMENT ME!
1269 void paste(boolean newAlignment)
1273 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1274 Transferable contents = c.getContents(this);
1276 if (contents == null)
1284 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1285 if (str.length() < 1)
1290 format = new IdentifyFile().Identify(str, "Paste");
1293 catch (OutOfMemoryError er)
1295 er.printStackTrace();
1296 javax.swing.SwingUtilities.invokeLater(new Runnable()
1300 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1301 "Out of memory pasting sequences!!"
1303 "\nSee help files for increasing Java Virtual Machine memory."
1305 javax.swing.JOptionPane.WARNING_MESSAGE);
1312 SequenceI[] sequences;
1314 if (Desktop.jalviewClipboard != null)
1316 // The clipboard was filled from within Jalview, we must use the sequences
1317 // And dataset from the copied alignment
1318 sequences = (SequenceI[]) Desktop.jalviewClipboard[0];
1322 sequences = new FormatAdapter().readFile(str, "Paste", format).
1323 getSequencesArray();
1326 AlignmentI alignment = null;
1330 alignment = new Alignment(sequences);
1332 if (Desktop.jalviewClipboard != null)
1334 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1338 alignment.setDataset(null);
1343 alignment = viewport.getAlignment();
1346 SequenceI[] newseqs = new SequenceI[sequences.length];
1347 for (int i = 0; i < sequences.length; i++)
1349 newseqs[i] = new Sequence(sequences[i].getName(),
1350 sequences[i].getSequence(),
1351 sequences[i].getStart(),
1352 sequences[i].getEnd());
1354 alignment.addSequence(newseqs[i]);
1360 addHistoryItem(new EditCommand(
1365 alignment.getWidth(),
1369 viewport.setEndSeq(alignment.getHeight());
1370 alignment.getWidth();
1371 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1374 // Add any annotations attached to sequences
1375 for (int i = 0; i < sequences.length; i++)
1377 if (sequences[i].getAnnotation() != null)
1379 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1381 AlignmentAnnotation newAnnot =
1382 new AlignmentAnnotation(
1383 sequences[i].getAnnotation()[a].label,
1384 sequences[i].getAnnotation()[a].description,
1385 sequences[i].getAnnotation()[a].annotations,
1386 sequences[i].getAnnotation()[a].graphMin,
1387 sequences[i].getAnnotation()[a].graphMax,
1388 sequences[i].getAnnotation()[a].graph);
1390 sequences[i].getAnnotation()[a] = newAnnot;
1391 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1393 newAnnot.sequenceRef = sequences[i];
1394 newAnnot.adjustForAlignment();
1395 alignment.addAnnotation(newAnnot);
1396 alignment.setAnnotationIndex(newAnnot, a);
1399 alignPanel.annotationPanel.adjustPanelHeight();
1405 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1406 String newtitle = new String("Copied sequences");
1408 if (Desktop.jalviewClipboard != null && Desktop.jalviewClipboard[2] != null)
1410 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1411 for (int i = 0; i < hc.size(); i++)
1413 int[] region = (int[]) hc.elementAt(i);
1414 af.viewport.hideColumns(region[0], region[1]);
1418 //>>>This is a fix for the moment, until a better solution is found!!<<<
1419 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1420 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1422 if (title.startsWith("Copied sequences"))
1428 newtitle = newtitle.concat("- from " + title);
1431 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1437 catch (Exception ex)
1439 ex.printStackTrace();
1440 System.out.println("Exception whilst pasting: " + ex);
1441 // could be anything being pasted in here
1449 * @param e DOCUMENT ME!
1451 protected void cut_actionPerformed(ActionEvent e)
1453 copy_actionPerformed(null);
1454 delete_actionPerformed(null);
1460 * @param e DOCUMENT ME!
1462 protected void delete_actionPerformed(ActionEvent evt)
1465 SequenceGroup sg = viewport.getSelectionGroup();
1471 Vector seqs = new Vector();
1473 for (int i = 0; i < sg.getSize(); i++)
1475 seq = sg.getSequenceAt(i);
1476 seqs.addElement(seq);
1479 // If the cut affects all sequences, remove highlighted columns
1480 if (sg.getSize() == viewport.alignment.getHeight())
1482 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1483 sg.getEndRes() + 1);
1486 SequenceI[] cut = new SequenceI[seqs.size()];
1487 for (int i = 0; i < seqs.size(); i++)
1489 cut[i] = (SequenceI) seqs.elementAt(i);
1495 addHistoryItem(new EditCommand("Cut Sequences",
1499 sg.getEndRes() - sg.getStartRes() + 1,
1500 viewport.alignment));
1502 viewport.setSelectionGroup(null);
1503 viewport.alignment.deleteGroup(sg);
1505 viewport.firePropertyChange("alignment", null,
1506 viewport.getAlignment().getSequences());
1508 if (viewport.getAlignment().getHeight() < 1)
1512 this.setClosed(true);
1514 catch (Exception ex)
1523 * @param e DOCUMENT ME!
1525 protected void deleteGroups_actionPerformed(ActionEvent e)
1527 viewport.alignment.deleteAllGroups();
1528 viewport.sequenceColours = null;
1529 viewport.setSelectionGroup(null);
1530 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1531 alignPanel.repaint();
1537 * @param e DOCUMENT ME!
1539 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1541 SequenceGroup sg = new SequenceGroup();
1543 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1546 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1549 sg.setEndRes(viewport.alignment.getWidth() - 1);
1550 viewport.setSelectionGroup(sg);
1551 alignPanel.repaint();
1552 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1558 * @param e DOCUMENT ME!
1560 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1562 if (viewport.cursorMode)
1564 alignPanel.seqPanel.keyboardNo1 = null;
1565 alignPanel.seqPanel.keyboardNo2 = null;
1567 viewport.setSelectionGroup(null);
1568 viewport.getColumnSelection().clear();
1569 viewport.setSelectionGroup(null);
1570 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1571 alignPanel.idPanel.idCanvas.searchResults = null;
1572 alignPanel.repaint();
1573 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1579 * @param e DOCUMENT ME!
1581 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1583 SequenceGroup sg = viewport.getSelectionGroup();
1587 selectAllSequenceMenuItem_actionPerformed(null);
1592 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1595 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1598 alignPanel.repaint();
1600 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1603 public void invertColSel_actionPerformed(ActionEvent e)
1605 viewport.invertColumnSelection();
1606 alignPanel.repaint();
1612 * @param e DOCUMENT ME!
1614 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1616 trimAlignment(true);
1622 * @param e DOCUMENT ME!
1624 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1626 trimAlignment(false);
1629 void trimAlignment(boolean trimLeft)
1631 ColumnSelection colSel = viewport.getColumnSelection();
1634 if (colSel.size() > 0)
1638 column = colSel.getMin();
1642 column = colSel.getMax();
1646 if (viewport.getSelectionGroup() != null)
1648 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1649 hiddenRepSequences);
1653 seqs = viewport.alignment.getSequencesArray();
1656 TrimRegionCommand trimRegion;
1659 trimRegion = new TrimRegionCommand("Remove Left",
1660 TrimRegionCommand.TRIM_LEFT,
1665 viewport.selectionGroup);
1666 viewport.setStartRes(0);
1670 trimRegion = new TrimRegionCommand("Remove Right",
1671 TrimRegionCommand.TRIM_RIGHT,
1676 viewport.selectionGroup);
1679 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
1681 addHistoryItem(trimRegion);
1683 Vector groups = viewport.alignment.getGroups();
1685 for (int i = 0; i < groups.size(); i++)
1687 SequenceGroup sg = (SequenceGroup) groups.get(i);
1689 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1690 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1692 viewport.alignment.deleteGroup(sg);
1696 viewport.firePropertyChange("alignment", null,
1697 viewport.getAlignment().getSequences());
1704 * @param e DOCUMENT ME!
1706 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1708 int start = 0, end = viewport.alignment.getWidth() - 1;
1711 if (viewport.getSelectionGroup() != null)
1713 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1714 hiddenRepSequences);
1715 start = viewport.getSelectionGroup().getStartRes();
1716 end = viewport.getSelectionGroup().getEndRes();
1720 seqs = viewport.alignment.getSequencesArray();
1723 RemoveGapColCommand removeGapCols =
1724 new RemoveGapColCommand("Remove Gapped Columns",
1727 viewport.alignment);
1729 addHistoryItem(removeGapCols);
1731 statusBar.setText("Removed " + removeGapCols.getSize() + " empty columns.");
1733 //This is to maintain viewport position on first residue
1735 SequenceI seq = viewport.alignment.getSequenceAt(0);
1736 int startRes = seq.findPosition(viewport.startRes);
1737 // ShiftList shifts;
1738 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1739 // edit.alColumnChanges=shifts.getInverse();
1740 // if (viewport.hasHiddenColumns)
1741 // viewport.getColumnSelection().compensateForEdits(shifts);
1742 viewport.setStartRes(seq.findIndex(startRes) - 1);
1743 viewport.firePropertyChange("alignment", null,
1744 viewport.getAlignment().getSequences());
1751 * @param e DOCUMENT ME!
1753 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1755 int start = 0, end = viewport.alignment.getWidth() - 1;
1758 if (viewport.getSelectionGroup() != null)
1760 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1761 hiddenRepSequences);
1762 start = viewport.getSelectionGroup().getStartRes();
1763 end = viewport.getSelectionGroup().getEndRes();
1767 seqs = viewport.alignment.getSequencesArray();
1770 //This is to maintain viewport position on first residue
1772 SequenceI seq = viewport.alignment.getSequenceAt(0);
1773 int startRes = seq.findPosition(viewport.startRes);
1775 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1778 viewport.alignment));
1780 viewport.setStartRes(seq.findIndex(startRes) - 1);
1782 viewport.firePropertyChange("alignment", null,
1783 viewport.getAlignment().getSequences());
1790 * @param e DOCUMENT ME!
1792 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1794 viewport.padGaps = padGapsMenuitem.isSelected();
1796 viewport.firePropertyChange("alignment",
1798 viewport.getAlignment().getSequences());
1804 * @param e DOCUMENT ME!
1806 public void findMenuItem_actionPerformed(ActionEvent e)
1811 public void newView_actionPerformed(ActionEvent e)
1813 AlignmentPanel newap =
1814 new Jalview2XML().copyAlignPanel(alignPanel, true);
1816 if (viewport.viewName == null)
1818 viewport.viewName = "Original";
1821 newap.av.historyList = viewport.historyList;
1822 newap.av.redoList = viewport.redoList;
1824 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1825 String newViewName = "View " + index;
1827 Vector comps = (Vector) PaintRefresher.components.get(viewport.
1828 getSequenceSetId());
1829 Vector existingNames = new Vector();
1830 for (int i = 0; i < comps.size(); i++)
1832 if (comps.elementAt(i) instanceof AlignmentPanel)
1834 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
1835 if (!existingNames.contains(ap.av.viewName))
1837 existingNames.addElement(ap.av.viewName);
1842 while (existingNames.contains(newViewName))
1844 newViewName = "View " + (++index);
1847 newap.av.viewName = newViewName;
1849 addAlignmentPanel(newap, false);
1851 if (alignPanels.size() == 2)
1853 viewport.gatherViewsHere = true;
1855 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1858 public void expandViews_actionPerformed(ActionEvent e)
1860 Desktop.instance.explodeViews(this);
1863 public void gatherViews_actionPerformed(ActionEvent e)
1865 Desktop.instance.gatherViews(this);
1871 * @param e DOCUMENT ME!
1873 public void font_actionPerformed(ActionEvent e)
1875 new FontChooser(alignPanel);
1881 * @param e DOCUMENT ME!
1883 protected void seqLimit_actionPerformed(ActionEvent e)
1885 viewport.setShowJVSuffix(seqLimits.isSelected());
1887 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1888 alignPanel.repaint();
1891 public void idRightAlign_actionPerformed(ActionEvent e)
1893 viewport.rightAlignIds = idRightAlign.isSelected();
1894 alignPanel.repaint();
1900 * @param e DOCUMENT ME!
1902 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1904 viewport.setColourText(colourTextMenuItem.isSelected());
1905 alignPanel.repaint();
1911 * @param e DOCUMENT ME!
1913 public void wrapMenuItem_actionPerformed(ActionEvent e)
1915 scaleAbove.setVisible(wrapMenuItem.isSelected());
1916 scaleLeft.setVisible(wrapMenuItem.isSelected());
1917 scaleRight.setVisible(wrapMenuItem.isSelected());
1918 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1919 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1922 public void showAllSeqs_actionPerformed(ActionEvent e)
1924 viewport.showAllHiddenSeqs();
1927 public void showAllColumns_actionPerformed(ActionEvent e)
1929 viewport.showAllHiddenColumns();
1933 public void hideSelSequences_actionPerformed(ActionEvent e)
1935 viewport.hideAllSelectedSeqs();
1936 alignPanel.repaint();
1939 public void hideSelColumns_actionPerformed(ActionEvent e)
1941 viewport.hideSelectedColumns();
1942 alignPanel.repaint();
1945 public void hiddenMarkers_actionPerformed(ActionEvent e)
1947 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1954 * @param e DOCUMENT ME!
1956 protected void scaleAbove_actionPerformed(ActionEvent e)
1958 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1959 alignPanel.repaint();
1965 * @param e DOCUMENT ME!
1967 protected void scaleLeft_actionPerformed(ActionEvent e)
1969 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1970 alignPanel.repaint();
1976 * @param e DOCUMENT ME!
1978 protected void scaleRight_actionPerformed(ActionEvent e)
1980 viewport.setScaleRightWrapped(scaleRight.isSelected());
1981 alignPanel.repaint();
1987 * @param e DOCUMENT ME!
1989 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1991 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1992 alignPanel.repaint();
1998 * @param e DOCUMENT ME!
2000 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2002 viewport.setShowText(viewTextMenuItem.isSelected());
2003 alignPanel.repaint();
2009 * @param e DOCUMENT ME!
2011 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2013 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2014 alignPanel.repaint();
2017 public FeatureSettings featureSettings;
2018 public void featureSettings_actionPerformed(ActionEvent e)
2020 if (featureSettings != null)
2022 featureSettings.close();
2023 featureSettings = null;
2025 featureSettings = new FeatureSettings(this);
2031 * @param evt DOCUMENT ME!
2033 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2035 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2036 alignPanel.repaint();
2037 if (alignPanel.getOverviewPanel() != null)
2039 alignPanel.getOverviewPanel().updateOverviewImage();
2046 * @param e DOCUMENT ME!
2048 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2050 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2051 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2057 * @param e DOCUMENT ME!
2059 public void overviewMenuItem_actionPerformed(ActionEvent e)
2061 if (alignPanel.overviewPanel != null)
2066 JInternalFrame frame = new JInternalFrame();
2067 OverviewPanel overview = new OverviewPanel(alignPanel);
2068 frame.setContentPane(overview);
2069 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2070 frame.getWidth(), frame.getHeight());
2072 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2073 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2075 public void internalFrameClosed(
2076 javax.swing.event.InternalFrameEvent evt)
2078 alignPanel.setOverviewPanel(null);
2083 alignPanel.setOverviewPanel(overview);
2086 public void textColour_actionPerformed(ActionEvent e)
2088 new TextColourChooser().chooseColour(alignPanel, null);
2094 * @param e DOCUMENT ME!
2096 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2104 * @param e DOCUMENT ME!
2106 public void clustalColour_actionPerformed(ActionEvent e)
2108 changeColour(new ClustalxColourScheme(
2109 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2115 * @param e DOCUMENT ME!
2117 public void zappoColour_actionPerformed(ActionEvent e)
2119 changeColour(new ZappoColourScheme());
2125 * @param e DOCUMENT ME!
2127 public void taylorColour_actionPerformed(ActionEvent e)
2129 changeColour(new TaylorColourScheme());
2135 * @param e DOCUMENT ME!
2137 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2139 changeColour(new HydrophobicColourScheme());
2145 * @param e DOCUMENT ME!
2147 public void helixColour_actionPerformed(ActionEvent e)
2149 changeColour(new HelixColourScheme());
2155 * @param e DOCUMENT ME!
2157 public void strandColour_actionPerformed(ActionEvent e)
2159 changeColour(new StrandColourScheme());
2165 * @param e DOCUMENT ME!
2167 public void turnColour_actionPerformed(ActionEvent e)
2169 changeColour(new TurnColourScheme());
2175 * @param e DOCUMENT ME!
2177 public void buriedColour_actionPerformed(ActionEvent e)
2179 changeColour(new BuriedColourScheme());
2185 * @param e DOCUMENT ME!
2187 public void nucleotideColour_actionPerformed(ActionEvent e)
2189 changeColour(new NucleotideColourScheme());
2192 public void annotationColour_actionPerformed(ActionEvent e)
2194 new AnnotationColourChooser(viewport, alignPanel);
2200 * @param e DOCUMENT ME!
2202 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2204 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2210 * @param cs DOCUMENT ME!
2212 public void changeColour(ColourSchemeI cs)
2218 if (viewport.getAbovePIDThreshold())
2220 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2223 cs.setThreshold(threshold,
2224 viewport.getIgnoreGapsConsensus());
2226 viewport.setGlobalColourScheme(cs);
2230 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2233 if (viewport.getConservationSelected())
2236 Alignment al = (Alignment) viewport.alignment;
2237 Conservation c = new Conservation("All",
2238 ResidueProperties.propHash, 3,
2239 al.getSequences(), 0,
2243 c.verdict(false, viewport.ConsPercGaps);
2245 cs.setConservation(c);
2247 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2252 cs.setConservation(null);
2255 cs.setConsensus(viewport.hconsensus);
2258 viewport.setGlobalColourScheme(cs);
2260 if (viewport.getColourAppliesToAllGroups())
2262 Vector groups = viewport.alignment.getGroups();
2264 for (int i = 0; i < groups.size(); i++)
2266 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2274 if (cs instanceof ClustalxColourScheme)
2276 sg.cs = new ClustalxColourScheme(
2277 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2279 else if (cs instanceof UserColourScheme)
2281 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2287 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2289 catch (Exception ex)
2294 if (viewport.getAbovePIDThreshold()
2295 || cs instanceof PIDColourScheme
2296 || cs instanceof Blosum62ColourScheme)
2298 sg.cs.setThreshold(threshold,
2299 viewport.getIgnoreGapsConsensus());
2301 sg.cs.setConsensus(AAFrequency.calculate(
2302 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2303 sg.getEndRes() + 1));
2307 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2310 if (viewport.getConservationSelected())
2312 Conservation c = new Conservation("Group",
2313 ResidueProperties.propHash, 3,
2314 sg.getSequences(viewport.
2315 hiddenRepSequences),
2317 sg.getEndRes() + 1);
2319 c.verdict(false, viewport.ConsPercGaps);
2320 sg.cs.setConservation(c);
2324 sg.cs.setConservation(null);
2329 if (alignPanel.getOverviewPanel() != null)
2331 alignPanel.getOverviewPanel().updateOverviewImage();
2334 alignPanel.repaint();
2340 * @param e DOCUMENT ME!
2342 protected void modifyPID_actionPerformed(ActionEvent e)
2344 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme != null)
2346 SliderPanel.setPIDSliderSource(alignPanel,
2347 viewport.getGlobalColourScheme(),
2349 SliderPanel.showPIDSlider();
2356 * @param e DOCUMENT ME!
2358 protected void modifyConservation_actionPerformed(ActionEvent e)
2360 if (viewport.getConservationSelected() && viewport.globalColourScheme != null)
2362 SliderPanel.setConservationSlider(alignPanel,
2363 viewport.globalColourScheme,
2365 SliderPanel.showConservationSlider();
2372 * @param e DOCUMENT ME!
2374 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2376 viewport.setConservationSelected(conservationMenuItem.isSelected());
2378 viewport.setAbovePIDThreshold(false);
2379 abovePIDThreshold.setSelected(false);
2381 changeColour(viewport.getGlobalColourScheme());
2383 modifyConservation_actionPerformed(null);
2389 * @param e DOCUMENT ME!
2391 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2393 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2395 conservationMenuItem.setSelected(false);
2396 viewport.setConservationSelected(false);
2398 changeColour(viewport.getGlobalColourScheme());
2400 modifyPID_actionPerformed(null);
2406 * @param e DOCUMENT ME!
2408 public void userDefinedColour_actionPerformed(ActionEvent e)
2410 if (e.getActionCommand().equals("User Defined..."))
2412 new UserDefinedColours(alignPanel, null);
2416 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2417 getUserColourSchemes().get(e.getActionCommand());
2423 public void updateUserColourMenu()
2426 Component[] menuItems = colourMenu.getMenuComponents();
2427 int i, iSize = menuItems.length;
2428 for (i = 0; i < iSize; i++)
2430 if (menuItems[i].getName() != null &&
2431 menuItems[i].getName().equals("USER_DEFINED"))
2433 colourMenu.remove(menuItems[i]);
2437 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2439 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2440 getUserColourSchemes().keys();
2442 while (userColours.hasMoreElements())
2444 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2446 nextElement().toString());
2447 radioItem.setName("USER_DEFINED");
2448 radioItem.addMouseListener(new MouseAdapter()
2450 public void mousePressed(MouseEvent evt)
2452 if (evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2454 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2456 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2458 "Remove from default list?",
2459 "Remove user defined colour",
2460 JOptionPane.YES_NO_OPTION);
2461 if (option == JOptionPane.YES_OPTION)
2463 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2464 radioItem.getText());
2465 colourMenu.remove(radioItem);
2469 radioItem.addActionListener(new ActionListener()
2471 public void actionPerformed(ActionEvent evt)
2473 userDefinedColour_actionPerformed(evt);
2480 radioItem.addActionListener(new ActionListener()
2482 public void actionPerformed(ActionEvent evt)
2484 userDefinedColour_actionPerformed(evt);
2488 colourMenu.insert(radioItem, 15);
2489 colours.add(radioItem);
2497 * @param e DOCUMENT ME!
2499 public void PIDColour_actionPerformed(ActionEvent e)
2501 changeColour(new PIDColourScheme());
2507 * @param e DOCUMENT ME!
2509 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2511 changeColour(new Blosum62ColourScheme());
2517 * @param e DOCUMENT ME!
2519 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2521 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2522 AlignmentSorter.sortByPID(viewport.getAlignment(),
2523 viewport.getAlignment().getSequenceAt(0));
2524 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2525 viewport.alignment));
2526 alignPanel.repaint();
2532 * @param e DOCUMENT ME!
2534 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2536 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2537 AlignmentSorter.sortByID(viewport.getAlignment());
2538 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2539 alignPanel.repaint();
2545 * @param e DOCUMENT ME!
2547 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2549 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2550 AlignmentSorter.sortByGroup(viewport.getAlignment());
2551 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2553 alignPanel.repaint();
2559 * @param e DOCUMENT ME!
2561 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2563 new RedundancyPanel(alignPanel, this);
2569 * @param e DOCUMENT ME!
2571 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2573 if ( (viewport.getSelectionGroup() == null) ||
2574 (viewport.getSelectionGroup().getSize() < 2))
2576 JOptionPane.showInternalMessageDialog(this,
2577 "You must select at least 2 sequences.",
2578 "Invalid Selection",
2579 JOptionPane.WARNING_MESSAGE);
2583 JInternalFrame frame = new JInternalFrame();
2584 frame.setContentPane(new PairwiseAlignPanel(viewport));
2585 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2592 * @param e DOCUMENT ME!
2594 public void PCAMenuItem_actionPerformed(ActionEvent e)
2596 if ( ( (viewport.getSelectionGroup() != null) &&
2597 (viewport.getSelectionGroup().getSize() < 4) &&
2598 (viewport.getSelectionGroup().getSize() > 0)) ||
2599 (viewport.getAlignment().getHeight() < 4))
2601 JOptionPane.showInternalMessageDialog(this,
2602 "Principal component analysis must take\n" +
2603 "at least 4 input sequences.",
2604 "Sequence selection insufficient",
2605 JOptionPane.WARNING_MESSAGE);
2610 new PCAPanel(alignPanel);
2613 public void autoCalculate_actionPerformed(ActionEvent e)
2615 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2616 if (viewport.autoCalculateConsensus)
2618 viewport.firePropertyChange("alignment",
2620 viewport.getAlignment().getSequences());
2627 * @param e DOCUMENT ME!
2629 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2631 NewTreePanel("AV", "PID", "Average distance tree using PID");
2637 * @param e DOCUMENT ME!
2639 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2641 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2647 * @param e DOCUMENT ME!
2649 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2651 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2657 * @param e DOCUMENT ME!
2659 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2661 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2667 * @param type DOCUMENT ME!
2668 * @param pwType DOCUMENT ME!
2669 * @param title DOCUMENT ME!
2671 void NewTreePanel(String type, String pwType, String title)
2675 if (viewport.getSelectionGroup() != null)
2677 if (viewport.getSelectionGroup().getSize() < 3)
2679 JOptionPane.showMessageDialog(Desktop.desktop,
2680 "You need to have more than two sequences selected to build a tree!",
2681 "Not enough sequences",
2682 JOptionPane.WARNING_MESSAGE);
2687 SequenceGroup sg = viewport.getSelectionGroup();
2689 /* Decide if the selection is a column region */
2690 while (s < sg.getSize())
2692 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2695 JOptionPane.showMessageDialog(Desktop.desktop,
2696 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2697 "Try using the Pad function in the edit menu,\n" +
2698 "or one of the multiple sequence alignment web services.",
2699 "Sequences in selection are not aligned",
2700 JOptionPane.WARNING_MESSAGE);
2706 title = title + " on region";
2707 tp = new TreePanel(alignPanel, type, pwType);
2711 //are the sequences aligned?
2712 if (!viewport.alignment.isAligned())
2714 JOptionPane.showMessageDialog(Desktop.desktop,
2715 "The sequences must be aligned before creating a tree.\n" +
2716 "Try using the Pad function in the edit menu,\n" +
2717 "or one of the multiple sequence alignment web services.",
2718 "Sequences not aligned",
2719 JOptionPane.WARNING_MESSAGE);
2724 if (viewport.alignment.getHeight() < 2)
2729 tp = new TreePanel(alignPanel, type, pwType);
2734 if (viewport.viewName != null)
2736 title += viewport.viewName + " of ";
2739 title += this.title;
2741 Desktop.addInternalFrame(tp, title, 600, 500);
2747 * @param title DOCUMENT ME!
2748 * @param order DOCUMENT ME!
2750 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2752 final JMenuItem item = new JMenuItem("by " + title);
2754 item.addActionListener(new java.awt.event.ActionListener()
2756 public void actionPerformed(ActionEvent e)
2758 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2760 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2761 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2763 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
2764 viewport.alignment));
2766 alignPanel.repaint();
2772 * Maintain the Order by->Displayed Tree menu.
2773 * Creates a new menu item for a TreePanel with an appropriate
2774 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2775 * to remove the menu item when the treePanel is closed, and adjust
2776 * the tree leaf to sequence mapping when the alignment is modified.
2777 * @param treePanel Displayed tree window.
2778 * @param title SortBy menu item title.
2780 public void buildTreeMenu()
2782 sortByTreeMenu.removeAll();
2784 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2785 getSequenceSetId());
2786 Vector treePanels = new Vector();
2787 int i, iSize = comps.size();
2788 for (i = 0; i < iSize; i++)
2790 if (comps.elementAt(i) instanceof TreePanel)
2792 treePanels.add(comps.elementAt(i));
2796 iSize = treePanels.size();
2800 sortByTreeMenu.setVisible(false);
2804 sortByTreeMenu.setVisible(true);
2806 for (i = 0; i < treePanels.size(); i++)
2808 TreePanel tp = (TreePanel) treePanels.elementAt(i);
2809 final JMenuItem item = new JMenuItem(tp.getTitle());
2810 final NJTree tree = ( (TreePanel) treePanels.elementAt(i)).getTree();
2811 item.addActionListener(new java.awt.event.ActionListener()
2813 public void actionPerformed(ActionEvent e)
2815 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2816 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2818 addHistoryItem(new OrderCommand("Tree Sort",
2820 viewport.alignment));
2822 alignPanel.repaint();
2826 sortByTreeMenu.add(item);
2831 * Work out whether the whole set of sequences
2832 * or just the selected set will be submitted for multiple alignment.
2835 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2837 // Now, check we have enough sequences
2838 AlignmentView msa = null;
2840 if ( (viewport.getSelectionGroup() != null) &&
2841 (viewport.getSelectionGroup().getSize() > 1))
2843 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2844 /*SequenceGroup seqs = viewport.getSelectionGroup();
2846 msa = new SequenceI[sz = seqs.getSize(false)];
2848 for (int i = 0; i < sz; i++)
2850 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2852 msa = viewport.getAlignmentView(true);
2856 /*Vector seqs = viewport.getAlignment().getSequences();
2857 if (seqs.size() > 1)
2859 msa = new SequenceI[seqs.size()];
2861 for (int i = 0; i < seqs.size(); i++)
2863 msa[i] = (SequenceI) seqs.elementAt(i);
2866 msa = viewport.getAlignmentView(false);
2872 * Decides what is submitted to a secondary structure prediction service,
2873 * the currently selected sequence, or the currently selected alignment
2874 * (where the first sequence in the set is the one that the prediction
2877 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2879 AlignmentView seqs = null;
2881 if ( (viewport.getSelectionGroup() != null) &&
2882 (viewport.getSelectionGroup().getSize() > 0))
2884 seqs = viewport.getAlignmentView(true);
2888 seqs = viewport.getAlignmentView(false);
2890 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2891 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2892 if (!viewport.alignment.isAligned())
2894 seqs.setSequences(new SeqCigar[]
2895 {seqs.getSequences()[0]});
2903 * @param e DOCUMENT ME!
2905 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2907 // Pick the tree file
2908 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2911 chooser.setFileView(new JalviewFileView());
2912 chooser.setDialogTitle("Select a newick-like tree file");
2913 chooser.setToolTipText("Load a tree file");
2915 int value = chooser.showOpenDialog(null);
2917 if (value == JalviewFileChooser.APPROVE_OPTION)
2919 String choice = chooser.getSelectedFile().getPath();
2920 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2924 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2926 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2928 catch (Exception ex)
2930 JOptionPane.showMessageDialog(Desktop.desktop,
2931 "Problem reading tree file",
2933 JOptionPane.WARNING_MESSAGE);
2934 ex.printStackTrace();
2939 public TreePanel ShowNewickTree(NewickFile nf, String title)
2941 return ShowNewickTree(nf, title, 600, 500, 4, 5);
2944 public TreePanel ShowNewickTree(NewickFile nf, String title,
2945 AlignmentView input)
2947 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
2950 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
2953 return ShowNewickTree(nf, title, null, w, h, x, y);
2957 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2959 * @param nf the tree
2960 * @param title tree viewer title
2961 * @param input Associated alignment input data (or null)
2966 * @return TreePanel handle
2968 public TreePanel ShowNewickTree(NewickFile nf, String title,
2969 AlignmentView input, int w, int h, int x,
2972 TreePanel tp = null;
2978 if (nf.getTree() != null)
2980 tp = new TreePanel(alignPanel,
2989 tp.setLocation(x, y);
2992 Desktop.addInternalFrame(tp, title, w, h);
2995 catch (Exception ex)
2997 ex.printStackTrace();
3004 * Generates menu items and listener event actions for web service clients
3007 public void BuildWebServiceMenu()
3009 if ( (Discoverer.services != null)
3010 && (Discoverer.services.size() > 0))
3012 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3013 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3014 Vector wsmenu = new Vector();
3015 final AlignFrame af = this;
3018 // Add any Multiple Sequence Alignment Services
3019 final JMenu msawsmenu = new JMenu("Alignment");
3020 for (int i = 0, j = msaws.size(); i < j; i++)
3022 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3024 final JMenuItem method = new JMenuItem(sh.getName());
3025 method.addActionListener(new ActionListener()
3027 public void actionPerformed(ActionEvent e)
3029 AlignmentView msa = gatherSequencesForAlignment();
3030 new jalview.ws.MsaWSClient(sh, title, msa,
3032 viewport.getAlignment().getDataset(),
3038 msawsmenu.add(method);
3039 // Deal with services that we know accept partial alignments.
3040 if (sh.getName().indexOf("lustal") > -1)
3042 // We know that ClustalWS can accept partial alignments for refinement.
3043 final JMenuItem methodR = new JMenuItem(sh.getName() + " Realign");
3044 methodR.addActionListener(new ActionListener()
3046 public void actionPerformed(ActionEvent e)
3048 AlignmentView msa = gatherSequencesForAlignment();
3049 new jalview.ws.MsaWSClient(sh, title, msa,
3051 viewport.getAlignment().getDataset(),
3057 msawsmenu.add(methodR);
3061 wsmenu.add(msawsmenu);
3063 if (secstrpr != null)
3065 // Add any secondary structure prediction services
3066 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3067 for (int i = 0, j = secstrpr.size(); i < j; i++)
3069 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3071 final JMenuItem method = new JMenuItem(sh.getName());
3072 method.addActionListener(new ActionListener()
3074 public void actionPerformed(ActionEvent e)
3076 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3077 if (msa.getSequences().length == 1)
3079 // Single Sequence prediction
3080 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3084 if (msa.getSequences().length > 1)
3086 // Sequence profile based prediction
3087 new jalview.ws.JPredClient(sh,
3088 title, true, msa, af, true);
3093 secstrmenu.add(method);
3095 wsmenu.add(secstrmenu);
3097 this.webService.removeAll();
3098 for (int i = 0, j = wsmenu.size(); i < j; i++)
3100 webService.add( (JMenu) wsmenu.get(i));
3105 this.webService.removeAll();
3106 this.webService.add(this.webServiceNoServices);
3108 // TODO: add in rediscovery function
3109 // TODO: reduce code redundancy.
3110 // TODO: group services by location as well as function.
3113 /* public void vamsasStore_actionPerformed(ActionEvent e)
3115 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3116 getProperty("LAST_DIRECTORY"));
3118 chooser.setFileView(new JalviewFileView());
3119 chooser.setDialogTitle("Export to Vamsas file");
3120 chooser.setToolTipText("Export");
3122 int value = chooser.showSaveDialog(this);
3124 if (value == JalviewFileChooser.APPROVE_OPTION)
3126 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3127 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3128 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3135 public void showTranslation_actionPerformed(ActionEvent e)
3137 SequenceI[] selection = viewport.getSelectionAsNewSequence();
3138 String[] seqstring = viewport.getViewAsString(true);
3140 int s, sSize = selection.length;
3141 SequenceI[] newSeq = new SequenceI[sSize];
3144 StringBuffer protein;
3146 for (s = 0; s < sSize; s++)
3148 protein = new StringBuffer();
3149 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3150 resSize = seq.length();
3151 resSize -= resSize % 3;
3153 for (res = 0; res < resSize; res += 3)
3155 String codon = seq.substring(res, res + 3);
3156 codon = codon.replace('U', 'T');
3157 String aa = ResidueProperties.codonTranslate(codon);
3160 protein.append(viewport.getGapCharacter());
3162 else if (aa.equals("STOP"))
3164 protein.append("X");
3171 newSeq[s] = new Sequence(selection[s].getName(),
3172 protein.toString());
3175 AlignmentI al = new Alignment(newSeq);
3176 al.setDataset(null);
3178 ////////////////////////////////
3179 // Copy annotations across
3180 jalview.datamodel.AlignmentAnnotation[] annotations
3181 = viewport.alignment.getAlignmentAnnotation();
3183 if (annotations != null)
3185 for (int i = 0; i < annotations.length; i++)
3187 if (annotations[i] == viewport.quality ||
3188 annotations[i] == viewport.conservation ||
3189 annotations[i] == viewport.consensus)
3191 System.out.println("COPT HERE");
3195 aSize = viewport.alignment.getWidth() / 3;
3196 jalview.datamodel.Annotation[] anots =
3197 new jalview.datamodel.Annotation[aSize];
3199 for (a = 0; a < viewport.alignment.getWidth(); a++)
3201 if (annotations[i].annotations[a] == null
3202 || annotations[i].annotations[a] == null)
3207 anots[a / 3] = new Annotation(
3208 annotations[i].annotations[a].displayCharacter,
3209 annotations[i].annotations[a].description,
3210 annotations[i].annotations[a].secondaryStructure,
3211 annotations[i].annotations[a].value,
3212 annotations[i].annotations[a].colour);
3215 jalview.datamodel.AlignmentAnnotation aa
3216 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3217 annotations[i].description, anots);
3218 al.addAnnotation(aa);
3222 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3223 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3232 * @param String DOCUMENT ME!
3234 public boolean parseFeaturesFile(String file, String type)
3236 boolean featuresFile = false;
3239 featuresFile = new FeaturesFile(file,
3240 type).parse(viewport.alignment.getDataset(),
3241 alignPanel.seqPanel.seqCanvas.
3242 getFeatureRenderer().featureColours,
3245 catch (Exception ex)
3247 ex.printStackTrace();
3252 viewport.showSequenceFeatures = true;
3253 showSeqFeatures.setSelected(true);
3254 alignPanel.repaint();
3257 return featuresFile;
3260 public void dragEnter(DropTargetDragEvent evt)
3263 public void dragExit(DropTargetEvent evt)
3266 public void dragOver(DropTargetDragEvent evt)
3269 public void dropActionChanged(DropTargetDragEvent evt)
3272 public void drop(DropTargetDropEvent evt)
3274 Transferable t = evt.getTransferable();
3275 java.util.List files = null;
3279 DataFlavor uriListFlavor = new DataFlavor(
3280 "text/uri-list;class=java.lang.String");
3281 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3283 //Works on Windows and MacOSX
3284 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3285 files = (java.util.List) t.getTransferData(DataFlavor.
3286 javaFileListFlavor);
3288 else if (t.isDataFlavorSupported(uriListFlavor))
3290 // This is used by Unix drag system
3291 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3292 String data = (String) t.getTransferData(uriListFlavor);
3293 files = new java.util.ArrayList(1);
3294 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3297 st.hasMoreTokens(); )
3299 String s = st.nextToken();
3300 if (s.startsWith("#"))
3302 // the line is a comment (as per the RFC 2483)
3306 java.net.URI uri = new java.net.URI(s);
3307 java.io.File file = new java.io.File(uri);
3314 e.printStackTrace();
3321 for (int i = 0; i < files.size(); i++)
3323 loadJalviewDataFile(files.get(i).toString());
3326 catch (Exception ex)
3328 ex.printStackTrace();
3333 // This method will attempt to load a "dropped" file first by testing
3334 // whether its and Annotation file, then features file. If both are
3335 // false then the user may have dropped an alignment file onto this
3337 public void loadJalviewDataFile(String file)
3341 String protocol = "File";
3343 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3348 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3349 alignment, file, protocol);
3353 boolean isGroupsFile = parseFeaturesFile(file, protocol);
3356 String format = new IdentifyFile().Identify(file, protocol);
3358 if (format.equalsIgnoreCase("JnetFile"))
3360 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3362 new JnetAnnotationMaker().add_annotation(predictions,
3363 viewport.getAlignment(),
3365 alignPanel.adjustAnnotationHeight();
3366 alignPanel.repaint();
3370 new FileLoader().LoadFile(viewport, file, protocol, format);
3377 alignPanel.adjustAnnotationHeight();
3381 catch (Exception ex)
3383 ex.printStackTrace();
3387 public void tabSelectionChanged(int index)
3391 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3392 viewport = alignPanel.av;
3393 setMenusFromViewport(viewport);
3397 public void tabbedPane_mousePressed(MouseEvent e)
3399 if (SwingUtilities.isRightMouseButton(e))
3401 String reply = JOptionPane.showInternalInputDialog(this,
3404 JOptionPane.QUESTION_MESSAGE);
3408 viewport.viewName = reply;
3409 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
3414 public AlignViewport getCurrentView()
3424 public PrintThread(AlignmentPanel ap)
3429 static PageFormat pf;
3432 PrinterJob printJob = PrinterJob.getPrinterJob();
3436 printJob.setPrintable(ap, pf);
3440 printJob.setPrintable(ap);
3443 if (printJob.printDialog())
3449 catch (Exception PrintException)
3451 PrintException.printStackTrace();