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, IProgressIndicator
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;
559 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
561 public void setProgressBar(String message, long id)
563 if(progressBars == null)
565 progressBars = new Hashtable();
568 JPanel progressPanel;
569 GridLayout layout = (GridLayout) statusPanel.getLayout();
570 if(progressBars.get( new Long(id) )!=null)
572 progressPanel = (JPanel)progressBars.get( new Long(id) );
573 statusPanel.remove(progressPanel);
574 progressBars.remove( progressPanel );
575 progressPanel = null;
578 statusBar.setText(message);
581 layout.setRows(layout.getRows() - 1);
585 progressPanel = new JPanel(new BorderLayout(10, 5));
587 JProgressBar progressBar = new JProgressBar();
588 progressBar.setIndeterminate(true);
590 progressPanel.add(new JLabel(message), BorderLayout.WEST);
591 progressPanel.add(progressBar, BorderLayout.CENTER);
593 layout.setRows(layout.getRows() + 1);
594 statusPanel.add(progressPanel);
596 progressBars.put(new Long(id), progressPanel);
603 * @return true if any progress bars are still active
605 public boolean operationInProgress()
607 if (progressBars!=null && progressBars.size()>0)
614 Added so Castor Mapping file can obtain Jalview Version
616 public String getVersion()
618 return jalview.bin.Cache.getProperty("VERSION");
621 public FeatureRenderer getFeatureRenderer()
623 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
627 public void fetchSequence_actionPerformed(ActionEvent e)
629 new SequenceFetcher(this);
632 public void addFromFile_actionPerformed(ActionEvent e)
634 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
637 public void reload_actionPerformed(ActionEvent e)
641 if(currentFileFormat.equals("Jalview"))
643 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
644 for(int i=0; i<frames.length; i++)
646 if (frames[i] instanceof AlignFrame
648 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
652 frames[i].setSelected(true);
653 Desktop.instance.closeAssociatedWindows();
655 catch (java.beans.PropertyVetoException ex)
660 Desktop.instance.closeAssociatedWindows();
662 FileLoader loader = new FileLoader();
663 String protocol = fileName.startsWith("http:")? "URL":"File";
664 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
668 Rectangle bounds = this.getBounds();
670 FileLoader loader = new FileLoader();
671 String protocol = fileName.startsWith("http:") ? "URL" : "File";
672 AlignFrame newframe =
673 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
675 newframe.setBounds(bounds);
677 this.closeMenuItem_actionPerformed(true);
683 public void addFromText_actionPerformed(ActionEvent e)
685 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
688 public void addFromURL_actionPerformed(ActionEvent e)
690 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
694 public void save_actionPerformed(ActionEvent e)
697 || (currentFileFormat==null || jalview.io.AppletFormatAdapter.isValidFormat(currentFileFormat, true))
698 || fileName.startsWith("http")
701 saveAs_actionPerformed(null);
705 saveAlignment(fileName, currentFileFormat);
712 * @param e DOCUMENT ME!
714 public void saveAs_actionPerformed(ActionEvent e)
716 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
717 getProperty( "LAST_DIRECTORY"),
718 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
719 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
724 chooser.setFileView(new JalviewFileView());
725 chooser.setDialogTitle("Save Alignment to file");
726 chooser.setToolTipText("Save");
728 int value = chooser.showSaveDialog(this);
730 if (value == JalviewFileChooser.APPROVE_OPTION)
732 currentFileFormat = chooser.getSelectedFormat();
733 if (currentFileFormat == null)
735 JOptionPane.showInternalMessageDialog(Desktop.desktop,
736 "You must select a file format before saving!",
737 "File format not specified",
738 JOptionPane.WARNING_MESSAGE);
739 value = chooser.showSaveDialog(this);
743 fileName = chooser.getSelectedFile().getPath();
745 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
748 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
749 if (currentFileFormat.indexOf(" ")>-1)
751 currentFileFormat = currentFileFormat.substring(0, currentFileFormat.indexOf(" "));
753 saveAlignment(fileName, currentFileFormat);
757 public boolean saveAlignment(String file, String format)
759 boolean success = true;
761 if (format.equalsIgnoreCase("Jalview"))
763 String shortName = title;
765 if (shortName.indexOf(java.io.File.separatorChar) > -1)
767 shortName = shortName.substring(shortName.lastIndexOf(
768 java.io.File.separatorChar) + 1);
771 success = new Jalview2XML().SaveAlignment(this, file, shortName);
773 statusBar.setText("Successfully saved to file: "
775 +format +" format.");
780 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
782 // JBPNote need to have a raise_gui flag here
783 JOptionPane.showInternalMessageDialog(
784 this, "Cannot save file " + fileName + " using format "+format,
785 "Alignment output format not supported",
786 JOptionPane.WARNING_MESSAGE);
787 saveAs_actionPerformed(null);
791 String[] omitHidden = null;
793 if (viewport.hasHiddenColumns)
795 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
796 "The Alignment contains hidden columns."
797 + "\nDo you want to save only the visible alignment?",
798 "Save / Omit Hidden Columns",
799 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
801 if (reply == JOptionPane.YES_OPTION)
803 omitHidden = viewport.getViewAsString(false);
806 FormatAdapter f = new FormatAdapter();
807 String output = f.formatSequences(
809 (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future
810 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
820 java.io.PrintWriter out = new java.io.PrintWriter(
821 new java.io.FileWriter(file));
826 statusBar.setText("Successfully saved to file: "
828 + format + " format.");
833 ex.printStackTrace();
840 JOptionPane.showInternalMessageDialog(
841 this, "Couldn't save file: " + fileName,
843 JOptionPane.WARNING_MESSAGE);
852 * @param e DOCUMENT ME!
854 protected void outputText_actionPerformed(ActionEvent e)
856 String [] omitHidden = null;
858 if(viewport.hasHiddenColumns)
860 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
861 "The Alignment contains hidden columns."
862 +"\nDo you want to output only the visible alignment?",
863 "Save / Omit Hidden Columns",
864 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
866 if(reply==JOptionPane.YES_OPTION)
868 omitHidden = viewport.getViewAsString(false);
872 CutAndPasteTransfer cap = new CutAndPasteTransfer();
873 cap.setForInput(null);
874 Desktop.addInternalFrame(cap,
875 "Alignment output - " + e.getActionCommand(), 600,
879 cap.setText(new FormatAdapter().formatSequences(
880 e.getActionCommand(),
882 omitHidden, viewport.colSel));
888 * @param e DOCUMENT ME!
890 protected void htmlMenuItem_actionPerformed(ActionEvent e)
892 new HTMLOutput(alignPanel,
893 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
894 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
897 public void createImageMap(File file, String image)
899 alignPanel.makePNGImageMap(file, image);
905 * @param e DOCUMENT ME!
907 public void createPNG(File f)
909 alignPanel.makePNG(f);
915 * @param e DOCUMENT ME!
917 public void createEPS(File f)
919 alignPanel.makeEPS(f);
923 public void pageSetup_actionPerformed(ActionEvent e)
925 PrinterJob printJob = PrinterJob.getPrinterJob();
926 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
932 * @param e DOCUMENT ME!
934 public void printMenuItem_actionPerformed(ActionEvent e)
936 //Putting in a thread avoids Swing painting problems
937 PrintThread thread = new PrintThread(alignPanel);
941 public void exportFeatures_actionPerformed(ActionEvent e)
943 new AnnotationExporter().exportFeatures(alignPanel);
947 public void exportAnnotations_actionPerformed(ActionEvent e)
949 new AnnotationExporter().exportAnnotations(
951 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
952 viewport.alignment.getGroups(),
953 ((Alignment)viewport.alignment).alignmentProperties
958 public void associatedData_actionPerformed(ActionEvent e)
960 // Pick the tree file
961 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
964 chooser.setFileView(new JalviewFileView());
965 chooser.setDialogTitle("Load Jalview Annotations or Features File");
966 chooser.setToolTipText("Load Jalview Annotations / Features file");
968 int value = chooser.showOpenDialog(null);
970 if (value == JalviewFileChooser.APPROVE_OPTION)
972 String choice = chooser.getSelectedFile().getPath();
973 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
974 loadJalviewDataFile(choice);
983 * @param e DOCUMENT ME!
985 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
987 if(alignPanels!=null && alignPanels.size()<2)
994 if(alignPanels!=null)
998 for (int i = 0; i < alignPanels.size(); i++)
1000 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1001 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
1002 .removeStructureViewerListener(ap.seqPanel, null);
1003 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
1004 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
1005 PaintRefresher.RemoveComponent(ap);
1006 ap.av.alignment = null;
1011 int index = tabbedPane.getSelectedIndex();
1013 alignPanels.removeElement(alignPanel);
1014 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1015 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1016 PaintRefresher.RemoveComponent(alignPanel);
1017 viewport.alignment = null;
1021 tabbedPane.removeTabAt(index);
1022 tabbedPane.validate();
1024 if(index==tabbedPane.getTabCount())
1029 this.tabSelectionChanged(index);
1035 this.setClosed(true);
1038 catch (Exception ex)
1040 ex.printStackTrace();
1048 void updateEditMenuBar()
1051 if (viewport.historyList.size() > 0)
1053 undoMenuItem.setEnabled(true);
1054 CommandI command = (CommandI) viewport.historyList.peek();
1055 undoMenuItem.setText("Undo " + command.getDescription());
1059 undoMenuItem.setEnabled(false);
1060 undoMenuItem.setText("Undo");
1063 if (viewport.redoList.size() > 0)
1065 redoMenuItem.setEnabled(true);
1067 CommandI command = (CommandI) viewport.redoList.peek();
1068 redoMenuItem.setText("Redo " + command.getDescription());
1072 redoMenuItem.setEnabled(false);
1073 redoMenuItem.setText("Redo");
1078 public void addHistoryItem(CommandI command)
1080 if(command.getSize()>0)
1082 viewport.historyList.push(command);
1083 viewport.redoList.clear();
1084 updateEditMenuBar();
1085 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1091 * @return alignment objects for all views
1093 AlignmentI[] getViewAlignments()
1095 if (alignPanels!=null)
1097 Enumeration e = alignPanels.elements();
1098 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1099 for (int i=0; e.hasMoreElements(); i++)
1101 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1107 return new AlignmentI[] { viewport.alignment };
1114 * @param e DOCUMENT ME!
1116 protected void undoMenuItem_actionPerformed(ActionEvent e)
1118 if (viewport.historyList.empty())
1120 CommandI command = (CommandI)viewport.historyList.pop();
1121 viewport.redoList.push(command);
1122 command.undoCommand(getViewAlignments());
1124 AlignViewport originalSource = getOriginatingSource(command);
1125 updateEditMenuBar();
1127 if(originalSource!=null)
1129 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1130 originalSource.firePropertyChange("alignment",
1132 originalSource.alignment.getSequences());
1139 * @param e DOCUMENT ME!
1141 protected void redoMenuItem_actionPerformed(ActionEvent e)
1143 if(viewport.redoList.size()<1)
1148 CommandI command = (CommandI) viewport.redoList.pop();
1149 viewport.historyList.push(command);
1150 command.doCommand(getViewAlignments());
1152 AlignViewport originalSource = getOriginatingSource(command);
1153 updateEditMenuBar();
1155 if(originalSource!=null)
1157 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1158 originalSource.firePropertyChange("alignment",
1160 originalSource.alignment.getSequences());
1164 AlignViewport getOriginatingSource(CommandI command)
1166 AlignViewport originalSource = null;
1167 //For sequence removal and addition, we need to fire
1168 //the property change event FROM the viewport where the
1169 //original alignment was altered
1171 if (command instanceof EditCommand)
1173 EditCommand editCommand = (EditCommand) command;
1174 al = editCommand.getAlignment();
1175 Vector comps = (Vector) PaintRefresher.components
1176 .get(viewport.getSequenceSetId());
1178 for (int i = 0; i < comps.size(); i++)
1180 if (comps.elementAt(i) instanceof AlignmentPanel)
1182 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1184 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1191 if (originalSource == null)
1193 //The original view is closed, we must validate
1194 //the current view against the closed view first
1197 PaintRefresher.validateSequences(al, viewport.alignment);
1200 originalSource = viewport;
1203 return originalSource;
1209 * @param up DOCUMENT ME!
1211 public void moveSelectedSequences(boolean up)
1213 SequenceGroup sg = viewport.getSelectionGroup();
1222 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1224 SequenceI seq = viewport.alignment.getSequenceAt(i);
1226 if (!sg.getSequences(null).contains(seq))
1231 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1233 if (sg.getSequences(null).contains(temp))
1238 viewport.alignment.getSequences().setElementAt(temp, i);
1239 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1244 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1246 SequenceI seq = viewport.alignment.getSequenceAt(i);
1248 if (!sg.getSequences(null).contains(seq))
1253 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1255 if (sg.getSequences(null).contains(temp))
1260 viewport.alignment.getSequences().setElementAt(temp, i);
1261 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1265 alignPanel.paintAlignment(true);
1271 synchronized void slideSequences(boolean right, int size)
1273 Vector sg = new Vector();
1274 if(viewport.cursorMode)
1276 sg.addElement(viewport.alignment.getSequenceAt(
1277 alignPanel.seqPanel.seqCanvas.cursorY));
1279 else if(viewport.getSelectionGroup()!=null
1280 && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
1282 sg = viewport.getSelectionGroup().getSequences(
1283 viewport.hiddenRepSequences);
1291 Vector invertGroup = new Vector();
1293 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1295 if(!sg.contains(viewport.alignment.getSequenceAt(i)))
1296 invertGroup.add(viewport.alignment.getSequenceAt(i));
1299 SequenceI[] seqs1 = new SequenceI[sg.size()];
1300 for (int i = 0; i < sg.size(); i++)
1301 seqs1[i] = (SequenceI) sg.elementAt(i);
1303 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1304 for (int i = 0; i < invertGroup.size(); i++)
1305 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1307 SlideSequencesCommand ssc;
1309 ssc = new SlideSequencesCommand("Slide Sequences",
1311 viewport.getGapCharacter()
1314 ssc = new SlideSequencesCommand("Slide Sequences",
1316 viewport.getGapCharacter()
1319 int groupAdjustment = 0;
1320 if (ssc.getGapsInsertedBegin() && right)
1322 if (viewport.cursorMode)
1323 alignPanel.seqPanel.moveCursor(size, 0);
1325 groupAdjustment = size;
1327 else if (!ssc.getGapsInsertedBegin() && !right)
1329 if (viewport.cursorMode)
1330 alignPanel.seqPanel.moveCursor( -size, 0);
1332 groupAdjustment = -size;
1335 if (groupAdjustment != 0)
1337 viewport.getSelectionGroup().setStartRes(
1338 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1339 viewport.getSelectionGroup().setEndRes(
1340 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1344 boolean appendHistoryItem = false;
1345 if(viewport.historyList!=null
1346 && viewport.historyList.size()>0
1347 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1349 appendHistoryItem = ssc.appendSlideCommand(
1350 (SlideSequencesCommand)viewport.historyList.peek())
1354 if(!appendHistoryItem)
1355 addHistoryItem(ssc);
1364 * @param e DOCUMENT ME!
1366 protected void copy_actionPerformed(ActionEvent e)
1369 if (viewport.getSelectionGroup() == null)
1373 // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
1374 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1375 String[] omitHidden = null;
1377 if (viewport.hasHiddenColumns)
1379 omitHidden = viewport.getViewAsString(true);
1382 String output = new FormatAdapter().formatSequences(
1387 StringSelection ss = new StringSelection(output);
1391 jalview.gui.Desktop.internalCopy = true;
1392 //Its really worth setting the clipboard contents
1393 //to empty before setting the large StringSelection!!
1394 Toolkit.getDefaultToolkit().getSystemClipboard()
1395 .setContents(new StringSelection(""), null);
1397 Toolkit.getDefaultToolkit().getSystemClipboard()
1398 .setContents(ss, Desktop.instance);
1400 catch (OutOfMemoryError er)
1402 er.printStackTrace();
1403 javax.swing.SwingUtilities.invokeLater(new Runnable()
1407 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1408 "Out of memory copying region!!"
1410 "\nSee help files for increasing Java Virtual Machine memory."
1412 javax.swing.JOptionPane.WARNING_MESSAGE);
1419 Vector hiddenColumns = null;
1420 if(viewport.hasHiddenColumns)
1422 hiddenColumns =new Vector();
1423 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1424 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1427 int[] region = (int[])
1428 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1430 hiddenColumns.addElement(new int[]
1431 {region[0] - hiddenOffset,
1432 region[1]-hiddenOffset});
1436 Desktop.jalviewClipboard = new Object[]
1439 viewport.alignment.getDataset(),
1441 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1447 * @param e DOCUMENT ME!
1449 protected void pasteNew_actionPerformed(ActionEvent e)
1457 * @param e DOCUMENT ME!
1459 protected void pasteThis_actionPerformed(ActionEvent e)
1465 * Paste contents of Jalview clipboard
1467 * @param newAlignment true to paste to a new alignment, otherwise add to this.
1469 void paste(boolean newAlignment)
1471 boolean externalPaste=true;
1474 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1475 Transferable contents = c.getContents(this);
1477 if (contents == null)
1485 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1486 if (str.length() < 1)
1491 format = new IdentifyFile().Identify(str, "Paste");
1494 catch (OutOfMemoryError er)
1496 er.printStackTrace();
1497 javax.swing.SwingUtilities.invokeLater(new Runnable()
1501 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1502 "Out of memory pasting sequences!!"
1504 "\nSee help files for increasing Java Virtual Machine memory."
1506 javax.swing.JOptionPane.WARNING_MESSAGE);
1513 SequenceI[] sequences;
1514 boolean annotationAdded = false;
1515 AlignmentI alignment = null;
1517 if(Desktop.jalviewClipboard!=null)
1519 // The clipboard was filled from within Jalview, we must use the sequences
1520 // And dataset from the copied alignment
1521 SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
1522 // be doubly sure that we create *new* sequence objects.
1523 sequences = new SequenceI[newseq.length];
1524 for (int i=0;i<newseq.length;i++) {
1525 sequences[i] = new Sequence(newseq[i]);
1527 alignment = new Alignment(sequences);
1528 externalPaste = false;
1532 // parse the clipboard as an alignment.
1533 alignment = new FormatAdapter().readFile(str, "Paste", format);
1534 sequences = alignment.getSequencesArray();
1542 if (Desktop.jalviewClipboard != null)
1544 // dataset is inherited
1545 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1549 // new dataset is constructed
1550 alignment.setDataset(null);
1552 alwidth = alignment.getWidth()+1;
1556 AlignmentI pastedal = alignment; // preserve pasted alignment object
1557 // Add pasted sequences and dataset into existing alignment.
1558 alignment = viewport.getAlignment();
1559 alwidth = alignment.getWidth()+1;
1560 // decide if we need to import sequences from an existing dataset
1561 boolean importDs = Desktop.jalviewClipboard != null
1562 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1563 // importDs==true instructs us to copy over new dataset sequences from
1564 // an existing alignment
1565 Vector newDs = (importDs) ? new Vector() : null; // used to create
1566 // minimum dataset set
1568 for (int i = 0; i < sequences.length; i++)
1572 newDs.addElement(null);
1574 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1576 if (importDs && ds != null)
1578 if (!newDs.contains(ds))
1580 newDs.setElementAt(ds, i);
1581 ds = new Sequence(ds);
1582 // update with new dataset sequence
1583 sequences[i].setDatasetSequence(ds);
1587 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1592 // copy and derive new dataset sequence
1593 sequences[i] = sequences[i].deriveSequence();
1594 alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
1595 // TODO: avoid creation of duplicate dataset sequences with a
1596 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1598 alignment.addSequence(sequences[i]); // merges dataset
1602 newDs.clear(); // tidy up
1604 if (pastedal.getAlignmentAnnotation()!=null) {
1605 // Add any annotation attached to alignment.
1606 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1607 for (int i=0; i<alann.length; i++)
1609 annotationAdded=true;
1610 if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
1611 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1612 newann.padAnnotation(alwidth);
1613 alignment.addAnnotation(newann);
1618 if (!newAlignment) {
1622 addHistoryItem(new EditCommand(
1627 alignment.getWidth(),
1631 // Add any annotations attached to sequences
1632 for (int i = 0; i < sequences.length; i++)
1634 if (sequences[i].getAnnotation() != null)
1636 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1638 annotationAdded=true;
1639 sequences[i].getAnnotation()[a].adjustForAlignment();
1640 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1641 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
1642 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1646 if (!newAlignment) {
1648 // propagate alignment changed.
1649 viewport.setEndSeq(alignment.getHeight());
1650 if (annotationAdded)
1652 // Duplicate sequence annotation in all views.
1653 AlignmentI[] alview = this.getViewAlignments();
1654 for (int i = 0; i < sequences.length; i++)
1656 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1659 for (int avnum=0;avnum<alview.length; avnum++)
1661 if (alview[avnum]!=alignment)
1663 // duplicate in a view other than the one with input focus
1664 int avwidth = alview[avnum].getWidth()+1;
1665 // this relies on sann being preserved after we
1666 // modify the sequence's annotation array for each duplication
1667 for (int a=0; a<sann.length; a++)
1669 AlignmentAnnotation newann = new AlignmentAnnotation(sann[a]);
1670 sequences[i].addAlignmentAnnotation(newann);
1671 newann.padAnnotation(avwidth);
1672 alview[avnum].addAnnotation(newann); // annotation was duplicated earlier
1673 alview[avnum].setAnnotationIndex(newann, a);
1678 buildSortByAnnotationScoresMenu();
1680 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1683 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1684 String newtitle = new String("Copied sequences");
1686 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1688 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1689 for(int i=0; i<hc.size(); i++)
1691 int [] region = (int[]) hc.elementAt(i);
1692 af.viewport.hideColumns(region[0], region[1]);
1697 //>>>This is a fix for the moment, until a better solution is found!!<<<
1698 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1699 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1701 // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
1702 if (!externalPaste) {
1703 if (title.startsWith("Copied sequences"))
1709 newtitle = newtitle.concat("- from " + title);
1712 newtitle = new String("Pasted sequences");
1715 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1722 catch (Exception ex)
1724 ex.printStackTrace();
1725 System.out.println("Exception whilst pasting: "+ex);
1726 // could be anything being pasted in here
1735 * @param e DOCUMENT ME!
1737 protected void cut_actionPerformed(ActionEvent e)
1739 copy_actionPerformed(null);
1740 delete_actionPerformed(null);
1746 * @param e DOCUMENT ME!
1748 protected void delete_actionPerformed(ActionEvent evt)
1751 SequenceGroup sg = viewport.getSelectionGroup();
1757 Vector seqs = new Vector();
1759 for (int i = 0; i < sg.getSize(); i++)
1761 seq = sg.getSequenceAt(i);
1762 seqs.addElement(seq);
1766 // If the cut affects all sequences, remove highlighted columns
1767 if (sg.getSize() == viewport.alignment.getHeight())
1769 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1770 sg.getEndRes() + 1);
1774 SequenceI [] cut = new SequenceI[seqs.size()];
1775 for(int i=0; i<seqs.size(); i++)
1777 cut[i] = (SequenceI)seqs.elementAt(i);
1784 addHistoryItem(new EditCommand("Cut Sequences",
1788 sg.getEndRes()-sg.getStartRes()+1,
1789 viewport.alignment));
1792 viewport.setSelectionGroup(null);
1793 viewport.alignment.deleteGroup(sg);
1795 viewport.firePropertyChange("alignment", null,
1796 viewport.getAlignment().getSequences());
1798 if (viewport.getAlignment().getHeight() < 1)
1802 this.setClosed(true);
1804 catch (Exception ex)
1813 * @param e DOCUMENT ME!
1815 protected void deleteGroups_actionPerformed(ActionEvent e)
1817 viewport.alignment.deleteAllGroups();
1818 viewport.sequenceColours = null;
1819 viewport.setSelectionGroup(null);
1820 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1821 alignPanel.paintAlignment(true);
1827 * @param e DOCUMENT ME!
1829 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1831 SequenceGroup sg = new SequenceGroup();
1833 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1836 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1839 sg.setEndRes(viewport.alignment.getWidth() - 1);
1840 viewport.setSelectionGroup(sg);
1841 alignPanel.paintAlignment(true);
1842 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1848 * @param e DOCUMENT ME!
1850 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1852 if(viewport.cursorMode)
1854 alignPanel.seqPanel.keyboardNo1 = null;
1855 alignPanel.seqPanel.keyboardNo2 = null;
1857 viewport.setSelectionGroup(null);
1858 viewport.getColumnSelection().clear();
1859 viewport.setSelectionGroup(null);
1860 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1861 alignPanel.idPanel.idCanvas.searchResults = null;
1862 alignPanel.paintAlignment(true);
1863 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1869 * @param e DOCUMENT ME!
1871 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1873 SequenceGroup sg = viewport.getSelectionGroup();
1877 selectAllSequenceMenuItem_actionPerformed(null);
1882 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1885 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1888 alignPanel.paintAlignment(true);
1890 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1893 public void invertColSel_actionPerformed(ActionEvent e)
1895 viewport.invertColumnSelection();
1896 alignPanel.paintAlignment(true);
1903 * @param e DOCUMENT ME!
1905 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1907 trimAlignment(true);
1913 * @param e DOCUMENT ME!
1915 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1917 trimAlignment(false);
1920 void trimAlignment(boolean trimLeft)
1922 ColumnSelection colSel = viewport.getColumnSelection();
1925 if (colSel.size() > 0)
1929 column = colSel.getMin();
1933 column = colSel.getMax();
1937 if(viewport.getSelectionGroup()!=null)
1939 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1940 hiddenRepSequences);
1944 seqs = viewport.alignment.getSequencesArray();
1948 TrimRegionCommand trimRegion;
1951 trimRegion = new TrimRegionCommand("Remove Left",
1952 TrimRegionCommand.TRIM_LEFT,
1957 viewport.selectionGroup);
1958 viewport.setStartRes(0);
1962 trimRegion = new TrimRegionCommand("Remove Right",
1963 TrimRegionCommand.TRIM_RIGHT,
1968 viewport.selectionGroup);
1971 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1974 addHistoryItem(trimRegion);
1976 Vector groups = viewport.alignment.getGroups();
1978 for (int i = 0; i < groups.size(); i++)
1980 SequenceGroup sg = (SequenceGroup) groups.get(i);
1982 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1983 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1985 viewport.alignment.deleteGroup(sg);
1989 viewport.firePropertyChange("alignment", null,
1990 viewport.getAlignment().getSequences());
1997 * @param e DOCUMENT ME!
1999 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2001 int start = 0, end = viewport.alignment.getWidth()-1;
2004 if (viewport.getSelectionGroup() != null)
2006 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
2007 hiddenRepSequences);
2008 start = viewport.getSelectionGroup().getStartRes();
2009 end = viewport.getSelectionGroup().getEndRes();
2013 seqs = viewport.alignment.getSequencesArray();
2017 RemoveGapColCommand removeGapCols =
2018 new RemoveGapColCommand("Remove Gapped Columns",
2021 viewport.alignment);
2023 addHistoryItem(removeGapCols);
2025 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
2027 //This is to maintain viewport position on first residue
2029 SequenceI seq = viewport.alignment.getSequenceAt(0);
2030 int startRes = seq.findPosition(viewport.startRes);
2031 // ShiftList shifts;
2032 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2033 // edit.alColumnChanges=shifts.getInverse();
2034 // if (viewport.hasHiddenColumns)
2035 // viewport.getColumnSelection().compensateForEdits(shifts);
2036 viewport.setStartRes(seq.findIndex(startRes)-1);
2037 viewport.firePropertyChange("alignment", null,
2038 viewport.getAlignment().getSequences());
2045 * @param e DOCUMENT ME!
2047 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2049 int start = 0, end = viewport.alignment.getWidth()-1;
2052 if (viewport.getSelectionGroup() != null)
2054 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
2055 hiddenRepSequences);
2056 start = viewport.getSelectionGroup().getStartRes();
2057 end = viewport.getSelectionGroup().getEndRes();
2061 seqs = viewport.alignment.getSequencesArray();
2064 //This is to maintain viewport position on first residue
2066 SequenceI seq = viewport.alignment.getSequenceAt(0);
2067 int startRes = seq.findPosition(viewport.startRes);
2069 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
2072 viewport.alignment));
2074 viewport.setStartRes(seq.findIndex(startRes)-1);
2076 viewport.firePropertyChange("alignment", null,
2077 viewport.getAlignment().getSequences());
2084 * @param e DOCUMENT ME!
2086 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2088 viewport.padGaps = padGapsMenuitem.isSelected();
2090 viewport.firePropertyChange("alignment",
2092 viewport.getAlignment().getSequences());
2098 * @param e DOCUMENT ME!
2100 public void findMenuItem_actionPerformed(ActionEvent e)
2105 public void newView_actionPerformed(ActionEvent e)
2107 AlignmentPanel newap =
2108 new Jalview2XML().copyAlignPanel(alignPanel, true);
2110 newap.av.gatherViewsHere = false;
2112 if (viewport.viewName == null)
2114 viewport.viewName = "Original";
2117 newap.av.historyList = viewport.historyList;
2118 newap.av.redoList = viewport.redoList;
2120 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2121 String newViewName = "View " +index;
2123 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2124 getSequenceSetId());
2125 Vector existingNames = new Vector();
2126 for(int i=0; i<comps.size(); i++)
2128 if(comps.elementAt(i) instanceof AlignmentPanel)
2130 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
2131 if(!existingNames.contains(ap.av.viewName))
2133 existingNames.addElement(ap.av.viewName);
2138 while(existingNames.contains(newViewName))
2140 newViewName = "View "+ (++index);
2143 newap.av.viewName = newViewName;
2145 addAlignmentPanel(newap, false);
2147 if(alignPanels.size()==2)
2149 viewport.gatherViewsHere = true;
2151 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2154 public void expandViews_actionPerformed(ActionEvent e)
2156 Desktop.instance.explodeViews(this);
2159 public void gatherViews_actionPerformed(ActionEvent e)
2161 Desktop.instance.gatherViews(this);
2169 * @param e DOCUMENT ME!
2171 public void font_actionPerformed(ActionEvent e)
2173 new FontChooser(alignPanel);
2180 * @param e DOCUMENT ME!
2182 protected void seqLimit_actionPerformed(ActionEvent e)
2184 viewport.setShowJVSuffix(seqLimits.isSelected());
2186 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
2187 alignPanel.paintAlignment(true);
2190 public void idRightAlign_actionPerformed(ActionEvent e)
2192 viewport.rightAlignIds = idRightAlign.isSelected();
2193 alignPanel.paintAlignment(true);
2196 public void centreColumnLabels_actionPerformed(ActionEvent e)
2198 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2199 alignPanel.paintAlignment(true);
2207 * @param e DOCUMENT ME!
2209 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2211 viewport.setColourText(colourTextMenuItem.isSelected());
2212 alignPanel.paintAlignment(true);
2218 * @param e DOCUMENT ME!
2220 public void wrapMenuItem_actionPerformed(ActionEvent e)
2222 scaleAbove.setVisible(wrapMenuItem.isSelected());
2223 scaleLeft.setVisible(wrapMenuItem.isSelected());
2224 scaleRight.setVisible(wrapMenuItem.isSelected());
2225 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2226 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2229 public void showAllSeqs_actionPerformed(ActionEvent e)
2231 viewport.showAllHiddenSeqs();
2234 public void showAllColumns_actionPerformed(ActionEvent e)
2236 viewport.showAllHiddenColumns();
2240 public void hideSelSequences_actionPerformed(ActionEvent e)
2242 viewport.hideAllSelectedSeqs();
2243 alignPanel.paintAlignment(true);
2246 public void hideSelColumns_actionPerformed(ActionEvent e)
2248 viewport.hideSelectedColumns();
2249 alignPanel.paintAlignment(true);
2252 public void hiddenMarkers_actionPerformed(ActionEvent e)
2254 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2261 * @param e DOCUMENT ME!
2263 protected void scaleAbove_actionPerformed(ActionEvent e)
2265 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2266 alignPanel.paintAlignment(true);
2272 * @param e DOCUMENT ME!
2274 protected void scaleLeft_actionPerformed(ActionEvent e)
2276 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2277 alignPanel.paintAlignment(true);
2283 * @param e DOCUMENT ME!
2285 protected void scaleRight_actionPerformed(ActionEvent e)
2287 viewport.setScaleRightWrapped(scaleRight.isSelected());
2288 alignPanel.paintAlignment(true);
2294 * @param e DOCUMENT ME!
2296 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2298 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2299 alignPanel.paintAlignment(true);
2305 * @param e DOCUMENT ME!
2307 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2309 viewport.setShowText(viewTextMenuItem.isSelected());
2310 alignPanel.paintAlignment(true);
2316 * @param e DOCUMENT ME!
2318 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2320 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2321 alignPanel.paintAlignment(true);
2325 public FeatureSettings featureSettings;
2326 public void featureSettings_actionPerformed(ActionEvent e)
2328 if(featureSettings !=null )
2330 featureSettings.close();
2331 featureSettings = null;
2333 featureSettings = new FeatureSettings(this);
2339 * @param evt DOCUMENT ME!
2341 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2343 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2344 alignPanel.paintAlignment(true);
2345 if (alignPanel.getOverviewPanel() != null)
2347 alignPanel.getOverviewPanel().updateOverviewImage();
2354 * @param e DOCUMENT ME!
2356 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2358 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2359 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2362 public void alignmentProperties()
2364 JEditorPane editPane = new JEditorPane("text/html","");
2365 editPane.setEditable(false);
2366 StringBuffer contents = new StringBuffer("<html>");
2369 int min=Integer.MAX_VALUE, max=0;
2370 for(int i=0; i<viewport.alignment.getHeight(); i++)
2372 int size = viewport.alignment.getSequenceAt(i).getEnd()
2373 -viewport.alignment.getSequenceAt(i).getStart();
2380 avg = avg/(float)viewport.alignment.getHeight();
2382 contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
2383 contents.append("<br>Minimum Sequence Length: "+min);
2384 contents.append("<br>Maximum Sequence Length: "+max);
2385 contents.append("<br>Average Length: "+(int)avg);
2387 if (((Alignment)viewport.alignment).getProperties() != null)
2389 Hashtable props = ((Alignment)viewport.alignment).getProperties();
2390 Enumeration en = props.keys();
2391 contents.append("<br><br><table border=\"1\">");
2392 while(en.hasMoreElements())
2394 String key = en.nextElement().toString();
2395 StringBuffer val = new StringBuffer();
2396 String vals = props.get(key).toString();
2399 npos = vals.indexOf("\n",pos);
2402 val.append(vals.substring(pos));
2404 val.append(vals.substring(pos, npos));
2409 contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
2411 contents.append("</table>");
2413 editPane.setText(contents.toString()+"</html>");
2414 JInternalFrame frame = new JInternalFrame();
2415 frame.getContentPane().add(new JScrollPane(editPane));
2417 Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
2424 * @param e DOCUMENT ME!
2426 public void overviewMenuItem_actionPerformed(ActionEvent e)
2428 if (alignPanel.overviewPanel != null)
2433 JInternalFrame frame = new JInternalFrame();
2434 OverviewPanel overview = new OverviewPanel(alignPanel);
2435 frame.setContentPane(overview);
2436 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2437 frame.getWidth(), frame.getHeight());
2439 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2440 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2442 public void internalFrameClosed(
2443 javax.swing.event.InternalFrameEvent evt)
2445 alignPanel.setOverviewPanel(null);
2450 alignPanel.setOverviewPanel(overview);
2453 public void textColour_actionPerformed(ActionEvent e)
2455 new TextColourChooser().chooseColour(alignPanel, null);
2461 * @param e DOCUMENT ME!
2463 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2471 * @param e DOCUMENT ME!
2473 public void clustalColour_actionPerformed(ActionEvent e)
2475 changeColour(new ClustalxColourScheme(
2476 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2482 * @param e DOCUMENT ME!
2484 public void zappoColour_actionPerformed(ActionEvent e)
2486 changeColour(new ZappoColourScheme());
2492 * @param e DOCUMENT ME!
2494 public void taylorColour_actionPerformed(ActionEvent e)
2496 changeColour(new TaylorColourScheme());
2502 * @param e DOCUMENT ME!
2504 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2506 changeColour(new HydrophobicColourScheme());
2512 * @param e DOCUMENT ME!
2514 public void helixColour_actionPerformed(ActionEvent e)
2516 changeColour(new HelixColourScheme());
2522 * @param e DOCUMENT ME!
2524 public void strandColour_actionPerformed(ActionEvent e)
2526 changeColour(new StrandColourScheme());
2532 * @param e DOCUMENT ME!
2534 public void turnColour_actionPerformed(ActionEvent e)
2536 changeColour(new TurnColourScheme());
2542 * @param e DOCUMENT ME!
2544 public void buriedColour_actionPerformed(ActionEvent e)
2546 changeColour(new BuriedColourScheme());
2552 * @param e DOCUMENT ME!
2554 public void nucleotideColour_actionPerformed(ActionEvent e)
2556 changeColour(new NucleotideColourScheme());
2559 public void annotationColour_actionPerformed(ActionEvent e)
2561 new AnnotationColourChooser(viewport, alignPanel);
2568 * @param e DOCUMENT ME!
2570 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2572 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2578 * @param cs DOCUMENT ME!
2580 public void changeColour(ColourSchemeI cs)
2586 if (viewport.getAbovePIDThreshold())
2588 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2591 cs.setThreshold(threshold,
2592 viewport.getIgnoreGapsConsensus());
2594 viewport.setGlobalColourScheme(cs);
2598 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2601 if (viewport.getConservationSelected())
2604 Alignment al = (Alignment) viewport.alignment;
2605 Conservation c = new Conservation("All",
2606 ResidueProperties.propHash, 3,
2607 al.getSequences(), 0,
2611 c.verdict(false, viewport.ConsPercGaps);
2613 cs.setConservation(c);
2615 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2620 cs.setConservation(null);
2623 cs.setConsensus(viewport.hconsensus);
2626 viewport.setGlobalColourScheme(cs);
2628 if (viewport.getColourAppliesToAllGroups())
2630 Vector groups = viewport.alignment.getGroups();
2632 for (int i = 0; i < groups.size(); i++)
2634 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2642 if (cs instanceof ClustalxColourScheme)
2644 sg.cs = new ClustalxColourScheme(
2645 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2647 else if (cs instanceof UserColourScheme)
2649 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2655 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2657 catch (Exception ex)
2662 if (viewport.getAbovePIDThreshold()
2663 || cs instanceof PIDColourScheme
2664 || cs instanceof Blosum62ColourScheme)
2666 sg.cs.setThreshold(threshold,
2667 viewport.getIgnoreGapsConsensus());
2669 sg.cs.setConsensus(AAFrequency.calculate(
2670 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2675 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2679 if (viewport.getConservationSelected())
2681 Conservation c = new Conservation("Group",
2682 ResidueProperties.propHash, 3,
2683 sg.getSequences(viewport.
2684 hiddenRepSequences),
2688 c.verdict(false, viewport.ConsPercGaps);
2689 sg.cs.setConservation(c);
2693 sg.cs.setConservation(null);
2698 if (alignPanel.getOverviewPanel() != null)
2700 alignPanel.getOverviewPanel().updateOverviewImage();
2706 alignPanel.paintAlignment(true);
2712 * @param e DOCUMENT ME!
2714 protected void modifyPID_actionPerformed(ActionEvent e)
2716 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2718 SliderPanel.setPIDSliderSource(alignPanel,
2719 viewport.getGlobalColourScheme(),
2721 SliderPanel.showPIDSlider();
2728 * @param e DOCUMENT ME!
2730 protected void modifyConservation_actionPerformed(ActionEvent e)
2732 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2734 SliderPanel.setConservationSlider(alignPanel,
2735 viewport.globalColourScheme,
2737 SliderPanel.showConservationSlider();
2744 * @param e DOCUMENT ME!
2746 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2748 viewport.setConservationSelected(conservationMenuItem.isSelected());
2750 viewport.setAbovePIDThreshold(false);
2751 abovePIDThreshold.setSelected(false);
2753 changeColour(viewport.getGlobalColourScheme());
2755 modifyConservation_actionPerformed(null);
2761 * @param e DOCUMENT ME!
2763 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2765 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2767 conservationMenuItem.setSelected(false);
2768 viewport.setConservationSelected(false);
2770 changeColour(viewport.getGlobalColourScheme());
2772 modifyPID_actionPerformed(null);
2778 * @param e DOCUMENT ME!
2780 public void userDefinedColour_actionPerformed(ActionEvent e)
2782 if (e.getActionCommand().equals("User Defined..."))
2784 new UserDefinedColours(alignPanel, null);
2788 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2789 getUserColourSchemes().get(e.getActionCommand());
2795 public void updateUserColourMenu()
2798 Component[] menuItems = colourMenu.getMenuComponents();
2799 int i, iSize = menuItems.length;
2800 for (i = 0; i < iSize; i++)
2802 if (menuItems[i].getName() != null &&
2803 menuItems[i].getName().equals("USER_DEFINED"))
2805 colourMenu.remove(menuItems[i]);
2809 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2811 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2812 getUserColourSchemes().keys();
2814 while (userColours.hasMoreElements())
2816 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2818 nextElement().toString());
2819 radioItem.setName("USER_DEFINED");
2820 radioItem.addMouseListener(new MouseAdapter()
2822 public void mousePressed(MouseEvent evt)
2824 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2826 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2828 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2830 "Remove from default list?",
2831 "Remove user defined colour",
2832 JOptionPane.YES_NO_OPTION);
2833 if(option == JOptionPane.YES_OPTION)
2835 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2836 radioItem.getText());
2837 colourMenu.remove(radioItem);
2841 radioItem.addActionListener(new ActionListener()
2843 public void actionPerformed(ActionEvent evt)
2845 userDefinedColour_actionPerformed(evt);
2852 radioItem.addActionListener(new ActionListener()
2854 public void actionPerformed(ActionEvent evt)
2856 userDefinedColour_actionPerformed(evt);
2860 colourMenu.insert(radioItem, 15);
2861 colours.add(radioItem);
2869 * @param e DOCUMENT ME!
2871 public void PIDColour_actionPerformed(ActionEvent e)
2873 changeColour(new PIDColourScheme());
2879 * @param e DOCUMENT ME!
2881 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2883 changeColour(new Blosum62ColourScheme());
2889 * @param e DOCUMENT ME!
2891 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2893 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2894 AlignmentSorter.sortByPID(viewport.getAlignment(),
2895 viewport.getAlignment().getSequenceAt(0), null);
2896 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2897 viewport.alignment));
2898 alignPanel.paintAlignment(true);
2904 * @param e DOCUMENT ME!
2906 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2908 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2909 AlignmentSorter.sortByID(viewport.getAlignment());
2910 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2911 alignPanel.paintAlignment(true);
2917 * @param e DOCUMENT ME!
2919 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2921 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2922 AlignmentSorter.sortByGroup(viewport.getAlignment());
2923 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2925 alignPanel.paintAlignment(true);
2930 * @param e DOCUMENT ME!
2932 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2934 new RedundancyPanel(alignPanel, this);
2941 * @param e DOCUMENT ME!
2943 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2945 if ( (viewport.getSelectionGroup() == null) ||
2946 (viewport.getSelectionGroup().getSize() < 2))
2948 JOptionPane.showInternalMessageDialog(this,
2949 "You must select at least 2 sequences.",
2950 "Invalid Selection",
2951 JOptionPane.WARNING_MESSAGE);
2955 JInternalFrame frame = new JInternalFrame();
2956 frame.setContentPane(new PairwiseAlignPanel(viewport));
2957 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2964 * @param e DOCUMENT ME!
2966 public void PCAMenuItem_actionPerformed(ActionEvent e)
2968 if ( ( (viewport.getSelectionGroup() != null) &&
2969 (viewport.getSelectionGroup().getSize() < 4) &&
2970 (viewport.getSelectionGroup().getSize() > 0)) ||
2971 (viewport.getAlignment().getHeight() < 4))
2973 JOptionPane.showInternalMessageDialog(this,
2974 "Principal component analysis must take\n" +
2975 "at least 4 input sequences.",
2976 "Sequence selection insufficient",
2977 JOptionPane.WARNING_MESSAGE);
2982 new PCAPanel(alignPanel);
2986 public void autoCalculate_actionPerformed(ActionEvent e)
2988 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2989 if(viewport.autoCalculateConsensus)
2991 viewport.firePropertyChange("alignment",
2993 viewport.getAlignment().getSequences());
3001 * @param e DOCUMENT ME!
3003 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3005 NewTreePanel("AV", "PID", "Average distance tree using PID");
3011 * @param e DOCUMENT ME!
3013 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3015 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3021 * @param e DOCUMENT ME!
3023 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3025 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3031 * @param e DOCUMENT ME!
3033 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3035 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3041 * @param type DOCUMENT ME!
3042 * @param pwType DOCUMENT ME!
3043 * @param title DOCUMENT ME!
3045 void NewTreePanel(String type, String pwType, String title)
3049 if (viewport.getSelectionGroup() != null)
3051 if (viewport.getSelectionGroup().getSize() < 3)
3053 JOptionPane.showMessageDialog(Desktop.desktop,
3054 "You need to have more than two sequences selected to build a tree!",
3055 "Not enough sequences",
3056 JOptionPane.WARNING_MESSAGE);
3061 SequenceGroup sg = viewport.getSelectionGroup();
3063 /* Decide if the selection is a column region */
3064 while (s < sg.getSize())
3066 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
3069 JOptionPane.showMessageDialog(Desktop.desktop,
3070 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
3071 "Try using the Pad function in the edit menu,\n" +
3072 "or one of the multiple sequence alignment web services.",
3073 "Sequences in selection are not aligned",
3074 JOptionPane.WARNING_MESSAGE);
3080 title = title + " on region";
3081 tp = new TreePanel(alignPanel, type, pwType);
3085 //are the sequences aligned?
3086 if (!viewport.alignment.isAligned())
3088 JOptionPane.showMessageDialog(Desktop.desktop,
3089 "The sequences must be aligned before creating a tree.\n" +
3090 "Try using the Pad function in the edit menu,\n" +
3091 "or one of the multiple sequence alignment web services.",
3092 "Sequences not aligned",
3093 JOptionPane.WARNING_MESSAGE);
3098 if(viewport.alignment.getHeight()<2)
3103 tp = new TreePanel(alignPanel, type, pwType);
3108 if(viewport.viewName!=null)
3110 title+= viewport.viewName+" of ";
3113 title += this.title;
3115 Desktop.addInternalFrame(tp, title, 600, 500);
3121 * @param title DOCUMENT ME!
3122 * @param order DOCUMENT ME!
3124 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
3126 final JMenuItem item = new JMenuItem("by " + title);
3128 item.addActionListener(new java.awt.event.ActionListener()
3130 public void actionPerformed(ActionEvent e)
3132 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3134 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
3135 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3137 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3138 viewport.alignment));
3140 alignPanel.paintAlignment(true);
3145 * Add a new sort by annotation score menu item
3146 * @param sort the menu to add the option to
3147 * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
3149 public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
3151 final JMenuItem item = new JMenuItem(scoreLabel);
3153 item.addActionListener(new java.awt.event.ActionListener()
3155 public void actionPerformed(ActionEvent e)
3157 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3158 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());//,viewport.getSelectionGroup());
3159 addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
3160 alignPanel.paintAlignment(true);
3165 * last hash for alignment's annotation array - used to minimise cost of rebuild.
3167 protected int _annotationScoreVectorHash;
3169 * search the alignment and rebuild the sort by annotation score submenu
3170 * the last alignment annotation vector hash is stored to minimize
3171 * cost of rebuilding in subsequence calls.
3174 public void buildSortByAnnotationScoresMenu()
3176 if(viewport.alignment.getAlignmentAnnotation()==null)
3181 if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
3183 sortByAnnotScore.removeAll();
3184 // almost certainly a quicker way to do this - but we keep it simple
3185 Hashtable scoreSorts=new Hashtable();
3186 AlignmentAnnotation aann[];
3187 Enumeration sq = viewport.alignment.getSequences().elements();
3188 while (sq.hasMoreElements())
3190 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3191 for (int i=0;aann!=null && i<aann.length; i++)
3193 if (aann[i].hasScore() && aann[i].sequenceRef!=null)
3195 scoreSorts.put(aann[i].label, aann[i].label);
3199 Enumeration labels = scoreSorts.keys();
3200 while (labels.hasMoreElements())
3202 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
3204 sortByAnnotScore.setVisible(scoreSorts.size()>0);
3207 _annotationScoreVectorHash =
3208 viewport.alignment.getAlignmentAnnotation().hashCode();
3213 * Maintain the Order by->Displayed Tree menu.
3214 * Creates a new menu item for a TreePanel with an appropriate
3215 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
3216 * to remove the menu item when the treePanel is closed, and adjust
3217 * the tree leaf to sequence mapping when the alignment is modified.
3218 * @param treePanel Displayed tree window.
3219 * @param title SortBy menu item title.
3221 public void buildTreeMenu()
3223 sortByTreeMenu.removeAll();
3225 Vector comps = (Vector) PaintRefresher.components.get(viewport.
3226 getSequenceSetId());
3227 Vector treePanels = new Vector();
3228 int i, iSize = comps.size();
3229 for(i=0; i<iSize; i++)
3231 if(comps.elementAt(i) instanceof TreePanel)
3233 treePanels.add(comps.elementAt(i));
3237 iSize = treePanels.size();
3241 sortByTreeMenu.setVisible(false);
3245 sortByTreeMenu.setVisible(true);
3247 for(i=0; i<treePanels.size(); i++)
3249 TreePanel tp = (TreePanel)treePanels.elementAt(i);
3250 final JMenuItem item = new JMenuItem(tp.getTitle());
3251 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
3252 item.addActionListener(new java.awt.event.ActionListener()
3254 public void actionPerformed(ActionEvent e)
3256 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3257 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3259 addHistoryItem(new OrderCommand("Tree Sort",
3261 viewport.alignment));
3263 alignPanel.paintAlignment(true);
3267 sortByTreeMenu.add(item);
3272 * Work out whether the whole set of sequences
3273 * or just the selected set will be submitted for multiple alignment.
3276 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3278 // Now, check we have enough sequences
3279 AlignmentView msa = null;
3281 if ( (viewport.getSelectionGroup() != null) &&
3282 (viewport.getSelectionGroup().getSize() > 1))
3284 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
3285 /*SequenceGroup seqs = viewport.getSelectionGroup();
3287 msa = new SequenceI[sz = seqs.getSize(false)];
3289 for (int i = 0; i < sz; i++)
3291 msa[i] = (SequenceI) seqs.getSequenceAt(i);
3293 msa = viewport.getAlignmentView(true);
3297 /*Vector seqs = viewport.getAlignment().getSequences();
3299 if (seqs.size() > 1)
3301 msa = new SequenceI[seqs.size()];
3303 for (int i = 0; i < seqs.size(); i++)
3305 msa[i] = (SequenceI) seqs.elementAt(i);
3308 msa = viewport.getAlignmentView(false);
3314 * Decides what is submitted to a secondary structure prediction service:
3315 * the first sequence in the alignment, or in the current selection,
3316 * or, if the alignment is 'aligned' (ie padded with gaps), then the
3317 * currently selected region or the whole alignment.
3318 * (where the first sequence in the set is the one that the prediction
3321 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3323 AlignmentView seqs = null;
3325 if ( (viewport.getSelectionGroup() != null) &&
3326 (viewport.getSelectionGroup().getSize() > 0))
3328 seqs = viewport.getAlignmentView(true);
3332 seqs = viewport.getAlignmentView(false);
3334 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
3335 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3336 if (!viewport.alignment.isAligned())
3338 seqs.setSequences(new SeqCigar[]
3339 {seqs.getSequences()[0]});
3346 * @param e DOCUMENT ME!
3348 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3350 // Pick the tree file
3351 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3354 chooser.setFileView(new JalviewFileView());
3355 chooser.setDialogTitle("Select a newick-like tree file");
3356 chooser.setToolTipText("Load a tree file");
3358 int value = chooser.showOpenDialog(null);
3360 if (value == JalviewFileChooser.APPROVE_OPTION)
3362 String choice = chooser.getSelectedFile().getPath();
3363 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3364 jalview.io.NewickFile fin = null;
3367 fin = new jalview.io.NewickFile(choice,
3369 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3371 catch (Exception ex)
3373 JOptionPane.showMessageDialog(Desktop.desktop,
3375 "Problem reading tree file",
3376 JOptionPane.WARNING_MESSAGE);
3377 ex.printStackTrace();
3379 if (fin!=null && fin.hasWarningMessage())
3381 JOptionPane.showMessageDialog(Desktop.desktop,
3382 fin.getWarningMessage(),
3383 "Possible problem with tree file",
3384 JOptionPane.WARNING_MESSAGE);
3390 public TreePanel ShowNewickTree(NewickFile nf, String title)
3392 return ShowNewickTree(nf,title,600,500,4,5);
3395 public TreePanel ShowNewickTree(NewickFile nf, String title,
3396 AlignmentView input)
3398 return ShowNewickTree(nf,title, input, 600,500,4,5);
3401 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
3404 return ShowNewickTree(nf, title, null, w, h, x, y);
3407 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
3409 * @param nf the tree
3410 * @param title tree viewer title
3411 * @param input Associated alignment input data (or null)
3416 * @return TreePanel handle
3418 public TreePanel ShowNewickTree(NewickFile nf, String title,
3419 AlignmentView input, int w, int h, int x,
3422 TreePanel tp = null;
3428 if (nf.getTree() != null)
3430 tp = new TreePanel(alignPanel,
3439 tp.setLocation(x,y);
3443 Desktop.addInternalFrame(tp, title, w, h);
3446 catch (Exception ex)
3448 ex.printStackTrace();
3456 * Generates menu items and listener event actions for web service clients
3459 public void BuildWebServiceMenu()
3461 // TODO: add support for context dependent disabling of services based on alignment and current selection
3462 // TODO: add additional serviceHandle parameter to specify abstract handler class independently of AbstractName
3463 // TODO: add in rediscovery GUI function to restart discoverer
3464 // TODO: group services by location as well as function and/or introduce object broker mechanism.
3465 if ( (Discoverer.services != null)
3466 && (Discoverer.services.size() > 0))
3468 // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere
3469 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3470 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3471 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3472 // 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)
3473 Vector wsmenu = new Vector();
3474 final IProgressIndicator af = this;
3477 // Add any Multiple Sequence Alignment Services
3478 final JMenu msawsmenu = new JMenu("Alignment");
3479 for (int i = 0, j = msaws.size(); i < j; i++)
3481 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3483 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3484 impl.attachWSMenuEntry(msawsmenu, this);
3487 wsmenu.add(msawsmenu);
3489 if (secstrpr != null)
3491 // Add any secondary structure prediction services
3492 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3493 for (int i = 0, j = secstrpr.size(); i < j; i++)
3495 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3497 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3498 impl.attachWSMenuEntry(secstrmenu, this);
3500 wsmenu.add(secstrmenu);
3504 // Add any sequence search services
3505 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3506 for (int i = 0, j = seqsrch.size(); i < j; i++)
3508 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3509 seqsrch.elementAt(i);
3510 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3511 impl.attachWSMenuEntry(seqsrchmenu, this);
3513 // finally, add the whole shebang onto the webservices menu
3514 wsmenu.add(seqsrchmenu);
3516 resetWebServiceMenu();
3517 for (int i = 0, j = wsmenu.size(); i < j; i++)
3519 webService.add( (JMenu) wsmenu.get(i));
3524 resetWebServiceMenu();
3525 this.webService.add(this.webServiceNoServices);
3531 * empty the web service menu and add any ad-hoc functions
3532 * not dynamically discovered.
3535 private void resetWebServiceMenu()
3537 webService.removeAll();
3538 // Temporary hack - DBRef Fetcher always top level ws entry.
3539 JMenuItem rfetch = new JMenuItem("Fetch DB References");
3540 rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
3541 webService.add(rfetch);
3542 rfetch.addActionListener(new ActionListener() {
3544 public void actionPerformed(ActionEvent e)
3546 new jalview.ws.DBRefFetcher(
3547 alignPanel.av.getSequenceSelection(),
3548 alignPanel.alignFrame).fetchDBRefs(false);
3554 /* public void vamsasStore_actionPerformed(ActionEvent e)
3556 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3557 getProperty("LAST_DIRECTORY"));
3559 chooser.setFileView(new JalviewFileView());
3560 chooser.setDialogTitle("Export to Vamsas file");
3561 chooser.setToolTipText("Export");
3563 int value = chooser.showSaveDialog(this);
3565 if (value == JalviewFileChooser.APPROVE_OPTION)
3567 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3568 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3569 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3573 * prototype of an automatically enabled/disabled analysis function
3576 protected void setShowProductsEnabled()
3578 SequenceI [] selection = viewport.getSequenceSelection();
3579 if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset()))
3581 showProducts.setEnabled(true);
3584 showProducts.setEnabled(false);
3588 * search selection for sequence xRef products and build the
3589 * show products menu.
3592 * @return true if showProducts menu should be enabled.
3594 public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset)
3596 boolean showp=false;
3598 showProducts.removeAll();
3599 final boolean dna = viewport.getAlignment().isNucleotide();
3600 final Alignment ds = dataset;
3601 String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset);
3602 //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true);
3603 final SequenceI[] sel = selection;
3604 for (int t=0; ptypes!=null && t<ptypes.length; t++)
3607 final boolean isRegSel = isRegionSelection;
3608 final AlignFrame af = this;
3609 final String source = ptypes[t];
3610 JMenuItem xtype = new JMenuItem(ptypes[t]);
3611 xtype.addActionListener(new ActionListener() {
3613 public void actionPerformed(ActionEvent e)
3615 // TODO: new thread for this call with vis-delay
3616 af.showProductsFor(sel, ds, isRegSel, dna, source);
3620 showProducts.add(xtype);
3622 showProducts.setVisible(showp);
3623 showProducts.setEnabled(showp);
3624 } catch (Exception e)
3626 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3631 protected void showProductsFor(SequenceI[] sel, Alignment ds, boolean isRegSel, boolean dna, String source)
3633 final boolean fisRegSel = isRegSel;
3634 final boolean fdna = dna;
3635 final String fsrc = source;
3636 final AlignFrame ths = this;
3637 final SequenceI[] fsel = sel;
3638 Runnable foo = new Runnable() {
3642 final long sttime = System.currentTimeMillis();
3643 ths.setProgressBar("Searching for sequences from "+fsrc, sttime);
3645 Alignment ds = ths.getViewport().alignment.getDataset(); // update our local dataset reference
3646 Alignment prods = CrossRef.findXrefSequences(fsel, fdna, fsrc, ds);
3649 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3650 for (int s=0; s<sprods.length;s++)
3652 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3653 if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
3654 ds.addSequence(sprods[s].getDatasetSequence());
3655 sprods[s].updatePDBIds();
3657 Alignment al = new Alignment(sprods);
3658 AlignedCodonFrame[] cf = prods.getCodonFrames();
3659 for (int s=0; cf!=null && s<cf.length; s++)
3661 al.addCodonFrame(cf[s]);
3665 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3666 String newtitle =""+((fdna) ? "Proteins " : "Nucleotides ") + " for "+((fisRegSel) ? "selected region of " : "")
3668 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3671 System.err.println("No Sequences generated for xRef type "+fsrc);
3676 jalview.bin.Cache.log.error("Exception when finding crossreferences",e);
3680 jalview.bin.Cache.log.error("Error when finding crossreferences",e);
3682 ths.setProgressBar("Finished searching for sequences from "+fsrc, sttime);
3686 Thread frunner = new Thread(foo);
3691 public boolean canShowTranslationProducts(SequenceI[] selection, AlignmentI alignment)
3695 return (jalview.analysis.Dna.canTranslate(selection, viewport.getViewAsVisibleContigs(true)));
3696 } catch (Exception e)
3698 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3703 public void showProducts_actionPerformed(ActionEvent e)
3705 ///////////////////////////////
3706 // Collect Data to be translated/transferred
3708 SequenceI [] selection = viewport.getSequenceSelection();
3709 AlignmentI al = null;
3711 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport.getViewAsVisibleContigs(true),
3712 viewport.getGapCharacter(), viewport.getAlignment().getDataset());
3713 } catch (Exception ex) {
3715 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3719 JOptionPane.showMessageDialog(Desktop.desktop,
3720 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3721 "Translation Failed",
3722 JOptionPane.WARNING_MESSAGE);
3724 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3725 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3731 public void showTranslation_actionPerformed(ActionEvent e)
3733 ///////////////////////////////
3734 // Collect Data to be translated/transferred
3736 SequenceI [] selection = viewport.getSequenceSelection();
3737 String [] seqstring = viewport.getViewAsString(true);
3738 AlignmentI al = null;
3740 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
3741 viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
3742 viewport.alignment.getWidth(), viewport.getAlignment().getDataset());
3743 } catch (Exception ex) {
3745 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3749 JOptionPane.showMessageDialog(Desktop.desktop,
3750 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3751 "Translation Failed",
3752 JOptionPane.WARNING_MESSAGE);
3754 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3755 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3762 * Try to load a features file onto the alignment.
3763 * @param file contents or path to retrieve file
3764 * @param type access mode of file (see jalview.io.AlignFile)
3765 * @return true if features file was parsed corectly.
3767 public boolean parseFeaturesFile(String file, String type)
3769 boolean featuresFile = false;
3772 featuresFile = new FeaturesFile(file,
3773 type).parse(viewport.alignment.getDataset(),
3774 alignPanel.seqPanel.seqCanvas.
3775 getFeatureRenderer().featureColours,
3780 ex.printStackTrace();
3785 viewport.showSequenceFeatures = true;
3786 showSeqFeatures.setSelected(true);
3787 alignPanel.paintAlignment(true);
3790 return featuresFile;
3793 public void dragEnter(DropTargetDragEvent evt)
3796 public void dragExit(DropTargetEvent evt)
3799 public void dragOver(DropTargetDragEvent evt)
3802 public void dropActionChanged(DropTargetDragEvent evt)
3805 public void drop(DropTargetDropEvent evt)
3807 Transferable t = evt.getTransferable();
3808 java.util.List files = null;
3812 DataFlavor uriListFlavor = new DataFlavor(
3813 "text/uri-list;class=java.lang.String");
3814 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3816 //Works on Windows and MacOSX
3817 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3818 files = (java.util.List) t.getTransferData(DataFlavor.
3819 javaFileListFlavor);
3821 else if (t.isDataFlavorSupported(uriListFlavor))
3823 // This is used by Unix drag system
3824 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3825 String data = (String) t.getTransferData(uriListFlavor);
3826 files = new java.util.ArrayList(1);
3827 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3830 st.hasMoreTokens(); )
3832 String s = st.nextToken();
3833 if (s.startsWith("#"))
3835 // the line is a comment (as per the RFC 2483)
3839 java.net.URI uri = new java.net.URI(s);
3840 java.io.File file = new java.io.File(uri);
3847 e.printStackTrace();
3854 for (int i = 0; i < files.size(); i++)
3856 loadJalviewDataFile(files.get(i).toString());
3859 catch (Exception ex)
3861 ex.printStackTrace();
3867 * Attempt to load a "dropped" file: First by testing
3868 * whether it's and Annotation file, then a JNet file, and finally a features file. If all are
3869 * false then the user may have dropped an alignment file onto this
3871 * @param file either a filename or a URL string.
3873 public void loadJalviewDataFile(String file)
3877 String protocol = "File";
3879 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3884 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3885 alignment, file, protocol);
3889 // try to see if its a JNet 'concise' style annotation file *before* we try to parse it as a features file
3890 String format = new IdentifyFile().Identify(file, protocol);
3891 if(format.equalsIgnoreCase("JnetFile"))
3893 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3895 new JnetAnnotationMaker().add_annotation(predictions,
3896 viewport.getAlignment(),
3902 // try to parse it as a features file
3903 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3904 // if it wasn't a features file then we just treat it as a general alignment file to load into the current view.
3907 new FileLoader().LoadFile(viewport, file, protocol, format);
3909 alignPanel.paintAlignment(true);
3916 alignPanel.adjustAnnotationHeight();
3917 viewport.updateSequenceIdColours();
3918 buildSortByAnnotationScoresMenu();
3919 alignPanel.paintAlignment(true);
3922 catch (Exception ex)
3924 ex.printStackTrace();
3928 public void tabSelectionChanged(int index)
3932 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3933 viewport = alignPanel.av;
3934 setMenusFromViewport(viewport);
3938 public void tabbedPane_mousePressed(MouseEvent e)
3940 if(SwingUtilities.isRightMouseButton(e))
3942 String reply = JOptionPane.showInternalInputDialog(this,
3945 JOptionPane.QUESTION_MESSAGE);
3949 viewport.viewName = reply;
3950 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3956 public AlignViewport getCurrentView()
3963 * Open the dialog for regex description parsing.
3965 protected void extractScores_actionPerformed(ActionEvent e)
3967 ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
3968 if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0)
3970 buildSortByAnnotationScoresMenu();
3979 public PrintThread(AlignmentPanel ap)
3983 static PageFormat pf;
3986 PrinterJob printJob = PrinterJob.getPrinterJob();
3990 printJob.setPrintable(ap, pf);
3994 printJob.setPrintable(ap);
3997 if (printJob.printDialog())
4003 catch (Exception PrintException)
4005 PrintException.printStackTrace();