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();
62 String currentFileFormat = null;
64 String fileName = null;
68 * Creates a new AlignFrame object.
70 * @param al DOCUMENT ME!
72 public AlignFrame(AlignmentI al, int width, int height)
74 this(al, null, width, height);
79 * new alignment window with hidden columns
80 * @param al AlignmentI
81 * @param hiddenColumns ColumnSelection or null
83 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
84 int width, int height)
86 this.setSize(width, height);
87 viewport = new AlignViewport(al, hiddenColumns);
89 alignPanel = new AlignmentPanel(this, viewport);
91 if(al.getDataset()==null)
96 addAlignmentPanel(alignPanel, true);
101 * Make a new AlignFrame from exisiting alignmentPanels
102 * @param ap AlignmentPanel
103 * @param av AlignViewport
105 public AlignFrame(AlignmentPanel ap)
109 addAlignmentPanel(ap, false);
115 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
117 if (viewport.conservation == null)
119 BLOSUM62Colour.setEnabled(false);
120 conservationMenuItem.setEnabled(false);
121 modifyConservation.setEnabled(false);
122 // PIDColour.setEnabled(false);
123 // abovePIDThreshold.setEnabled(false);
124 // modifyPID.setEnabled(false);
127 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
129 if (sortby.equals("Id"))
131 sortIDMenuItem_actionPerformed(null);
133 else if (sortby.equals("Pairwise Identity"))
135 sortPairwiseMenuItem_actionPerformed(null);
138 if (Desktop.desktop != null)
140 addServiceListeners();
141 setGUINucleotide(viewport.alignment.isNucleotide());
144 setMenusFromViewport(viewport);
146 if (viewport.wrapAlignment)
148 wrapMenuItem_actionPerformed(null);
151 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
153 this.overviewMenuItem_actionPerformed(null);
160 public void setFileName(String file, String format)
163 currentFileFormat = format;
164 reload.setEnabled(true);
167 void addKeyListener()
169 addKeyListener(new KeyAdapter()
171 public void keyPressed(KeyEvent evt)
173 if (viewport.cursorMode &&
174 ( (evt.getKeyCode() >= KeyEvent.VK_0 &&
175 evt.getKeyCode() <= KeyEvent.VK_9)
177 (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 &&
178 evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)
180 && Character.isDigit(evt.getKeyChar()))
181 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
183 switch (evt.getKeyCode())
186 case 27: // escape key
187 deselectAllSequenceMenuItem_actionPerformed(null);
191 case KeyEvent.VK_DOWN:
192 if (evt.isAltDown() || !viewport.cursorMode)
193 moveSelectedSequences(false);
194 if (viewport.cursorMode)
195 alignPanel.seqPanel.moveCursor(0, 1);
199 if (evt.isAltDown() || !viewport.cursorMode)
200 moveSelectedSequences(true);
201 if (viewport.cursorMode)
202 alignPanel.seqPanel.moveCursor(0, -1);
206 case KeyEvent.VK_LEFT:
207 if (evt.isAltDown() || !viewport.cursorMode)
208 slideSequences(false,
209 alignPanel.seqPanel.getKeyboardNo1());
211 alignPanel.seqPanel.moveCursor( -1, 0);
216 case KeyEvent.VK_RIGHT:
217 if (evt.isAltDown() || !viewport.cursorMode)
219 alignPanel.seqPanel.getKeyboardNo1());
221 alignPanel.seqPanel.moveCursor(1, 0);
224 case KeyEvent.VK_SPACE:
225 if (viewport.cursorMode)
227 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
233 case KeyEvent.VK_DELETE:
234 case KeyEvent.VK_BACK_SPACE:
235 if (!viewport.cursorMode)
237 cut_actionPerformed(null);
241 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
249 if (viewport.cursorMode)
251 alignPanel.seqPanel.setCursorRow();
255 if (viewport.cursorMode && !evt.isControlDown())
257 alignPanel.seqPanel.setCursorColumn();
261 if (viewport.cursorMode)
263 alignPanel.seqPanel.setCursorPosition();
267 case KeyEvent.VK_ENTER:
268 case KeyEvent.VK_COMMA:
269 if (viewport.cursorMode)
271 alignPanel.seqPanel.setCursorRowAndColumn();
276 if (viewport.cursorMode)
278 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
282 if (viewport.cursorMode)
284 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
289 viewport.cursorMode = !viewport.cursorMode;
290 statusBar.setText("Keyboard editing mode is " +
291 (viewport.cursorMode ? "on" : "off"));
292 if (viewport.cursorMode)
294 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
295 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
297 alignPanel.seqPanel.seqCanvas.repaint();
303 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
304 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
305 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
307 javax.help.HelpBroker hb = hs.createHelpBroker();
308 hb.setCurrentID("home");
309 hb.setDisplayed(true);
313 ex.printStackTrace();
319 boolean toggleSeqs = !evt.isControlDown();
320 boolean toggleCols = !evt.isShiftDown();
322 boolean hide = false;
324 SequenceGroup sg = viewport.getSelectionGroup();
327 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
329 hideSelSequences_actionPerformed(null);
332 else if (! (toggleCols &&
333 viewport.colSel.getSelected().size() > 0))
335 showAllSeqs_actionPerformed(null);
341 if (viewport.colSel.getSelected().size() > 0)
343 hideSelColumns_actionPerformed(null);
346 viewport.selectionGroup = sg;
351 showAllColumns_actionPerformed(null);
356 case KeyEvent.VK_PAGE_UP:
357 if (viewport.wrapAlignment)
359 alignPanel.scrollUp(true);
363 alignPanel.setScrollValues(viewport.startRes,
365 - viewport.endSeq + viewport.startSeq);
368 case KeyEvent.VK_PAGE_DOWN:
369 if (viewport.wrapAlignment)
371 alignPanel.scrollUp(false);
375 alignPanel.setScrollValues(viewport.startRes,
377 + viewport.endSeq - viewport.startSeq);
383 public void keyReleased(KeyEvent evt)
385 switch(evt.getKeyCode())
387 case KeyEvent.VK_LEFT:
388 if (evt.isAltDown() || !viewport.cursorMode)
389 viewport.firePropertyChange("alignment", null,
390 viewport.getAlignment().getSequences());
393 case KeyEvent.VK_RIGHT:
394 if (evt.isAltDown() || !viewport.cursorMode)
395 viewport.firePropertyChange("alignment", null,
396 viewport.getAlignment().getSequences());
404 public void addAlignmentPanel(final AlignmentPanel ap,
407 ap.alignFrame = this;
409 alignPanels.addElement(ap);
411 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
413 int aSize = alignPanels.size();
415 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
417 if (aSize == 1 && ap.av.viewName==null)
419 this.getContentPane().add(ap, BorderLayout.CENTER);
425 setInitialTabVisible();
428 expandViews.setEnabled(true);
429 gatherViews.setEnabled(true);
430 tabbedPane.addTab(ap.av.viewName, ap);
432 ap.setVisible(false);
439 ap.av.alignment.padGaps();
441 ap.av.updateConservation(ap);
442 ap.av.updateConsensus(ap);
446 public void setInitialTabVisible()
448 expandViews.setEnabled(true);
449 gatherViews.setEnabled(true);
450 tabbedPane.setVisible(true);
451 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
452 tabbedPane.addTab(first.av.viewName,first);
453 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
457 public AlignViewport getViewport()
462 /* Set up intrinsic listeners for dynamically generated GUI bits. */
463 private void addServiceListeners()
465 final java.beans.PropertyChangeListener thisListener;
466 // Do this once to get current state
467 BuildWebServiceMenu();
468 Desktop.discoverer.addPropertyChangeListener(
469 thisListener = new java.beans.PropertyChangeListener()
471 public void propertyChange(PropertyChangeEvent evt)
473 // System.out.println("Discoverer property change.");
474 if (evt.getPropertyName().equals("services"))
476 // System.out.println("Rebuilding web service menu");
477 BuildWebServiceMenu();
482 addInternalFrameListener(new javax.swing.event.
483 InternalFrameAdapter()
485 public void internalFrameClosed(
486 javax.swing.event.InternalFrameEvent evt)
488 // System.out.println("deregistering discoverer listener");
489 Desktop.discoverer.removePropertyChangeListener(thisListener);
490 closeMenuItem_actionPerformed(true);
496 public void setGUINucleotide(boolean nucleotide)
498 showTranslation.setVisible( nucleotide );
499 conservationMenuItem.setEnabled( !nucleotide );
500 modifyConservation.setEnabled( !nucleotide );
502 //Remember AlignFrame always starts as protein
505 calculateMenu.remove(calculateMenu.getItemCount()-2);
510 * Need to call this method when tabs are selected for multiple views,
511 * or when loading from Jalview2XML.java
512 * @param av AlignViewport
514 void setMenusFromViewport(AlignViewport av)
516 padGapsMenuitem.setSelected(av.padGaps);
517 colourTextMenuItem.setSelected(av.showColourText);
518 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
519 conservationMenuItem.setSelected(av.getConservationSelected());
520 seqLimits.setSelected(av.getShowJVSuffix());
521 idRightAlign.setSelected(av.rightAlignIds);
522 renderGapsMenuItem.setSelected(av.renderGaps);
523 wrapMenuItem.setSelected(av.wrapAlignment);
524 scaleAbove.setVisible(av.wrapAlignment);
525 scaleLeft.setVisible(av.wrapAlignment);
526 scaleRight.setVisible(av.wrapAlignment);
527 annotationPanelMenuItem.setState(av.showAnnotation);
528 viewBoxesMenuItem.setSelected(av.showBoxes);
529 viewTextMenuItem.setSelected(av.showText);
531 setColourSelected(ColourSchemeProperty.
532 getColourName(av.getGlobalColourScheme()));
534 showSeqFeatures.setSelected(av.showSequenceFeatures);
535 hiddenMarkers.setState(av.showHiddenMarkers);
536 applyToAllGroups.setState(av.colourAppliesToAllGroups);
542 Hashtable progressBars;
543 public void setProgressBar(String message, long id)
545 if(progressBars == null)
547 progressBars = new Hashtable();
550 JPanel progressPanel;
551 GridLayout layout = (GridLayout) statusPanel.getLayout();
552 if(progressBars.get( new Long(id) )!=null)
554 progressPanel = (JPanel)progressBars.get( new Long(id) );
555 statusPanel.remove(progressPanel);
556 progressBars.remove( progressPanel );
557 progressPanel = null;
560 statusBar.setText(message);
563 layout.setRows(layout.getRows() - 1);
567 progressPanel = new JPanel(new BorderLayout(10, 5));
569 JProgressBar progressBar = new JProgressBar();
570 progressBar.setIndeterminate(true);
572 progressPanel.add(new JLabel(message), BorderLayout.WEST);
573 progressPanel.add(progressBar, BorderLayout.CENTER);
575 layout.setRows(layout.getRows() + 1);
576 statusPanel.add(progressPanel);
578 progressBars.put(new Long(id), progressPanel);
588 Added so Castor Mapping file can obtain Jalview Version
590 public String getVersion()
592 return jalview.bin.Cache.getProperty("VERSION");
595 public FeatureRenderer getFeatureRenderer()
597 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
601 public void fetchSequence_actionPerformed(ActionEvent e)
603 new SequenceFetcher(this);
606 public void addFromFile_actionPerformed(ActionEvent e)
608 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
611 public void reload_actionPerformed(ActionEvent e)
615 if(currentFileFormat.equals("Jalview"))
617 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
618 for(int i=0; i<frames.length; i++)
620 if (frames[i] instanceof AlignFrame
622 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
626 frames[i].setSelected(true);
627 Desktop.instance.closeAssociatedWindows();
629 catch (java.beans.PropertyVetoException ex)
634 Desktop.instance.closeAssociatedWindows();
636 FileLoader loader = new FileLoader();
637 String protocol = fileName.startsWith("http:")? "URL":"File";
638 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
642 Rectangle bounds = this.getBounds();
644 FileLoader loader = new FileLoader();
645 String protocol = fileName.startsWith("http:") ? "URL" : "File";
646 AlignFrame newframe =
647 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
649 newframe.setBounds(bounds);
651 this.closeMenuItem_actionPerformed(true);
657 public void addFromText_actionPerformed(ActionEvent e)
659 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
662 public void addFromURL_actionPerformed(ActionEvent e)
664 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
668 public void save_actionPerformed(ActionEvent e)
671 || currentFileFormat==null
672 || fileName.startsWith("http")
675 saveAs_actionPerformed(null);
679 saveAlignment(fileName, currentFileFormat);
686 * @param e DOCUMENT ME!
688 public void saveAs_actionPerformed(ActionEvent e)
690 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
691 getProperty( "LAST_DIRECTORY"),
693 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
695 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
700 chooser.setFileView(new JalviewFileView());
701 chooser.setDialogTitle("Save Alignment to file");
702 chooser.setToolTipText("Save");
704 int value = chooser.showSaveDialog(this);
706 if (value == JalviewFileChooser.APPROVE_OPTION)
708 currentFileFormat = chooser.getSelectedFormat();
709 if (currentFileFormat == null)
711 JOptionPane.showInternalMessageDialog(Desktop.desktop,
712 "You must select a file format before saving!",
713 "File format not specified",
714 JOptionPane.WARNING_MESSAGE);
715 value = chooser.showSaveDialog(this);
719 fileName = chooser.getSelectedFile().getPath();
721 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
724 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
726 saveAlignment(fileName, currentFileFormat);
730 public boolean saveAlignment(String file, String format)
732 boolean success = true;
734 if (format.equalsIgnoreCase("Jalview"))
736 String shortName = title;
738 if (shortName.indexOf(java.io.File.separatorChar) > -1)
740 shortName = shortName.substring(shortName.lastIndexOf(
741 java.io.File.separatorChar) + 1);
744 success = new Jalview2XML().SaveAlignment(this, file, shortName);
746 statusBar.setText("Successfully saved to file: "
748 +format +" format.");
754 String[] omitHidden = null;
756 if (viewport.hasHiddenColumns)
758 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
759 "The Alignment contains hidden columns."
760 + "\nDo you want to save only the visible alignment?",
761 "Save / Omit Hidden Columns",
762 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
764 if (reply == JOptionPane.YES_OPTION)
766 omitHidden = viewport.getViewAsString(false);
770 String output = new FormatAdapter().formatSequences(
772 viewport.alignment.getSequencesArray(),
783 java.io.PrintWriter out = new java.io.PrintWriter(
784 new java.io.FileWriter(file));
789 statusBar.setText("Successfully saved to file: "
791 + format + " format.");
796 ex.printStackTrace();
803 JOptionPane.showInternalMessageDialog(
804 this, "Couldn't save file: " + fileName,
806 JOptionPane.WARNING_MESSAGE);
815 * @param e DOCUMENT ME!
817 protected void outputText_actionPerformed(ActionEvent e)
819 String [] omitHidden = null;
821 if(viewport.hasHiddenColumns)
823 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
824 "The Alignment contains hidden columns."
825 +"\nDo you want to output only the visible alignment?",
826 "Save / Omit Hidden Columns",
827 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
829 if(reply==JOptionPane.YES_OPTION)
831 omitHidden = viewport.getViewAsString(false);
835 CutAndPasteTransfer cap = new CutAndPasteTransfer();
836 cap.setForInput(null);
837 Desktop.addInternalFrame(cap,
838 "Alignment output - " + e.getActionCommand(), 600,
842 cap.setText(new FormatAdapter().formatSequences(
843 e.getActionCommand(),
844 viewport.alignment.getSequencesArray(),
851 * @param e DOCUMENT ME!
853 protected void htmlMenuItem_actionPerformed(ActionEvent e)
855 new HTMLOutput(alignPanel,
856 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
857 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
860 public void createImageMap(File file, String image)
862 alignPanel.makePNGImageMap(file, image);
868 * @param e DOCUMENT ME!
870 public void createPNG(File f)
872 alignPanel.makePNG(f);
878 * @param e DOCUMENT ME!
880 public void createEPS(File f)
882 alignPanel.makeEPS(f);
886 public void pageSetup_actionPerformed(ActionEvent e)
888 PrinterJob printJob = PrinterJob.getPrinterJob();
889 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
895 * @param e DOCUMENT ME!
897 public void printMenuItem_actionPerformed(ActionEvent e)
899 //Putting in a thread avoids Swing painting problems
900 PrintThread thread = new PrintThread(alignPanel);
904 public void exportFeatures_actionPerformed(ActionEvent e)
906 new AnnotationExporter().exportFeatures(alignPanel);
910 public void exportAnnotations_actionPerformed(ActionEvent e)
912 new AnnotationExporter().exportAnnotations(
914 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
915 viewport.alignment.getGroups()
920 public void associatedData_actionPerformed(ActionEvent e)
922 // Pick the tree file
923 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
926 chooser.setFileView(new JalviewFileView());
927 chooser.setDialogTitle("Load Jalview Annotations or Features File");
928 chooser.setToolTipText("Load Jalview Annotations / Features file");
930 int value = chooser.showOpenDialog(null);
932 if (value == JalviewFileChooser.APPROVE_OPTION)
934 String choice = chooser.getSelectedFile().getPath();
935 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
936 loadJalviewDataFile(choice);
945 * @param e DOCUMENT ME!
947 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
949 if(alignPanels!=null && alignPanels.size()<2)
956 if(alignPanels!=null)
960 for (int i = 0; i < alignPanels.size(); i++)
962 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
963 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
964 .removeStructureViewerListener(ap.seqPanel, null);
965 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
966 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
967 PaintRefresher.RemoveComponent(ap);
968 ap.av.alignment = null;
973 int index = tabbedPane.getSelectedIndex();
975 alignPanels.removeElement(alignPanel);
976 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
977 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
978 PaintRefresher.RemoveComponent(alignPanel);
979 viewport.alignment = null;
983 tabbedPane.removeTabAt(index);
984 tabbedPane.validate();
986 if(index==tabbedPane.getTabCount())
991 this.tabSelectionChanged(index);
997 this.setClosed(true);
1000 catch (Exception ex)
1002 ex.printStackTrace();
1010 void updateEditMenuBar()
1013 if (viewport.historyList.size() > 0)
1015 undoMenuItem.setEnabled(true);
1016 CommandI command = (CommandI) viewport.historyList.peek();
1017 undoMenuItem.setText("Undo " + command.getDescription());
1021 undoMenuItem.setEnabled(false);
1022 undoMenuItem.setText("Undo");
1025 if (viewport.redoList.size() > 0)
1027 redoMenuItem.setEnabled(true);
1029 CommandI command = (CommandI) viewport.redoList.peek();
1030 redoMenuItem.setText("Redo " + command.getDescription());
1034 redoMenuItem.setEnabled(false);
1035 redoMenuItem.setText("Redo");
1040 public void addHistoryItem(CommandI command)
1042 if(command.getSize()>0)
1044 viewport.historyList.push(command);
1045 viewport.redoList.clear();
1046 updateEditMenuBar();
1047 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1056 * @param e DOCUMENT ME!
1058 protected void undoMenuItem_actionPerformed(ActionEvent e)
1060 CommandI command = (CommandI)viewport.historyList.pop();
1061 viewport.redoList.push(command);
1062 command.undoCommand();
1064 AlignViewport originalSource = getOriginatingSource(command);
1065 updateEditMenuBar();
1067 if(originalSource!=null)
1069 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1070 originalSource.firePropertyChange("alignment",
1072 originalSource.alignment.getSequences());
1079 * @param e DOCUMENT ME!
1081 protected void redoMenuItem_actionPerformed(ActionEvent e)
1083 if(viewport.redoList.size()<1)
1088 CommandI command = (CommandI) viewport.redoList.pop();
1089 viewport.historyList.push(command);
1090 command.doCommand();
1092 AlignViewport originalSource = getOriginatingSource(command);
1093 updateEditMenuBar();
1095 if(originalSource!=null)
1097 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1098 originalSource.firePropertyChange("alignment",
1100 originalSource.alignment.getSequences());
1104 AlignViewport getOriginatingSource(CommandI command)
1106 AlignViewport originalSource = null;
1107 //For sequence removal and addition, we need to fire
1108 //the property change event FROM the viewport where the
1109 //original alignment was altered
1111 if (command instanceof EditCommand)
1113 EditCommand editCommand = (EditCommand) command;
1114 al = editCommand.getAlignment();
1115 Vector comps = (Vector) PaintRefresher.components
1116 .get(viewport.getSequenceSetId());
1118 for (int i = 0; i < comps.size(); i++)
1120 if (comps.elementAt(i) instanceof AlignmentPanel)
1122 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1124 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1131 if (originalSource == null)
1133 //The original view is closed, we must validate
1134 //the current view against the closed view first
1137 PaintRefresher.validateSequences(al, viewport.alignment);
1140 originalSource = viewport;
1143 return originalSource;
1149 * @param up DOCUMENT ME!
1151 public void moveSelectedSequences(boolean up)
1153 SequenceGroup sg = viewport.getSelectionGroup();
1162 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1164 SequenceI seq = viewport.alignment.getSequenceAt(i);
1166 if (!sg.getSequences(null).contains(seq))
1171 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1173 if (sg.getSequences(null).contains(temp))
1178 viewport.alignment.getSequences().setElementAt(temp, i);
1179 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1184 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1186 SequenceI seq = viewport.alignment.getSequenceAt(i);
1188 if (!sg.getSequences(null).contains(seq))
1193 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1195 if (sg.getSequences(null).contains(temp))
1200 viewport.alignment.getSequences().setElementAt(temp, i);
1201 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1205 alignPanel.paintAlignment(true);
1211 synchronized void slideSequences(boolean right, int size)
1213 Vector sg = new Vector();
1214 if(viewport.cursorMode)
1216 sg.addElement(viewport.alignment.getSequenceAt(
1217 alignPanel.seqPanel.seqCanvas.cursorY));
1219 else if(viewport.getSelectionGroup()!=null
1220 && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
1222 sg = viewport.getSelectionGroup().getSequences(
1223 viewport.hiddenRepSequences);
1231 Vector invertGroup = new Vector();
1233 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1235 if(!sg.contains(viewport.alignment.getSequenceAt(i)))
1236 invertGroup.add(viewport.alignment.getSequenceAt(i));
1239 SequenceI[] seqs1 = new SequenceI[sg.size()];
1240 for (int i = 0; i < sg.size(); i++)
1241 seqs1[i] = (SequenceI) sg.elementAt(i);
1243 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1244 for (int i = 0; i < invertGroup.size(); i++)
1245 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1247 SlideSequencesCommand ssc;
1249 ssc = new SlideSequencesCommand("Slide Sequences",
1251 viewport.getGapCharacter()
1254 ssc = new SlideSequencesCommand("Slide Sequences",
1256 viewport.getGapCharacter()
1259 int groupAdjustment = 0;
1260 if (ssc.getGapsInsertedBegin() && right)
1262 if (viewport.cursorMode)
1263 alignPanel.seqPanel.moveCursor(size, 0);
1265 groupAdjustment = size;
1267 else if (!ssc.getGapsInsertedBegin() && !right)
1269 if (viewport.cursorMode)
1270 alignPanel.seqPanel.moveCursor( -size, 0);
1272 groupAdjustment = -size;
1275 if (groupAdjustment != 0)
1277 viewport.getSelectionGroup().setStartRes(
1278 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1279 viewport.getSelectionGroup().setEndRes(
1280 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1284 boolean appendHistoryItem = false;
1285 if(viewport.historyList!=null
1286 && viewport.historyList.size()>0
1287 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1289 appendHistoryItem = ssc.appendSlideCommand(
1290 (SlideSequencesCommand)viewport.historyList.peek())
1294 if(!appendHistoryItem)
1295 addHistoryItem(ssc);
1304 * @param e DOCUMENT ME!
1306 protected void copy_actionPerformed(ActionEvent e)
1309 if (viewport.getSelectionGroup() == null)
1314 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1315 String[] omitHidden = null;
1317 if (viewport.hasHiddenColumns)
1319 omitHidden = viewport.getViewAsString(true);
1322 String output = new FormatAdapter().formatSequences(
1327 StringSelection ss = new StringSelection(output);
1331 jalview.gui.Desktop.internalCopy = true;
1332 //Its really worth setting the clipboard contents
1333 //to empty before setting the large StringSelection!!
1334 Toolkit.getDefaultToolkit().getSystemClipboard()
1335 .setContents(new StringSelection(""), null);
1337 Toolkit.getDefaultToolkit().getSystemClipboard()
1338 .setContents(ss, Desktop.instance);
1340 catch (OutOfMemoryError er)
1342 er.printStackTrace();
1343 javax.swing.SwingUtilities.invokeLater(new Runnable()
1347 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1348 "Out of memory copying region!!"
1350 "\nSee help files for increasing Java Virtual Machine memory."
1352 javax.swing.JOptionPane.WARNING_MESSAGE);
1359 Vector hiddenColumns = null;
1360 if(viewport.hasHiddenColumns)
1362 hiddenColumns =new Vector();
1363 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1364 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1367 int[] region = (int[])
1368 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1370 hiddenColumns.addElement(new int[]
1371 {region[0] - hiddenOffset,
1372 region[1]-hiddenOffset});
1376 Desktop.jalviewClipboard = new Object[]
1379 viewport.alignment.getDataset(),
1381 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1387 * @param e DOCUMENT ME!
1389 protected void pasteNew_actionPerformed(ActionEvent e)
1397 * @param e DOCUMENT ME!
1399 protected void pasteThis_actionPerformed(ActionEvent e)
1407 * @param newAlignment DOCUMENT ME!
1409 void paste(boolean newAlignment)
1411 boolean externalPaste=true;
1414 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1415 Transferable contents = c.getContents(this);
1417 if (contents == null)
1425 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1426 if (str.length() < 1)
1431 format = new IdentifyFile().Identify(str, "Paste");
1434 catch (OutOfMemoryError er)
1436 er.printStackTrace();
1437 javax.swing.SwingUtilities.invokeLater(new Runnable()
1441 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1442 "Out of memory pasting sequences!!"
1444 "\nSee help files for increasing Java Virtual Machine memory."
1446 javax.swing.JOptionPane.WARNING_MESSAGE);
1453 SequenceI[] sequences;
1454 boolean annotationAdded = false;
1455 AlignmentI alignment = null;
1457 if(Desktop.jalviewClipboard!=null)
1459 // The clipboard was filled from within Jalview, we must use the sequences
1460 // And dataset from the copied alignment
1461 SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
1462 // be doubly sure that we create *new* sequence objects.
1463 sequences = new SequenceI[newseq.length];
1464 for (int i=0;i<newseq.length;i++) {
1465 sequences[i] = new Sequence(newseq[i]);
1467 alignment = new Alignment(sequences);
1468 externalPaste = false;
1472 // parse the clipboard as an alignment.
1473 alignment = new FormatAdapter().readFile(str, "Paste", format);
1474 sequences = alignment.getSequencesArray();
1481 if (Desktop.jalviewClipboard != null)
1483 // dataset is inherited
1484 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1488 // new dataset is constructed
1489 alignment.setDataset(null);
1494 AlignmentI pastedal = alignment; // preserve pasted alignment object
1495 // Add pasted sequences and dataset into existing alignment.
1496 alignment = viewport.getAlignment();
1497 // decide if we need to import sequences from an existing dataset
1498 boolean importDs = Desktop.jalviewClipboard != null
1499 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1500 // importDs==true instructs us to copy over new dataset sequences from
1501 // an existing alignment
1502 Vector newDs = (importDs) ? new Vector() : null; // used to create
1503 // minimum dataset set
1505 for (int i = 0; i < sequences.length; i++)
1509 newDs.addElement(null);
1511 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1513 if (importDs && ds != null)
1515 if (!newDs.contains(ds))
1517 newDs.setElementAt(ds, i);
1518 ds = new Sequence(ds);
1519 // update with new dataset sequence
1520 sequences[i].setDatasetSequence(ds);
1524 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1529 // copy and derive new dataset sequence
1530 sequences[i] = sequences[i].deriveSequence();
1531 alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
1532 // TODO: avoid creation of duplicate dataset sequences with a
1533 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1535 alignment.addSequence(sequences[i]); // merges dataset
1539 newDs.clear(); // tidy up
1541 if (pastedal.getAlignmentAnnotation()!=null) {
1542 // Add any annotation attached to alignment.
1543 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1544 for (int i=0; i<alann.length; i++)
1546 annotationAdded=true;
1547 if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
1548 alignment.addAnnotation(new AlignmentAnnotation(alann[i]));
1553 if (!newAlignment) {
1557 addHistoryItem(new EditCommand(
1562 alignment.getWidth(),
1566 // Add any annotations attached to sequences
1567 for (int i = 0; i < sequences.length; i++)
1569 if (sequences[i].getAnnotation() != null)
1571 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1573 annotationAdded=true;
1574 sequences[i].getAnnotation()[a].adjustForAlignment();
1575 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
1576 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1582 if (!newAlignment) {
1583 // propagate alignment changed.
1584 viewport.setEndSeq(alignment.getHeight());
1585 if (annotationAdded)
1587 alignPanel.annotationPanel.adjustPanelHeight();
1589 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1591 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1592 String newtitle = new String("Copied sequences");
1594 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1596 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1597 for(int i=0; i<hc.size(); i++)
1599 int [] region = (int[]) hc.elementAt(i);
1600 af.viewport.hideColumns(region[0], region[1]);
1605 //>>>This is a fix for the moment, until a better solution is found!!<<<
1606 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1607 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1609 // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
1610 if (!externalPaste) {
1611 if (title.startsWith("Copied sequences"))
1617 newtitle = newtitle.concat("- from " + title);
1620 newtitle = new String("Pasted sequences");
1623 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1630 catch (Exception ex)
1632 ex.printStackTrace();
1633 System.out.println("Exception whilst pasting: "+ex);
1634 // could be anything being pasted in here
1643 * @param e DOCUMENT ME!
1645 protected void cut_actionPerformed(ActionEvent e)
1647 copy_actionPerformed(null);
1648 delete_actionPerformed(null);
1654 * @param e DOCUMENT ME!
1656 protected void delete_actionPerformed(ActionEvent evt)
1659 SequenceGroup sg = viewport.getSelectionGroup();
1665 Vector seqs = new Vector();
1667 for (int i = 0; i < sg.getSize(); i++)
1669 seq = sg.getSequenceAt(i);
1670 seqs.addElement(seq);
1674 // If the cut affects all sequences, remove highlighted columns
1675 if (sg.getSize() == viewport.alignment.getHeight())
1677 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1678 sg.getEndRes() + 1);
1682 SequenceI [] cut = new SequenceI[seqs.size()];
1683 for(int i=0; i<seqs.size(); i++)
1685 cut[i] = (SequenceI)seqs.elementAt(i);
1692 addHistoryItem(new EditCommand("Cut Sequences",
1696 sg.getEndRes()-sg.getStartRes()+1,
1697 viewport.alignment));
1700 viewport.setSelectionGroup(null);
1701 viewport.alignment.deleteGroup(sg);
1703 viewport.firePropertyChange("alignment", null,
1704 viewport.getAlignment().getSequences());
1706 if (viewport.getAlignment().getHeight() < 1)
1710 this.setClosed(true);
1712 catch (Exception ex)
1721 * @param e DOCUMENT ME!
1723 protected void deleteGroups_actionPerformed(ActionEvent e)
1725 viewport.alignment.deleteAllGroups();
1726 viewport.sequenceColours = null;
1727 viewport.setSelectionGroup(null);
1728 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1729 alignPanel.paintAlignment(true);
1735 * @param e DOCUMENT ME!
1737 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1739 SequenceGroup sg = new SequenceGroup();
1741 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1744 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1747 sg.setEndRes(viewport.alignment.getWidth() - 1);
1748 viewport.setSelectionGroup(sg);
1749 alignPanel.paintAlignment(true);
1750 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1756 * @param e DOCUMENT ME!
1758 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1760 if(viewport.cursorMode)
1762 alignPanel.seqPanel.keyboardNo1 = null;
1763 alignPanel.seqPanel.keyboardNo2 = null;
1765 viewport.setSelectionGroup(null);
1766 viewport.getColumnSelection().clear();
1767 viewport.setSelectionGroup(null);
1768 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1769 alignPanel.idPanel.idCanvas.searchResults = null;
1770 alignPanel.paintAlignment(true);
1771 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1777 * @param e DOCUMENT ME!
1779 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1781 SequenceGroup sg = viewport.getSelectionGroup();
1785 selectAllSequenceMenuItem_actionPerformed(null);
1790 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1793 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1796 alignPanel.paintAlignment(true);
1798 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1801 public void invertColSel_actionPerformed(ActionEvent e)
1803 viewport.invertColumnSelection();
1804 alignPanel.paintAlignment(true);
1811 * @param e DOCUMENT ME!
1813 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1815 trimAlignment(true);
1821 * @param e DOCUMENT ME!
1823 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1825 trimAlignment(false);
1828 void trimAlignment(boolean trimLeft)
1830 ColumnSelection colSel = viewport.getColumnSelection();
1833 if (colSel.size() > 0)
1837 column = colSel.getMin();
1841 column = colSel.getMax();
1845 if(viewport.getSelectionGroup()!=null)
1847 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1848 hiddenRepSequences);
1852 seqs = viewport.alignment.getSequencesArray();
1856 TrimRegionCommand trimRegion;
1859 trimRegion = new TrimRegionCommand("Remove Left",
1860 TrimRegionCommand.TRIM_LEFT,
1865 viewport.selectionGroup);
1866 viewport.setStartRes(0);
1870 trimRegion = new TrimRegionCommand("Remove Right",
1871 TrimRegionCommand.TRIM_RIGHT,
1876 viewport.selectionGroup);
1879 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1882 addHistoryItem(trimRegion);
1884 Vector groups = viewport.alignment.getGroups();
1886 for (int i = 0; i < groups.size(); i++)
1888 SequenceGroup sg = (SequenceGroup) groups.get(i);
1890 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1891 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1893 viewport.alignment.deleteGroup(sg);
1897 viewport.firePropertyChange("alignment", null,
1898 viewport.getAlignment().getSequences());
1905 * @param e DOCUMENT ME!
1907 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1909 int start = 0, end = viewport.alignment.getWidth()-1;
1912 if (viewport.getSelectionGroup() != null)
1914 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1915 hiddenRepSequences);
1916 start = viewport.getSelectionGroup().getStartRes();
1917 end = viewport.getSelectionGroup().getEndRes();
1921 seqs = viewport.alignment.getSequencesArray();
1925 RemoveGapColCommand removeGapCols =
1926 new RemoveGapColCommand("Remove Gapped Columns",
1929 viewport.alignment);
1931 addHistoryItem(removeGapCols);
1933 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1935 //This is to maintain viewport position on first residue
1937 SequenceI seq = viewport.alignment.getSequenceAt(0);
1938 int startRes = seq.findPosition(viewport.startRes);
1939 // ShiftList shifts;
1940 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1941 // edit.alColumnChanges=shifts.getInverse();
1942 // if (viewport.hasHiddenColumns)
1943 // viewport.getColumnSelection().compensateForEdits(shifts);
1944 viewport.setStartRes(seq.findIndex(startRes)-1);
1945 viewport.firePropertyChange("alignment", null,
1946 viewport.getAlignment().getSequences());
1953 * @param e DOCUMENT ME!
1955 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1957 int start = 0, end = viewport.alignment.getWidth()-1;
1960 if (viewport.getSelectionGroup() != null)
1962 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1963 hiddenRepSequences);
1964 start = viewport.getSelectionGroup().getStartRes();
1965 end = viewport.getSelectionGroup().getEndRes();
1969 seqs = viewport.alignment.getSequencesArray();
1972 //This is to maintain viewport position on first residue
1974 SequenceI seq = viewport.alignment.getSequenceAt(0);
1975 int startRes = seq.findPosition(viewport.startRes);
1977 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1980 viewport.alignment));
1982 viewport.setStartRes(seq.findIndex(startRes)-1);
1984 viewport.firePropertyChange("alignment", null,
1985 viewport.getAlignment().getSequences());
1992 * @param e DOCUMENT ME!
1994 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1996 viewport.padGaps = padGapsMenuitem.isSelected();
1998 viewport.firePropertyChange("alignment",
2000 viewport.getAlignment().getSequences());
2006 * @param e DOCUMENT ME!
2008 public void findMenuItem_actionPerformed(ActionEvent e)
2013 public void newView_actionPerformed(ActionEvent e)
2015 AlignmentPanel newap =
2016 new Jalview2XML().copyAlignPanel(alignPanel, true);
2018 newap.av.gatherViewsHere = false;
2020 if (viewport.viewName == null)
2022 viewport.viewName = "Original";
2025 newap.av.historyList = viewport.historyList;
2026 newap.av.redoList = viewport.redoList;
2028 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2029 String newViewName = "View " +index;
2031 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2032 getSequenceSetId());
2033 Vector existingNames = new Vector();
2034 for(int i=0; i<comps.size(); i++)
2036 if(comps.elementAt(i) instanceof AlignmentPanel)
2038 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
2039 if(!existingNames.contains(ap.av.viewName))
2041 existingNames.addElement(ap.av.viewName);
2046 while(existingNames.contains(newViewName))
2048 newViewName = "View "+ (++index);
2051 newap.av.viewName = newViewName;
2053 addAlignmentPanel(newap, false);
2055 if(alignPanels.size()==2)
2057 viewport.gatherViewsHere = true;
2059 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2062 public void expandViews_actionPerformed(ActionEvent e)
2064 Desktop.instance.explodeViews(this);
2067 public void gatherViews_actionPerformed(ActionEvent e)
2069 Desktop.instance.gatherViews(this);
2077 * @param e DOCUMENT ME!
2079 public void font_actionPerformed(ActionEvent e)
2081 new FontChooser(alignPanel);
2088 * @param e DOCUMENT ME!
2090 protected void seqLimit_actionPerformed(ActionEvent e)
2092 viewport.setShowJVSuffix(seqLimits.isSelected());
2094 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
2095 alignPanel.paintAlignment(true);
2098 public void idRightAlign_actionPerformed(ActionEvent e)
2100 viewport.rightAlignIds = idRightAlign.isSelected();
2101 alignPanel.paintAlignment(true);
2109 * @param e DOCUMENT ME!
2111 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2113 viewport.setColourText(colourTextMenuItem.isSelected());
2114 alignPanel.paintAlignment(true);
2120 * @param e DOCUMENT ME!
2122 public void wrapMenuItem_actionPerformed(ActionEvent e)
2124 scaleAbove.setVisible(wrapMenuItem.isSelected());
2125 scaleLeft.setVisible(wrapMenuItem.isSelected());
2126 scaleRight.setVisible(wrapMenuItem.isSelected());
2127 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2128 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2131 public void showAllSeqs_actionPerformed(ActionEvent e)
2133 viewport.showAllHiddenSeqs();
2136 public void showAllColumns_actionPerformed(ActionEvent e)
2138 viewport.showAllHiddenColumns();
2142 public void hideSelSequences_actionPerformed(ActionEvent e)
2144 viewport.hideAllSelectedSeqs();
2145 alignPanel.paintAlignment(true);
2148 public void hideSelColumns_actionPerformed(ActionEvent e)
2150 viewport.hideSelectedColumns();
2151 alignPanel.paintAlignment(true);
2154 public void hiddenMarkers_actionPerformed(ActionEvent e)
2156 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2163 * @param e DOCUMENT ME!
2165 protected void scaleAbove_actionPerformed(ActionEvent e)
2167 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2168 alignPanel.paintAlignment(true);
2174 * @param e DOCUMENT ME!
2176 protected void scaleLeft_actionPerformed(ActionEvent e)
2178 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2179 alignPanel.paintAlignment(true);
2185 * @param e DOCUMENT ME!
2187 protected void scaleRight_actionPerformed(ActionEvent e)
2189 viewport.setScaleRightWrapped(scaleRight.isSelected());
2190 alignPanel.paintAlignment(true);
2196 * @param e DOCUMENT ME!
2198 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2200 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2201 alignPanel.paintAlignment(true);
2207 * @param e DOCUMENT ME!
2209 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2211 viewport.setShowText(viewTextMenuItem.isSelected());
2212 alignPanel.paintAlignment(true);
2218 * @param e DOCUMENT ME!
2220 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2222 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2223 alignPanel.paintAlignment(true);
2227 public FeatureSettings featureSettings;
2228 public void featureSettings_actionPerformed(ActionEvent e)
2230 if(featureSettings !=null )
2232 featureSettings.close();
2233 featureSettings = null;
2235 featureSettings = new FeatureSettings(this);
2241 * @param evt DOCUMENT ME!
2243 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2245 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2246 alignPanel.paintAlignment(true);
2247 if (alignPanel.getOverviewPanel() != null)
2249 alignPanel.getOverviewPanel().updateOverviewImage();
2256 * @param e DOCUMENT ME!
2258 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2260 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2261 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2267 * @param e DOCUMENT ME!
2269 public void overviewMenuItem_actionPerformed(ActionEvent e)
2271 if (alignPanel.overviewPanel != null)
2276 JInternalFrame frame = new JInternalFrame();
2277 OverviewPanel overview = new OverviewPanel(alignPanel);
2278 frame.setContentPane(overview);
2279 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2280 frame.getWidth(), frame.getHeight());
2282 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2283 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2285 public void internalFrameClosed(
2286 javax.swing.event.InternalFrameEvent evt)
2288 alignPanel.setOverviewPanel(null);
2293 alignPanel.setOverviewPanel(overview);
2296 public void textColour_actionPerformed(ActionEvent e)
2298 new TextColourChooser().chooseColour(alignPanel, null);
2304 * @param e DOCUMENT ME!
2306 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2314 * @param e DOCUMENT ME!
2316 public void clustalColour_actionPerformed(ActionEvent e)
2318 changeColour(new ClustalxColourScheme(
2319 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2325 * @param e DOCUMENT ME!
2327 public void zappoColour_actionPerformed(ActionEvent e)
2329 changeColour(new ZappoColourScheme());
2335 * @param e DOCUMENT ME!
2337 public void taylorColour_actionPerformed(ActionEvent e)
2339 changeColour(new TaylorColourScheme());
2345 * @param e DOCUMENT ME!
2347 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2349 changeColour(new HydrophobicColourScheme());
2355 * @param e DOCUMENT ME!
2357 public void helixColour_actionPerformed(ActionEvent e)
2359 changeColour(new HelixColourScheme());
2365 * @param e DOCUMENT ME!
2367 public void strandColour_actionPerformed(ActionEvent e)
2369 changeColour(new StrandColourScheme());
2375 * @param e DOCUMENT ME!
2377 public void turnColour_actionPerformed(ActionEvent e)
2379 changeColour(new TurnColourScheme());
2385 * @param e DOCUMENT ME!
2387 public void buriedColour_actionPerformed(ActionEvent e)
2389 changeColour(new BuriedColourScheme());
2395 * @param e DOCUMENT ME!
2397 public void nucleotideColour_actionPerformed(ActionEvent e)
2399 changeColour(new NucleotideColourScheme());
2402 public void annotationColour_actionPerformed(ActionEvent e)
2404 new AnnotationColourChooser(viewport, alignPanel);
2411 * @param e DOCUMENT ME!
2413 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2415 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2421 * @param cs DOCUMENT ME!
2423 public void changeColour(ColourSchemeI cs)
2429 if (viewport.getAbovePIDThreshold())
2431 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2434 cs.setThreshold(threshold,
2435 viewport.getIgnoreGapsConsensus());
2437 viewport.setGlobalColourScheme(cs);
2441 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2444 if (viewport.getConservationSelected())
2447 Alignment al = (Alignment) viewport.alignment;
2448 Conservation c = new Conservation("All",
2449 ResidueProperties.propHash, 3,
2450 al.getSequences(), 0,
2454 c.verdict(false, viewport.ConsPercGaps);
2456 cs.setConservation(c);
2458 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2463 cs.setConservation(null);
2466 cs.setConsensus(viewport.hconsensus);
2469 viewport.setGlobalColourScheme(cs);
2471 if (viewport.getColourAppliesToAllGroups())
2473 Vector groups = viewport.alignment.getGroups();
2475 for (int i = 0; i < groups.size(); i++)
2477 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2485 if (cs instanceof ClustalxColourScheme)
2487 sg.cs = new ClustalxColourScheme(
2488 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2490 else if (cs instanceof UserColourScheme)
2492 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2498 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2500 catch (Exception ex)
2505 if (viewport.getAbovePIDThreshold()
2506 || cs instanceof PIDColourScheme
2507 || cs instanceof Blosum62ColourScheme)
2509 sg.cs.setThreshold(threshold,
2510 viewport.getIgnoreGapsConsensus());
2512 sg.cs.setConsensus(AAFrequency.calculate(
2513 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2518 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2522 if (viewport.getConservationSelected())
2524 Conservation c = new Conservation("Group",
2525 ResidueProperties.propHash, 3,
2526 sg.getSequences(viewport.
2527 hiddenRepSequences),
2531 c.verdict(false, viewport.ConsPercGaps);
2532 sg.cs.setConservation(c);
2536 sg.cs.setConservation(null);
2541 if (alignPanel.getOverviewPanel() != null)
2543 alignPanel.getOverviewPanel().updateOverviewImage();
2549 alignPanel.paintAlignment(true);
2555 * @param e DOCUMENT ME!
2557 protected void modifyPID_actionPerformed(ActionEvent e)
2559 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2561 SliderPanel.setPIDSliderSource(alignPanel,
2562 viewport.getGlobalColourScheme(),
2564 SliderPanel.showPIDSlider();
2571 * @param e DOCUMENT ME!
2573 protected void modifyConservation_actionPerformed(ActionEvent e)
2575 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2577 SliderPanel.setConservationSlider(alignPanel,
2578 viewport.globalColourScheme,
2580 SliderPanel.showConservationSlider();
2587 * @param e DOCUMENT ME!
2589 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2591 viewport.setConservationSelected(conservationMenuItem.isSelected());
2593 viewport.setAbovePIDThreshold(false);
2594 abovePIDThreshold.setSelected(false);
2596 changeColour(viewport.getGlobalColourScheme());
2598 modifyConservation_actionPerformed(null);
2604 * @param e DOCUMENT ME!
2606 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2608 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2610 conservationMenuItem.setSelected(false);
2611 viewport.setConservationSelected(false);
2613 changeColour(viewport.getGlobalColourScheme());
2615 modifyPID_actionPerformed(null);
2621 * @param e DOCUMENT ME!
2623 public void userDefinedColour_actionPerformed(ActionEvent e)
2625 if (e.getActionCommand().equals("User Defined..."))
2627 new UserDefinedColours(alignPanel, null);
2631 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2632 getUserColourSchemes().get(e.getActionCommand());
2638 public void updateUserColourMenu()
2641 Component[] menuItems = colourMenu.getMenuComponents();
2642 int i, iSize = menuItems.length;
2643 for (i = 0; i < iSize; i++)
2645 if (menuItems[i].getName() != null &&
2646 menuItems[i].getName().equals("USER_DEFINED"))
2648 colourMenu.remove(menuItems[i]);
2652 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2654 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2655 getUserColourSchemes().keys();
2657 while (userColours.hasMoreElements())
2659 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2661 nextElement().toString());
2662 radioItem.setName("USER_DEFINED");
2663 radioItem.addMouseListener(new MouseAdapter()
2665 public void mousePressed(MouseEvent evt)
2667 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2669 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2671 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2673 "Remove from default list?",
2674 "Remove user defined colour",
2675 JOptionPane.YES_NO_OPTION);
2676 if(option == JOptionPane.YES_OPTION)
2678 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2679 radioItem.getText());
2680 colourMenu.remove(radioItem);
2684 radioItem.addActionListener(new ActionListener()
2686 public void actionPerformed(ActionEvent evt)
2688 userDefinedColour_actionPerformed(evt);
2695 radioItem.addActionListener(new ActionListener()
2697 public void actionPerformed(ActionEvent evt)
2699 userDefinedColour_actionPerformed(evt);
2703 colourMenu.insert(radioItem, 15);
2704 colours.add(radioItem);
2712 * @param e DOCUMENT ME!
2714 public void PIDColour_actionPerformed(ActionEvent e)
2716 changeColour(new PIDColourScheme());
2722 * @param e DOCUMENT ME!
2724 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2726 changeColour(new Blosum62ColourScheme());
2732 * @param e DOCUMENT ME!
2734 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2736 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2737 AlignmentSorter.sortByPID(viewport.getAlignment(),
2738 viewport.getAlignment().getSequenceAt(0));
2739 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2740 viewport.alignment));
2741 alignPanel.paintAlignment(true);
2747 * @param e DOCUMENT ME!
2749 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2751 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2752 AlignmentSorter.sortByID(viewport.getAlignment());
2753 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2754 alignPanel.paintAlignment(true);
2760 * @param e DOCUMENT ME!
2762 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2764 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2765 AlignmentSorter.sortByGroup(viewport.getAlignment());
2766 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2768 alignPanel.paintAlignment(true);
2774 * @param e DOCUMENT ME!
2776 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2778 new RedundancyPanel(alignPanel, this);
2785 * @param e DOCUMENT ME!
2787 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2789 if ( (viewport.getSelectionGroup() == null) ||
2790 (viewport.getSelectionGroup().getSize() < 2))
2792 JOptionPane.showInternalMessageDialog(this,
2793 "You must select at least 2 sequences.",
2794 "Invalid Selection",
2795 JOptionPane.WARNING_MESSAGE);
2799 JInternalFrame frame = new JInternalFrame();
2800 frame.setContentPane(new PairwiseAlignPanel(viewport));
2801 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2808 * @param e DOCUMENT ME!
2810 public void PCAMenuItem_actionPerformed(ActionEvent e)
2812 if ( ( (viewport.getSelectionGroup() != null) &&
2813 (viewport.getSelectionGroup().getSize() < 4) &&
2814 (viewport.getSelectionGroup().getSize() > 0)) ||
2815 (viewport.getAlignment().getHeight() < 4))
2817 JOptionPane.showInternalMessageDialog(this,
2818 "Principal component analysis must take\n" +
2819 "at least 4 input sequences.",
2820 "Sequence selection insufficient",
2821 JOptionPane.WARNING_MESSAGE);
2826 new PCAPanel(alignPanel);
2830 public void autoCalculate_actionPerformed(ActionEvent e)
2832 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2833 if(viewport.autoCalculateConsensus)
2835 viewport.firePropertyChange("alignment",
2837 viewport.getAlignment().getSequences());
2845 * @param e DOCUMENT ME!
2847 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2849 NewTreePanel("AV", "PID", "Average distance tree using PID");
2855 * @param e DOCUMENT ME!
2857 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2859 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2865 * @param e DOCUMENT ME!
2867 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2869 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2875 * @param e DOCUMENT ME!
2877 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2879 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2885 * @param type DOCUMENT ME!
2886 * @param pwType DOCUMENT ME!
2887 * @param title DOCUMENT ME!
2889 void NewTreePanel(String type, String pwType, String title)
2893 if (viewport.getSelectionGroup() != null)
2895 if (viewport.getSelectionGroup().getSize() < 3)
2897 JOptionPane.showMessageDialog(Desktop.desktop,
2898 "You need to have more than two sequences selected to build a tree!",
2899 "Not enough sequences",
2900 JOptionPane.WARNING_MESSAGE);
2905 SequenceGroup sg = viewport.getSelectionGroup();
2907 /* Decide if the selection is a column region */
2908 while (s < sg.getSize())
2910 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2913 JOptionPane.showMessageDialog(Desktop.desktop,
2914 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2915 "Try using the Pad function in the edit menu,\n" +
2916 "or one of the multiple sequence alignment web services.",
2917 "Sequences in selection are not aligned",
2918 JOptionPane.WARNING_MESSAGE);
2924 title = title + " on region";
2925 tp = new TreePanel(alignPanel, type, pwType);
2929 //are the sequences aligned?
2930 if (!viewport.alignment.isAligned())
2932 JOptionPane.showMessageDialog(Desktop.desktop,
2933 "The sequences must be aligned before creating a tree.\n" +
2934 "Try using the Pad function in the edit menu,\n" +
2935 "or one of the multiple sequence alignment web services.",
2936 "Sequences not aligned",
2937 JOptionPane.WARNING_MESSAGE);
2942 if(viewport.alignment.getHeight()<2)
2947 tp = new TreePanel(alignPanel, type, pwType);
2952 if(viewport.viewName!=null)
2954 title+= viewport.viewName+" of ";
2957 title += this.title;
2959 Desktop.addInternalFrame(tp, title, 600, 500);
2965 * @param title DOCUMENT ME!
2966 * @param order DOCUMENT ME!
2968 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2970 final JMenuItem item = new JMenuItem("by " + title);
2972 item.addActionListener(new java.awt.event.ActionListener()
2974 public void actionPerformed(ActionEvent e)
2976 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2978 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2979 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2981 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
2982 viewport.alignment));
2984 alignPanel.paintAlignment(true);
2990 * Maintain the Order by->Displayed Tree menu.
2991 * Creates a new menu item for a TreePanel with an appropriate
2992 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2993 * to remove the menu item when the treePanel is closed, and adjust
2994 * the tree leaf to sequence mapping when the alignment is modified.
2995 * @param treePanel Displayed tree window.
2996 * @param title SortBy menu item title.
2998 public void buildTreeMenu()
3000 sortByTreeMenu.removeAll();
3002 Vector comps = (Vector) PaintRefresher.components.get(viewport.
3003 getSequenceSetId());
3004 Vector treePanels = new Vector();
3005 int i, iSize = comps.size();
3006 for(i=0; i<iSize; i++)
3008 if(comps.elementAt(i) instanceof TreePanel)
3010 treePanels.add(comps.elementAt(i));
3014 iSize = treePanels.size();
3018 sortByTreeMenu.setVisible(false);
3022 sortByTreeMenu.setVisible(true);
3024 for(i=0; i<treePanels.size(); i++)
3026 TreePanel tp = (TreePanel)treePanels.elementAt(i);
3027 final JMenuItem item = new JMenuItem(tp.getTitle());
3028 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
3029 item.addActionListener(new java.awt.event.ActionListener()
3031 public void actionPerformed(ActionEvent e)
3033 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3034 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3036 addHistoryItem(new OrderCommand("Tree Sort",
3038 viewport.alignment));
3040 alignPanel.paintAlignment(true);
3044 sortByTreeMenu.add(item);
3049 * Work out whether the whole set of sequences
3050 * or just the selected set will be submitted for multiple alignment.
3053 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3055 // Now, check we have enough sequences
3056 AlignmentView msa = null;
3058 if ( (viewport.getSelectionGroup() != null) &&
3059 (viewport.getSelectionGroup().getSize() > 1))
3061 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
3062 /*SequenceGroup seqs = viewport.getSelectionGroup();
3064 msa = new SequenceI[sz = seqs.getSize(false)];
3066 for (int i = 0; i < sz; i++)
3068 msa[i] = (SequenceI) seqs.getSequenceAt(i);
3070 msa = viewport.getAlignmentView(true);
3074 /*Vector seqs = viewport.getAlignment().getSequences();
3076 if (seqs.size() > 1)
3078 msa = new SequenceI[seqs.size()];
3080 for (int i = 0; i < seqs.size(); i++)
3082 msa[i] = (SequenceI) seqs.elementAt(i);
3085 msa = viewport.getAlignmentView(false);
3091 * Decides what is submitted to a secondary structure prediction service,
3092 * the currently selected sequence, or the currently selected alignment
3093 * (where the first sequence in the set is the one that the prediction
3096 AlignmentView gatherSeqOrMsaForSecStrPrediction()
3098 AlignmentView seqs = null;
3100 if ( (viewport.getSelectionGroup() != null) &&
3101 (viewport.getSelectionGroup().getSize() > 0))
3103 seqs = viewport.getAlignmentView(true);
3107 seqs = viewport.getAlignmentView(false);
3109 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
3110 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3111 if (!viewport.alignment.isAligned())
3113 seqs.setSequences(new SeqCigar[]
3114 {seqs.getSequences()[0]});
3121 * @param e DOCUMENT ME!
3123 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3125 // Pick the tree file
3126 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3129 chooser.setFileView(new JalviewFileView());
3130 chooser.setDialogTitle("Select a newick-like tree file");
3131 chooser.setToolTipText("Load a tree file");
3133 int value = chooser.showOpenDialog(null);
3135 if (value == JalviewFileChooser.APPROVE_OPTION)
3137 String choice = chooser.getSelectedFile().getPath();
3138 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3142 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
3144 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3146 catch (Exception ex)
3148 JOptionPane.showMessageDialog(Desktop.desktop,
3149 "Problem reading tree file",
3151 JOptionPane.WARNING_MESSAGE);
3152 ex.printStackTrace();
3158 public TreePanel ShowNewickTree(NewickFile nf, String title)
3160 return ShowNewickTree(nf,title,600,500,4,5);
3163 public TreePanel ShowNewickTree(NewickFile nf, String title,
3164 AlignmentView input)
3166 return ShowNewickTree(nf,title, input, 600,500,4,5);
3169 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
3172 return ShowNewickTree(nf, title, null, w, h, x, y);
3175 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
3177 * @param nf the tree
3178 * @param title tree viewer title
3179 * @param input Associated alignment input data (or null)
3184 * @return TreePanel handle
3186 public TreePanel ShowNewickTree(NewickFile nf, String title,
3187 AlignmentView input, int w, int h, int x,
3190 TreePanel tp = null;
3196 if (nf.getTree() != null)
3198 tp = new TreePanel(alignPanel,
3207 tp.setLocation(x,y);
3211 Desktop.addInternalFrame(tp, title, w, h);
3214 catch (Exception ex)
3216 ex.printStackTrace();
3224 * Generates menu items and listener event actions for web service clients
3227 public void BuildWebServiceMenu()
3229 if ( (Discoverer.services != null)
3230 && (Discoverer.services.size() > 0))
3232 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3233 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3234 Vector wsmenu = new Vector();
3235 final AlignFrame af = this;
3238 // Add any Multiple Sequence Alignment Services
3239 final JMenu msawsmenu = new JMenu("Alignment");
3240 for (int i = 0, j = msaws.size(); i < j; i++)
3242 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3244 final JMenuItem method = new JMenuItem(sh.getName());
3245 method.addActionListener(new ActionListener()
3247 public void actionPerformed(ActionEvent e)
3249 AlignmentView msa = gatherSequencesForAlignment();
3250 new jalview.ws.MsaWSClient(sh, title, msa,
3252 viewport.getAlignment().getDataset(),
3258 msawsmenu.add(method);
3259 // Deal with services that we know accept partial alignments.
3260 if (sh.getName().indexOf("lustal") > -1)
3262 // We know that ClustalWS can accept partial alignments for refinement.
3263 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
3264 methodR.addActionListener(new ActionListener()
3266 public void actionPerformed(ActionEvent e)
3268 AlignmentView msa = gatherSequencesForAlignment();
3269 new jalview.ws.MsaWSClient(sh, title, msa,
3271 viewport.getAlignment().getDataset(),
3277 msawsmenu.add(methodR);
3281 wsmenu.add(msawsmenu);
3283 if (secstrpr != null)
3285 // Add any secondary structure prediction services
3286 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3287 for (int i = 0, j = secstrpr.size(); i < j; i++)
3289 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3291 final JMenuItem method = new JMenuItem(sh.getName());
3292 method.addActionListener(new ActionListener()
3294 public void actionPerformed(ActionEvent e)
3296 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3297 if (msa.getSequences().length == 1)
3299 // Single Sequence prediction
3300 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3304 if (msa.getSequences().length > 1)
3306 // Sequence profile based prediction
3307 new jalview.ws.JPredClient(sh,
3308 title, true, msa, af, true);
3313 secstrmenu.add(method);
3315 wsmenu.add(secstrmenu);
3317 this.webService.removeAll();
3318 for (int i = 0, j = wsmenu.size(); i < j; i++)
3320 webService.add( (JMenu) wsmenu.get(i));
3325 this.webService.removeAll();
3326 this.webService.add(this.webServiceNoServices);
3328 // TODO: add in rediscovery function
3329 // TODO: reduce code redundancy.
3330 // TODO: group services by location as well as function.
3333 /* public void vamsasStore_actionPerformed(ActionEvent e)
3335 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3336 getProperty("LAST_DIRECTORY"));
3338 chooser.setFileView(new JalviewFileView());
3339 chooser.setDialogTitle("Export to Vamsas file");
3340 chooser.setToolTipText("Export");
3342 int value = chooser.showSaveDialog(this);
3344 if (value == JalviewFileChooser.APPROVE_OPTION)
3346 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3347 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3348 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3355 public void showTranslation_actionPerformed(ActionEvent e)
3357 ///////////////////////////////
3358 // Collect Data to be translated/transferred
3360 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3361 String [] seqstring = viewport.getViewAsString(true);
3362 AlignmentI al = null;
3364 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
3365 viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
3366 viewport.alignment.getWidth());
3367 } catch (Exception ex) {
3369 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3373 JOptionPane.showMessageDialog(Desktop.desktop,
3374 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3375 "Translation Failed",
3376 JOptionPane.WARNING_MESSAGE);
3378 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3379 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3388 * @param String DOCUMENT ME!
3390 public boolean parseFeaturesFile(String file, String type)
3392 boolean featuresFile = false;
3395 featuresFile = new FeaturesFile(file,
3396 type).parse(viewport.alignment.getDataset(),
3397 alignPanel.seqPanel.seqCanvas.
3398 getFeatureRenderer().featureColours,
3403 ex.printStackTrace();
3408 viewport.showSequenceFeatures = true;
3409 showSeqFeatures.setSelected(true);
3410 alignPanel.paintAlignment(true);
3413 return featuresFile;
3416 public void dragEnter(DropTargetDragEvent evt)
3419 public void dragExit(DropTargetEvent evt)
3422 public void dragOver(DropTargetDragEvent evt)
3425 public void dropActionChanged(DropTargetDragEvent evt)
3428 public void drop(DropTargetDropEvent evt)
3430 Transferable t = evt.getTransferable();
3431 java.util.List files = null;
3435 DataFlavor uriListFlavor = new DataFlavor(
3436 "text/uri-list;class=java.lang.String");
3437 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3439 //Works on Windows and MacOSX
3440 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3441 files = (java.util.List) t.getTransferData(DataFlavor.
3442 javaFileListFlavor);
3444 else if (t.isDataFlavorSupported(uriListFlavor))
3446 // This is used by Unix drag system
3447 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3448 String data = (String) t.getTransferData(uriListFlavor);
3449 files = new java.util.ArrayList(1);
3450 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3453 st.hasMoreTokens(); )
3455 String s = st.nextToken();
3456 if (s.startsWith("#"))
3458 // the line is a comment (as per the RFC 2483)
3462 java.net.URI uri = new java.net.URI(s);
3463 java.io.File file = new java.io.File(uri);
3470 e.printStackTrace();
3477 for (int i = 0; i < files.size(); i++)
3479 loadJalviewDataFile(files.get(i).toString());
3482 catch (Exception ex)
3484 ex.printStackTrace();
3489 // This method will attempt to load a "dropped" file first by testing
3490 // whether its and Annotation file, then features file. If both are
3491 // false then the user may have dropped an alignment file onto this
3493 public void loadJalviewDataFile(String file)
3497 String protocol = "File";
3499 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3504 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3505 alignment, file, protocol);
3509 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3512 String format = new IdentifyFile().Identify(file, protocol);
3514 if(format.equalsIgnoreCase("JnetFile"))
3516 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3518 new JnetAnnotationMaker().add_annotation(predictions,
3519 viewport.getAlignment(),
3521 alignPanel.adjustAnnotationHeight();
3522 alignPanel.paintAlignment(true);
3526 new FileLoader().LoadFile(viewport, file, protocol, format);
3533 alignPanel.adjustAnnotationHeight();
3537 catch (Exception ex)
3539 ex.printStackTrace();
3543 public void tabSelectionChanged(int index)
3547 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3548 viewport = alignPanel.av;
3549 setMenusFromViewport(viewport);
3553 public void tabbedPane_mousePressed(MouseEvent e)
3555 if(SwingUtilities.isRightMouseButton(e))
3557 String reply = JOptionPane.showInternalInputDialog(this,
3560 JOptionPane.QUESTION_MESSAGE);
3564 viewport.viewName = reply;
3565 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3571 public AlignViewport getCurrentView()
3581 public PrintThread(AlignmentPanel ap)
3585 static PageFormat pf;
3588 PrinterJob printJob = PrinterJob.getPrinterJob();
3592 printJob.setPrintable(ap, pf);
3596 printJob.setPrintable(ap);
3599 if (printJob.printDialog())
3605 catch (Exception PrintException)
3607 PrintException.printStackTrace();