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(false) != 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);
831 * @param e DOCUMENT ME!
833 public void printMenuItem_actionPerformed(ActionEvent e)
835 //Putting in a thread avoids Swing painting problems
836 PrintThread thread = new PrintThread();
840 public void exportFeatures_actionPerformed(ActionEvent e)
842 new AnnotationExporter().exportFeatures(alignPanel);
846 public void exportAnnotations_actionPerformed(ActionEvent e)
848 new AnnotationExporter().exportAnnotations(
850 viewport.alignment.getAlignmentAnnotation()
855 public void associatedData_actionPerformed(ActionEvent e)
857 // Pick the tree file
858 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
861 chooser.setFileView(new JalviewFileView());
862 chooser.setDialogTitle("Load Jalview Annotations or Features File");
863 chooser.setToolTipText("Load Jalview Annotations / Features file");
865 int value = chooser.showOpenDialog(null);
867 if (value == JalviewFileChooser.APPROVE_OPTION)
869 String choice = chooser.getSelectedFile().getPath();
870 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
871 loadJalviewDataFile(choice);
880 * @param e DOCUMENT ME!
882 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
884 if(alignPanels!=null && alignPanels.size()<2)
889 if(alignPanels!=null)
892 for (int i = 0; i < alignPanels.size(); i++)
894 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
895 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
896 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
897 PaintRefresher.RemoveComponent(ap);
901 int index = tabbedPane.getSelectedIndex();
903 alignPanels.removeElement(alignPanel);
904 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
905 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
906 PaintRefresher.RemoveComponent(alignPanel);
910 tabbedPane.removeTabAt(index);
911 tabbedPane.validate();
913 if(index==tabbedPane.getTabCount())
916 this.tabSelectionChanged(index);
921 this.setClosed(true);
925 ex.printStackTrace();
933 void updateEditMenuBar()
936 if (viewport.historyList.size() > 0)
938 undoMenuItem.setEnabled(true);
939 CommandI command = (CommandI) viewport.historyList.peek();
940 undoMenuItem.setText("Undo " + command.getDescription());
944 undoMenuItem.setEnabled(false);
945 undoMenuItem.setText("Undo");
948 if (viewport.redoList.size() > 0)
950 redoMenuItem.setEnabled(true);
952 CommandI command = (CommandI) viewport.redoList.peek();
953 redoMenuItem.setText("Redo " + command.getDescription());
957 redoMenuItem.setEnabled(false);
958 redoMenuItem.setText("Redo");
963 public void addHistoryItem(CommandI command)
965 if(command.getSize()>0)
967 viewport.historyList.push(command);
968 viewport.redoList.clear();
970 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
979 * @param e DOCUMENT ME!
981 protected void undoMenuItem_actionPerformed(ActionEvent e)
983 CommandI command = (CommandI)viewport.historyList.pop();
984 viewport.redoList.push(command);
985 command.undoCommand();
987 AlignViewport originalSource = getOriginatingSource(command);
990 if(originalSource!=null)
992 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
993 originalSource.firePropertyChange("alignment",
995 originalSource.alignment.getSequences());
1002 * @param e DOCUMENT ME!
1004 protected void redoMenuItem_actionPerformed(ActionEvent e)
1006 if(viewport.redoList.size()<1)
1009 CommandI command = (CommandI) viewport.redoList.pop();
1010 viewport.historyList.push(command);
1011 command.doCommand();
1013 AlignViewport originalSource = getOriginatingSource(command);
1014 updateEditMenuBar();
1016 if(originalSource!=null)
1018 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1019 originalSource.firePropertyChange("alignment",
1021 originalSource.alignment.getSequences());
1025 AlignViewport getOriginatingSource(CommandI command)
1027 AlignViewport originalSource = null;
1028 //For sequence removal and addition, we need to fire
1029 //the property change event FROM the viewport where the
1030 //original alignment was altered
1032 if (command instanceof EditCommand)
1034 EditCommand editCommand = (EditCommand) command;
1035 al = editCommand.getAlignment();
1036 Vector comps = (Vector) PaintRefresher.components
1037 .get(viewport.getSequenceSetId());
1039 for (int i = 0; i < comps.size(); i++)
1041 if (comps.elementAt(i) instanceof AlignmentPanel)
1043 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1045 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1052 if (originalSource == null)
1054 //The original view is closed, we must validate
1055 //the current view against the closed view first
1057 PaintRefresher.validateSequences(al, viewport.alignment);
1059 originalSource = viewport;
1062 return originalSource;
1068 * @param up DOCUMENT ME!
1070 public void moveSelectedSequences(boolean up)
1072 SequenceGroup sg = viewport.getSelectionGroup();
1081 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1083 SequenceI seq = viewport.alignment.getSequenceAt(i);
1085 if (!sg.getSequences(false).contains(seq))
1090 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1092 if (sg.getSequences(false).contains(temp))
1097 viewport.alignment.getSequences().setElementAt(temp, i);
1098 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1103 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1105 SequenceI seq = viewport.alignment.getSequenceAt(i);
1107 if (!sg.getSequences(false).contains(seq))
1112 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1114 if (sg.getSequences(false).contains(temp))
1119 viewport.alignment.getSequences().setElementAt(temp, i);
1120 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1124 alignPanel.repaint();
1132 * @param e DOCUMENT ME!
1134 protected void copy_actionPerformed(ActionEvent e)
1137 if (viewport.getSelectionGroup() == null)
1142 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1143 String[] omitHidden = null;
1145 if (viewport.hasHiddenColumns)
1147 omitHidden = viewport.getViewAsString(true);
1150 String output = new FormatAdapter().formatSequences(
1155 StringSelection ss = new StringSelection(output);
1159 //Its really worth setting the clipboard contents
1160 //to empty before setting the large StringSelection!!
1161 Toolkit.getDefaultToolkit().getSystemClipboard()
1162 .setContents(new StringSelection(""), null);
1164 Toolkit.getDefaultToolkit().getSystemClipboard()
1165 .setContents(ss, Desktop.instance);
1167 catch (OutOfMemoryError er)
1169 er.printStackTrace();
1170 javax.swing.SwingUtilities.invokeLater(new Runnable()
1174 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1175 "Out of memory copying region!!"
1177 "\nSee help files for increasing Java Virtual Machine memory."
1179 javax.swing.JOptionPane.WARNING_MESSAGE);
1186 Vector hiddenColumns = null;
1187 if(viewport.hasHiddenColumns)
1189 hiddenColumns =new Vector();
1190 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1191 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1193 int[] region = (int[])
1194 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1196 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1197 region[1]-hiddenOffset});
1203 Desktop.jalviewClipboard = new Object[]{ seqs,
1204 viewport.alignment.getDataset(),
1206 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1212 * @param e DOCUMENT ME!
1214 protected void pasteNew_actionPerformed(ActionEvent e)
1222 * @param e DOCUMENT ME!
1224 protected void pasteThis_actionPerformed(ActionEvent e)
1232 * @param newAlignment DOCUMENT ME!
1234 void paste(boolean newAlignment)
1238 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1239 Transferable contents = c.getContents(this);
1241 if (contents == null)
1249 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1250 if (str.length() < 1)
1253 format = new IdentifyFile().Identify(str, "Paste");
1256 catch (OutOfMemoryError er)
1258 er.printStackTrace();
1259 javax.swing.SwingUtilities.invokeLater(new Runnable()
1263 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1264 "Out of memory pasting sequences!!"
1266 "\nSee help files for increasing Java Virtual Machine memory."
1268 javax.swing.JOptionPane.WARNING_MESSAGE);
1275 SequenceI[] sequences;
1278 if(Desktop.jalviewClipboard!=null)
1280 // The clipboard was filled from within Jalview, we must use the sequences
1281 // And dataset from the copied alignment
1282 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1286 sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray();
1289 AlignmentI alignment = null;
1293 alignment = new Alignment(sequences);
1295 if (Desktop.jalviewClipboard != null)
1296 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1298 alignment.setDataset(null);
1302 alignment = viewport.getAlignment();
1305 SequenceI [] newseqs = new SequenceI[sequences.length];
1306 for (int i = 0; i < sequences.length; i++)
1308 newseqs[i] = new Sequence(sequences[i].getName(),
1309 sequences[i].getSequence(), sequences[i].getStart(),
1310 sequences[i].getEnd());
1312 alignment.addSequence(newseqs[i]);
1318 addHistoryItem(new EditCommand(
1323 alignment.getWidth(),
1328 viewport.setEndSeq(alignment.getHeight());
1329 alignment.getWidth();
1330 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1335 // Add any annotations attached to sequences
1336 for (int i = 0; i < sequences.length; i++)
1338 if (sequences[i].getAnnotation() != null)
1340 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1342 AlignmentAnnotation newAnnot =
1343 new AlignmentAnnotation(
1344 sequences[i].getAnnotation()[a].label,
1345 sequences[i].getAnnotation()[a].description,
1346 sequences[i].getAnnotation()[a].annotations,
1347 sequences[i].getAnnotation()[a].graphMin,
1348 sequences[i].getAnnotation()[a].graphMax,
1349 sequences[i].getAnnotation()[a].graph);
1351 sequences[i].getAnnotation()[a] = newAnnot;
1352 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1354 newAnnot.sequenceRef = sequences[i];
1355 newAnnot.adjustForAlignment();
1356 alignment.addAnnotation(newAnnot);
1357 alignment.setAnnotationIndex(newAnnot, a);
1360 alignPanel.annotationPanel.adjustPanelHeight();
1366 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1367 String newtitle = new String("Copied sequences");
1369 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1371 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1372 for(int i=0; i<hc.size(); i++)
1374 int [] region = (int[]) hc.elementAt(i);
1375 af.viewport.hideColumns(region[0], region[1]);
1380 //>>>This is a fix for the moment, until a better solution is found!!<<<
1381 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1382 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1385 if (title.startsWith("Copied sequences"))
1391 newtitle = newtitle.concat("- from " + title);
1394 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1401 catch (Exception ex)
1403 ex.printStackTrace();
1404 System.out.println("Exception whilst pasting: "+ex);
1405 // could be anything being pasted in here
1414 * @param e DOCUMENT ME!
1416 protected void cut_actionPerformed(ActionEvent e)
1418 copy_actionPerformed(null);
1419 delete_actionPerformed(null);
1425 * @param e DOCUMENT ME!
1427 protected void delete_actionPerformed(ActionEvent evt)
1430 SequenceGroup sg = viewport.getSelectionGroup();
1436 Vector seqs = new Vector();
1438 for (int i = 0; i < sg.getSize(false); i++)
1440 seq = sg.getSequenceAt(i);
1441 seqs.addElement(seq);
1445 // If the cut affects all sequences, remove highlighted columns
1446 if (sg.getSize(false) == viewport.alignment.getHeight())
1448 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1449 sg.getEndRes() + 1);
1453 SequenceI [] cut = new SequenceI[seqs.size()];
1454 for(int i=0; i<seqs.size(); i++)
1455 cut[i] = (SequenceI)seqs.elementAt(i);
1461 addHistoryItem(new EditCommand("Cut Sequences",
1465 sg.getEndRes()-sg.getStartRes()+1,
1466 viewport.alignment));
1469 viewport.setSelectionGroup(null);
1470 viewport.alignment.deleteGroup(sg);
1472 viewport.firePropertyChange("alignment", null,
1473 viewport.getAlignment().getSequences());
1475 if (viewport.getAlignment().getHeight() < 1)
1479 this.setClosed(true);
1481 catch (Exception ex)
1490 * @param e DOCUMENT ME!
1492 protected void deleteGroups_actionPerformed(ActionEvent e)
1494 viewport.alignment.deleteAllGroups();
1495 viewport.sequenceColours = null;
1496 viewport.setSelectionGroup(null);
1497 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1498 alignPanel.repaint();
1504 * @param e DOCUMENT ME!
1506 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1508 SequenceGroup sg = new SequenceGroup();
1510 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1513 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1516 sg.setEndRes(viewport.alignment.getWidth() - 1);
1517 viewport.setSelectionGroup(sg);
1518 alignPanel.repaint();
1519 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1525 * @param e DOCUMENT ME!
1527 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1529 if(viewport.cursorMode)
1531 alignPanel.seqPanel.keyboardNo1 = null;
1532 alignPanel.seqPanel.keyboardNo2 = null;
1534 viewport.setSelectionGroup(null);
1535 viewport.getColumnSelection().clear();
1536 viewport.setSelectionGroup(null);
1537 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1538 alignPanel.idPanel.idCanvas.searchResults = null;
1539 alignPanel.repaint();
1540 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1546 * @param e DOCUMENT ME!
1548 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1550 SequenceGroup sg = viewport.getSelectionGroup();
1554 selectAllSequenceMenuItem_actionPerformed(null);
1559 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1562 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1565 alignPanel.repaint();
1567 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1570 public void invertColSel_actionPerformed(ActionEvent e)
1572 viewport.invertColumnSelection();
1573 alignPanel.repaint();
1580 * @param e DOCUMENT ME!
1582 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1584 trimAlignment(true);
1590 * @param e DOCUMENT ME!
1592 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1594 trimAlignment(false);
1597 void trimAlignment(boolean trimLeft)
1599 ColumnSelection colSel = viewport.getColumnSelection();
1602 if (colSel.size() > 0)
1605 column = colSel.getMin();
1607 column = colSel.getMax();
1610 if(viewport.getSelectionGroup()!=null)
1611 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1613 seqs = viewport.alignment.getSequencesArray();
1616 TrimRegionCommand trimRegion;
1619 trimRegion = new TrimRegionCommand("Remove Left",
1620 TrimRegionCommand.TRIM_LEFT,
1625 viewport.selectionGroup);
1626 viewport.setStartRes(0);
1630 trimRegion = new TrimRegionCommand("Remove Right",
1631 TrimRegionCommand.TRIM_RIGHT,
1636 viewport.selectionGroup);
1639 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1642 addHistoryItem(trimRegion);
1644 Vector groups = viewport.alignment.getGroups();
1646 for (int i = 0; i < groups.size(); i++)
1648 SequenceGroup sg = (SequenceGroup) groups.get(i);
1650 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1651 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1653 viewport.alignment.deleteGroup(sg);
1657 viewport.firePropertyChange("alignment", null,
1658 viewport.getAlignment().getSequences());
1665 * @param e DOCUMENT ME!
1667 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1669 int start = 0, end = viewport.alignment.getWidth()-1;
1672 if (viewport.getSelectionGroup() != null)
1674 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1675 start = viewport.getSelectionGroup().getStartRes();
1676 end = viewport.getSelectionGroup().getEndRes();
1679 seqs = viewport.alignment.getSequencesArray();
1682 RemoveGapColCommand removeGapCols =
1683 new RemoveGapColCommand("Remove Gapped Columns",
1686 viewport.getGapCharacter());
1688 addHistoryItem(removeGapCols);
1690 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1692 //This is to maintain viewport position on first residue
1694 SequenceI seq = viewport.alignment.getSequenceAt(0);
1695 int startRes = seq.findPosition(viewport.startRes);
1696 // ShiftList shifts;
1697 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1698 // edit.alColumnChanges=shifts.getInverse();
1699 // if (viewport.hasHiddenColumns)
1700 // viewport.getColumnSelection().compensateForEdits(shifts);
1701 viewport.setStartRes(seq.findIndex(startRes)-1);
1702 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1709 * @param e DOCUMENT ME!
1711 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1713 int start = 0, end = viewport.alignment.getWidth()-1;
1716 if (viewport.getSelectionGroup() != null)
1718 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1719 start = viewport.getSelectionGroup().getStartRes();
1720 end = viewport.getSelectionGroup().getEndRes();
1723 seqs = viewport.alignment.getSequencesArray();
1725 //This is to maintain viewport position on first residue
1727 SequenceI seq = viewport.alignment.getSequenceAt(0);
1728 int startRes = seq.findPosition(viewport.startRes);
1730 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1733 viewport.getGapCharacter()));
1735 viewport.setStartRes(seq.findIndex(startRes)-1);
1737 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1744 * @param e DOCUMENT ME!
1746 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1748 viewport.padGaps = padGapsMenuitem.isSelected();
1750 viewport.firePropertyChange("alignment",
1752 viewport.getAlignment().getSequences());
1758 * @param e DOCUMENT ME!
1760 public void findMenuItem_actionPerformed(ActionEvent e)
1765 public void newView_actionPerformed(ActionEvent e)
1767 AlignmentPanel newap =
1768 new Jalview2XML().copyAlignPanel(alignPanel, true);
1770 if (viewport.viewName == null)
1771 viewport.viewName = "Original";
1773 newap.av.historyList = viewport.historyList;
1774 newap.av.redoList = viewport.redoList;
1776 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1777 String newViewName = "View " +index;
1779 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1780 Vector existingNames = new Vector();
1781 for(int i=0; i<comps.size(); i++)
1783 if(comps.elementAt(i) instanceof AlignmentPanel)
1785 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1786 if(!existingNames.contains(ap.av.viewName))
1787 existingNames.addElement(ap.av.viewName);
1791 while(existingNames.contains(newViewName))
1793 newViewName = "View "+ (++index);
1796 newap.av.viewName = newViewName;
1798 addAlignmentPanel(newap, false);
1800 if(alignPanels.size()==2)
1802 viewport.gatherViewsHere = true;
1804 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1807 public void expandViews_actionPerformed(ActionEvent e)
1809 Desktop.instance.explodeViews(this);
1812 public void gatherViews_actionPerformed(ActionEvent e)
1814 Desktop.instance.gatherViews(this);
1822 * @param e DOCUMENT ME!
1824 public void font_actionPerformed(ActionEvent e)
1826 new FontChooser(alignPanel);
1833 * @param e DOCUMENT ME!
1835 protected void seqLimit_actionPerformed(ActionEvent e)
1837 viewport.setShowJVSuffix(seqLimits.isSelected());
1839 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1840 alignPanel.repaint();
1843 public void idRightAlign_actionPerformed(ActionEvent e)
1845 viewport.rightAlignIds = idRightAlign.isSelected();
1846 alignPanel.repaint();
1854 * @param e DOCUMENT ME!
1856 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1858 viewport.setColourText(colourTextMenuItem.isSelected());
1859 alignPanel.repaint();
1865 * @param e DOCUMENT ME!
1867 public void wrapMenuItem_actionPerformed(ActionEvent e)
1869 scaleAbove.setVisible(wrapMenuItem.isSelected());
1870 scaleLeft.setVisible(wrapMenuItem.isSelected());
1871 scaleRight.setVisible(wrapMenuItem.isSelected());
1872 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1873 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1876 public void showAllSeqs_actionPerformed(ActionEvent e)
1878 viewport.showAllHiddenSeqs();
1881 public void showAllColumns_actionPerformed(ActionEvent e)
1883 viewport.showAllHiddenColumns();
1887 public void hideSelSequences_actionPerformed(ActionEvent e)
1889 viewport.hideAllSelectedSeqs();
1890 alignPanel.repaint();
1893 public void hideSelColumns_actionPerformed(ActionEvent e)
1895 viewport.hideSelectedColumns();
1896 alignPanel.repaint();
1899 public void hiddenMarkers_actionPerformed(ActionEvent e)
1901 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1908 * @param e DOCUMENT ME!
1910 protected void scaleAbove_actionPerformed(ActionEvent e)
1912 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1913 alignPanel.repaint();
1919 * @param e DOCUMENT ME!
1921 protected void scaleLeft_actionPerformed(ActionEvent e)
1923 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1924 alignPanel.repaint();
1930 * @param e DOCUMENT ME!
1932 protected void scaleRight_actionPerformed(ActionEvent e)
1934 viewport.setScaleRightWrapped(scaleRight.isSelected());
1935 alignPanel.repaint();
1941 * @param e DOCUMENT ME!
1943 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1945 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1946 alignPanel.repaint();
1952 * @param e DOCUMENT ME!
1954 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1956 viewport.setShowText(viewTextMenuItem.isSelected());
1957 alignPanel.repaint();
1963 * @param e DOCUMENT ME!
1965 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1967 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1968 alignPanel.repaint();
1972 public FeatureSettings featureSettings;
1973 public void featureSettings_actionPerformed(ActionEvent e)
1975 if(featureSettings !=null )
1977 featureSettings.close();
1978 featureSettings = null;
1980 featureSettings = new FeatureSettings(this);
1986 * @param evt DOCUMENT ME!
1988 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1990 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1991 alignPanel.repaint();
1992 if (alignPanel.getOverviewPanel() != null)
1994 alignPanel.getOverviewPanel().updateOverviewImage();
2001 * @param e DOCUMENT ME!
2003 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2005 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2006 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2012 * @param e DOCUMENT ME!
2014 public void overviewMenuItem_actionPerformed(ActionEvent e)
2016 if (alignPanel.overviewPanel != null)
2021 JInternalFrame frame = new JInternalFrame();
2022 OverviewPanel overview = new OverviewPanel(alignPanel);
2023 frame.setContentPane(overview);
2024 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2025 frame.getWidth(), frame.getHeight());
2027 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2028 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2030 public void internalFrameClosed(
2031 javax.swing.event.InternalFrameEvent evt)
2033 alignPanel.setOverviewPanel(null);
2038 alignPanel.setOverviewPanel(overview);
2041 public void textColour_actionPerformed(ActionEvent e)
2043 new TextColourChooser().chooseColour(alignPanel, null);
2049 * @param e DOCUMENT ME!
2051 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2059 * @param e DOCUMENT ME!
2061 public void clustalColour_actionPerformed(ActionEvent e)
2063 changeColour(new ClustalxColourScheme(
2064 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2070 * @param e DOCUMENT ME!
2072 public void zappoColour_actionPerformed(ActionEvent e)
2074 changeColour(new ZappoColourScheme());
2080 * @param e DOCUMENT ME!
2082 public void taylorColour_actionPerformed(ActionEvent e)
2084 changeColour(new TaylorColourScheme());
2090 * @param e DOCUMENT ME!
2092 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2094 changeColour(new HydrophobicColourScheme());
2100 * @param e DOCUMENT ME!
2102 public void helixColour_actionPerformed(ActionEvent e)
2104 changeColour(new HelixColourScheme());
2110 * @param e DOCUMENT ME!
2112 public void strandColour_actionPerformed(ActionEvent e)
2114 changeColour(new StrandColourScheme());
2120 * @param e DOCUMENT ME!
2122 public void turnColour_actionPerformed(ActionEvent e)
2124 changeColour(new TurnColourScheme());
2130 * @param e DOCUMENT ME!
2132 public void buriedColour_actionPerformed(ActionEvent e)
2134 changeColour(new BuriedColourScheme());
2140 * @param e DOCUMENT ME!
2142 public void nucleotideColour_actionPerformed(ActionEvent e)
2144 changeColour(new NucleotideColourScheme());
2147 public void annotationColour_actionPerformed(ActionEvent e)
2149 new AnnotationColourChooser(viewport, alignPanel);
2156 * @param e DOCUMENT ME!
2158 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2160 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2166 * @param cs DOCUMENT ME!
2168 public void changeColour(ColourSchemeI cs)
2174 if (viewport.getAbovePIDThreshold())
2176 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2179 cs.setThreshold(threshold,
2180 viewport.getIgnoreGapsConsensus());
2182 viewport.setGlobalColourScheme(cs);
2186 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2189 if (viewport.getConservationSelected())
2192 Alignment al = (Alignment) viewport.alignment;
2193 Conservation c = new Conservation("All",
2194 ResidueProperties.propHash, 3,
2195 al.getSequences(), 0,
2199 c.verdict(false, viewport.ConsPercGaps);
2201 cs.setConservation(c);
2203 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2208 cs.setConservation(null);
2211 cs.setConsensus(viewport.hconsensus);
2214 viewport.setGlobalColourScheme(cs);
2216 if (viewport.getColourAppliesToAllGroups())
2218 Vector groups = viewport.alignment.getGroups();
2220 for (int i = 0; i < groups.size(); i++)
2222 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2230 if (cs instanceof ClustalxColourScheme)
2232 sg.cs = new ClustalxColourScheme(
2233 sg.getSequences(true), sg.getWidth());
2235 else if (cs instanceof UserColourScheme)
2237 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2243 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2245 catch (Exception ex)
2250 if (viewport.getAbovePIDThreshold()
2251 || cs instanceof PIDColourScheme
2252 || cs instanceof Blosum62ColourScheme)
2254 sg.cs.setThreshold(threshold,
2255 viewport.getIgnoreGapsConsensus());
2257 sg.cs.setConsensus(AAFrequency.calculate(
2258 sg.getSequences(true), sg.getStartRes(),
2262 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2265 if (viewport.getConservationSelected())
2267 Conservation c = new Conservation("Group",
2268 ResidueProperties.propHash, 3,
2269 sg.getSequences(true),
2273 c.verdict(false, viewport.ConsPercGaps);
2274 sg.cs.setConservation(c);
2277 sg.cs.setConservation(null);
2281 if (alignPanel.getOverviewPanel() != null)
2283 alignPanel.getOverviewPanel().updateOverviewImage();
2286 alignPanel.repaint();
2292 * @param e DOCUMENT ME!
2294 protected void modifyPID_actionPerformed(ActionEvent e)
2296 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2298 SliderPanel.setPIDSliderSource(alignPanel,
2299 viewport.getGlobalColourScheme(),
2301 SliderPanel.showPIDSlider();
2308 * @param e DOCUMENT ME!
2310 protected void modifyConservation_actionPerformed(ActionEvent e)
2312 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2314 SliderPanel.setConservationSlider(alignPanel,
2315 viewport.globalColourScheme,
2317 SliderPanel.showConservationSlider();
2324 * @param e DOCUMENT ME!
2326 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2328 viewport.setConservationSelected(conservationMenuItem.isSelected());
2330 viewport.setAbovePIDThreshold(false);
2331 abovePIDThreshold.setSelected(false);
2333 changeColour(viewport.getGlobalColourScheme());
2335 modifyConservation_actionPerformed(null);
2341 * @param e DOCUMENT ME!
2343 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2345 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2347 conservationMenuItem.setSelected(false);
2348 viewport.setConservationSelected(false);
2350 changeColour(viewport.getGlobalColourScheme());
2352 modifyPID_actionPerformed(null);
2358 * @param e DOCUMENT ME!
2360 public void userDefinedColour_actionPerformed(ActionEvent e)
2362 if (e.getActionCommand().equals("User Defined..."))
2364 new UserDefinedColours(alignPanel, null);
2368 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2369 getUserColourSchemes().get(e.getActionCommand());
2375 public void updateUserColourMenu()
2378 Component[] menuItems = colourMenu.getMenuComponents();
2379 int i, iSize = menuItems.length;
2380 for (i = 0; i < iSize; i++)
2382 if (menuItems[i].getName() != null &&
2383 menuItems[i].getName().equals("USER_DEFINED"))
2385 colourMenu.remove(menuItems[i]);
2389 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2391 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2392 getUserColourSchemes().keys();
2394 while (userColours.hasMoreElements())
2396 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2397 nextElement().toString());
2398 radioItem.setName("USER_DEFINED");
2399 radioItem.addMouseListener(new MouseAdapter()
2401 public void mousePressed(MouseEvent evt)
2403 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2405 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2407 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2408 "Remove from default list?",
2409 "Remove user defined colour",
2410 JOptionPane.YES_NO_OPTION);
2411 if(option == JOptionPane.YES_OPTION)
2413 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2414 colourMenu.remove(radioItem);
2417 radioItem.addActionListener(new ActionListener()
2419 public void actionPerformed(ActionEvent evt)
2421 userDefinedColour_actionPerformed(evt);
2427 radioItem.addActionListener(new ActionListener()
2429 public void actionPerformed(ActionEvent evt)
2431 userDefinedColour_actionPerformed(evt);
2435 colourMenu.insert(radioItem, 15);
2436 colours.add(radioItem);
2444 * @param e DOCUMENT ME!
2446 public void PIDColour_actionPerformed(ActionEvent e)
2448 changeColour(new PIDColourScheme());
2454 * @param e DOCUMENT ME!
2456 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2458 changeColour(new Blosum62ColourScheme());
2464 * @param e DOCUMENT ME!
2466 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2468 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2469 AlignmentSorter.sortByPID(viewport.getAlignment(),
2470 viewport.getAlignment().getSequenceAt(0));
2471 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2472 alignPanel.repaint();
2478 * @param e DOCUMENT ME!
2480 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2482 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2483 AlignmentSorter.sortByID(viewport.getAlignment());
2484 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2485 alignPanel.repaint();
2491 * @param e DOCUMENT ME!
2493 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2495 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2496 AlignmentSorter.sortByGroup(viewport.getAlignment());
2497 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2499 alignPanel.repaint();
2505 * @param e DOCUMENT ME!
2507 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2509 new RedundancyPanel(alignPanel, this);
2516 * @param e DOCUMENT ME!
2518 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2520 if ( (viewport.getSelectionGroup() == null) ||
2521 (viewport.getSelectionGroup().getSize(false) < 2))
2523 JOptionPane.showInternalMessageDialog(this,
2524 "You must select at least 2 sequences.",
2525 "Invalid Selection",
2526 JOptionPane.WARNING_MESSAGE);
2530 JInternalFrame frame = new JInternalFrame();
2531 frame.setContentPane(new PairwiseAlignPanel(viewport));
2532 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2539 * @param e DOCUMENT ME!
2541 public void PCAMenuItem_actionPerformed(ActionEvent e)
2543 if ( ( (viewport.getSelectionGroup() != null) &&
2544 (viewport.getSelectionGroup().getSize(false) < 4) &&
2545 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2546 (viewport.getAlignment().getHeight() < 4))
2548 JOptionPane.showInternalMessageDialog(this,
2549 "Principal component analysis must take\n" +
2550 "at least 4 input sequences.",
2551 "Sequence selection insufficient",
2552 JOptionPane.WARNING_MESSAGE);
2557 new PCAPanel(alignPanel);
2561 public void autoCalculate_actionPerformed(ActionEvent e)
2563 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2564 if(viewport.autoCalculateConsensus)
2566 viewport.firePropertyChange("alignment",
2568 viewport.getAlignment().getSequences());
2576 * @param e DOCUMENT ME!
2578 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2580 NewTreePanel("AV", "PID", "Average distance tree using PID");
2586 * @param e DOCUMENT ME!
2588 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2590 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2596 * @param e DOCUMENT ME!
2598 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2600 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2606 * @param e DOCUMENT ME!
2608 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2610 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2616 * @param type DOCUMENT ME!
2617 * @param pwType DOCUMENT ME!
2618 * @param title DOCUMENT ME!
2620 void NewTreePanel(String type, String pwType, String title)
2624 if (viewport.getSelectionGroup() != null) {
2625 if (viewport.getSelectionGroup().getSize(false) < 3) {
2626 JOptionPane.showMessageDialog(Desktop.desktop,
2627 "You need to have more than two sequences selected to build a tree!",
2628 "Not enough sequences",
2629 JOptionPane.WARNING_MESSAGE);
2634 SequenceGroup sg = viewport.getSelectionGroup();
2636 /* Decide if the selection is a column region */
2637 while (s < sg.getSize(false))
2639 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2642 JOptionPane.showMessageDialog(Desktop.desktop,
2643 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2644 "Try using the Pad function in the edit menu,\n" +
2645 "or one of the multiple sequence alignment web services.",
2646 "Sequences in selection are not aligned",
2647 JOptionPane.WARNING_MESSAGE);
2653 title = title + " on region";
2654 tp = new TreePanel(alignPanel, type, pwType);
2658 //are the sequences aligned?
2659 if (!viewport.alignment.isAligned())
2661 JOptionPane.showMessageDialog(Desktop.desktop,
2662 "The sequences must be aligned before creating a tree.\n" +
2663 "Try using the Pad function in the edit menu,\n" +
2664 "or one of the multiple sequence alignment web services.",
2665 "Sequences not aligned",
2666 JOptionPane.WARNING_MESSAGE);
2671 if(viewport.alignment.getHeight()<2)
2674 tp = new TreePanel(alignPanel, type, pwType);
2679 if(viewport.viewName!=null)
2680 title+= viewport.viewName+" of ";
2682 title += this.title;
2684 Desktop.addInternalFrame(tp, title, 600, 500);
2690 * @param title DOCUMENT ME!
2691 * @param order DOCUMENT ME!
2693 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2695 final JMenuItem item = new JMenuItem("by " + title);
2697 item.addActionListener(new java.awt.event.ActionListener()
2699 public void actionPerformed(ActionEvent e)
2701 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2703 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2704 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2706 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2708 alignPanel.repaint();
2714 * Maintain the Order by->Displayed Tree menu.
2715 * Creates a new menu item for a TreePanel with an appropriate
2716 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2717 * to remove the menu item when the treePanel is closed, and adjust
2718 * the tree leaf to sequence mapping when the alignment is modified.
2719 * @param treePanel Displayed tree window.
2720 * @param title SortBy menu item title.
2722 public void buildTreeMenu()
2724 sortByTreeMenu.removeAll();
2726 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2727 Vector treePanels = new Vector();
2728 int i, iSize = comps.size();
2729 for(i=0; i<iSize; i++)
2731 if(comps.elementAt(i) instanceof TreePanel)
2733 treePanels.add(comps.elementAt(i));
2737 iSize = treePanels.size();
2741 sortByTreeMenu.setVisible(false);
2745 sortByTreeMenu.setVisible(true);
2747 for(i=0; i<treePanels.size(); i++)
2749 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2750 final JMenuItem item = new JMenuItem(tp.getTitle());
2751 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2752 item.addActionListener(new java.awt.event.ActionListener()
2754 public void actionPerformed(ActionEvent e)
2756 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2757 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2759 addHistoryItem(new OrderCommand("Tree Sort",
2761 viewport.alignment));
2763 alignPanel.repaint();
2767 sortByTreeMenu.add(item);
2772 * Work out whether the whole set of sequences
2773 * or just the selected set will be submitted for multiple alignment.
2776 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2778 // Now, check we have enough sequences
2779 AlignmentView msa = null;
2781 if ( (viewport.getSelectionGroup() != null) &&
2782 (viewport.getSelectionGroup().getSize(false) > 1))
2784 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2785 /*SequenceGroup seqs = viewport.getSelectionGroup();
2787 msa = new SequenceI[sz = seqs.getSize(false)];
2789 for (int i = 0; i < sz; i++)
2791 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2793 msa = viewport.getAlignmentView(true);
2797 /*Vector seqs = viewport.getAlignment().getSequences();
2799 if (seqs.size() > 1)
2801 msa = new SequenceI[seqs.size()];
2803 for (int i = 0; i < seqs.size(); i++)
2805 msa[i] = (SequenceI) seqs.elementAt(i);
2808 msa = viewport.getAlignmentView(false);
2814 * Decides what is submitted to a secondary structure prediction service,
2815 * the currently selected sequence, or the currently selected alignment
2816 * (where the first sequence in the set is the one that the prediction
2819 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2821 AlignmentView seqs = null;
2823 if ( (viewport.getSelectionGroup() != null) &&
2824 (viewport.getSelectionGroup().getSize(false) > 0))
2826 seqs = viewport.getAlignmentView(true);
2830 seqs = viewport.getAlignmentView(false);
2832 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2833 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2834 if (!viewport.alignment.isAligned())
2836 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2843 * @param e DOCUMENT ME!
2845 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2847 // Pick the tree file
2848 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2851 chooser.setFileView(new JalviewFileView());
2852 chooser.setDialogTitle("Select a newick-like tree file");
2853 chooser.setToolTipText("Load a tree file");
2855 int value = chooser.showOpenDialog(null);
2857 if (value == JalviewFileChooser.APPROVE_OPTION)
2859 String choice = chooser.getSelectedFile().getPath();
2860 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2864 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2866 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2868 catch (Exception ex)
2870 JOptionPane.showMessageDialog(Desktop.desktop,
2871 "Problem reading tree file",
2873 JOptionPane.WARNING_MESSAGE);
2874 ex.printStackTrace();
2880 public TreePanel ShowNewickTree(NewickFile nf, String title)
2882 return ShowNewickTree(nf,title,600,500,4,5);
2884 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2886 return ShowNewickTree(nf,title, input, 600,500,4,5);
2888 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2889 return ShowNewickTree(nf, title, null, w, h, x, y);
2892 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2894 * @param nf the tree
2895 * @param title tree viewer title
2896 * @param input Associated alignment input data (or null)
2901 * @return TreePanel handle
2903 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2904 TreePanel tp = null;
2910 if (nf.getTree() != null)
2912 tp = new TreePanel(alignPanel,
2920 tp.setLocation(x,y);
2923 Desktop.addInternalFrame(tp, title, w, h);
2926 catch (Exception ex)
2928 ex.printStackTrace();
2939 PrinterJob printJob = PrinterJob.getPrinterJob();
2940 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2941 printJob.setPrintable(alignPanel, pf);
2943 if (printJob.printDialog())
2949 catch (Exception PrintException)
2951 PrintException.printStackTrace();
2958 * Generates menu items and listener event actions for web service clients
2961 public void BuildWebServiceMenu()
2963 if ( (Discoverer.services != null)
2964 && (Discoverer.services.size() > 0))
2966 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2967 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2968 Vector wsmenu = new Vector();
2969 final AlignFrame af = this;
2972 // Add any Multiple Sequence Alignment Services
2973 final JMenu msawsmenu = new JMenu("Alignment");
2974 for (int i = 0, j = msaws.size(); i < j; i++)
2976 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2978 final JMenuItem method = new JMenuItem(sh.getName());
2979 method.addActionListener(new ActionListener()
2981 public void actionPerformed(ActionEvent e)
2983 AlignmentView msa = gatherSequencesForAlignment();
2984 new jalview.ws.MsaWSClient(sh, title, msa,
2985 false, true, viewport.getAlignment().getDataset(), af);
2990 msawsmenu.add(method);
2991 // Deal with services that we know accept partial alignments.
2992 if (sh.getName().indexOf("lustal") > -1)
2994 // We know that ClustalWS can accept partial alignments for refinement.
2995 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2996 methodR.addActionListener(new ActionListener()
2998 public void actionPerformed(ActionEvent e)
3000 AlignmentView msa = gatherSequencesForAlignment();
3001 new jalview.ws.MsaWSClient(sh, title, msa,
3002 true, true, viewport.getAlignment().getDataset(), af);
3007 msawsmenu.add(methodR);
3011 wsmenu.add(msawsmenu);
3013 if (secstrpr != null)
3015 // Add any secondary structure prediction services
3016 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3017 for (int i = 0, j = secstrpr.size(); i < j; i++)
3019 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3021 final JMenuItem method = new JMenuItem(sh.getName());
3022 method.addActionListener(new ActionListener()
3024 public void actionPerformed(ActionEvent e)
3026 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3027 if (msa.getSequences().length == 1)
3029 // Single Sequence prediction
3030 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3034 if (msa.getSequences().length > 1)
3036 // Sequence profile based prediction
3037 new jalview.ws.JPredClient(sh,
3038 title, true, msa, af, true);
3043 secstrmenu.add(method);
3045 wsmenu.add(secstrmenu);
3047 this.webService.removeAll();
3048 for (int i = 0, j = wsmenu.size(); i < j; i++)
3050 webService.add( (JMenu) wsmenu.get(i));
3055 this.webService.removeAll();
3056 this.webService.add(this.webServiceNoServices);
3058 // TODO: add in rediscovery function
3059 // TODO: reduce code redundancy.
3060 // TODO: group services by location as well as function.
3063 /* public void vamsasStore_actionPerformed(ActionEvent e)
3065 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3066 getProperty("LAST_DIRECTORY"));
3068 chooser.setFileView(new JalviewFileView());
3069 chooser.setDialogTitle("Export to Vamsas file");
3070 chooser.setToolTipText("Export");
3072 int value = chooser.showSaveDialog(this);
3074 if (value == JalviewFileChooser.APPROVE_OPTION)
3076 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3077 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3078 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3085 public void showTranslation_actionPerformed(ActionEvent e)
3087 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3088 String [] seqstring = viewport.getViewAsString(true);
3090 int s, sSize = selection.length;
3091 SequenceI [] newSeq = new SequenceI[sSize];
3094 StringBuffer protein;
3096 for(s=0; s<sSize; s++)
3098 protein = new StringBuffer();
3099 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3100 resSize = seq.length();
3101 resSize -= resSize%3;
3103 for(res = 0; res < resSize; res+=3)
3105 String codon = seq.substring(res, res+3);
3106 codon = codon.replace('U', 'T');
3107 String aa = ResidueProperties.codonTranslate(codon);
3109 protein.append(viewport.getGapCharacter());
3110 else if(aa.equals("STOP"))
3111 protein.append("X");
3113 protein.append( aa );
3115 newSeq[s] = new Sequence(selection[s].getName(),
3116 protein.toString());
3120 AlignmentI al = new Alignment(newSeq);
3121 al.setDataset(null);
3124 ////////////////////////////////
3125 // Copy annotations across
3126 jalview.datamodel.AlignmentAnnotation[] annotations
3127 = viewport.alignment.getAlignmentAnnotation();
3129 if(annotations!=null)
3131 for (int i = 0; i < annotations.length; i++)
3133 if (annotations[i].label.equals("Quality") ||
3134 annotations[i].label.equals("Conservation") ||
3135 annotations[i].label.equals("Consensus"))
3140 aSize = viewport.alignment.getWidth() / 3;
3141 jalview.datamodel.Annotation[] anots =
3142 new jalview.datamodel.Annotation[aSize];
3144 for (a = 0; a < viewport.alignment.getWidth(); a++)
3146 if (annotations[i].annotations[a] == null
3147 || annotations[i].annotations[a] == null)
3150 anots[a / 3] = new Annotation(
3151 annotations[i].annotations[a].displayCharacter,
3152 annotations[i].annotations[a].description,
3153 annotations[i].annotations[a].secondaryStructure,
3154 annotations[i].annotations[a].value,
3155 annotations[i].annotations[a].colour);
3158 jalview.datamodel.AlignmentAnnotation aa
3159 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3160 annotations[i].description, anots);
3161 al.addAnnotation(aa);
3165 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3166 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3178 * @param String DOCUMENT ME!
3180 public boolean parseFeaturesFile(String file, String type)
3182 boolean featuresFile = false;
3184 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3185 alignPanel.seqPanel.seqCanvas.
3186 getFeatureRenderer().featureColours,
3191 ex.printStackTrace();
3196 viewport.showSequenceFeatures = true;
3197 showSeqFeatures.setSelected(true);
3198 alignPanel.repaint();
3201 return featuresFile;
3204 public void dragEnter(DropTargetDragEvent evt)
3207 public void dragExit(DropTargetEvent evt)
3210 public void dragOver(DropTargetDragEvent evt)
3213 public void dropActionChanged(DropTargetDragEvent evt)
3216 public void drop(DropTargetDropEvent evt)
3218 Transferable t = evt.getTransferable();
3219 java.util.List files = null;
3223 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3224 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3226 //Works on Windows and MacOSX
3227 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3228 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3230 else if (t.isDataFlavorSupported(uriListFlavor))
3232 // This is used by Unix drag system
3233 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3234 String data = (String) t.getTransferData(uriListFlavor);
3235 files = new java.util.ArrayList(1);
3236 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3239 st.hasMoreTokens(); )
3241 String s = st.nextToken();
3242 if (s.startsWith("#"))
3244 // the line is a comment (as per the RFC 2483)
3248 java.net.URI uri = new java.net.URI(s);
3249 java.io.File file = new java.io.File(uri);
3256 e.printStackTrace();
3263 for (int i = 0; i < files.size(); i++)
3265 loadJalviewDataFile(files.get(i).toString());
3268 catch (Exception ex)
3270 ex.printStackTrace();
3275 // This method will attempt to load a "dropped" file first by testing
3276 // whether its and Annotation file, then features file. If both are
3277 // false then the user may have dropped an alignment file onto this
3279 public void loadJalviewDataFile(String file)
3282 String protocol = "File";
3284 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3289 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3294 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3297 String format = new IdentifyFile().Identify(file, protocol);
3299 if(format.equalsIgnoreCase("JnetFile"))
3301 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3303 new JnetAnnotationMaker().add_annotation(predictions,
3304 viewport.getAlignment(),
3306 alignPanel.adjustAnnotationHeight();
3307 alignPanel.repaint();
3310 new FileLoader().LoadFile(viewport, file, protocol, format);
3316 alignPanel.adjustAnnotationHeight();
3319 }catch(Exception ex)
3321 ex.printStackTrace();
3325 public void tabSelectionChanged(int index)
3329 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3330 viewport = alignPanel.av;
3331 setMenusFromViewport(viewport);
3335 public void tabbedPane_mousePressed(MouseEvent e)
3337 if(SwingUtilities.isRightMouseButton(e))
3339 String reply = JOptionPane.showInternalInputDialog(this,
3342 JOptionPane.QUESTION_MESSAGE);
3346 viewport.viewName = reply;
3347 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3353 public AlignViewport getCurrentView()