2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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 Software
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);
522 * set up menus for the currently viewport.
523 * This may be called after any operation that affects the data in the current view (selection changed, etc) to update the menus to reflect the new state.
525 public void setMenusForViewport()
527 setMenusFromViewport(viewport);
530 * Need to call this method when tabs are selected for multiple views,
531 * or when loading from Jalview2XML.java
532 * @param av AlignViewport
534 void setMenusFromViewport(AlignViewport av)
536 padGapsMenuitem.setSelected(av.padGaps);
537 colourTextMenuItem.setSelected(av.showColourText);
538 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
539 conservationMenuItem.setSelected(av.getConservationSelected());
540 seqLimits.setSelected(av.getShowJVSuffix());
541 idRightAlign.setSelected(av.rightAlignIds);
542 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
543 renderGapsMenuItem.setSelected(av.renderGaps);
544 wrapMenuItem.setSelected(av.wrapAlignment);
545 scaleAbove.setVisible(av.wrapAlignment);
546 scaleLeft.setVisible(av.wrapAlignment);
547 scaleRight.setVisible(av.wrapAlignment);
548 annotationPanelMenuItem.setState(av.showAnnotation);
549 viewBoxesMenuItem.setSelected(av.showBoxes);
550 viewTextMenuItem.setSelected(av.showText);
552 setColourSelected(ColourSchemeProperty.
553 getColourName(av.getGlobalColourScheme()));
555 showSeqFeatures.setSelected(av.showSequenceFeatures);
556 hiddenMarkers.setState(av.showHiddenMarkers);
557 applyToAllGroups.setState(av.colourAppliesToAllGroups);
559 setShowProductsEnabled();
565 Hashtable progressBars;
567 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
569 public void setProgressBar(String message, long id)
571 if(progressBars == null)
573 progressBars = new Hashtable();
576 JPanel progressPanel;
577 GridLayout layout = (GridLayout) statusPanel.getLayout();
578 if(progressBars.get( new Long(id) )!=null)
580 progressPanel = (JPanel)progressBars.get( new Long(id) );
581 statusPanel.remove(progressPanel);
582 progressBars.remove( progressPanel );
583 progressPanel = null;
586 statusBar.setText(message);
589 layout.setRows(layout.getRows() - 1);
593 progressPanel = new JPanel(new BorderLayout(10, 5));
595 JProgressBar progressBar = new JProgressBar();
596 progressBar.setIndeterminate(true);
598 progressPanel.add(new JLabel(message), BorderLayout.WEST);
599 progressPanel.add(progressBar, BorderLayout.CENTER);
601 layout.setRows(layout.getRows() + 1);
602 statusPanel.add(progressPanel);
604 progressBars.put(new Long(id), progressPanel);
607 setMenusForViewport();
612 * @return true if any progress bars are still active
614 public boolean operationInProgress()
616 if (progressBars!=null && progressBars.size()>0)
623 Added so Castor Mapping file can obtain Jalview Version
625 public String getVersion()
627 return jalview.bin.Cache.getProperty("VERSION");
630 public FeatureRenderer getFeatureRenderer()
632 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
636 public void fetchSequence_actionPerformed(ActionEvent e)
638 new SequenceFetcher(this);
641 public void addFromFile_actionPerformed(ActionEvent e)
643 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
646 public void reload_actionPerformed(ActionEvent e)
650 if(currentFileFormat.equals("Jalview"))
652 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
653 for(int i=0; i<frames.length; i++)
655 if (frames[i] instanceof AlignFrame
657 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
661 frames[i].setSelected(true);
662 Desktop.instance.closeAssociatedWindows();
664 catch (java.beans.PropertyVetoException ex)
669 Desktop.instance.closeAssociatedWindows();
671 FileLoader loader = new FileLoader();
672 String protocol = fileName.startsWith("http:")? "URL":"File";
673 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
677 Rectangle bounds = this.getBounds();
679 FileLoader loader = new FileLoader();
680 String protocol = fileName.startsWith("http:") ? "URL" : "File";
681 AlignFrame newframe =
682 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
684 newframe.setBounds(bounds);
686 this.closeMenuItem_actionPerformed(true);
692 public void addFromText_actionPerformed(ActionEvent e)
694 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
697 public void addFromURL_actionPerformed(ActionEvent e)
699 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
703 public void save_actionPerformed(ActionEvent e)
706 || (currentFileFormat==null || jalview.io.AppletFormatAdapter.isValidFormat(currentFileFormat, true))
707 || fileName.startsWith("http")
710 saveAs_actionPerformed(null);
714 saveAlignment(fileName, currentFileFormat);
721 * @param e DOCUMENT ME!
723 public void saveAs_actionPerformed(ActionEvent e)
725 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
726 getProperty( "LAST_DIRECTORY"),
727 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
728 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
733 chooser.setFileView(new JalviewFileView());
734 chooser.setDialogTitle("Save Alignment to file");
735 chooser.setToolTipText("Save");
737 int value = chooser.showSaveDialog(this);
739 if (value == JalviewFileChooser.APPROVE_OPTION)
741 currentFileFormat = chooser.getSelectedFormat();
742 if (currentFileFormat == null)
744 JOptionPane.showInternalMessageDialog(Desktop.desktop,
745 "You must select a file format before saving!",
746 "File format not specified",
747 JOptionPane.WARNING_MESSAGE);
748 value = chooser.showSaveDialog(this);
752 fileName = chooser.getSelectedFile().getPath();
754 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
757 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
758 if (currentFileFormat.indexOf(" ")>-1)
760 currentFileFormat = currentFileFormat.substring(0, currentFileFormat.indexOf(" "));
762 saveAlignment(fileName, currentFileFormat);
766 public boolean saveAlignment(String file, String format)
768 boolean success = true;
770 if (format.equalsIgnoreCase("Jalview"))
772 String shortName = title;
774 if (shortName.indexOf(java.io.File.separatorChar) > -1)
776 shortName = shortName.substring(shortName.lastIndexOf(
777 java.io.File.separatorChar) + 1);
780 success = new Jalview2XML().SaveAlignment(this, file, shortName);
782 statusBar.setText("Successfully saved to file: "
784 +format +" format.");
789 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
791 // JBPNote need to have a raise_gui flag here
792 JOptionPane.showInternalMessageDialog(
793 this, "Cannot save file " + fileName + " using format "+format,
794 "Alignment output format not supported",
795 JOptionPane.WARNING_MESSAGE);
796 saveAs_actionPerformed(null);
800 String[] omitHidden = null;
802 if (viewport.hasHiddenColumns)
804 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
805 "The Alignment contains hidden columns."
806 + "\nDo you want to save only the visible alignment?",
807 "Save / Omit Hidden Columns",
808 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
810 if (reply == JOptionPane.YES_OPTION)
812 omitHidden = viewport.getViewAsString(false);
815 FormatAdapter f = new FormatAdapter();
816 String output = f.formatSequences(
818 (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future
819 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
829 java.io.PrintWriter out = new java.io.PrintWriter(
830 new java.io.FileWriter(file));
835 statusBar.setText("Successfully saved to file: "
837 + format + " format.");
842 ex.printStackTrace();
849 JOptionPane.showInternalMessageDialog(
850 this, "Couldn't save file: " + fileName,
852 JOptionPane.WARNING_MESSAGE);
861 * @param e DOCUMENT ME!
863 protected void outputText_actionPerformed(ActionEvent e)
865 String [] omitHidden = null;
867 if(viewport.hasHiddenColumns)
869 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
870 "The Alignment contains hidden columns."
871 +"\nDo you want to output only the visible alignment?",
872 "Save / Omit Hidden Columns",
873 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
875 if(reply==JOptionPane.YES_OPTION)
877 omitHidden = viewport.getViewAsString(false);
881 CutAndPasteTransfer cap = new CutAndPasteTransfer();
882 cap.setForInput(null);
883 Desktop.addInternalFrame(cap,
884 "Alignment output - " + e.getActionCommand(), 600,
888 cap.setText(new FormatAdapter().formatSequences(
889 e.getActionCommand(),
891 omitHidden, viewport.colSel));
897 * @param e DOCUMENT ME!
899 protected void htmlMenuItem_actionPerformed(ActionEvent e)
901 new HTMLOutput(alignPanel,
902 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
903 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
906 public void createImageMap(File file, String image)
908 alignPanel.makePNGImageMap(file, image);
914 * @param e DOCUMENT ME!
916 public void createPNG(File f)
918 alignPanel.makePNG(f);
924 * @param e DOCUMENT ME!
926 public void createEPS(File f)
928 alignPanel.makeEPS(f);
932 public void pageSetup_actionPerformed(ActionEvent e)
934 PrinterJob printJob = PrinterJob.getPrinterJob();
935 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
941 * @param e DOCUMENT ME!
943 public void printMenuItem_actionPerformed(ActionEvent e)
945 //Putting in a thread avoids Swing painting problems
946 PrintThread thread = new PrintThread(alignPanel);
950 public void exportFeatures_actionPerformed(ActionEvent e)
952 new AnnotationExporter().exportFeatures(alignPanel);
956 public void exportAnnotations_actionPerformed(ActionEvent e)
958 new AnnotationExporter().exportAnnotations(
960 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
961 viewport.alignment.getGroups(),
962 ((Alignment)viewport.alignment).alignmentProperties
967 public void associatedData_actionPerformed(ActionEvent e)
969 // Pick the tree file
970 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
973 chooser.setFileView(new JalviewFileView());
974 chooser.setDialogTitle("Load Jalview Annotations or Features File");
975 chooser.setToolTipText("Load Jalview Annotations / Features file");
977 int value = chooser.showOpenDialog(null);
979 if (value == JalviewFileChooser.APPROVE_OPTION)
981 String choice = chooser.getSelectedFile().getPath();
982 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
983 loadJalviewDataFile(choice);
992 * @param e DOCUMENT ME!
994 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
996 if(alignPanels!=null && alignPanels.size()<2)
1003 if(alignPanels!=null)
1007 for (int i = 0; i < alignPanels.size(); i++)
1009 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1010 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
1011 .removeStructureViewerListener(ap.seqPanel, null);
1012 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
1013 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
1014 PaintRefresher.RemoveComponent(ap);
1015 ap.av.alignment = null;
1020 int index = tabbedPane.getSelectedIndex();
1022 alignPanels.removeElement(alignPanel);
1023 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1024 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1025 PaintRefresher.RemoveComponent(alignPanel);
1026 viewport.alignment = null;
1030 tabbedPane.removeTabAt(index);
1031 tabbedPane.validate();
1033 if(index==tabbedPane.getTabCount())
1038 this.tabSelectionChanged(index);
1044 this.setClosed(true);
1047 catch (Exception ex)
1049 ex.printStackTrace();
1057 void updateEditMenuBar()
1060 if (viewport.historyList.size() > 0)
1062 undoMenuItem.setEnabled(true);
1063 CommandI command = (CommandI) viewport.historyList.peek();
1064 undoMenuItem.setText("Undo " + command.getDescription());
1068 undoMenuItem.setEnabled(false);
1069 undoMenuItem.setText("Undo");
1072 if (viewport.redoList.size() > 0)
1074 redoMenuItem.setEnabled(true);
1076 CommandI command = (CommandI) viewport.redoList.peek();
1077 redoMenuItem.setText("Redo " + command.getDescription());
1081 redoMenuItem.setEnabled(false);
1082 redoMenuItem.setText("Redo");
1087 public void addHistoryItem(CommandI command)
1089 if(command.getSize()>0)
1091 viewport.historyList.push(command);
1092 viewport.redoList.clear();
1093 updateEditMenuBar();
1094 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1100 * @return alignment objects for all views
1102 AlignmentI[] getViewAlignments()
1104 if (alignPanels!=null)
1106 Enumeration e = alignPanels.elements();
1107 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1108 for (int i=0; e.hasMoreElements(); i++)
1110 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1116 return new AlignmentI[] { viewport.alignment };
1123 * @param e DOCUMENT ME!
1125 protected void undoMenuItem_actionPerformed(ActionEvent e)
1127 if (viewport.historyList.empty())
1129 CommandI command = (CommandI)viewport.historyList.pop();
1130 viewport.redoList.push(command);
1131 command.undoCommand(getViewAlignments());
1133 AlignViewport originalSource = getOriginatingSource(command);
1134 updateEditMenuBar();
1136 if(originalSource!=null)
1138 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1139 originalSource.firePropertyChange("alignment",
1141 originalSource.alignment.getSequences());
1148 * @param e DOCUMENT ME!
1150 protected void redoMenuItem_actionPerformed(ActionEvent e)
1152 if(viewport.redoList.size()<1)
1157 CommandI command = (CommandI) viewport.redoList.pop();
1158 viewport.historyList.push(command);
1159 command.doCommand(getViewAlignments());
1161 AlignViewport originalSource = getOriginatingSource(command);
1162 updateEditMenuBar();
1164 if(originalSource!=null)
1166 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1167 originalSource.firePropertyChange("alignment",
1169 originalSource.alignment.getSequences());
1173 AlignViewport getOriginatingSource(CommandI command)
1175 AlignViewport originalSource = null;
1176 //For sequence removal and addition, we need to fire
1177 //the property change event FROM the viewport where the
1178 //original alignment was altered
1180 if (command instanceof EditCommand)
1182 EditCommand editCommand = (EditCommand) command;
1183 al = editCommand.getAlignment();
1184 Vector comps = (Vector) PaintRefresher.components
1185 .get(viewport.getSequenceSetId());
1187 for (int i = 0; i < comps.size(); i++)
1189 if (comps.elementAt(i) instanceof AlignmentPanel)
1191 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1193 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1200 if (originalSource == null)
1202 //The original view is closed, we must validate
1203 //the current view against the closed view first
1206 PaintRefresher.validateSequences(al, viewport.alignment);
1209 originalSource = viewport;
1212 return originalSource;
1218 * @param up DOCUMENT ME!
1220 public void moveSelectedSequences(boolean up)
1222 SequenceGroup sg = viewport.getSelectionGroup();
1231 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1233 SequenceI seq = viewport.alignment.getSequenceAt(i);
1235 if (!sg.getSequences(null).contains(seq))
1240 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1242 if (sg.getSequences(null).contains(temp))
1247 viewport.alignment.getSequences().setElementAt(temp, i);
1248 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1253 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1255 SequenceI seq = viewport.alignment.getSequenceAt(i);
1257 if (!sg.getSequences(null).contains(seq))
1262 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1264 if (sg.getSequences(null).contains(temp))
1269 viewport.alignment.getSequences().setElementAt(temp, i);
1270 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1274 alignPanel.paintAlignment(true);
1280 synchronized void slideSequences(boolean right, int size)
1282 Vector sg = new Vector();
1283 if(viewport.cursorMode)
1285 sg.addElement(viewport.alignment.getSequenceAt(
1286 alignPanel.seqPanel.seqCanvas.cursorY));
1288 else if(viewport.getSelectionGroup()!=null
1289 && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
1291 sg = viewport.getSelectionGroup().getSequences(
1292 viewport.hiddenRepSequences);
1300 Vector invertGroup = new Vector();
1302 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1304 if(!sg.contains(viewport.alignment.getSequenceAt(i)))
1305 invertGroup.add(viewport.alignment.getSequenceAt(i));
1308 SequenceI[] seqs1 = new SequenceI[sg.size()];
1309 for (int i = 0; i < sg.size(); i++)
1310 seqs1[i] = (SequenceI) sg.elementAt(i);
1312 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1313 for (int i = 0; i < invertGroup.size(); i++)
1314 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1316 SlideSequencesCommand ssc;
1318 ssc = new SlideSequencesCommand("Slide Sequences",
1320 viewport.getGapCharacter()
1323 ssc = new SlideSequencesCommand("Slide Sequences",
1325 viewport.getGapCharacter()
1328 int groupAdjustment = 0;
1329 if (ssc.getGapsInsertedBegin() && right)
1331 if (viewport.cursorMode)
1332 alignPanel.seqPanel.moveCursor(size, 0);
1334 groupAdjustment = size;
1336 else if (!ssc.getGapsInsertedBegin() && !right)
1338 if (viewport.cursorMode)
1339 alignPanel.seqPanel.moveCursor( -size, 0);
1341 groupAdjustment = -size;
1344 if (groupAdjustment != 0)
1346 viewport.getSelectionGroup().setStartRes(
1347 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1348 viewport.getSelectionGroup().setEndRes(
1349 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1353 boolean appendHistoryItem = false;
1354 if(viewport.historyList!=null
1355 && viewport.historyList.size()>0
1356 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1358 appendHistoryItem = ssc.appendSlideCommand(
1359 (SlideSequencesCommand)viewport.historyList.peek())
1363 if(!appendHistoryItem)
1364 addHistoryItem(ssc);
1373 * @param e DOCUMENT ME!
1375 protected void copy_actionPerformed(ActionEvent e)
1378 if (viewport.getSelectionGroup() == null)
1382 // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
1383 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1384 String[] omitHidden = null;
1386 if (viewport.hasHiddenColumns)
1388 omitHidden = viewport.getViewAsString(true);
1391 String output = new FormatAdapter().formatSequences(
1396 StringSelection ss = new StringSelection(output);
1400 jalview.gui.Desktop.internalCopy = true;
1401 //Its really worth setting the clipboard contents
1402 //to empty before setting the large StringSelection!!
1403 Toolkit.getDefaultToolkit().getSystemClipboard()
1404 .setContents(new StringSelection(""), null);
1406 Toolkit.getDefaultToolkit().getSystemClipboard()
1407 .setContents(ss, Desktop.instance);
1409 catch (OutOfMemoryError er)
1411 new OOMWarning("copying region", er);
1415 Vector hiddenColumns = null;
1416 if(viewport.hasHiddenColumns)
1418 hiddenColumns =new Vector();
1419 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1420 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1423 int[] region = (int[])
1424 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1426 hiddenColumns.addElement(new int[]
1427 {region[0] - hiddenOffset,
1428 region[1]-hiddenOffset});
1432 Desktop.jalviewClipboard = new Object[]
1435 viewport.alignment.getDataset(),
1437 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1443 * @param e DOCUMENT ME!
1445 protected void pasteNew_actionPerformed(ActionEvent e)
1453 * @param e DOCUMENT ME!
1455 protected void pasteThis_actionPerformed(ActionEvent e)
1461 * Paste contents of Jalview clipboard
1463 * @param newAlignment true to paste to a new alignment, otherwise add to this.
1465 void paste(boolean newAlignment)
1467 boolean externalPaste=true;
1470 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1471 Transferable contents = c.getContents(this);
1473 if (contents == null)
1481 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1482 if (str.length() < 1)
1487 format = new IdentifyFile().Identify(str, "Paste");
1490 catch (OutOfMemoryError er)
1492 new OOMWarning("Out of memory pasting sequences!!", er);
1496 SequenceI[] sequences;
1497 boolean annotationAdded = false;
1498 AlignmentI alignment = null;
1500 if(Desktop.jalviewClipboard!=null)
1502 // The clipboard was filled from within Jalview, we must use the sequences
1503 // And dataset from the copied alignment
1504 SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
1505 // be doubly sure that we create *new* sequence objects.
1506 sequences = new SequenceI[newseq.length];
1507 for (int i=0;i<newseq.length;i++) {
1508 sequences[i] = new Sequence(newseq[i]);
1510 alignment = new Alignment(sequences);
1511 externalPaste = false;
1515 // parse the clipboard as an alignment.
1516 alignment = new FormatAdapter().readFile(str, "Paste", format);
1517 sequences = alignment.getSequencesArray();
1525 if (Desktop.jalviewClipboard != null)
1527 // dataset is inherited
1528 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1532 // new dataset is constructed
1533 alignment.setDataset(null);
1535 alwidth = alignment.getWidth()+1;
1539 AlignmentI pastedal = alignment; // preserve pasted alignment object
1540 // Add pasted sequences and dataset into existing alignment.
1541 alignment = viewport.getAlignment();
1542 alwidth = alignment.getWidth()+1;
1543 // decide if we need to import sequences from an existing dataset
1544 boolean importDs = Desktop.jalviewClipboard != null
1545 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1546 // importDs==true instructs us to copy over new dataset sequences from
1547 // an existing alignment
1548 Vector newDs = (importDs) ? new Vector() : null; // used to create
1549 // minimum dataset set
1551 for (int i = 0; i < sequences.length; i++)
1555 newDs.addElement(null);
1557 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1559 if (importDs && ds != null)
1561 if (!newDs.contains(ds))
1563 newDs.setElementAt(ds, i);
1564 ds = new Sequence(ds);
1565 // update with new dataset sequence
1566 sequences[i].setDatasetSequence(ds);
1570 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1575 // copy and derive new dataset sequence
1576 sequences[i] = sequences[i].deriveSequence();
1577 alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
1578 // TODO: avoid creation of duplicate dataset sequences with a
1579 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1581 alignment.addSequence(sequences[i]); // merges dataset
1585 newDs.clear(); // tidy up
1587 if (pastedal.getAlignmentAnnotation()!=null) {
1588 // Add any annotation attached to alignment.
1589 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1590 for (int i=0; i<alann.length; i++)
1592 annotationAdded=true;
1593 if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
1594 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1595 newann.padAnnotation(alwidth);
1596 alignment.addAnnotation(newann);
1601 if (!newAlignment) {
1605 addHistoryItem(new EditCommand(
1610 alignment.getWidth(),
1614 // Add any annotations attached to sequences
1615 for (int i = 0; i < sequences.length; i++)
1617 if (sequences[i].getAnnotation() != null)
1619 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1621 annotationAdded=true;
1622 sequences[i].getAnnotation()[a].adjustForAlignment();
1623 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1624 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
1625 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1629 if (!newAlignment) {
1631 // propagate alignment changed.
1632 viewport.setEndSeq(alignment.getHeight());
1633 if (annotationAdded)
1635 // Duplicate sequence annotation in all views.
1636 AlignmentI[] alview = this.getViewAlignments();
1637 for (int i = 0; i < sequences.length; i++)
1639 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1642 for (int avnum=0;avnum<alview.length; avnum++)
1644 if (alview[avnum]!=alignment)
1646 // duplicate in a view other than the one with input focus
1647 int avwidth = alview[avnum].getWidth()+1;
1648 // this relies on sann being preserved after we
1649 // modify the sequence's annotation array for each duplication
1650 for (int a=0; a<sann.length; a++)
1652 AlignmentAnnotation newann = new AlignmentAnnotation(sann[a]);
1653 sequences[i].addAlignmentAnnotation(newann);
1654 newann.padAnnotation(avwidth);
1655 alview[avnum].addAnnotation(newann); // annotation was duplicated earlier
1656 alview[avnum].setAnnotationIndex(newann, a);
1661 buildSortByAnnotationScoresMenu();
1663 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1666 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1667 String newtitle = new String("Copied sequences");
1669 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1671 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1672 for(int i=0; i<hc.size(); i++)
1674 int [] region = (int[]) hc.elementAt(i);
1675 af.viewport.hideColumns(region[0], region[1]);
1680 //>>>This is a fix for the moment, until a better solution is found!!<<<
1681 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1682 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1684 // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
1685 if (!externalPaste) {
1686 if (title.startsWith("Copied sequences"))
1692 newtitle = newtitle.concat("- from " + title);
1695 newtitle = new String("Pasted sequences");
1698 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1705 catch (Exception ex)
1707 ex.printStackTrace();
1708 System.out.println("Exception whilst pasting: "+ex);
1709 // could be anything being pasted in here
1718 * @param e DOCUMENT ME!
1720 protected void cut_actionPerformed(ActionEvent e)
1722 copy_actionPerformed(null);
1723 delete_actionPerformed(null);
1729 * @param e DOCUMENT ME!
1731 protected void delete_actionPerformed(ActionEvent evt)
1734 SequenceGroup sg = viewport.getSelectionGroup();
1740 Vector seqs = new Vector();
1742 for (int i = 0; i < sg.getSize(); i++)
1744 seq = sg.getSequenceAt(i);
1745 seqs.addElement(seq);
1749 // If the cut affects all sequences, remove highlighted columns
1750 if (sg.getSize() == viewport.alignment.getHeight())
1752 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1753 sg.getEndRes() + 1);
1757 SequenceI [] cut = new SequenceI[seqs.size()];
1758 for(int i=0; i<seqs.size(); i++)
1760 cut[i] = (SequenceI)seqs.elementAt(i);
1767 addHistoryItem(new EditCommand("Cut Sequences",
1771 sg.getEndRes()-sg.getStartRes()+1,
1772 viewport.alignment));
1775 viewport.setSelectionGroup(null);
1776 viewport.alignment.deleteGroup(sg);
1778 viewport.firePropertyChange("alignment", null,
1779 viewport.getAlignment().getSequences());
1781 if (viewport.getAlignment().getHeight() < 1)
1785 this.setClosed(true);
1787 catch (Exception ex)
1796 * @param e DOCUMENT ME!
1798 protected void deleteGroups_actionPerformed(ActionEvent e)
1800 viewport.alignment.deleteAllGroups();
1801 viewport.sequenceColours = null;
1802 viewport.setSelectionGroup(null);
1803 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1804 alignPanel.paintAlignment(true);
1810 * @param e DOCUMENT ME!
1812 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1814 SequenceGroup sg = new SequenceGroup();
1816 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1819 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1822 sg.setEndRes(viewport.alignment.getWidth() - 1);
1823 viewport.setSelectionGroup(sg);
1824 alignPanel.paintAlignment(true);
1825 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1831 * @param e DOCUMENT ME!
1833 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1835 if(viewport.cursorMode)
1837 alignPanel.seqPanel.keyboardNo1 = null;
1838 alignPanel.seqPanel.keyboardNo2 = null;
1840 viewport.setSelectionGroup(null);
1841 viewport.getColumnSelection().clear();
1842 viewport.setSelectionGroup(null);
1843 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1844 alignPanel.idPanel.idCanvas.searchResults = null;
1845 alignPanel.paintAlignment(true);
1846 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1852 * @param e DOCUMENT ME!
1854 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1856 SequenceGroup sg = viewport.getSelectionGroup();
1860 selectAllSequenceMenuItem_actionPerformed(null);
1865 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1868 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1871 alignPanel.paintAlignment(true);
1873 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1876 public void invertColSel_actionPerformed(ActionEvent e)
1878 viewport.invertColumnSelection();
1879 alignPanel.paintAlignment(true);
1886 * @param e DOCUMENT ME!
1888 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1890 trimAlignment(true);
1896 * @param e DOCUMENT ME!
1898 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1900 trimAlignment(false);
1903 void trimAlignment(boolean trimLeft)
1905 ColumnSelection colSel = viewport.getColumnSelection();
1908 if (colSel.size() > 0)
1912 column = colSel.getMin();
1916 column = colSel.getMax();
1920 if(viewport.getSelectionGroup()!=null)
1922 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1923 hiddenRepSequences);
1927 seqs = viewport.alignment.getSequencesArray();
1931 TrimRegionCommand trimRegion;
1934 trimRegion = new TrimRegionCommand("Remove Left",
1935 TrimRegionCommand.TRIM_LEFT,
1940 viewport.selectionGroup);
1941 viewport.setStartRes(0);
1945 trimRegion = new TrimRegionCommand("Remove Right",
1946 TrimRegionCommand.TRIM_RIGHT,
1951 viewport.selectionGroup);
1954 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1957 addHistoryItem(trimRegion);
1959 Vector groups = viewport.alignment.getGroups();
1961 for (int i = 0; i < groups.size(); i++)
1963 SequenceGroup sg = (SequenceGroup) groups.get(i);
1965 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1966 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1968 viewport.alignment.deleteGroup(sg);
1972 viewport.firePropertyChange("alignment", null,
1973 viewport.getAlignment().getSequences());
1980 * @param e DOCUMENT ME!
1982 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1984 int start = 0, end = viewport.alignment.getWidth()-1;
1987 if (viewport.getSelectionGroup() != null)
1989 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1990 hiddenRepSequences);
1991 start = viewport.getSelectionGroup().getStartRes();
1992 end = viewport.getSelectionGroup().getEndRes();
1996 seqs = viewport.alignment.getSequencesArray();
2000 RemoveGapColCommand removeGapCols =
2001 new RemoveGapColCommand("Remove Gapped Columns",
2004 viewport.alignment);
2006 addHistoryItem(removeGapCols);
2008 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
2010 //This is to maintain viewport position on first residue
2012 SequenceI seq = viewport.alignment.getSequenceAt(0);
2013 int startRes = seq.findPosition(viewport.startRes);
2014 // ShiftList shifts;
2015 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2016 // edit.alColumnChanges=shifts.getInverse();
2017 // if (viewport.hasHiddenColumns)
2018 // viewport.getColumnSelection().compensateForEdits(shifts);
2019 viewport.setStartRes(seq.findIndex(startRes)-1);
2020 viewport.firePropertyChange("alignment", null,
2021 viewport.getAlignment().getSequences());
2028 * @param e DOCUMENT ME!
2030 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2032 int start = 0, end = viewport.alignment.getWidth()-1;
2035 if (viewport.getSelectionGroup() != null)
2037 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
2038 hiddenRepSequences);
2039 start = viewport.getSelectionGroup().getStartRes();
2040 end = viewport.getSelectionGroup().getEndRes();
2044 seqs = viewport.alignment.getSequencesArray();
2047 //This is to maintain viewport position on first residue
2049 SequenceI seq = viewport.alignment.getSequenceAt(0);
2050 int startRes = seq.findPosition(viewport.startRes);
2052 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
2055 viewport.alignment));
2057 viewport.setStartRes(seq.findIndex(startRes)-1);
2059 viewport.firePropertyChange("alignment", null,
2060 viewport.getAlignment().getSequences());
2067 * @param e DOCUMENT ME!
2069 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2071 viewport.padGaps = padGapsMenuitem.isSelected();
2073 viewport.firePropertyChange("alignment",
2075 viewport.getAlignment().getSequences());
2081 * @param e DOCUMENT ME!
2083 public void findMenuItem_actionPerformed(ActionEvent e)
2088 public void newView_actionPerformed(ActionEvent e)
2090 AlignmentPanel newap =
2091 new Jalview2XML().copyAlignPanel(alignPanel, true);
2093 newap.av.gatherViewsHere = false;
2095 if (viewport.viewName == null)
2097 viewport.viewName = "Original";
2100 newap.av.historyList = viewport.historyList;
2101 newap.av.redoList = viewport.redoList;
2103 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2104 String newViewName = "View " +index;
2106 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2107 getSequenceSetId());
2108 Vector existingNames = new Vector();
2109 for(int i=0; i<comps.size(); i++)
2111 if(comps.elementAt(i) instanceof AlignmentPanel)
2113 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
2114 if(!existingNames.contains(ap.av.viewName))
2116 existingNames.addElement(ap.av.viewName);
2121 while(existingNames.contains(newViewName))
2123 newViewName = "View "+ (++index);
2126 newap.av.viewName = newViewName;
2128 addAlignmentPanel(newap, false);
2130 if(alignPanels.size()==2)
2132 viewport.gatherViewsHere = true;
2134 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2137 public void expandViews_actionPerformed(ActionEvent e)
2139 Desktop.instance.explodeViews(this);
2142 public void gatherViews_actionPerformed(ActionEvent e)
2144 Desktop.instance.gatherViews(this);
2152 * @param e DOCUMENT ME!
2154 public void font_actionPerformed(ActionEvent e)
2156 new FontChooser(alignPanel);
2163 * @param e DOCUMENT ME!
2165 protected void seqLimit_actionPerformed(ActionEvent e)
2167 viewport.setShowJVSuffix(seqLimits.isSelected());
2169 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
2170 alignPanel.paintAlignment(true);
2173 public void idRightAlign_actionPerformed(ActionEvent e)
2175 viewport.rightAlignIds = idRightAlign.isSelected();
2176 alignPanel.paintAlignment(true);
2179 public void centreColumnLabels_actionPerformed(ActionEvent e)
2181 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2182 alignPanel.paintAlignment(true);
2190 * @param e DOCUMENT ME!
2192 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2194 viewport.setColourText(colourTextMenuItem.isSelected());
2195 alignPanel.paintAlignment(true);
2201 * @param e DOCUMENT ME!
2203 public void wrapMenuItem_actionPerformed(ActionEvent e)
2205 scaleAbove.setVisible(wrapMenuItem.isSelected());
2206 scaleLeft.setVisible(wrapMenuItem.isSelected());
2207 scaleRight.setVisible(wrapMenuItem.isSelected());
2208 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2209 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2212 public void showAllSeqs_actionPerformed(ActionEvent e)
2214 viewport.showAllHiddenSeqs();
2217 public void showAllColumns_actionPerformed(ActionEvent e)
2219 viewport.showAllHiddenColumns();
2223 public void hideSelSequences_actionPerformed(ActionEvent e)
2225 viewport.hideAllSelectedSeqs();
2226 alignPanel.paintAlignment(true);
2229 public void hideSelColumns_actionPerformed(ActionEvent e)
2231 viewport.hideSelectedColumns();
2232 alignPanel.paintAlignment(true);
2235 public void hiddenMarkers_actionPerformed(ActionEvent e)
2237 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2244 * @param e DOCUMENT ME!
2246 protected void scaleAbove_actionPerformed(ActionEvent e)
2248 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2249 alignPanel.paintAlignment(true);
2255 * @param e DOCUMENT ME!
2257 protected void scaleLeft_actionPerformed(ActionEvent e)
2259 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2260 alignPanel.paintAlignment(true);
2266 * @param e DOCUMENT ME!
2268 protected void scaleRight_actionPerformed(ActionEvent e)
2270 viewport.setScaleRightWrapped(scaleRight.isSelected());
2271 alignPanel.paintAlignment(true);
2277 * @param e DOCUMENT ME!
2279 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2281 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2282 alignPanel.paintAlignment(true);
2288 * @param e DOCUMENT ME!
2290 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2292 viewport.setShowText(viewTextMenuItem.isSelected());
2293 alignPanel.paintAlignment(true);
2299 * @param e DOCUMENT ME!
2301 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2303 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2304 alignPanel.paintAlignment(true);
2308 public FeatureSettings featureSettings;
2309 public void featureSettings_actionPerformed(ActionEvent e)
2311 if(featureSettings !=null )
2313 featureSettings.close();
2314 featureSettings = null;
2316 featureSettings = new FeatureSettings(this);
2322 * @param evt DOCUMENT ME!
2324 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2326 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2327 alignPanel.paintAlignment(true);
2328 if (alignPanel.getOverviewPanel() != null)
2330 alignPanel.getOverviewPanel().updateOverviewImage();
2337 * @param e DOCUMENT ME!
2339 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2341 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2342 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2345 public void alignmentProperties()
2347 JEditorPane editPane = new JEditorPane("text/html","");
2348 editPane.setEditable(false);
2349 StringBuffer contents = new StringBuffer("<html>");
2352 int min=Integer.MAX_VALUE, max=0;
2353 for(int i=0; i<viewport.alignment.getHeight(); i++)
2355 int size = viewport.alignment.getSequenceAt(i).getEnd()
2356 -viewport.alignment.getSequenceAt(i).getStart();
2363 avg = avg/(float)viewport.alignment.getHeight();
2365 contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
2366 contents.append("<br>Minimum Sequence Length: "+min);
2367 contents.append("<br>Maximum Sequence Length: "+max);
2368 contents.append("<br>Average Length: "+(int)avg);
2370 if (((Alignment)viewport.alignment).getProperties() != null)
2372 Hashtable props = ((Alignment)viewport.alignment).getProperties();
2373 Enumeration en = props.keys();
2374 contents.append("<br><br><table border=\"1\">");
2375 while(en.hasMoreElements())
2377 String key = en.nextElement().toString();
2378 StringBuffer val = new StringBuffer();
2379 String vals = props.get(key).toString();
2382 npos = vals.indexOf("\n",pos);
2385 val.append(vals.substring(pos));
2387 val.append(vals.substring(pos, npos));
2392 contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
2394 contents.append("</table>");
2396 editPane.setText(contents.toString()+"</html>");
2397 JInternalFrame frame = new JInternalFrame();
2398 frame.getContentPane().add(new JScrollPane(editPane));
2400 Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
2407 * @param e DOCUMENT ME!
2409 public void overviewMenuItem_actionPerformed(ActionEvent e)
2411 if (alignPanel.overviewPanel != null)
2416 JInternalFrame frame = new JInternalFrame();
2417 OverviewPanel overview = new OverviewPanel(alignPanel);
2418 frame.setContentPane(overview);
2419 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2420 frame.getWidth(), frame.getHeight());
2422 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2423 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2425 public void internalFrameClosed(
2426 javax.swing.event.InternalFrameEvent evt)
2428 alignPanel.setOverviewPanel(null);
2433 alignPanel.setOverviewPanel(overview);
2436 public void textColour_actionPerformed(ActionEvent e)
2438 new TextColourChooser().chooseColour(alignPanel, null);
2444 * @param e DOCUMENT ME!
2446 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2454 * @param e DOCUMENT ME!
2456 public void clustalColour_actionPerformed(ActionEvent e)
2458 changeColour(new ClustalxColourScheme(
2459 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2465 * @param e DOCUMENT ME!
2467 public void zappoColour_actionPerformed(ActionEvent e)
2469 changeColour(new ZappoColourScheme());
2475 * @param e DOCUMENT ME!
2477 public void taylorColour_actionPerformed(ActionEvent e)
2479 changeColour(new TaylorColourScheme());
2485 * @param e DOCUMENT ME!
2487 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2489 changeColour(new HydrophobicColourScheme());
2495 * @param e DOCUMENT ME!
2497 public void helixColour_actionPerformed(ActionEvent e)
2499 changeColour(new HelixColourScheme());
2505 * @param e DOCUMENT ME!
2507 public void strandColour_actionPerformed(ActionEvent e)
2509 changeColour(new StrandColourScheme());
2515 * @param e DOCUMENT ME!
2517 public void turnColour_actionPerformed(ActionEvent e)
2519 changeColour(new TurnColourScheme());
2525 * @param e DOCUMENT ME!
2527 public void buriedColour_actionPerformed(ActionEvent e)
2529 changeColour(new BuriedColourScheme());
2535 * @param e DOCUMENT ME!
2537 public void nucleotideColour_actionPerformed(ActionEvent e)
2539 changeColour(new NucleotideColourScheme());
2542 public void annotationColour_actionPerformed(ActionEvent e)
2544 new AnnotationColourChooser(viewport, alignPanel);
2551 * @param e DOCUMENT ME!
2553 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2555 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2561 * @param cs DOCUMENT ME!
2563 public void changeColour(ColourSchemeI cs)
2569 if (viewport.getAbovePIDThreshold())
2571 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2574 cs.setThreshold(threshold,
2575 viewport.getIgnoreGapsConsensus());
2577 viewport.setGlobalColourScheme(cs);
2581 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2584 if (viewport.getConservationSelected())
2587 Alignment al = (Alignment) viewport.alignment;
2588 Conservation c = new Conservation("All",
2589 ResidueProperties.propHash, 3,
2590 al.getSequences(), 0,
2594 c.verdict(false, viewport.ConsPercGaps);
2596 cs.setConservation(c);
2598 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2603 cs.setConservation(null);
2606 cs.setConsensus(viewport.hconsensus);
2609 viewport.setGlobalColourScheme(cs);
2611 if (viewport.getColourAppliesToAllGroups())
2613 Vector groups = viewport.alignment.getGroups();
2615 for (int i = 0; i < groups.size(); i++)
2617 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2625 if (cs instanceof ClustalxColourScheme)
2627 sg.cs = new ClustalxColourScheme(
2628 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2630 else if (cs instanceof UserColourScheme)
2632 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2638 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2640 catch (Exception ex)
2645 if (viewport.getAbovePIDThreshold()
2646 || cs instanceof PIDColourScheme
2647 || cs instanceof Blosum62ColourScheme)
2649 sg.cs.setThreshold(threshold,
2650 viewport.getIgnoreGapsConsensus());
2652 sg.cs.setConsensus(AAFrequency.calculate(
2653 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2658 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2662 if (viewport.getConservationSelected())
2664 Conservation c = new Conservation("Group",
2665 ResidueProperties.propHash, 3,
2666 sg.getSequences(viewport.
2667 hiddenRepSequences),
2671 c.verdict(false, viewport.ConsPercGaps);
2672 sg.cs.setConservation(c);
2676 sg.cs.setConservation(null);
2681 if (alignPanel.getOverviewPanel() != null)
2683 alignPanel.getOverviewPanel().updateOverviewImage();
2689 alignPanel.paintAlignment(true);
2695 * @param e DOCUMENT ME!
2697 protected void modifyPID_actionPerformed(ActionEvent e)
2699 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2701 SliderPanel.setPIDSliderSource(alignPanel,
2702 viewport.getGlobalColourScheme(),
2704 SliderPanel.showPIDSlider();
2711 * @param e DOCUMENT ME!
2713 protected void modifyConservation_actionPerformed(ActionEvent e)
2715 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2717 SliderPanel.setConservationSlider(alignPanel,
2718 viewport.globalColourScheme,
2720 SliderPanel.showConservationSlider();
2727 * @param e DOCUMENT ME!
2729 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2731 viewport.setConservationSelected(conservationMenuItem.isSelected());
2733 viewport.setAbovePIDThreshold(false);
2734 abovePIDThreshold.setSelected(false);
2736 changeColour(viewport.getGlobalColourScheme());
2738 modifyConservation_actionPerformed(null);
2744 * @param e DOCUMENT ME!
2746 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2748 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2750 conservationMenuItem.setSelected(false);
2751 viewport.setConservationSelected(false);
2753 changeColour(viewport.getGlobalColourScheme());
2755 modifyPID_actionPerformed(null);
2761 * @param e DOCUMENT ME!
2763 public void userDefinedColour_actionPerformed(ActionEvent e)
2765 if (e.getActionCommand().equals("User Defined..."))
2767 new UserDefinedColours(alignPanel, null);
2771 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2772 getUserColourSchemes().get(e.getActionCommand());
2778 public void updateUserColourMenu()
2781 Component[] menuItems = colourMenu.getMenuComponents();
2782 int i, iSize = menuItems.length;
2783 for (i = 0; i < iSize; i++)
2785 if (menuItems[i].getName() != null &&
2786 menuItems[i].getName().equals("USER_DEFINED"))
2788 colourMenu.remove(menuItems[i]);
2792 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2794 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2795 getUserColourSchemes().keys();
2797 while (userColours.hasMoreElements())
2799 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2801 nextElement().toString());
2802 radioItem.setName("USER_DEFINED");
2803 radioItem.addMouseListener(new MouseAdapter()
2805 public void mousePressed(MouseEvent evt)
2807 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2809 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2811 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2813 "Remove from default list?",
2814 "Remove user defined colour",
2815 JOptionPane.YES_NO_OPTION);
2816 if(option == JOptionPane.YES_OPTION)
2818 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2819 radioItem.getText());
2820 colourMenu.remove(radioItem);
2824 radioItem.addActionListener(new ActionListener()
2826 public void actionPerformed(ActionEvent evt)
2828 userDefinedColour_actionPerformed(evt);
2835 radioItem.addActionListener(new ActionListener()
2837 public void actionPerformed(ActionEvent evt)
2839 userDefinedColour_actionPerformed(evt);
2843 colourMenu.insert(radioItem, 15);
2844 colours.add(radioItem);
2852 * @param e DOCUMENT ME!
2854 public void PIDColour_actionPerformed(ActionEvent e)
2856 changeColour(new PIDColourScheme());
2862 * @param e DOCUMENT ME!
2864 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2866 changeColour(new Blosum62ColourScheme());
2872 * @param e DOCUMENT ME!
2874 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2876 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2877 AlignmentSorter.sortByPID(viewport.getAlignment(),
2878 viewport.getAlignment().getSequenceAt(0), null);
2879 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2880 viewport.alignment));
2881 alignPanel.paintAlignment(true);
2887 * @param e DOCUMENT ME!
2889 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2891 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2892 AlignmentSorter.sortByID(viewport.getAlignment());
2893 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2894 alignPanel.paintAlignment(true);
2900 * @param e DOCUMENT ME!
2902 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2904 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2905 AlignmentSorter.sortByGroup(viewport.getAlignment());
2906 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2908 alignPanel.paintAlignment(true);
2913 * @param e DOCUMENT ME!
2915 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2917 new RedundancyPanel(alignPanel, this);
2924 * @param e DOCUMENT ME!
2926 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2928 if ( (viewport.getSelectionGroup() == null) ||
2929 (viewport.getSelectionGroup().getSize() < 2))
2931 JOptionPane.showInternalMessageDialog(this,
2932 "You must select at least 2 sequences.",
2933 "Invalid Selection",
2934 JOptionPane.WARNING_MESSAGE);
2938 JInternalFrame frame = new JInternalFrame();
2939 frame.setContentPane(new PairwiseAlignPanel(viewport));
2940 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2947 * @param e DOCUMENT ME!
2949 public void PCAMenuItem_actionPerformed(ActionEvent e)
2951 if ( ( (viewport.getSelectionGroup() != null) &&
2952 (viewport.getSelectionGroup().getSize() < 4) &&
2953 (viewport.getSelectionGroup().getSize() > 0)) ||
2954 (viewport.getAlignment().getHeight() < 4))
2956 JOptionPane.showInternalMessageDialog(this,
2957 "Principal component analysis must take\n" +
2958 "at least 4 input sequences.",
2959 "Sequence selection insufficient",
2960 JOptionPane.WARNING_MESSAGE);
2965 new PCAPanel(alignPanel);
2969 public void autoCalculate_actionPerformed(ActionEvent e)
2971 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2972 if(viewport.autoCalculateConsensus)
2974 viewport.firePropertyChange("alignment",
2976 viewport.getAlignment().getSequences());
2984 * @param e DOCUMENT ME!
2986 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2988 NewTreePanel("AV", "PID", "Average distance tree using PID");
2994 * @param e DOCUMENT ME!
2996 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2998 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3004 * @param e DOCUMENT ME!
3006 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3008 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3014 * @param e DOCUMENT ME!
3016 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3018 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3024 * @param type DOCUMENT ME!
3025 * @param pwType DOCUMENT ME!
3026 * @param title DOCUMENT ME!
3028 void NewTreePanel(String type, String pwType, String title)
3032 if (viewport.getSelectionGroup() != null)
3034 if (viewport.getSelectionGroup().getSize() < 3)
3036 JOptionPane.showMessageDialog(Desktop.desktop,
3037 "You need to have more than two sequences selected to build a tree!",
3038 "Not enough sequences",
3039 JOptionPane.WARNING_MESSAGE);
3044 SequenceGroup sg = viewport.getSelectionGroup();
3046 /* Decide if the selection is a column region */
3047 while (s < sg.getSize())
3049 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
3052 JOptionPane.showMessageDialog(Desktop.desktop,
3053 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
3054 "Try using the Pad function in the edit menu,\n" +
3055 "or one of the multiple sequence alignment web services.",
3056 "Sequences in selection are not aligned",
3057 JOptionPane.WARNING_MESSAGE);
3063 title = title + " on region";
3064 tp = new TreePanel(alignPanel, type, pwType);
3068 //are the sequences aligned?
3069 if (!viewport.alignment.isAligned())
3071 JOptionPane.showMessageDialog(Desktop.desktop,
3072 "The sequences must be aligned before creating a tree.\n" +
3073 "Try using the Pad function in the edit menu,\n" +
3074 "or one of the multiple sequence alignment web services.",
3075 "Sequences not aligned",
3076 JOptionPane.WARNING_MESSAGE);
3081 if(viewport.alignment.getHeight()<2)
3086 tp = new TreePanel(alignPanel, type, pwType);
3091 if(viewport.viewName!=null)
3093 title+= viewport.viewName+" of ";
3096 title += this.title;
3098 Desktop.addInternalFrame(tp, title, 600, 500);
3104 * @param title DOCUMENT ME!
3105 * @param order DOCUMENT ME!
3107 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
3109 final JMenuItem item = new JMenuItem("by " + title);
3111 item.addActionListener(new java.awt.event.ActionListener()
3113 public void actionPerformed(ActionEvent e)
3115 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3117 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
3118 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3120 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3121 viewport.alignment));
3123 alignPanel.paintAlignment(true);
3128 * Add a new sort by annotation score menu item
3129 * @param sort the menu to add the option to
3130 * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
3132 public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
3134 final JMenuItem item = new JMenuItem(scoreLabel);
3136 item.addActionListener(new java.awt.event.ActionListener()
3138 public void actionPerformed(ActionEvent e)
3140 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
3141 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());//,viewport.getSelectionGroup());
3142 addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
3143 alignPanel.paintAlignment(true);
3148 * last hash for alignment's annotation array - used to minimise cost of rebuild.
3150 protected int _annotationScoreVectorHash;
3152 * search the alignment and rebuild the sort by annotation score submenu
3153 * the last alignment annotation vector hash is stored to minimize
3154 * cost of rebuilding in subsequence calls.
3157 public void buildSortByAnnotationScoresMenu()
3159 if(viewport.alignment.getAlignmentAnnotation()==null)
3164 if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
3166 sortByAnnotScore.removeAll();
3167 // almost certainly a quicker way to do this - but we keep it simple
3168 Hashtable scoreSorts=new Hashtable();
3169 AlignmentAnnotation aann[];
3170 Enumeration sq = viewport.alignment.getSequences().elements();
3171 while (sq.hasMoreElements())
3173 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3174 for (int i=0;aann!=null && i<aann.length; i++)
3176 if (aann[i].hasScore() && aann[i].sequenceRef!=null)
3178 scoreSorts.put(aann[i].label, aann[i].label);
3182 Enumeration labels = scoreSorts.keys();
3183 while (labels.hasMoreElements())
3185 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
3187 sortByAnnotScore.setVisible(scoreSorts.size()>0);
3190 _annotationScoreVectorHash =
3191 viewport.alignment.getAlignmentAnnotation().hashCode();
3196 * Maintain the Order by->Displayed Tree menu.
3197 * Creates a new menu item for a TreePanel with an appropriate
3198 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
3199 * to remove the menu item when the treePanel is closed, and adjust
3200 * the tree leaf to sequence mapping when the alignment is modified.
3201 * @param treePanel Displayed tree window.
3202 * @param title SortBy menu item title.
3204 public void buildTreeMenu()
3206 sortByTreeMenu.removeAll();
3208 Vector comps = (Vector) PaintRefresher.components.get(viewport.
3209 getSequenceSetId());
3210 Vector treePanels = new Vector();
3211 int i, iSize = comps.size();
3212 for(i=0; i<iSize; i++)
3214 if(comps.elementAt(i) instanceof TreePanel)
3216 treePanels.add(comps.elementAt(i));
3220 iSize = treePanels.size();
3224 sortByTreeMenu.setVisible(false);
3228 sortByTreeMenu.setVisible(true);
3230 for(i=0; i<treePanels.size(); i++)
3232 TreePanel tp = (TreePanel)treePanels.elementAt(i);
3233 final JMenuItem item = new JMenuItem(tp.getTitle());
3234 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
3235 item.addActionListener(new java.awt.event.ActionListener()
3237 public void actionPerformed(ActionEvent e)
3239 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3240 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3242 addHistoryItem(new OrderCommand("Tree Sort",
3244 viewport.alignment));
3246 alignPanel.paintAlignment(true);
3250 sortByTreeMenu.add(item);
3255 * Work out whether the whole set of sequences
3256 * or just the selected set will be submitted for multiple alignment.
3259 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3261 // Now, check we have enough sequences
3262 AlignmentView msa = null;
3264 if ( (viewport.getSelectionGroup() != null) &&
3265 (viewport.getSelectionGroup().getSize() > 1))
3267 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
3268 /*SequenceGroup seqs = viewport.getSelectionGroup();
3270 msa = new SequenceI[sz = seqs.getSize(false)];
3272 for (int i = 0; i < sz; i++)
3274 msa[i] = (SequenceI) seqs.getSequenceAt(i);
3276 msa = viewport.getAlignmentView(true);
3280 /*Vector seqs = viewport.getAlignment().getSequences();
3282 if (seqs.size() > 1)
3284 msa = new SequenceI[seqs.size()];
3286 for (int i = 0; i < seqs.size(); i++)
3288 msa[i] = (SequenceI) seqs.elementAt(i);
3291 msa = viewport.getAlignmentView(false);
3297 * Decides what is submitted to a secondary structure prediction service:
3298 * the first sequence in the alignment, or in the current selection,
3299 * or, if the alignment is 'aligned' (ie padded with gaps), then the
3300 * currently selected region or the whole alignment.
3301 * (where the first sequence in the set is the one that the prediction
3304 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3306 AlignmentView seqs = null;
3308 if ( (viewport.getSelectionGroup() != null) &&
3309 (viewport.getSelectionGroup().getSize() > 0))
3311 seqs = viewport.getAlignmentView(true);
3315 seqs = viewport.getAlignmentView(false);
3317 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
3318 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3319 if (!viewport.alignment.isAligned())
3321 seqs.setSequences(new SeqCigar[]
3322 {seqs.getSequences()[0]});
3329 * @param e DOCUMENT ME!
3331 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3333 // Pick the tree file
3334 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3337 chooser.setFileView(new JalviewFileView());
3338 chooser.setDialogTitle("Select a newick-like tree file");
3339 chooser.setToolTipText("Load a tree file");
3341 int value = chooser.showOpenDialog(null);
3343 if (value == JalviewFileChooser.APPROVE_OPTION)
3345 String choice = chooser.getSelectedFile().getPath();
3346 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3347 jalview.io.NewickFile fin = null;
3350 fin = new jalview.io.NewickFile(choice,
3352 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3354 catch (Exception ex)
3356 JOptionPane.showMessageDialog(Desktop.desktop,
3358 "Problem reading tree file",
3359 JOptionPane.WARNING_MESSAGE);
3360 ex.printStackTrace();
3362 if (fin!=null && fin.hasWarningMessage())
3364 JOptionPane.showMessageDialog(Desktop.desktop,
3365 fin.getWarningMessage(),
3366 "Possible problem with tree file",
3367 JOptionPane.WARNING_MESSAGE);
3373 public TreePanel ShowNewickTree(NewickFile nf, String title)
3375 return ShowNewickTree(nf,title,600,500,4,5);
3378 public TreePanel ShowNewickTree(NewickFile nf, String title,
3379 AlignmentView input)
3381 return ShowNewickTree(nf,title, input, 600,500,4,5);
3384 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
3387 return ShowNewickTree(nf, title, null, w, h, x, y);
3390 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
3392 * @param nf the tree
3393 * @param title tree viewer title
3394 * @param input Associated alignment input data (or null)
3399 * @return TreePanel handle
3401 public TreePanel ShowNewickTree(NewickFile nf, String title,
3402 AlignmentView input, int w, int h, int x,
3405 TreePanel tp = null;
3411 if (nf.getTree() != null)
3413 tp = new TreePanel(alignPanel,
3422 tp.setLocation(x,y);
3426 Desktop.addInternalFrame(tp, title, w, h);
3429 catch (Exception ex)
3431 ex.printStackTrace();
3439 * Generates menu items and listener event actions for web service clients
3442 public void BuildWebServiceMenu()
3444 // TODO: add support for context dependent disabling of services based on alignment and current selection
3445 // TODO: add additional serviceHandle parameter to specify abstract handler class independently of AbstractName
3446 // TODO: add in rediscovery GUI function to restart discoverer
3447 // TODO: group services by location as well as function and/or introduce object broker mechanism.
3448 if ( (Discoverer.services != null)
3449 && (Discoverer.services.size() > 0))
3451 // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere
3452 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3453 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3454 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3455 // 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)
3456 Vector wsmenu = new Vector();
3457 final IProgressIndicator af = this;
3460 // Add any Multiple Sequence Alignment Services
3461 final JMenu msawsmenu = new JMenu("Alignment");
3462 for (int i = 0, j = msaws.size(); i < j; i++)
3464 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3466 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3467 impl.attachWSMenuEntry(msawsmenu, this);
3470 wsmenu.add(msawsmenu);
3472 if (secstrpr != null)
3474 // Add any secondary structure prediction services
3475 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3476 for (int i = 0, j = secstrpr.size(); i < j; i++)
3478 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3480 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3481 impl.attachWSMenuEntry(secstrmenu, this);
3483 wsmenu.add(secstrmenu);
3487 // Add any sequence search services
3488 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3489 for (int i = 0, j = seqsrch.size(); i < j; i++)
3491 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3492 seqsrch.elementAt(i);
3493 jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
3494 impl.attachWSMenuEntry(seqsrchmenu, this);
3496 // finally, add the whole shebang onto the webservices menu
3497 wsmenu.add(seqsrchmenu);
3499 resetWebServiceMenu();
3500 for (int i = 0, j = wsmenu.size(); i < j; i++)
3502 webService.add( (JMenu) wsmenu.get(i));
3507 resetWebServiceMenu();
3508 this.webService.add(this.webServiceNoServices);
3514 * empty the web service menu and add any ad-hoc functions
3515 * not dynamically discovered.
3518 private void resetWebServiceMenu()
3520 webService.removeAll();
3521 // Temporary hack - DBRef Fetcher always top level ws entry.
3522 JMenuItem rfetch = new JMenuItem("Fetch DB References");
3523 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
3524 webService.add(rfetch);
3525 rfetch.addActionListener(new ActionListener() {
3527 public void actionPerformed(ActionEvent e)
3529 new Thread(new Runnable() {
3533 new jalview.ws.DBRefFetcher(
3534 alignPanel.av.getSequenceSelection(),
3535 alignPanel.alignFrame).fetchDBRefs(false);
3544 /* public void vamsasStore_actionPerformed(ActionEvent e)
3546 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3547 getProperty("LAST_DIRECTORY"));
3549 chooser.setFileView(new JalviewFileView());
3550 chooser.setDialogTitle("Export to Vamsas file");
3551 chooser.setToolTipText("Export");
3553 int value = chooser.showSaveDialog(this);
3555 if (value == JalviewFileChooser.APPROVE_OPTION)
3557 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3558 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3559 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3563 * prototype of an automatically enabled/disabled analysis function
3566 protected void setShowProductsEnabled()
3568 SequenceI [] selection = viewport.getSequenceSelection();
3569 if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset()))
3571 showProducts.setEnabled(true);
3574 showProducts.setEnabled(false);
3578 * search selection for sequence xRef products and build the
3579 * show products menu.
3582 * @return true if showProducts menu should be enabled.
3584 public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset)
3586 boolean showp=false;
3588 showProducts.removeAll();
3589 final boolean dna = viewport.getAlignment().isNucleotide();
3590 final Alignment ds = dataset;
3591 String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset);
3592 //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true);
3593 final SequenceI[] sel = selection;
3594 for (int t=0; ptypes!=null && t<ptypes.length; t++)
3597 final boolean isRegSel = isRegionSelection;
3598 final AlignFrame af = this;
3599 final String source = ptypes[t];
3600 JMenuItem xtype = new JMenuItem(ptypes[t]);
3601 xtype.addActionListener(new ActionListener() {
3603 public void actionPerformed(ActionEvent e)
3605 // TODO: new thread for this call with vis-delay
3606 af.showProductsFor(af.viewport.getSequenceSelection(), ds, isRegSel, dna, source);
3610 showProducts.add(xtype);
3612 showProducts.setVisible(showp);
3613 showProducts.setEnabled(showp);
3614 } catch (Exception e)
3616 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3621 protected void showProductsFor(SequenceI[] sel, Alignment ds, boolean isRegSel, boolean dna, String source)
3623 final boolean fisRegSel = isRegSel;
3624 final boolean fdna = dna;
3625 final String fsrc = source;
3626 final AlignFrame ths = this;
3627 final SequenceI[] fsel = sel;
3628 Runnable foo = new Runnable() {
3632 final long sttime = System.currentTimeMillis();
3633 ths.setProgressBar("Searching for sequences from "+fsrc, sttime);
3635 Alignment ds = ths.getViewport().alignment.getDataset(); // update our local dataset reference
3636 Alignment prods = CrossRef.findXrefSequences(fsel, fdna, fsrc, ds);
3639 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3640 for (int s=0; s<sprods.length;s++)
3642 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3643 if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
3644 ds.addSequence(sprods[s].getDatasetSequence());
3645 sprods[s].updatePDBIds();
3647 Alignment al = new Alignment(sprods);
3648 AlignedCodonFrame[] cf = prods.getCodonFrames();
3649 for (int s=0; cf!=null && s<cf.length; s++)
3651 al.addCodonFrame(cf[s]);
3655 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3656 String newtitle =""+((fdna) ? "Proteins " : "Nucleotides ") + " for "+((fisRegSel) ? "selected region of " : "")
3658 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3661 System.err.println("No Sequences generated for xRef type "+fsrc);
3666 jalview.bin.Cache.log.error("Exception when finding crossreferences",e);
3668 catch (OutOfMemoryError e) {
3669 new OOMWarning("whilst fetching crossreferences", e);
3673 jalview.bin.Cache.log.error("Error when finding crossreferences",e);
3675 ths.setProgressBar("Finished searching for sequences from "+fsrc, sttime);
3679 Thread frunner = new Thread(foo);
3684 public boolean canShowTranslationProducts(SequenceI[] selection, AlignmentI alignment)
3688 return (jalview.analysis.Dna.canTranslate(selection, viewport.getViewAsVisibleContigs(true)));
3689 } catch (Exception e)
3691 jalview.bin.Cache.log.warn("canTranslate threw an exception - please report to help@jalview.org",e);
3696 public void showProducts_actionPerformed(ActionEvent e)
3698 ///////////////////////////////
3699 // Collect Data to be translated/transferred
3701 SequenceI [] selection = viewport.getSequenceSelection();
3702 AlignmentI al = null;
3704 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport.getViewAsVisibleContigs(true),
3705 viewport.getGapCharacter(), viewport.getAlignment().getDataset());
3706 } catch (Exception ex) {
3708 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3712 JOptionPane.showMessageDialog(Desktop.desktop,
3713 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3714 "Translation Failed",
3715 JOptionPane.WARNING_MESSAGE);
3717 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3718 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3724 public void showTranslation_actionPerformed(ActionEvent e)
3726 ///////////////////////////////
3727 // Collect Data to be translated/transferred
3729 SequenceI [] selection = viewport.getSequenceSelection();
3730 String [] seqstring = viewport.getViewAsString(true);
3731 AlignmentI al = null;
3733 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
3734 viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
3735 viewport.alignment.getWidth(), viewport.getAlignment().getDataset());
3736 } catch (Exception ex) {
3738 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3742 JOptionPane.showMessageDialog(Desktop.desktop,
3743 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3744 "Translation Failed",
3745 JOptionPane.WARNING_MESSAGE);
3747 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3748 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3755 * Try to load a features file onto the alignment.
3756 * @param file contents or path to retrieve file
3757 * @param type access mode of file (see jalview.io.AlignFile)
3758 * @return true if features file was parsed corectly.
3760 public boolean parseFeaturesFile(String file, String type)
3762 boolean featuresFile = false;
3765 featuresFile = new FeaturesFile(file,
3766 type).parse(viewport.alignment.getDataset(),
3767 alignPanel.seqPanel.seqCanvas.
3768 getFeatureRenderer().featureColours,
3773 ex.printStackTrace();
3778 viewport.showSequenceFeatures = true;
3779 showSeqFeatures.setSelected(true);
3780 alignPanel.paintAlignment(true);
3783 return featuresFile;
3786 public void dragEnter(DropTargetDragEvent evt)
3789 public void dragExit(DropTargetEvent evt)
3792 public void dragOver(DropTargetDragEvent evt)
3795 public void dropActionChanged(DropTargetDragEvent evt)
3798 public void drop(DropTargetDropEvent evt)
3800 Transferable t = evt.getTransferable();
3801 java.util.List files = null;
3805 DataFlavor uriListFlavor = new DataFlavor(
3806 "text/uri-list;class=java.lang.String");
3807 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3809 //Works on Windows and MacOSX
3810 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3811 files = (java.util.List) t.getTransferData(DataFlavor.
3812 javaFileListFlavor);
3814 else if (t.isDataFlavorSupported(uriListFlavor))
3816 // This is used by Unix drag system
3817 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3818 String data = (String) t.getTransferData(uriListFlavor);
3819 files = new java.util.ArrayList(1);
3820 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3823 st.hasMoreTokens(); )
3825 String s = st.nextToken();
3826 if (s.startsWith("#"))
3828 // the line is a comment (as per the RFC 2483)
3832 java.net.URI uri = new java.net.URI(s);
3833 java.io.File file = new java.io.File(uri);
3840 e.printStackTrace();
3847 for (int i = 0; i < files.size(); i++)
3849 loadJalviewDataFile(files.get(i).toString());
3852 catch (Exception ex)
3854 ex.printStackTrace();
3860 * Attempt to load a "dropped" file: First by testing
3861 * whether it's and Annotation file, then a JNet file, and finally a features file. If all are
3862 * false then the user may have dropped an alignment file onto this
3864 * @param file either a filename or a URL string.
3866 public void loadJalviewDataFile(String file)
3870 String protocol = "File";
3872 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3877 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3878 alignment, file, protocol);
3882 // try to see if its a JNet 'concise' style annotation file *before* we try to parse it as a features file
3883 String format = new IdentifyFile().Identify(file, protocol);
3884 if(format.equalsIgnoreCase("JnetFile"))
3886 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3888 new JnetAnnotationMaker().add_annotation(predictions,
3889 viewport.getAlignment(),
3895 // try to parse it as a features file
3896 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3897 // if it wasn't a features file then we just treat it as a general alignment file to load into the current view.
3900 new FileLoader().LoadFile(viewport, file, protocol, format);
3902 alignPanel.paintAlignment(true);
3909 alignPanel.adjustAnnotationHeight();
3910 viewport.updateSequenceIdColours();
3911 buildSortByAnnotationScoresMenu();
3912 alignPanel.paintAlignment(true);
3915 catch (Exception ex)
3917 ex.printStackTrace();
3921 public void tabSelectionChanged(int index)
3925 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3926 viewport = alignPanel.av;
3927 setMenusFromViewport(viewport);
3931 public void tabbedPane_mousePressed(MouseEvent e)
3933 if(SwingUtilities.isRightMouseButton(e))
3935 String reply = JOptionPane.showInternalInputDialog(this,
3938 JOptionPane.QUESTION_MESSAGE);
3942 viewport.viewName = reply;
3943 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3949 public AlignViewport getCurrentView()
3956 * Open the dialog for regex description parsing.
3958 protected void extractScores_actionPerformed(ActionEvent e)
3960 ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
3961 // TODO: verify regex and introduce GUI dialog for version 2.5
3962 //if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0)
3963 if (pp.getScoresFromDescription("description column", "score in description column ", "\\W*([-+eE0-9.]+)", true)>0) {
3964 buildSortByAnnotationScoresMenu();
3973 public PrintThread(AlignmentPanel ap)
3977 static PageFormat pf;
3980 PrinterJob printJob = PrinterJob.getPrinterJob();
3984 printJob.setPrintable(ap, pf);
3988 printJob.setPrintable(ap);
3991 if (printJob.printDialog())
3997 catch (Exception PrintException)
3999 PrintException.printStackTrace();