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;
67 private int treeCount = 0;
70 * Creates a new AlignFrame object.
72 * @param al DOCUMENT ME!
74 public AlignFrame(AlignmentI al, int width, int height)
76 this(al, null, width, height);
81 * new alignment window with hidden columns
82 * @param al AlignmentI
83 * @param hiddenColumns ColumnSelection or null
85 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
86 int width, int height)
88 this.setSize(width, height);
89 viewport = new AlignViewport(al, hiddenColumns);
91 alignPanel = new AlignmentPanel(this, viewport);
93 if(al.getDataset()==null)
98 addAlignmentPanel(alignPanel, true);
103 * Make a new AlignFrame from exisiting alignmentPanels
104 * @param ap AlignmentPanel
105 * @param av AlignViewport
107 public AlignFrame(AlignmentPanel ap)
111 addAlignmentPanel(ap, false);
117 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
119 if (viewport.conservation == null)
121 BLOSUM62Colour.setEnabled(false);
122 conservationMenuItem.setEnabled(false);
123 modifyConservation.setEnabled(false);
124 // PIDColour.setEnabled(false);
125 // abovePIDThreshold.setEnabled(false);
126 // modifyPID.setEnabled(false);
129 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
131 if (sortby.equals("Id"))
132 sortIDMenuItem_actionPerformed(null);
133 else if (sortby.equals("Pairwise Identity"))
134 sortPairwiseMenuItem_actionPerformed(null);
136 if (Desktop.desktop != null)
138 addServiceListeners();
139 setGUINucleotide(viewport.alignment.isNucleotide());
142 setMenusFromViewport(viewport);
144 if (viewport.wrapAlignment)
146 wrapMenuItem_actionPerformed(null);
153 public void setFileName(String file, String format)
156 currentFileFormat = format;
157 reload.setEnabled(true);
160 void addKeyListener()
162 final AlignFrame af = this;
163 addKeyListener(new KeyAdapter()
165 public void keyPressed(KeyEvent evt)
167 if (viewport.cursorMode
168 && evt.getKeyCode() >= KeyEvent.VK_0
169 && evt.getKeyCode() <= KeyEvent.VK_9)
171 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
174 switch (evt.getKeyCode())
177 Desktop.instance.gatherViews(af);
181 if (!evt.isControlDown())
183 Desktop.instance.explodeViews(af);
188 case 27: // escape key
189 deselectAllSequenceMenuItem_actionPerformed(null);
193 case KeyEvent.VK_DOWN:
194 if (viewport.cursorMode)
196 alignPanel.seqPanel.moveCursor(0, 1);
199 moveSelectedSequences(false);
203 if (viewport.cursorMode)
205 alignPanel.seqPanel.moveCursor(0, -1);
208 moveSelectedSequences(true);
211 case KeyEvent.VK_LEFT:
212 if (viewport.cursorMode)
214 alignPanel.seqPanel.moveCursor( -1, 0);
218 case KeyEvent.VK_RIGHT:
219 if (viewport.cursorMode)
221 alignPanel.seqPanel.moveCursor(1, 0);
225 case KeyEvent.VK_SPACE:
226 if (viewport.cursorMode)
228 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
234 case KeyEvent.VK_DELETE:
235 case KeyEvent.VK_BACK_SPACE:
236 if (!viewport.cursorMode)
238 cut_actionPerformed(null);
241 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorRow();
254 if (viewport.cursorMode && !evt.isControlDown())
256 alignPanel.seqPanel.setCursorColumn();
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setCursorPosition();
266 case KeyEvent.VK_ENTER:
267 case KeyEvent.VK_COMMA:
268 if (viewport.cursorMode)
270 alignPanel.seqPanel.setCursorRowAndColumn();
275 if (viewport.cursorMode)
277 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
281 if (viewport.cursorMode)
283 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
288 viewport.cursorMode = !viewport.cursorMode;
289 statusBar.setText("Keyboard editing mode is " +
290 (viewport.cursorMode ? "on" : "off"));
291 if (viewport.cursorMode)
293 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
294 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
296 alignPanel.seqPanel.seqCanvas.repaint();
302 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
303 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
304 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
306 javax.help.HelpBroker hb = hs.createHelpBroker();
307 hb.setCurrentID("home");
308 hb.setDisplayed(true);
312 ex.printStackTrace();
318 boolean toggleSeqs = !evt.isControlDown();
319 boolean toggleCols = !evt.isShiftDown();
321 boolean hide = false;
323 SequenceGroup sg = viewport.getSelectionGroup();
326 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
328 hideSelSequences_actionPerformed(null);
331 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
332 showAllSeqs_actionPerformed(null);
337 if (viewport.colSel.getSelected().size() > 0)
339 hideSelColumns_actionPerformed(null);
341 viewport.selectionGroup = sg;
344 showAllColumns_actionPerformed(null);
348 case KeyEvent.VK_PAGE_UP:
349 if (viewport.wrapAlignment)
350 alignPanel.scrollUp(true);
352 alignPanel.setScrollValues(viewport.startRes,
354 - viewport.endSeq + viewport.startSeq);
356 case KeyEvent.VK_PAGE_DOWN:
357 if (viewport.wrapAlignment)
358 alignPanel.scrollUp(false);
360 alignPanel.setScrollValues(viewport.startRes,
362 + viewport.endSeq - viewport.startSeq);
370 public void addAlignmentPanel(final AlignmentPanel ap,
373 ap.alignFrame = this;
375 alignPanels.addElement(ap);
377 int aSize = alignPanels.size();
379 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
381 if (aSize == 1 && ap.av.viewName==null)
383 this.getContentPane().add(ap, BorderLayout.CENTER);
389 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
390 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
392 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
395 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
397 ap.setVisible(false);
403 ap.av.alignment.padGaps();
404 ap.av.updateConservation(ap);
405 ap.av.updateConsensus(ap);
410 public AlignViewport getViewport()
415 /* Set up intrinsic listeners for dynamically generated GUI bits. */
416 private void addServiceListeners()
418 final java.beans.PropertyChangeListener thisListener;
419 // Do this once to get current state
420 BuildWebServiceMenu();
421 Desktop.discoverer.addPropertyChangeListener(
422 thisListener = new java.beans.PropertyChangeListener()
424 public void propertyChange(PropertyChangeEvent evt)
426 // System.out.println("Discoverer property change.");
427 if (evt.getPropertyName().equals("services"))
429 // System.out.println("Rebuilding web service menu");
430 BuildWebServiceMenu();
435 addInternalFrameListener(new javax.swing.event.
436 InternalFrameAdapter()
438 public void internalFrameClosed(
439 javax.swing.event.InternalFrameEvent evt)
441 // System.out.println("deregistering discoverer listener");
442 Desktop.discoverer.removePropertyChangeListener(thisListener);
443 closeMenuItem_actionPerformed(true);
449 public void setGUINucleotide(boolean nucleotide)
451 showTranslation.setVisible( nucleotide );
452 conservationMenuItem.setEnabled( !nucleotide );
453 modifyConservation.setEnabled( !nucleotide );
455 //Remember AlignFrame always starts as protein
458 calculateMenu.remove(calculateMenu.getItemCount()-2);
463 * Need to call this method when tabs are selected for multiple views,
464 * or when loading from Jalview2XML.java
465 * @param av AlignViewport
467 void setMenusFromViewport(AlignViewport av)
469 colourTextMenuItem.setSelected(av.showColourText);
470 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
471 conservationMenuItem.setSelected(av.getConservationSelected());
472 seqLimits.setSelected(av.getShowJVSuffix());
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 this.closeMenuItem_actionPerformed(true);
565 viewport.alignment.deleteAllGroups();
566 viewport.sequenceColours=null;
567 while (viewport.alignment.getHeight() > 0)
569 viewport.alignment.deleteSequence(0);
572 viewport.historyList.clear();
573 viewport.redoList.clear();
574 Alignment dset = viewport.alignment.getDataset();
575 while (dset.getHeight() > 0)
577 dset.deleteSequence(0);
580 firePropertyChange("Alignment", null, null);
585 FileLoader loader = new FileLoader();
586 String protocol = fileName.startsWith("http:")? "URL":"File";
587 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
593 public void addFromText_actionPerformed(ActionEvent e)
595 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
598 public void addFromURL_actionPerformed(ActionEvent e)
600 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
604 public void save_actionPerformed(ActionEvent e)
606 if(fileName==null || currentFileFormat==null)
607 saveAs_actionPerformed(null);
609 saveAlignment(fileName, currentFileFormat);
615 * @param e DOCUMENT ME!
617 public void saveAs_actionPerformed(ActionEvent e)
619 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
620 getProperty( "LAST_DIRECTORY"),
622 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
624 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
629 chooser.setFileView(new JalviewFileView());
630 chooser.setDialogTitle("Save Alignment to file");
631 chooser.setToolTipText("Save");
633 int value = chooser.showSaveDialog(this);
635 if (value == JalviewFileChooser.APPROVE_OPTION)
637 currentFileFormat = chooser.getSelectedFormat();
638 if (currentFileFormat == null)
640 JOptionPane.showInternalMessageDialog(Desktop.desktop,
641 "You must select a file format before saving!",
642 "File format not specified",
643 JOptionPane.WARNING_MESSAGE);
644 value = chooser.showSaveDialog(this);
648 fileName = chooser.getSelectedFile().getPath();
650 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
653 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
655 saveAlignment(fileName, currentFileFormat);
659 public boolean saveAlignment(String file, String format)
661 if (format.equalsIgnoreCase("Jalview"))
663 String shortName = title;
665 if (shortName.indexOf(java.io.File.separatorChar) > -1)
667 shortName = shortName.substring(shortName.lastIndexOf(
668 java.io.File.separatorChar) + 1);
671 new Jalview2XML().SaveAlignment(this, file, shortName);
673 statusBar.setText("Successfully saved to file: "
675 +format +" format.");
678 // USE Jalview2XML to save this file
684 String[] omitHidden = null;
686 if (viewport.hasHiddenColumns)
688 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
689 "The Alignment contains hidden columns."
690 + "\nDo you want to save only the visible alignment?",
691 "Save / Omit Hidden Columns",
692 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
694 if (reply == JOptionPane.YES_OPTION)
695 omitHidden = viewport.getViewAsString(false);
698 String output = new FormatAdapter().formatSequences(
700 viewport.alignment.getSequencesArray(),
710 java.io.PrintWriter out = new java.io.PrintWriter(
711 new java.io.FileWriter(file));
716 statusBar.setText("Successfully saved to file: "
718 +format +" format.");
723 ex.printStackTrace();
732 * @param e DOCUMENT ME!
734 protected void outputText_actionPerformed(ActionEvent e)
736 String [] omitHidden = null;
738 if(viewport.hasHiddenColumns)
740 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
741 "The Alignment contains hidden columns."
742 +"\nDo you want to output only the visible alignment?",
743 "Save / Omit Hidden Columns",
744 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
746 if(reply==JOptionPane.YES_OPTION)
748 omitHidden = viewport.getViewAsString(false);
752 CutAndPasteTransfer cap = new CutAndPasteTransfer();
753 cap.setForInput(null);
754 Desktop.addInternalFrame(cap,
755 "Alignment output - " + e.getActionCommand(), 600,
759 cap.setText(new FormatAdapter().formatSequences(
760 e.getActionCommand(),
761 viewport.alignment.getSequencesArray(),
768 * @param e DOCUMENT ME!
770 protected void htmlMenuItem_actionPerformed(ActionEvent e)
772 new HTMLOutput(viewport,
773 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
774 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
777 public void createImageMap(File file, String image)
779 alignPanel.makePNGImageMap(file, image);
785 * @param e DOCUMENT ME!
787 public void createPNG(File f)
789 alignPanel.makePNG(f);
795 * @param e DOCUMENT ME!
797 public void createEPS(File f)
799 alignPanel.makeEPS(f);
805 * @param e DOCUMENT ME!
807 public void printMenuItem_actionPerformed(ActionEvent e)
809 //Putting in a thread avoids Swing painting problems
810 PrintThread thread = new PrintThread();
814 public void exportFeatures_actionPerformed(ActionEvent e)
816 new AnnotationExporter().exportFeatures(alignPanel);
820 public void exportAnnotations_actionPerformed(ActionEvent e)
822 new AnnotationExporter().exportAnnotations(
824 viewport.alignment.getAlignmentAnnotation()
829 public void associatedData_actionPerformed(ActionEvent e)
831 // Pick the tree file
832 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
835 chooser.setFileView(new JalviewFileView());
836 chooser.setDialogTitle("Load Jalview Annotations or Features File");
837 chooser.setToolTipText("Load Jalview Annotations / Features file");
839 int value = chooser.showOpenDialog(null);
841 if (value == JalviewFileChooser.APPROVE_OPTION)
843 String choice = chooser.getSelectedFile().getPath();
844 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
845 loadJalviewDataFile(choice);
854 * @param e DOCUMENT ME!
856 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
858 if(alignPanels!=null && alignPanels.size()<2)
863 if(alignPanels!=null)
866 for (int i = 0; i < alignPanels.size(); i++)
868 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
869 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
870 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
871 PaintRefresher.RemoveComponent(ap);
875 int index = tabbedPane.getSelectedIndex();
877 tabbedPane.removeTabAt(index);
878 alignPanels.removeElement(alignPanel);
879 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
880 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
881 PaintRefresher.RemoveComponent(alignPanel);
884 tabbedPane.validate();
886 if(index==tabbedPane.getTabCount())
889 this.tabSelectionChanged(index);
894 this.setClosed(true);
898 ex.printStackTrace();
906 void updateEditMenuBar()
909 if (viewport.historyList.size() > 0)
911 undoMenuItem.setEnabled(true);
912 CommandI command = (CommandI) viewport.historyList.peek();
913 undoMenuItem.setText("Undo " + command.getDescription());
917 undoMenuItem.setEnabled(false);
918 undoMenuItem.setText("Undo");
921 if (viewport.redoList.size() > 0)
923 redoMenuItem.setEnabled(true);
925 CommandI command = (CommandI) viewport.redoList.peek();
926 redoMenuItem.setText("Redo " + command.getDescription());
930 redoMenuItem.setEnabled(false);
931 redoMenuItem.setText("Redo");
936 public void addHistoryItem(CommandI command)
938 if(command.getSize()>0)
940 viewport.historyList.push(command);
941 viewport.redoList.clear();
943 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
952 * @param e DOCUMENT ME!
954 protected void undoMenuItem_actionPerformed(ActionEvent e)
956 CommandI command = (CommandI)viewport.historyList.pop();
957 viewport.redoList.push(command);
958 command.undoCommand();
960 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
962 viewport.firePropertyChange("alignment", null,
963 viewport.getAlignment().getSequences());
969 * @param e DOCUMENT ME!
971 protected void redoMenuItem_actionPerformed(ActionEvent e)
973 CommandI command = (CommandI) viewport.redoList.pop();
974 viewport.historyList.push(command);
976 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
979 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
986 * @param up DOCUMENT ME!
988 public void moveSelectedSequences(boolean up)
990 SequenceGroup sg = viewport.getSelectionGroup();
999 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1001 SequenceI seq = viewport.alignment.getSequenceAt(i);
1003 if (!sg.getSequences(false).contains(seq))
1008 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1010 if (sg.getSequences(false).contains(temp))
1015 viewport.alignment.getSequences().setElementAt(temp, i);
1016 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1021 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1023 SequenceI seq = viewport.alignment.getSequenceAt(i);
1025 if (!sg.getSequences(false).contains(seq))
1030 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1032 if (sg.getSequences(false).contains(temp))
1037 viewport.alignment.getSequences().setElementAt(temp, i);
1038 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1042 alignPanel.repaint();
1050 * @param e DOCUMENT ME!
1052 protected void copy_actionPerformed(ActionEvent e)
1055 if (viewport.getSelectionGroup() == null)
1060 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1061 String[] omitHidden = null;
1063 if (viewport.hasHiddenColumns)
1065 omitHidden = viewport.getViewAsString(true);
1068 String output = new FormatAdapter().formatSequences(
1073 StringSelection ss = new StringSelection(output);
1077 //Its really worth setting the clipboard contents
1078 //to empty before setting the large StringSelection!!
1079 Toolkit.getDefaultToolkit().getSystemClipboard()
1080 .setContents(new StringSelection(""), null);
1082 Toolkit.getDefaultToolkit().getSystemClipboard()
1083 .setContents(ss, Desktop.instance);
1085 catch (OutOfMemoryError er)
1087 er.printStackTrace();
1088 javax.swing.SwingUtilities.invokeLater(new Runnable()
1092 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1093 "Out of memory copying region!!"
1095 "\nSee help files for increasing Java Virtual Machine memory."
1097 javax.swing.JOptionPane.WARNING_MESSAGE);
1104 Vector hiddenColumns = null;
1105 if(viewport.hasHiddenColumns)
1107 hiddenColumns =new Vector();
1108 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1109 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1111 int[] region = (int[])
1112 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1114 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1115 region[1]-hiddenOffset});
1121 Desktop.jalviewClipboard = new Object[]{ seqs,
1122 viewport.alignment.getDataset(),
1124 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1130 * @param e DOCUMENT ME!
1132 protected void pasteNew_actionPerformed(ActionEvent e)
1140 * @param e DOCUMENT ME!
1142 protected void pasteThis_actionPerformed(ActionEvent e)
1150 * @param newAlignment DOCUMENT ME!
1152 void paste(boolean newAlignment)
1156 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1157 Transferable contents = c.getContents(this);
1159 if (contents == null)
1167 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1168 if (str.length() < 1)
1171 format = new IdentifyFile().Identify(str, "Paste");
1174 catch (OutOfMemoryError er)
1176 er.printStackTrace();
1177 javax.swing.SwingUtilities.invokeLater(new Runnable()
1181 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1182 "Out of memory pasting sequences!!"
1184 "\nSee help files for increasing Java Virtual Machine memory."
1186 javax.swing.JOptionPane.WARNING_MESSAGE);
1193 SequenceI[] sequences;
1196 if(Desktop.jalviewClipboard!=null)
1198 // The clipboard was filled from within Jalview, we must use the sequences
1199 // And dataset from the copied alignment
1200 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1204 sequences = new FormatAdapter().readFile(str, "Paste", format);
1207 AlignmentI alignment = null;
1211 alignment = new Alignment(sequences);
1213 if (Desktop.jalviewClipboard != null)
1214 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1216 alignment.setDataset(null);
1220 alignment = viewport.getAlignment();
1223 SequenceI [] newseqs = new SequenceI[sequences.length];
1224 for (int i = 0; i < sequences.length; i++)
1226 newseqs[i] = new Sequence(sequences[i].getName(),
1227 sequences[i].getSequence(), sequences[i].getStart(),
1228 sequences[i].getEnd());
1230 alignment.addSequence(newseqs[i]);
1236 addHistoryItem(new EditCommand(
1241 alignment.getWidth(),
1246 viewport.setEndSeq(alignment.getHeight());
1247 alignment.getWidth();
1248 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1253 // Add any annotations attached to sequences
1254 for (int i = 0; i < sequences.length; i++)
1256 if (sequences[i].getAnnotation() != null)
1258 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1260 AlignmentAnnotation newAnnot =
1261 new AlignmentAnnotation(
1262 sequences[i].getAnnotation()[a].label,
1263 sequences[i].getAnnotation()[a].description,
1264 sequences[i].getAnnotation()[a].annotations,
1265 sequences[i].getAnnotation()[a].graphMin,
1266 sequences[i].getAnnotation()[a].graphMax,
1267 sequences[i].getAnnotation()[a].graph);
1269 sequences[i].getAnnotation()[a] = newAnnot;
1270 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1272 newAnnot.sequenceRef = sequences[i];
1273 newAnnot.adjustForAlignment();
1274 alignment.addAnnotation(newAnnot);
1275 alignment.setAnnotationIndex(newAnnot, a);
1278 alignPanel.annotationPanel.adjustPanelHeight();
1284 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1285 String newtitle = new String("Copied sequences");
1287 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1289 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1290 for(int i=0; i<hc.size(); i++)
1292 int [] region = (int[]) hc.elementAt(i);
1293 af.viewport.hideColumns(region[0], region[1]);
1298 //>>>This is a fix for the moment, until a better solution is found!!<<<
1299 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1300 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1303 if (title.startsWith("Copied sequences"))
1309 newtitle = newtitle.concat("- from " + title);
1312 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1319 catch (Exception ex)
1321 ex.printStackTrace();
1322 System.out.println("Exception whilst pasting: "+ex);
1323 // could be anything being pasted in here
1332 * @param e DOCUMENT ME!
1334 protected void cut_actionPerformed(ActionEvent e)
1336 copy_actionPerformed(null);
1337 delete_actionPerformed(null);
1343 * @param e DOCUMENT ME!
1345 protected void delete_actionPerformed(ActionEvent evt)
1348 SequenceGroup sg = viewport.getSelectionGroup();
1354 Vector seqs = new Vector();
1355 int cutLength = sg.getEndRes()-sg.getStartRes()+1;
1356 boolean seqsCut = false;
1358 for (int i = 0; i < sg.getSize(false); i++)
1360 seq = sg.getSequenceAt(i);
1361 seqs.addElement(seq);
1362 if(seq.getLength()<=cutLength)
1367 // If the cut affects all sequences, remove highlighted columns
1368 if (sg.getSize(false) == viewport.alignment.getHeight())
1370 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1371 sg.getEndRes() + 1);
1375 SequenceI [] cut = new SequenceI[seqs.size()];
1376 for(int i=0; i<seqs.size(); i++)
1377 cut[i] = (SequenceI)seqs.elementAt(i);
1383 addHistoryItem(new EditCommand("Cut Sequences",
1387 sg.getEndRes()-sg.getStartRes()+1,
1388 viewport.alignment));
1391 viewport.setSelectionGroup(null);
1392 viewport.alignment.deleteGroup(sg);
1394 viewport.firePropertyChange("alignment", null,
1395 viewport.getAlignment().getSequences());
1397 if (viewport.getAlignment().getHeight() < 1)
1401 this.setClosed(true);
1403 catch (Exception ex)
1412 * @param e DOCUMENT ME!
1414 protected void deleteGroups_actionPerformed(ActionEvent e)
1416 viewport.alignment.deleteAllGroups();
1417 viewport.sequenceColours.clear();
1418 viewport.setSelectionGroup(null);
1419 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1420 alignPanel.repaint();
1426 * @param e DOCUMENT ME!
1428 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1430 SequenceGroup sg = new SequenceGroup();
1432 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1435 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1438 sg.setEndRes(viewport.alignment.getWidth() - 1);
1439 viewport.setSelectionGroup(sg);
1440 alignPanel.repaint();
1441 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1447 * @param e DOCUMENT ME!
1449 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1451 if(viewport.cursorMode)
1453 alignPanel.seqPanel.keyboardNo1 = null;
1454 alignPanel.seqPanel.keyboardNo2 = null;
1456 viewport.setSelectionGroup(null);
1457 viewport.getColumnSelection().clear();
1458 viewport.setSelectionGroup(null);
1459 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1460 alignPanel.idPanel.idCanvas.searchResults = null;
1461 alignPanel.repaint();
1462 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1468 * @param e DOCUMENT ME!
1470 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1472 SequenceGroup sg = viewport.getSelectionGroup();
1476 selectAllSequenceMenuItem_actionPerformed(null);
1481 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1484 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1487 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1490 public void invertColSel_actionPerformed(ActionEvent e)
1492 viewport.invertColumnSelection();
1493 alignPanel.repaint();
1500 * @param e DOCUMENT ME!
1502 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1504 trimAlignment(true);
1510 * @param e DOCUMENT ME!
1512 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1514 trimAlignment(false);
1517 void trimAlignment(boolean trimLeft)
1519 ColumnSelection colSel = viewport.getColumnSelection();
1522 if (colSel.size() > 0)
1525 column = colSel.getMin();
1527 column = colSel.getMax();
1530 if(viewport.getSelectionGroup()!=null)
1531 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1533 seqs = viewport.alignment.getSequencesArray();
1536 TrimRegionCommand trimRegion;
1539 trimRegion = new TrimRegionCommand("Remove Left",
1540 TrimRegionCommand.TRIM_LEFT,
1545 viewport.selectionGroup);
1546 viewport.setStartRes(0);
1550 trimRegion = new TrimRegionCommand("Remove Right",
1551 TrimRegionCommand.TRIM_RIGHT,
1556 viewport.selectionGroup);
1559 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1562 addHistoryItem(trimRegion);
1564 Vector groups = viewport.alignment.getGroups();
1566 for (int i = 0; i < groups.size(); i++)
1568 SequenceGroup sg = (SequenceGroup) groups.get(i);
1570 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1571 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1573 viewport.alignment.deleteGroup(sg);
1577 viewport.firePropertyChange("alignment", null,
1578 viewport.getAlignment().getSequences());
1585 * @param e DOCUMENT ME!
1587 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1589 int start = 0, end = viewport.alignment.getWidth()-1;
1592 if (viewport.getSelectionGroup() != null)
1594 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1595 start = viewport.getSelectionGroup().getStartRes();
1596 end = viewport.getSelectionGroup().getEndRes();
1599 seqs = viewport.alignment.getSequencesArray();
1602 RemoveGapColCommand removeGapCols =
1603 new RemoveGapColCommand("Remove Gapped Columns",
1606 viewport.getGapCharacter());
1608 addHistoryItem(removeGapCols);
1610 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1612 //This is to maintain viewport position on first residue
1614 SequenceI seq = viewport.alignment.getSequenceAt(0);
1615 int startRes = seq.findPosition(viewport.startRes);
1616 // ShiftList shifts;
1617 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1618 // edit.alColumnChanges=shifts.getInverse();
1619 // if (viewport.hasHiddenColumns)
1620 // viewport.getColumnSelection().compensateForEdits(shifts);
1621 viewport.setStartRes(seq.findIndex(startRes)-1);
1622 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1629 * @param e DOCUMENT ME!
1631 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1633 int start = 0, end = viewport.alignment.getWidth()-1;
1636 if (viewport.getSelectionGroup() != null)
1638 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1639 start = viewport.getSelectionGroup().getStartRes();
1640 end = viewport.getSelectionGroup().getEndRes();
1643 seqs = viewport.alignment.getSequencesArray();
1645 //This is to maintain viewport position on first residue
1647 SequenceI seq = viewport.alignment.getSequenceAt(0);
1648 int startRes = seq.findPosition(viewport.startRes);
1650 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1653 viewport.getGapCharacter()));
1655 viewport.setStartRes(seq.findIndex(startRes)-1);
1657 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1664 * @param e DOCUMENT ME!
1666 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1668 viewport.padGaps = padGapsMenuitem.isSelected();
1670 viewport.firePropertyChange("alignment",
1672 viewport.getAlignment().getSequences());
1678 * @param e DOCUMENT ME!
1680 public void findMenuItem_actionPerformed(ActionEvent e)
1682 JInternalFrame frame = new JInternalFrame();
1683 Finder finder = new Finder(viewport, alignPanel, frame);
1684 frame.setContentPane(finder);
1685 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1686 Desktop.addInternalFrame(frame, "Find", 340, 110);
1689 public void newView_actionPerformed(ActionEvent e)
1691 AlignmentPanel newap =
1692 new Jalview2XML().copyAlignPanel(alignPanel, true);
1694 if (viewport.viewName == null)
1695 viewport.viewName = "View 1";
1697 newap.av.historyList = viewport.historyList;
1698 newap.av.redoList = viewport.redoList;
1699 newap.av.viewName = "View " +
1700 (Desktop.getViewCount(viewport.getSequenceSetId()) + 1);
1702 addAlignmentPanel(newap, false);
1704 if(alignPanels.size()==2)
1706 viewport.gatherViewsHere = true;
1708 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1715 * @param e DOCUMENT ME!
1717 public void font_actionPerformed(ActionEvent e)
1719 new FontChooser(alignPanel);
1726 * @param e DOCUMENT ME!
1728 protected void seqLimit_actionPerformed(ActionEvent e)
1730 viewport.setShowJVSuffix(seqLimits.isSelected());
1732 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1733 alignPanel.repaint();
1740 * @param e DOCUMENT ME!
1742 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1744 viewport.setColourText(colourTextMenuItem.isSelected());
1745 alignPanel.repaint();
1751 * @param e DOCUMENT ME!
1753 public void wrapMenuItem_actionPerformed(ActionEvent e)
1755 scaleAbove.setVisible(wrapMenuItem.isSelected());
1756 scaleLeft.setVisible(wrapMenuItem.isSelected());
1757 scaleRight.setVisible(wrapMenuItem.isSelected());
1758 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1759 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1762 public void showAllSeqs_actionPerformed(ActionEvent e)
1764 viewport.showAllHiddenSeqs();
1767 public void showAllColumns_actionPerformed(ActionEvent e)
1769 viewport.showAllHiddenColumns();
1773 public void hideSelSequences_actionPerformed(ActionEvent e)
1775 viewport.hideAllSelectedSeqs();
1776 alignPanel.repaint();
1779 public void hideSelColumns_actionPerformed(ActionEvent e)
1781 viewport.hideSelectedColumns();
1782 alignPanel.repaint();
1785 public void hiddenMarkers_actionPerformed(ActionEvent e)
1787 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1794 * @param e DOCUMENT ME!
1796 protected void scaleAbove_actionPerformed(ActionEvent e)
1798 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1799 alignPanel.repaint();
1805 * @param e DOCUMENT ME!
1807 protected void scaleLeft_actionPerformed(ActionEvent e)
1809 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1810 alignPanel.repaint();
1816 * @param e DOCUMENT ME!
1818 protected void scaleRight_actionPerformed(ActionEvent e)
1820 viewport.setScaleRightWrapped(scaleRight.isSelected());
1821 alignPanel.repaint();
1827 * @param e DOCUMENT ME!
1829 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1831 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1832 alignPanel.repaint();
1838 * @param e DOCUMENT ME!
1840 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1842 viewport.setShowText(viewTextMenuItem.isSelected());
1843 alignPanel.repaint();
1849 * @param e DOCUMENT ME!
1851 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1853 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1854 alignPanel.repaint();
1858 public FeatureSettings featureSettings;
1859 public void featureSettings_actionPerformed(ActionEvent e)
1861 if(featureSettings !=null )
1863 featureSettings.close();
1864 featureSettings = null;
1866 featureSettings = new FeatureSettings(this);
1872 * @param evt DOCUMENT ME!
1874 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1876 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1877 alignPanel.repaint();
1878 if (alignPanel.getOverviewPanel() != null)
1880 alignPanel.getOverviewPanel().updateOverviewImage();
1887 * @param e DOCUMENT ME!
1889 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1891 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1892 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1898 * @param e DOCUMENT ME!
1900 public void overviewMenuItem_actionPerformed(ActionEvent e)
1902 if (alignPanel.overviewPanel != null)
1907 JInternalFrame frame = new JInternalFrame();
1908 OverviewPanel overview = new OverviewPanel(alignPanel);
1909 frame.setContentPane(overview);
1910 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1911 frame.getWidth(), frame.getHeight());
1913 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1914 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1916 public void internalFrameClosed(
1917 javax.swing.event.InternalFrameEvent evt)
1919 alignPanel.setOverviewPanel(null);
1924 alignPanel.setOverviewPanel(overview);
1927 public void textColour_actionPerformed(ActionEvent e)
1929 int original1 = viewport.textColour.getRGB();
1930 int original2 = viewport.textColour2.getRGB();
1931 int thresh = viewport.thresholdTextColour;
1932 final JSlider slider = new JSlider(0, 750, viewport.thresholdTextColour);
1933 final JButton col1 = new JButton("DARK");
1934 col1.setBackground(viewport.textColour);
1935 col1.setForeground(viewport.textColour);
1936 final JButton col2 = new JButton("LIGHT");
1937 col2.setBackground(viewport.textColour2);
1938 col2.setForeground(viewport.textColour2);
1939 final JPanel bigpanel = new JPanel(new BorderLayout());
1940 JPanel panel = new JPanel();
1941 bigpanel.add(panel, BorderLayout.CENTER);
1942 bigpanel.add(new JLabel(
1943 "<html><i>Select a dark and light text colour, then set the threshold to"
1944 +"<br>switch between colours, based on background colour</i></html>"),
1945 BorderLayout.NORTH);
1950 col1.addActionListener(new ActionListener()
1952 public void actionPerformed(ActionEvent e)
1954 Color col = JColorChooser.showDialog(bigpanel,
1955 "Select Colour for Text",
1956 viewport.textColour);
1959 viewport.textColour = col;
1960 col1.setBackground(col);
1961 col1.setForeground(col);
1962 if(viewport.colourAppliesToAllGroups)
1963 setGroupTextColour();
1965 alignPanel.repaint();
1969 col2.addActionListener(new ActionListener()
1971 public void actionPerformed(ActionEvent e)
1973 Color col = JColorChooser.showDialog(bigpanel,
1974 "Select Colour for Text",
1975 viewport.textColour);
1978 viewport.textColour2 = col;
1979 col2.setBackground(col);
1980 col2.setForeground(col);
1981 if(viewport.colourAppliesToAllGroups)
1982 setGroupTextColour();
1984 alignPanel.repaint();
1989 slider.addChangeListener(new ChangeListener()
1991 public void stateChanged(ChangeEvent evt)
1993 viewport.thresholdTextColour = slider.getValue();
1994 if(viewport.colourAppliesToAllGroups)
1995 setGroupTextColour();
1996 alignPanel.repaint();
2000 int reply = JOptionPane.showInternalOptionDialog(this,
2002 "Adjust Foreground Text Colour Threshold",
2003 JOptionPane.OK_CANCEL_OPTION,
2004 JOptionPane.QUESTION_MESSAGE,
2008 if(reply==JOptionPane.CANCEL_OPTION)
2010 viewport.textColour = new Color(original1);
2011 viewport.textColour2 = new Color(original2);
2012 viewport.thresholdTextColour = thresh;
2016 void setGroupTextColour()
2018 if(viewport.alignment.getGroups()==null)
2021 Vector groups = viewport.alignment.getGroups();
2023 for(int i=0; i<groups.size(); i++)
2025 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
2026 sg.textColour = viewport.textColour;
2027 sg.textColour2 = viewport.textColour2;
2028 sg.thresholdTextColour = viewport.thresholdTextColour;
2038 * @param e DOCUMENT ME!
2040 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2048 * @param e DOCUMENT ME!
2050 public void clustalColour_actionPerformed(ActionEvent e)
2052 changeColour(new ClustalxColourScheme(
2053 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2059 * @param e DOCUMENT ME!
2061 public void zappoColour_actionPerformed(ActionEvent e)
2063 changeColour(new ZappoColourScheme());
2069 * @param e DOCUMENT ME!
2071 public void taylorColour_actionPerformed(ActionEvent e)
2073 changeColour(new TaylorColourScheme());
2079 * @param e DOCUMENT ME!
2081 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2083 changeColour(new HydrophobicColourScheme());
2089 * @param e DOCUMENT ME!
2091 public void helixColour_actionPerformed(ActionEvent e)
2093 changeColour(new HelixColourScheme());
2099 * @param e DOCUMENT ME!
2101 public void strandColour_actionPerformed(ActionEvent e)
2103 changeColour(new StrandColourScheme());
2109 * @param e DOCUMENT ME!
2111 public void turnColour_actionPerformed(ActionEvent e)
2113 changeColour(new TurnColourScheme());
2119 * @param e DOCUMENT ME!
2121 public void buriedColour_actionPerformed(ActionEvent e)
2123 changeColour(new BuriedColourScheme());
2129 * @param e DOCUMENT ME!
2131 public void nucleotideColour_actionPerformed(ActionEvent e)
2133 changeColour(new NucleotideColourScheme());
2136 public void annotationColour_actionPerformed(ActionEvent e)
2138 new AnnotationColourChooser(viewport, alignPanel);
2145 * @param e DOCUMENT ME!
2147 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2149 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2155 * @param cs DOCUMENT ME!
2157 public void changeColour(ColourSchemeI cs)
2163 if (viewport.getAbovePIDThreshold())
2165 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2168 cs.setThreshold(threshold,
2169 viewport.getIgnoreGapsConsensus());
2171 viewport.setGlobalColourScheme(cs);
2175 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2178 if (viewport.getConservationSelected())
2181 Alignment al = (Alignment) viewport.alignment;
2182 Conservation c = new Conservation("All",
2183 ResidueProperties.propHash, 3,
2184 al.getSequences(), 0,
2188 c.verdict(false, viewport.ConsPercGaps);
2190 cs.setConservation(c);
2192 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2197 cs.setConservation(null);
2200 cs.setConsensus(viewport.hconsensus);
2203 viewport.setGlobalColourScheme(cs);
2205 if (viewport.getColourAppliesToAllGroups())
2207 Vector groups = viewport.alignment.getGroups();
2209 for (int i = 0; i < groups.size(); i++)
2211 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2219 if (cs instanceof ClustalxColourScheme)
2221 sg.cs = new ClustalxColourScheme(
2222 sg.getSequences(true), sg.getWidth());
2224 else if (cs instanceof UserColourScheme)
2226 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2232 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2234 catch (Exception ex)
2239 if (viewport.getAbovePIDThreshold()
2240 || cs instanceof PIDColourScheme
2241 || cs instanceof Blosum62ColourScheme)
2243 sg.cs.setThreshold(threshold,
2244 viewport.getIgnoreGapsConsensus());
2246 sg.cs.setConsensus(AAFrequency.calculate(
2247 sg.getSequences(true), sg.getStartRes(),
2251 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2254 if (viewport.getConservationSelected())
2256 Conservation c = new Conservation("Group",
2257 ResidueProperties.propHash, 3,
2258 sg.getSequences(true),
2262 c.verdict(false, viewport.ConsPercGaps);
2263 sg.cs.setConservation(c);
2266 sg.cs.setConservation(null);
2270 if (alignPanel.getOverviewPanel() != null)
2272 alignPanel.getOverviewPanel().updateOverviewImage();
2275 alignPanel.repaint();
2281 * @param e DOCUMENT ME!
2283 protected void modifyPID_actionPerformed(ActionEvent e)
2285 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2287 SliderPanel.setPIDSliderSource(alignPanel,
2288 viewport.getGlobalColourScheme(),
2290 SliderPanel.showPIDSlider();
2297 * @param e DOCUMENT ME!
2299 protected void modifyConservation_actionPerformed(ActionEvent e)
2301 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2303 SliderPanel.setConservationSlider(alignPanel,
2304 viewport.globalColourScheme,
2306 SliderPanel.showConservationSlider();
2313 * @param e DOCUMENT ME!
2315 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2317 viewport.setConservationSelected(conservationMenuItem.isSelected());
2319 viewport.setAbovePIDThreshold(false);
2320 abovePIDThreshold.setSelected(false);
2322 changeColour(viewport.getGlobalColourScheme());
2324 modifyConservation_actionPerformed(null);
2330 * @param e DOCUMENT ME!
2332 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2334 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2336 conservationMenuItem.setSelected(false);
2337 viewport.setConservationSelected(false);
2339 changeColour(viewport.getGlobalColourScheme());
2341 modifyPID_actionPerformed(null);
2347 * @param e DOCUMENT ME!
2349 public void userDefinedColour_actionPerformed(ActionEvent e)
2351 if (e.getActionCommand().equals("User Defined..."))
2353 new UserDefinedColours(alignPanel, null);
2357 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2358 getUserColourSchemes().get(e.getActionCommand());
2364 public void updateUserColourMenu()
2367 Component[] menuItems = colourMenu.getMenuComponents();
2368 int i, iSize = menuItems.length;
2369 for (i = 0; i < iSize; i++)
2371 if (menuItems[i].getName() != null &&
2372 menuItems[i].getName().equals("USER_DEFINED"))
2374 colourMenu.remove(menuItems[i]);
2378 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2380 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2381 getUserColourSchemes().keys();
2383 while (userColours.hasMoreElements())
2385 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2386 nextElement().toString());
2387 radioItem.setName("USER_DEFINED");
2388 radioItem.addMouseListener(new MouseAdapter()
2390 public void mousePressed(MouseEvent evt)
2392 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2394 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2396 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2397 "Remove from default list?",
2398 "Remove user defined colour",
2399 JOptionPane.YES_NO_OPTION);
2400 if(option == JOptionPane.YES_OPTION)
2402 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2403 colourMenu.remove(radioItem);
2406 radioItem.addActionListener(new ActionListener()
2408 public void actionPerformed(ActionEvent evt)
2410 userDefinedColour_actionPerformed(evt);
2416 radioItem.addActionListener(new ActionListener()
2418 public void actionPerformed(ActionEvent evt)
2420 userDefinedColour_actionPerformed(evt);
2424 colourMenu.insert(radioItem, 15);
2425 colours.add(radioItem);
2433 * @param e DOCUMENT ME!
2435 public void PIDColour_actionPerformed(ActionEvent e)
2437 changeColour(new PIDColourScheme());
2443 * @param e DOCUMENT ME!
2445 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2447 changeColour(new Blosum62ColourScheme());
2453 * @param e DOCUMENT ME!
2455 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2457 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2458 AlignmentSorter.sortByPID(viewport.getAlignment(),
2459 viewport.getAlignment().getSequenceAt(0));
2460 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2461 alignPanel.repaint();
2467 * @param e DOCUMENT ME!
2469 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2471 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2472 AlignmentSorter.sortByID(viewport.getAlignment());
2473 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2474 alignPanel.repaint();
2480 * @param e DOCUMENT ME!
2482 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2484 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2485 AlignmentSorter.sortByGroup(viewport.getAlignment());
2486 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2488 alignPanel.repaint();
2494 * @param e DOCUMENT ME!
2496 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2498 new RedundancyPanel(alignPanel, this);
2505 * @param e DOCUMENT ME!
2507 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2509 if ( (viewport.getSelectionGroup() == null) ||
2510 (viewport.getSelectionGroup().getSize(false) < 2))
2512 JOptionPane.showInternalMessageDialog(this,
2513 "You must select at least 2 sequences.",
2514 "Invalid Selection",
2515 JOptionPane.WARNING_MESSAGE);
2519 JInternalFrame frame = new JInternalFrame();
2520 frame.setContentPane(new PairwiseAlignPanel(viewport));
2521 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2528 * @param e DOCUMENT ME!
2530 public void PCAMenuItem_actionPerformed(ActionEvent e)
2532 if ( ( (viewport.getSelectionGroup() != null) &&
2533 (viewport.getSelectionGroup().getSize(false) < 4) &&
2534 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2535 (viewport.getAlignment().getHeight() < 4))
2537 JOptionPane.showInternalMessageDialog(this,
2538 "Principal component analysis must take\n" +
2539 "at least 4 input sequences.",
2540 "Sequence selection insufficient",
2541 JOptionPane.WARNING_MESSAGE);
2546 new PCAPanel(viewport);
2550 public void autoCalculate_actionPerformed(ActionEvent e)
2552 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2553 if(viewport.autoCalculateConsensus)
2555 viewport.firePropertyChange("alignment",
2557 viewport.getAlignment().getSequences());
2565 * @param e DOCUMENT ME!
2567 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2569 NewTreePanel("AV", "PID", "Average distance tree using PID");
2575 * @param e DOCUMENT ME!
2577 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2579 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2585 * @param e DOCUMENT ME!
2587 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2589 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2595 * @param e DOCUMENT ME!
2597 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2599 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2605 * @param type DOCUMENT ME!
2606 * @param pwType DOCUMENT ME!
2607 * @param title DOCUMENT ME!
2609 void NewTreePanel(String type, String pwType, String title)
2613 if (viewport.getSelectionGroup() != null) {
2614 if (viewport.getSelectionGroup().getSize(false) < 3) {
2615 JOptionPane.showMessageDialog(Desktop.desktop,
2616 "You need to have more than two sequences selected to build a tree!",
2617 "Not enough sequences",
2618 JOptionPane.WARNING_MESSAGE);
2623 SequenceGroup sg = viewport.getSelectionGroup();
2625 /* Decide if the selection is a column region */
2626 while (s < sg.getSize(false))
2628 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2631 JOptionPane.showMessageDialog(Desktop.desktop,
2632 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2633 "Try using the Pad function in the edit menu,\n" +
2634 "or one of the multiple sequence alignment web services.",
2635 "Sequences in selection are not aligned",
2636 JOptionPane.WARNING_MESSAGE);
2642 title = title + " on region";
2643 tp = new TreePanel(alignPanel, type, pwType);
2647 //are the sequences aligned?
2648 if (!viewport.alignment.isAligned())
2650 JOptionPane.showMessageDialog(Desktop.desktop,
2651 "The sequences must be aligned before creating a tree.\n" +
2652 "Try using the Pad function in the edit menu,\n" +
2653 "or one of the multiple sequence alignment web services.",
2654 "Sequences not aligned",
2655 JOptionPane.WARNING_MESSAGE);
2660 if(viewport.alignment.getHeight()<2)
2663 tp = new TreePanel(alignPanel, type, pwType);
2666 addTreeMenuItem(tp, title);
2668 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2674 * @param title DOCUMENT ME!
2675 * @param order DOCUMENT ME!
2677 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2679 final JMenuItem item = new JMenuItem("by " + title);
2681 item.addActionListener(new java.awt.event.ActionListener()
2683 public void actionPerformed(ActionEvent e)
2685 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2687 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2688 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2690 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2692 alignPanel.repaint();
2698 * Maintain the Order by->Displayed Tree menu.
2699 * Creates a new menu item for a TreePanel with an appropriate
2700 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2701 * to remove the menu item when the treePanel is closed, and adjust
2702 * the tree leaf to sequence mapping when the alignment is modified.
2703 * @param treePanel Displayed tree window.
2704 * @param title SortBy menu item title.
2706 void addTreeMenuItem(final TreePanel treePanel, String title)
2708 final JMenuItem item = new JMenuItem(title);
2714 sort.add(sortByTreeMenu);
2717 sortByTreeMenu.add(item);
2718 item.addActionListener(new java.awt.event.ActionListener()
2720 public void actionPerformed(ActionEvent e)
2722 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2723 AlignmentSorter.sortByTree(viewport.getAlignment(),
2724 treePanel.getTree());
2726 addHistoryItem(new OrderCommand("Tree Sort",
2728 viewport.alignment));
2731 alignPanel.repaint();
2735 treePanel.addInternalFrameListener(new javax.swing.event.
2736 InternalFrameAdapter()
2738 public void internalFrameClosed(
2739 javax.swing.event.InternalFrameEvent evt)
2742 sortByTreeMenu.remove(item);
2746 sort.remove(sortByTreeMenu);
2754 * Work out whether the whole set of sequences
2755 * or just the selected set will be submitted for multiple alignment.
2758 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2760 // Now, check we have enough sequences
2761 AlignmentView msa = null;
2763 if ( (viewport.getSelectionGroup() != null) &&
2764 (viewport.getSelectionGroup().getSize(false) > 1))
2766 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2767 /*SequenceGroup seqs = viewport.getSelectionGroup();
2769 msa = new SequenceI[sz = seqs.getSize(false)];
2771 for (int i = 0; i < sz; i++)
2773 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2775 msa = viewport.getAlignmentView(true);
2779 /*Vector seqs = viewport.getAlignment().getSequences();
2781 if (seqs.size() > 1)
2783 msa = new SequenceI[seqs.size()];
2785 for (int i = 0; i < seqs.size(); i++)
2787 msa[i] = (SequenceI) seqs.elementAt(i);
2790 msa = viewport.getAlignmentView(false);
2796 * Decides what is submitted to a secondary structure prediction service,
2797 * the currently selected sequence, or the currently selected alignment
2798 * (where the first sequence in the set is the one that the prediction
2801 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2803 AlignmentView seqs = null;
2805 if ( (viewport.getSelectionGroup() != null) &&
2806 (viewport.getSelectionGroup().getSize(false) > 0))
2808 seqs = viewport.getAlignmentView(true);
2812 seqs = viewport.getAlignmentView(false);
2814 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2815 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2816 if (!viewport.alignment.isAligned())
2818 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2825 * @param e DOCUMENT ME!
2827 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2829 // Pick the tree file
2830 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2833 chooser.setFileView(new JalviewFileView());
2834 chooser.setDialogTitle("Select a newick-like tree file");
2835 chooser.setToolTipText("Load a tree file");
2837 int value = chooser.showOpenDialog(null);
2839 if (value == JalviewFileChooser.APPROVE_OPTION)
2841 String choice = chooser.getSelectedFile().getPath();
2842 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2846 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2848 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2850 catch (Exception ex)
2852 JOptionPane.showMessageDialog(Desktop.desktop,
2853 "Problem reading tree file",
2855 JOptionPane.WARNING_MESSAGE);
2856 ex.printStackTrace();
2862 public TreePanel ShowNewickTree(NewickFile nf, String title)
2864 return ShowNewickTree(nf,title,600,500,4,5);
2866 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2868 return ShowNewickTree(nf,title, input, 600,500,4,5);
2870 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2871 return ShowNewickTree(nf, title, null, w, h, x, y);
2874 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2876 * @param nf the tree
2877 * @param title tree viewer title
2878 * @param input Associated alignment input data (or null)
2883 * @return TreePanel handle
2885 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2886 TreePanel tp = null;
2892 if (nf.getTree() != null)
2894 tp = new TreePanel(alignPanel,
2902 tp.setLocation(x,y);
2905 Desktop.addInternalFrame(tp, title, w, h);
2906 addTreeMenuItem(tp, title);
2909 catch (Exception ex)
2911 ex.printStackTrace();
2922 PrinterJob printJob = PrinterJob.getPrinterJob();
2923 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2924 printJob.setPrintable(alignPanel, pf);
2926 if (printJob.printDialog())
2932 catch (Exception PrintException)
2934 PrintException.printStackTrace();
2941 * Generates menu items and listener event actions for web service clients
2944 public void BuildWebServiceMenu()
2946 if ( (Discoverer.services != null)
2947 && (Discoverer.services.size() > 0))
2949 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2950 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2951 Vector wsmenu = new Vector();
2952 final AlignFrame af = this;
2955 // Add any Multiple Sequence Alignment Services
2956 final JMenu msawsmenu = new JMenu("Alignment");
2957 for (int i = 0, j = msaws.size(); i < j; i++)
2959 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2961 final JMenuItem method = new JMenuItem(sh.getName());
2962 method.addActionListener(new ActionListener()
2964 public void actionPerformed(ActionEvent e)
2966 AlignmentView msa = gatherSequencesForAlignment();
2967 new jalview.ws.MsaWSClient(sh, title, msa,
2968 false, true, viewport.getAlignment().getDataset(), af);
2973 msawsmenu.add(method);
2974 // Deal with services that we know accept partial alignments.
2975 if (sh.getName().indexOf("lustal") > -1)
2977 // We know that ClustalWS can accept partial alignments for refinement.
2978 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2979 methodR.addActionListener(new ActionListener()
2981 public void actionPerformed(ActionEvent e)
2983 AlignmentView msa = gatherSequencesForAlignment();
2984 new jalview.ws.MsaWSClient(sh, title, msa,
2985 true, true, viewport.getAlignment().getDataset(), af);
2990 msawsmenu.add(methodR);
2994 wsmenu.add(msawsmenu);
2996 if (secstrpr != null)
2998 // Add any secondary structure prediction services
2999 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3000 for (int i = 0, j = secstrpr.size(); i < j; i++)
3002 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3004 final JMenuItem method = new JMenuItem(sh.getName());
3005 method.addActionListener(new ActionListener()
3007 public void actionPerformed(ActionEvent e)
3009 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3010 if (msa.getSequences().length == 1)
3012 // Single Sequence prediction
3013 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3017 if (msa.getSequences().length > 1)
3019 // Sequence profile based prediction
3020 new jalview.ws.JPredClient(sh,
3021 title, true, msa, af, true);
3026 secstrmenu.add(method);
3028 wsmenu.add(secstrmenu);
3030 this.webService.removeAll();
3031 for (int i = 0, j = wsmenu.size(); i < j; i++)
3033 webService.add( (JMenu) wsmenu.get(i));
3038 this.webService.removeAll();
3039 this.webService.add(this.webServiceNoServices);
3041 // TODO: add in rediscovery function
3042 // TODO: reduce code redundancy.
3043 // TODO: group services by location as well as function.
3046 /* public void vamsasStore_actionPerformed(ActionEvent e)
3048 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3049 getProperty("LAST_DIRECTORY"));
3051 chooser.setFileView(new JalviewFileView());
3052 chooser.setDialogTitle("Export to Vamsas file");
3053 chooser.setToolTipText("Export");
3055 int value = chooser.showSaveDialog(this);
3057 if (value == JalviewFileChooser.APPROVE_OPTION)
3059 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3060 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3061 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3068 public void showTranslation_actionPerformed(ActionEvent e)
3070 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3071 String [] seqstring = viewport.getViewAsString(true);
3073 int s, sSize = selection.length;
3074 SequenceI [] newSeq = new SequenceI[sSize];
3077 StringBuffer protein;
3079 for(s=0; s<sSize; s++)
3081 protein = new StringBuffer();
3082 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3083 resSize = seq.length();
3084 resSize -= resSize%3;
3086 for(res = 0; res < resSize; res+=3)
3088 String codon = seq.substring(res, res+3);
3089 codon = codon.replace('U', 'T');
3090 String aa = ResidueProperties.codonTranslate(codon);
3092 protein.append(viewport.getGapCharacter());
3093 else if(aa.equals("STOP"))
3094 protein.append("X");
3096 protein.append( aa );
3098 newSeq[s] = new Sequence(selection[s].getName(),
3099 protein.toString());
3103 AlignmentI al = new Alignment(newSeq);
3104 al.setDataset(null);
3107 ////////////////////////////////
3108 // Copy annotations across
3109 jalview.datamodel.AlignmentAnnotation[] annotations
3110 = viewport.alignment.getAlignmentAnnotation();
3112 if(annotations!=null)
3114 for (int i = 0; i < annotations.length; i++)
3116 if (annotations[i].label.equals("Quality") ||
3117 annotations[i].label.equals("Conservation") ||
3118 annotations[i].label.equals("Consensus"))
3123 aSize = viewport.alignment.getWidth() / 3;
3124 jalview.datamodel.Annotation[] anots =
3125 new jalview.datamodel.Annotation[aSize];
3127 for (a = 0; a < viewport.alignment.getWidth(); a++)
3129 if (annotations[i].annotations[a] == null
3130 || annotations[i].annotations[a] == null)
3133 anots[a / 3] = new Annotation(
3134 annotations[i].annotations[a].displayCharacter,
3135 annotations[i].annotations[a].description,
3136 annotations[i].annotations[a].secondaryStructure,
3137 annotations[i].annotations[a].value,
3138 annotations[i].annotations[a].colour);
3141 jalview.datamodel.AlignmentAnnotation aa
3142 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3143 annotations[i].description, anots);
3144 al.addAnnotation(aa);
3148 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3149 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3161 * @param String DOCUMENT ME!
3163 public boolean parseFeaturesFile(String file, String type)
3165 boolean featuresFile = false;
3167 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3168 alignPanel.seqPanel.seqCanvas.
3169 getFeatureRenderer().featureColours,
3174 ex.printStackTrace();
3179 viewport.showSequenceFeatures = true;
3180 showSeqFeatures.setSelected(true);
3181 alignPanel.repaint();
3184 return featuresFile;
3187 public void dragEnter(DropTargetDragEvent evt)
3190 public void dragExit(DropTargetEvent evt)
3193 public void dragOver(DropTargetDragEvent evt)
3196 public void dropActionChanged(DropTargetDragEvent evt)
3199 public void drop(DropTargetDropEvent evt)
3201 Transferable t = evt.getTransferable();
3202 java.util.List files = null;
3206 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3207 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3209 //Works on Windows and MacOSX
3210 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3211 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3213 else if (t.isDataFlavorSupported(uriListFlavor))
3215 // This is used by Unix drag system
3216 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3217 String data = (String) t.getTransferData(uriListFlavor);
3218 files = new java.util.ArrayList(1);
3219 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3222 st.hasMoreTokens(); )
3224 String s = st.nextToken();
3225 if (s.startsWith("#"))
3227 // the line is a comment (as per the RFC 2483)
3231 java.net.URI uri = new java.net.URI(s);
3232 java.io.File file = new java.io.File(uri);
3239 e.printStackTrace();
3246 for (int i = 0; i < files.size(); i++)
3248 loadJalviewDataFile(files.get(i).toString());
3251 catch (Exception ex)
3253 ex.printStackTrace();
3258 // This method will attempt to load a "dropped" file first by testing
3259 // whether its and Annotation file, then features file. If both are
3260 // false then the user may have dropped an alignment file onto this
3262 public void loadJalviewDataFile(String file)
3265 String protocol = "File";
3267 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3272 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3277 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3280 String format = new IdentifyFile().Identify(file, protocol);
3282 if(format.equalsIgnoreCase("JnetFile"))
3284 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3286 new JnetAnnotationMaker().add_annotation(predictions,
3287 viewport.getAlignment(),
3289 alignPanel.adjustAnnotationHeight();
3290 alignPanel.repaint();
3293 new FileLoader().LoadFile(viewport, file, protocol, format);
3299 alignPanel.adjustAnnotationHeight();
3302 }catch(Exception ex)
3304 ex.printStackTrace();
3308 public void tabSelectionChanged(int index)
3312 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3313 viewport = alignPanel.av;
3314 setMenusFromViewport(viewport);
3318 public void tabbedPane_mousePressed(MouseEvent e)
3320 if(SwingUtilities.isRightMouseButton(e))
3322 String reply = JOptionPane.showInternalInputDialog(this,
3325 JOptionPane.QUESTION_MESSAGE);
3329 viewport.viewName = reply;
3330 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3336 public AlignViewport getCurrentView()