2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Softwarechang
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import java.awt.datatransfer.*;
27 import java.awt.event.*;
28 import java.awt.print.*;
31 import jalview.analysis.*;
32 import jalview.datamodel.*;
34 import jalview.jbgui.*;
35 import jalview.schemes.*;
36 import jalview.commands.*;
38 import java.awt.dnd.*;
39 import javax.swing.event.ChangeListener;
40 import javax.swing.event.ChangeEvent;
48 public class AlignFrame extends GAlignFrame implements DropTargetListener
51 public static final int DEFAULT_WIDTH = 700;
54 public static final int DEFAULT_HEIGHT = 500;
55 public AlignmentPanel alignPanel;
57 AlignViewport viewport;
59 Vector alignPanels = new Vector();
63 String currentFileFormat = null;
65 String fileName = null;
69 * Creates a new AlignFrame object.
71 * @param al DOCUMENT ME!
73 public AlignFrame(AlignmentI al, int width, int height)
75 this(al, null, width, height);
80 * new alignment window with hidden columns
81 * @param al AlignmentI
82 * @param hiddenColumns ColumnSelection or null
84 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
85 int width, int height)
87 this.setSize(width, height);
88 viewport = new AlignViewport(al, hiddenColumns);
90 alignPanel = new AlignmentPanel(this, viewport);
92 if(al.getDataset()==null)
97 addAlignmentPanel(alignPanel, true);
102 * Make a new AlignFrame from exisiting alignmentPanels
103 * @param ap AlignmentPanel
104 * @param av AlignViewport
106 public AlignFrame(AlignmentPanel ap)
110 addAlignmentPanel(ap, false);
116 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
118 if (viewport.conservation == null)
120 BLOSUM62Colour.setEnabled(false);
121 conservationMenuItem.setEnabled(false);
122 modifyConservation.setEnabled(false);
123 // PIDColour.setEnabled(false);
124 // abovePIDThreshold.setEnabled(false);
125 // modifyPID.setEnabled(false);
128 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
130 if (sortby.equals("Id"))
131 sortIDMenuItem_actionPerformed(null);
132 else if (sortby.equals("Pairwise Identity"))
133 sortPairwiseMenuItem_actionPerformed(null);
135 if (Desktop.desktop != null)
137 addServiceListeners();
138 setGUINucleotide(viewport.alignment.isNucleotide());
141 setMenusFromViewport(viewport);
143 if (viewport.wrapAlignment)
145 wrapMenuItem_actionPerformed(null);
152 public void setFileName(String file, String format)
155 currentFileFormat = format;
156 reload.setEnabled(true);
159 void addKeyListener()
161 addKeyListener(new KeyAdapter()
163 public void keyPressed(KeyEvent evt)
165 if (viewport.cursorMode
166 && evt.getKeyCode() >= KeyEvent.VK_0
167 && evt.getKeyCode() <= KeyEvent.VK_9)
169 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
172 switch (evt.getKeyCode())
175 case 27: // escape key
176 deselectAllSequenceMenuItem_actionPerformed(null);
180 case KeyEvent.VK_DOWN:
181 if (viewport.cursorMode)
183 alignPanel.seqPanel.moveCursor(0, 1);
186 moveSelectedSequences(false);
190 if (viewport.cursorMode)
192 alignPanel.seqPanel.moveCursor(0, -1);
195 moveSelectedSequences(true);
198 case KeyEvent.VK_LEFT:
199 if (viewport.cursorMode)
201 alignPanel.seqPanel.moveCursor( -1, 0);
205 case KeyEvent.VK_RIGHT:
206 if (viewport.cursorMode)
208 alignPanel.seqPanel.moveCursor(1, 0);
212 case KeyEvent.VK_SPACE:
213 if (viewport.cursorMode)
215 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
221 case KeyEvent.VK_DELETE:
222 case KeyEvent.VK_BACK_SPACE:
223 if (!viewport.cursorMode)
225 cut_actionPerformed(null);
228 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
235 if (viewport.cursorMode)
237 alignPanel.seqPanel.setCursorRow();
241 if (viewport.cursorMode && !evt.isControlDown())
243 alignPanel.seqPanel.setCursorColumn();
247 if (viewport.cursorMode)
249 alignPanel.seqPanel.setCursorPosition();
253 case KeyEvent.VK_ENTER:
254 case KeyEvent.VK_COMMA:
255 if (viewport.cursorMode)
257 alignPanel.seqPanel.setCursorRowAndColumn();
262 if (viewport.cursorMode)
264 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
268 if (viewport.cursorMode)
270 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
275 viewport.cursorMode = !viewport.cursorMode;
276 statusBar.setText("Keyboard editing mode is " +
277 (viewport.cursorMode ? "on" : "off"));
278 if (viewport.cursorMode)
280 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
281 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
283 alignPanel.seqPanel.seqCanvas.repaint();
289 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
290 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
291 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
293 javax.help.HelpBroker hb = hs.createHelpBroker();
294 hb.setCurrentID("home");
295 hb.setDisplayed(true);
299 ex.printStackTrace();
305 boolean toggleSeqs = !evt.isControlDown();
306 boolean toggleCols = !evt.isShiftDown();
308 boolean hide = false;
310 SequenceGroup sg = viewport.getSelectionGroup();
313 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
315 hideSelSequences_actionPerformed(null);
318 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
319 showAllSeqs_actionPerformed(null);
324 if (viewport.colSel.getSelected().size() > 0)
326 hideSelColumns_actionPerformed(null);
328 viewport.selectionGroup = sg;
331 showAllColumns_actionPerformed(null);
335 case KeyEvent.VK_PAGE_UP:
336 if (viewport.wrapAlignment)
337 alignPanel.scrollUp(true);
339 alignPanel.setScrollValues(viewport.startRes,
341 - viewport.endSeq + viewport.startSeq);
343 case KeyEvent.VK_PAGE_DOWN:
344 if (viewport.wrapAlignment)
345 alignPanel.scrollUp(false);
347 alignPanel.setScrollValues(viewport.startRes,
349 + viewport.endSeq - viewport.startSeq);
357 public void addAlignmentPanel(final AlignmentPanel ap,
360 ap.alignFrame = this;
362 alignPanels.addElement(ap);
364 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
366 int aSize = alignPanels.size();
368 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
370 if (aSize == 1 && ap.av.viewName==null)
372 this.getContentPane().add(ap, BorderLayout.CENTER);
378 setInitialTabVisible();
381 expandViews.setEnabled(true);
382 gatherViews.setEnabled(true);
383 tabbedPane.addTab(ap.av.viewName, ap);
385 ap.setVisible(false);
391 ap.av.alignment.padGaps();
392 ap.av.updateConservation(ap);
393 ap.av.updateConsensus(ap);
397 public void setInitialTabVisible()
399 expandViews.setEnabled(true);
400 gatherViews.setEnabled(true);
401 tabbedPane.setVisible(true);
402 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
403 tabbedPane.addTab(first.av.viewName,first);
404 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
408 public AlignViewport getViewport()
413 /* Set up intrinsic listeners for dynamically generated GUI bits. */
414 private void addServiceListeners()
416 final java.beans.PropertyChangeListener thisListener;
417 // Do this once to get current state
418 BuildWebServiceMenu();
419 Desktop.discoverer.addPropertyChangeListener(
420 thisListener = new java.beans.PropertyChangeListener()
422 public void propertyChange(PropertyChangeEvent evt)
424 // System.out.println("Discoverer property change.");
425 if (evt.getPropertyName().equals("services"))
427 // System.out.println("Rebuilding web service menu");
428 BuildWebServiceMenu();
433 addInternalFrameListener(new javax.swing.event.
434 InternalFrameAdapter()
436 public void internalFrameClosed(
437 javax.swing.event.InternalFrameEvent evt)
439 // System.out.println("deregistering discoverer listener");
440 Desktop.discoverer.removePropertyChangeListener(thisListener);
441 closeMenuItem_actionPerformed(true);
447 public void setGUINucleotide(boolean nucleotide)
449 showTranslation.setVisible( nucleotide );
450 conservationMenuItem.setEnabled( !nucleotide );
451 modifyConservation.setEnabled( !nucleotide );
453 //Remember AlignFrame always starts as protein
456 calculateMenu.remove(calculateMenu.getItemCount()-2);
461 * Need to call this method when tabs are selected for multiple views,
462 * or when loading from Jalview2XML.java
463 * @param av AlignViewport
465 void setMenusFromViewport(AlignViewport av)
467 padGapsMenuitem.setSelected(av.padGaps);
468 colourTextMenuItem.setSelected(av.showColourText);
469 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
470 conservationMenuItem.setSelected(av.getConservationSelected());
471 seqLimits.setSelected(av.getShowJVSuffix());
472 idRightAlign.setSelected(av.rightAlignIds);
473 renderGapsMenuItem.setSelected(av.renderGaps);
474 wrapMenuItem.setSelected(av.wrapAlignment);
475 annotationPanelMenuItem.setState(av.showAnnotation);
476 viewBoxesMenuItem.setSelected(av.showBoxes);
477 viewTextMenuItem.setSelected(av.showText);
479 setColourSelected(ColourSchemeProperty.
480 getColourName(av.getGlobalColourScheme()));
482 showSeqFeatures.setSelected(av.showSequenceFeatures);
483 hiddenMarkers.setState(av.showHiddenMarkers);
484 applyToAllGroups.setState(av.colourAppliesToAllGroups);
490 Hashtable progressBars;
491 public void setProgressBar(String message, long id)
493 if(progressBars == null)
494 progressBars = new Hashtable();
496 JPanel progressPanel;
497 GridLayout layout = (GridLayout) statusPanel.getLayout();
498 if(progressBars.get( new Long(id) )!=null)
500 progressPanel = (JPanel)progressBars.get( new Long(id) );
501 statusPanel.remove(progressPanel);
502 progressBars.remove( progressPanel );
503 progressPanel = null;
505 statusBar.setText(message);
507 layout.setRows(layout.getRows() - 1);
511 progressPanel = new JPanel(new BorderLayout(10, 5));
513 JProgressBar progressBar = new JProgressBar();
514 progressBar.setIndeterminate(true);
516 progressPanel.add(new JLabel(message), BorderLayout.WEST);
517 progressPanel.add(progressBar, BorderLayout.CENTER);
519 layout.setRows(layout.getRows() + 1);
520 statusPanel.add(progressPanel);
522 progressBars.put(new Long(id), progressPanel);
532 Added so Castor Mapping file can obtain Jalview Version
534 public String getVersion()
536 return jalview.bin.Cache.getProperty("VERSION");
539 public FeatureRenderer getFeatureRenderer()
541 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
545 public void fetchSequence_actionPerformed(ActionEvent e)
547 new SequenceFetcher(this);
550 public void addFromFile_actionPerformed(ActionEvent e)
552 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
555 public void reload_actionPerformed(ActionEvent e)
559 if(currentFileFormat.equals("Jalview"))
561 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
562 for(int i=0; i<frames.length; i++)
564 if (frames[i] instanceof AlignFrame
566 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
569 frames[i].setSelected(true);
570 Desktop.instance.closeAssociatedWindows();
571 }catch(java.beans.PropertyVetoException ex){}
575 Desktop.instance.closeAssociatedWindows();
580 viewport.alignment.deleteAllGroups();
581 viewport.sequenceColours=null;
582 while (viewport.alignment.getHeight() > 0)
584 viewport.alignment.deleteSequence(0);
587 viewport.historyList.clear();
588 viewport.redoList.clear();
589 Alignment dset = viewport.alignment.getDataset();
590 while (dset.getHeight() > 0)
592 dset.deleteSequence(0);
595 firePropertyChange("Alignment", null, viewport.alignment.getSequences());
600 FileLoader loader = new FileLoader();
601 String protocol = fileName.startsWith("http:")? "URL":"File";
602 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
608 public void addFromText_actionPerformed(ActionEvent e)
610 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
613 public void addFromURL_actionPerformed(ActionEvent e)
615 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
619 public void save_actionPerformed(ActionEvent e)
622 || currentFileFormat==null
623 || fileName.startsWith("http")
625 saveAs_actionPerformed(null);
627 saveAlignment(fileName, currentFileFormat);
633 * @param e DOCUMENT ME!
635 public void saveAs_actionPerformed(ActionEvent e)
637 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
638 getProperty( "LAST_DIRECTORY"),
640 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
642 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
647 chooser.setFileView(new JalviewFileView());
648 chooser.setDialogTitle("Save Alignment to file");
649 chooser.setToolTipText("Save");
651 int value = chooser.showSaveDialog(this);
653 if (value == JalviewFileChooser.APPROVE_OPTION)
655 currentFileFormat = chooser.getSelectedFormat();
656 if (currentFileFormat == null)
658 JOptionPane.showInternalMessageDialog(Desktop.desktop,
659 "You must select a file format before saving!",
660 "File format not specified",
661 JOptionPane.WARNING_MESSAGE);
662 value = chooser.showSaveDialog(this);
666 fileName = chooser.getSelectedFile().getPath();
668 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
671 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
673 saveAlignment(fileName, currentFileFormat);
677 public boolean saveAlignment(String file, String format)
679 boolean success = true;
681 if (format.equalsIgnoreCase("Jalview"))
683 String shortName = title;
685 if (shortName.indexOf(java.io.File.separatorChar) > -1)
687 shortName = shortName.substring(shortName.lastIndexOf(
688 java.io.File.separatorChar) + 1);
691 success = new Jalview2XML().SaveAlignment(this, file, shortName);
693 statusBar.setText("Successfully saved to file: "
695 +format +" format.");
701 String[] omitHidden = null;
703 if (viewport.hasHiddenColumns)
705 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
706 "The Alignment contains hidden columns."
707 + "\nDo you want to save only the visible alignment?",
708 "Save / Omit Hidden Columns",
709 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
711 if (reply == JOptionPane.YES_OPTION)
712 omitHidden = viewport.getViewAsString(false);
715 String output = new FormatAdapter().formatSequences(
717 viewport.alignment.getSequencesArray(),
728 java.io.PrintWriter out = new java.io.PrintWriter(
729 new java.io.FileWriter(file));
734 statusBar.setText("Successfully saved to file: "
736 + format + " format.");
741 ex.printStackTrace();
747 JOptionPane.showInternalMessageDialog(
748 this, "Couldn't save file: " + fileName,
750 JOptionPane.WARNING_MESSAGE);
758 * @param e DOCUMENT ME!
760 protected void outputText_actionPerformed(ActionEvent e)
762 String [] omitHidden = null;
764 if(viewport.hasHiddenColumns)
766 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
767 "The Alignment contains hidden columns."
768 +"\nDo you want to output only the visible alignment?",
769 "Save / Omit Hidden Columns",
770 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
772 if(reply==JOptionPane.YES_OPTION)
774 omitHidden = viewport.getViewAsString(false);
778 CutAndPasteTransfer cap = new CutAndPasteTransfer();
779 cap.setForInput(null);
780 Desktop.addInternalFrame(cap,
781 "Alignment output - " + e.getActionCommand(), 600,
785 cap.setText(new FormatAdapter().formatSequences(
786 e.getActionCommand(),
787 viewport.alignment.getSequencesArray(),
794 * @param e DOCUMENT ME!
796 protected void htmlMenuItem_actionPerformed(ActionEvent e)
798 new HTMLOutput(viewport,
799 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
800 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
803 public void createImageMap(File file, String image)
805 alignPanel.makePNGImageMap(file, image);
811 * @param e DOCUMENT ME!
813 public void createPNG(File f)
815 alignPanel.makePNG(f);
821 * @param e DOCUMENT ME!
823 public void createEPS(File f)
825 alignPanel.makeEPS(f);
829 public void pageSetup_actionPerformed(ActionEvent e)
831 PrinterJob printJob = PrinterJob.getPrinterJob();
832 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
838 * @param e DOCUMENT ME!
840 public void printMenuItem_actionPerformed(ActionEvent e)
842 //Putting in a thread avoids Swing painting problems
843 PrintThread thread = new PrintThread(alignPanel);
847 public void exportFeatures_actionPerformed(ActionEvent e)
849 new AnnotationExporter().exportFeatures(alignPanel);
853 public void exportAnnotations_actionPerformed(ActionEvent e)
855 new AnnotationExporter().exportAnnotations(
857 viewport.alignment.getAlignmentAnnotation()
862 public void associatedData_actionPerformed(ActionEvent e)
864 // Pick the tree file
865 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
868 chooser.setFileView(new JalviewFileView());
869 chooser.setDialogTitle("Load Jalview Annotations or Features File");
870 chooser.setToolTipText("Load Jalview Annotations / Features file");
872 int value = chooser.showOpenDialog(null);
874 if (value == JalviewFileChooser.APPROVE_OPTION)
876 String choice = chooser.getSelectedFile().getPath();
877 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
878 loadJalviewDataFile(choice);
887 * @param e DOCUMENT ME!
889 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
891 if(alignPanels!=null && alignPanels.size()<2)
896 if(alignPanels!=null)
899 for (int i = 0; i < alignPanels.size(); i++)
901 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
902 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
903 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
904 PaintRefresher.RemoveComponent(ap);
908 int index = tabbedPane.getSelectedIndex();
910 alignPanels.removeElement(alignPanel);
911 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
912 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
913 PaintRefresher.RemoveComponent(alignPanel);
917 tabbedPane.removeTabAt(index);
918 tabbedPane.validate();
920 if(index==tabbedPane.getTabCount())
923 this.tabSelectionChanged(index);
928 this.setClosed(true);
932 ex.printStackTrace();
940 void updateEditMenuBar()
943 if (viewport.historyList.size() > 0)
945 undoMenuItem.setEnabled(true);
946 CommandI command = (CommandI) viewport.historyList.peek();
947 undoMenuItem.setText("Undo " + command.getDescription());
951 undoMenuItem.setEnabled(false);
952 undoMenuItem.setText("Undo");
955 if (viewport.redoList.size() > 0)
957 redoMenuItem.setEnabled(true);
959 CommandI command = (CommandI) viewport.redoList.peek();
960 redoMenuItem.setText("Redo " + command.getDescription());
964 redoMenuItem.setEnabled(false);
965 redoMenuItem.setText("Redo");
970 public void addHistoryItem(CommandI command)
972 if(command.getSize()>0)
974 viewport.historyList.push(command);
975 viewport.redoList.clear();
977 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
986 * @param e DOCUMENT ME!
988 protected void undoMenuItem_actionPerformed(ActionEvent e)
990 CommandI command = (CommandI)viewport.historyList.pop();
991 viewport.redoList.push(command);
992 command.undoCommand();
994 AlignViewport originalSource = getOriginatingSource(command);
997 if(originalSource!=null)
999 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1000 originalSource.firePropertyChange("alignment",
1002 originalSource.alignment.getSequences());
1009 * @param e DOCUMENT ME!
1011 protected void redoMenuItem_actionPerformed(ActionEvent e)
1013 if(viewport.redoList.size()<1)
1016 CommandI command = (CommandI) viewport.redoList.pop();
1017 viewport.historyList.push(command);
1018 command.doCommand();
1020 AlignViewport originalSource = getOriginatingSource(command);
1021 updateEditMenuBar();
1023 if(originalSource!=null)
1025 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1026 originalSource.firePropertyChange("alignment",
1028 originalSource.alignment.getSequences());
1032 AlignViewport getOriginatingSource(CommandI command)
1034 AlignViewport originalSource = null;
1035 //For sequence removal and addition, we need to fire
1036 //the property change event FROM the viewport where the
1037 //original alignment was altered
1039 if (command instanceof EditCommand)
1041 EditCommand editCommand = (EditCommand) command;
1042 al = editCommand.getAlignment();
1043 Vector comps = (Vector) PaintRefresher.components
1044 .get(viewport.getSequenceSetId());
1046 for (int i = 0; i < comps.size(); i++)
1048 if (comps.elementAt(i) instanceof AlignmentPanel)
1050 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1052 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1059 if (originalSource == null)
1061 //The original view is closed, we must validate
1062 //the current view against the closed view first
1064 PaintRefresher.validateSequences(al, viewport.alignment);
1066 originalSource = viewport;
1069 return originalSource;
1075 * @param up DOCUMENT ME!
1077 public void moveSelectedSequences(boolean up)
1079 SequenceGroup sg = viewport.getSelectionGroup();
1088 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1090 SequenceI seq = viewport.alignment.getSequenceAt(i);
1092 if (!sg.getSequences(null).contains(seq))
1097 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1099 if (sg.getSequences(null).contains(temp))
1104 viewport.alignment.getSequences().setElementAt(temp, i);
1105 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1110 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1112 SequenceI seq = viewport.alignment.getSequenceAt(i);
1114 if (!sg.getSequences(null).contains(seq))
1119 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1121 if (sg.getSequences(null).contains(temp))
1126 viewport.alignment.getSequences().setElementAt(temp, i);
1127 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1131 alignPanel.repaint();
1139 * @param e DOCUMENT ME!
1141 protected void copy_actionPerformed(ActionEvent e)
1144 if (viewport.getSelectionGroup() == null)
1149 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1150 String[] omitHidden = null;
1152 if (viewport.hasHiddenColumns)
1154 omitHidden = viewport.getViewAsString(true);
1157 String output = new FormatAdapter().formatSequences(
1162 StringSelection ss = new StringSelection(output);
1166 jalview.gui.Desktop.internalCopy = true;
1167 //Its really worth setting the clipboard contents
1168 //to empty before setting the large StringSelection!!
1169 Toolkit.getDefaultToolkit().getSystemClipboard()
1170 .setContents(new StringSelection(""), null);
1172 Toolkit.getDefaultToolkit().getSystemClipboard()
1173 .setContents(ss, Desktop.instance);
1175 catch (OutOfMemoryError er)
1177 er.printStackTrace();
1178 javax.swing.SwingUtilities.invokeLater(new Runnable()
1182 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1183 "Out of memory copying region!!"
1185 "\nSee help files for increasing Java Virtual Machine memory."
1187 javax.swing.JOptionPane.WARNING_MESSAGE);
1194 Vector hiddenColumns = null;
1195 if(viewport.hasHiddenColumns)
1197 hiddenColumns =new Vector();
1198 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1199 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1201 int[] region = (int[])
1202 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1204 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1205 region[1]-hiddenOffset});
1211 Desktop.jalviewClipboard = new Object[]{ seqs,
1212 viewport.alignment.getDataset(),
1214 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1220 * @param e DOCUMENT ME!
1222 protected void pasteNew_actionPerformed(ActionEvent e)
1230 * @param e DOCUMENT ME!
1232 protected void pasteThis_actionPerformed(ActionEvent e)
1240 * @param newAlignment DOCUMENT ME!
1242 void paste(boolean newAlignment)
1246 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1247 Transferable contents = c.getContents(this);
1249 if (contents == null)
1257 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1258 if (str.length() < 1)
1261 format = new IdentifyFile().Identify(str, "Paste");
1264 catch (OutOfMemoryError er)
1266 er.printStackTrace();
1267 javax.swing.SwingUtilities.invokeLater(new Runnable()
1271 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1272 "Out of memory pasting sequences!!"
1274 "\nSee help files for increasing Java Virtual Machine memory."
1276 javax.swing.JOptionPane.WARNING_MESSAGE);
1283 SequenceI[] sequences;
1286 if(Desktop.jalviewClipboard!=null)
1288 // The clipboard was filled from within Jalview, we must use the sequences
1289 // And dataset from the copied alignment
1290 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1294 sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray();
1297 AlignmentI alignment = null;
1301 alignment = new Alignment(sequences);
1303 if (Desktop.jalviewClipboard != null)
1304 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1306 alignment.setDataset(null);
1310 alignment = viewport.getAlignment();
1313 SequenceI [] newseqs = new SequenceI[sequences.length];
1314 for (int i = 0; i < sequences.length; i++)
1316 newseqs[i] = new Sequence(sequences[i].getName(),
1317 sequences[i].getSequence(), sequences[i].getStart(),
1318 sequences[i].getEnd());
1320 alignment.addSequence(newseqs[i]);
1326 addHistoryItem(new EditCommand(
1331 alignment.getWidth(),
1336 viewport.setEndSeq(alignment.getHeight());
1337 alignment.getWidth();
1338 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1343 // Add any annotations attached to sequences
1344 for (int i = 0; i < sequences.length; i++)
1346 if (sequences[i].getAnnotation() != null)
1348 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1350 AlignmentAnnotation newAnnot =
1351 new AlignmentAnnotation(
1352 sequences[i].getAnnotation()[a].label,
1353 sequences[i].getAnnotation()[a].description,
1354 sequences[i].getAnnotation()[a].annotations,
1355 sequences[i].getAnnotation()[a].graphMin,
1356 sequences[i].getAnnotation()[a].graphMax,
1357 sequences[i].getAnnotation()[a].graph);
1359 sequences[i].getAnnotation()[a] = newAnnot;
1360 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1362 newAnnot.sequenceRef = sequences[i];
1363 newAnnot.adjustForAlignment();
1364 alignment.addAnnotation(newAnnot);
1365 alignment.setAnnotationIndex(newAnnot, a);
1368 alignPanel.annotationPanel.adjustPanelHeight();
1374 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1375 String newtitle = new String("Copied sequences");
1377 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1379 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1380 for(int i=0; i<hc.size(); i++)
1382 int [] region = (int[]) hc.elementAt(i);
1383 af.viewport.hideColumns(region[0], region[1]);
1388 //>>>This is a fix for the moment, until a better solution is found!!<<<
1389 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1390 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1393 if (title.startsWith("Copied sequences"))
1399 newtitle = newtitle.concat("- from " + title);
1402 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1409 catch (Exception ex)
1411 ex.printStackTrace();
1412 System.out.println("Exception whilst pasting: "+ex);
1413 // could be anything being pasted in here
1422 * @param e DOCUMENT ME!
1424 protected void cut_actionPerformed(ActionEvent e)
1426 copy_actionPerformed(null);
1427 delete_actionPerformed(null);
1433 * @param e DOCUMENT ME!
1435 protected void delete_actionPerformed(ActionEvent evt)
1438 SequenceGroup sg = viewport.getSelectionGroup();
1444 Vector seqs = new Vector();
1446 for (int i = 0; i < sg.getSize(); i++)
1448 seq = sg.getSequenceAt(i);
1449 seqs.addElement(seq);
1453 // If the cut affects all sequences, remove highlighted columns
1454 if (sg.getSize() == viewport.alignment.getHeight())
1456 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1457 sg.getEndRes() + 1);
1461 SequenceI [] cut = new SequenceI[seqs.size()];
1462 for(int i=0; i<seqs.size(); i++)
1463 cut[i] = (SequenceI)seqs.elementAt(i);
1469 addHistoryItem(new EditCommand("Cut Sequences",
1473 sg.getEndRes()-sg.getStartRes()+1,
1474 viewport.alignment));
1477 viewport.setSelectionGroup(null);
1478 viewport.alignment.deleteGroup(sg);
1480 viewport.firePropertyChange("alignment", null,
1481 viewport.getAlignment().getSequences());
1483 if (viewport.getAlignment().getHeight() < 1)
1487 this.setClosed(true);
1489 catch (Exception ex)
1498 * @param e DOCUMENT ME!
1500 protected void deleteGroups_actionPerformed(ActionEvent e)
1502 viewport.alignment.deleteAllGroups();
1503 viewport.sequenceColours = null;
1504 viewport.setSelectionGroup(null);
1505 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1506 alignPanel.repaint();
1512 * @param e DOCUMENT ME!
1514 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1516 SequenceGroup sg = new SequenceGroup();
1518 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1521 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1524 sg.setEndRes(viewport.alignment.getWidth() - 1);
1525 viewport.setSelectionGroup(sg);
1526 alignPanel.repaint();
1527 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1533 * @param e DOCUMENT ME!
1535 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1537 if(viewport.cursorMode)
1539 alignPanel.seqPanel.keyboardNo1 = null;
1540 alignPanel.seqPanel.keyboardNo2 = null;
1542 viewport.setSelectionGroup(null);
1543 viewport.getColumnSelection().clear();
1544 viewport.setSelectionGroup(null);
1545 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1546 alignPanel.idPanel.idCanvas.searchResults = null;
1547 alignPanel.repaint();
1548 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1554 * @param e DOCUMENT ME!
1556 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1558 SequenceGroup sg = viewport.getSelectionGroup();
1562 selectAllSequenceMenuItem_actionPerformed(null);
1567 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1570 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1573 alignPanel.repaint();
1575 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1578 public void invertColSel_actionPerformed(ActionEvent e)
1580 viewport.invertColumnSelection();
1581 alignPanel.repaint();
1588 * @param e DOCUMENT ME!
1590 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1592 trimAlignment(true);
1598 * @param e DOCUMENT ME!
1600 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1602 trimAlignment(false);
1605 void trimAlignment(boolean trimLeft)
1607 ColumnSelection colSel = viewport.getColumnSelection();
1610 if (colSel.size() > 0)
1613 column = colSel.getMin();
1615 column = colSel.getMax();
1618 if(viewport.getSelectionGroup()!=null)
1619 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1621 seqs = viewport.alignment.getSequencesArray();
1624 TrimRegionCommand trimRegion;
1627 trimRegion = new TrimRegionCommand("Remove Left",
1628 TrimRegionCommand.TRIM_LEFT,
1633 viewport.selectionGroup);
1634 viewport.setStartRes(0);
1638 trimRegion = new TrimRegionCommand("Remove Right",
1639 TrimRegionCommand.TRIM_RIGHT,
1644 viewport.selectionGroup);
1647 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1650 addHistoryItem(trimRegion);
1652 Vector groups = viewport.alignment.getGroups();
1654 for (int i = 0; i < groups.size(); i++)
1656 SequenceGroup sg = (SequenceGroup) groups.get(i);
1658 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1659 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1661 viewport.alignment.deleteGroup(sg);
1665 viewport.firePropertyChange("alignment", null,
1666 viewport.getAlignment().getSequences());
1673 * @param e DOCUMENT ME!
1675 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1677 int start = 0, end = viewport.alignment.getWidth()-1;
1680 if (viewport.getSelectionGroup() != null)
1682 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1683 start = viewport.getSelectionGroup().getStartRes();
1684 end = viewport.getSelectionGroup().getEndRes();
1687 seqs = viewport.alignment.getSequencesArray();
1690 RemoveGapColCommand removeGapCols =
1691 new RemoveGapColCommand("Remove Gapped Columns",
1694 viewport.getGapCharacter());
1696 addHistoryItem(removeGapCols);
1698 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1700 //This is to maintain viewport position on first residue
1702 SequenceI seq = viewport.alignment.getSequenceAt(0);
1703 int startRes = seq.findPosition(viewport.startRes);
1704 // ShiftList shifts;
1705 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1706 // edit.alColumnChanges=shifts.getInverse();
1707 // if (viewport.hasHiddenColumns)
1708 // viewport.getColumnSelection().compensateForEdits(shifts);
1709 viewport.setStartRes(seq.findIndex(startRes)-1);
1710 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1717 * @param e DOCUMENT ME!
1719 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1721 int start = 0, end = viewport.alignment.getWidth()-1;
1724 if (viewport.getSelectionGroup() != null)
1726 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1727 start = viewport.getSelectionGroup().getStartRes();
1728 end = viewport.getSelectionGroup().getEndRes();
1731 seqs = viewport.alignment.getSequencesArray();
1733 //This is to maintain viewport position on first residue
1735 SequenceI seq = viewport.alignment.getSequenceAt(0);
1736 int startRes = seq.findPosition(viewport.startRes);
1738 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1741 viewport.getGapCharacter()));
1743 viewport.setStartRes(seq.findIndex(startRes)-1);
1745 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1752 * @param e DOCUMENT ME!
1754 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1756 viewport.padGaps = padGapsMenuitem.isSelected();
1758 viewport.firePropertyChange("alignment",
1760 viewport.getAlignment().getSequences());
1766 * @param e DOCUMENT ME!
1768 public void findMenuItem_actionPerformed(ActionEvent e)
1773 public void newView_actionPerformed(ActionEvent e)
1775 AlignmentPanel newap =
1776 new Jalview2XML().copyAlignPanel(alignPanel, true);
1778 if (viewport.viewName == null)
1779 viewport.viewName = "Original";
1781 newap.av.historyList = viewport.historyList;
1782 newap.av.redoList = viewport.redoList;
1784 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1785 String newViewName = "View " +index;
1787 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1788 Vector existingNames = new Vector();
1789 for(int i=0; i<comps.size(); i++)
1791 if(comps.elementAt(i) instanceof AlignmentPanel)
1793 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1794 if(!existingNames.contains(ap.av.viewName))
1795 existingNames.addElement(ap.av.viewName);
1799 while(existingNames.contains(newViewName))
1801 newViewName = "View "+ (++index);
1804 newap.av.viewName = newViewName;
1806 addAlignmentPanel(newap, false);
1808 if(alignPanels.size()==2)
1810 viewport.gatherViewsHere = true;
1812 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1815 public void expandViews_actionPerformed(ActionEvent e)
1817 Desktop.instance.explodeViews(this);
1820 public void gatherViews_actionPerformed(ActionEvent e)
1822 Desktop.instance.gatherViews(this);
1830 * @param e DOCUMENT ME!
1832 public void font_actionPerformed(ActionEvent e)
1834 new FontChooser(alignPanel);
1841 * @param e DOCUMENT ME!
1843 protected void seqLimit_actionPerformed(ActionEvent e)
1845 viewport.setShowJVSuffix(seqLimits.isSelected());
1847 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1848 alignPanel.repaint();
1851 public void idRightAlign_actionPerformed(ActionEvent e)
1853 viewport.rightAlignIds = idRightAlign.isSelected();
1854 alignPanel.repaint();
1862 * @param e DOCUMENT ME!
1864 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1866 viewport.setColourText(colourTextMenuItem.isSelected());
1867 alignPanel.repaint();
1873 * @param e DOCUMENT ME!
1875 public void wrapMenuItem_actionPerformed(ActionEvent e)
1877 scaleAbove.setVisible(wrapMenuItem.isSelected());
1878 scaleLeft.setVisible(wrapMenuItem.isSelected());
1879 scaleRight.setVisible(wrapMenuItem.isSelected());
1880 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1881 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1884 public void showAllSeqs_actionPerformed(ActionEvent e)
1886 viewport.showAllHiddenSeqs();
1889 public void showAllColumns_actionPerformed(ActionEvent e)
1891 viewport.showAllHiddenColumns();
1895 public void hideSelSequences_actionPerformed(ActionEvent e)
1897 viewport.hideAllSelectedSeqs();
1898 alignPanel.repaint();
1901 public void hideSelColumns_actionPerformed(ActionEvent e)
1903 viewport.hideSelectedColumns();
1904 alignPanel.repaint();
1907 public void hiddenMarkers_actionPerformed(ActionEvent e)
1909 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1916 * @param e DOCUMENT ME!
1918 protected void scaleAbove_actionPerformed(ActionEvent e)
1920 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1921 alignPanel.repaint();
1927 * @param e DOCUMENT ME!
1929 protected void scaleLeft_actionPerformed(ActionEvent e)
1931 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1932 alignPanel.repaint();
1938 * @param e DOCUMENT ME!
1940 protected void scaleRight_actionPerformed(ActionEvent e)
1942 viewport.setScaleRightWrapped(scaleRight.isSelected());
1943 alignPanel.repaint();
1949 * @param e DOCUMENT ME!
1951 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1953 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1954 alignPanel.repaint();
1960 * @param e DOCUMENT ME!
1962 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1964 viewport.setShowText(viewTextMenuItem.isSelected());
1965 alignPanel.repaint();
1971 * @param e DOCUMENT ME!
1973 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1975 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1976 alignPanel.repaint();
1980 public FeatureSettings featureSettings;
1981 public void featureSettings_actionPerformed(ActionEvent e)
1983 if(featureSettings !=null )
1985 featureSettings.close();
1986 featureSettings = null;
1988 featureSettings = new FeatureSettings(this);
1994 * @param evt DOCUMENT ME!
1996 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1998 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1999 alignPanel.repaint();
2000 if (alignPanel.getOverviewPanel() != null)
2002 alignPanel.getOverviewPanel().updateOverviewImage();
2009 * @param e DOCUMENT ME!
2011 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2013 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2014 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2020 * @param e DOCUMENT ME!
2022 public void overviewMenuItem_actionPerformed(ActionEvent e)
2024 if (alignPanel.overviewPanel != null)
2029 JInternalFrame frame = new JInternalFrame();
2030 OverviewPanel overview = new OverviewPanel(alignPanel);
2031 frame.setContentPane(overview);
2032 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2033 frame.getWidth(), frame.getHeight());
2035 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2036 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2038 public void internalFrameClosed(
2039 javax.swing.event.InternalFrameEvent evt)
2041 alignPanel.setOverviewPanel(null);
2046 alignPanel.setOverviewPanel(overview);
2049 public void textColour_actionPerformed(ActionEvent e)
2051 new TextColourChooser().chooseColour(alignPanel, null);
2057 * @param e DOCUMENT ME!
2059 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2067 * @param e DOCUMENT ME!
2069 public void clustalColour_actionPerformed(ActionEvent e)
2071 changeColour(new ClustalxColourScheme(
2072 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2078 * @param e DOCUMENT ME!
2080 public void zappoColour_actionPerformed(ActionEvent e)
2082 changeColour(new ZappoColourScheme());
2088 * @param e DOCUMENT ME!
2090 public void taylorColour_actionPerformed(ActionEvent e)
2092 changeColour(new TaylorColourScheme());
2098 * @param e DOCUMENT ME!
2100 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2102 changeColour(new HydrophobicColourScheme());
2108 * @param e DOCUMENT ME!
2110 public void helixColour_actionPerformed(ActionEvent e)
2112 changeColour(new HelixColourScheme());
2118 * @param e DOCUMENT ME!
2120 public void strandColour_actionPerformed(ActionEvent e)
2122 changeColour(new StrandColourScheme());
2128 * @param e DOCUMENT ME!
2130 public void turnColour_actionPerformed(ActionEvent e)
2132 changeColour(new TurnColourScheme());
2138 * @param e DOCUMENT ME!
2140 public void buriedColour_actionPerformed(ActionEvent e)
2142 changeColour(new BuriedColourScheme());
2148 * @param e DOCUMENT ME!
2150 public void nucleotideColour_actionPerformed(ActionEvent e)
2152 changeColour(new NucleotideColourScheme());
2155 public void annotationColour_actionPerformed(ActionEvent e)
2157 new AnnotationColourChooser(viewport, alignPanel);
2164 * @param e DOCUMENT ME!
2166 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2168 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2174 * @param cs DOCUMENT ME!
2176 public void changeColour(ColourSchemeI cs)
2182 if (viewport.getAbovePIDThreshold())
2184 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2187 cs.setThreshold(threshold,
2188 viewport.getIgnoreGapsConsensus());
2190 viewport.setGlobalColourScheme(cs);
2194 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2197 if (viewport.getConservationSelected())
2200 Alignment al = (Alignment) viewport.alignment;
2201 Conservation c = new Conservation("All",
2202 ResidueProperties.propHash, 3,
2203 al.getSequences(), 0,
2207 c.verdict(false, viewport.ConsPercGaps);
2209 cs.setConservation(c);
2211 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2216 cs.setConservation(null);
2219 cs.setConsensus(viewport.hconsensus);
2222 viewport.setGlobalColourScheme(cs);
2224 if (viewport.getColourAppliesToAllGroups())
2226 Vector groups = viewport.alignment.getGroups();
2228 for (int i = 0; i < groups.size(); i++)
2230 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2238 if (cs instanceof ClustalxColourScheme)
2240 sg.cs = new ClustalxColourScheme(
2241 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2243 else if (cs instanceof UserColourScheme)
2245 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2251 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2253 catch (Exception ex)
2258 if (viewport.getAbovePIDThreshold()
2259 || cs instanceof PIDColourScheme
2260 || cs instanceof Blosum62ColourScheme)
2262 sg.cs.setThreshold(threshold,
2263 viewport.getIgnoreGapsConsensus());
2265 sg.cs.setConsensus(AAFrequency.calculate(
2266 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2270 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2273 if (viewport.getConservationSelected())
2275 Conservation c = new Conservation("Group",
2276 ResidueProperties.propHash, 3,
2277 sg.getSequences(viewport.hiddenRepSequences),
2281 c.verdict(false, viewport.ConsPercGaps);
2282 sg.cs.setConservation(c);
2285 sg.cs.setConservation(null);
2289 if (alignPanel.getOverviewPanel() != null)
2291 alignPanel.getOverviewPanel().updateOverviewImage();
2294 alignPanel.repaint();
2300 * @param e DOCUMENT ME!
2302 protected void modifyPID_actionPerformed(ActionEvent e)
2304 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2306 SliderPanel.setPIDSliderSource(alignPanel,
2307 viewport.getGlobalColourScheme(),
2309 SliderPanel.showPIDSlider();
2316 * @param e DOCUMENT ME!
2318 protected void modifyConservation_actionPerformed(ActionEvent e)
2320 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2322 SliderPanel.setConservationSlider(alignPanel,
2323 viewport.globalColourScheme,
2325 SliderPanel.showConservationSlider();
2332 * @param e DOCUMENT ME!
2334 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2336 viewport.setConservationSelected(conservationMenuItem.isSelected());
2338 viewport.setAbovePIDThreshold(false);
2339 abovePIDThreshold.setSelected(false);
2341 changeColour(viewport.getGlobalColourScheme());
2343 modifyConservation_actionPerformed(null);
2349 * @param e DOCUMENT ME!
2351 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2353 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2355 conservationMenuItem.setSelected(false);
2356 viewport.setConservationSelected(false);
2358 changeColour(viewport.getGlobalColourScheme());
2360 modifyPID_actionPerformed(null);
2366 * @param e DOCUMENT ME!
2368 public void userDefinedColour_actionPerformed(ActionEvent e)
2370 if (e.getActionCommand().equals("User Defined..."))
2372 new UserDefinedColours(alignPanel, null);
2376 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2377 getUserColourSchemes().get(e.getActionCommand());
2383 public void updateUserColourMenu()
2386 Component[] menuItems = colourMenu.getMenuComponents();
2387 int i, iSize = menuItems.length;
2388 for (i = 0; i < iSize; i++)
2390 if (menuItems[i].getName() != null &&
2391 menuItems[i].getName().equals("USER_DEFINED"))
2393 colourMenu.remove(menuItems[i]);
2397 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2399 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2400 getUserColourSchemes().keys();
2402 while (userColours.hasMoreElements())
2404 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2405 nextElement().toString());
2406 radioItem.setName("USER_DEFINED");
2407 radioItem.addMouseListener(new MouseAdapter()
2409 public void mousePressed(MouseEvent evt)
2411 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2413 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2415 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2416 "Remove from default list?",
2417 "Remove user defined colour",
2418 JOptionPane.YES_NO_OPTION);
2419 if(option == JOptionPane.YES_OPTION)
2421 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2422 colourMenu.remove(radioItem);
2425 radioItem.addActionListener(new ActionListener()
2427 public void actionPerformed(ActionEvent evt)
2429 userDefinedColour_actionPerformed(evt);
2435 radioItem.addActionListener(new ActionListener()
2437 public void actionPerformed(ActionEvent evt)
2439 userDefinedColour_actionPerformed(evt);
2443 colourMenu.insert(radioItem, 15);
2444 colours.add(radioItem);
2452 * @param e DOCUMENT ME!
2454 public void PIDColour_actionPerformed(ActionEvent e)
2456 changeColour(new PIDColourScheme());
2462 * @param e DOCUMENT ME!
2464 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2466 changeColour(new Blosum62ColourScheme());
2472 * @param e DOCUMENT ME!
2474 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2476 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2477 AlignmentSorter.sortByPID(viewport.getAlignment(),
2478 viewport.getAlignment().getSequenceAt(0));
2479 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2480 alignPanel.repaint();
2486 * @param e DOCUMENT ME!
2488 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2490 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2491 AlignmentSorter.sortByID(viewport.getAlignment());
2492 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2493 alignPanel.repaint();
2499 * @param e DOCUMENT ME!
2501 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2503 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2504 AlignmentSorter.sortByGroup(viewport.getAlignment());
2505 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2507 alignPanel.repaint();
2513 * @param e DOCUMENT ME!
2515 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2517 new RedundancyPanel(alignPanel, this);
2524 * @param e DOCUMENT ME!
2526 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2528 if ( (viewport.getSelectionGroup() == null) ||
2529 (viewport.getSelectionGroup().getSize() < 2))
2531 JOptionPane.showInternalMessageDialog(this,
2532 "You must select at least 2 sequences.",
2533 "Invalid Selection",
2534 JOptionPane.WARNING_MESSAGE);
2538 JInternalFrame frame = new JInternalFrame();
2539 frame.setContentPane(new PairwiseAlignPanel(viewport));
2540 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2547 * @param e DOCUMENT ME!
2549 public void PCAMenuItem_actionPerformed(ActionEvent e)
2551 if ( ( (viewport.getSelectionGroup() != null) &&
2552 (viewport.getSelectionGroup().getSize() < 4) &&
2553 (viewport.getSelectionGroup().getSize() > 0)) ||
2554 (viewport.getAlignment().getHeight() < 4))
2556 JOptionPane.showInternalMessageDialog(this,
2557 "Principal component analysis must take\n" +
2558 "at least 4 input sequences.",
2559 "Sequence selection insufficient",
2560 JOptionPane.WARNING_MESSAGE);
2565 new PCAPanel(alignPanel);
2569 public void autoCalculate_actionPerformed(ActionEvent e)
2571 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2572 if(viewport.autoCalculateConsensus)
2574 viewport.firePropertyChange("alignment",
2576 viewport.getAlignment().getSequences());
2584 * @param e DOCUMENT ME!
2586 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2588 NewTreePanel("AV", "PID", "Average distance tree using PID");
2594 * @param e DOCUMENT ME!
2596 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2598 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2604 * @param e DOCUMENT ME!
2606 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2608 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2614 * @param e DOCUMENT ME!
2616 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2618 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2624 * @param type DOCUMENT ME!
2625 * @param pwType DOCUMENT ME!
2626 * @param title DOCUMENT ME!
2628 void NewTreePanel(String type, String pwType, String title)
2632 if (viewport.getSelectionGroup() != null) {
2633 if (viewport.getSelectionGroup().getSize() < 3) {
2634 JOptionPane.showMessageDialog(Desktop.desktop,
2635 "You need to have more than two sequences selected to build a tree!",
2636 "Not enough sequences",
2637 JOptionPane.WARNING_MESSAGE);
2642 SequenceGroup sg = viewport.getSelectionGroup();
2644 /* Decide if the selection is a column region */
2645 while (s < sg.getSize())
2647 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2650 JOptionPane.showMessageDialog(Desktop.desktop,
2651 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2652 "Try using the Pad function in the edit menu,\n" +
2653 "or one of the multiple sequence alignment web services.",
2654 "Sequences in selection are not aligned",
2655 JOptionPane.WARNING_MESSAGE);
2661 title = title + " on region";
2662 tp = new TreePanel(alignPanel, type, pwType);
2666 //are the sequences aligned?
2667 if (!viewport.alignment.isAligned())
2669 JOptionPane.showMessageDialog(Desktop.desktop,
2670 "The sequences must be aligned before creating a tree.\n" +
2671 "Try using the Pad function in the edit menu,\n" +
2672 "or one of the multiple sequence alignment web services.",
2673 "Sequences not aligned",
2674 JOptionPane.WARNING_MESSAGE);
2679 if(viewport.alignment.getHeight()<2)
2682 tp = new TreePanel(alignPanel, type, pwType);
2687 if(viewport.viewName!=null)
2688 title+= viewport.viewName+" of ";
2690 title += this.title;
2692 Desktop.addInternalFrame(tp, title, 600, 500);
2698 * @param title DOCUMENT ME!
2699 * @param order DOCUMENT ME!
2701 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2703 final JMenuItem item = new JMenuItem("by " + title);
2705 item.addActionListener(new java.awt.event.ActionListener()
2707 public void actionPerformed(ActionEvent e)
2709 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2711 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2712 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2714 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2716 alignPanel.repaint();
2722 * Maintain the Order by->Displayed Tree menu.
2723 * Creates a new menu item for a TreePanel with an appropriate
2724 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2725 * to remove the menu item when the treePanel is closed, and adjust
2726 * the tree leaf to sequence mapping when the alignment is modified.
2727 * @param treePanel Displayed tree window.
2728 * @param title SortBy menu item title.
2730 public void buildTreeMenu()
2732 sortByTreeMenu.removeAll();
2734 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2735 Vector treePanels = new Vector();
2736 int i, iSize = comps.size();
2737 for(i=0; i<iSize; i++)
2739 if(comps.elementAt(i) instanceof TreePanel)
2741 treePanels.add(comps.elementAt(i));
2745 iSize = treePanels.size();
2749 sortByTreeMenu.setVisible(false);
2753 sortByTreeMenu.setVisible(true);
2755 for(i=0; i<treePanels.size(); i++)
2757 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2758 final JMenuItem item = new JMenuItem(tp.getTitle());
2759 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2760 item.addActionListener(new java.awt.event.ActionListener()
2762 public void actionPerformed(ActionEvent e)
2764 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2765 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2767 addHistoryItem(new OrderCommand("Tree Sort",
2769 viewport.alignment));
2771 alignPanel.repaint();
2775 sortByTreeMenu.add(item);
2780 * Work out whether the whole set of sequences
2781 * or just the selected set will be submitted for multiple alignment.
2784 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2786 // Now, check we have enough sequences
2787 AlignmentView msa = null;
2789 if ( (viewport.getSelectionGroup() != null) &&
2790 (viewport.getSelectionGroup().getSize() > 1))
2792 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2793 /*SequenceGroup seqs = viewport.getSelectionGroup();
2795 msa = new SequenceI[sz = seqs.getSize(false)];
2797 for (int i = 0; i < sz; i++)
2799 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2801 msa = viewport.getAlignmentView(true);
2805 /*Vector seqs = viewport.getAlignment().getSequences();
2807 if (seqs.size() > 1)
2809 msa = new SequenceI[seqs.size()];
2811 for (int i = 0; i < seqs.size(); i++)
2813 msa[i] = (SequenceI) seqs.elementAt(i);
2816 msa = viewport.getAlignmentView(false);
2822 * Decides what is submitted to a secondary structure prediction service,
2823 * the currently selected sequence, or the currently selected alignment
2824 * (where the first sequence in the set is the one that the prediction
2827 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2829 AlignmentView seqs = null;
2831 if ( (viewport.getSelectionGroup() != null) &&
2832 (viewport.getSelectionGroup().getSize() > 0))
2834 seqs = viewport.getAlignmentView(true);
2838 seqs = viewport.getAlignmentView(false);
2840 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2841 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2842 if (!viewport.alignment.isAligned())
2844 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2851 * @param e DOCUMENT ME!
2853 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2855 // Pick the tree file
2856 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2859 chooser.setFileView(new JalviewFileView());
2860 chooser.setDialogTitle("Select a newick-like tree file");
2861 chooser.setToolTipText("Load a tree file");
2863 int value = chooser.showOpenDialog(null);
2865 if (value == JalviewFileChooser.APPROVE_OPTION)
2867 String choice = chooser.getSelectedFile().getPath();
2868 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2872 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2874 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2876 catch (Exception ex)
2878 JOptionPane.showMessageDialog(Desktop.desktop,
2879 "Problem reading tree file",
2881 JOptionPane.WARNING_MESSAGE);
2882 ex.printStackTrace();
2888 public TreePanel ShowNewickTree(NewickFile nf, String title)
2890 return ShowNewickTree(nf,title,600,500,4,5);
2892 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2894 return ShowNewickTree(nf,title, input, 600,500,4,5);
2896 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2897 return ShowNewickTree(nf, title, null, w, h, x, y);
2900 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2902 * @param nf the tree
2903 * @param title tree viewer title
2904 * @param input Associated alignment input data (or null)
2909 * @return TreePanel handle
2911 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2912 TreePanel tp = null;
2918 if (nf.getTree() != null)
2920 tp = new TreePanel(alignPanel,
2928 tp.setLocation(x,y);
2931 Desktop.addInternalFrame(tp, title, w, h);
2934 catch (Exception ex)
2936 ex.printStackTrace();
2944 * Generates menu items and listener event actions for web service clients
2947 public void BuildWebServiceMenu()
2949 if ( (Discoverer.services != null)
2950 && (Discoverer.services.size() > 0))
2952 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2953 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2954 Vector wsmenu = new Vector();
2955 final AlignFrame af = this;
2958 // Add any Multiple Sequence Alignment Services
2959 final JMenu msawsmenu = new JMenu("Alignment");
2960 for (int i = 0, j = msaws.size(); i < j; i++)
2962 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2964 final JMenuItem method = new JMenuItem(sh.getName());
2965 method.addActionListener(new ActionListener()
2967 public void actionPerformed(ActionEvent e)
2969 AlignmentView msa = gatherSequencesForAlignment();
2970 new jalview.ws.MsaWSClient(sh, title, msa,
2971 false, true, viewport.getAlignment().getDataset(), af);
2976 msawsmenu.add(method);
2977 // Deal with services that we know accept partial alignments.
2978 if (sh.getName().indexOf("lustal") > -1)
2980 // We know that ClustalWS can accept partial alignments for refinement.
2981 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2982 methodR.addActionListener(new ActionListener()
2984 public void actionPerformed(ActionEvent e)
2986 AlignmentView msa = gatherSequencesForAlignment();
2987 new jalview.ws.MsaWSClient(sh, title, msa,
2988 true, true, viewport.getAlignment().getDataset(), af);
2993 msawsmenu.add(methodR);
2997 wsmenu.add(msawsmenu);
2999 if (secstrpr != null)
3001 // Add any secondary structure prediction services
3002 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3003 for (int i = 0, j = secstrpr.size(); i < j; i++)
3005 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3007 final JMenuItem method = new JMenuItem(sh.getName());
3008 method.addActionListener(new ActionListener()
3010 public void actionPerformed(ActionEvent e)
3012 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3013 if (msa.getSequences().length == 1)
3015 // Single Sequence prediction
3016 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3020 if (msa.getSequences().length > 1)
3022 // Sequence profile based prediction
3023 new jalview.ws.JPredClient(sh,
3024 title, true, msa, af, true);
3029 secstrmenu.add(method);
3031 wsmenu.add(secstrmenu);
3033 this.webService.removeAll();
3034 for (int i = 0, j = wsmenu.size(); i < j; i++)
3036 webService.add( (JMenu) wsmenu.get(i));
3041 this.webService.removeAll();
3042 this.webService.add(this.webServiceNoServices);
3044 // TODO: add in rediscovery function
3045 // TODO: reduce code redundancy.
3046 // TODO: group services by location as well as function.
3049 /* public void vamsasStore_actionPerformed(ActionEvent e)
3051 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3052 getProperty("LAST_DIRECTORY"));
3054 chooser.setFileView(new JalviewFileView());
3055 chooser.setDialogTitle("Export to Vamsas file");
3056 chooser.setToolTipText("Export");
3058 int value = chooser.showSaveDialog(this);
3060 if (value == JalviewFileChooser.APPROVE_OPTION)
3062 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3063 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3064 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3071 public void showTranslation_actionPerformed(ActionEvent e)
3073 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3074 String [] seqstring = viewport.getViewAsString(true);
3076 int s, sSize = selection.length;
3077 SequenceI [] newSeq = new SequenceI[sSize];
3080 StringBuffer protein;
3082 for(s=0; s<sSize; s++)
3084 protein = new StringBuffer();
3085 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3086 resSize = seq.length();
3087 resSize -= resSize%3;
3089 for(res = 0; res < resSize; res+=3)
3091 String codon = seq.substring(res, res+3);
3092 codon = codon.replace('U', 'T');
3093 String aa = ResidueProperties.codonTranslate(codon);
3095 protein.append(viewport.getGapCharacter());
3096 else if(aa.equals("STOP"))
3097 protein.append("X");
3099 protein.append( aa );
3101 newSeq[s] = new Sequence(selection[s].getName(),
3102 protein.toString());
3106 AlignmentI al = new Alignment(newSeq);
3107 al.setDataset(null);
3110 ////////////////////////////////
3111 // Copy annotations across
3112 jalview.datamodel.AlignmentAnnotation[] annotations
3113 = viewport.alignment.getAlignmentAnnotation();
3115 if(annotations!=null)
3117 for (int i = 0; i < annotations.length; i++)
3119 if (annotations[i].label.equals("Quality") ||
3120 annotations[i].label.equals("Conservation") ||
3121 annotations[i].label.equals("Consensus"))
3126 aSize = viewport.alignment.getWidth() / 3;
3127 jalview.datamodel.Annotation[] anots =
3128 new jalview.datamodel.Annotation[aSize];
3130 for (a = 0; a < viewport.alignment.getWidth(); a++)
3132 if (annotations[i].annotations[a] == null
3133 || annotations[i].annotations[a] == null)
3136 anots[a / 3] = new Annotation(
3137 annotations[i].annotations[a].displayCharacter,
3138 annotations[i].annotations[a].description,
3139 annotations[i].annotations[a].secondaryStructure,
3140 annotations[i].annotations[a].value,
3141 annotations[i].annotations[a].colour);
3144 jalview.datamodel.AlignmentAnnotation aa
3145 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3146 annotations[i].description, anots);
3147 al.addAnnotation(aa);
3151 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3152 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3164 * @param String DOCUMENT ME!
3166 public boolean parseFeaturesFile(String file, String type)
3168 boolean featuresFile = false;
3170 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3171 alignPanel.seqPanel.seqCanvas.
3172 getFeatureRenderer().featureColours,
3177 ex.printStackTrace();
3182 viewport.showSequenceFeatures = true;
3183 showSeqFeatures.setSelected(true);
3184 alignPanel.repaint();
3187 return featuresFile;
3190 public void dragEnter(DropTargetDragEvent evt)
3193 public void dragExit(DropTargetEvent evt)
3196 public void dragOver(DropTargetDragEvent evt)
3199 public void dropActionChanged(DropTargetDragEvent evt)
3202 public void drop(DropTargetDropEvent evt)
3204 Transferable t = evt.getTransferable();
3205 java.util.List files = null;
3209 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3210 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3212 //Works on Windows and MacOSX
3213 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3214 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3216 else if (t.isDataFlavorSupported(uriListFlavor))
3218 // This is used by Unix drag system
3219 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3220 String data = (String) t.getTransferData(uriListFlavor);
3221 files = new java.util.ArrayList(1);
3222 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3225 st.hasMoreTokens(); )
3227 String s = st.nextToken();
3228 if (s.startsWith("#"))
3230 // the line is a comment (as per the RFC 2483)
3234 java.net.URI uri = new java.net.URI(s);
3235 java.io.File file = new java.io.File(uri);
3242 e.printStackTrace();
3249 for (int i = 0; i < files.size(); i++)
3251 loadJalviewDataFile(files.get(i).toString());
3254 catch (Exception ex)
3256 ex.printStackTrace();
3261 // This method will attempt to load a "dropped" file first by testing
3262 // whether its and Annotation file, then features file. If both are
3263 // false then the user may have dropped an alignment file onto this
3265 public void loadJalviewDataFile(String file)
3268 String protocol = "File";
3270 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3275 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3276 alignment, file, protocol);
3280 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3283 String format = new IdentifyFile().Identify(file, protocol);
3285 if(format.equalsIgnoreCase("JnetFile"))
3287 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3289 new JnetAnnotationMaker().add_annotation(predictions,
3290 viewport.getAlignment(),
3292 alignPanel.adjustAnnotationHeight();
3293 alignPanel.repaint();
3296 new FileLoader().LoadFile(viewport, file, protocol, format);
3302 alignPanel.adjustAnnotationHeight();
3305 }catch(Exception ex)
3307 ex.printStackTrace();
3311 public void tabSelectionChanged(int index)
3315 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3316 viewport = alignPanel.av;
3317 setMenusFromViewport(viewport);
3321 public void tabbedPane_mousePressed(MouseEvent e)
3323 if(SwingUtilities.isRightMouseButton(e))
3325 String reply = JOptionPane.showInternalInputDialog(this,
3328 JOptionPane.QUESTION_MESSAGE);
3332 viewport.viewName = reply;
3333 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3339 public AlignViewport getCurrentView()
3345 class PrintThread extends Thread
3348 public PrintThread(AlignmentPanel ap)
3352 static PageFormat pf;
3355 PrinterJob printJob = PrinterJob.getPrinterJob();
3358 printJob.setPrintable(ap, pf);
3360 printJob.setPrintable(ap);
3362 if (printJob.printDialog())
3368 catch (Exception PrintException)
3370 PrintException.printStackTrace();