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.*;
46 public class AlignFrame extends GAlignFrame implements DropTargetListener
49 public static final int DEFAULT_WIDTH = 700;
52 public static final int DEFAULT_HEIGHT = 500;
53 public AlignmentPanel alignPanel;
55 AlignViewport viewport;
57 Vector alignPanels = new Vector();
61 String currentFileFormat = null;
63 String fileName = null;
67 * Creates a new AlignFrame object.
69 * @param al DOCUMENT ME!
71 public AlignFrame(AlignmentI al, int width, int height)
73 this(al, null, width, height);
78 * new alignment window with hidden columns
79 * @param al AlignmentI
80 * @param hiddenColumns ColumnSelection or null
82 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
83 int width, int height)
85 this.setSize(width, height);
86 viewport = new AlignViewport(al, hiddenColumns);
88 alignPanel = new AlignmentPanel(this, viewport);
90 if(al.getDataset()==null)
95 addAlignmentPanel(alignPanel, true);
100 * Make a new AlignFrame from exisiting alignmentPanels
101 * @param ap AlignmentPanel
102 * @param av AlignViewport
104 public AlignFrame(AlignmentPanel ap)
108 addAlignmentPanel(ap, false);
114 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
116 if (viewport.conservation == null)
118 BLOSUM62Colour.setEnabled(false);
119 conservationMenuItem.setEnabled(false);
120 modifyConservation.setEnabled(false);
121 // PIDColour.setEnabled(false);
122 // abovePIDThreshold.setEnabled(false);
123 // modifyPID.setEnabled(false);
126 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
128 if (sortby.equals("Id"))
129 sortIDMenuItem_actionPerformed(null);
130 else if (sortby.equals("Pairwise Identity"))
131 sortPairwiseMenuItem_actionPerformed(null);
133 if (Desktop.desktop != null)
135 addServiceListeners();
136 setGUINucleotide(viewport.alignment.isNucleotide());
139 setMenusFromViewport(viewport);
141 if (viewport.wrapAlignment)
143 wrapMenuItem_actionPerformed(null);
150 public void setFileName(String file, String format)
153 currentFileFormat = format;
154 reload.setEnabled(true);
157 void addKeyListener()
159 addKeyListener(new KeyAdapter()
161 public void keyPressed(KeyEvent evt)
163 if (viewport.cursorMode
164 && evt.getKeyCode() >= KeyEvent.VK_0
165 && evt.getKeyCode() <= KeyEvent.VK_9)
167 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
170 switch (evt.getKeyCode())
173 case 27: // escape key
174 deselectAllSequenceMenuItem_actionPerformed(null);
178 case KeyEvent.VK_DOWN:
179 if (viewport.cursorMode)
181 alignPanel.seqPanel.moveCursor(0, 1);
184 moveSelectedSequences(false);
188 if (viewport.cursorMode)
190 alignPanel.seqPanel.moveCursor(0, -1);
193 moveSelectedSequences(true);
196 case KeyEvent.VK_LEFT:
197 if (viewport.cursorMode)
199 alignPanel.seqPanel.moveCursor( -1, 0);
203 case KeyEvent.VK_RIGHT:
204 if (viewport.cursorMode)
206 alignPanel.seqPanel.moveCursor(1, 0);
210 case KeyEvent.VK_SPACE:
211 if (viewport.cursorMode)
213 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
219 case KeyEvent.VK_DELETE:
220 case KeyEvent.VK_BACK_SPACE:
221 if (!viewport.cursorMode)
223 cut_actionPerformed(null);
226 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
233 if (viewport.cursorMode)
235 alignPanel.seqPanel.setCursorRow();
239 if (viewport.cursorMode && !evt.isControlDown())
241 alignPanel.seqPanel.setCursorColumn();
245 if (viewport.cursorMode)
247 alignPanel.seqPanel.setCursorPosition();
251 case KeyEvent.VK_ENTER:
252 case KeyEvent.VK_COMMA:
253 if (viewport.cursorMode)
255 alignPanel.seqPanel.setCursorRowAndColumn();
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
266 if (viewport.cursorMode)
268 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
273 viewport.cursorMode = !viewport.cursorMode;
274 statusBar.setText("Keyboard editing mode is " +
275 (viewport.cursorMode ? "on" : "off"));
276 if (viewport.cursorMode)
278 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
279 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
281 alignPanel.seqPanel.seqCanvas.repaint();
287 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
288 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
289 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
291 javax.help.HelpBroker hb = hs.createHelpBroker();
292 hb.setCurrentID("home");
293 hb.setDisplayed(true);
297 ex.printStackTrace();
303 boolean toggleSeqs = !evt.isControlDown();
304 boolean toggleCols = !evt.isShiftDown();
306 boolean hide = false;
308 SequenceGroup sg = viewport.getSelectionGroup();
311 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
313 hideSelSequences_actionPerformed(null);
316 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
317 showAllSeqs_actionPerformed(null);
322 if (viewport.colSel.getSelected().size() > 0)
324 hideSelColumns_actionPerformed(null);
326 viewport.selectionGroup = sg;
329 showAllColumns_actionPerformed(null);
333 case KeyEvent.VK_PAGE_UP:
334 if (viewport.wrapAlignment)
335 alignPanel.scrollUp(true);
337 alignPanel.setScrollValues(viewport.startRes,
339 - viewport.endSeq + viewport.startSeq);
341 case KeyEvent.VK_PAGE_DOWN:
342 if (viewport.wrapAlignment)
343 alignPanel.scrollUp(false);
345 alignPanel.setScrollValues(viewport.startRes,
347 + viewport.endSeq - viewport.startSeq);
355 public void addAlignmentPanel(final AlignmentPanel ap,
358 ap.alignFrame = this;
360 alignPanels.addElement(ap);
362 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
364 int aSize = alignPanels.size();
366 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
368 if (aSize == 1 && ap.av.viewName==null)
370 this.getContentPane().add(ap, BorderLayout.CENTER);
376 setInitialTabVisible();
379 expandViews.setEnabled(true);
380 gatherViews.setEnabled(true);
381 tabbedPane.addTab(ap.av.viewName, ap);
383 ap.setVisible(false);
389 ap.av.alignment.padGaps();
390 ap.av.updateConservation(ap);
391 ap.av.updateConsensus(ap);
395 public void setInitialTabVisible()
397 expandViews.setEnabled(true);
398 gatherViews.setEnabled(true);
399 tabbedPane.setVisible(true);
400 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
401 tabbedPane.addTab(first.av.viewName,first);
402 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
406 public AlignViewport getViewport()
411 /* Set up intrinsic listeners for dynamically generated GUI bits. */
412 private void addServiceListeners()
414 final java.beans.PropertyChangeListener thisListener;
415 // Do this once to get current state
416 BuildWebServiceMenu();
417 Desktop.discoverer.addPropertyChangeListener(
418 thisListener = new java.beans.PropertyChangeListener()
420 public void propertyChange(PropertyChangeEvent evt)
422 // System.out.println("Discoverer property change.");
423 if (evt.getPropertyName().equals("services"))
425 // System.out.println("Rebuilding web service menu");
426 BuildWebServiceMenu();
431 addInternalFrameListener(new javax.swing.event.
432 InternalFrameAdapter()
434 public void internalFrameClosed(
435 javax.swing.event.InternalFrameEvent evt)
437 // System.out.println("deregistering discoverer listener");
438 Desktop.discoverer.removePropertyChangeListener(thisListener);
439 closeMenuItem_actionPerformed(true);
445 public void setGUINucleotide(boolean nucleotide)
447 showTranslation.setVisible( nucleotide );
448 conservationMenuItem.setEnabled( !nucleotide );
449 modifyConservation.setEnabled( !nucleotide );
451 //Remember AlignFrame always starts as protein
454 calculateMenu.remove(calculateMenu.getItemCount()-2);
459 * Need to call this method when tabs are selected for multiple views,
460 * or when loading from Jalview2XML.java
461 * @param av AlignViewport
463 void setMenusFromViewport(AlignViewport av)
465 padGapsMenuitem.setSelected(av.padGaps);
466 colourTextMenuItem.setSelected(av.showColourText);
467 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
468 conservationMenuItem.setSelected(av.getConservationSelected());
469 seqLimits.setSelected(av.getShowJVSuffix());
470 idRightAlign.setSelected(av.rightAlignIds);
471 renderGapsMenuItem.setSelected(av.renderGaps);
472 wrapMenuItem.setSelected(av.wrapAlignment);
473 scaleAbove.setVisible(av.wrapAlignment);
474 scaleLeft.setVisible(av.wrapAlignment);
475 scaleRight.setVisible(av.wrapAlignment);
476 annotationPanelMenuItem.setState(av.showAnnotation);
477 viewBoxesMenuItem.setSelected(av.showBoxes);
478 viewTextMenuItem.setSelected(av.showText);
480 setColourSelected(ColourSchemeProperty.
481 getColourName(av.getGlobalColourScheme()));
483 showSeqFeatures.setSelected(av.showSequenceFeatures);
484 hiddenMarkers.setState(av.showHiddenMarkers);
485 applyToAllGroups.setState(av.colourAppliesToAllGroups);
491 Hashtable progressBars;
492 public void setProgressBar(String message, long id)
494 if(progressBars == null)
495 progressBars = new Hashtable();
497 JPanel progressPanel;
498 GridLayout layout = (GridLayout) statusPanel.getLayout();
499 if(progressBars.get( new Long(id) )!=null)
501 progressPanel = (JPanel)progressBars.get( new Long(id) );
502 statusPanel.remove(progressPanel);
503 progressBars.remove( progressPanel );
504 progressPanel = null;
506 statusBar.setText(message);
508 layout.setRows(layout.getRows() - 1);
512 progressPanel = new JPanel(new BorderLayout(10, 5));
514 JProgressBar progressBar = new JProgressBar();
515 progressBar.setIndeterminate(true);
517 progressPanel.add(new JLabel(message), BorderLayout.WEST);
518 progressPanel.add(progressBar, BorderLayout.CENTER);
520 layout.setRows(layout.getRows() + 1);
521 statusPanel.add(progressPanel);
523 progressBars.put(new Long(id), progressPanel);
533 Added so Castor Mapping file can obtain Jalview Version
535 public String getVersion()
537 return jalview.bin.Cache.getProperty("VERSION");
540 public FeatureRenderer getFeatureRenderer()
542 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
546 public void fetchSequence_actionPerformed(ActionEvent e)
548 new SequenceFetcher(this);
551 public void addFromFile_actionPerformed(ActionEvent e)
553 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
556 public void reload_actionPerformed(ActionEvent e)
560 if(currentFileFormat.equals("Jalview"))
562 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
563 for(int i=0; i<frames.length; i++)
565 if (frames[i] instanceof AlignFrame
567 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
570 frames[i].setSelected(true);
571 Desktop.instance.closeAssociatedWindows();
572 }catch(java.beans.PropertyVetoException ex){}
576 Desktop.instance.closeAssociatedWindows();
581 Rectangle bounds = this.getBounds();
583 FileLoader loader = new FileLoader();
584 String protocol = fileName.startsWith("http:") ? "URL" : "File";
585 AlignFrame newframe =
586 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
588 newframe.setBounds(bounds);
590 this.closeMenuItem_actionPerformed(true);
596 public void addFromText_actionPerformed(ActionEvent e)
598 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
601 public void addFromURL_actionPerformed(ActionEvent e)
603 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
607 public void save_actionPerformed(ActionEvent e)
610 || currentFileFormat==null
611 || fileName.startsWith("http")
613 saveAs_actionPerformed(null);
615 saveAlignment(fileName, currentFileFormat);
621 * @param e DOCUMENT ME!
623 public void saveAs_actionPerformed(ActionEvent e)
625 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
626 getProperty( "LAST_DIRECTORY"),
628 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
630 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
635 chooser.setFileView(new JalviewFileView());
636 chooser.setDialogTitle("Save Alignment to file");
637 chooser.setToolTipText("Save");
639 int value = chooser.showSaveDialog(this);
641 if (value == JalviewFileChooser.APPROVE_OPTION)
643 currentFileFormat = chooser.getSelectedFormat();
644 if (currentFileFormat == null)
646 JOptionPane.showInternalMessageDialog(Desktop.desktop,
647 "You must select a file format before saving!",
648 "File format not specified",
649 JOptionPane.WARNING_MESSAGE);
650 value = chooser.showSaveDialog(this);
654 fileName = chooser.getSelectedFile().getPath();
656 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
659 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
661 saveAlignment(fileName, currentFileFormat);
665 public boolean saveAlignment(String file, String format)
667 boolean success = true;
669 if (format.equalsIgnoreCase("Jalview"))
671 String shortName = title;
673 if (shortName.indexOf(java.io.File.separatorChar) > -1)
675 shortName = shortName.substring(shortName.lastIndexOf(
676 java.io.File.separatorChar) + 1);
679 success = new Jalview2XML().SaveAlignment(this, file, shortName);
681 statusBar.setText("Successfully saved to file: "
683 +format +" format.");
689 String[] omitHidden = null;
691 if (viewport.hasHiddenColumns)
693 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
694 "The Alignment contains hidden columns."
695 + "\nDo you want to save only the visible alignment?",
696 "Save / Omit Hidden Columns",
697 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
699 if (reply == JOptionPane.YES_OPTION)
700 omitHidden = viewport.getViewAsString(false);
703 String output = new FormatAdapter().formatSequences(
705 viewport.alignment.getSequencesArray(),
716 java.io.PrintWriter out = new java.io.PrintWriter(
717 new java.io.FileWriter(file));
722 statusBar.setText("Successfully saved to file: "
724 + format + " format.");
729 ex.printStackTrace();
735 JOptionPane.showInternalMessageDialog(
736 this, "Couldn't save file: " + fileName,
738 JOptionPane.WARNING_MESSAGE);
746 * @param e DOCUMENT ME!
748 protected void outputText_actionPerformed(ActionEvent e)
750 String [] omitHidden = null;
752 if(viewport.hasHiddenColumns)
754 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
755 "The Alignment contains hidden columns."
756 +"\nDo you want to output only the visible alignment?",
757 "Save / Omit Hidden Columns",
758 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
760 if(reply==JOptionPane.YES_OPTION)
762 omitHidden = viewport.getViewAsString(false);
766 CutAndPasteTransfer cap = new CutAndPasteTransfer();
767 cap.setForInput(null);
768 Desktop.addInternalFrame(cap,
769 "Alignment output - " + e.getActionCommand(), 600,
773 cap.setText(new FormatAdapter().formatSequences(
774 e.getActionCommand(),
775 viewport.alignment.getSequencesArray(),
782 * @param e DOCUMENT ME!
784 protected void htmlMenuItem_actionPerformed(ActionEvent e)
786 new HTMLOutput(viewport,
787 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
788 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
791 public void createImageMap(File file, String image)
793 alignPanel.makePNGImageMap(file, image);
799 * @param e DOCUMENT ME!
801 public void createPNG(File f)
803 alignPanel.makePNG(f);
809 * @param e DOCUMENT ME!
811 public void createEPS(File f)
813 alignPanel.makeEPS(f);
817 public void pageSetup_actionPerformed(ActionEvent e)
819 PrinterJob printJob = PrinterJob.getPrinterJob();
820 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
826 * @param e DOCUMENT ME!
828 public void printMenuItem_actionPerformed(ActionEvent e)
830 //Putting in a thread avoids Swing painting problems
831 PrintThread thread = new PrintThread(alignPanel);
835 public void exportFeatures_actionPerformed(ActionEvent e)
837 new AnnotationExporter().exportFeatures(alignPanel);
841 public void exportAnnotations_actionPerformed(ActionEvent e)
843 new AnnotationExporter().exportAnnotations(
845 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
846 viewport.alignment.getGroups()
851 public void associatedData_actionPerformed(ActionEvent e)
853 // Pick the tree file
854 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
857 chooser.setFileView(new JalviewFileView());
858 chooser.setDialogTitle("Load Jalview Annotations or Features File");
859 chooser.setToolTipText("Load Jalview Annotations / Features file");
861 int value = chooser.showOpenDialog(null);
863 if (value == JalviewFileChooser.APPROVE_OPTION)
865 String choice = chooser.getSelectedFile().getPath();
866 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
867 loadJalviewDataFile(choice);
876 * @param e DOCUMENT ME!
878 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
880 if(alignPanels!=null && alignPanels.size()<2)
885 if(alignPanels!=null)
888 for (int i = 0; i < alignPanels.size(); i++)
890 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
891 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
892 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
893 PaintRefresher.RemoveComponent(ap);
897 int index = tabbedPane.getSelectedIndex();
899 alignPanels.removeElement(alignPanel);
900 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
901 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
902 PaintRefresher.RemoveComponent(alignPanel);
906 tabbedPane.removeTabAt(index);
907 tabbedPane.validate();
909 if(index==tabbedPane.getTabCount())
912 this.tabSelectionChanged(index);
917 this.setClosed(true);
921 ex.printStackTrace();
929 void updateEditMenuBar()
932 if (viewport.historyList.size() > 0)
934 undoMenuItem.setEnabled(true);
935 CommandI command = (CommandI) viewport.historyList.peek();
936 undoMenuItem.setText("Undo " + command.getDescription());
940 undoMenuItem.setEnabled(false);
941 undoMenuItem.setText("Undo");
944 if (viewport.redoList.size() > 0)
946 redoMenuItem.setEnabled(true);
948 CommandI command = (CommandI) viewport.redoList.peek();
949 redoMenuItem.setText("Redo " + command.getDescription());
953 redoMenuItem.setEnabled(false);
954 redoMenuItem.setText("Redo");
959 public void addHistoryItem(CommandI command)
961 if(command.getSize()>0)
963 viewport.historyList.push(command);
964 viewport.redoList.clear();
966 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
975 * @param e DOCUMENT ME!
977 protected void undoMenuItem_actionPerformed(ActionEvent e)
979 CommandI command = (CommandI)viewport.historyList.pop();
980 viewport.redoList.push(command);
981 command.undoCommand();
983 AlignViewport originalSource = getOriginatingSource(command);
986 if(originalSource!=null)
988 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
989 originalSource.firePropertyChange("alignment",
991 originalSource.alignment.getSequences());
998 * @param e DOCUMENT ME!
1000 protected void redoMenuItem_actionPerformed(ActionEvent e)
1002 if(viewport.redoList.size()<1)
1005 CommandI command = (CommandI) viewport.redoList.pop();
1006 viewport.historyList.push(command);
1007 command.doCommand();
1009 AlignViewport originalSource = getOriginatingSource(command);
1010 updateEditMenuBar();
1012 if(originalSource!=null)
1014 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1015 originalSource.firePropertyChange("alignment",
1017 originalSource.alignment.getSequences());
1021 AlignViewport getOriginatingSource(CommandI command)
1023 AlignViewport originalSource = null;
1024 //For sequence removal and addition, we need to fire
1025 //the property change event FROM the viewport where the
1026 //original alignment was altered
1028 if (command instanceof EditCommand)
1030 EditCommand editCommand = (EditCommand) command;
1031 al = editCommand.getAlignment();
1032 Vector comps = (Vector) PaintRefresher.components
1033 .get(viewport.getSequenceSetId());
1035 for (int i = 0; i < comps.size(); i++)
1037 if (comps.elementAt(i) instanceof AlignmentPanel)
1039 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1041 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1048 if (originalSource == null)
1050 //The original view is closed, we must validate
1051 //the current view against the closed view first
1053 PaintRefresher.validateSequences(al, viewport.alignment);
1055 originalSource = viewport;
1058 return originalSource;
1064 * @param up DOCUMENT ME!
1066 public void moveSelectedSequences(boolean up)
1068 SequenceGroup sg = viewport.getSelectionGroup();
1077 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1079 SequenceI seq = viewport.alignment.getSequenceAt(i);
1081 if (!sg.getSequences(null).contains(seq))
1086 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1088 if (sg.getSequences(null).contains(temp))
1093 viewport.alignment.getSequences().setElementAt(temp, i);
1094 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1099 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1101 SequenceI seq = viewport.alignment.getSequenceAt(i);
1103 if (!sg.getSequences(null).contains(seq))
1108 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1110 if (sg.getSequences(null).contains(temp))
1115 viewport.alignment.getSequences().setElementAt(temp, i);
1116 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1120 alignPanel.repaint();
1128 * @param e DOCUMENT ME!
1130 protected void copy_actionPerformed(ActionEvent e)
1133 if (viewport.getSelectionGroup() == null)
1138 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1139 String[] omitHidden = null;
1141 if (viewport.hasHiddenColumns)
1143 omitHidden = viewport.getViewAsString(true);
1146 String output = new FormatAdapter().formatSequences(
1151 StringSelection ss = new StringSelection(output);
1155 jalview.gui.Desktop.internalCopy = true;
1156 //Its really worth setting the clipboard contents
1157 //to empty before setting the large StringSelection!!
1158 Toolkit.getDefaultToolkit().getSystemClipboard()
1159 .setContents(new StringSelection(""), null);
1161 Toolkit.getDefaultToolkit().getSystemClipboard()
1162 .setContents(ss, Desktop.instance);
1164 catch (OutOfMemoryError er)
1166 er.printStackTrace();
1167 javax.swing.SwingUtilities.invokeLater(new Runnable()
1171 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1172 "Out of memory copying region!!"
1174 "\nSee help files for increasing Java Virtual Machine memory."
1176 javax.swing.JOptionPane.WARNING_MESSAGE);
1183 Vector hiddenColumns = null;
1184 if(viewport.hasHiddenColumns)
1186 hiddenColumns =new Vector();
1187 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1188 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1190 int[] region = (int[])
1191 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1193 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1194 region[1]-hiddenOffset});
1200 Desktop.jalviewClipboard = new Object[]{ seqs,
1201 viewport.alignment.getDataset(),
1203 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1209 * @param e DOCUMENT ME!
1211 protected void pasteNew_actionPerformed(ActionEvent e)
1219 * @param e DOCUMENT ME!
1221 protected void pasteThis_actionPerformed(ActionEvent e)
1229 * @param newAlignment DOCUMENT ME!
1231 void paste(boolean newAlignment)
1235 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1236 Transferable contents = c.getContents(this);
1238 if (contents == null)
1246 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1247 if (str.length() < 1)
1250 format = new IdentifyFile().Identify(str, "Paste");
1253 catch (OutOfMemoryError er)
1255 er.printStackTrace();
1256 javax.swing.SwingUtilities.invokeLater(new Runnable()
1260 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1261 "Out of memory pasting sequences!!"
1263 "\nSee help files for increasing Java Virtual Machine memory."
1265 javax.swing.JOptionPane.WARNING_MESSAGE);
1272 SequenceI[] sequences;
1275 if(Desktop.jalviewClipboard!=null)
1277 // The clipboard was filled from within Jalview, we must use the sequences
1278 // And dataset from the copied alignment
1279 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1283 sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray();
1286 AlignmentI alignment = null;
1290 alignment = new Alignment(sequences);
1292 if (Desktop.jalviewClipboard != null)
1293 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1295 alignment.setDataset(null);
1299 alignment = viewport.getAlignment();
1302 SequenceI [] newseqs = new SequenceI[sequences.length];
1303 for (int i = 0; i < sequences.length; i++)
1305 newseqs[i] = new Sequence(sequences[i].getName(),
1306 sequences[i].getSequence(), sequences[i].getStart(),
1307 sequences[i].getEnd());
1309 alignment.addSequence(newseqs[i]);
1315 addHistoryItem(new EditCommand(
1320 alignment.getWidth(),
1325 viewport.setEndSeq(alignment.getHeight());
1326 alignment.getWidth();
1327 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1332 // Add any annotations attached to sequences
1333 for (int i = 0; i < sequences.length; i++)
1335 if (sequences[i].getAnnotation() != null)
1337 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1339 AlignmentAnnotation newAnnot =
1340 new AlignmentAnnotation(
1341 sequences[i].getAnnotation()[a].label,
1342 sequences[i].getAnnotation()[a].description,
1343 sequences[i].getAnnotation()[a].annotations,
1344 sequences[i].getAnnotation()[a].graphMin,
1345 sequences[i].getAnnotation()[a].graphMax,
1346 sequences[i].getAnnotation()[a].graph);
1348 sequences[i].getAnnotation()[a] = newAnnot;
1349 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1351 newAnnot.sequenceRef = sequences[i];
1352 newAnnot.adjustForAlignment();
1353 alignment.addAnnotation(newAnnot);
1354 alignment.setAnnotationIndex(newAnnot, a);
1357 alignPanel.annotationPanel.adjustPanelHeight();
1363 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1364 String newtitle = new String("Copied sequences");
1366 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1368 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1369 for(int i=0; i<hc.size(); i++)
1371 int [] region = (int[]) hc.elementAt(i);
1372 af.viewport.hideColumns(region[0], region[1]);
1377 //>>>This is a fix for the moment, until a better solution is found!!<<<
1378 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1379 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1382 if (title.startsWith("Copied sequences"))
1388 newtitle = newtitle.concat("- from " + title);
1391 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1398 catch (Exception ex)
1400 ex.printStackTrace();
1401 System.out.println("Exception whilst pasting: "+ex);
1402 // could be anything being pasted in here
1411 * @param e DOCUMENT ME!
1413 protected void cut_actionPerformed(ActionEvent e)
1415 copy_actionPerformed(null);
1416 delete_actionPerformed(null);
1422 * @param e DOCUMENT ME!
1424 protected void delete_actionPerformed(ActionEvent evt)
1427 SequenceGroup sg = viewport.getSelectionGroup();
1433 Vector seqs = new Vector();
1435 for (int i = 0; i < sg.getSize(); i++)
1437 seq = sg.getSequenceAt(i);
1438 seqs.addElement(seq);
1442 // If the cut affects all sequences, remove highlighted columns
1443 if (sg.getSize() == viewport.alignment.getHeight())
1445 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1446 sg.getEndRes() + 1);
1450 SequenceI [] cut = new SequenceI[seqs.size()];
1451 for(int i=0; i<seqs.size(); i++)
1452 cut[i] = (SequenceI)seqs.elementAt(i);
1458 addHistoryItem(new EditCommand("Cut Sequences",
1462 sg.getEndRes()-sg.getStartRes()+1,
1463 viewport.alignment));
1466 viewport.setSelectionGroup(null);
1467 viewport.alignment.deleteGroup(sg);
1469 viewport.firePropertyChange("alignment", null,
1470 viewport.getAlignment().getSequences());
1472 if (viewport.getAlignment().getHeight() < 1)
1476 this.setClosed(true);
1478 catch (Exception ex)
1487 * @param e DOCUMENT ME!
1489 protected void deleteGroups_actionPerformed(ActionEvent e)
1491 viewport.alignment.deleteAllGroups();
1492 viewport.sequenceColours = null;
1493 viewport.setSelectionGroup(null);
1494 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1495 alignPanel.repaint();
1501 * @param e DOCUMENT ME!
1503 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1505 SequenceGroup sg = new SequenceGroup();
1507 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1510 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1513 sg.setEndRes(viewport.alignment.getWidth() - 1);
1514 viewport.setSelectionGroup(sg);
1515 alignPanel.repaint();
1516 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1522 * @param e DOCUMENT ME!
1524 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1526 if(viewport.cursorMode)
1528 alignPanel.seqPanel.keyboardNo1 = null;
1529 alignPanel.seqPanel.keyboardNo2 = null;
1531 viewport.setSelectionGroup(null);
1532 viewport.getColumnSelection().clear();
1533 viewport.setSelectionGroup(null);
1534 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1535 alignPanel.idPanel.idCanvas.searchResults = null;
1536 alignPanel.repaint();
1537 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1543 * @param e DOCUMENT ME!
1545 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1547 SequenceGroup sg = viewport.getSelectionGroup();
1551 selectAllSequenceMenuItem_actionPerformed(null);
1556 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1559 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1562 alignPanel.repaint();
1564 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1567 public void invertColSel_actionPerformed(ActionEvent e)
1569 viewport.invertColumnSelection();
1570 alignPanel.repaint();
1577 * @param e DOCUMENT ME!
1579 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1581 trimAlignment(true);
1587 * @param e DOCUMENT ME!
1589 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1591 trimAlignment(false);
1594 void trimAlignment(boolean trimLeft)
1596 ColumnSelection colSel = viewport.getColumnSelection();
1599 if (colSel.size() > 0)
1602 column = colSel.getMin();
1604 column = colSel.getMax();
1607 if(viewport.getSelectionGroup()!=null)
1608 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1610 seqs = viewport.alignment.getSequencesArray();
1613 TrimRegionCommand trimRegion;
1616 trimRegion = new TrimRegionCommand("Remove Left",
1617 TrimRegionCommand.TRIM_LEFT,
1622 viewport.selectionGroup);
1623 viewport.setStartRes(0);
1627 trimRegion = new TrimRegionCommand("Remove Right",
1628 TrimRegionCommand.TRIM_RIGHT,
1633 viewport.selectionGroup);
1636 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1639 addHistoryItem(trimRegion);
1641 Vector groups = viewport.alignment.getGroups();
1643 for (int i = 0; i < groups.size(); i++)
1645 SequenceGroup sg = (SequenceGroup) groups.get(i);
1647 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1648 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1650 viewport.alignment.deleteGroup(sg);
1654 viewport.firePropertyChange("alignment", null,
1655 viewport.getAlignment().getSequences());
1662 * @param e DOCUMENT ME!
1664 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1666 int start = 0, end = viewport.alignment.getWidth()-1;
1669 if (viewport.getSelectionGroup() != null)
1671 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1672 start = viewport.getSelectionGroup().getStartRes();
1673 end = viewport.getSelectionGroup().getEndRes();
1676 seqs = viewport.alignment.getSequencesArray();
1679 RemoveGapColCommand removeGapCols =
1680 new RemoveGapColCommand("Remove Gapped Columns",
1683 viewport.alignment);
1685 addHistoryItem(removeGapCols);
1687 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1689 //This is to maintain viewport position on first residue
1691 SequenceI seq = viewport.alignment.getSequenceAt(0);
1692 int startRes = seq.findPosition(viewport.startRes);
1693 // ShiftList shifts;
1694 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1695 // edit.alColumnChanges=shifts.getInverse();
1696 // if (viewport.hasHiddenColumns)
1697 // viewport.getColumnSelection().compensateForEdits(shifts);
1698 viewport.setStartRes(seq.findIndex(startRes)-1);
1699 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1706 * @param e DOCUMENT ME!
1708 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1710 int start = 0, end = viewport.alignment.getWidth()-1;
1713 if (viewport.getSelectionGroup() != null)
1715 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
1716 start = viewport.getSelectionGroup().getStartRes();
1717 end = viewport.getSelectionGroup().getEndRes();
1720 seqs = viewport.alignment.getSequencesArray();
1722 //This is to maintain viewport position on first residue
1724 SequenceI seq = viewport.alignment.getSequenceAt(0);
1725 int startRes = seq.findPosition(viewport.startRes);
1727 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1730 viewport.alignment));
1732 viewport.setStartRes(seq.findIndex(startRes)-1);
1734 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1741 * @param e DOCUMENT ME!
1743 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1745 viewport.padGaps = padGapsMenuitem.isSelected();
1747 viewport.firePropertyChange("alignment",
1749 viewport.getAlignment().getSequences());
1755 * @param e DOCUMENT ME!
1757 public void findMenuItem_actionPerformed(ActionEvent e)
1762 public void newView_actionPerformed(ActionEvent e)
1764 AlignmentPanel newap =
1765 new Jalview2XML().copyAlignPanel(alignPanel, true);
1767 if (viewport.viewName == null)
1768 viewport.viewName = "Original";
1770 newap.av.historyList = viewport.historyList;
1771 newap.av.redoList = viewport.redoList;
1773 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1774 String newViewName = "View " +index;
1776 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1777 Vector existingNames = new Vector();
1778 for(int i=0; i<comps.size(); i++)
1780 if(comps.elementAt(i) instanceof AlignmentPanel)
1782 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1783 if(!existingNames.contains(ap.av.viewName))
1784 existingNames.addElement(ap.av.viewName);
1788 while(existingNames.contains(newViewName))
1790 newViewName = "View "+ (++index);
1793 newap.av.viewName = newViewName;
1795 addAlignmentPanel(newap, false);
1797 if(alignPanels.size()==2)
1799 viewport.gatherViewsHere = true;
1801 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1804 public void expandViews_actionPerformed(ActionEvent e)
1806 Desktop.instance.explodeViews(this);
1809 public void gatherViews_actionPerformed(ActionEvent e)
1811 Desktop.instance.gatherViews(this);
1819 * @param e DOCUMENT ME!
1821 public void font_actionPerformed(ActionEvent e)
1823 new FontChooser(alignPanel);
1830 * @param e DOCUMENT ME!
1832 protected void seqLimit_actionPerformed(ActionEvent e)
1834 viewport.setShowJVSuffix(seqLimits.isSelected());
1836 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1837 alignPanel.repaint();
1840 public void idRightAlign_actionPerformed(ActionEvent e)
1842 viewport.rightAlignIds = idRightAlign.isSelected();
1843 alignPanel.repaint();
1851 * @param e DOCUMENT ME!
1853 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1855 viewport.setColourText(colourTextMenuItem.isSelected());
1856 alignPanel.repaint();
1862 * @param e DOCUMENT ME!
1864 public void wrapMenuItem_actionPerformed(ActionEvent e)
1866 scaleAbove.setVisible(wrapMenuItem.isSelected());
1867 scaleLeft.setVisible(wrapMenuItem.isSelected());
1868 scaleRight.setVisible(wrapMenuItem.isSelected());
1869 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1870 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1873 public void showAllSeqs_actionPerformed(ActionEvent e)
1875 viewport.showAllHiddenSeqs();
1878 public void showAllColumns_actionPerformed(ActionEvent e)
1880 viewport.showAllHiddenColumns();
1884 public void hideSelSequences_actionPerformed(ActionEvent e)
1886 viewport.hideAllSelectedSeqs();
1887 alignPanel.repaint();
1890 public void hideSelColumns_actionPerformed(ActionEvent e)
1892 viewport.hideSelectedColumns();
1893 alignPanel.repaint();
1896 public void hiddenMarkers_actionPerformed(ActionEvent e)
1898 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1905 * @param e DOCUMENT ME!
1907 protected void scaleAbove_actionPerformed(ActionEvent e)
1909 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1910 alignPanel.repaint();
1916 * @param e DOCUMENT ME!
1918 protected void scaleLeft_actionPerformed(ActionEvent e)
1920 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1921 alignPanel.repaint();
1927 * @param e DOCUMENT ME!
1929 protected void scaleRight_actionPerformed(ActionEvent e)
1931 viewport.setScaleRightWrapped(scaleRight.isSelected());
1932 alignPanel.repaint();
1938 * @param e DOCUMENT ME!
1940 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1942 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1943 alignPanel.repaint();
1949 * @param e DOCUMENT ME!
1951 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1953 viewport.setShowText(viewTextMenuItem.isSelected());
1954 alignPanel.repaint();
1960 * @param e DOCUMENT ME!
1962 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1964 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1965 alignPanel.repaint();
1969 public FeatureSettings featureSettings;
1970 public void featureSettings_actionPerformed(ActionEvent e)
1972 if(featureSettings !=null )
1974 featureSettings.close();
1975 featureSettings = null;
1977 featureSettings = new FeatureSettings(this);
1983 * @param evt DOCUMENT ME!
1985 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1987 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1988 alignPanel.repaint();
1989 if (alignPanel.getOverviewPanel() != null)
1991 alignPanel.getOverviewPanel().updateOverviewImage();
1998 * @param e DOCUMENT ME!
2000 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2002 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2003 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2009 * @param e DOCUMENT ME!
2011 public void overviewMenuItem_actionPerformed(ActionEvent e)
2013 if (alignPanel.overviewPanel != null)
2018 JInternalFrame frame = new JInternalFrame();
2019 OverviewPanel overview = new OverviewPanel(alignPanel);
2020 frame.setContentPane(overview);
2021 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2022 frame.getWidth(), frame.getHeight());
2024 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2025 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2027 public void internalFrameClosed(
2028 javax.swing.event.InternalFrameEvent evt)
2030 alignPanel.setOverviewPanel(null);
2035 alignPanel.setOverviewPanel(overview);
2038 public void textColour_actionPerformed(ActionEvent e)
2040 new TextColourChooser().chooseColour(alignPanel, null);
2046 * @param e DOCUMENT ME!
2048 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2056 * @param e DOCUMENT ME!
2058 public void clustalColour_actionPerformed(ActionEvent e)
2060 changeColour(new ClustalxColourScheme(
2061 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2067 * @param e DOCUMENT ME!
2069 public void zappoColour_actionPerformed(ActionEvent e)
2071 changeColour(new ZappoColourScheme());
2077 * @param e DOCUMENT ME!
2079 public void taylorColour_actionPerformed(ActionEvent e)
2081 changeColour(new TaylorColourScheme());
2087 * @param e DOCUMENT ME!
2089 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2091 changeColour(new HydrophobicColourScheme());
2097 * @param e DOCUMENT ME!
2099 public void helixColour_actionPerformed(ActionEvent e)
2101 changeColour(new HelixColourScheme());
2107 * @param e DOCUMENT ME!
2109 public void strandColour_actionPerformed(ActionEvent e)
2111 changeColour(new StrandColourScheme());
2117 * @param e DOCUMENT ME!
2119 public void turnColour_actionPerformed(ActionEvent e)
2121 changeColour(new TurnColourScheme());
2127 * @param e DOCUMENT ME!
2129 public void buriedColour_actionPerformed(ActionEvent e)
2131 changeColour(new BuriedColourScheme());
2137 * @param e DOCUMENT ME!
2139 public void nucleotideColour_actionPerformed(ActionEvent e)
2141 changeColour(new NucleotideColourScheme());
2144 public void annotationColour_actionPerformed(ActionEvent e)
2146 new AnnotationColourChooser(viewport, alignPanel);
2153 * @param e DOCUMENT ME!
2155 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2157 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2163 * @param cs DOCUMENT ME!
2165 public void changeColour(ColourSchemeI cs)
2171 if (viewport.getAbovePIDThreshold())
2173 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2176 cs.setThreshold(threshold,
2177 viewport.getIgnoreGapsConsensus());
2179 viewport.setGlobalColourScheme(cs);
2183 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2186 if (viewport.getConservationSelected())
2189 Alignment al = (Alignment) viewport.alignment;
2190 Conservation c = new Conservation("All",
2191 ResidueProperties.propHash, 3,
2192 al.getSequences(), 0,
2196 c.verdict(false, viewport.ConsPercGaps);
2198 cs.setConservation(c);
2200 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2205 cs.setConservation(null);
2208 cs.setConsensus(viewport.hconsensus);
2211 viewport.setGlobalColourScheme(cs);
2213 if (viewport.getColourAppliesToAllGroups())
2215 Vector groups = viewport.alignment.getGroups();
2217 for (int i = 0; i < groups.size(); i++)
2219 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2227 if (cs instanceof ClustalxColourScheme)
2229 sg.cs = new ClustalxColourScheme(
2230 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2232 else if (cs instanceof UserColourScheme)
2234 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2240 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2242 catch (Exception ex)
2247 if (viewport.getAbovePIDThreshold()
2248 || cs instanceof PIDColourScheme
2249 || cs instanceof Blosum62ColourScheme)
2251 sg.cs.setThreshold(threshold,
2252 viewport.getIgnoreGapsConsensus());
2254 sg.cs.setConsensus(AAFrequency.calculate(
2255 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2259 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2262 if (viewport.getConservationSelected())
2264 Conservation c = new Conservation("Group",
2265 ResidueProperties.propHash, 3,
2266 sg.getSequences(viewport.hiddenRepSequences),
2270 c.verdict(false, viewport.ConsPercGaps);
2271 sg.cs.setConservation(c);
2274 sg.cs.setConservation(null);
2278 if (alignPanel.getOverviewPanel() != null)
2280 alignPanel.getOverviewPanel().updateOverviewImage();
2283 alignPanel.repaint();
2289 * @param e DOCUMENT ME!
2291 protected void modifyPID_actionPerformed(ActionEvent e)
2293 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2295 SliderPanel.setPIDSliderSource(alignPanel,
2296 viewport.getGlobalColourScheme(),
2298 SliderPanel.showPIDSlider();
2305 * @param e DOCUMENT ME!
2307 protected void modifyConservation_actionPerformed(ActionEvent e)
2309 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2311 SliderPanel.setConservationSlider(alignPanel,
2312 viewport.globalColourScheme,
2314 SliderPanel.showConservationSlider();
2321 * @param e DOCUMENT ME!
2323 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2325 viewport.setConservationSelected(conservationMenuItem.isSelected());
2327 viewport.setAbovePIDThreshold(false);
2328 abovePIDThreshold.setSelected(false);
2330 changeColour(viewport.getGlobalColourScheme());
2332 modifyConservation_actionPerformed(null);
2338 * @param e DOCUMENT ME!
2340 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2342 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2344 conservationMenuItem.setSelected(false);
2345 viewport.setConservationSelected(false);
2347 changeColour(viewport.getGlobalColourScheme());
2349 modifyPID_actionPerformed(null);
2355 * @param e DOCUMENT ME!
2357 public void userDefinedColour_actionPerformed(ActionEvent e)
2359 if (e.getActionCommand().equals("User Defined..."))
2361 new UserDefinedColours(alignPanel, null);
2365 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2366 getUserColourSchemes().get(e.getActionCommand());
2372 public void updateUserColourMenu()
2375 Component[] menuItems = colourMenu.getMenuComponents();
2376 int i, iSize = menuItems.length;
2377 for (i = 0; i < iSize; i++)
2379 if (menuItems[i].getName() != null &&
2380 menuItems[i].getName().equals("USER_DEFINED"))
2382 colourMenu.remove(menuItems[i]);
2386 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2388 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2389 getUserColourSchemes().keys();
2391 while (userColours.hasMoreElements())
2393 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2394 nextElement().toString());
2395 radioItem.setName("USER_DEFINED");
2396 radioItem.addMouseListener(new MouseAdapter()
2398 public void mousePressed(MouseEvent evt)
2400 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2402 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2404 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2405 "Remove from default list?",
2406 "Remove user defined colour",
2407 JOptionPane.YES_NO_OPTION);
2408 if(option == JOptionPane.YES_OPTION)
2410 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2411 colourMenu.remove(radioItem);
2414 radioItem.addActionListener(new ActionListener()
2416 public void actionPerformed(ActionEvent evt)
2418 userDefinedColour_actionPerformed(evt);
2424 radioItem.addActionListener(new ActionListener()
2426 public void actionPerformed(ActionEvent evt)
2428 userDefinedColour_actionPerformed(evt);
2432 colourMenu.insert(radioItem, 15);
2433 colours.add(radioItem);
2441 * @param e DOCUMENT ME!
2443 public void PIDColour_actionPerformed(ActionEvent e)
2445 changeColour(new PIDColourScheme());
2451 * @param e DOCUMENT ME!
2453 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2455 changeColour(new Blosum62ColourScheme());
2461 * @param e DOCUMENT ME!
2463 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2465 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2466 AlignmentSorter.sortByPID(viewport.getAlignment(),
2467 viewport.getAlignment().getSequenceAt(0));
2468 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2469 alignPanel.repaint();
2475 * @param e DOCUMENT ME!
2477 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2479 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2480 AlignmentSorter.sortByID(viewport.getAlignment());
2481 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2482 alignPanel.repaint();
2488 * @param e DOCUMENT ME!
2490 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2492 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2493 AlignmentSorter.sortByGroup(viewport.getAlignment());
2494 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2496 alignPanel.repaint();
2502 * @param e DOCUMENT ME!
2504 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2506 new RedundancyPanel(alignPanel, this);
2513 * @param e DOCUMENT ME!
2515 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2517 if ( (viewport.getSelectionGroup() == null) ||
2518 (viewport.getSelectionGroup().getSize() < 2))
2520 JOptionPane.showInternalMessageDialog(this,
2521 "You must select at least 2 sequences.",
2522 "Invalid Selection",
2523 JOptionPane.WARNING_MESSAGE);
2527 JInternalFrame frame = new JInternalFrame();
2528 frame.setContentPane(new PairwiseAlignPanel(viewport));
2529 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2536 * @param e DOCUMENT ME!
2538 public void PCAMenuItem_actionPerformed(ActionEvent e)
2540 if ( ( (viewport.getSelectionGroup() != null) &&
2541 (viewport.getSelectionGroup().getSize() < 4) &&
2542 (viewport.getSelectionGroup().getSize() > 0)) ||
2543 (viewport.getAlignment().getHeight() < 4))
2545 JOptionPane.showInternalMessageDialog(this,
2546 "Principal component analysis must take\n" +
2547 "at least 4 input sequences.",
2548 "Sequence selection insufficient",
2549 JOptionPane.WARNING_MESSAGE);
2554 new PCAPanel(alignPanel);
2558 public void autoCalculate_actionPerformed(ActionEvent e)
2560 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2561 if(viewport.autoCalculateConsensus)
2563 viewport.firePropertyChange("alignment",
2565 viewport.getAlignment().getSequences());
2573 * @param e DOCUMENT ME!
2575 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2577 NewTreePanel("AV", "PID", "Average distance tree using PID");
2583 * @param e DOCUMENT ME!
2585 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2587 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2593 * @param e DOCUMENT ME!
2595 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2597 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2603 * @param e DOCUMENT ME!
2605 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2607 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2613 * @param type DOCUMENT ME!
2614 * @param pwType DOCUMENT ME!
2615 * @param title DOCUMENT ME!
2617 void NewTreePanel(String type, String pwType, String title)
2621 if (viewport.getSelectionGroup() != null) {
2622 if (viewport.getSelectionGroup().getSize() < 3) {
2623 JOptionPane.showMessageDialog(Desktop.desktop,
2624 "You need to have more than two sequences selected to build a tree!",
2625 "Not enough sequences",
2626 JOptionPane.WARNING_MESSAGE);
2631 SequenceGroup sg = viewport.getSelectionGroup();
2633 /* Decide if the selection is a column region */
2634 while (s < sg.getSize())
2636 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2639 JOptionPane.showMessageDialog(Desktop.desktop,
2640 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2641 "Try using the Pad function in the edit menu,\n" +
2642 "or one of the multiple sequence alignment web services.",
2643 "Sequences in selection are not aligned",
2644 JOptionPane.WARNING_MESSAGE);
2650 title = title + " on region";
2651 tp = new TreePanel(alignPanel, type, pwType);
2655 //are the sequences aligned?
2656 if (!viewport.alignment.isAligned())
2658 JOptionPane.showMessageDialog(Desktop.desktop,
2659 "The sequences must be aligned before creating a tree.\n" +
2660 "Try using the Pad function in the edit menu,\n" +
2661 "or one of the multiple sequence alignment web services.",
2662 "Sequences not aligned",
2663 JOptionPane.WARNING_MESSAGE);
2668 if(viewport.alignment.getHeight()<2)
2671 tp = new TreePanel(alignPanel, type, pwType);
2676 if(viewport.viewName!=null)
2677 title+= viewport.viewName+" of ";
2679 title += this.title;
2681 Desktop.addInternalFrame(tp, title, 600, 500);
2687 * @param title DOCUMENT ME!
2688 * @param order DOCUMENT ME!
2690 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2692 final JMenuItem item = new JMenuItem("by " + title);
2694 item.addActionListener(new java.awt.event.ActionListener()
2696 public void actionPerformed(ActionEvent e)
2698 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2700 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2701 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2703 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2705 alignPanel.repaint();
2711 * Maintain the Order by->Displayed Tree menu.
2712 * Creates a new menu item for a TreePanel with an appropriate
2713 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2714 * to remove the menu item when the treePanel is closed, and adjust
2715 * the tree leaf to sequence mapping when the alignment is modified.
2716 * @param treePanel Displayed tree window.
2717 * @param title SortBy menu item title.
2719 public void buildTreeMenu()
2721 sortByTreeMenu.removeAll();
2723 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2724 Vector treePanels = new Vector();
2725 int i, iSize = comps.size();
2726 for(i=0; i<iSize; i++)
2728 if(comps.elementAt(i) instanceof TreePanel)
2730 treePanels.add(comps.elementAt(i));
2734 iSize = treePanels.size();
2738 sortByTreeMenu.setVisible(false);
2742 sortByTreeMenu.setVisible(true);
2744 for(i=0; i<treePanels.size(); i++)
2746 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2747 final JMenuItem item = new JMenuItem(tp.getTitle());
2748 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2749 item.addActionListener(new java.awt.event.ActionListener()
2751 public void actionPerformed(ActionEvent e)
2753 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2754 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2756 addHistoryItem(new OrderCommand("Tree Sort",
2758 viewport.alignment));
2760 alignPanel.repaint();
2764 sortByTreeMenu.add(item);
2769 * Work out whether the whole set of sequences
2770 * or just the selected set will be submitted for multiple alignment.
2773 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2775 // Now, check we have enough sequences
2776 AlignmentView msa = null;
2778 if ( (viewport.getSelectionGroup() != null) &&
2779 (viewport.getSelectionGroup().getSize() > 1))
2781 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2782 /*SequenceGroup seqs = viewport.getSelectionGroup();
2784 msa = new SequenceI[sz = seqs.getSize(false)];
2786 for (int i = 0; i < sz; i++)
2788 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2790 msa = viewport.getAlignmentView(true);
2794 /*Vector seqs = viewport.getAlignment().getSequences();
2796 if (seqs.size() > 1)
2798 msa = new SequenceI[seqs.size()];
2800 for (int i = 0; i < seqs.size(); i++)
2802 msa[i] = (SequenceI) seqs.elementAt(i);
2805 msa = viewport.getAlignmentView(false);
2811 * Decides what is submitted to a secondary structure prediction service,
2812 * the currently selected sequence, or the currently selected alignment
2813 * (where the first sequence in the set is the one that the prediction
2816 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2818 AlignmentView seqs = null;
2820 if ( (viewport.getSelectionGroup() != null) &&
2821 (viewport.getSelectionGroup().getSize() > 0))
2823 seqs = viewport.getAlignmentView(true);
2827 seqs = viewport.getAlignmentView(false);
2829 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2830 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2831 if (!viewport.alignment.isAligned())
2833 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2840 * @param e DOCUMENT ME!
2842 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2844 // Pick the tree file
2845 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2848 chooser.setFileView(new JalviewFileView());
2849 chooser.setDialogTitle("Select a newick-like tree file");
2850 chooser.setToolTipText("Load a tree file");
2852 int value = chooser.showOpenDialog(null);
2854 if (value == JalviewFileChooser.APPROVE_OPTION)
2856 String choice = chooser.getSelectedFile().getPath();
2857 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2861 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2863 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2865 catch (Exception ex)
2867 JOptionPane.showMessageDialog(Desktop.desktop,
2868 "Problem reading tree file",
2870 JOptionPane.WARNING_MESSAGE);
2871 ex.printStackTrace();
2877 public TreePanel ShowNewickTree(NewickFile nf, String title)
2879 return ShowNewickTree(nf,title,600,500,4,5);
2881 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2883 return ShowNewickTree(nf,title, input, 600,500,4,5);
2885 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2886 return ShowNewickTree(nf, title, null, w, h, x, y);
2889 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2891 * @param nf the tree
2892 * @param title tree viewer title
2893 * @param input Associated alignment input data (or null)
2898 * @return TreePanel handle
2900 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2901 TreePanel tp = null;
2907 if (nf.getTree() != null)
2909 tp = new TreePanel(alignPanel,
2917 tp.setLocation(x,y);
2920 Desktop.addInternalFrame(tp, title, w, h);
2923 catch (Exception ex)
2925 ex.printStackTrace();
2933 * Generates menu items and listener event actions for web service clients
2936 public void BuildWebServiceMenu()
2938 if ( (Discoverer.services != null)
2939 && (Discoverer.services.size() > 0))
2941 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2942 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2943 Vector wsmenu = new Vector();
2944 final AlignFrame af = this;
2947 // Add any Multiple Sequence Alignment Services
2948 final JMenu msawsmenu = new JMenu("Alignment");
2949 for (int i = 0, j = msaws.size(); i < j; i++)
2951 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2953 final JMenuItem method = new JMenuItem(sh.getName());
2954 method.addActionListener(new ActionListener()
2956 public void actionPerformed(ActionEvent e)
2958 AlignmentView msa = gatherSequencesForAlignment();
2959 new jalview.ws.MsaWSClient(sh, title, msa,
2960 false, true, viewport.getAlignment().getDataset(), af);
2965 msawsmenu.add(method);
2966 // Deal with services that we know accept partial alignments.
2967 if (sh.getName().indexOf("lustal") > -1)
2969 // We know that ClustalWS can accept partial alignments for refinement.
2970 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2971 methodR.addActionListener(new ActionListener()
2973 public void actionPerformed(ActionEvent e)
2975 AlignmentView msa = gatherSequencesForAlignment();
2976 new jalview.ws.MsaWSClient(sh, title, msa,
2977 true, true, viewport.getAlignment().getDataset(), af);
2982 msawsmenu.add(methodR);
2986 wsmenu.add(msawsmenu);
2988 if (secstrpr != null)
2990 // Add any secondary structure prediction services
2991 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2992 for (int i = 0, j = secstrpr.size(); i < j; i++)
2994 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2996 final JMenuItem method = new JMenuItem(sh.getName());
2997 method.addActionListener(new ActionListener()
2999 public void actionPerformed(ActionEvent e)
3001 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3002 if (msa.getSequences().length == 1)
3004 // Single Sequence prediction
3005 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3009 if (msa.getSequences().length > 1)
3011 // Sequence profile based prediction
3012 new jalview.ws.JPredClient(sh,
3013 title, true, msa, af, true);
3018 secstrmenu.add(method);
3020 wsmenu.add(secstrmenu);
3022 this.webService.removeAll();
3023 for (int i = 0, j = wsmenu.size(); i < j; i++)
3025 webService.add( (JMenu) wsmenu.get(i));
3030 this.webService.removeAll();
3031 this.webService.add(this.webServiceNoServices);
3033 // TODO: add in rediscovery function
3034 // TODO: reduce code redundancy.
3035 // TODO: group services by location as well as function.
3038 /* public void vamsasStore_actionPerformed(ActionEvent e)
3040 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3041 getProperty("LAST_DIRECTORY"));
3043 chooser.setFileView(new JalviewFileView());
3044 chooser.setDialogTitle("Export to Vamsas file");
3045 chooser.setToolTipText("Export");
3047 int value = chooser.showSaveDialog(this);
3049 if (value == JalviewFileChooser.APPROVE_OPTION)
3051 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3052 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3053 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3060 public void showTranslation_actionPerformed(ActionEvent e)
3062 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3063 String [] seqstring = viewport.getViewAsString(true);
3065 int s, sSize = selection.length;
3066 SequenceI [] newSeq = new SequenceI[sSize];
3069 StringBuffer protein;
3071 for(s=0; s<sSize; s++)
3073 protein = new StringBuffer();
3074 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3075 resSize = seq.length();
3076 resSize -= resSize%3;
3078 for(res = 0; res < resSize; res+=3)
3080 String codon = seq.substring(res, res+3);
3081 codon = codon.replace('U', 'T');
3082 String aa = ResidueProperties.codonTranslate(codon);
3084 protein.append(viewport.getGapCharacter());
3085 else if(aa.equals("STOP"))
3086 protein.append("X");
3088 protein.append( aa );
3090 newSeq[s] = new Sequence(selection[s].getName(),
3091 protein.toString());
3095 AlignmentI al = new Alignment(newSeq);
3096 al.setDataset(null);
3099 ////////////////////////////////
3100 // Copy annotations across
3101 jalview.datamodel.AlignmentAnnotation[] annotations
3102 = viewport.alignment.getAlignmentAnnotation();
3104 if(annotations!=null)
3106 for (int i = 0; i < annotations.length; i++)
3108 if (annotations[i]==viewport.quality ||
3109 annotations[i]==viewport.conservation ||
3110 annotations[i]==viewport.consensus)
3112 System.out.println("COPT HERE");
3116 aSize = viewport.alignment.getWidth() / 3;
3117 jalview.datamodel.Annotation[] anots =
3118 new jalview.datamodel.Annotation[aSize];
3120 for (a = 0; a < viewport.alignment.getWidth(); a++)
3122 if (annotations[i].annotations[a] == null
3123 || annotations[i].annotations[a] == null)
3126 anots[a / 3] = new Annotation(
3127 annotations[i].annotations[a].displayCharacter,
3128 annotations[i].annotations[a].description,
3129 annotations[i].annotations[a].secondaryStructure,
3130 annotations[i].annotations[a].value,
3131 annotations[i].annotations[a].colour);
3134 jalview.datamodel.AlignmentAnnotation aa
3135 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3136 annotations[i].description, anots);
3137 al.addAnnotation(aa);
3141 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3142 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3154 * @param String DOCUMENT ME!
3156 public boolean parseFeaturesFile(String file, String type)
3158 boolean featuresFile = false;
3160 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3161 alignPanel.seqPanel.seqCanvas.
3162 getFeatureRenderer().featureColours,
3167 ex.printStackTrace();
3172 viewport.showSequenceFeatures = true;
3173 showSeqFeatures.setSelected(true);
3174 alignPanel.repaint();
3177 return featuresFile;
3180 public void dragEnter(DropTargetDragEvent evt)
3183 public void dragExit(DropTargetEvent evt)
3186 public void dragOver(DropTargetDragEvent evt)
3189 public void dropActionChanged(DropTargetDragEvent evt)
3192 public void drop(DropTargetDropEvent evt)
3194 Transferable t = evt.getTransferable();
3195 java.util.List files = null;
3199 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3200 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3202 //Works on Windows and MacOSX
3203 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3204 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3206 else if (t.isDataFlavorSupported(uriListFlavor))
3208 // This is used by Unix drag system
3209 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3210 String data = (String) t.getTransferData(uriListFlavor);
3211 files = new java.util.ArrayList(1);
3212 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3215 st.hasMoreTokens(); )
3217 String s = st.nextToken();
3218 if (s.startsWith("#"))
3220 // the line is a comment (as per the RFC 2483)
3224 java.net.URI uri = new java.net.URI(s);
3225 java.io.File file = new java.io.File(uri);
3232 e.printStackTrace();
3239 for (int i = 0; i < files.size(); i++)
3241 loadJalviewDataFile(files.get(i).toString());
3244 catch (Exception ex)
3246 ex.printStackTrace();
3251 // This method will attempt to load a "dropped" file first by testing
3252 // whether its and Annotation file, then features file. If both are
3253 // false then the user may have dropped an alignment file onto this
3255 public void loadJalviewDataFile(String file)
3258 String protocol = "File";
3260 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3265 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3266 alignment, file, protocol);
3270 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3273 String format = new IdentifyFile().Identify(file, protocol);
3275 if(format.equalsIgnoreCase("JnetFile"))
3277 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3279 new JnetAnnotationMaker().add_annotation(predictions,
3280 viewport.getAlignment(),
3282 alignPanel.adjustAnnotationHeight();
3283 alignPanel.repaint();
3286 new FileLoader().LoadFile(viewport, file, protocol, format);
3292 alignPanel.adjustAnnotationHeight();
3295 }catch(Exception ex)
3297 ex.printStackTrace();
3301 public void tabSelectionChanged(int index)
3305 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3306 viewport = alignPanel.av;
3307 setMenusFromViewport(viewport);
3311 public void tabbedPane_mousePressed(MouseEvent e)
3313 if(SwingUtilities.isRightMouseButton(e))
3315 String reply = JOptionPane.showInternalInputDialog(this,
3318 JOptionPane.QUESTION_MESSAGE);
3322 viewport.viewName = reply;
3323 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3329 public AlignViewport getCurrentView()
3335 class PrintThread extends Thread
3338 public PrintThread(AlignmentPanel ap)
3342 static PageFormat pf;
3345 PrinterJob printJob = PrinterJob.getPrinterJob();
3348 printJob.setPrintable(ap, pf);
3350 printJob.setPrintable(ap);
3352 if (printJob.printDialog())
3358 catch (Exception PrintException)
3360 PrintException.printStackTrace();