2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentUtils;
24 import jalview.api.StructureSelectionManagerProvider;
25 import jalview.appletgui.AlignFrame;
26 import jalview.appletgui.AlignViewport;
27 import jalview.appletgui.EmbmenuFrame;
28 import jalview.appletgui.FeatureSettings;
29 import jalview.appletgui.SplitFrame;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AlignmentOrder;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.AnnotationFile;
39 import jalview.io.AppletFormatAdapter;
40 import jalview.io.FileParse;
41 import jalview.io.IdentifyFile;
42 import jalview.io.JPredFile;
43 import jalview.io.JnetAnnotationMaker;
44 import jalview.io.NewickFile;
45 import jalview.javascript.JSFunctionExec;
46 import jalview.javascript.JalviewLiteJsApi;
47 import jalview.javascript.JsCallBack;
48 import jalview.structure.SelectionListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.util.MessageManager;
52 import java.applet.Applet;
53 import java.awt.Button;
54 import java.awt.Color;
55 import java.awt.Component;
56 import java.awt.EventQueue;
58 import java.awt.Frame;
59 import java.awt.Graphics;
60 import java.awt.event.ActionEvent;
61 import java.awt.event.WindowAdapter;
62 import java.awt.event.WindowEvent;
63 import java.io.BufferedReader;
64 import java.io.IOException;
65 import java.io.InputStream;
66 import java.io.InputStreamReader;
68 import java.util.Hashtable;
69 import java.util.List;
70 import java.util.StringTokenizer;
71 import java.util.Vector;
73 import netscape.javascript.JSObject;
76 * Jalview Applet. Runs in Java 1.18 runtime
79 * @version $Revision: 1.92 $
81 public class JalviewLite extends Applet implements
82 StructureSelectionManagerProvider, JalviewLiteJsApi
85 private static final String TRUE = "true";
87 private static final String FALSE = "false";
89 public StructureSelectionManager getStructureSelectionManager()
91 return StructureSelectionManager.getStructureSelectionManager(this);
94 // /////////////////////////////////////////
95 // The following public methods may be called
96 // externally, eg via javascript in HTML page
100 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
102 public String getSelectedSequences()
104 return getSelectedSequencesFrom(getDefaultTargetFrame());
110 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
112 public String getSelectedSequences(String sep)
114 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
121 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
124 public String getSelectedSequencesFrom(AlignFrame alf)
126 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
133 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
134 * .AlignFrame, java.lang.String)
136 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
138 StringBuffer result = new StringBuffer("");
139 if (sep == null || sep.length() == 0)
141 sep = separator; // "+0x00AC;
143 if (alf.viewport.getSelectionGroup() != null)
145 SequenceI[] seqs = alf.viewport.getSelectionGroup()
146 .getSequencesInOrder(alf.viewport.getAlignment());
148 for (int i = 0; i < seqs.length; i++)
150 result.append(seqs[i].getName());
155 return result.toString();
161 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
162 * java.lang.String, java.lang.String)
164 public void highlight(String sequenceId, String position,
165 String alignedPosition)
167 highlightIn(getDefaultTargetFrame(), sequenceId, position,
174 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
175 * java.lang.String, java.lang.String, java.lang.String)
177 public void highlightIn(final AlignFrame alf, final String sequenceId,
178 final String position, final String alignedPosition)
180 // TODO: could try to highlight in all alignments if alf==null
181 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
182 alf.viewport.getAlignment().getSequencesArray());
183 final SequenceI sq = matcher.findIdMatch(sequenceId);
189 apos = new Integer(position).intValue();
191 } catch (NumberFormatException ex)
195 final StructureSelectionManagerProvider me = this;
196 final int pos = apos;
197 // use vamsas listener to broadcast to all listeners in scope
198 if (alignedPosition != null
199 && (alignedPosition.trim().length() == 0 || alignedPosition
200 .toLowerCase().indexOf("false") > -1))
202 java.awt.EventQueue.invokeLater(new Runnable()
207 StructureSelectionManager.getStructureSelectionManager(me)
208 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
214 java.awt.EventQueue.invokeLater(new Runnable()
219 StructureSelectionManager.getStructureSelectionManager(me)
220 .mouseOverVamsasSequence(sq, pos, null);
230 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
233 public void select(String sequenceIds, String columns)
235 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
241 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
242 * java.lang.String, java.lang.String)
244 public void select(String sequenceIds, String columns, String sep)
246 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
252 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
253 * java.lang.String, java.lang.String)
255 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
257 selectIn(alf, sequenceIds, columns, separator);
263 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
264 * java.lang.String, java.lang.String, java.lang.String)
266 public void selectIn(final AlignFrame alf, String sequenceIds,
267 String columns, String sep)
269 if (sep == null || sep.length() == 0)
277 System.err.println("Selecting region using separator string '"
282 String[] ids = separatorListToArray(sequenceIds, sep);
283 String[] cols = separatorListToArray(columns, sep);
284 final SequenceGroup sel = new SequenceGroup();
285 final ColumnSelection csel = new ColumnSelection();
286 AlignmentI al = alf.viewport.getAlignment();
287 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
288 alf.viewport.getAlignment().getSequencesArray());
289 int start = 0, end = al.getWidth(), alw = al.getWidth();
290 boolean seqsfound = true;
291 if (ids != null && ids.length > 0)
294 for (int i = 0; i < ids.length; i++)
296 if (ids[i].trim().length() == 0)
300 SequenceI sq = matcher.findIdMatch(ids[i]);
304 sel.addSequence(sq, false);
308 boolean inseqpos = false;
309 if (cols != null && cols.length > 0)
311 boolean seset = false;
312 for (int i = 0; i < cols.length; i++)
314 String cl = cols[i].trim();
315 if (cl.length() == 0)
320 if ((p = cl.indexOf("-")) > -1)
322 int from = -1, to = -1;
325 from = new Integer(cl.substring(0, p)).intValue();
327 } catch (NumberFormatException ex)
330 .println("ERROR: Couldn't parse first integer in range element column selection string '"
331 + cl + "' - format is 'from-to'");
336 to = new Integer(cl.substring(p + 1)).intValue();
338 } catch (NumberFormatException ex)
341 .println("ERROR: Couldn't parse second integer in range element column selection string '"
342 + cl + "' - format is 'from-to'");
345 if (from >= 0 && to >= 0)
362 // comment to prevent range extension
372 for (int r = from; r <= to; r++)
374 if (r >= 0 && r < alw)
381 System.err.println("Range '" + cl + "' deparsed as [" + from
387 System.err.println("ERROR: Invalid Range '" + cl
388 + "' deparsed as [" + from + "," + to + "]");
396 r = new Integer(cl).intValue();
398 } catch (NumberFormatException ex)
400 if (cl.toLowerCase().equals("sequence"))
402 // we are in the dataset sequence's coordinate frame.
408 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
413 if (r >= 0 && r <= alw)
423 // comment to prevent range extension
436 System.err.println("Point selection '" + cl
437 + "' deparsed as [" + r + "]");
442 System.err.println("ERROR: Invalid Point selection '" + cl
443 + "' deparsed as [" + r + "]");
450 // we only propagate the selection when it was the null selection, or the
451 // given sequences were found in the alignment.
452 if (inseqpos && sel.getSize() > 0)
454 // assume first sequence provides reference frame ?
455 SequenceI rs = sel.getSequenceAt(0);
456 start = rs.findIndex(start);
457 end = rs.findIndex(end);
460 List<Integer> cs = csel.getSelected();
462 for (Integer selectedCol : cs)
464 csel.addElement(rs.findIndex(selectedCol));
468 sel.setStartRes(start);
470 EventQueue.invokeLater(new Runnable()
475 alf.select(sel, csel);
485 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
486 * String, java.lang.String)
488 public String getSelectedSequencesAsAlignment(String format, String suffix)
490 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
498 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
499 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
501 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
502 String format, String suffix)
506 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
507 if (alf.viewport.getSelectionGroup() != null)
509 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
510 // method now returns a full copy of sequence data
511 // TODO consider using getSequenceSelection instead here
512 String reply = new AppletFormatAdapter().formatSequences(format,
513 new Alignment(alf.viewport.getSelectionAsNewSequence()),
517 } catch (Exception ex)
519 ex.printStackTrace();
520 return "Error retrieving alignment in " + format + " format. ";
528 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
530 public String getAlignmentOrder()
532 return getAlignmentOrderFrom(getDefaultTargetFrame());
539 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
542 public String getAlignmentOrderFrom(AlignFrame alf)
544 return getAlignmentOrderFrom(alf, separator);
551 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
552 * , java.lang.String)
554 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
556 AlignmentI alorder = alf.getAlignViewport().getAlignment();
557 String[] order = new String[alorder.getHeight()];
558 for (int i = 0; i < order.length; i++)
560 order[i] = alorder.getSequenceAt(i).getName();
562 return arrayToSeparatorList(order);
568 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
571 public String orderBy(String order, String undoName)
573 return orderBy(order, undoName, separator);
579 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
580 * java.lang.String, java.lang.String)
582 public String orderBy(String order, String undoName, String sep)
584 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
591 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
592 * java.lang.String, java.lang.String, java.lang.String)
594 public String orderAlignmentBy(AlignFrame alf, String order,
595 String undoName, String sep)
597 String[] ids = separatorListToArray(order, sep);
598 SequenceI[] sqs = null;
599 if (ids != null && ids.length > 0)
601 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
602 alf.viewport.getAlignment().getSequencesArray());
604 sqs = new SequenceI[ids.length];
605 for (int i = 0; i < ids.length; i++)
607 if (ids[i].trim().length() == 0)
611 SequenceI sq = matcher.findIdMatch(ids[i]);
619 SequenceI[] sqq = new SequenceI[s];
620 System.arraycopy(sqs, 0, sqq, 0, s);
633 final AlignmentOrder aorder = new AlignmentOrder(sqs);
635 if (undoName != null && undoName.trim().length() == 0)
639 final String _undoName = undoName;
640 // TODO: deal with synchronization here: cannot raise any events until after
641 // this has returned.
642 return alf.sortBy(aorder, _undoName) ? TRUE : "";
648 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
650 public String getAlignment(String format)
652 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
659 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
662 public String getAlignmentFrom(AlignFrame alf, String format)
664 return getAlignmentFrom(alf, format, TRUE);
670 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
673 public String getAlignment(String format, String suffix)
675 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
682 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
683 * java.lang.String, java.lang.String)
685 public String getAlignmentFrom(AlignFrame alf, String format,
690 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
692 String reply = new AppletFormatAdapter().formatSequences(format,
693 alf.viewport.getAlignment(), seqlimits);
695 } catch (Exception ex)
697 ex.printStackTrace();
698 return "Error retrieving alignment in " + format + " format. ";
705 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
707 public void loadAnnotation(String annotation)
709 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
716 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
717 * , java.lang.String)
719 public void loadAnnotationFrom(AlignFrame alf, String annotation)
721 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
722 annotation, AppletFormatAdapter.PASTE))
724 alf.alignPanel.fontChanged();
725 alf.alignPanel.setScrollValues(0, 0);
729 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
736 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
738 public void loadFeatures(String features, boolean autoenabledisplay)
740 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
747 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
748 * , java.lang.String)
750 public boolean loadFeaturesFrom(AlignFrame alf, String features,
751 boolean autoenabledisplay)
753 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
760 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
762 public String getFeatures(String format)
764 return getFeaturesFrom(getDefaultTargetFrame(), format);
771 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
774 public String getFeaturesFrom(AlignFrame alf, String format)
776 return alf.outputFeatures(false, format);
782 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
784 public String getAnnotation()
786 return getAnnotationFrom(getDefaultTargetFrame());
793 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
796 public String getAnnotationFrom(AlignFrame alf)
798 return alf.outputAnnotations(false);
804 * @see jalview.bin.JalviewLiteJsApi#newView()
806 public AlignFrame newView()
808 return newViewFrom(getDefaultTargetFrame());
814 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
816 public AlignFrame newView(String name)
818 return newViewFrom(getDefaultTargetFrame(), name);
824 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
826 public AlignFrame newViewFrom(AlignFrame alf)
828 return alf.newView(null);
834 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
837 public AlignFrame newViewFrom(AlignFrame alf, String name)
839 return alf.newView(name);
845 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
848 public AlignFrame loadAlignment(String text, String title)
850 AlignmentI al = null;
852 String format = new IdentifyFile().Identify(text,
853 AppletFormatAdapter.PASTE);
856 al = new AppletFormatAdapter().readFile(text,
857 AppletFormatAdapter.PASTE, format);
858 if (al.getHeight() > 0)
860 return new AlignFrame(al, this, title, false);
862 } catch (java.io.IOException ex)
864 ex.printStackTrace();
872 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
874 public void setMouseoverListener(String listener)
876 setMouseoverListener(currentAlignFrame, listener);
879 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
885 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
886 * , java.lang.String)
888 public void setMouseoverListener(AlignFrame af, String listener)
890 if (listener != null)
892 listener = listener.trim();
893 if (listener.length() == 0)
896 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
900 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
902 javascriptListeners.addElement(mol);
903 StructureSelectionManager.getStructureSelectionManager(this)
904 .addStructureViewerListener(mol);
907 System.err.println("Added a mouseover listener for "
908 + ((af == null) ? "All frames" : "Just views for "
909 + af.getAlignViewport().getSequenceSetId()));
910 System.err.println("There are now " + javascriptListeners.size()
911 + " listeners in total.");
918 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
920 public void setSelectionListener(String listener)
922 setSelectionListener(null, listener);
929 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
930 * , java.lang.String)
932 public void setSelectionListener(AlignFrame af, String listener)
934 if (listener != null)
936 listener = listener.trim();
937 if (listener.length() == 0)
940 .println("jalview Javascript error: Ignoring empty function for selection listener.");
944 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
946 javascriptListeners.addElement(mol);
947 StructureSelectionManager.getStructureSelectionManager(this)
948 .addSelectionListener(mol);
951 System.err.println("Added a selection listener for "
952 + ((af == null) ? "All frames" : "Just views for "
953 + af.getAlignViewport().getSequenceSetId()));
954 System.err.println("There are now " + javascriptListeners.size()
955 + " listeners in total.");
960 * Callable from javascript to register a javascript function to pass events
961 * to a structure viewer.
964 * the name of a javascript function
966 * a token separated list of PDB file names listened for
967 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
970 public void setStructureListener(String listener, String modelSet)
972 if (listener != null)
974 listener = listener.trim();
975 if (listener.length() == 0)
978 .println("jalview Javascript error: Ignoring empty function for selection listener.");
982 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
983 this, listener, separatorListToArray(modelSet));
984 javascriptListeners.addElement(mol);
985 StructureSelectionManager.getStructureSelectionManager(this)
986 .addStructureViewerListener(mol);
989 System.err.println("Added a javascript structure viewer listener '"
991 System.err.println("There are now " + javascriptListeners.size()
992 + " listeners in total.");
1000 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
1001 * .AlignFrame, java.lang.String)
1003 public void removeJavascriptListener(AlignFrame af, String listener)
1005 if (listener != null)
1007 listener = listener.trim();
1008 if (listener.length() == 0)
1013 boolean rprt = false;
1014 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1016 Object lstn = javascriptListeners.elementAt(ms);
1017 JsCallBack lstner = (JsCallBack) lstn;
1018 if ((af == null || lstner.getAlignFrame() == af)
1019 && (listener == null || lstner.getListenerFunction().equals(
1022 javascriptListeners.removeElement(lstner);
1024 if (lstner instanceof SelectionListener)
1026 StructureSelectionManager.getStructureSelectionManager(this)
1027 .removeSelectionListener((SelectionListener) lstner);
1031 StructureSelectionManager.getStructureSelectionManager(this)
1032 .removeStructureViewerListener(lstner, null);
1037 System.err.println("Removed listener '" + listener + "'");
1047 System.err.println("There are now " + javascriptListeners.size()
1048 + " listeners in total.");
1054 System.err.println("Applet " + getName() + " stop().");
1058 public void destroy()
1060 System.err.println("Applet " + getName() + " destroy().");
1064 private void tidyUp()
1067 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1068 && currentAlignFrame.viewport.applet != null)
1070 AlignViewport av = currentAlignFrame.viewport;
1071 currentAlignFrame.closeMenuItem_actionPerformed();
1073 currentAlignFrame = null;
1075 if (javascriptListeners != null)
1077 while (javascriptListeners.size() > 0)
1079 jalview.javascript.JSFunctionExec mol = javascriptListeners
1081 javascriptListeners.removeElement(mol);
1082 if (mol instanceof SelectionListener)
1084 StructureSelectionManager.getStructureSelectionManager(this)
1085 .removeSelectionListener((SelectionListener) mol);
1089 StructureSelectionManager.getStructureSelectionManager(this)
1090 .removeStructureViewerListener(mol, null);
1095 if (jsFunctionExec != null)
1097 jsFunctionExec.stopQueue();
1098 jsFunctionExec.jvlite = null;
1100 initialAlignFrame = null;
1101 jsFunctionExec = null;
1102 javascriptListeners = null;
1103 StructureSelectionManager.release(this);
1106 private jalview.javascript.JSFunctionExec jsFunctionExec;
1111 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1112 * java.lang.String, java.lang.String)
1114 public void mouseOverStructure(final String pdbResNum,
1115 final String chain, final String pdbfile)
1117 final StructureSelectionManagerProvider me = this;
1118 java.awt.EventQueue.invokeLater(new Runnable()
1125 StructureSelectionManager.getStructureSelectionManager(me)
1126 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1130 System.err.println("mouseOver for '" + pdbResNum
1131 + "' in chain '" + chain + "' in structure '" + pdbfile
1134 } catch (NumberFormatException e)
1136 System.err.println("Ignoring invalid residue number string '"
1148 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1149 * java.lang.String, java.lang.String)
1151 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1152 final String leftHandColumn)
1154 java.awt.EventQueue.invokeLater(new Runnable()
1161 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1162 leftHandColumn).intValue());
1164 } catch (Exception ex)
1166 System.err.println("Couldn't parse integer arguments (topRow='"
1167 + topRow + "' and leftHandColumn='" + leftHandColumn
1169 ex.printStackTrace();
1179 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1180 * .AlignFrame, java.lang.String)
1183 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1186 java.awt.EventQueue.invokeLater(new Runnable()
1193 alf.scrollToRow(new Integer(topRow).intValue());
1195 } catch (Exception ex)
1197 System.err.println("Couldn't parse integer arguments (topRow='"
1199 ex.printStackTrace();
1210 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1211 * .AlignFrame, java.lang.String)
1214 public void scrollViewToColumnIn(final AlignFrame alf,
1215 final String leftHandColumn)
1217 java.awt.EventQueue.invokeLater(new Runnable()
1225 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1227 } catch (Exception ex)
1230 .println("Couldn't parse integer arguments (leftHandColumn='"
1231 + leftHandColumn + "')");
1232 ex.printStackTrace();
1239 // //////////////////////////////////////////////
1240 // //////////////////////////////////////////////
1242 public static int lastFrameX = 200;
1244 public static int lastFrameY = 200;
1246 boolean fileFound = true;
1248 String file = "No file";
1250 String file2 = null;
1252 Button launcher = new Button(
1253 MessageManager.getString("label.start_jalview"));
1256 * The currentAlignFrame is static, it will change if and when the user
1257 * selects a new window. Note that it will *never* point back to the embedded
1258 * AlignFrame if the applet is started as embedded on the page and then
1259 * afterwards a new view is created.
1261 public AlignFrame currentAlignFrame = null;
1264 * This is the first frame to be displayed, and does not change. API calls
1265 * will default to this instance if currentAlignFrame is null.
1267 AlignFrame initialAlignFrame = null;
1269 boolean embedded = false;
1271 private boolean checkForJmol = true;
1273 private boolean checkedForJmol = false; // ensure we don't check for jmol
1275 // every time the app is re-inited
1277 public boolean jmolAvailable = false;
1279 private boolean alignPdbStructures = false;
1282 * use an external structure viewer exclusively (no jmols or MCViews will be
1283 * opened by JalviewLite itself)
1285 public boolean useXtrnalSviewer = false;
1287 public static boolean debug = false;
1289 static String builddate = null, version = null, installation = null;
1291 private static void initBuildDetails()
1293 if (builddate == null)
1295 builddate = "unknown";
1297 installation = "applet";
1298 java.net.URL url = JalviewLite.class
1299 .getResource("/.build_properties");
1304 BufferedReader reader = new BufferedReader(new InputStreamReader(
1307 while ((line = reader.readLine()) != null)
1309 if (line.indexOf("VERSION") > -1)
1311 version = line.substring(line.indexOf("=") + 1);
1313 if (line.indexOf("BUILD_DATE") > -1)
1315 builddate = line.substring(line.indexOf("=") + 1);
1317 if (line.indexOf("INSTALLATION") > -1)
1319 installation = line.substring(line.indexOf("=") + 1);
1322 } catch (Exception ex)
1324 ex.printStackTrace();
1330 public static String getBuildDate()
1336 public static String getInstallation()
1339 return installation;
1342 public static String getVersion()
1348 // public JSObject scriptObject = null;
1351 * init method for Jalview Applet
1356 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1361 System.err.println("Applet context is '"
1362 + getAppletContext().getClass().toString() + "'");
1364 JSObject scriptObject = JSObject.getWindow(this);
1365 if (debug && scriptObject != null)
1367 System.err.println("Applet has Javascript callback support.");
1370 } catch (Exception ex)
1373 .println("Warning: No JalviewLite javascript callbacks available.");
1376 ex.printStackTrace();
1382 System.err.println("JalviewLite Version " + getVersion());
1383 System.err.println("Build Date : " + getBuildDate());
1384 System.err.println("Installation : " + getInstallation());
1386 String externalsviewer = getParameter("externalstructureviewer");
1387 if (externalsviewer != null)
1389 useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
1392 * if true disable the check for jmol
1394 String chkforJmol = getParameter("nojmol");
1395 if (chkforJmol != null)
1397 checkForJmol = !chkforJmol.equals(TRUE);
1400 * get the separator parameter if present
1402 String sep = getParameter("separator");
1405 if (sep.length() > 0)
1410 System.err.println("Separator set to '" + separator + "'");
1417 .getString("error.invalid_separator_parameter"));
1423 String param = getParameter("RGB");
1429 r = Integer.parseInt(param.substring(0, 2), 16);
1430 g = Integer.parseInt(param.substring(2, 4), 16);
1431 b = Integer.parseInt(param.substring(4, 6), 16);
1432 } catch (Exception ex)
1439 param = getParameter("label");
1442 launcher.setLabel(param);
1445 setBackground(new Color(r, g, b));
1447 file = getParameter("file");
1451 // Maybe the sequences are added as parameters
1452 StringBuffer data = new StringBuffer("PASTE");
1454 while ((file = getParameter("sequence" + i)) != null)
1456 data.append(file.toString() + "\n");
1459 if (data.length() > 5)
1461 file = data.toString();
1464 if (getDefaultParameter("enableSplitFrame", true))
1466 file2 = getParameter("file2");
1469 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
1472 LoadingThread loader = new LoadingThread(file, file2, this);
1475 else if (file != null)
1478 * Start the applet immediately or show a button to start it
1480 if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
1482 LoadingThread loader = new LoadingThread(file, file2, this);
1488 launcher.addActionListener(new java.awt.event.ActionListener()
1490 public void actionPerformed(ActionEvent e)
1492 LoadingThread loader = new LoadingThread(file, file2,
1501 // jalview initialisation with no alignment. loadAlignment() method can
1502 // still be called to open new alignments.
1509 private void initLiveConnect()
1511 // try really hard to get the liveConnect thing working
1512 boolean notFailed = false;
1514 while (!notFailed && tries < 10)
1518 System.err.println("LiveConnect request thread going to sleep.");
1522 Thread.sleep(700 * (1 + tries));
1523 } catch (InterruptedException q)
1529 System.err.println("LiveConnect request thread woken up.");
1533 JSObject scriptObject = JSObject.getWindow(this);
1534 if (scriptObject.eval("navigator") != null)
1538 } catch (Exception jsex)
1540 System.err.println("Attempt " + tries
1541 + " to access LiveConnect javascript failed.");
1546 private void callInitCallback()
1548 String initjscallback = getParameter("oninit");
1549 if (initjscallback == null)
1553 initjscallback = initjscallback.trim();
1554 if (initjscallback.length() > 0)
1556 JSObject scriptObject = null;
1559 scriptObject = JSObject.getWindow(this);
1560 } catch (Exception ex)
1564 // try really hard to let the browser plugin know we want liveconnect
1567 if (scriptObject != null)
1571 // do onInit with the JS executor thread
1572 new JSFunctionExec(this).executeJavascriptFunction(true,
1573 initjscallback, null, "Calling oninit callback '"
1574 + initjscallback + "'.");
1575 } catch (Exception e)
1577 System.err.println("Exception when executing _oninit callback '"
1578 + initjscallback + "'.");
1579 e.printStackTrace();
1584 System.err.println("Not executing _oninit callback '"
1585 + initjscallback + "' - no scripting allowed.");
1591 * Initialises and displays a new java.awt.Frame
1594 * java.awt.Frame to be displayed
1596 * title of new frame
1598 * width if new frame
1600 * height of new frame
1602 public static void addFrame(final Frame frame, String title, int width,
1605 frame.setLocation(lastFrameX, lastFrameY);
1608 frame.setSize(width, height);
1609 frame.setTitle(title);
1610 frame.addWindowListener(new WindowAdapter()
1612 public void windowClosing(WindowEvent e)
1614 if (frame instanceof AlignFrame)
1616 AlignViewport vp = ((AlignFrame) frame).viewport;
1617 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1618 if (vp.applet.currentAlignFrame == frame)
1620 vp.applet.currentAlignFrame = null;
1628 if (frame instanceof EmbmenuFrame)
1630 ((EmbmenuFrame) frame).destroyMenus();
1632 frame.setMenuBar(null);
1636 public void windowActivated(WindowEvent e)
1638 if (frame instanceof AlignFrame)
1640 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1643 System.err.println("Activated window " + frame);
1647 super.windowActivated(e);
1650 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1653 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1656 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1657 * frame) { currentAlignFrame = null; if (debug) {
1658 * System.err.println("Deactivated window "+frame); } }
1659 * super.windowDeactivated(e); }
1662 frame.setVisible(true);
1666 * This paints the background surrounding the "Launch Jalview button" <br>
1668 * If file given in parameter not found, displays error message
1673 public void paint(Graphics g)
1677 g.setColor(new Color(200, 200, 200));
1678 g.setColor(Color.cyan);
1679 g.fillRect(0, 0, getSize().width, getSize().height);
1680 g.setColor(Color.red);
1682 MessageManager.getString("label.jalview_cannot_open_file"),
1684 g.drawString("\"" + file + "\"", 5, 30);
1688 g.setColor(Color.black);
1689 g.setFont(new Font("Arial", Font.BOLD, 24));
1690 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1691 getSize().height / 2 - 30);
1692 g.drawString(MessageManager.getString("label.loading_data") + "...",
1693 50, getSize().height / 2);
1698 * get all components associated with the applet of the given type
1703 public Vector getAppletWindow(Class class1)
1705 Vector wnds = new Vector();
1706 Component[] cmp = getComponents();
1709 for (int i = 0; i < cmp.length; i++)
1711 if (class1.isAssignableFrom(cmp[i].getClass()))
1713 wnds.addElement(cmp);
1720 class LoadJmolThread extends Thread
1722 private boolean running = false;
1726 if (running || checkedForJmol)
1735 if (!System.getProperty("java.version").startsWith("1.1"))
1737 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1738 jmolAvailable = true;
1743 .println("Jmol not available - Using MCview for structures");
1745 } catch (java.lang.ClassNotFoundException ex)
1751 jmolAvailable = false;
1755 .println("Skipping Jmol check. Will use MCView (probably)");
1758 checkedForJmol = true;
1762 public boolean notFinished()
1764 return running || !checkedForJmol;
1768 class LoadingThread extends Thread
1771 * State variable: protocol for access to file source
1775 String _file; // alignment file or URL spec
1777 String _file2; // second alignment file or URL spec
1781 private void dbgMsg(String msg)
1783 if (JalviewLite.debug)
1785 System.err.println(msg);
1790 * update the protocol state variable for accessing the datasource located
1794 * @return possibly updated datasource string
1796 public String setProtocolState(String file)
1798 if (file.startsWith("PASTE"))
1800 file = file.substring(5);
1801 protocol = AppletFormatAdapter.PASTE;
1803 else if (inArchive(file))
1805 protocol = AppletFormatAdapter.CLASSLOADER;
1809 file = addProtocol(file);
1810 protocol = AppletFormatAdapter.URL;
1812 dbgMsg("Protocol identified as '" + protocol + "'");
1816 public LoadingThread(String file, String file2, JalviewLite _applet)
1819 this._file2 = file2;
1825 LoadJmolThread jmolchecker = new LoadJmolThread();
1826 jmolchecker.start();
1827 while (jmolchecker.notFinished())
1829 // wait around until the Jmol check is complete.
1833 } catch (Exception e)
1838 // applet.callInitCallback();
1842 * Load the alignment and any related files as specified by applet
1845 private void startLoading()
1847 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1849 dbgMsg("Loading started.");
1851 AlignFrame newAlignFrame = readAlignment(_file);
1852 AlignFrame newAlignFrame2 = readAlignment(_file2);
1853 if (newAlignFrame != null)
1855 addToDisplay(newAlignFrame, newAlignFrame2);
1856 loadTree(newAlignFrame);
1858 loadScoreFile(newAlignFrame);
1860 loadFeatures(newAlignFrame);
1862 loadAnnotations(newAlignFrame);
1864 loadJnetFile(newAlignFrame);
1866 loadPdbFiles(newAlignFrame);
1871 applet.remove(launcher);
1878 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1883 public void addToDisplay(AlignFrame af, AlignFrame af2)
1887 AlignmentI al1 = af.viewport.getAlignment();
1888 AlignmentI al2 = af2.viewport.getAlignment();
1889 AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
1890 AlignmentI prot = al1.isNucleotide() ? al2 : al1;
1891 if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
1894 SplitFrame sf = new SplitFrame(af, af2);
1895 sf.addToDisplay(embedded, JalviewLite.this);
1900 String msg = "Could not map any sequence in " + af2.getTitle()
1902 + (al1.isNucleotide() ? "protein product" : "cDNA")
1903 + " for " + af.getTitle();
1904 System.err.println(msg);
1908 af.addToDisplay(embedded);
1912 * Read the alignment file (from URL, text 'paste', or archive by
1917 protected AlignFrame readAlignment(String fileParam)
1919 if (fileParam == null)
1923 String resolvedFile = setProtocolState(fileParam);
1924 String format = new IdentifyFile().Identify(resolvedFile, protocol);
1925 dbgMsg("File identified as '" + format + "'");
1926 AlignmentI al = null;
1929 al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
1931 if ((al != null) && (al.getHeight() > 0))
1933 dbgMsg("Successfully loaded file.");
1934 al.setDataset(null);
1935 AlignFrame newAlignFrame = new AlignFrame(al, applet,
1936 resolvedFile, embedded, false);
1937 newAlignFrame.setTitle(resolvedFile);
1938 if (initialAlignFrame == null)
1940 initialAlignFrame = newAlignFrame;
1942 // update the focus.
1943 currentAlignFrame = newAlignFrame;
1945 if (protocol == AppletFormatAdapter.PASTE)
1947 newAlignFrame.setTitle(MessageManager.formatMessage(
1948 "label.sequences_from", new Object[] { applet
1949 .getDocumentBase().toString() }));
1952 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1953 "label.successfully_loaded_file",
1954 new Object[] { resolvedFile }));
1956 return newAlignFrame;
1958 } catch (java.io.IOException ex)
1960 dbgMsg("File load exception.");
1961 ex.printStackTrace();
1966 FileParse fp = new FileParse(resolvedFile, protocol);
1968 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
1970 while ((ln = fp.nextLine()) != null)
1974 dbgMsg(">>>Dump finished.");
1975 } catch (Exception e)
1978 .println("Exception when trying to dump the content of the file parameter.");
1979 e.printStackTrace();
1987 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
1993 protected boolean loadPdbFiles(AlignFrame alignFrame)
1995 boolean result = false;
1997 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
1998 * related to JAL-434
2001 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2004 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2007 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2009 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2012 int pdbFileCount = 0;
2013 // Accumulate pdbs here if they are heading for the same view (if
2014 // alignPdbStructures is true)
2015 Vector pdbs = new Vector();
2016 // create a lazy matcher if we're asked to
2017 jalview.analysis.SequenceIdMatcher matcher = (applet
2018 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2019 alignFrame.getAlignViewport().getAlignment()
2020 .getSequencesArray()) : null;
2025 if (pdbFileCount > 0)
2027 param = applet.getParameter("PDBFILE" + pdbFileCount);
2031 param = applet.getParameter("PDBFILE");
2036 PDBEntry pdb = new PDBEntry();
2039 SequenceI[] seqs = null;
2040 String[] chains = null;
2042 StringTokenizer st = new StringTokenizer(param, " ");
2044 if (st.countTokens() < 2)
2046 String sequence = applet.getParameter("PDBSEQ");
2047 if (sequence != null)
2049 seqs = new SequenceI[] { matcher == null ? (Sequence) alignFrame
2050 .getAlignViewport().getAlignment().findName(sequence)
2051 : matcher.findIdMatch(sequence) };
2057 param = st.nextToken();
2058 Vector tmp = new Vector();
2059 Vector tmp2 = new Vector();
2061 while (st.hasMoreTokens())
2063 seqstring = st.nextToken();
2064 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2065 if (st2.countTokens() > 1)
2067 // This is the chain
2068 tmp2.addElement(st2.nextToken());
2069 seqstring = st2.nextToken();
2071 tmp.addElement(matcher == null ? (Sequence) alignFrame
2072 .getAlignViewport().getAlignment()
2073 .findName(seqstring) : matcher.findIdMatch(seqstring));
2076 seqs = new SequenceI[tmp.size()];
2078 if (tmp2.size() == tmp.size())
2080 chains = new String[tmp2.size()];
2081 tmp2.copyInto(chains);
2084 param = setProtocolState(param);
2086 if (// !jmolAvailable
2088 protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
2090 // Re: JAL-357 : the bug isn't a problem if we are using an
2092 // TODO: verify this Re:
2093 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2094 // This exception preserves the current behaviour where, even if
2095 // the local pdb file was identified in the class loader
2096 protocol = AppletFormatAdapter.URL; // this is probably NOT
2098 param = addProtocol(param); //
2105 for (int i = 0; i < seqs.length; i++)
2107 if (seqs[i] != null)
2109 ((Sequence) seqs[i]).addPDBId(pdb);
2110 StructureSelectionManager.getStructureSelectionManager(
2111 applet).registerPDBEntry(pdb);
2115 if (JalviewLite.debug)
2117 // this may not really be a problem but we give a warning
2120 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2126 if (!alignPdbStructures)
2128 alignFrame.newStructureView(applet, pdb, seqs, chains,
2133 pdbs.addElement(new Object[] { pdb, seqs, chains,
2134 new String(protocol) });
2140 } while (param != null || pdbFileCount < 10);
2141 if (pdbs.size() > 0)
2143 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2144 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2145 String[][] chains = new String[pdbs.size()][];
2146 String[] protocols = new String[pdbs.size()];
2147 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2149 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2150 pdb[pdbsi] = (PDBEntry) o[0];
2151 seqs[pdbsi] = (SequenceI[]) o[1];
2152 chains[pdbsi] = (String[]) o[2];
2153 protocols[pdbsi] = (String) o[3];
2155 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2163 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2169 protected boolean loadJnetFile(AlignFrame alignFrame)
2171 boolean result = false;
2172 String param = applet.getParameter("jnetfile");
2177 param = setProtocolState(param);
2178 JPredFile predictions = new JPredFile(param, protocol);
2179 JnetAnnotationMaker.add_annotation(predictions,
2180 alignFrame.viewport.getAlignment(), 0, false);
2181 // false == do not add sequence profile from concise output
2182 SequenceI repseq = alignFrame.viewport.getAlignment()
2184 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2185 ColumnSelection cs = new ColumnSelection();
2186 cs.hideInsertionsFor(repseq);
2187 alignFrame.viewport.setColumnSelection(cs);
2188 alignFrame.alignPanel.fontChanged();
2189 alignFrame.alignPanel.setScrollValues(0, 0);
2191 } catch (Exception ex)
2193 ex.printStackTrace();
2200 * Load annotations if specified by parameter. Returns true if loaded, else
2206 protected boolean loadAnnotations(AlignFrame alignFrame)
2208 boolean result = false;
2209 String param = applet.getParameter("annotations");
2212 param = setProtocolState(param);
2214 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2217 alignFrame.alignPanel.fontChanged();
2218 alignFrame.alignPanel.setScrollValues(0, 0);
2224 .println("Annotations were not added from annotation file '"
2232 * Load features file and view settings as specified by parameters. Returns
2233 * true if features were loaded, else false.
2238 protected boolean loadFeatures(AlignFrame alignFrame)
2240 boolean result = false;
2241 // ///////////////////////////
2242 // modify display of features
2243 // we do this before any features have been loaded, ensuring any hidden
2244 // groups are hidden when features first displayed
2246 // hide specific groups
2248 String param = applet.getParameter("hidefeaturegroups");
2251 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2252 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2254 // show specific groups
2255 param = applet.getParameter("showfeaturegroups");
2258 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2259 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2261 // and now load features
2262 param = applet.getParameter("features");
2265 param = setProtocolState(param);
2267 result = alignFrame.parseFeaturesFile(param, protocol);
2270 param = applet.getParameter("showFeatureSettings");
2271 if (param != null && param.equalsIgnoreCase(TRUE))
2273 alignFrame.viewport.setShowSequenceFeatures(true);
2274 new FeatureSettings(alignFrame.alignPanel);
2280 * Load a score file if specified by parameter. Returns true if file was
2281 * loaded, else false.
2285 protected boolean loadScoreFile(AlignFrame alignFrame)
2287 boolean result = false;
2288 String sScoreFile = applet.getParameter("scoreFile");
2289 if (sScoreFile != null && !"".equals(sScoreFile))
2296 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2298 result = alignFrame.loadScoreFile(sScoreFile);
2302 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2303 + sScoreFile + "')");
2305 } catch (Exception e)
2307 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2308 sScoreFile, e.getMessage());
2315 * Load a tree for the alignment if specified by parameter. Returns true if
2316 * a tree was loaded, else false.
2321 protected boolean loadTree(AlignFrame alignFrame)
2323 boolean result = false;
2324 String treeFile = applet.getParameter("tree");
2325 if (treeFile == null)
2327 treeFile = applet.getParameter("treeFile");
2330 if (treeFile != null)
2334 treeFile = setProtocolState(treeFile);
2335 NewickFile fin = new NewickFile(treeFile, protocol);
2338 if (fin.getTree() != null)
2340 alignFrame.loadTree(fin, treeFile);
2342 dbgMsg("Successfully imported tree.");
2346 dbgMsg("Tree parameter did not resolve to a valid tree.");
2348 } catch (Exception ex)
2350 ex.printStackTrace();
2357 * Discovers whether the given file is in the Applet Archive
2363 boolean inArchive(String f)
2365 // This might throw a security exception in certain browsers
2366 // Netscape Communicator for instance.
2369 boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
2372 System.err.println("Resource '" + f + "' was "
2373 + (rtn ? "" : "not ") + "located by classloader.");
2376 } catch (Exception ex)
2378 System.out.println("Exception checking resources: " + f + " "
2385 * If the file is not already in URL format, tries to locate it by resolving
2391 String addProtocol(final String f)
2393 if (f.indexOf("://") != -1)
2395 // already has URL format
2400 * Try relative to document base
2402 URL documentBase = getDocumentBase();
2403 String url = applet.resolveUrlForLocalOrAbsolute(f, documentBase);
2408 System.err.println("Prepended document base '" + documentBase
2409 + "' to make: '" + url + "'");
2415 * Try relative to codebase
2417 URL codeBase = getCodeBase();
2418 url = applet.resolveUrlForLocalOrAbsolute(f, codeBase);
2423 System.err.println("Prepended codebase '" + codeBase
2424 + "' to make: '" + url + "'");
2433 * Returns true if an input stream can be opened on the specified URL, else
2439 private boolean urlExists(String url)
2441 InputStream is = null;
2444 is = new URL(url).openStream();
2449 } catch (Exception x)
2459 } catch (IOException e)
2470 * @return the default alignFrame acted on by the public applet methods. May
2471 * return null with an error message on System.err indicating the
2474 public AlignFrame getDefaultTargetFrame()
2476 if (currentAlignFrame != null)
2478 return currentAlignFrame;
2480 if (initialAlignFrame != null)
2482 return initialAlignFrame;
2485 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2490 * separator used for separatorList
2492 protected String separator = "" + ((char) 0x00AC); // the default used to be
2493 // '|' but many sequence
2494 // IDS include pipes.
2497 * set to enable the URL based javascript execution mechanism
2499 public boolean jsfallbackEnabled = false;
2502 * parse the string into a list
2505 * @return elements separated by separator
2507 public String[] separatorListToArray(String list)
2509 return separatorListToArray(list, separator);
2513 * parse the string into a list
2517 * @return elements separated by separator
2519 public static String[] separatorListToArray(String list, String separator)
2521 // TODO use StringUtils version (slightly different...)
2522 int seplen = separator.length();
2523 if (list == null || list.equals("") || list.equals(separator))
2527 java.util.Vector jv = new Vector();
2529 while ((pos = list.indexOf(separator, cp)) > cp)
2531 jv.addElement(list.substring(cp, pos));
2534 if (cp < list.length())
2536 String c = list.substring(cp);
2537 if (!c.equals(separator))
2544 String[] v = new String[jv.size()];
2545 for (int i = 0; i < v.length; i++)
2547 v[i] = (String) jv.elementAt(i);
2549 jv.removeAllElements();
2552 System.err.println("Array from '" + separator
2553 + "' separated List:\n" + v.length);
2554 for (int i = 0; i < v.length; i++)
2556 System.err.println("item " + i + " '" + v[i] + "'");
2563 System.err.println("Empty Array from '" + separator
2564 + "' separated List");
2570 * concatenate the list with separator
2573 * @return concatenated string
2575 public String arrayToSeparatorList(String[] list)
2577 return arrayToSeparatorList(list, separator);
2581 * concatenate the list with separator
2585 * @return concatenated string
2587 public static String arrayToSeparatorList(String[] list, String separator)
2589 // TODO use StringUtils version
2590 StringBuffer v = new StringBuffer();
2591 if (list != null && list.length > 0)
2593 for (int i = 0, iSize = list.length; i < iSize; i++)
2595 if (list[i] != null)
2599 v.append(separator);
2606 System.err.println("Returning '" + separator
2607 + "' separated List:\n");
2608 System.err.println(v);
2610 return v.toString();
2614 System.err.println("Returning empty '" + separator
2615 + "' separated List\n");
2617 return "" + separator;
2623 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2625 public String getFeatureGroups()
2627 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2628 .getFeatureGroups());
2636 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2639 public String getFeatureGroupsOn(AlignFrame alf)
2641 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2648 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2650 public String getFeatureGroupsOfState(boolean visible)
2652 return arrayToSeparatorList(getDefaultTargetFrame()
2653 .getFeatureGroupsOfState(visible));
2660 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2661 * .AlignFrame, boolean)
2663 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2665 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2671 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2672 * AlignFrame, java.lang.String, boolean)
2674 public void setFeatureGroupStateOn(final AlignFrame alf,
2675 final String groups, boolean state)
2677 final boolean st = state;// !(state==null || state.equals("") ||
2678 // state.toLowerCase().equals("false"));
2679 java.awt.EventQueue.invokeLater(new Runnable()
2684 alf.setFeatureGroupState(separatorListToArray(groups), st);
2692 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2695 public void setFeatureGroupState(String groups, boolean state)
2697 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2703 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2705 public String getSeparator()
2713 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2715 public void setSeparator(String separator)
2717 if (separator == null || separator.length() < 1)
2720 separator = "" + ((char) 0x00AC);
2722 this.separator = separator;
2725 System.err.println("Default Separator now: '" + separator + "'");
2730 * get boolean value of applet parameter 'name' and return default if
2731 * parameter is not set
2736 * the value to return otherwise
2737 * @return true or false
2739 public boolean getDefaultParameter(String name, boolean def)
2742 if ((stn = getParameter(name)) == null)
2746 if (TRUE.equalsIgnoreCase(stn))
2756 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2757 * java.lang.String, java.lang.String, java.lang.String)
2759 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2760 String pdbEntryString, String pdbFile)
2762 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2765 protected void setAlignPdbStructures(boolean alignPdbStructures)
2767 this.alignPdbStructures = alignPdbStructures;
2770 public boolean isAlignPdbStructures()
2772 return alignPdbStructures;
2777 // callInitCallback();
2780 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2782 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2784 public void setJsMessageSet(String messageclass, String viewId,
2785 String[] colcommands)
2787 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2790 msgset = new Hashtable<String, String[]>();
2791 jsmessages.put(messageclass, msgset);
2793 msgset.put(viewId, colcommands);
2794 long[] l = new long[colcommands.length];
2795 for (int i = 0; i < colcommands.length; i++)
2797 l[i] = colcommands[i].hashCode();
2799 jshashes.put(messageclass + "|" + viewId, l);
2805 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2808 public String getJsMessage(String messageclass, String viewId)
2810 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2813 String[] msgs = msgset.get(viewId);
2816 for (int i = 0; i < msgs.length; i++)
2818 if (msgs[i] != null)
2830 public boolean isJsMessageSetChanged(String string, String string2,
2831 String[] colcommands)
2833 long[] l = jshashes.get(string + "|" + string2);
2834 if (l == null && colcommands != null)
2838 for (int i = 0; i < colcommands.length; i++)
2840 if (l[i] != colcommands[i].hashCode())
2848 private Vector jsExecQueue = new Vector();
2850 public Vector getJsExecQueue()
2855 public void setExecutor(JSFunctionExec jsFunctionExec2)
2857 jsFunctionExec = jsFunctionExec2;
2861 * return the given colour value parameter or the given default if parameter
2868 public Color getDefaultColourParameter(String colparam, Color defcolour)
2870 String colprop = getParameter(colparam);
2871 if (colprop == null || colprop.trim().length() == 0)
2875 Color col = jalview.schemes.ColourSchemeProperty
2876 .getAWTColorFromName(colprop);
2881 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2882 } catch (Exception ex)
2884 System.err.println("Couldn't parse '" + colprop
2885 + "' as a colour for " + colparam);
2889 return (col == null) ? defcolour : col;
2893 public void openJalviewHelpUrl()
2895 String helpUrl = getParameter("jalviewhelpurl");
2896 if (helpUrl == null || helpUrl.trim().length() < 5)
2898 helpUrl = "http://www.jalview.org/help.html";
2900 showURL(helpUrl, "HELP");
2904 * form a complete URL given a path to a resource and a reference location on
2908 * - an absolute path on the same server as localref or a document
2909 * located relative to localref
2911 * - a URL on the same server as url
2912 * @return a complete URL for the resource located by url
2914 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2916 String codebase = localref.toString();
2917 if (url.indexOf("/") == 0)
2919 String localfile = localref.getFile();
2920 url = codebase.substring(0, codebase.length() - localfile.length())
2925 url = localref + url;
2929 System.err.println("URL: " + localref.toString());
2930 System.err.println("URL.getFile: " + localref.getFile());
2931 System.err.println("URL.getPath: " + localref.getPath());
2932 System.err.println("URL.getQuery: " + localref.getQuery());
2933 System.err.println("returning " + url);
2939 * open a URL in the browser - resolving it according to relative refs and
2940 * coping with javascript: protocol if necessary.
2945 public void showURL(String url, String target)
2949 if (url.indexOf(":") == -1)
2951 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2953 // Should really use docbase, not codebase.
2955 url = resolveUrlForLocalOrAbsolute(
2957 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2962 .println("Show url (prepended "
2964 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2972 System.err.println("Show url: " + url);
2975 if (url.indexOf("javascript:") == 0)
2977 // no target for the javascript context
2978 getAppletContext().showDocument(new java.net.URL(url));
2982 getAppletContext().showDocument(new java.net.URL(url), target);
2984 } catch (Exception ex)
2986 ex.printStackTrace();
2991 * bind structures in a viewer to any matching sequences in an alignFrame (use
2992 * sequenceIds to limit scope of search to specific sequences)
2996 * @param sequenceIds
2997 * @return TODO: consider making an exception structure for indicating when
2998 * binding fails public SequenceStructureBinding
2999 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
3002 * if (sequenceIds != null && sequenceIds.length() > 0) { return
3003 * alFrame.addStructureViewInstance(viewer,
3004 * separatorListToArray(sequenceIds)); } else { return
3005 * alFrame.addStructureViewInstance(viewer, null); } // return null; }