2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.event.*;
28 import java.awt.print.*;
31 import jalview.analysis.*;
32 import jalview.datamodel.*;
34 import jalview.jbgui.*;
35 import jalview.schemes.*;
36 import jalview.commands.*;
38 import java.awt.dnd.*;
46 public class AlignFrame extends GAlignFrame implements DropTargetListener
49 public static final int DEFAULT_WIDTH = 700;
52 public static final int DEFAULT_HEIGHT = 500;
53 public AlignmentPanel alignPanel;
55 AlignViewport viewport;
57 Vector alignPanels = new Vector();
61 String currentFileFormat = null;
63 String fileName = null;
67 * Creates a new AlignFrame object.
69 * @param al DOCUMENT ME!
71 public AlignFrame(AlignmentI al, int width, int height)
73 this(al, null, width, height);
78 * new alignment window with hidden columns
79 * @param al AlignmentI
80 * @param hiddenColumns ColumnSelection or null
82 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
83 int width, int height)
85 this.setSize(width, height);
86 viewport = new AlignViewport(al, hiddenColumns);
88 alignPanel = new AlignmentPanel(this, viewport);
90 if(al.getDataset()==null)
95 addAlignmentPanel(alignPanel, true);
100 * Make a new AlignFrame from exisiting alignmentPanels
101 * @param ap AlignmentPanel
102 * @param av AlignViewport
104 public AlignFrame(AlignmentPanel ap)
108 addAlignmentPanel(ap, false);
114 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
116 if (viewport.conservation == null)
118 BLOSUM62Colour.setEnabled(false);
119 conservationMenuItem.setEnabled(false);
120 modifyConservation.setEnabled(false);
121 // PIDColour.setEnabled(false);
122 // abovePIDThreshold.setEnabled(false);
123 // modifyPID.setEnabled(false);
126 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
128 if (sortby.equals("Id"))
129 sortIDMenuItem_actionPerformed(null);
130 else if (sortby.equals("Pairwise Identity"))
131 sortPairwiseMenuItem_actionPerformed(null);
133 if (Desktop.desktop != null)
135 addServiceListeners();
136 setGUINucleotide(viewport.alignment.isNucleotide());
139 setMenusFromViewport(viewport);
141 if (viewport.wrapAlignment)
143 wrapMenuItem_actionPerformed(null);
150 public void setFileName(String file, String format)
153 currentFileFormat = format;
154 reload.setEnabled(true);
157 void addKeyListener()
159 addKeyListener(new KeyAdapter()
161 public void keyPressed(KeyEvent evt)
163 if (viewport.cursorMode
164 && evt.getKeyCode() >= KeyEvent.VK_0
165 && evt.getKeyCode() <= KeyEvent.VK_9)
167 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
170 switch (evt.getKeyCode())
173 case 27: // escape key
174 deselectAllSequenceMenuItem_actionPerformed(null);
178 case KeyEvent.VK_DOWN:
179 if (viewport.cursorMode)
181 alignPanel.seqPanel.moveCursor(0, 1);
184 moveSelectedSequences(false);
188 if (viewport.cursorMode)
190 alignPanel.seqPanel.moveCursor(0, -1);
193 moveSelectedSequences(true);
196 case KeyEvent.VK_LEFT:
197 if (viewport.cursorMode)
199 alignPanel.seqPanel.moveCursor( -1, 0);
203 case KeyEvent.VK_RIGHT:
204 if (viewport.cursorMode)
206 alignPanel.seqPanel.moveCursor(1, 0);
210 case KeyEvent.VK_SPACE:
211 if (viewport.cursorMode)
213 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
219 case KeyEvent.VK_DELETE:
220 case KeyEvent.VK_BACK_SPACE:
221 if (!viewport.cursorMode)
223 cut_actionPerformed(null);
226 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
233 if (viewport.cursorMode)
235 alignPanel.seqPanel.setCursorRow();
239 if (viewport.cursorMode && !evt.isControlDown())
241 alignPanel.seqPanel.setCursorColumn();
245 if (viewport.cursorMode)
247 alignPanel.seqPanel.setCursorPosition();
251 case KeyEvent.VK_ENTER:
252 case KeyEvent.VK_COMMA:
253 if (viewport.cursorMode)
255 alignPanel.seqPanel.setCursorRowAndColumn();
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
266 if (viewport.cursorMode)
268 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
273 viewport.cursorMode = !viewport.cursorMode;
274 statusBar.setText("Keyboard editing mode is " +
275 (viewport.cursorMode ? "on" : "off"));
276 if (viewport.cursorMode)
278 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
279 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
281 alignPanel.seqPanel.seqCanvas.repaint();
287 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
288 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
289 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
291 javax.help.HelpBroker hb = hs.createHelpBroker();
292 hb.setCurrentID("home");
293 hb.setDisplayed(true);
297 ex.printStackTrace();
303 boolean toggleSeqs = !evt.isControlDown();
304 boolean toggleCols = !evt.isShiftDown();
306 boolean hide = false;
308 SequenceGroup sg = viewport.getSelectionGroup();
311 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
313 hideSelSequences_actionPerformed(null);
316 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
317 showAllSeqs_actionPerformed(null);
322 if (viewport.colSel.getSelected().size() > 0)
324 hideSelColumns_actionPerformed(null);
326 viewport.selectionGroup = sg;
329 showAllColumns_actionPerformed(null);
333 case KeyEvent.VK_PAGE_UP:
334 if (viewport.wrapAlignment)
335 alignPanel.scrollUp(true);
337 alignPanel.setScrollValues(viewport.startRes,
339 - viewport.endSeq + viewport.startSeq);
341 case KeyEvent.VK_PAGE_DOWN:
342 if (viewport.wrapAlignment)
343 alignPanel.scrollUp(false);
345 alignPanel.setScrollValues(viewport.startRes,
347 + viewport.endSeq - viewport.startSeq);
355 public void addAlignmentPanel(final AlignmentPanel ap,
358 ap.alignFrame = this;
360 alignPanels.addElement(ap);
362 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
364 int aSize = alignPanels.size();
366 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
368 if (aSize == 1 && ap.av.viewName==null)
370 this.getContentPane().add(ap, BorderLayout.CENTER);
376 setInitialTabVisible();
379 expandViews.setEnabled(true);
380 gatherViews.setEnabled(true);
381 tabbedPane.addTab(ap.av.viewName, ap);
383 ap.setVisible(false);
389 ap.av.alignment.padGaps();
390 ap.av.updateConservation(ap);
391 ap.av.updateConsensus(ap);
395 public void setInitialTabVisible()
397 expandViews.setEnabled(true);
398 gatherViews.setEnabled(true);
399 tabbedPane.setVisible(true);
400 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
401 tabbedPane.addTab(first.av.viewName,first);
402 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
406 public AlignViewport getViewport()
411 /* Set up intrinsic listeners for dynamically generated GUI bits. */
412 private void addServiceListeners()
414 final java.beans.PropertyChangeListener thisListener;
415 // Do this once to get current state
416 BuildWebServiceMenu();
417 Desktop.discoverer.addPropertyChangeListener(
418 thisListener = new java.beans.PropertyChangeListener()
420 public void propertyChange(PropertyChangeEvent evt)
422 // System.out.println("Discoverer property change.");
423 if (evt.getPropertyName().equals("services"))
425 // System.out.println("Rebuilding web service menu");
426 BuildWebServiceMenu();
431 addInternalFrameListener(new javax.swing.event.
432 InternalFrameAdapter()
434 public void internalFrameClosed(
435 javax.swing.event.InternalFrameEvent evt)
437 // System.out.println("deregistering discoverer listener");
438 Desktop.discoverer.removePropertyChangeListener(thisListener);
439 closeMenuItem_actionPerformed(true);
445 public void setGUINucleotide(boolean nucleotide)
447 showTranslation.setVisible( nucleotide );
448 conservationMenuItem.setEnabled( !nucleotide );
449 modifyConservation.setEnabled( !nucleotide );
451 //Remember AlignFrame always starts as protein
454 calculateMenu.remove(calculateMenu.getItemCount()-2);
459 * Need to call this method when tabs are selected for multiple views,
460 * or when loading from Jalview2XML.java
461 * @param av AlignViewport
463 void setMenusFromViewport(AlignViewport av)
465 padGapsMenuitem.setSelected(av.padGaps);
466 colourTextMenuItem.setSelected(av.showColourText);
467 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
468 conservationMenuItem.setSelected(av.getConservationSelected());
469 seqLimits.setSelected(av.getShowJVSuffix());
470 idRightAlign.setSelected(av.rightAlignIds);
471 renderGapsMenuItem.setSelected(av.renderGaps);
472 wrapMenuItem.setSelected(av.wrapAlignment);
473 scaleAbove.setVisible(av.wrapAlignment);
474 scaleLeft.setVisible(av.wrapAlignment);
475 scaleRight.setVisible(av.wrapAlignment);
476 annotationPanelMenuItem.setState(av.showAnnotation);
477 viewBoxesMenuItem.setSelected(av.showBoxes);
478 viewTextMenuItem.setSelected(av.showText);
480 setColourSelected(ColourSchemeProperty.
481 getColourName(av.getGlobalColourScheme()));
483 showSeqFeatures.setSelected(av.showSequenceFeatures);
484 hiddenMarkers.setState(av.showHiddenMarkers);
485 applyToAllGroups.setState(av.colourAppliesToAllGroups);
491 Hashtable progressBars;
492 public void setProgressBar(String message, long id)
494 if(progressBars == null)
495 progressBars = new Hashtable();
497 JPanel progressPanel;
498 GridLayout layout = (GridLayout) statusPanel.getLayout();
499 if(progressBars.get( new Long(id) )!=null)
501 progressPanel = (JPanel)progressBars.get( new Long(id) );
502 statusPanel.remove(progressPanel);
503 progressBars.remove( progressPanel );
504 progressPanel = null;
506 statusBar.setText(message);
508 layout.setRows(layout.getRows() - 1);
512 progressPanel = new JPanel(new BorderLayout(10, 5));
514 JProgressBar progressBar = new JProgressBar();
515 progressBar.setIndeterminate(true);
517 progressPanel.add(new JLabel(message), BorderLayout.WEST);
518 progressPanel.add(progressBar, BorderLayout.CENTER);
520 layout.setRows(layout.getRows() + 1);
521 statusPanel.add(progressPanel);
523 progressBars.put(new Long(id), progressPanel);
533 Added so Castor Mapping file can obtain Jalview Version
535 public String getVersion()
537 return jalview.bin.Cache.getProperty("VERSION");
540 public FeatureRenderer getFeatureRenderer()
542 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
546 public void fetchSequence_actionPerformed(ActionEvent e)
548 new SequenceFetcher(this);
551 public void addFromFile_actionPerformed(ActionEvent e)
553 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
556 public void reload_actionPerformed(ActionEvent e)
560 if(currentFileFormat.equals("Jalview"))
562 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
563 for(int i=0; i<frames.length; i++)
565 if (frames[i] instanceof AlignFrame
567 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
570 frames[i].setSelected(true);
571 Desktop.instance.closeAssociatedWindows();
572 }catch(java.beans.PropertyVetoException ex){}
576 Desktop.instance.closeAssociatedWindows();
581 viewport.alignment.deleteAllGroups();
582 viewport.sequenceColours=null;
583 while (viewport.alignment.getHeight() > 0)
585 viewport.alignment.deleteSequence(0);
588 viewport.historyList.clear();
589 viewport.redoList.clear();
590 Alignment dset = viewport.alignment.getDataset();
591 while (dset.getHeight() > 0)
593 dset.deleteSequence(0);
596 firePropertyChange("Alignment", null, viewport.alignment.getSequences());
601 FileLoader loader = new FileLoader();
602 String protocol = fileName.startsWith("http:")? "URL":"File";
603 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
609 public void addFromText_actionPerformed(ActionEvent e)
611 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
614 public void addFromURL_actionPerformed(ActionEvent e)
616 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
620 public void save_actionPerformed(ActionEvent e)
623 || currentFileFormat==null
624 || fileName.startsWith("http")
626 saveAs_actionPerformed(null);
628 saveAlignment(fileName, currentFileFormat);
634 * @param e DOCUMENT ME!
636 public void saveAs_actionPerformed(ActionEvent e)
638 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
639 getProperty( "LAST_DIRECTORY"),
641 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
643 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
648 chooser.setFileView(new JalviewFileView());
649 chooser.setDialogTitle("Save Alignment to file");
650 chooser.setToolTipText("Save");
652 int value = chooser.showSaveDialog(this);
654 if (value == JalviewFileChooser.APPROVE_OPTION)
656 currentFileFormat = chooser.getSelectedFormat();
657 if (currentFileFormat == null)
659 JOptionPane.showInternalMessageDialog(Desktop.desktop,
660 "You must select a file format before saving!",
661 "File format not specified",
662 JOptionPane.WARNING_MESSAGE);
663 value = chooser.showSaveDialog(this);
667 fileName = chooser.getSelectedFile().getPath();
669 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
672 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
674 saveAlignment(fileName, currentFileFormat);
678 public boolean saveAlignment(String file, String format)
680 boolean success = true;
682 if (format.equalsIgnoreCase("Jalview"))
684 String shortName = title;
686 if (shortName.indexOf(java.io.File.separatorChar) > -1)
688 shortName = shortName.substring(shortName.lastIndexOf(
689 java.io.File.separatorChar) + 1);
692 success = new Jalview2XML().SaveAlignment(this, file, shortName);
694 statusBar.setText("Successfully saved to file: "
696 +format +" format.");
702 String[] omitHidden = null;
704 if (viewport.hasHiddenColumns)
706 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
707 "The Alignment contains hidden columns."
708 + "\nDo you want to save only the visible alignment?",
709 "Save / Omit Hidden Columns",
710 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
712 if (reply == JOptionPane.YES_OPTION)
713 omitHidden = viewport.getViewAsString(false);
716 String output = new FormatAdapter().formatSequences(
718 viewport.alignment.getSequencesArray(),
729 java.io.PrintWriter out = new java.io.PrintWriter(
730 new java.io.FileWriter(file));
735 statusBar.setText("Successfully saved to file: "
737 + format + " format.");
742 ex.printStackTrace();
748 JOptionPane.showInternalMessageDialog(
749 this, "Couldn't save file: " + fileName,
751 JOptionPane.WARNING_MESSAGE);
759 * @param e DOCUMENT ME!
761 protected void outputText_actionPerformed(ActionEvent e)
763 String [] omitHidden = null;
765 if(viewport.hasHiddenColumns)
767 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
768 "The Alignment contains hidden columns."
769 +"\nDo you want to output only the visible alignment?",
770 "Save / Omit Hidden Columns",
771 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
773 if(reply==JOptionPane.YES_OPTION)
775 omitHidden = viewport.getViewAsString(false);
779 CutAndPasteTransfer cap = new CutAndPasteTransfer();
780 cap.setForInput(null);
781 Desktop.addInternalFrame(cap,
782 "Alignment output - " + e.getActionCommand(), 600,
786 cap.setText(new FormatAdapter().formatSequences(
787 e.getActionCommand(),
788 viewport.alignment.getSequencesArray(),
795 * @param e DOCUMENT ME!
797 protected void htmlMenuItem_actionPerformed(ActionEvent e)
799 new HTMLOutput(viewport,
800 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
801 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
804 public void createImageMap(File file, String image)
806 alignPanel.makePNGImageMap(file, image);
812 * @param e DOCUMENT ME!
814 public void createPNG(File f)
816 alignPanel.makePNG(f);
822 * @param e DOCUMENT ME!
824 public void createEPS(File f)
826 alignPanel.makeEPS(f);
830 public void pageSetup_actionPerformed(ActionEvent e)
832 PrinterJob printJob = PrinterJob.getPrinterJob();
833 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
839 * @param e DOCUMENT ME!
841 public void printMenuItem_actionPerformed(ActionEvent e)
843 //Putting in a thread avoids Swing painting problems
844 PrintThread thread = new PrintThread(alignPanel);
848 public void exportFeatures_actionPerformed(ActionEvent e)
850 new AnnotationExporter().exportFeatures(alignPanel);
854 public void exportAnnotations_actionPerformed(ActionEvent e)
856 new AnnotationExporter().exportAnnotations(
858 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
859 viewport.alignment.getGroups()
864 public void associatedData_actionPerformed(ActionEvent e)
866 // Pick the tree file
867 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
870 chooser.setFileView(new JalviewFileView());
871 chooser.setDialogTitle("Load Jalview Annotations or Features File");
872 chooser.setToolTipText("Load Jalview Annotations / Features file");
874 int value = chooser.showOpenDialog(null);
876 if (value == JalviewFileChooser.APPROVE_OPTION)
878 String choice = chooser.getSelectedFile().getPath();
879 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
880 loadJalviewDataFile(choice);
889 * @param e DOCUMENT ME!
891 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
893 if(alignPanels!=null && alignPanels.size()<2)
898 if(alignPanels!=null)
901 for (int i = 0; i < alignPanels.size(); i++)
903 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
904 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
905 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
906 PaintRefresher.RemoveComponent(ap);
910 int index = tabbedPane.getSelectedIndex();
912 alignPanels.removeElement(alignPanel);
913 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
914 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
915 PaintRefresher.RemoveComponent(alignPanel);
919 tabbedPane.removeTabAt(index);
920 tabbedPane.validate();
922 if(index==tabbedPane.getTabCount())
925 this.tabSelectionChanged(index);
930 this.setClosed(true);
934 ex.printStackTrace();
942 void updateEditMenuBar()
945 if (viewport.historyList.size() > 0)
947 undoMenuItem.setEnabled(true);
948 CommandI command = (CommandI) viewport.historyList.peek();
949 undoMenuItem.setText("Undo " + command.getDescription());
953 undoMenuItem.setEnabled(false);
954 undoMenuItem.setText("Undo");
957 if (viewport.redoList.size() > 0)
959 redoMenuItem.setEnabled(true);
961 CommandI command = (CommandI) viewport.redoList.peek();
962 redoMenuItem.setText("Redo " + command.getDescription());
966 redoMenuItem.setEnabled(false);
967 redoMenuItem.setText("Redo");
972 public void addHistoryItem(CommandI command)
974 if(command.getSize()>0)
976 viewport.historyList.push(command);
977 viewport.redoList.clear();
979 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
988 * @param e DOCUMENT ME!
990 protected void undoMenuItem_actionPerformed(ActionEvent e)
992 CommandI command = (CommandI)viewport.historyList.pop();
993 viewport.redoList.push(command);
994 command.undoCommand();
996 AlignViewport originalSource = getOriginatingSource(command);
999 if(originalSource!=null)
1001 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1002 originalSource.firePropertyChange("alignment",
1004 originalSource.alignment.getSequences());
1011 * @param e DOCUMENT ME!
1013 protected void redoMenuItem_actionPerformed(ActionEvent e)
1015 if(viewport.redoList.size()<1)
1018 CommandI command = (CommandI) viewport.redoList.pop();
1019 viewport.historyList.push(command);
1020 command.doCommand();
1022 AlignViewport originalSource = getOriginatingSource(command);
1023 updateEditMenuBar();
1025 if(originalSource!=null)
1027 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1028 originalSource.firePropertyChange("alignment",
1030 originalSource.alignment.getSequences());
1034 AlignViewport getOriginatingSource(CommandI command)
1036 AlignViewport originalSource = null;
1037 //For sequence removal and addition, we need to fire
1038 //the property change event FROM the viewport where the
1039 //original alignment was altered
1041 if (command instanceof EditCommand)
1043 EditCommand editCommand = (EditCommand) command;
1044 al = editCommand.getAlignment();
1045 Vector comps = (Vector) PaintRefresher.components
1046 .get(viewport.getSequenceSetId());
1048 for (int i = 0; i < comps.size(); i++)
1050 if (comps.elementAt(i) instanceof AlignmentPanel)
1052 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1054 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1061 if (originalSource == null)
1063 //The original view is closed, we must validate
1064 //the current view against the closed view first
1066 PaintRefresher.validateSequences(al, viewport.alignment);
1068 originalSource = viewport;
1071 return originalSource;
1077 * @param up DOCUMENT ME!
1079 public void moveSelectedSequences(boolean up)
1081 SequenceGroup sg = viewport.getSelectionGroup();
1090 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1092 SequenceI seq = viewport.alignment.getSequenceAt(i);
1094 if (!sg.getSequences(null).contains(seq))
1099 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1101 if (sg.getSequences(null).contains(temp))
1106 viewport.alignment.getSequences().setElementAt(temp, i);
1107 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1112 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1114 SequenceI seq = viewport.alignment.getSequenceAt(i);
1116 if (!sg.getSequences(null).contains(seq))
1121 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1123 if (sg.getSequences(null).contains(temp))
1128 viewport.alignment.getSequences().setElementAt(temp, i);
1129 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1133 alignPanel.repaint();
1141 * @param e DOCUMENT ME!
1143 protected void copy_actionPerformed(ActionEvent e)
1146 if (viewport.getSelectionGroup() == null)
1151 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1152 String[] omitHidden = null;
1154 if (viewport.hasHiddenColumns)
1156 omitHidden = viewport.getViewAsString(true);
1159 String output = new FormatAdapter().formatSequences(
1164 StringSelection ss = new StringSelection(output);
1168 jalview.gui.Desktop.internalCopy = true;
1169 //Its really worth setting the clipboard contents
1170 //to empty before setting the large StringSelection!!
1171 Toolkit.getDefaultToolkit().getSystemClipboard()
1172 .setContents(new StringSelection(""), null);
1174 Toolkit.getDefaultToolkit().getSystemClipboard()
1175 .setContents(ss, Desktop.instance);
1177 catch (OutOfMemoryError er)
1179 er.printStackTrace();
1180 javax.swing.SwingUtilities.invokeLater(new Runnable()
1184 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1185 "Out of memory copying region!!"
1187 "\nSee help files for increasing Java Virtual Machine memory."
1189 javax.swing.JOptionPane.WARNING_MESSAGE);
1196 Vector hiddenColumns = null;
1197 if(viewport.hasHiddenColumns)
1199 hiddenColumns =new Vector();
1200 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1201 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1203 int[] region = (int[])
1204 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1206 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1207 region[1]-hiddenOffset});
1213 Desktop.jalviewClipboard = new Object[]{ seqs,
1214 viewport.alignment.getDataset(),
1216 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1222 * @param e DOCUMENT ME!
1224 protected void pasteNew_actionPerformed(ActionEvent e)
1232 * @param e DOCUMENT ME!
1234 protected void pasteThis_actionPerformed(ActionEvent e)
1242 * @param newAlignment DOCUMENT ME!
1244 void paste(boolean newAlignment)
1248 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1249 Transferable contents = c.getContents(this);
1251 if (contents == null)
1259 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1260 if (str.length() < 1)
1263 format = new IdentifyFile().Identify(str, "Paste");
1266 catch (OutOfMemoryError er)
1268 er.printStackTrace();
1269 javax.swing.SwingUtilities.invokeLater(new Runnable()
1273 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1274 "Out of memory pasting sequences!!"
1276 "\nSee help files for increasing Java Virtual Machine memory."
1278 javax.swing.JOptionPane.WARNING_MESSAGE);
1285 SequenceI[] sequences;
1288 if(Desktop.jalviewClipboard!=null)
1290 // The clipboard was filled from within Jalview, we must use the sequences
1291 // And dataset from the copied alignment
1292 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1296 sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray();
1299 AlignmentI alignment = null;
1303 alignment = new Alignment(sequences);
1305 if (Desktop.jalviewClipboard != null)
1306 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1308 alignment.setDataset(null);
1312 alignment = viewport.getAlignment();
1315 SequenceI [] newseqs = new SequenceI[sequences.length];
1316 for (int i = 0; i < sequences.length; i++)
1318 newseqs[i] = new Sequence(sequences[i].getName(),
1319 sequences[i].getSequence(), sequences[i].getStart(),
1320 sequences[i].getEnd());
1322 alignment.addSequence(newseqs[i]);
1328 addHistoryItem(new EditCommand(
1333 alignment.getWidth(),
1338 viewport.setEndSeq(alignment.getHeight());
1339 alignment.getWidth();
1340 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1345 // Add any annotations attached to sequences
1346 for (int i = 0; i < sequences.length; i++)
1348 if (sequences[i].getAnnotation() != null)
1350 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1352 AlignmentAnnotation newAnnot =
1353 new AlignmentAnnotation(
1354 sequences[i].getAnnotation()[a].label,
1355 sequences[i].getAnnotation()[a].description,
1356 sequences[i].getAnnotation()[a].annotations,
1357 sequences[i].getAnnotation()[a].graphMin,
1358 sequences[i].getAnnotation()[a].graphMax,
1359 sequences[i].getAnnotation()[a].graph);
1361 sequences[i].getAnnotation()[a] = newAnnot;
1362 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1364 newAnnot.sequenceRef = sequences[i];
1365 newAnnot.adjustForAlignment();
1366 alignment.addAnnotation(newAnnot);
1367 alignment.setAnnotationIndex(newAnnot, a);
1370 alignPanel.annotationPanel.adjustPanelHeight();
1376 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1377 String newtitle = new String("Copied sequences");
1379 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1381 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1382 for(int i=0; i<hc.size(); i++)
1384 int [] region = (int[]) hc.elementAt(i);
1385 af.viewport.hideColumns(region[0], region[1]);
1390 //>>>This is a fix for the moment, until a better solution is found!!<<<
1391 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1392 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1395 if (title.startsWith("Copied sequences"))
1401 newtitle = newtitle.concat("- from " + title);
1404 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1411 catch (Exception ex)
1413 ex.printStackTrace();
1414 System.out.println("Exception whilst pasting: "+ex);
1415 // could be anything being pasted in here
1424 * @param e DOCUMENT ME!
1426 protected void cut_actionPerformed(ActionEvent e)
1428 copy_actionPerformed(null);
1429 delete_actionPerformed(null);
1435 * @param e DOCUMENT ME!
1437 protected void delete_actionPerformed(ActionEvent evt)
1440 SequenceGroup sg = viewport.getSelectionGroup();
1446 Vector seqs = new Vector();
1448 for (int i = 0; i < sg.getSize(); i++)
1450 seq = sg.getSequenceAt(i);
1451 seqs.addElement(seq);
1455 // If the cut affects all sequences, remove highlighted columns
1456 if (sg.getSize() == viewport.alignment.getHeight())
1458 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1459 sg.getEndRes() + 1);
1463 SequenceI [] cut = new SequenceI[seqs.size()];
1464 for(int i=0; i<seqs.size(); i++)
1465 cut[i] = (SequenceI)seqs.elementAt(i);
1471 addHistoryItem(new EditCommand("Cut Sequences",
1475 sg.getEndRes()-sg.getStartRes()+1,
1476 viewport.alignment));
1479 viewport.setSelectionGroup(null);
1480 viewport.alignment.deleteGroup(sg);
1482 viewport.firePropertyChange("alignment", null,
1483 viewport.getAlignment().getSequences());
1485 if (viewport.getAlignment().getHeight() < 1)
1489 this.setClosed(true);
1491 catch (Exception ex)
1500 * @param e DOCUMENT ME!
1502 protected void deleteGroups_actionPerformed(ActionEvent e)
1504 viewport.alignment.deleteAllGroups();
1505 viewport.sequenceColours = null;
1506 viewport.setSelectionGroup(null);
1507 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1508 alignPanel.repaint();
1514 * @param e DOCUMENT ME!
1516 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1518 SequenceGroup sg = new SequenceGroup();
1520 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1523 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1526 sg.setEndRes(viewport.alignment.getWidth() - 1);
1527 viewport.setSelectionGroup(sg);
1528 alignPanel.repaint();
1529 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1535 * @param e DOCUMENT ME!
1537 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1539 if(viewport.cursorMode)
1541 alignPanel.seqPanel.keyboardNo1 = null;
1542 alignPanel.seqPanel.keyboardNo2 = null;
1544 viewport.setSelectionGroup(null);
1545 viewport.getColumnSelection().clear();
1546 viewport.setSelectionGroup(null);
1547 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1548 alignPanel.idPanel.idCanvas.searchResults = null;
1549 alignPanel.repaint();
1550 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1556 * @param e DOCUMENT ME!
1558 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1560 SequenceGroup sg = viewport.getSelectionGroup();
1564 selectAllSequenceMenuItem_actionPerformed(null);
1569 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1572 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1575 alignPanel.repaint();
1577 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1580 public void invertColSel_actionPerformed(ActionEvent e)
1582 viewport.invertColumnSelection();
1583 alignPanel.repaint();
1590 * @param e DOCUMENT ME!
1592 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1594 trimAlignment(true);
1600 * @param e DOCUMENT ME!
1602 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1604 trimAlignment(false);
1607 void trimAlignment(boolean trimLeft)
1609 ColumnSelection colSel = viewport.getColumnSelection();
1612 if (colSel.size() > 0)
1615 column = colSel.getMin();
1617 column = colSel.getMax();
1620 if(viewport.getSelectionGroup()!=null)
1621 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1623 seqs = viewport.alignment.getSequencesArray();
1626 TrimRegionCommand trimRegion;
1629 trimRegion = new TrimRegionCommand("Remove Left",
1630 TrimRegionCommand.TRIM_LEFT,
1635 viewport.selectionGroup);
1636 viewport.setStartRes(0);
1640 trimRegion = new TrimRegionCommand("Remove Right",
1641 TrimRegionCommand.TRIM_RIGHT,
1646 viewport.selectionGroup);
1649 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1652 addHistoryItem(trimRegion);
1654 Vector groups = viewport.alignment.getGroups();
1656 for (int i = 0; i < groups.size(); i++)
1658 SequenceGroup sg = (SequenceGroup) groups.get(i);
1660 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1661 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1663 viewport.alignment.deleteGroup(sg);
1667 viewport.firePropertyChange("alignment", null,
1668 viewport.getAlignment().getSequences());
1675 * @param e DOCUMENT ME!
1677 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1679 int start = 0, end = viewport.alignment.getWidth()-1;
1682 if (viewport.getSelectionGroup() != null)
1684 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1685 start = viewport.getSelectionGroup().getStartRes();
1686 end = viewport.getSelectionGroup().getEndRes();
1689 seqs = viewport.alignment.getSequencesArray();
1692 RemoveGapColCommand removeGapCols =
1693 new RemoveGapColCommand("Remove Gapped Columns",
1696 viewport.alignment);
1698 addHistoryItem(removeGapCols);
1700 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1702 //This is to maintain viewport position on first residue
1704 SequenceI seq = viewport.alignment.getSequenceAt(0);
1705 int startRes = seq.findPosition(viewport.startRes);
1706 // ShiftList shifts;
1707 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1708 // edit.alColumnChanges=shifts.getInverse();
1709 // if (viewport.hasHiddenColumns)
1710 // viewport.getColumnSelection().compensateForEdits(shifts);
1711 viewport.setStartRes(seq.findIndex(startRes)-1);
1712 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1719 * @param e DOCUMENT ME!
1721 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1723 int start = 0, end = viewport.alignment.getWidth()-1;
1726 if (viewport.getSelectionGroup() != null)
1728 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1729 start = viewport.getSelectionGroup().getStartRes();
1730 end = viewport.getSelectionGroup().getEndRes();
1733 seqs = viewport.alignment.getSequencesArray();
1735 //This is to maintain viewport position on first residue
1737 SequenceI seq = viewport.alignment.getSequenceAt(0);
1738 int startRes = seq.findPosition(viewport.startRes);
1740 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1743 viewport.alignment));
1745 viewport.setStartRes(seq.findIndex(startRes)-1);
1747 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1754 * @param e DOCUMENT ME!
1756 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1758 viewport.padGaps = padGapsMenuitem.isSelected();
1760 viewport.firePropertyChange("alignment",
1762 viewport.getAlignment().getSequences());
1768 * @param e DOCUMENT ME!
1770 public void findMenuItem_actionPerformed(ActionEvent e)
1775 public void newView_actionPerformed(ActionEvent e)
1777 AlignmentPanel newap =
1778 new Jalview2XML().copyAlignPanel(alignPanel, true);
1780 if (viewport.viewName == null)
1781 viewport.viewName = "Original";
1783 newap.av.historyList = viewport.historyList;
1784 newap.av.redoList = viewport.redoList;
1786 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1787 String newViewName = "View " +index;
1789 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1790 Vector existingNames = new Vector();
1791 for(int i=0; i<comps.size(); i++)
1793 if(comps.elementAt(i) instanceof AlignmentPanel)
1795 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1796 if(!existingNames.contains(ap.av.viewName))
1797 existingNames.addElement(ap.av.viewName);
1801 while(existingNames.contains(newViewName))
1803 newViewName = "View "+ (++index);
1806 newap.av.viewName = newViewName;
1808 addAlignmentPanel(newap, false);
1810 if(alignPanels.size()==2)
1812 viewport.gatherViewsHere = true;
1814 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1817 public void expandViews_actionPerformed(ActionEvent e)
1819 Desktop.instance.explodeViews(this);
1822 public void gatherViews_actionPerformed(ActionEvent e)
1824 Desktop.instance.gatherViews(this);
1832 * @param e DOCUMENT ME!
1834 public void font_actionPerformed(ActionEvent e)
1836 new FontChooser(alignPanel);
1843 * @param e DOCUMENT ME!
1845 protected void seqLimit_actionPerformed(ActionEvent e)
1847 viewport.setShowJVSuffix(seqLimits.isSelected());
1849 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1850 alignPanel.repaint();
1853 public void idRightAlign_actionPerformed(ActionEvent e)
1855 viewport.rightAlignIds = idRightAlign.isSelected();
1856 alignPanel.repaint();
1864 * @param e DOCUMENT ME!
1866 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1868 viewport.setColourText(colourTextMenuItem.isSelected());
1869 alignPanel.repaint();
1875 * @param e DOCUMENT ME!
1877 public void wrapMenuItem_actionPerformed(ActionEvent e)
1879 scaleAbove.setVisible(wrapMenuItem.isSelected());
1880 scaleLeft.setVisible(wrapMenuItem.isSelected());
1881 scaleRight.setVisible(wrapMenuItem.isSelected());
1882 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1883 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1886 public void showAllSeqs_actionPerformed(ActionEvent e)
1888 viewport.showAllHiddenSeqs();
1891 public void showAllColumns_actionPerformed(ActionEvent e)
1893 viewport.showAllHiddenColumns();
1897 public void hideSelSequences_actionPerformed(ActionEvent e)
1899 viewport.hideAllSelectedSeqs();
1900 alignPanel.repaint();
1903 public void hideSelColumns_actionPerformed(ActionEvent e)
1905 viewport.hideSelectedColumns();
1906 alignPanel.repaint();
1909 public void hiddenMarkers_actionPerformed(ActionEvent e)
1911 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1918 * @param e DOCUMENT ME!
1920 protected void scaleAbove_actionPerformed(ActionEvent e)
1922 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1923 alignPanel.repaint();
1929 * @param e DOCUMENT ME!
1931 protected void scaleLeft_actionPerformed(ActionEvent e)
1933 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1934 alignPanel.repaint();
1940 * @param e DOCUMENT ME!
1942 protected void scaleRight_actionPerformed(ActionEvent e)
1944 viewport.setScaleRightWrapped(scaleRight.isSelected());
1945 alignPanel.repaint();
1951 * @param e DOCUMENT ME!
1953 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1955 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1956 alignPanel.repaint();
1962 * @param e DOCUMENT ME!
1964 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1966 viewport.setShowText(viewTextMenuItem.isSelected());
1967 alignPanel.repaint();
1973 * @param e DOCUMENT ME!
1975 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1977 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1978 alignPanel.repaint();
1982 public FeatureSettings featureSettings;
1983 public void featureSettings_actionPerformed(ActionEvent e)
1985 if(featureSettings !=null )
1987 featureSettings.close();
1988 featureSettings = null;
1990 featureSettings = new FeatureSettings(this);
1996 * @param evt DOCUMENT ME!
1998 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2000 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2001 alignPanel.repaint();
2002 if (alignPanel.getOverviewPanel() != null)
2004 alignPanel.getOverviewPanel().updateOverviewImage();
2011 * @param e DOCUMENT ME!
2013 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2015 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2016 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2022 * @param e DOCUMENT ME!
2024 public void overviewMenuItem_actionPerformed(ActionEvent e)
2026 if (alignPanel.overviewPanel != null)
2031 JInternalFrame frame = new JInternalFrame();
2032 OverviewPanel overview = new OverviewPanel(alignPanel);
2033 frame.setContentPane(overview);
2034 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2035 frame.getWidth(), frame.getHeight());
2037 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2038 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2040 public void internalFrameClosed(
2041 javax.swing.event.InternalFrameEvent evt)
2043 alignPanel.setOverviewPanel(null);
2048 alignPanel.setOverviewPanel(overview);
2051 public void textColour_actionPerformed(ActionEvent e)
2053 new TextColourChooser().chooseColour(alignPanel, null);
2059 * @param e DOCUMENT ME!
2061 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2069 * @param e DOCUMENT ME!
2071 public void clustalColour_actionPerformed(ActionEvent e)
2073 changeColour(new ClustalxColourScheme(
2074 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2080 * @param e DOCUMENT ME!
2082 public void zappoColour_actionPerformed(ActionEvent e)
2084 changeColour(new ZappoColourScheme());
2090 * @param e DOCUMENT ME!
2092 public void taylorColour_actionPerformed(ActionEvent e)
2094 changeColour(new TaylorColourScheme());
2100 * @param e DOCUMENT ME!
2102 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2104 changeColour(new HydrophobicColourScheme());
2110 * @param e DOCUMENT ME!
2112 public void helixColour_actionPerformed(ActionEvent e)
2114 changeColour(new HelixColourScheme());
2120 * @param e DOCUMENT ME!
2122 public void strandColour_actionPerformed(ActionEvent e)
2124 changeColour(new StrandColourScheme());
2130 * @param e DOCUMENT ME!
2132 public void turnColour_actionPerformed(ActionEvent e)
2134 changeColour(new TurnColourScheme());
2140 * @param e DOCUMENT ME!
2142 public void buriedColour_actionPerformed(ActionEvent e)
2144 changeColour(new BuriedColourScheme());
2150 * @param e DOCUMENT ME!
2152 public void nucleotideColour_actionPerformed(ActionEvent e)
2154 changeColour(new NucleotideColourScheme());
2157 public void annotationColour_actionPerformed(ActionEvent e)
2159 new AnnotationColourChooser(viewport, alignPanel);
2166 * @param e DOCUMENT ME!
2168 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2170 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2176 * @param cs DOCUMENT ME!
2178 public void changeColour(ColourSchemeI cs)
2184 if (viewport.getAbovePIDThreshold())
2186 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2189 cs.setThreshold(threshold,
2190 viewport.getIgnoreGapsConsensus());
2192 viewport.setGlobalColourScheme(cs);
2196 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2199 if (viewport.getConservationSelected())
2202 Alignment al = (Alignment) viewport.alignment;
2203 Conservation c = new Conservation("All",
2204 ResidueProperties.propHash, 3,
2205 al.getSequences(), 0,
2209 c.verdict(false, viewport.ConsPercGaps);
2211 cs.setConservation(c);
2213 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2218 cs.setConservation(null);
2221 cs.setConsensus(viewport.hconsensus);
2224 viewport.setGlobalColourScheme(cs);
2226 if (viewport.getColourAppliesToAllGroups())
2228 Vector groups = viewport.alignment.getGroups();
2230 for (int i = 0; i < groups.size(); i++)
2232 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2240 if (cs instanceof ClustalxColourScheme)
2242 sg.cs = new ClustalxColourScheme(
2243 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2245 else if (cs instanceof UserColourScheme)
2247 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2253 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2255 catch (Exception ex)
2260 if (viewport.getAbovePIDThreshold()
2261 || cs instanceof PIDColourScheme
2262 || cs instanceof Blosum62ColourScheme)
2264 sg.cs.setThreshold(threshold,
2265 viewport.getIgnoreGapsConsensus());
2267 sg.cs.setConsensus(AAFrequency.calculate(
2268 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2272 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2275 if (viewport.getConservationSelected())
2277 Conservation c = new Conservation("Group",
2278 ResidueProperties.propHash, 3,
2279 sg.getSequences(viewport.hiddenRepSequences),
2283 c.verdict(false, viewport.ConsPercGaps);
2284 sg.cs.setConservation(c);
2287 sg.cs.setConservation(null);
2291 if (alignPanel.getOverviewPanel() != null)
2293 alignPanel.getOverviewPanel().updateOverviewImage();
2296 alignPanel.repaint();
2302 * @param e DOCUMENT ME!
2304 protected void modifyPID_actionPerformed(ActionEvent e)
2306 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2308 SliderPanel.setPIDSliderSource(alignPanel,
2309 viewport.getGlobalColourScheme(),
2311 SliderPanel.showPIDSlider();
2318 * @param e DOCUMENT ME!
2320 protected void modifyConservation_actionPerformed(ActionEvent e)
2322 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2324 SliderPanel.setConservationSlider(alignPanel,
2325 viewport.globalColourScheme,
2327 SliderPanel.showConservationSlider();
2334 * @param e DOCUMENT ME!
2336 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2338 viewport.setConservationSelected(conservationMenuItem.isSelected());
2340 viewport.setAbovePIDThreshold(false);
2341 abovePIDThreshold.setSelected(false);
2343 changeColour(viewport.getGlobalColourScheme());
2345 modifyConservation_actionPerformed(null);
2351 * @param e DOCUMENT ME!
2353 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2355 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2357 conservationMenuItem.setSelected(false);
2358 viewport.setConservationSelected(false);
2360 changeColour(viewport.getGlobalColourScheme());
2362 modifyPID_actionPerformed(null);
2368 * @param e DOCUMENT ME!
2370 public void userDefinedColour_actionPerformed(ActionEvent e)
2372 if (e.getActionCommand().equals("User Defined..."))
2374 new UserDefinedColours(alignPanel, null);
2378 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2379 getUserColourSchemes().get(e.getActionCommand());
2385 public void updateUserColourMenu()
2388 Component[] menuItems = colourMenu.getMenuComponents();
2389 int i, iSize = menuItems.length;
2390 for (i = 0; i < iSize; i++)
2392 if (menuItems[i].getName() != null &&
2393 menuItems[i].getName().equals("USER_DEFINED"))
2395 colourMenu.remove(menuItems[i]);
2399 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2401 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2402 getUserColourSchemes().keys();
2404 while (userColours.hasMoreElements())
2406 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2407 nextElement().toString());
2408 radioItem.setName("USER_DEFINED");
2409 radioItem.addMouseListener(new MouseAdapter()
2411 public void mousePressed(MouseEvent evt)
2413 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2415 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2417 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2418 "Remove from default list?",
2419 "Remove user defined colour",
2420 JOptionPane.YES_NO_OPTION);
2421 if(option == JOptionPane.YES_OPTION)
2423 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2424 colourMenu.remove(radioItem);
2427 radioItem.addActionListener(new ActionListener()
2429 public void actionPerformed(ActionEvent evt)
2431 userDefinedColour_actionPerformed(evt);
2437 radioItem.addActionListener(new ActionListener()
2439 public void actionPerformed(ActionEvent evt)
2441 userDefinedColour_actionPerformed(evt);
2445 colourMenu.insert(radioItem, 15);
2446 colours.add(radioItem);
2454 * @param e DOCUMENT ME!
2456 public void PIDColour_actionPerformed(ActionEvent e)
2458 changeColour(new PIDColourScheme());
2464 * @param e DOCUMENT ME!
2466 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2468 changeColour(new Blosum62ColourScheme());
2474 * @param e DOCUMENT ME!
2476 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2478 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2479 AlignmentSorter.sortByPID(viewport.getAlignment(),
2480 viewport.getAlignment().getSequenceAt(0));
2481 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2482 alignPanel.repaint();
2488 * @param e DOCUMENT ME!
2490 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2492 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2493 AlignmentSorter.sortByID(viewport.getAlignment());
2494 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2495 alignPanel.repaint();
2501 * @param e DOCUMENT ME!
2503 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2505 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2506 AlignmentSorter.sortByGroup(viewport.getAlignment());
2507 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2509 alignPanel.repaint();
2515 * @param e DOCUMENT ME!
2517 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2519 new RedundancyPanel(alignPanel, this);
2526 * @param e DOCUMENT ME!
2528 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2530 if ( (viewport.getSelectionGroup() == null) ||
2531 (viewport.getSelectionGroup().getSize() < 2))
2533 JOptionPane.showInternalMessageDialog(this,
2534 "You must select at least 2 sequences.",
2535 "Invalid Selection",
2536 JOptionPane.WARNING_MESSAGE);
2540 JInternalFrame frame = new JInternalFrame();
2541 frame.setContentPane(new PairwiseAlignPanel(viewport));
2542 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2549 * @param e DOCUMENT ME!
2551 public void PCAMenuItem_actionPerformed(ActionEvent e)
2553 if ( ( (viewport.getSelectionGroup() != null) &&
2554 (viewport.getSelectionGroup().getSize() < 4) &&
2555 (viewport.getSelectionGroup().getSize() > 0)) ||
2556 (viewport.getAlignment().getHeight() < 4))
2558 JOptionPane.showInternalMessageDialog(this,
2559 "Principal component analysis must take\n" +
2560 "at least 4 input sequences.",
2561 "Sequence selection insufficient",
2562 JOptionPane.WARNING_MESSAGE);
2567 new PCAPanel(alignPanel);
2571 public void autoCalculate_actionPerformed(ActionEvent e)
2573 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2574 if(viewport.autoCalculateConsensus)
2576 viewport.firePropertyChange("alignment",
2578 viewport.getAlignment().getSequences());
2586 * @param e DOCUMENT ME!
2588 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2590 NewTreePanel("AV", "PID", "Average distance tree using PID");
2596 * @param e DOCUMENT ME!
2598 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2600 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2606 * @param e DOCUMENT ME!
2608 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2610 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2616 * @param e DOCUMENT ME!
2618 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2620 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2626 * @param type DOCUMENT ME!
2627 * @param pwType DOCUMENT ME!
2628 * @param title DOCUMENT ME!
2630 void NewTreePanel(String type, String pwType, String title)
2634 if (viewport.getSelectionGroup() != null) {
2635 if (viewport.getSelectionGroup().getSize() < 3) {
2636 JOptionPane.showMessageDialog(Desktop.desktop,
2637 "You need to have more than two sequences selected to build a tree!",
2638 "Not enough sequences",
2639 JOptionPane.WARNING_MESSAGE);
2644 SequenceGroup sg = viewport.getSelectionGroup();
2646 /* Decide if the selection is a column region */
2647 while (s < sg.getSize())
2649 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2652 JOptionPane.showMessageDialog(Desktop.desktop,
2653 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2654 "Try using the Pad function in the edit menu,\n" +
2655 "or one of the multiple sequence alignment web services.",
2656 "Sequences in selection are not aligned",
2657 JOptionPane.WARNING_MESSAGE);
2663 title = title + " on region";
2664 tp = new TreePanel(alignPanel, type, pwType);
2668 //are the sequences aligned?
2669 if (!viewport.alignment.isAligned())
2671 JOptionPane.showMessageDialog(Desktop.desktop,
2672 "The sequences must be aligned before creating a tree.\n" +
2673 "Try using the Pad function in the edit menu,\n" +
2674 "or one of the multiple sequence alignment web services.",
2675 "Sequences not aligned",
2676 JOptionPane.WARNING_MESSAGE);
2681 if(viewport.alignment.getHeight()<2)
2684 tp = new TreePanel(alignPanel, type, pwType);
2689 if(viewport.viewName!=null)
2690 title+= viewport.viewName+" of ";
2692 title += this.title;
2694 Desktop.addInternalFrame(tp, title, 600, 500);
2700 * @param title DOCUMENT ME!
2701 * @param order DOCUMENT ME!
2703 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2705 final JMenuItem item = new JMenuItem("by " + title);
2707 item.addActionListener(new java.awt.event.ActionListener()
2709 public void actionPerformed(ActionEvent e)
2711 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2713 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2714 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2716 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2718 alignPanel.repaint();
2724 * Maintain the Order by->Displayed Tree menu.
2725 * Creates a new menu item for a TreePanel with an appropriate
2726 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2727 * to remove the menu item when the treePanel is closed, and adjust
2728 * the tree leaf to sequence mapping when the alignment is modified.
2729 * @param treePanel Displayed tree window.
2730 * @param title SortBy menu item title.
2732 public void buildTreeMenu()
2734 sortByTreeMenu.removeAll();
2736 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2737 Vector treePanels = new Vector();
2738 int i, iSize = comps.size();
2739 for(i=0; i<iSize; i++)
2741 if(comps.elementAt(i) instanceof TreePanel)
2743 treePanels.add(comps.elementAt(i));
2747 iSize = treePanels.size();
2751 sortByTreeMenu.setVisible(false);
2755 sortByTreeMenu.setVisible(true);
2757 for(i=0; i<treePanels.size(); i++)
2759 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2760 final JMenuItem item = new JMenuItem(tp.getTitle());
2761 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2762 item.addActionListener(new java.awt.event.ActionListener()
2764 public void actionPerformed(ActionEvent e)
2766 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2767 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2769 addHistoryItem(new OrderCommand("Tree Sort",
2771 viewport.alignment));
2773 alignPanel.repaint();
2777 sortByTreeMenu.add(item);
2782 * Work out whether the whole set of sequences
2783 * or just the selected set will be submitted for multiple alignment.
2786 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2788 // Now, check we have enough sequences
2789 AlignmentView msa = null;
2791 if ( (viewport.getSelectionGroup() != null) &&
2792 (viewport.getSelectionGroup().getSize() > 1))
2794 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2795 /*SequenceGroup seqs = viewport.getSelectionGroup();
2797 msa = new SequenceI[sz = seqs.getSize(false)];
2799 for (int i = 0; i < sz; i++)
2801 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2803 msa = viewport.getAlignmentView(true);
2807 /*Vector seqs = viewport.getAlignment().getSequences();
2809 if (seqs.size() > 1)
2811 msa = new SequenceI[seqs.size()];
2813 for (int i = 0; i < seqs.size(); i++)
2815 msa[i] = (SequenceI) seqs.elementAt(i);
2818 msa = viewport.getAlignmentView(false);
2824 * Decides what is submitted to a secondary structure prediction service,
2825 * the currently selected sequence, or the currently selected alignment
2826 * (where the first sequence in the set is the one that the prediction
2829 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2831 AlignmentView seqs = null;
2833 if ( (viewport.getSelectionGroup() != null) &&
2834 (viewport.getSelectionGroup().getSize() > 0))
2836 seqs = viewport.getAlignmentView(true);
2840 seqs = viewport.getAlignmentView(false);
2842 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2843 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2844 if (!viewport.alignment.isAligned())
2846 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2853 * @param e DOCUMENT ME!
2855 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2857 // Pick the tree file
2858 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2861 chooser.setFileView(new JalviewFileView());
2862 chooser.setDialogTitle("Select a newick-like tree file");
2863 chooser.setToolTipText("Load a tree file");
2865 int value = chooser.showOpenDialog(null);
2867 if (value == JalviewFileChooser.APPROVE_OPTION)
2869 String choice = chooser.getSelectedFile().getPath();
2870 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2874 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2876 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2878 catch (Exception ex)
2880 JOptionPane.showMessageDialog(Desktop.desktop,
2881 "Problem reading tree file",
2883 JOptionPane.WARNING_MESSAGE);
2884 ex.printStackTrace();
2890 public TreePanel ShowNewickTree(NewickFile nf, String title)
2892 return ShowNewickTree(nf,title,600,500,4,5);
2894 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2896 return ShowNewickTree(nf,title, input, 600,500,4,5);
2898 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2899 return ShowNewickTree(nf, title, null, w, h, x, y);
2902 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2904 * @param nf the tree
2905 * @param title tree viewer title
2906 * @param input Associated alignment input data (or null)
2911 * @return TreePanel handle
2913 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2914 TreePanel tp = null;
2920 if (nf.getTree() != null)
2922 tp = new TreePanel(alignPanel,
2930 tp.setLocation(x,y);
2933 Desktop.addInternalFrame(tp, title, w, h);
2936 catch (Exception ex)
2938 ex.printStackTrace();
2946 * Generates menu items and listener event actions for web service clients
2949 public void BuildWebServiceMenu()
2951 if ( (Discoverer.services != null)
2952 && (Discoverer.services.size() > 0))
2954 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2955 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2956 Vector wsmenu = new Vector();
2957 final AlignFrame af = this;
2960 // Add any Multiple Sequence Alignment Services
2961 final JMenu msawsmenu = new JMenu("Alignment");
2962 for (int i = 0, j = msaws.size(); i < j; i++)
2964 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2966 final JMenuItem method = new JMenuItem(sh.getName());
2967 method.addActionListener(new ActionListener()
2969 public void actionPerformed(ActionEvent e)
2971 AlignmentView msa = gatherSequencesForAlignment();
2972 new jalview.ws.MsaWSClient(sh, title, msa,
2973 false, true, viewport.getAlignment().getDataset(), af);
2978 msawsmenu.add(method);
2979 // Deal with services that we know accept partial alignments.
2980 if (sh.getName().indexOf("lustal") > -1)
2982 // We know that ClustalWS can accept partial alignments for refinement.
2983 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2984 methodR.addActionListener(new ActionListener()
2986 public void actionPerformed(ActionEvent e)
2988 AlignmentView msa = gatherSequencesForAlignment();
2989 new jalview.ws.MsaWSClient(sh, title, msa,
2990 true, true, viewport.getAlignment().getDataset(), af);
2995 msawsmenu.add(methodR);
2999 wsmenu.add(msawsmenu);
3001 if (secstrpr != null)
3003 // Add any secondary structure prediction services
3004 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3005 for (int i = 0, j = secstrpr.size(); i < j; i++)
3007 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3009 final JMenuItem method = new JMenuItem(sh.getName());
3010 method.addActionListener(new ActionListener()
3012 public void actionPerformed(ActionEvent e)
3014 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3015 if (msa.getSequences().length == 1)
3017 // Single Sequence prediction
3018 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3022 if (msa.getSequences().length > 1)
3024 // Sequence profile based prediction
3025 new jalview.ws.JPredClient(sh,
3026 title, true, msa, af, true);
3031 secstrmenu.add(method);
3033 wsmenu.add(secstrmenu);
3035 this.webService.removeAll();
3036 for (int i = 0, j = wsmenu.size(); i < j; i++)
3038 webService.add( (JMenu) wsmenu.get(i));
3043 this.webService.removeAll();
3044 this.webService.add(this.webServiceNoServices);
3046 // TODO: add in rediscovery function
3047 // TODO: reduce code redundancy.
3048 // TODO: group services by location as well as function.
3051 /* public void vamsasStore_actionPerformed(ActionEvent e)
3053 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3054 getProperty("LAST_DIRECTORY"));
3056 chooser.setFileView(new JalviewFileView());
3057 chooser.setDialogTitle("Export to Vamsas file");
3058 chooser.setToolTipText("Export");
3060 int value = chooser.showSaveDialog(this);
3062 if (value == JalviewFileChooser.APPROVE_OPTION)
3064 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3065 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3066 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3073 public void showTranslation_actionPerformed(ActionEvent e)
3075 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3076 String [] seqstring = viewport.getViewAsString(true);
3078 int s, sSize = selection.length;
3079 SequenceI [] newSeq = new SequenceI[sSize];
3082 StringBuffer protein;
3084 for(s=0; s<sSize; s++)
3086 protein = new StringBuffer();
3087 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3088 resSize = seq.length();
3089 resSize -= resSize%3;
3091 for(res = 0; res < resSize; res+=3)
3093 String codon = seq.substring(res, res+3);
3094 codon = codon.replace('U', 'T');
3095 String aa = ResidueProperties.codonTranslate(codon);
3097 protein.append(viewport.getGapCharacter());
3098 else if(aa.equals("STOP"))
3099 protein.append("X");
3101 protein.append( aa );
3103 newSeq[s] = new Sequence(selection[s].getName(),
3104 protein.toString());
3108 AlignmentI al = new Alignment(newSeq);
3109 al.setDataset(null);
3112 ////////////////////////////////
3113 // Copy annotations across
3114 jalview.datamodel.AlignmentAnnotation[] annotations
3115 = viewport.alignment.getAlignmentAnnotation();
3117 if(annotations!=null)
3119 for (int i = 0; i < annotations.length; i++)
3121 if (annotations[i]==viewport.quality ||
3122 annotations[i]==viewport.conservation ||
3123 annotations[i]==viewport.consensus)
3125 System.out.println("COPT HERE");
3129 aSize = viewport.alignment.getWidth() / 3;
3130 jalview.datamodel.Annotation[] anots =
3131 new jalview.datamodel.Annotation[aSize];
3133 for (a = 0; a < viewport.alignment.getWidth(); a++)
3135 if (annotations[i].annotations[a] == null
3136 || annotations[i].annotations[a] == null)
3139 anots[a / 3] = new Annotation(
3140 annotations[i].annotations[a].displayCharacter,
3141 annotations[i].annotations[a].description,
3142 annotations[i].annotations[a].secondaryStructure,
3143 annotations[i].annotations[a].value,
3144 annotations[i].annotations[a].colour);
3147 jalview.datamodel.AlignmentAnnotation aa
3148 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3149 annotations[i].description, anots);
3150 al.addAnnotation(aa);
3154 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3155 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3167 * @param String DOCUMENT ME!
3169 public boolean parseFeaturesFile(String file, String type)
3171 boolean featuresFile = false;
3173 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3174 alignPanel.seqPanel.seqCanvas.
3175 getFeatureRenderer().featureColours,
3180 ex.printStackTrace();
3185 viewport.showSequenceFeatures = true;
3186 showSeqFeatures.setSelected(true);
3187 alignPanel.repaint();
3190 return featuresFile;
3193 public void dragEnter(DropTargetDragEvent evt)
3196 public void dragExit(DropTargetEvent evt)
3199 public void dragOver(DropTargetDragEvent evt)
3202 public void dropActionChanged(DropTargetDragEvent evt)
3205 public void drop(DropTargetDropEvent evt)
3207 Transferable t = evt.getTransferable();
3208 java.util.List files = null;
3212 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3213 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3215 //Works on Windows and MacOSX
3216 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3217 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3219 else if (t.isDataFlavorSupported(uriListFlavor))
3221 // This is used by Unix drag system
3222 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3223 String data = (String) t.getTransferData(uriListFlavor);
3224 files = new java.util.ArrayList(1);
3225 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3228 st.hasMoreTokens(); )
3230 String s = st.nextToken();
3231 if (s.startsWith("#"))
3233 // the line is a comment (as per the RFC 2483)
3237 java.net.URI uri = new java.net.URI(s);
3238 java.io.File file = new java.io.File(uri);
3245 e.printStackTrace();
3252 for (int i = 0; i < files.size(); i++)
3254 loadJalviewDataFile(files.get(i).toString());
3257 catch (Exception ex)
3259 ex.printStackTrace();
3264 // This method will attempt to load a "dropped" file first by testing
3265 // whether its and Annotation file, then features file. If both are
3266 // false then the user may have dropped an alignment file onto this
3268 public void loadJalviewDataFile(String file)
3271 String protocol = "File";
3273 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3278 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3279 alignment, file, protocol);
3283 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3286 String format = new IdentifyFile().Identify(file, protocol);
3288 if(format.equalsIgnoreCase("JnetFile"))
3290 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3292 new JnetAnnotationMaker().add_annotation(predictions,
3293 viewport.getAlignment(),
3295 alignPanel.adjustAnnotationHeight();
3296 alignPanel.repaint();
3299 new FileLoader().LoadFile(viewport, file, protocol, format);
3305 alignPanel.adjustAnnotationHeight();
3308 }catch(Exception ex)
3310 ex.printStackTrace();
3314 public void tabSelectionChanged(int index)
3318 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3319 viewport = alignPanel.av;
3320 setMenusFromViewport(viewport);
3324 public void tabbedPane_mousePressed(MouseEvent e)
3326 if(SwingUtilities.isRightMouseButton(e))
3328 String reply = JOptionPane.showInternalInputDialog(this,
3331 JOptionPane.QUESTION_MESSAGE);
3335 viewport.viewName = reply;
3336 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3342 public AlignViewport getCurrentView()
3348 class PrintThread extends Thread
3351 public PrintThread(AlignmentPanel ap)
3355 static PageFormat pf;
3358 PrinterJob printJob = PrinterJob.getPrinterJob();
3361 printJob.setPrintable(ap, pf);
3363 printJob.setPrintable(ap);
3365 if (printJob.printDialog())
3371 catch (Exception PrintException)
3373 PrintException.printStackTrace();