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.*;
31 import javax.swing.event.MenuEvent;
33 import jalview.analysis.*;
34 import jalview.commands.*;
35 import jalview.datamodel.*;
37 import jalview.jbgui.*;
38 import jalview.schemes.*;
47 public class AlignFrame
48 extends GAlignFrame implements DropTargetListener
51 public static final int DEFAULT_WIDTH = 700;
54 public static final int DEFAULT_HEIGHT = 500;
55 public AlignmentPanel alignPanel;
57 AlignViewport viewport;
59 Vector alignPanels = new Vector();
63 * Last format used to load or save alignments in this window
65 String currentFileFormat = null;
67 * Current filename for this alignment
69 String fileName = null;
75 * Creates a new AlignFrame object.
77 * @param al DOCUMENT ME!
79 public AlignFrame(AlignmentI al, int width, int height)
81 this(al, null, width, height);
86 * new alignment window with hidden columns
87 * @param al AlignmentI
88 * @param hiddenColumns ColumnSelection or null
90 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
91 int width, int height)
93 this.setSize(width, height);
94 viewport = new AlignViewport(al, hiddenColumns);
96 alignPanel = new AlignmentPanel(this, viewport);
98 if(al.getDataset()==null)
103 addAlignmentPanel(alignPanel, true);
108 * Make a new AlignFrame from exisiting alignmentPanels
109 * @param ap AlignmentPanel
110 * @param av AlignViewport
112 public AlignFrame(AlignmentPanel ap)
116 addAlignmentPanel(ap, false);
122 if (viewport.conservation == null)
124 BLOSUM62Colour.setEnabled(false);
125 conservationMenuItem.setEnabled(false);
126 modifyConservation.setEnabled(false);
127 // PIDColour.setEnabled(false);
128 // abovePIDThreshold.setEnabled(false);
129 // modifyPID.setEnabled(false);
132 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
134 if (sortby.equals("Id"))
136 sortIDMenuItem_actionPerformed(null);
138 else if (sortby.equals("Pairwise Identity"))
140 sortPairwiseMenuItem_actionPerformed(null);
143 if (Desktop.desktop != null)
145 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
146 addServiceListeners();
147 setGUINucleotide(viewport.alignment.isNucleotide());
150 setMenusFromViewport(viewport);
151 buildSortByAnnotationScoresMenu();
152 if (viewport.wrapAlignment)
154 wrapMenuItem_actionPerformed(null);
157 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
159 this.overviewMenuItem_actionPerformed(null);
166 * Change the filename and format for the alignment, and
167 * enable the 'reload' button functionality.
168 * @param file valid filename
169 * @param format format of file
171 public void setFileName(String file, String format)
174 currentFileFormat = format;
175 reload.setEnabled(true);
178 void addKeyListener()
180 addKeyListener(new KeyAdapter()
182 public void keyPressed(KeyEvent evt)
184 if (viewport.cursorMode &&
185 ( (evt.getKeyCode() >= KeyEvent.VK_0 &&
186 evt.getKeyCode() <= KeyEvent.VK_9)
188 (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 &&
189 evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)
191 && Character.isDigit(evt.getKeyChar()))
192 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
194 switch (evt.getKeyCode())
197 case 27: // escape key
198 deselectAllSequenceMenuItem_actionPerformed(null);
202 case KeyEvent.VK_DOWN:
203 if (evt.isAltDown() || !viewport.cursorMode)
204 moveSelectedSequences(false);
205 if (viewport.cursorMode)
206 alignPanel.seqPanel.moveCursor(0, 1);
210 if (evt.isAltDown() || !viewport.cursorMode)
211 moveSelectedSequences(true);
212 if (viewport.cursorMode)
213 alignPanel.seqPanel.moveCursor(0, -1);
217 case KeyEvent.VK_LEFT:
218 if (evt.isAltDown() || !viewport.cursorMode)
219 slideSequences(false,
220 alignPanel.seqPanel.getKeyboardNo1());
222 alignPanel.seqPanel.moveCursor( -1, 0);
227 case KeyEvent.VK_RIGHT:
228 if (evt.isAltDown() || !viewport.cursorMode)
230 alignPanel.seqPanel.getKeyboardNo1());
232 alignPanel.seqPanel.moveCursor(1, 0);
235 case KeyEvent.VK_SPACE:
236 if (viewport.cursorMode)
238 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
244 case KeyEvent.VK_DELETE:
245 case KeyEvent.VK_BACK_SPACE:
246 if (!viewport.cursorMode)
248 cut_actionPerformed(null);
252 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setCursorRow();
266 if (viewport.cursorMode && !evt.isControlDown())
268 alignPanel.seqPanel.setCursorColumn();
272 if (viewport.cursorMode)
274 alignPanel.seqPanel.setCursorPosition();
278 case KeyEvent.VK_ENTER:
279 case KeyEvent.VK_COMMA:
280 if (viewport.cursorMode)
282 alignPanel.seqPanel.setCursorRowAndColumn();
287 if (viewport.cursorMode)
289 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
293 if (viewport.cursorMode)
295 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
300 viewport.cursorMode = !viewport.cursorMode;
301 statusBar.setText("Keyboard editing mode is " +
302 (viewport.cursorMode ? "on" : "off"));
303 if (viewport.cursorMode)
305 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
306 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
308 alignPanel.seqPanel.seqCanvas.repaint();
314 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
315 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
316 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
318 javax.help.HelpBroker hb = hs.createHelpBroker();
319 hb.setCurrentID("home");
320 hb.setDisplayed(true);
324 ex.printStackTrace();
330 boolean toggleSeqs = !evt.isControlDown();
331 boolean toggleCols = !evt.isShiftDown();
333 boolean hide = false;
335 SequenceGroup sg = viewport.getSelectionGroup();
338 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
340 hideSelSequences_actionPerformed(null);
343 else if (! (toggleCols &&
344 viewport.colSel.getSelected().size() > 0))
346 showAllSeqs_actionPerformed(null);
352 if (viewport.colSel.getSelected().size() > 0)
354 hideSelColumns_actionPerformed(null);
357 viewport.selectionGroup = sg;
362 showAllColumns_actionPerformed(null);
367 case KeyEvent.VK_PAGE_UP:
368 if (viewport.wrapAlignment)
370 alignPanel.scrollUp(true);
374 alignPanel.setScrollValues(viewport.startRes,
376 - viewport.endSeq + viewport.startSeq);
379 case KeyEvent.VK_PAGE_DOWN:
380 if (viewport.wrapAlignment)
382 alignPanel.scrollUp(false);
386 alignPanel.setScrollValues(viewport.startRes,
388 + viewport.endSeq - viewport.startSeq);
394 public void keyReleased(KeyEvent evt)
396 switch(evt.getKeyCode())
398 case KeyEvent.VK_LEFT:
399 if (evt.isAltDown() || !viewport.cursorMode)
400 viewport.firePropertyChange("alignment", null,
401 viewport.getAlignment().getSequences());
404 case KeyEvent.VK_RIGHT:
405 if (evt.isAltDown() || !viewport.cursorMode)
406 viewport.firePropertyChange("alignment", null,
407 viewport.getAlignment().getSequences());
415 public void addAlignmentPanel(final AlignmentPanel ap,
418 ap.alignFrame = this;
420 alignPanels.addElement(ap);
422 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
424 int aSize = alignPanels.size();
426 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
428 if (aSize == 1 && ap.av.viewName==null)
430 this.getContentPane().add(ap, BorderLayout.CENTER);
436 setInitialTabVisible();
439 expandViews.setEnabled(true);
440 gatherViews.setEnabled(true);
441 tabbedPane.addTab(ap.av.viewName, ap);
443 ap.setVisible(false);
450 ap.av.alignment.padGaps();
452 ap.av.updateConservation(ap);
453 ap.av.updateConsensus(ap);
457 public void setInitialTabVisible()
459 expandViews.setEnabled(true);
460 gatherViews.setEnabled(true);
461 tabbedPane.setVisible(true);
462 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
463 tabbedPane.addTab(first.av.viewName,first);
464 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
468 public AlignViewport getViewport()
473 /* Set up intrinsic listeners for dynamically generated GUI bits. */
474 private void addServiceListeners()
476 final java.beans.PropertyChangeListener thisListener;
477 // Do this once to get current state
478 BuildWebServiceMenu();
479 Desktop.discoverer.addPropertyChangeListener(
480 thisListener = new java.beans.PropertyChangeListener()
482 public void propertyChange(PropertyChangeEvent evt)
484 // System.out.println("Discoverer property change.");
485 if (evt.getPropertyName().equals("services"))
487 // System.out.println("Rebuilding web service menu");
488 BuildWebServiceMenu();
493 addInternalFrameListener(new javax.swing.event.
494 InternalFrameAdapter()
496 public void internalFrameClosed(
497 javax.swing.event.InternalFrameEvent evt)
499 // System.out.println("deregistering discoverer listener");
500 Desktop.discoverer.removePropertyChangeListener(thisListener);
501 closeMenuItem_actionPerformed(true);
507 public void setGUINucleotide(boolean nucleotide)
509 showTranslation.setVisible( nucleotide );
510 conservationMenuItem.setEnabled( !nucleotide );
511 modifyConservation.setEnabled( !nucleotide );
513 //Remember AlignFrame always starts as protein
516 calculateMenu.remove(calculateMenu.getItemCount()-2);
518 setShowProductsEnabled();
524 * Need to call this method when tabs are selected for multiple views,
525 * or when loading from Jalview2XML.java
526 * @param av AlignViewport
528 void setMenusFromViewport(AlignViewport av)
530 padGapsMenuitem.setSelected(av.padGaps);
531 colourTextMenuItem.setSelected(av.showColourText);
532 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
533 conservationMenuItem.setSelected(av.getConservationSelected());
534 seqLimits.setSelected(av.getShowJVSuffix());
535 idRightAlign.setSelected(av.rightAlignIds);
536 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
537 renderGapsMenuItem.setSelected(av.renderGaps);
538 wrapMenuItem.setSelected(av.wrapAlignment);
539 scaleAbove.setVisible(av.wrapAlignment);
540 scaleLeft.setVisible(av.wrapAlignment);
541 scaleRight.setVisible(av.wrapAlignment);
542 annotationPanelMenuItem.setState(av.showAnnotation);
543 viewBoxesMenuItem.setSelected(av.showBoxes);
544 viewTextMenuItem.setSelected(av.showText);
546 setColourSelected(ColourSchemeProperty.
547 getColourName(av.getGlobalColourScheme()));
549 showSeqFeatures.setSelected(av.showSequenceFeatures);
550 hiddenMarkers.setState(av.showHiddenMarkers);
551 applyToAllGroups.setState(av.colourAppliesToAllGroups);
557 Hashtable progressBars;
558 public void setProgressBar(String message, long id)
560 if(progressBars == null)
562 progressBars = new Hashtable();
565 JPanel progressPanel;
566 GridLayout layout = (GridLayout) statusPanel.getLayout();
567 if(progressBars.get( new Long(id) )!=null)
569 progressPanel = (JPanel)progressBars.get( new Long(id) );
570 statusPanel.remove(progressPanel);
571 progressBars.remove( progressPanel );
572 progressPanel = null;
575 statusBar.setText(message);
578 layout.setRows(layout.getRows() - 1);
582 progressPanel = new JPanel(new BorderLayout(10, 5));
584 JProgressBar progressBar = new JProgressBar();
585 progressBar.setIndeterminate(true);
587 progressPanel.add(new JLabel(message), BorderLayout.WEST);
588 progressPanel.add(progressBar, BorderLayout.CENTER);
590 layout.setRows(layout.getRows() + 1);
591 statusPanel.add(progressPanel);
593 progressBars.put(new Long(id), progressPanel);
600 * @return true if any progress bars are still active
602 public boolean operationInProgress()
604 if (progressBars!=null && progressBars.size()>0)
611 Added so Castor Mapping file can obtain Jalview Version
613 public String getVersion()
615 return jalview.bin.Cache.getProperty("VERSION");
618 public FeatureRenderer getFeatureRenderer()
620 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
624 public void fetchSequence_actionPerformed(ActionEvent e)
626 new SequenceFetcher(this);
629 public void addFromFile_actionPerformed(ActionEvent e)
631 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
634 public void reload_actionPerformed(ActionEvent e)
638 if(currentFileFormat.equals("Jalview"))
640 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
641 for(int i=0; i<frames.length; i++)
643 if (frames[i] instanceof AlignFrame
645 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
649 frames[i].setSelected(true);
650 Desktop.instance.closeAssociatedWindows();
652 catch (java.beans.PropertyVetoException ex)
657 Desktop.instance.closeAssociatedWindows();
659 FileLoader loader = new FileLoader();
660 String protocol = fileName.startsWith("http:")? "URL":"File";
661 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
665 Rectangle bounds = this.getBounds();
667 FileLoader loader = new FileLoader();
668 String protocol = fileName.startsWith("http:") ? "URL" : "File";
669 AlignFrame newframe =
670 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
672 newframe.setBounds(bounds);
674 this.closeMenuItem_actionPerformed(true);
680 public void addFromText_actionPerformed(ActionEvent e)
682 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
685 public void addFromURL_actionPerformed(ActionEvent e)
687 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
691 public void save_actionPerformed(ActionEvent e)
694 || (currentFileFormat==null || jalview.io.AppletFormatAdapter.isValidFormat(currentFileFormat, true))
695 || fileName.startsWith("http")
698 saveAs_actionPerformed(null);
702 saveAlignment(fileName, currentFileFormat);
709 * @param e DOCUMENT ME!
711 public void saveAs_actionPerformed(ActionEvent e)
713 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
714 getProperty( "LAST_DIRECTORY"),
715 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
716 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
721 chooser.setFileView(new JalviewFileView());
722 chooser.setDialogTitle("Save Alignment to file");
723 chooser.setToolTipText("Save");
725 int value = chooser.showSaveDialog(this);
727 if (value == JalviewFileChooser.APPROVE_OPTION)
729 currentFileFormat = chooser.getSelectedFormat();
730 if (currentFileFormat == null)
732 JOptionPane.showInternalMessageDialog(Desktop.desktop,
733 "You must select a file format before saving!",
734 "File format not specified",
735 JOptionPane.WARNING_MESSAGE);
736 value = chooser.showSaveDialog(this);
740 fileName = chooser.getSelectedFile().getPath();
742 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
745 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
746 if (currentFileFormat.indexOf(" ")>-1)
748 currentFileFormat = currentFileFormat.substring(0, currentFileFormat.indexOf(" "));
750 saveAlignment(fileName, currentFileFormat);
754 public boolean saveAlignment(String file, String format)
756 boolean success = true;
758 if (format.equalsIgnoreCase("Jalview"))
760 String shortName = title;
762 if (shortName.indexOf(java.io.File.separatorChar) > -1)
764 shortName = shortName.substring(shortName.lastIndexOf(
765 java.io.File.separatorChar) + 1);
768 success = new Jalview2XML().SaveAlignment(this, file, shortName);
770 statusBar.setText("Successfully saved to file: "
772 +format +" format.");
777 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
779 // JBPNote need to have a raise_gui flag here
780 JOptionPane.showInternalMessageDialog(
781 this, "Cannot save file " + fileName + " using format "+format,
782 "Alignment output format not supported",
783 JOptionPane.WARNING_MESSAGE);
784 saveAs_actionPerformed(null);
788 String[] omitHidden = null;
790 if (viewport.hasHiddenColumns)
792 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
793 "The Alignment contains hidden columns."
794 + "\nDo you want to save only the visible alignment?",
795 "Save / Omit Hidden Columns",
796 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
798 if (reply == JOptionPane.YES_OPTION)
800 omitHidden = viewport.getViewAsString(false);
803 FormatAdapter f = new FormatAdapter();
804 String output = f.formatSequences(
806 (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future
807 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
817 java.io.PrintWriter out = new java.io.PrintWriter(
818 new java.io.FileWriter(file));
823 statusBar.setText("Successfully saved to file: "
825 + format + " format.");
830 ex.printStackTrace();
837 JOptionPane.showInternalMessageDialog(
838 this, "Couldn't save file: " + fileName,
840 JOptionPane.WARNING_MESSAGE);
849 * @param e DOCUMENT ME!
851 protected void outputText_actionPerformed(ActionEvent e)
853 String [] omitHidden = null;
855 if(viewport.hasHiddenColumns)
857 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
858 "The Alignment contains hidden columns."
859 +"\nDo you want to output only the visible alignment?",
860 "Save / Omit Hidden Columns",
861 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
863 if(reply==JOptionPane.YES_OPTION)
865 omitHidden = viewport.getViewAsString(false);
869 CutAndPasteTransfer cap = new CutAndPasteTransfer();
870 cap.setForInput(null);
871 Desktop.addInternalFrame(cap,
872 "Alignment output - " + e.getActionCommand(), 600,
876 cap.setText(new FormatAdapter().formatSequences(
877 e.getActionCommand(),
879 omitHidden, viewport.colSel));
885 * @param e DOCUMENT ME!
887 protected void htmlMenuItem_actionPerformed(ActionEvent e)
889 new HTMLOutput(alignPanel,
890 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
891 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
894 public void createImageMap(File file, String image)
896 alignPanel.makePNGImageMap(file, image);
902 * @param e DOCUMENT ME!
904 public void createPNG(File f)
906 alignPanel.makePNG(f);
912 * @param e DOCUMENT ME!
914 public void createEPS(File f)
916 alignPanel.makeEPS(f);
920 public void pageSetup_actionPerformed(ActionEvent e)
922 PrinterJob printJob = PrinterJob.getPrinterJob();
923 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
929 * @param e DOCUMENT ME!
931 public void printMenuItem_actionPerformed(ActionEvent e)
933 //Putting in a thread avoids Swing painting problems
934 PrintThread thread = new PrintThread(alignPanel);
938 public void exportFeatures_actionPerformed(ActionEvent e)
940 new AnnotationExporter().exportFeatures(alignPanel);
944 public void exportAnnotations_actionPerformed(ActionEvent e)
946 new AnnotationExporter().exportAnnotations(
948 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
949 viewport.alignment.getGroups(),
950 ((Alignment)viewport.alignment).alignmentProperties
955 public void associatedData_actionPerformed(ActionEvent e)
957 // Pick the tree file
958 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
961 chooser.setFileView(new JalviewFileView());
962 chooser.setDialogTitle("Load Jalview Annotations or Features File");
963 chooser.setToolTipText("Load Jalview Annotations / Features file");
965 int value = chooser.showOpenDialog(null);
967 if (value == JalviewFileChooser.APPROVE_OPTION)
969 String choice = chooser.getSelectedFile().getPath();
970 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
971 loadJalviewDataFile(choice);
980 * @param e DOCUMENT ME!
982 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
984 if(alignPanels!=null && alignPanels.size()<2)
991 if(alignPanels!=null)
995 for (int i = 0; i < alignPanels.size(); i++)
997 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
998 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
999 .removeStructureViewerListener(ap.seqPanel, null);
1000 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
1001 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
1002 PaintRefresher.RemoveComponent(ap);
1003 ap.av.alignment = null;
1008 int index = tabbedPane.getSelectedIndex();
1010 alignPanels.removeElement(alignPanel);
1011 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1012 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1013 PaintRefresher.RemoveComponent(alignPanel);
1014 viewport.alignment = null;
1018 tabbedPane.removeTabAt(index);
1019 tabbedPane.validate();
1021 if(index==tabbedPane.getTabCount())
1026 this.tabSelectionChanged(index);
1032 this.setClosed(true);
1035 catch (Exception ex)
1037 ex.printStackTrace();
1045 void updateEditMenuBar()
1048 if (viewport.historyList.size() > 0)
1050 undoMenuItem.setEnabled(true);
1051 CommandI command = (CommandI) viewport.historyList.peek();
1052 undoMenuItem.setText("Undo " + command.getDescription());
1056 undoMenuItem.setEnabled(false);
1057 undoMenuItem.setText("Undo");
1060 if (viewport.redoList.size() > 0)
1062 redoMenuItem.setEnabled(true);
1064 CommandI command = (CommandI) viewport.redoList.peek();
1065 redoMenuItem.setText("Redo " + command.getDescription());
1069 redoMenuItem.setEnabled(false);
1070 redoMenuItem.setText("Redo");
1075 public void addHistoryItem(CommandI command)
1077 if(command.getSize()>0)
1079 viewport.historyList.push(command);
1080 viewport.redoList.clear();
1081 updateEditMenuBar();
1082 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1088 * @return alignment objects for all views
1090 AlignmentI[] getViewAlignments()
1092 if (alignPanels!=null)
1094 Enumeration e = alignPanels.elements();
1095 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1096 for (int i=0; e.hasMoreElements(); i++)
1098 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1104 return new AlignmentI[] { viewport.alignment };
1111 * @param e DOCUMENT ME!
1113 protected void undoMenuItem_actionPerformed(ActionEvent e)
1115 if (viewport.historyList.empty())
1117 CommandI command = (CommandI)viewport.historyList.pop();
1118 viewport.redoList.push(command);
1119 command.undoCommand(getViewAlignments());
1121 AlignViewport originalSource = getOriginatingSource(command);
1122 updateEditMenuBar();
1124 if(originalSource!=null)
1126 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1127 originalSource.firePropertyChange("alignment",
1129 originalSource.alignment.getSequences());
1136 * @param e DOCUMENT ME!
1138 protected void redoMenuItem_actionPerformed(ActionEvent e)
1140 if(viewport.redoList.size()<1)
1145 CommandI command = (CommandI) viewport.redoList.pop();
1146 viewport.historyList.push(command);
1147 command.doCommand(getViewAlignments());
1149 AlignViewport originalSource = getOriginatingSource(command);
1150 updateEditMenuBar();
1152 if(originalSource!=null)
1154 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1155 originalSource.firePropertyChange("alignment",
1157 originalSource.alignment.getSequences());
1161 AlignViewport getOriginatingSource(CommandI command)
1163 AlignViewport originalSource = null;
1164 //For sequence removal and addition, we need to fire
1165 //the property change event FROM the viewport where the
1166 //original alignment was altered
1168 if (command instanceof EditCommand)
1170 EditCommand editCommand = (EditCommand) command;
1171 al = editCommand.getAlignment();
1172 Vector comps = (Vector) PaintRefresher.components
1173 .get(viewport.getSequenceSetId());
1175 for (int i = 0; i < comps.size(); i++)
1177 if (comps.elementAt(i) instanceof AlignmentPanel)
1179 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1181 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1188 if (originalSource == null)
1190 //The original view is closed, we must validate
1191 //the current view against the closed view first
1194 PaintRefresher.validateSequences(al, viewport.alignment);
1197 originalSource = viewport;
1200 return originalSource;
1206 * @param up DOCUMENT ME!
1208 public void moveSelectedSequences(boolean up)
1210 SequenceGroup sg = viewport.getSelectionGroup();
1219 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1221 SequenceI seq = viewport.alignment.getSequenceAt(i);
1223 if (!sg.getSequences(null).contains(seq))
1228 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1230 if (sg.getSequences(null).contains(temp))
1235 viewport.alignment.getSequences().setElementAt(temp, i);
1236 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1241 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1243 SequenceI seq = viewport.alignment.getSequenceAt(i);
1245 if (!sg.getSequences(null).contains(seq))
1250 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1252 if (sg.getSequences(null).contains(temp))
1257 viewport.alignment.getSequences().setElementAt(temp, i);
1258 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1262 alignPanel.paintAlignment(true);
1268 synchronized void slideSequences(boolean right, int size)
1270 Vector sg = new Vector();
1271 if(viewport.cursorMode)
1273 sg.addElement(viewport.alignment.getSequenceAt(
1274 alignPanel.seqPanel.seqCanvas.cursorY));
1276 else if(viewport.getSelectionGroup()!=null
1277 && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
1279 sg = viewport.getSelectionGroup().getSequences(
1280 viewport.hiddenRepSequences);
1288 Vector invertGroup = new Vector();
1290 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1292 if(!sg.contains(viewport.alignment.getSequenceAt(i)))
1293 invertGroup.add(viewport.alignment.getSequenceAt(i));
1296 SequenceI[] seqs1 = new SequenceI[sg.size()];
1297 for (int i = 0; i < sg.size(); i++)
1298 seqs1[i] = (SequenceI) sg.elementAt(i);
1300 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1301 for (int i = 0; i < invertGroup.size(); i++)
1302 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1304 SlideSequencesCommand ssc;
1306 ssc = new SlideSequencesCommand("Slide Sequences",
1308 viewport.getGapCharacter()
1311 ssc = new SlideSequencesCommand("Slide Sequences",
1313 viewport.getGapCharacter()
1316 int groupAdjustment = 0;
1317 if (ssc.getGapsInsertedBegin() && right)
1319 if (viewport.cursorMode)
1320 alignPanel.seqPanel.moveCursor(size, 0);
1322 groupAdjustment = size;
1324 else if (!ssc.getGapsInsertedBegin() && !right)
1326 if (viewport.cursorMode)
1327 alignPanel.seqPanel.moveCursor( -size, 0);
1329 groupAdjustment = -size;
1332 if (groupAdjustment != 0)
1334 viewport.getSelectionGroup().setStartRes(
1335 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1336 viewport.getSelectionGroup().setEndRes(
1337 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1341 boolean appendHistoryItem = false;
1342 if(viewport.historyList!=null
1343 && viewport.historyList.size()>0
1344 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1346 appendHistoryItem = ssc.appendSlideCommand(
1347 (SlideSequencesCommand)viewport.historyList.peek())
1351 if(!appendHistoryItem)
1352 addHistoryItem(ssc);
1361 * @param e DOCUMENT ME!
1363 protected void copy_actionPerformed(ActionEvent e)
1366 if (viewport.getSelectionGroup() == null)
1370 // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
1371 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1372 String[] omitHidden = null;
1374 if (viewport.hasHiddenColumns)
1376 omitHidden = viewport.getViewAsString(true);
1379 String output = new FormatAdapter().formatSequences(
1384 StringSelection ss = new StringSelection(output);
1388 jalview.gui.Desktop.internalCopy = true;
1389 //Its really worth setting the clipboard contents
1390 //to empty before setting the large StringSelection!!
1391 Toolkit.getDefaultToolkit().getSystemClipboard()
1392 .setContents(new StringSelection(""), null);
1394 Toolkit.getDefaultToolkit().getSystemClipboard()
1395 .setContents(ss, Desktop.instance);
1397 catch (OutOfMemoryError er)
1399 er.printStackTrace();
1400 javax.swing.SwingUtilities.invokeLater(new Runnable()
1404 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1405 "Out of memory copying region!!"
1407 "\nSee help files for increasing Java Virtual Machine memory."
1409 javax.swing.JOptionPane.WARNING_MESSAGE);
1416 Vector hiddenColumns = null;
1417 if(viewport.hasHiddenColumns)
1419 hiddenColumns =new Vector();
1420 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1421 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1424 int[] region = (int[])
1425 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1427 hiddenColumns.addElement(new int[]
1428 {region[0] - hiddenOffset,
1429 region[1]-hiddenOffset});
1433 Desktop.jalviewClipboard = new Object[]
1436 viewport.alignment.getDataset(),
1438 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1444 * @param e DOCUMENT ME!
1446 protected void pasteNew_actionPerformed(ActionEvent e)
1454 * @param e DOCUMENT ME!
1456 protected void pasteThis_actionPerformed(ActionEvent e)
1462 * Paste contents of Jalview clipboard
1464 * @param newAlignment true to paste to a new alignment, otherwise add to this.
1466 void paste(boolean newAlignment)
1468 boolean externalPaste=true;
1471 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1472 Transferable contents = c.getContents(this);
1474 if (contents == null)
1482 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1483 if (str.length() < 1)
1488 format = new IdentifyFile().Identify(str, "Paste");
1491 catch (OutOfMemoryError er)
1493 er.printStackTrace();
1494 javax.swing.SwingUtilities.invokeLater(new Runnable()
1498 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1499 "Out of memory pasting sequences!!"
1501 "\nSee help files for increasing Java Virtual Machine memory."
1503 javax.swing.JOptionPane.WARNING_MESSAGE);
1510 SequenceI[] sequences;
1511 boolean annotationAdded = false;
1512 AlignmentI alignment = null;
1514 if(Desktop.jalviewClipboard!=null)
1516 // The clipboard was filled from within Jalview, we must use the sequences
1517 // And dataset from the copied alignment
1518 SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
1519 // be doubly sure that we create *new* sequence objects.
1520 sequences = new SequenceI[newseq.length];
1521 for (int i=0;i<newseq.length;i++) {
1522 sequences[i] = new Sequence(newseq[i]);
1524 alignment = new Alignment(sequences);
1525 externalPaste = false;
1529 // parse the clipboard as an alignment.
1530 alignment = new FormatAdapter().readFile(str, "Paste", format);
1531 sequences = alignment.getSequencesArray();
1539 if (Desktop.jalviewClipboard != null)
1541 // dataset is inherited
1542 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1546 // new dataset is constructed
1547 alignment.setDataset(null);
1549 alwidth = alignment.getWidth()+1;
1553 AlignmentI pastedal = alignment; // preserve pasted alignment object
1554 // Add pasted sequences and dataset into existing alignment.
1555 alignment = viewport.getAlignment();
1556 alwidth = alignment.getWidth()+1;
1557 // decide if we need to import sequences from an existing dataset
1558 boolean importDs = Desktop.jalviewClipboard != null
1559 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1560 // importDs==true instructs us to copy over new dataset sequences from
1561 // an existing alignment
1562 Vector newDs = (importDs) ? new Vector() : null; // used to create
1563 // minimum dataset set
1565 for (int i = 0; i < sequences.length; i++)
1569 newDs.addElement(null);
1571 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1573 if (importDs && ds != null)
1575 if (!newDs.contains(ds))
1577 newDs.setElementAt(ds, i);
1578 ds = new Sequence(ds);
1579 // update with new dataset sequence
1580 sequences[i].setDatasetSequence(ds);
1584 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1589 // copy and derive new dataset sequence
1590 sequences[i] = sequences[i].deriveSequence();
1591 alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
1592 // TODO: avoid creation of duplicate dataset sequences with a
1593 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1595 alignment.addSequence(sequences[i]); // merges dataset
1599 newDs.clear(); // tidy up
1601 if (pastedal.getAlignmentAnnotation()!=null) {
1602 // Add any annotation attached to alignment.
1603 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1604 for (int i=0; i<alann.length; i++)
1606 annotationAdded=true;
1607 if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
1608 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1609 newann.padAnnotation(alwidth);
1610 alignment.addAnnotation(newann);
1615 if (!newAlignment) {
1619 addHistoryItem(new EditCommand(
1624 alignment.getWidth(),
1628 // Add any annotations attached to sequences
1629 for (int i = 0; i < sequences.length; i++)
1631 if (sequences[i].getAnnotation() != null)
1633 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1635 annotationAdded=true;
1636 sequences[i].getAnnotation()[a].adjustForAlignment();
1637 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1638 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
1639 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1643 if (!newAlignment) {
1645 // propagate alignment changed.
1646 viewport.setEndSeq(alignment.getHeight());
1647 if (annotationAdded)
1649 // Duplicate sequence annotation in all views.
1650 AlignmentI[] alview = this.getViewAlignments();
1651 for (int i = 0; i < sequences.length; i++)
1653 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1656 for (int avnum=0;avnum<alview.length; avnum++)
1658 if (alview[avnum]!=alignment)
1660 // duplicate in a view other than the one with input focus
1661 int avwidth = alview[avnum].getWidth()+1;
1662 // this relies on sann being preserved after we
1663 // modify the sequence's annotation array for each duplication
1664 for (int a=0; a<sann.length; a++)
1666 AlignmentAnnotation newann = new AlignmentAnnotation(sann[a]);
1667 sequences[i].addAlignmentAnnotation(newann);
1668 newann.padAnnotation(avwidth);
1669 alview[avnum].addAnnotation(newann); // annotation was duplicated earlier
1670 alview[avnum].setAnnotationIndex(newann, a);
1675 buildSortByAnnotationScoresMenu();
1677 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1680 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1681 String newtitle = new String("Copied sequences");
1683 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1685 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1686 for(int i=0; i<hc.size(); i++)
1688 int [] region = (int[]) hc.elementAt(i);
1689 af.viewport.hideColumns(region[0], region[1]);
1694 //>>>This is a fix for the moment, until a better solution is found!!<<<
1695 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1696 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1698 // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
1699 if (!externalPaste) {
1700 if (title.startsWith("Copied sequences"))
1706 newtitle = newtitle.concat("- from " + title);
1709 newtitle = new String("Pasted sequences");
1712 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1719 catch (Exception ex)
1721 ex.printStackTrace();
1722 System.out.println("Exception whilst pasting: "+ex);
1723 // could be anything being pasted in here
1732 * @param e DOCUMENT ME!
1734 protected void cut_actionPerformed(ActionEvent e)
1736 copy_actionPerformed(null);
1737 delete_actionPerformed(null);
1743 * @param e DOCUMENT ME!
1745 protected void delete_actionPerformed(ActionEvent evt)
1748 SequenceGroup sg = viewport.getSelectionGroup();
1754 Vector seqs = new Vector();
1756 for (int i = 0; i < sg.getSize(); i++)
1758 seq = sg.getSequenceAt(i);
1759 seqs.addElement(seq);
1763 // If the cut affects all sequences, remove highlighted columns
1764 if (sg.getSize() == viewport.alignment.getHeight())
1766 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1767 sg.getEndRes() + 1);
1771 SequenceI [] cut = new SequenceI[seqs.size()];
1772 for(int i=0; i<seqs.size(); i++)
1774 cut[i] = (SequenceI)seqs.elementAt(i);
1781 addHistoryItem(new EditCommand("Cut Sequences",
1785 sg.getEndRes()-sg.getStartRes()+1,
1786 viewport.alignment));
1789 viewport.setSelectionGroup(null);
1790 viewport.alignment.deleteGroup(sg);
1792 viewport.firePropertyChange("alignment", null,
1793 viewport.getAlignment().getSequences());
1795 if (viewport.getAlignment().getHeight() < 1)
1799 this.setClosed(true);
1801 catch (Exception ex)
1810 * @param e DOCUMENT ME!
1812 protected void deleteGroups_actionPerformed(ActionEvent e)
1814 viewport.alignment.deleteAllGroups();
1815 viewport.sequenceColours = null;
1816 viewport.setSelectionGroup(null);
1817 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1818 alignPanel.paintAlignment(true);
1824 * @param e DOCUMENT ME!
1826 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1828 SequenceGroup sg = new SequenceGroup();
1830 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1833 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1836 sg.setEndRes(viewport.alignment.getWidth() - 1);
1837 viewport.setSelectionGroup(sg);
1838 alignPanel.paintAlignment(true);
1839 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1845 * @param e DOCUMENT ME!
1847 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1849 if(viewport.cursorMode)
1851 alignPanel.seqPanel.keyboardNo1 = null;
1852 alignPanel.seqPanel.keyboardNo2 = null;
1854 viewport.setSelectionGroup(null);
1855 viewport.getColumnSelection().clear();
1856 viewport.setSelectionGroup(null);
1857 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1858 alignPanel.idPanel.idCanvas.searchResults = null;
1859 alignPanel.paintAlignment(true);
1860 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1866 * @param e DOCUMENT ME!
1868 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1870 SequenceGroup sg = viewport.getSelectionGroup();
1874 selectAllSequenceMenuItem_actionPerformed(null);
1879 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1882 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1885 alignPanel.paintAlignment(true);
1887 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1890 public void invertColSel_actionPerformed(ActionEvent e)
1892 viewport.invertColumnSelection();
1893 alignPanel.paintAlignment(true);
1900 * @param e DOCUMENT ME!
1902 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1904 trimAlignment(true);
1910 * @param e DOCUMENT ME!
1912 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1914 trimAlignment(false);
1917 void trimAlignment(boolean trimLeft)
1919 ColumnSelection colSel = viewport.getColumnSelection();
1922 if (colSel.size() > 0)
1926 column = colSel.getMin();
1930 column = colSel.getMax();
1934 if(viewport.getSelectionGroup()!=null)
1936 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1937 hiddenRepSequences);
1941 seqs = viewport.alignment.getSequencesArray();
1945 TrimRegionCommand trimRegion;
1948 trimRegion = new TrimRegionCommand("Remove Left",
1949 TrimRegionCommand.TRIM_LEFT,
1954 viewport.selectionGroup);
1955 viewport.setStartRes(0);
1959 trimRegion = new TrimRegionCommand("Remove Right",
1960 TrimRegionCommand.TRIM_RIGHT,
1965 viewport.selectionGroup);
1968 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1971 addHistoryItem(trimRegion);
1973 Vector groups = viewport.alignment.getGroups();
1975 for (int i = 0; i < groups.size(); i++)
1977 SequenceGroup sg = (SequenceGroup) groups.get(i);
1979 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1980 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1982 viewport.alignment.deleteGroup(sg);
1986 viewport.firePropertyChange("alignment", null,
1987 viewport.getAlignment().getSequences());
1994 * @param e DOCUMENT ME!
1996 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1998 int start = 0, end = viewport.alignment.getWidth()-1;
2001 if (viewport.getSelectionGroup() != null)
2003 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
2004 hiddenRepSequences);
2005 start = viewport.getSelectionGroup().getStartRes();
2006 end = viewport.getSelectionGroup().getEndRes();
2010 seqs = viewport.alignment.getSequencesArray();
2014 RemoveGapColCommand removeGapCols =
2015 new RemoveGapColCommand("Remove Gapped Columns",
2018 viewport.alignment);
2020 addHistoryItem(removeGapCols);
2022 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
2024 //This is to maintain viewport position on first residue
2026 SequenceI seq = viewport.alignment.getSequenceAt(0);
2027 int startRes = seq.findPosition(viewport.startRes);
2028 // ShiftList shifts;
2029 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2030 // edit.alColumnChanges=shifts.getInverse();
2031 // if (viewport.hasHiddenColumns)
2032 // viewport.getColumnSelection().compensateForEdits(shifts);
2033 viewport.setStartRes(seq.findIndex(startRes)-1);
2034 viewport.firePropertyChange("alignment", null,
2035 viewport.getAlignment().getSequences());
2042 * @param e DOCUMENT ME!
2044 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2046 int start = 0, end = viewport.alignment.getWidth()-1;
2049 if (viewport.getSelectionGroup() != null)
2051 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
2052 hiddenRepSequences);
2053 start = viewport.getSelectionGroup().getStartRes();
2054 end = viewport.getSelectionGroup().getEndRes();
2058 seqs = viewport.alignment.getSequencesArray();
2061 //This is to maintain viewport position on first residue
2063 SequenceI seq = viewport.alignment.getSequenceAt(0);
2064 int startRes = seq.findPosition(viewport.startRes);
2066 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
2069 viewport.alignment));
2071 viewport.setStartRes(seq.findIndex(startRes)-1);
2073 viewport.firePropertyChange("alignment", null,
2074 viewport.getAlignment().getSequences());
2081 * @param e DOCUMENT ME!
2083 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2085 viewport.padGaps = padGapsMenuitem.isSelected();
2087 viewport.firePropertyChange("alignment",
2089 viewport.getAlignment().getSequences());
2095 * @param e DOCUMENT ME!
2097 public void findMenuItem_actionPerformed(ActionEvent e)
2102 public void newView_actionPerformed(ActionEvent e)
2104 AlignmentPanel newap =
2105 new Jalview2XML().copyAlignPanel(alignPanel, true);
2107 newap.av.gatherViewsHere = false;
2109 if (viewport.viewName == null)
2111 viewport.viewName = "Original";
2114 newap.av.historyList = viewport.historyList;
2115 newap.av.redoList = viewport.redoList;
2117 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2118 String newViewName = "View " +index;
2120 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2121 getSequenceSetId());
2122 Vector existingNames = new Vector();
2123 for(int i=0; i<comps.size(); i++)
2125 if(comps.elementAt(i) instanceof AlignmentPanel)
2127 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
2128 if(!existingNames.contains(ap.av.viewName))
2130 existingNames.addElement(ap.av.viewName);
2135 while(existingNames.contains(newViewName))
2137 newViewName = "View "+ (++index);
2140 newap.av.viewName = newViewName;
2142 addAlignmentPanel(newap, false);
2144 if(alignPanels.size()==2)
2146 viewport.gatherViewsHere = true;
2148 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2151 public void expandViews_actionPerformed(ActionEvent e)
2153 Desktop.instance.explodeViews(this);
2156 public void gatherViews_actionPerformed(ActionEvent e)
2158 Desktop.instance.gatherViews(this);
2166 * @param e DOCUMENT ME!
2168 public void font_actionPerformed(ActionEvent e)
2170 new FontChooser(alignPanel);
2177 * @param e DOCUMENT ME!
2179 protected void seqLimit_actionPerformed(ActionEvent e)
2181 viewport.setShowJVSuffix(seqLimits.isSelected());
2183 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
2184 alignPanel.paintAlignment(true);
2187 public void idRightAlign_actionPerformed(ActionEvent e)
2189 viewport.rightAlignIds = idRightAlign.isSelected();
2190 alignPanel.paintAlignment(true);
2193 public void centreColumnLabels_actionPerformed(ActionEvent e)
2195 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2196 alignPanel.paintAlignment(true);
2204 * @param e DOCUMENT ME!
2206 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2208 viewport.setColourText(colourTextMenuItem.isSelected());
2209 alignPanel.paintAlignment(true);
2215 * @param e DOCUMENT ME!
2217 public void wrapMenuItem_actionPerformed(ActionEvent e)
2219 scaleAbove.setVisible(wrapMenuItem.isSelected());
2220 scaleLeft.setVisible(wrapMenuItem.isSelected());
2221 scaleRight.setVisible(wrapMenuItem.isSelected());
2222 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2223 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2226 public void showAllSeqs_actionPerformed(ActionEvent e)
2228 viewport.showAllHiddenSeqs();
2231 public void showAllColumns_actionPerformed(ActionEvent e)
2233 viewport.showAllHiddenColumns();
2237 public void hideSelSequences_actionPerformed(ActionEvent e)
2239 viewport.hideAllSelectedSeqs();
2240 alignPanel.paintAlignment(true);
2243 public void hideSelColumns_actionPerformed(ActionEvent e)
2245 viewport.hideSelectedColumns();
2246 alignPanel.paintAlignment(true);
2249 public void hiddenMarkers_actionPerformed(ActionEvent e)
2251 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2258 * @param e DOCUMENT ME!
2260 protected void scaleAbove_actionPerformed(ActionEvent e)
2262 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2263 alignPanel.paintAlignment(true);
2269 * @param e DOCUMENT ME!
2271 protected void scaleLeft_actionPerformed(ActionEvent e)
2273 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2274 alignPanel.paintAlignment(true);
2280 * @param e DOCUMENT ME!
2282 protected void scaleRight_actionPerformed(ActionEvent e)
2284 viewport.setScaleRightWrapped(scaleRight.isSelected());
2285 alignPanel.paintAlignment(true);
2291 * @param e DOCUMENT ME!
2293 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2295 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2296 alignPanel.paintAlignment(true);
2302 * @param e DOCUMENT ME!
2304 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2306 viewport.setShowText(viewTextMenuItem.isSelected());
2307 alignPanel.paintAlignment(true);
2313 * @param e DOCUMENT ME!
2315 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2317 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2318 alignPanel.paintAlignment(true);
2322 public FeatureSettings featureSettings;
2323 public void featureSettings_actionPerformed(ActionEvent e)
2325 if(featureSettings !=null )
2327 featureSettings.close();
2328 featureSettings = null;
2330 featureSettings = new FeatureSettings(this);
2336 * @param evt DOCUMENT ME!
2338 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2340 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2341 alignPanel.paintAlignment(true);
2342 if (alignPanel.getOverviewPanel() != null)
2344 alignPanel.getOverviewPanel().updateOverviewImage();
2351 * @param e DOCUMENT ME!
2353 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2355 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2356 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2359 public void alignmentProperties()
2361 JEditorPane editPane = new JEditorPane("text/html","");
2362 editPane.setEditable(false);
2363 StringBuffer contents = new StringBuffer("<html>");
2366 int min=Integer.MAX_VALUE, max=0;
2367 for(int i=0; i<viewport.alignment.getHeight(); i++)
2369 int size = viewport.alignment.getSequenceAt(i).getEnd()
2370 -viewport.alignment.getSequenceAt(i).getStart();
2377 avg = avg/(float)viewport.alignment.getHeight();
2379 contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
2380 contents.append("<br>Minimum Sequence Length: "+min);
2381 contents.append("<br>Maximum Sequence Length: "+max);
2382 contents.append("<br>Average Length: "+(int)avg);
2384 if (((Alignment)viewport.alignment).getProperties() != null)
2386 Hashtable props = ((Alignment)viewport.alignment).getProperties();
2387 Enumeration en = props.keys();
2388 contents.append("<br><br><table border=\"1\">");
2389 while(en.hasMoreElements())
2391 String key = en.nextElement().toString();
2392 StringBuffer val = new StringBuffer();
2393 String vals = props.get(key).toString();
2396 npos = vals.indexOf("\n",pos);
2399 val.append(vals.substring(pos));
2401 val.append(vals.substring(pos, npos));
2406 contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
2408 contents.append("</table>");
2410 editPane.setText(contents.toString()+"</html>");
2411 JInternalFrame frame = new JInternalFrame();
2412 frame.getContentPane().add(new JScrollPane(editPane));
2414 Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
2421 * @param e DOCUMENT ME!
2423 public void overviewMenuItem_actionPerformed(ActionEvent e)
2425 if (alignPanel.overviewPanel != null)
2430 JInternalFrame frame = new JInternalFrame();
2431 OverviewPanel overview = new OverviewPanel(alignPanel);
2432 frame.setContentPane(overview);
2433 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2434 frame.getWidth(), frame.getHeight());
2436 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2437 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2439 public void internalFrameClosed(
2440 javax.swing.event.InternalFrameEvent evt)
2442 alignPanel.setOverviewPanel(null);
2447 alignPanel.setOverviewPanel(overview);
2450 public void textColour_actionPerformed(ActionEvent e)
2452 new TextColourChooser().chooseColour(alignPanel, null);
2458 * @param e DOCUMENT ME!
2460 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2468 * @param e DOCUMENT ME!
2470 public void clustalColour_actionPerformed(ActionEvent e)
2472 changeColour(new ClustalxColourScheme(
2473 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2479 * @param e DOCUMENT ME!
2481 public void zappoColour_actionPerformed(ActionEvent e)
2483 changeColour(new ZappoColourScheme());
2489 * @param e DOCUMENT ME!
2491 public void taylorColour_actionPerformed(ActionEvent e)
2493 changeColour(new TaylorColourScheme());
2499 * @param e DOCUMENT ME!
2501 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2503 changeColour(new HydrophobicColourScheme());
2509 * @param e DOCUMENT ME!
2511 public void helixColour_actionPerformed(ActionEvent e)
2513 changeColour(new HelixColourScheme());
2519 * @param e DOCUMENT ME!
2521 public void strandColour_actionPerformed(ActionEvent e)
2523 changeColour(new StrandColourScheme());
2529 * @param e DOCUMENT ME!
2531 public void turnColour_actionPerformed(ActionEvent e)
2533 changeColour(new TurnColourScheme());
2539 * @param e DOCUMENT ME!
2541 public void buriedColour_actionPerformed(ActionEvent e)
2543 changeColour(new BuriedColourScheme());
2549 * @param e DOCUMENT ME!
2551 public void nucleotideColour_actionPerformed(ActionEvent e)
2553 changeColour(new NucleotideColourScheme());
2556 public void annotationColour_actionPerformed(ActionEvent e)
2558 new AnnotationColourChooser(viewport, alignPanel);
2565 * @param e DOCUMENT ME!
2567 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2569 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2575 * @param cs DOCUMENT ME!
2577 public void changeColour(ColourSchemeI cs)
2583 if (viewport.getAbovePIDThreshold())
2585 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2588 cs.setThreshold(threshold,
2589 viewport.getIgnoreGapsConsensus());
2591 viewport.setGlobalColourScheme(cs);
2595 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2598 if (viewport.getConservationSelected())
2601 Alignment al = (Alignment) viewport.alignment;
2602 Conservation c = new Conservation("All",
2603 ResidueProperties.propHash, 3,
2604 al.getSequences(), 0,
2608 c.verdict(false, viewport.ConsPercGaps);
2610 cs.setConservation(c);
2612 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2617 cs.setConservation(null);
2620 cs.setConsensus(viewport.hconsensus);
2623 viewport.setGlobalColourScheme(cs);
2625 if (viewport.getColourAppliesToAllGroups())
2627 Vector groups = viewport.alignment.getGroups();
2629 for (int i = 0; i < groups.size(); i++)
2631 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2639 if (cs instanceof ClustalxColourScheme)
2641 sg.cs = new ClustalxColourScheme(
2642 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2644 else if (cs instanceof UserColourScheme)
2646 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2652 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2654 catch (Exception ex)
2659 if (viewport.getAbovePIDThreshold()
2660 || cs instanceof PIDColourScheme
2661 || cs instanceof Blosum62ColourScheme)
2663 sg.cs.setThreshold(threshold,
2664 viewport.getIgnoreGapsConsensus());
2666 sg.cs.setConsensus(AAFrequency.calculate(
2667 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2672 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2676 if (viewport.getConservationSelected())
2678 Conservation c = new Conservation("Group",
2679 ResidueProperties.propHash, 3,
2680 sg.getSequences(viewport.
2681 hiddenRepSequences),
2685 c.verdict(false, viewport.ConsPercGaps);
2686 sg.cs.setConservation(c);
2690 sg.cs.setConservation(null);
2695 if (alignPanel.getOverviewPanel() != null)
2697 alignPanel.getOverviewPanel().updateOverviewImage();
2703 alignPanel.paintAlignment(true);
2709 * @param e DOCUMENT ME!
2711 protected void modifyPID_actionPerformed(ActionEvent e)
2713 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2715 SliderPanel.setPIDSliderSource(alignPanel,
2716 viewport.getGlobalColourScheme(),
2718 SliderPanel.showPIDSlider();
2725 * @param e DOCUMENT ME!
2727 protected void modifyConservation_actionPerformed(ActionEvent e)
2729 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2731 SliderPanel.setConservationSlider(alignPanel,
2732 viewport.globalColourScheme,
2734 SliderPanel.showConservationSlider();
2741 * @param e DOCUMENT ME!
2743 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2745 viewport.setConservationSelected(conservationMenuItem.isSelected());
2747 viewport.setAbovePIDThreshold(false);
2748 abovePIDThreshold.setSelected(false);
2750 changeColour(viewport.getGlobalColourScheme());
2752 modifyConservation_actionPerformed(null);
2758 * @param e DOCUMENT ME!
2760 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2762 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2764 conservationMenuItem.setSelected(false);
2765 viewport.setConservationSelected(false);
2767 changeColour(viewport.getGlobalColourScheme());
2769 modifyPID_actionPerformed(null);
2775 * @param e DOCUMENT ME!
2777 public void userDefinedColour_actionPerformed(ActionEvent e)
2779 if (e.getActionCommand().equals("User Defined..."))
2781 new UserDefinedColours(alignPanel, null);
2785 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2786 getUserColourSchemes().get(e.getActionCommand());
2792 public void updateUserColourMenu()
2795 Component[] menuItems = colourMenu.getMenuComponents();
2796 int i, iSize = menuItems.length;
2797 for (i = 0; i < iSize; i++)
2799 if (menuItems[i].getName() != null &&
2800 menuItems[i].getName().equals("USER_DEFINED"))
2802 colourMenu.remove(menuItems[i]);
2806 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2808 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2809 getUserColourSchemes().keys();
2811 while (userColours.hasMoreElements())
2813 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2815 nextElement().toString());
2816 radioItem.setName("USER_DEFINED");
2817 radioItem.addMouseListener(new MouseAdapter()
2819 public void mousePressed(MouseEvent evt)
2821 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2823 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2825 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2827 "Remove from default list?",
2828 "Remove user defined colour",
2829 JOptionPane.YES_NO_OPTION);
2830 if(option == JOptionPane.YES_OPTION)
2832 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2833 radioItem.getText());
2834 colourMenu.remove(radioItem);
2838 radioItem.addActionListener(new ActionListener()
2840 public void actionPerformed(ActionEvent evt)
2842 userDefinedColour_actionPerformed(evt);
2849 radioItem.addActionListener(new ActionListener()
2851 public void actionPerformed(ActionEvent evt)
2853 userDefinedColour_actionPerformed(evt);
2857 colourMenu.insert(radioItem, 15);
2858 colours.add(radioItem);
2866 * @param e DOCUMENT ME!
2868 public void PIDColour_actionPerformed(ActionEvent e)
2870 changeColour(new PIDColourScheme());
2876 * @param e DOCUMENT ME!
2878 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2880 changeColour(new Blosum62ColourScheme());
2886 * @param e DOCUMENT ME!
2888 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2890 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2891 AlignmentSorter.sortByPID(viewport.getAlignment(),
2892 viewport.getAlignment().getSequenceAt(0), null);
2893 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2894 viewport.alignment));
2895 alignPanel.paintAlignment(true);
2901 * @param e DOCUMENT ME!
2903 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2905 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2906 AlignmentSorter.sortByID(viewport.getAlignment());
2907 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2908 alignPanel.paintAlignment(true);
2914 * @param e DOCUMENT ME!
2916 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2918 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2919 AlignmentSorter.sortByGroup(viewport.getAlignment());
2920 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2922 alignPanel.paintAlignment(true);
2927 * @param e DOCUMENT ME!
2929 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2931 new RedundancyPanel(alignPanel, this);
2938 * @param e DOCUMENT ME!
2940 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2942 if ( (viewport.getSelectionGroup() == null) ||
2943 (viewport.getSelectionGroup().getSize() < 2))
2945 JOptionPane.showInternalMessageDialog(this,
2946 "You must select at least 2 sequences.",
2947 "Invalid Selection",
2948 JOptionPane.WARNING_MESSAGE);
2952 JInternalFrame frame = new JInternalFrame();
2953 frame.setContentPane(new PairwiseAlignPanel(viewport));
2954 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2961 * @param e DOCUMENT ME!
2963 public void PCAMenuItem_actionPerformed(ActionEvent e)
2965 if ( ( (viewport.getSelectionGroup() != null) &&
2966 (viewport.getSelectionGroup().getSize() < 4) &&
2967 (viewport.getSelectionGroup().getSize() > 0)) ||
2968 (viewport.getAlignment().getHeight() < 4))
2970 JOptionPane.showInternalMessageDialog(this,
2971 "Principal component analysis must take\n" +
2972 "at least 4 input sequences.",
2973 "Sequence selection insufficient",
2974 JOptionPane.WARNING_MESSAGE);
2979 new PCAPanel(alignPanel);
2983 public void autoCalculate_actionPerformed(ActionEvent e)
2985 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2986 if(viewport.autoCalculateConsensus)
2988 viewport.firePropertyChange("alignment",
2990 viewport.getAlignment().getSequences());
2998 * @param e DOCUMENT ME!
3000 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3002 NewTreePanel("AV", "PID", "Average distance tree using PID");
3008 * @param e DOCUMENT ME!
3010 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3012 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3018 * @param e DOCUMENT ME!
3020 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3022 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3028 * @param e DOCUMENT ME!
3030 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3032 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3038 * @param type DOCUMENT ME!
3039 * @param pwType DOCUMENT ME!
3040 * @param title DOCUMENT ME!
3042 void NewTreePanel(String type, String pwType, String title)
3046 if (viewport.getSelectionGroup() != null)
3048 if (viewport.getSelectionGroup().getSize() < 3)
3050 JOptionPane.showMessageDialog(Desktop.desktop,
3051 "You need to have more than two sequences selected to build a tree!",
3052 "Not enough sequences",
3053 JOptionPane.WARNING_MESSAGE);
3058 SequenceGroup sg = viewport.getSelectionGroup();
3060 /* Decide if the selection is a column region */
3061 while (s < sg.getSize())
3063 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
3066 JOptionPane.showMessageDialog(Desktop.desktop,
3067 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
3068 "Try using the Pad function in the edit menu,\n" +
3069 "or one of the multiple sequence alignment web services.",
3070 "Sequences in selection are not aligned",
3071 JOptionPane.WARNING_MESSAGE);
3077 title = title + " on region";
3078 tp = new TreePanel(alignPanel, type, pwType);
3082 //are the sequences aligned?
3083 if (!viewport.alignment.isAligned())
3085 JOptionPane.showMessageDialog(Desktop.desktop,
3086 "The sequences must be aligned before creating a tree.\n" +
3087 "Try using the Pad function in the edit menu,\n" +
3088 "or one of the multiple sequence alignment web services.",
3089 "Sequences not aligned",
3090 JOptionPane.WARNING_MESSAGE);
3095 if(viewport.alignment.getHeight()<2)
3100 tp = new TreePanel(alignPanel, type, pwType);
3105 if(viewport.viewName!=null)
3107 title+= viewport.viewName+" of ";
3110 title += this.title;
3112 Desktop.addInternalFrame(tp, title, 600, 500);
3118 * @param title DOCUMENT ME!
3119 * @param order DOCUMENT ME!
3121 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
3123 final JMenuItem item = new JMenuItem("by " + title);
3125 item.addActionListener(new java.awt.event.ActionListener()
3127 public void actionPerformed(ActionEvent e)
3129 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3131 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
3132 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3134 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3135 viewport.alignment));
3137 alignPanel.paintAlignment(true);
3142 * Add a new sort by annotation score menu item
3143 * @param sort the menu to add the option to
3144 * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
3146 public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
3148 final JMenuItem item = new JMenuItem(scoreLabel);
3150 item.addActionListener(new java.awt.event.ActionListener()
3152 public void actionPerformed(ActionEvent e)
3154 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3155 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());//,viewport.getSelectionGroup());
3156 addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
3157 alignPanel.paintAlignment(true);
3162 * last hash for alignment's annotation array - used to minimise cost of rebuild.
3164 protected int _annotationScoreVectorHash;
3166 * search the alignment and rebuild the sort by annotation score submenu
3167 * the last alignment annotation vector hash is stored to minimize
3168 * cost of rebuilding in subsequence calls.
3171 public void buildSortByAnnotationScoresMenu()
3173 if(viewport.alignment.getAlignmentAnnotation()==null)
3178 if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
3180 sortByAnnotScore.removeAll();
3181 // almost certainly a quicker way to do this - but we keep it simple
3182 Hashtable scoreSorts=new Hashtable();
3183 AlignmentAnnotation aann[];
3184 Enumeration sq = viewport.alignment.getSequences().elements();
3185 while (sq.hasMoreElements())
3187 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3188 for (int i=0;aann!=null && i<aann.length; i++)
3190 if (aann[i].hasScore() && aann[i].sequenceRef!=null)
3192 scoreSorts.put(aann[i].label, aann[i].label);
3196 Enumeration labels = scoreSorts.keys();
3197 while (labels.hasMoreElements())
3199 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
3201 sortByAnnotScore.setVisible(scoreSorts.size()>0);
3204 _annotationScoreVectorHash =
3205 viewport.alignment.getAlignmentAnnotation().hashCode();
3210 * Maintain the Order by->Displayed Tree menu.
3211 * Creates a new menu item for a TreePanel with an appropriate
3212 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
3213 * to remove the menu item when the treePanel is closed, and adjust
3214 * the tree leaf to sequence mapping when the alignment is modified.
3215 * @param treePanel Displayed tree window.
3216 * @param title SortBy menu item title.
3218 public void buildTreeMenu()
3220 sortByTreeMenu.removeAll();
3222 Vector comps = (Vector) PaintRefresher.components.get(viewport.
3223 getSequenceSetId());
3224 Vector treePanels = new Vector();
3225 int i, iSize = comps.size();
3226 for(i=0; i<iSize; i++)
3228 if(comps.elementAt(i) instanceof TreePanel)
3230 treePanels.add(comps.elementAt(i));
3234 iSize = treePanels.size();
3238 sortByTreeMenu.setVisible(false);
3242 sortByTreeMenu.setVisible(true);
3244 for(i=0; i<treePanels.size(); i++)
3246 TreePanel tp = (TreePanel)treePanels.elementAt(i);
3247 final JMenuItem item = new JMenuItem(tp.getTitle());
3248 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
3249 item.addActionListener(new java.awt.event.ActionListener()
3251 public void actionPerformed(ActionEvent e)
3253 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3254 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3256 addHistoryItem(new OrderCommand("Tree Sort",
3258 viewport.alignment));
3260 alignPanel.paintAlignment(true);
3264 sortByTreeMenu.add(item);
3269 * Work out whether the whole set of sequences
3270 * or just the selected set will be submitted for multiple alignment.
3273 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3275 // Now, check we have enough sequences
3276 AlignmentView msa = null;
3278 if ( (viewport.getSelectionGroup() != null) &&
3279 (viewport.getSelectionGroup().getSize() > 1))
3281 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
3282 /*SequenceGroup seqs = viewport.getSelectionGroup();
3284 msa = new SequenceI[sz = seqs.getSize(false)];
3286 for (int i = 0; i < sz; i++)
3288 msa[i] = (SequenceI) seqs.getSequenceAt(i);
3290 msa = viewport.getAlignmentView(true);
3294 /*Vector seqs = viewport.getAlignment().getSequences();
3296 if (seqs.size() > 1)
3298 msa = new SequenceI[seqs.size()];
3300 for (int i = 0; i < seqs.size(); i++)
3302 msa[i] = (SequenceI) seqs.elementAt(i);
3305 msa = viewport.getAlignmentView(false);
3311 * Decides what is submitted to a secondary structure prediction service:
3312 * the first sequence in the alignment, or in the current selection,
3313 * or, if the alignment is 'aligned' (ie padded with gaps), then the
3314 * currently selected region or the whole alignment.
3315 * (where the first sequence in the set is the one that the prediction
3318 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3320 AlignmentView seqs = null;
3322 if ( (viewport.getSelectionGroup() != null) &&
3323 (viewport.getSelectionGroup().getSize() > 0))
3325 seqs = viewport.getAlignmentView(true);
3329 seqs = viewport.getAlignmentView(false);
3331 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
3332 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3333 if (!viewport.alignment.isAligned())
3335 seqs.setSequences(new SeqCigar[]
3336 {seqs.getSequences()[0]});
3343 * @param e DOCUMENT ME!
3345 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3347 // Pick the tree file
3348 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3351 chooser.setFileView(new JalviewFileView());
3352 chooser.setDialogTitle("Select a newick-like tree file");
3353 chooser.setToolTipText("Load a tree file");
3355 int value = chooser.showOpenDialog(null);
3357 if (value == JalviewFileChooser.APPROVE_OPTION)
3359 String choice = chooser.getSelectedFile().getPath();
3360 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3361 jalview.io.NewickFile fin = null;
3364 fin = new jalview.io.NewickFile(choice,
3366 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3368 catch (Exception ex)
3370 JOptionPane.showMessageDialog(Desktop.desktop,
3372 "Problem reading tree file",
3373 JOptionPane.WARNING_MESSAGE);
3374 ex.printStackTrace();
3376 if (fin!=null && fin.hasWarningMessage())
3378 JOptionPane.showMessageDialog(Desktop.desktop,
3379 fin.getWarningMessage(),
3380 "Possible problem with tree file",
3381 JOptionPane.WARNING_MESSAGE);
3387 public TreePanel ShowNewickTree(NewickFile nf, String title)
3389 return ShowNewickTree(nf,title,600,500,4,5);
3392 public TreePanel ShowNewickTree(NewickFile nf, String title,
3393 AlignmentView input)
3395 return ShowNewickTree(nf,title, input, 600,500,4,5);
3398 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
3401 return ShowNewickTree(nf, title, null, w, h, x, y);
3404 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
3406 * @param nf the tree
3407 * @param title tree viewer title
3408 * @param input Associated alignment input data (or null)
3413 * @return TreePanel handle
3415 public TreePanel ShowNewickTree(NewickFile nf, String title,
3416 AlignmentView input, int w, int h, int x,
3419 TreePanel tp = null;
3425 if (nf.getTree() != null)
3427 tp = new TreePanel(alignPanel,
3436 tp.setLocation(x,y);
3440 Desktop.addInternalFrame(tp, title, w, h);
3443 catch (Exception ex)
3445 ex.printStackTrace();
3453 * Generates menu items and listener event actions for web service clients
3456 public void BuildWebServiceMenu()
3458 // TODO: add support for context dependent disabling of services based on alignment and current selection
3459 // TODO: add additional serviceHandle parameter to specify abstract handler class independently of AbstractName
3460 // TODO: add in rediscovery GUI function to restart discoverer
3461 // TODO: group services by location as well as function and/or introduce object broker mechanism.
3462 if ( (Discoverer.services != null)
3463 && (Discoverer.services.size() > 0))
3465 // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere
3466 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3467 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3468 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3469 // TODO: move GUI generation code onto service implementation - so a client instance attaches itself to the GUI with method call like jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, alignframe)
3470 Vector wsmenu = new Vector();
3471 final AlignFrame af = this;
3474 // Add any Multiple Sequence Alignment Services
3475 final JMenu msawsmenu = new JMenu("Alignment");
3476 for (int i = 0, j = msaws.size(); i < j; i++)
3478 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3480 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3481 impl.attachWSMenuEntry(msawsmenu, this);
3484 wsmenu.add(msawsmenu);
3486 if (secstrpr != null)
3488 // Add any secondary structure prediction services
3489 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3490 for (int i = 0, j = secstrpr.size(); i < j; i++)
3492 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3494 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3495 impl.attachWSMenuEntry(secstrmenu, this);
3497 wsmenu.add(secstrmenu);
3501 // Add any sequence search services
3502 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3503 for (int i = 0, j = seqsrch.size(); i < j; i++)
3505 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3506 seqsrch.elementAt(i);
3507 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3508 impl.attachWSMenuEntry(seqsrchmenu, this);
3510 // finally, add the whole shebang onto the webservices menu
3511 wsmenu.add(seqsrchmenu);
3513 resetWebServiceMenu();
3514 for (int i = 0, j = wsmenu.size(); i < j; i++)
3516 webService.add( (JMenu) wsmenu.get(i));
3521 resetWebServiceMenu();
3522 this.webService.add(this.webServiceNoServices);
3528 * empty the web service menu and add any ad-hoc functions
3529 * not dynamically discovered.
3532 private void resetWebServiceMenu()
3534 webService.removeAll();
3535 // Temporary hack - DBRef Fetcher always top level ws entry.
3536 JMenuItem rfetch = new JMenuItem("Fetch DB References");
3537 rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
3538 webService.add(rfetch);
3539 rfetch.addActionListener(new ActionListener() {
3541 public void actionPerformed(ActionEvent e)
3543 new jalview.ws.DBRefFetcher(
3544 alignPanel.av.getSequenceSelection(),
3545 alignPanel.alignFrame).fetchDBRefs(false);
3551 /* public void vamsasStore_actionPerformed(ActionEvent e)
3553 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3554 getProperty("LAST_DIRECTORY"));
3556 chooser.setFileView(new JalviewFileView());
3557 chooser.setDialogTitle("Export to Vamsas file");
3558 chooser.setToolTipText("Export");
3560 int value = chooser.showSaveDialog(this);
3562 if (value == JalviewFileChooser.APPROVE_OPTION)
3564 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3565 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3566 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3570 * prototype of an automatically enabled/disabled analysis function
3573 protected void setShowProductsEnabled()
3575 SequenceI [] selection = viewport.getSequenceSelection();
3576 if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset()))
3578 showProducts.setEnabled(true);
3581 showProducts.setEnabled(false);
3585 * search selection for sequence xRef products and build the
3586 * show products menu.
3589 * @return true if showProducts menu should be enabled.
3591 public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset)
3593 boolean showp=false;
3595 showProducts.removeAll();
3596 final boolean dna = viewport.getAlignment().isNucleotide();
3597 final Alignment ds = dataset;
3598 String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset);
3599 //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true);
3600 final SequenceI[] sel = selection;
3601 for (int t=0; ptypes!=null && t<ptypes.length; t++)
3604 final boolean isRegSel = isRegionSelection;
3605 final AlignFrame af = this;
3606 final String source = ptypes[t];
3607 JMenuItem xtype = new JMenuItem(ptypes[t]);
3608 xtype.addActionListener(new ActionListener() {
3610 public void actionPerformed(ActionEvent e)
3612 // TODO: new thread for this call with vis-delay
3613 af.showProductsFor(sel, ds, isRegSel, dna, source);
3617 showProducts.add(xtype);
3619 showProducts.setVisible(showp);
3620 showProducts.setEnabled(showp);
3621 } catch (Exception e)
3623 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3628 protected void showProductsFor(SequenceI[] sel, Alignment ds, boolean isRegSel, boolean dna, String source)
3630 final boolean fisRegSel = isRegSel;
3631 final boolean fdna = dna;
3632 final String fsrc = source;
3633 final AlignFrame ths = this;
3634 final SequenceI[] fsel = sel;
3635 Runnable foo = new Runnable() {
3639 final long sttime = System.currentTimeMillis();
3640 ths.setProgressBar("Searching for sequences from "+fsrc, sttime);
3642 Alignment ds = ths.getViewport().alignment.getDataset(); // update our local dataset reference
3643 Alignment prods = CrossRef.findXrefSequences(fsel, fdna, fsrc, ds);
3646 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3647 for (int s=0; s<sprods.length;s++)
3649 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3650 if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
3651 ds.addSequence(sprods[s].getDatasetSequence());
3652 sprods[s].updatePDBIds();
3654 Alignment al = new Alignment(sprods);
3655 AlignedCodonFrame[] cf = prods.getCodonFrames();
3656 for (int s=0; cf!=null && s<cf.length; s++)
3658 al.addCodonFrame(cf[s]);
3662 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3663 String newtitle =""+((fdna) ? "Proteins " : "Nucleotides ") + " for "+((fisRegSel) ? "selected region of " : "")
3665 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3668 System.err.println("No Sequences generated for xRef type "+fsrc);
3673 jalview.bin.Cache.log.error("Exception when finding crossreferences",e);
3677 jalview.bin.Cache.log.error("Error when finding crossreferences",e);
3679 ths.setProgressBar("Finished searching for sequences from "+fsrc, sttime);
3683 Thread frunner = new Thread(foo);
3688 public boolean canShowTranslationProducts(SequenceI[] selection, AlignmentI alignment)
3692 return (jalview.analysis.Dna.canTranslate(selection, viewport.getViewAsVisibleContigs(true)));
3693 } catch (Exception e)
3695 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3700 public void showProducts_actionPerformed(ActionEvent e)
3702 ///////////////////////////////
3703 // Collect Data to be translated/transferred
3705 SequenceI [] selection = viewport.getSequenceSelection();
3706 AlignmentI al = null;
3708 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport.getViewAsVisibleContigs(true),
3709 viewport.getGapCharacter(), viewport.getAlignment().getDataset());
3710 } catch (Exception ex) {
3712 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3716 JOptionPane.showMessageDialog(Desktop.desktop,
3717 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3718 "Translation Failed",
3719 JOptionPane.WARNING_MESSAGE);
3721 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3722 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3728 public void showTranslation_actionPerformed(ActionEvent e)
3730 ///////////////////////////////
3731 // Collect Data to be translated/transferred
3733 SequenceI [] selection = viewport.getSequenceSelection();
3734 String [] seqstring = viewport.getViewAsString(true);
3735 AlignmentI al = null;
3737 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
3738 viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
3739 viewport.alignment.getWidth(), viewport.getAlignment().getDataset());
3740 } catch (Exception ex) {
3742 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3746 JOptionPane.showMessageDialog(Desktop.desktop,
3747 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3748 "Translation Failed",
3749 JOptionPane.WARNING_MESSAGE);
3751 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3752 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3759 * Try to load a features file onto the alignment.
3760 * @param file contents or path to retrieve file
3761 * @param type access mode of file (see jalview.io.AlignFile)
3762 * @return true if features file was parsed corectly.
3764 public boolean parseFeaturesFile(String file, String type)
3766 boolean featuresFile = false;
3769 featuresFile = new FeaturesFile(file,
3770 type).parse(viewport.alignment.getDataset(),
3771 alignPanel.seqPanel.seqCanvas.
3772 getFeatureRenderer().featureColours,
3777 ex.printStackTrace();
3782 viewport.showSequenceFeatures = true;
3783 showSeqFeatures.setSelected(true);
3784 alignPanel.paintAlignment(true);
3787 return featuresFile;
3790 public void dragEnter(DropTargetDragEvent evt)
3793 public void dragExit(DropTargetEvent evt)
3796 public void dragOver(DropTargetDragEvent evt)
3799 public void dropActionChanged(DropTargetDragEvent evt)
3802 public void drop(DropTargetDropEvent evt)
3804 Transferable t = evt.getTransferable();
3805 java.util.List files = null;
3809 DataFlavor uriListFlavor = new DataFlavor(
3810 "text/uri-list;class=java.lang.String");
3811 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3813 //Works on Windows and MacOSX
3814 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3815 files = (java.util.List) t.getTransferData(DataFlavor.
3816 javaFileListFlavor);
3818 else if (t.isDataFlavorSupported(uriListFlavor))
3820 // This is used by Unix drag system
3821 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3822 String data = (String) t.getTransferData(uriListFlavor);
3823 files = new java.util.ArrayList(1);
3824 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3827 st.hasMoreTokens(); )
3829 String s = st.nextToken();
3830 if (s.startsWith("#"))
3832 // the line is a comment (as per the RFC 2483)
3836 java.net.URI uri = new java.net.URI(s);
3837 java.io.File file = new java.io.File(uri);
3844 e.printStackTrace();
3851 for (int i = 0; i < files.size(); i++)
3853 loadJalviewDataFile(files.get(i).toString());
3856 catch (Exception ex)
3858 ex.printStackTrace();
3864 * Attempt to load a "dropped" file: First by testing
3865 * whether it's and Annotation file, then a JNet file, and finally a features file. If all are
3866 * false then the user may have dropped an alignment file onto this
3868 * @param file either a filename or a URL string.
3870 public void loadJalviewDataFile(String file)
3874 String protocol = "File";
3876 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3881 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3882 alignment, file, protocol);
3886 // try to see if its a JNet 'concise' style annotation file *before* we try to parse it as a features file
3887 String format = new IdentifyFile().Identify(file, protocol);
3888 if(format.equalsIgnoreCase("JnetFile"))
3890 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3892 new JnetAnnotationMaker().add_annotation(predictions,
3893 viewport.getAlignment(),
3899 // try to parse it as a features file
3900 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3901 // if it wasn't a features file then we just treat it as a general alignment file to load into the current view.
3904 new FileLoader().LoadFile(viewport, file, protocol, format);
3906 alignPanel.paintAlignment(true);
3913 alignPanel.adjustAnnotationHeight();
3914 buildSortByAnnotationScoresMenu();
3915 alignPanel.paintAlignment(true);
3918 catch (Exception ex)
3920 ex.printStackTrace();
3924 public void tabSelectionChanged(int index)
3928 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3929 viewport = alignPanel.av;
3930 setMenusFromViewport(viewport);
3934 public void tabbedPane_mousePressed(MouseEvent e)
3936 if(SwingUtilities.isRightMouseButton(e))
3938 String reply = JOptionPane.showInternalInputDialog(this,
3941 JOptionPane.QUESTION_MESSAGE);
3945 viewport.viewName = reply;
3946 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3952 public AlignViewport getCurrentView()
3959 * Open the dialog for regex description parsing.
3961 protected void extractScores_actionPerformed(ActionEvent e)
3963 ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
3964 if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0)
3966 buildSortByAnnotationScoresMenu();
3975 public PrintThread(AlignmentPanel ap)
3979 static PageFormat pf;
3982 PrinterJob printJob = PrinterJob.getPrinterJob();
3986 printJob.setPrintable(ap, pf);
3990 printJob.setPrintable(ap);
3993 if (printJob.printDialog())
3999 catch (Exception PrintException)
4001 PrintException.printStackTrace();