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.SequenceIdMatcher;
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.appletgui.AlignViewport;
31 //import jalview.appletgui.EmbmenuFrame;
32 //import jalview.appletgui.FeatureSettings;
33 //import jalview.appletgui.SplitFrame;
34 import jalview.datamodel.Alignment;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.AlignmentOrder;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.PDBEntry;
39 import jalview.datamodel.Sequence;
40 import jalview.datamodel.SequenceGroup;
41 import jalview.datamodel.SequenceI;
42 import jalview.io.AlignFile;
43 import jalview.io.AnnotationFile;
44 import jalview.io.AppletFormatAdapter;
45 import jalview.io.FileParse;
46 import jalview.io.IdentifyFile;
47 import jalview.io.JnetAnnotationMaker;
48 //import jalview.io.JPredFile;
49 //import jalview.io.JnetAnnotationMaker;
50 import jalview.io.NewickFile;
51 import jalview.javascript.JSFunctionExec;
52 import jalview.javascript.JalviewLiteJsApi;
53 import jalview.javascript.JsCallBack;
54 import jalview.javascript.JsSelectionSender;
55 import jalview.javascript.MouseOverListener;
56 import jalview.javascript.MouseOverStructureListener;
57 import jalview.jsdev.GenericFileAdapter;
58 //import jalview.javascript.MouseOverListener;
59 //import jalview.javascript.MouseOverStructureListener;
60 import jalview.schemes.ColourSchemeProperty;
61 import jalview.schemes.UserColourScheme;
62 import jalview.structure.SelectionListener;
63 import jalview.structure.StructureSelectionManager;
64 import jalview.util.MessageManager;
66 import java.awt.Color;
67 import java.awt.Component;
68 import java.awt.EventQueue;
70 import java.awt.Graphics;
71 import java.awt.event.ActionEvent;
72 import java.awt.event.WindowAdapter;
73 import java.awt.event.WindowEvent;
74 import java.io.BufferedReader;
75 import java.io.IOException;
76 import java.io.InputStream;
77 import java.io.InputStreamReader;
79 import java.util.Hashtable;
80 import java.util.List;
81 import java.util.StringTokenizer;
82 import java.util.Vector;
84 import javax.swing.JApplet;
85 import javax.swing.JButton;
86 import javax.swing.JFrame;
88 import netscape.javascript.JSObject;
90 //import netscape.javascript.JSObject;
93 * Jalview Applet. Runs in Java 1.18 runtime
96 * @version $Revision: 1.92 $
98 public class JalviewLite extends JApplet implements
99 StructureSelectionManagerProvider, JalviewLiteJsApi
102 private static final String TRUE = "true";
104 private static final String FALSE = "false";
106 public static boolean debug = false;
108 public boolean embedded = false;
109 public boolean enableSplitFrame = false;
110 public boolean showButton = true;
111 public boolean checkForJmol = true;
114 public String jalviewServletURL;
115 public String startupFile = "No file";
116 public String helpUrl;
117 public String externalstructureviewer;
120 public String labelColour;
121 public String initjscallback;
122 public String pdbFile;
123 public String sequence;
124 public String jnetFile;
125 public String annotations;
126 public String hideFeatureGroups;
127 public String showFeatureGroups;
128 public String features;
129 public String showFeatureSettings;
130 public String scoreFile;
131 public String treeFile;
132 public String windowWidth;
133 public String windowHeight;
134 public String defaultColour;
135 public String sortBy;
137 public String centrecolumnlabels;
138 public String userDefinedColour;
139 public String widthScale;
140 public String heightScale;
141 public String upperCase;
144 private void setParams() {
145 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
146 enableSplitFrame = TRUE.equalsIgnoreCase(getParameter("enableSplitFrame"));
147 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
148 showButton = !FALSE.equalsIgnoreCase(getParameter("showbutton"));
150 jalviewServletURL = getParameter("APPLICATION_URL");
151 startupFile = getParameter("file");
152 helpUrl = getParameter("jalviewhelpurl");
153 externalstructureviewer = getParameter("externalstructureviewer");
154 checkForJmol = !TRUE.equals(getParameter("nojmol"));
155 sep = getParameter("separator");
156 rgb = getParameter("RGB");
157 labelColour = getParameter("label");
158 initjscallback = getParameter("oninit");
159 pdbFile = getParameter("PDBFILE");
160 sequence = getParameter("PDBSEQ");
161 jnetFile = getParameter("jnetfile");
162 annotations = getParameter("annotations");
163 hideFeatureGroups = getParameter("hidefeaturegroups");
164 showFeatureGroups = getParameter("showfeaturegroups");
165 features = getParameter("features");
166 showFeatureSettings = getParameter("showFeatureSettings");
167 scoreFile = getParameter("scoreFile");
168 treeFile = getParameter("tree");
169 if (treeFile == null)
170 treeFile = getParameter("treeFile");
171 windowWidth = getParameter("windowWidth");
172 windowHeight = getParameter("windowHeight");
173 defaultColour = getParameter("defaultColour");
175 sortBy = getParameter("sortBy");
176 wrap = getParameter("wrap");
177 centrecolumnlabels = getParameter("centrecolumnlabels");
178 userDefinedColour = getParameter("userDefinedColour");
179 widthScale = getParameter("widthScale");
180 heightScale = getParameter("heightScale");
181 upperCase = getParameter("upperCase");
182 file2 = getParameter("file2");
187 * get boolean value of applet parameter 'name' and return default if
188 * parameter is not set
193 * the value to return otherwise
194 * @return true or false
196 public boolean getDefaultParameter(String name, boolean def)
199 if ((stn = getParameter(name)) == null)
203 if (stn.toLowerCase().equals(TRUE))
210 public void getLinkParams(Vector links) {
212 for (int i = 1; i < 10; i++)
214 label = getParameter("linkLabel_" + i);
215 url = getParameter("linkURL_" + i);
216 if (label != null && url != null)
218 links.addElement(label + "|" + url);
225 public StructureSelectionManager getStructureSelectionManager()
227 return StructureSelectionManager.getStructureSelectionManager(this);
230 // /////////////////////////////////////////
231 // The following public methods maybe called
232 // externally, eg via javascript in HTML page
236 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
238 public String getSelectedSequences()
240 return getSelectedSequencesFrom(getDefaultTargetFrame());
246 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
248 public String getSelectedSequences(String sep)
250 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
257 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
260 public String getSelectedSequencesFrom(AlignFrame alf)
262 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
269 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
270 * .AlignFrame, java.lang.String)
272 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
274 StringBuffer result = new StringBuffer("");
275 if (sep == null || sep.length() == 0)
277 sep = separator; // "+0x00AC;
279 if (alf.viewport.getSelectionGroup() != null)
281 SequenceI[] seqs = alf.viewport.getSelectionGroup()
282 .getSequencesInOrder(alf.viewport.getAlignment());
284 for (int i = 0; i < seqs.length; i++)
286 result.append(seqs[i].getName());
291 return result.toString();
297 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
298 * java.lang.String, java.lang.String)
300 public void highlight(String sequenceId, String position,
301 String alignedPosition)
303 highlightIn(getDefaultTargetFrame(), sequenceId, position,
310 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
311 * java.lang.String, java.lang.String, java.lang.String)
313 public void highlightIn(final AlignFrame alf, final String sequenceId,
314 final String position, final String alignedPosition)
316 // TODO: could try to highlight in all alignments if alf==null
317 SequenceIdMatcher matcher = new SequenceIdMatcher(
318 alf.viewport.getAlignment().getSequencesArray());
319 final SequenceI sq = matcher.findIdMatch(sequenceId);
325 apos = new Integer(position).intValue();
327 } catch (NumberFormatException ex)
331 final StructureSelectionManagerProvider me = this;
332 final int pos = apos;
333 // use vamsas listener to broadcast to all listeners in scope
334 if (alignedPosition != null
335 && (alignedPosition.trim().length() == 0 || alignedPosition
336 .toLowerCase().indexOf("false") > -1))
338 java.awt.EventQueue.invokeLater(new Runnable()
343 StructureSelectionManager.getStructureSelectionManager(me)
344 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
350 java.awt.EventQueue.invokeLater(new Runnable()
355 StructureSelectionManager.getStructureSelectionManager(me)
356 .mouseOverVamsasSequence(sq, pos, null);
366 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
369 public void select(String sequenceIds, String columns)
371 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
377 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
378 * java.lang.String, java.lang.String)
380 public void select(String sequenceIds, String columns, String sep)
382 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
388 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
389 * java.lang.String, java.lang.String)
391 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
393 selectIn(alf, sequenceIds, columns, separator);
399 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
400 * java.lang.String, java.lang.String, java.lang.String)
402 public void selectIn(final AlignFrame alf, String sequenceIds,
403 String columns, String sep)
405 if (sep == null || sep.length() == 0)
413 System.err.println("Selecting region using separator string '"
418 String[] ids = separatorListToArray(sequenceIds, sep);
419 String[] cols = separatorListToArray(columns, sep);
420 final SequenceGroup sel = new SequenceGroup();
421 final ColumnSelection csel = new ColumnSelection();
422 AlignmentI al = alf.viewport.getAlignment();
423 SequenceIdMatcher matcher = new SequenceIdMatcher(
424 alf.viewport.getAlignment().getSequencesArray());
425 int start = 0, end = al.getWidth(), alw = al.getWidth();
426 boolean seqsfound = true;
427 if (ids != null && ids.length > 0)
430 for (int i = 0; i < ids.length; i++)
432 if (ids[i].trim().length() == 0)
436 SequenceI sq = matcher.findIdMatch(ids[i]);
440 sel.addSequence(sq, false);
444 boolean inseqpos = false;
445 if (cols != null && cols.length > 0)
447 boolean seset = false;
448 for (int i = 0; i < cols.length; i++)
450 String cl = cols[i].trim();
451 if (cl.length() == 0)
456 if ((p = cl.indexOf("-")) > -1)
458 int from = -1, to = -1;
461 from = new Integer(cl.substring(0, p)).intValue();
463 } catch (NumberFormatException ex)
466 .println("ERROR: Couldn't parse first integer in range element column selection string '"
467 + cl + "' - format is 'from-to'");
472 to = new Integer(cl.substring(p + 1)).intValue();
474 } catch (NumberFormatException ex)
477 .println("ERROR: Couldn't parse second integer in range element column selection string '"
478 + cl + "' - format is 'from-to'");
481 if (from >= 0 && to >= 0)
498 // comment to prevent range extension
508 for (int r = from; r <= to; r++)
510 if (r >= 0 && r < alw)
517 System.err.println("Range '" + cl + "' deparsed as [" + from
523 System.err.println("ERROR: Invalid Range '" + cl
524 + "' deparsed as [" + from + "," + to + "]");
532 r = new Integer(cl).intValue();
534 } catch (NumberFormatException ex)
536 if (cl.toLowerCase().equals("sequence"))
538 // we are in the dataset sequence's coordinate frame.
544 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
549 if (r >= 0 && r <= alw)
559 // comment to prevent range extension
572 System.err.println("Point selection '" + cl
573 + "' deparsed as [" + r + "]");
578 System.err.println("ERROR: Invalid Point selection '" + cl
579 + "' deparsed as [" + r + "]");
586 // we only propagate the selection when it was the null selection, or the
587 // given sequences were found in the alignment.
588 if (inseqpos && sel.getSize() > 0)
590 // assume first sequence provides reference frame ?
591 SequenceI rs = sel.getSequenceAt(0);
592 start = rs.findIndex(start);
593 end = rs.findIndex(end);
596 List<Integer> cs = csel.getSelected();
598 for (Integer selectedCol : cs)
600 csel.addElement(rs.findIndex(selectedCol));
604 sel.setStartRes(start);
606 EventQueue.invokeLater(new Runnable()
611 alf.select(sel, csel);
621 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
622 * String, java.lang.String)
624 public String getSelectedSequencesAsAlignment(String format, String suffix)
626 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
634 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
635 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
637 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
638 String format, String suffix)
642 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
643 if (alf.viewport.getSelectionGroup() != null)
645 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
646 // method now returns a full copy of sequence data
647 // TODO consider using getSequenceSelection instead here
648 String reply = new AppletFormatAdapter().formatSequences(format,
649 new Alignment(alf.viewport.getSelectionAsNewSequence()),
653 } catch (Exception ex)
655 ex.printStackTrace();
656 return "Error retrieving alignment in " + format + " format. ";
664 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
666 public String getAlignmentOrder()
668 return getAlignmentOrderFrom(getDefaultTargetFrame());
675 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
678 public String getAlignmentOrderFrom(AlignFrame alf)
680 return getAlignmentOrderFrom(alf, separator);
687 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
688 * , java.lang.String)
690 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
692 AlignmentI alorder = alf.getAlignViewport().getAlignment();
693 String[] order = new String[alorder.getHeight()];
694 for (int i = 0; i < order.length; i++)
696 order[i] = alorder.getSequenceAt(i).getName();
698 return arrayToSeparatorList(order);
704 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
707 public String orderBy(String order, String undoName)
709 return orderBy(order, undoName, separator);
715 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
716 * java.lang.String, java.lang.String)
718 public String orderBy(String order, String undoName, String sep)
720 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
727 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
728 * java.lang.String, java.lang.String, java.lang.String)
730 public String orderAlignmentBy(AlignFrame alf, String order,
731 String undoName, String sep)
733 String[] ids = separatorListToArray(order, sep);
734 SequenceI[] sqs = null;
735 if (ids != null && ids.length > 0)
737 SequenceIdMatcher matcher = new SequenceIdMatcher(
738 alf.viewport.getAlignment().getSequencesArray());
740 sqs = new SequenceI[ids.length];
741 for (int i = 0; i < ids.length; i++)
743 if (ids[i].trim().length() == 0)
747 SequenceI sq = matcher.findIdMatch(ids[i]);
755 SequenceI[] sqq = new SequenceI[s];
756 System.arraycopy(sqs, 0, sqq, 0, s);
769 final AlignmentOrder aorder = new AlignmentOrder(sqs);
771 if (undoName != null && undoName.trim().length() == 0)
775 final String _undoName = undoName;
776 // TODO: deal with synchronization here: cannot raise any events until after
777 // this has returned.
778 return alf.sortBy(aorder, _undoName) ? TRUE : "";
784 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
786 public String getAlignment(String format)
788 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
795 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
798 public String getAlignmentFrom(AlignFrame alf, String format)
800 return getAlignmentFrom(alf, format, TRUE);
806 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
809 public String getAlignment(String format, String suffix)
811 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
818 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
819 * java.lang.String, java.lang.String)
821 public String getAlignmentFrom(AlignFrame alf, String format,
826 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
828 String reply = new AppletFormatAdapter().formatSequences(format,
829 alf.viewport.getAlignment(), seqlimits);
831 } catch (Exception ex)
833 ex.printStackTrace();
834 return "Error retrieving alignment in " + format + " format. ";
841 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
843 public void loadAnnotation(String annotation)
845 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
852 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
853 * , java.lang.String)
855 public void loadAnnotationFrom(AlignFrame alf, String annotation)
857 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
858 annotation, AppletFormatAdapter.PASTE))
860 alf.alignPanel.fontChanged();
861 alf.alignPanel.setScrollValues(0, 0);
865 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
872 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
874 public void loadFeatures(String features, boolean autoenabledisplay)
876 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
883 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
884 * , java.lang.String)
886 public boolean loadFeaturesFrom(AlignFrame alf, String features,
887 boolean autoenabledisplay)
889 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
896 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
898 public String getFeatures(String format)
900 return getFeaturesFrom(getDefaultTargetFrame(), format);
907 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
910 public String getFeaturesFrom(AlignFrame alf, String format)
912 return alf.outputFeatures(false, format);
918 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
920 public String getAnnotation()
922 return getAnnotationFrom(getDefaultTargetFrame());
929 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
932 public String getAnnotationFrom(AlignFrame alf)
934 return alf.outputAnnotations(false);
940 * @see jalview.bin.JalviewLiteJsApi#newView()
942 public AlignFrame newView()
944 return newViewFrom(getDefaultTargetFrame());
950 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
952 public AlignFrame newView(String name)
954 return newViewFrom(getDefaultTargetFrame(), name);
960 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
962 public AlignFrame newViewFrom(AlignFrame alf)
964 return alf.newView(null);
970 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
973 public AlignFrame newViewFrom(AlignFrame alf, String name)
975 return alf.newView(name);
981 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
984 public AlignFrame loadAlignment(String text, String title)
986 AlignmentI al = null;
988 String format = new IdentifyFile().Identify(text,
989 AppletFormatAdapter.PASTE);
992 al = new AppletFormatAdapter().readFile(text,
993 AppletFormatAdapter.PASTE, format);
994 if (al.getHeight() > 0)
996 return new AlignFrame(al, this, title, false);
998 } catch (java.io.IOException ex)
1000 ex.printStackTrace();
1008 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
1010 public void setMouseoverListener(String listener)
1012 setMouseoverListener(currentAlignFrame, listener);
1015 private Vector<JSFunctionExec> javascriptListeners = new Vector<JSFunctionExec>();
1021 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
1022 * , java.lang.String)
1024 public void setMouseoverListener(AlignFrame af, String listener)
1026 if (listener != null)
1028 listener = listener.trim();
1029 if (listener.length() == 0)
1032 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
1036 MouseOverListener mol = new MouseOverListener(
1037 this, af, listener);
1038 javascriptListeners.addElement(mol);
1039 StructureSelectionManager.getStructureSelectionManager(this)
1040 .addStructureViewerListener(mol);
1043 System.err.println("Added a mouseover listener for "
1044 + ((af == null) ? "All frames" : "Just views for "
1045 + af.getAlignViewport().getSequenceSetId()));
1046 System.err.println("There are now " + javascriptListeners.size()
1047 + " listeners in total.");
1054 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
1056 public void setSelectionListener(String listener)
1058 setSelectionListener(null, listener);
1065 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
1066 * , java.lang.String)
1068 public void setSelectionListener(AlignFrame af, String listener)
1070 if (listener != null)
1072 listener = listener.trim();
1073 if (listener.length() == 0)
1076 .println("jalview Javascript error: Ignoring empty function for selection listener.");
1080 JsSelectionSender mol = new JsSelectionSender(this, af, listener);
1081 javascriptListeners.addElement(mol);
1082 StructureSelectionManager.getStructureSelectionManager(this)
1083 .addSelectionListener(mol);
1086 System.err.println("Added a selection listener for "
1087 + ((af == null) ? "All frames" : "Just views for "
1088 + af.getAlignViewport().getSequenceSetId()));
1089 System.err.println("There are now " + javascriptListeners.size()
1090 + " listeners in total.");
1097 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
1100 public void setStructureListener(String listener, String modelSet)
1102 if (listener != null)
1104 listener = listener.trim();
1105 if (listener.length() == 0)
1108 .println("jalview Javascript error: Ignoring empty function for selection listener.");
1112 MouseOverStructureListener mol = new MouseOverStructureListener(
1113 this, listener, separatorListToArray(modelSet));
1114 javascriptListeners.addElement(mol);
1115 StructureSelectionManager.getStructureSelectionManager(this)
1116 .addStructureViewerListener(mol);
1119 System.err.println("Added a javascript structure viewer listener '"
1121 System.err.println("There are now " + javascriptListeners.size()
1122 + " listeners in total.");
1130 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
1131 * .AlignFrame, java.lang.String)
1133 public void removeJavascriptListener(AlignFrame af, String listener)
1135 if (listener != null)
1137 listener = listener.trim();
1138 if (listener.length() == 0)
1143 boolean rprt = false;
1144 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1146 Object lstn = javascriptListeners.elementAt(ms);
1147 JsCallBack lstner = (JsCallBack) lstn;
1148 if ((af == null || lstner.getAlignFrame() == af)
1149 && (listener == null || lstner.getListenerFunction().equals(
1152 javascriptListeners.removeElement(lstner);
1154 if (lstner instanceof SelectionListener)
1156 StructureSelectionManager.getStructureSelectionManager(this)
1157 .removeSelectionListener((SelectionListener) lstner);
1161 StructureSelectionManager.getStructureSelectionManager(this)
1162 .removeStructureViewerListener(lstner, null);
1167 System.err.println("Removed listener '" + listener + "'");
1177 System.err.println("There are now " + javascriptListeners.size()
1178 + " listeners in total.");
1184 System.err.println("Applet " + getName() + " stop().");
1188 public void destroy()
1190 System.err.println("Applet " + getName() + " destroy().");
1194 private void tidyUp()
1197 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1198 && currentAlignFrame.viewport.applet != null)
1200 AlignViewport av = currentAlignFrame.viewport;
1201 currentAlignFrame.closeMenuItem_actionPerformed();
1203 currentAlignFrame = null;
1205 if (javascriptListeners != null)
1207 while (javascriptListeners.size() > 0)
1209 JSFunctionExec mol = javascriptListeners.elementAt(0);
1210 javascriptListeners.removeElement(mol);
1211 if (mol instanceof SelectionListener)
1213 StructureSelectionManager.getStructureSelectionManager(this)
1214 .removeSelectionListener((SelectionListener) mol);
1218 StructureSelectionManager.getStructureSelectionManager(this)
1219 .removeStructureViewerListener(mol, null);
1224 if (jsFunctionExec != null)
1226 jsFunctionExec.stopQueue();
1227 jsFunctionExec.jvlite = null;
1229 initialAlignFrame = null;
1230 jsFunctionExec = null;
1231 javascriptListeners = null;
1232 StructureSelectionManager.release(this);
1235 private JSFunctionExec jsFunctionExec;
1240 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1241 * java.lang.String, java.lang.String)
1243 public void mouseOverStructure(final String pdbResNum,
1244 final String chain, final String pdbfile)
1246 final StructureSelectionManagerProvider me = this;
1247 java.awt.EventQueue.invokeLater(new Runnable()
1254 StructureSelectionManager.getStructureSelectionManager(me)
1255 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1259 System.err.println("mouseOver for '" + pdbResNum
1260 + "' in chain '" + chain + "' in structure '" + pdbfile
1263 } catch (NumberFormatException e)
1265 System.err.println("Ignoring invalid residue number string '"
1277 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1278 * java.lang.String, java.lang.String)
1280 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1281 final String leftHandColumn)
1283 java.awt.EventQueue.invokeLater(new Runnable()
1290 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1291 leftHandColumn).intValue());
1293 } catch (Exception ex)
1295 System.err.println("Couldn't parse integer arguments (topRow='"
1296 + topRow + "' and leftHandColumn='" + leftHandColumn
1298 ex.printStackTrace();
1308 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1309 * .AlignFrame, java.lang.String)
1312 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1315 java.awt.EventQueue.invokeLater(new Runnable()
1322 alf.scrollToRow(new Integer(topRow).intValue());
1324 } catch (Exception ex)
1326 System.err.println("Couldn't parse integer arguments (topRow='"
1328 ex.printStackTrace();
1339 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1340 * .AlignFrame, java.lang.String)
1343 public void scrollViewToColumnIn(final AlignFrame alf,
1344 final String leftHandColumn)
1346 EventQueue.invokeLater(new Runnable()
1354 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1356 } catch (Exception ex)
1359 .println("Couldn't parse integer arguments (leftHandColumn='"
1360 + leftHandColumn + "')");
1361 ex.printStackTrace();
1368 // //////////////////////////////////////////////
1369 // //////////////////////////////////////////////
1371 public static int lastFrameX = 200;
1373 public static int lastFrameY = 200;
1375 boolean fileFound = true;
1377 JButton launcher = new JButton(
1378 MessageManager.getString("label.start_jalview"));
1381 * The currentAlignFrame is static, it will change if and when the user
1382 * selects a new window. Note that it will *never* point back to the embedded
1383 * AlignFrame if the applet is started as embedded on the page and then
1384 * afterwards a new view is created.
1386 public AlignFrame currentAlignFrame = null;
1389 * This is the first frame to be displayed, and does not change. API calls
1390 * will default to this instance if currentAlignFrame is null.
1392 AlignFrame initialAlignFrame = null;
1394 private boolean checkedForJmol = false; // ensure we don't check for jmol
1396 // every time the app is re-inited
1398 public boolean jmolAvailable = false;
1400 private boolean alignPdbStructures = false;
1403 * use an external structure viewer exclusively (no jmols or MCViews will be
1404 * opened by JalviewLite itself)
1406 public boolean useXtrnalSviewer = false;
1408 private boolean haveShownLoadMessage;
1410 static String builddate = null, version = null, installation = null;
1412 private static void initBuildDetails()
1414 if (builddate == null)
1416 builddate = "unknown";
1418 installation = "Webstart";
1419 java.net.URL url = JalviewLite.class
1420 .getResource("/.build_properties");
1425 BufferedReader reader = new BufferedReader(new InputStreamReader(
1428 while ((line = reader.readLine()) != null)
1430 if (line.indexOf("VERSION") > -1)
1432 version = line.substring(line.indexOf("=") + 1);
1434 if (line.indexOf("BUILD_DATE") > -1)
1436 builddate = line.substring(line.indexOf("=") + 1);
1438 if (line.indexOf("INSTALLATION") > -1)
1440 installation = line.substring(line.indexOf("=") + 1);
1443 } catch (Exception ex)
1445 ex.printStackTrace();
1451 public static String getBuildDate()
1457 public static String getInstallation()
1460 return installation;
1463 public static String getVersion()
1469 // public JSObject scriptObject = null;
1472 * init method for Jalview Applet
1479 // remove any handlers that might be hanging around from an earlier instance
1484 System.err.println("Applet context is '"
1485 + getAppletContext().getClass().toString() + "'");
1487 JSObject scriptObject = JSObject.getWindow(this);
1488 if (debug && scriptObject != null)
1490 System.err.println("Applet has Javascript callback support.");
1493 } catch (Exception ex)
1496 .println("Warning: No JalviewLite javascript callbacks available.");
1499 ex.printStackTrace();
1503 * turn on extra applet debugging
1509 System.err.println("JalviewLite Version " + getVersion());
1510 System.err.println("Build Date : " + getBuildDate());
1511 System.err.println("Installation : " + getInstallation());
1514 if (externalstructureviewer != null)
1516 useXtrnalSviewer = externalstructureviewer.trim().toLowerCase()
1520 * get the separator parameter if present
1524 if (sep.length() > 0)
1529 System.err.println("Separator set to '" + separator + "'");
1534 throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
1545 r = Integer.parseInt(rgb.substring(0, 2), 16);
1546 g = Integer.parseInt(rgb.substring(2, 4), 16);
1547 b = Integer.parseInt(rgb.substring(4, 6), 16);
1548 } catch (Exception ex)
1558 launcher.setLabel(rgb);
1561 setBackground(new Color(r, g, b));
1563 if (startupFile == null)
1565 // Maybe the sequences are added as parameters
1566 StringBuffer data = new StringBuffer("PASTE");
1568 while ((startupFile = getParameter("sequence" + i)) != null)
1570 data.append(startupFile.toString() + "\n");
1573 if (data.length() > 5)
1575 startupFile = data.toString();
1578 if (!enableSplitFrame)
1585 LoadingThread loader = new LoadingThread(startupFile, file2, this);
1595 else if (startupFile != null)
1598 * Start the applet immediately or show a button to start it
1602 LoadingThread loader = new LoadingThread(startupFile, file2, this);
1608 launcher.addActionListener(new java.awt.event.ActionListener()
1610 public void actionPerformed(ActionEvent e)
1612 LoadingThread loader = new LoadingThread(startupFile, file2,
1621 // jalview initialisation with no alignment. loadAlignment() method can
1622 // still be called to open new alignments.
1623 startupFile = "NO FILE";
1629 private void initLiveConnect()
1631 // try really hard to get the liveConnect thing working
1632 boolean notFailed = false;
1634 while (!notFailed && tries < 10)
1638 System.err.println("LiveConnect request thread going to sleep.");
1642 Thread.sleep(700 * (1 + tries));
1643 } catch (InterruptedException q)
1649 System.err.println("LiveConnect request thread woken up.");
1653 JSObject scriptObject = JSObject.getWindow(this);
1654 if (scriptObject.eval("navigator") != null)
1658 } catch (Exception jsex)
1660 System.err.println("Attempt " + tries
1661 + " to access LiveConnect javascript failed.");
1666 private void callInitCallback()
1668 if (initjscallback == null)
1672 initjscallback = initjscallback.trim();
1673 if (initjscallback.length() > 0)
1675 JSObject scriptObject = null;
1678 scriptObject = JSObject.getWindow(this);
1679 } catch (Exception ex)
1683 // try really hard to let the browser plugin know we want liveconnect
1686 if (scriptObject != null)
1690 // do onInit with the JS executor thread
1691 new JSFunctionExec(this).executeJavascriptFunction(true,
1692 initjscallback, null, "Calling oninit callback '"
1693 + initjscallback + "'.");
1694 } catch (Exception e)
1696 System.err.println("Exception when executing _oninit callback '"
1697 + initjscallback + "'.");
1698 e.printStackTrace();
1703 System.err.println("Not executing _oninit callback '"
1704 + initjscallback + "' - no scripting allowed.");
1710 * Initialises and displays a new java.awt.Frame
1713 * java.awt.Frame to be displayed
1715 * title of new frame
1717 * width if new frame
1719 * height of new frame
1721 public static void addFrame(final JFrame frame, String title, int width,
1724 frame.setLocation(lastFrameX, lastFrameY);
1727 frame.setSize(width, height);
1728 frame.setTitle(title);
1729 frame.addWindowListener(new WindowAdapter()
1731 public void windowClosing(WindowEvent e)
1733 if (frame instanceof AlignFrame)
1735 AlignViewport vp = ((AlignFrame) frame).viewport;
1736 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1737 if (vp.applet.currentAlignFrame == frame)
1739 vp.applet.currentAlignFrame = null;
1747 if (frame instanceof EmbmenuFrame)
1749 ((EmbmenuFrame) frame).destroyMenus();
1751 frame.setMenuBar(null);
1755 public void windowActivated(WindowEvent e)
1757 if (frame instanceof AlignFrame)
1759 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1762 System.err.println("Activated window " + frame);
1766 super.windowActivated(e);
1769 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1772 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1775 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1776 * frame) { currentAlignFrame = null; if (debug) {
1777 * System.err.println("Deactivated window "+frame); } }
1778 * super.windowDeactivated(e); }
1781 frame.setVisible(true);
1785 * This paints the background surrounding the "Launch Jalview button" <br>
1787 * If file given in parameter not found, displays error message
1792 public void paintComponent(Graphics g)
1796 g.setColor(new Color(200, 200, 200));
1797 g.setColor(Color.cyan);
1798 g.fillRect(0, 0, getSize().width, getSize().height);
1799 g.setColor(Color.red);
1801 MessageManager.getString("label.jalview_cannot_open_file"),
1803 g.drawString("\"" + startupFile + "\"", 5, 30);
1805 else if (embedded && !haveShownLoadMessage)
1807 g.setColor(Color.black);
1808 g.setFont(new Font("Arial", Font.BOLD, 24));
1809 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1810 getSize().height / 2 - 30);
1811 g.drawString(MessageManager.getString("label.loading_data") + "...",
1812 50, getSize().height / 2);
1813 haveShownLoadMessage = true;
1818 * get all components associated with the applet of the given type
1823 public Vector getAppletWindow(Class class1)
1825 Vector wnds = new Vector();
1826 Component[] cmp = getComponents();
1829 for (int i = 0; i < cmp.length; i++)
1831 if (class1.isAssignableFrom(cmp[i].getClass()))
1833 wnds.addElement(cmp);
1840 class LoadJmolThread extends Thread
1842 private boolean running = false;
1846 if (running || checkedForJmol)
1855 if (!System.getProperty("java.version").startsWith("1.1"))
1857 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1858 jmolAvailable = true;
1863 .println("Jmol not available - Using MCview for structures");
1865 } catch (java.lang.ClassNotFoundException ex)
1871 jmolAvailable = false;
1875 .println("Skipping Jmol check. Will use MCView (probably)");
1878 checkedForJmol = true;
1882 public boolean notFinished()
1884 return running || !checkedForJmol;
1888 class LoadingThread extends Thread
1891 * State variable: protocol for access to file source
1895 String _file; // alignment file or URL spec
1897 String _file2; // second alignment file or URL spec
1901 private void dbgMsg(String msg)
1903 if (JalviewLite.debug)
1905 System.err.println(msg);
1910 * update the protocol state variable for accessing the datasource located
1914 * @return possibly updated datasource string
1916 public String setProtocolState(String file)
1918 if (file.startsWith("PASTE"))
1920 file = file.substring(5);
1921 protocol = AppletFormatAdapter.PASTE;
1923 else if (inArchive(file))
1925 protocol = AppletFormatAdapter.CLASSLOADER;
1929 file = addProtocol(file);
1930 protocol = AppletFormatAdapter.URL;
1932 dbgMsg("Protocol identified as '" + protocol + "'");
1936 public LoadingThread(String file, String file2, JalviewLite _applet)
1939 this._file2 = file2;
1949 * System.out.println("BYPASSING JMOL LOADING FOR NOW. THIS WILL BE DONE ANOTHER WAY")
1953 LoadJmolThread jmolchecker = new LoadJmolThread();
1954 jmolchecker.start();
1955 while (jmolchecker.notFinished()) {
1956 // wait around until the Jmol check is complete.
1959 } catch (Exception e) {
1964 // applet.callInitCallback();
1968 * Load the alignment and any related files as specified by applet
1971 private void startLoading()
1973 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1975 dbgMsg("Loading started.");
1977 AlignFrame newAlignFrame = readAlignment(_file);
1978 AlignFrame newAlignFrame2 = readAlignment(_file2);
1979 if (newAlignFrame != null)
1981 addToDisplay(newAlignFrame, newAlignFrame2);
1982 loadTree(newAlignFrame);
1984 loadScoreFile(newAlignFrame);
1986 loadFeatures(newAlignFrame);
1988 loadAnnotations(newAlignFrame);
1990 loadJnetFile(newAlignFrame);
1992 loadPdbFiles(newAlignFrame);
1997 applet.remove(launcher);
2004 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
2009 public void addToDisplay(AlignFrame af, AlignFrame af2)
2013 af.addToDisplay(embedded);
2017 SplitFrame sf = new SplitFrame(af, af2);
2018 sf.addToDisplay(embedded, JalviewLite.this);
2023 * Read the alignment file (from URL, text 'paste', or archive by
2028 protected AlignFrame readAlignment(String fileParam)
2030 if (fileParam == null)
2034 String resolvedFile = setProtocolState(fileParam);
2035 String format = new IdentifyFile().Identify(resolvedFile, protocol);
2036 dbgMsg("File identified as '" + format + "'");
2037 AlignmentI al = null;
2040 al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
2041 if ((al != null) && (al.getHeight() > 0))
2043 dbgMsg("Successfully loaded file.");
2044 al.setDataset(null);
2045 AlignFrame newAlignFrame = new AlignFrame(al, applet,
2046 resolvedFile, embedded, false);
2047 newAlignFrame.setTitle(resolvedFile);
2048 if (initialAlignFrame == null)
2050 initialAlignFrame = newAlignFrame;
2052 // update the focus.
2053 currentAlignFrame = newAlignFrame;
2055 if (protocol == AppletFormatAdapter.PASTE)
2057 newAlignFrame.setTitle(MessageManager.formatMessage(
2058 "label.sequences_from", new Object[]
2059 { applet.getDocumentBase().toString() }));
2062 newAlignFrame.setStatus(MessageManager.formatMessage(
2063 "label.successfully_loaded_file", new Object[]
2066 return newAlignFrame;
2068 } catch (java.io.IOException ex)
2070 dbgMsg("File load exception.");
2071 ex.printStackTrace();
2076 FileParse fp = new FileParse(resolvedFile, protocol);
2078 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
2080 while ((ln = fp.nextLine()) != null)
2084 dbgMsg(">>>Dump finished.");
2085 } catch (Exception e)
2088 .println("Exception when trying to dump the content of the file parameter.");
2089 e.printStackTrace();
2097 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
2103 protected boolean loadPdbFiles(AlignFrame alignFrame)
2105 boolean result = false;
2107 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
2108 * related to JAL-434
2111 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2114 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2117 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2119 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2122 int pdbFileCount = 0;
2123 // Accumulate pdbs here if they are heading for the same view (if
2124 // alignPdbStructures is true)
2125 Vector pdbs = new Vector();
2126 // create a lazy matcher if we're asked to
2127 SequenceIdMatcher matcher = (applet.getDefaultParameter(
2128 "relaxedidmatch", false)) ? new SequenceIdMatcher(
2129 alignFrame.getAlignViewport().getAlignment()
2130 .getSequencesArray()) : null;
2135 if (pdbFileCount > 0)
2137 param = applet.getParameter("PDBFILE" + pdbFileCount);
2146 PDBEntry pdb = new PDBEntry();
2149 SequenceI[] seqs = null;
2150 String[] chains = null;
2152 StringTokenizer st = new StringTokenizer(param, " ");
2154 if (st.countTokens() < 2)
2156 if (sequence != null)
2158 seqs = new SequenceI[]
2159 { matcher == null ? (Sequence) alignFrame.getAlignViewport()
2160 .getAlignment().findName(sequence) : matcher
2161 .findIdMatch(sequence) };
2167 param = st.nextToken();
2168 Vector tmp = new Vector();
2169 Vector tmp2 = new Vector();
2171 while (st.hasMoreTokens())
2173 seqstring = st.nextToken();
2174 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2175 if (st2.countTokens() > 1)
2177 // This is the chain
2178 tmp2.addElement(st2.nextToken());
2179 seqstring = st2.nextToken();
2181 tmp.addElement(matcher == null ? (Sequence) alignFrame
2182 .getAlignViewport().getAlignment()
2183 .findName(seqstring) : matcher.findIdMatch(seqstring));
2186 seqs = new SequenceI[tmp.size()];
2188 if (tmp2.size() == tmp.size())
2190 chains = new String[tmp2.size()];
2191 tmp2.copyInto(chains);
2194 param = setProtocolState(param);
2196 if (// !jmolAvailable
2198 protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
2200 // Re: JAL-357 : the bug isn't a problem if we are using an
2202 // TODO: verify this Re:
2203 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2204 // This exception preserves the current behaviour where, even if
2205 // the local pdb file was identified in the class loader
2206 protocol = AppletFormatAdapter.URL; // this is probably NOT
2208 param = addProtocol(param); //
2215 for (int i = 0; i < seqs.length; i++)
2217 if (seqs[i] != null)
2219 ((Sequence) seqs[i]).addPDBId(pdb);
2220 StructureSelectionManager.getStructureSelectionManager(
2221 applet).registerPDBEntry(pdb);
2225 if (JalviewLite.debug)
2227 // this may not really be a problem but we give a warning
2230 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2236 if (!alignPdbStructures)
2238 alignFrame.newStructureView(applet, pdb, seqs, chains,
2243 pdbs.addElement(new Object[]
2244 { pdb, seqs, chains, new String(protocol) });
2250 } while (param != null || pdbFileCount < 10);
2251 if (pdbs.size() > 0)
2253 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2254 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2255 String[][] chains = new String[pdbs.size()][];
2256 String[] protocols = new String[pdbs.size()];
2257 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2259 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2260 pdb[pdbsi] = (PDBEntry) o[0];
2261 seqs[pdbsi] = (SequenceI[]) o[1];
2262 chains[pdbsi] = (String[]) o[2];
2263 protocols[pdbsi] = (String) o[3];
2265 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2273 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2279 protected boolean loadJnetFile(AlignFrame alignFrame)
2281 boolean result = false;
2282 String param = jnetFile;
2287 param = setProtocolState(param);
2288 AlignFile predictions = GenericFileAdapter.getFile("JPredFile", param, protocol);
2289 JnetAnnotationMaker.add_annotation(predictions,
2290 alignFrame.viewport.getAlignment(), 0, false);
2291 // false == do not add sequence profile from concise output
2292 SequenceI repseq = alignFrame.viewport.getAlignment()
2294 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2295 ColumnSelection cs = new ColumnSelection();
2296 cs.hideInsertionsFor(repseq);
2297 alignFrame.viewport.setColumnSelection(cs);
2298 alignFrame.alignPanel.fontChanged();
2299 alignFrame.alignPanel.setScrollValues(0, 0);
2301 } catch (Exception ex)
2303 ex.printStackTrace();
2310 * Load annotations if specified by parameter. Returns true if loaded, else
2316 protected boolean loadAnnotations(AlignFrame alignFrame)
2318 boolean result = false;
2319 String param = annotations;
2322 param = setProtocolState(param);
2324 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2327 alignFrame.alignPanel.fontChanged();
2328 alignFrame.alignPanel.setScrollValues(0, 0);
2334 .println("Annotations were not added from annotation file '"
2342 * Load features file and view settings as specified by parameters. Returns
2343 * true if features were loaded, else false.
2348 protected boolean loadFeatures(AlignFrame alignFrame)
2350 boolean result = false;
2351 // ///////////////////////////
2352 // modify display of features
2353 // we do this before any features have been loaded, ensuring any hidden
2354 // groups are hidden when features first displayed
2356 // hide specific groups
2358 String param = hideFeatureGroups;
2361 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2362 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2364 // show specific groups
2366 param = showFeatureGroups;
2369 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2370 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2373 // and now load features
2377 param = setProtocolState(param);
2379 result = alignFrame.parseFeaturesFile(param, protocol);
2382 param = showFeatureSettings;
2383 if (param != null && param.equalsIgnoreCase(TRUE))
2385 alignFrame.viewport.setShowSequenceFeatures(true);
2386 new FeatureSettings(alignFrame.alignPanel);
2392 * Load a score file if specified by parameter. Returns true if file was
2393 * loaded, else false.
2397 protected boolean loadScoreFile(AlignFrame alignFrame)
2399 boolean result = false;
2400 if (scoreFile != null && !"".equals(scoreFile))
2407 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2409 result = alignFrame.loadScoreFile(scoreFile);
2413 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2414 + scoreFile + "')");
2416 } catch (Exception e)
2418 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2419 scoreFile, e.getMessage());
2426 * Load a tree for the alignment if specified by parameter. Returns true if
2427 * a tree was loaded, else false.
2432 protected boolean loadTree(AlignFrame alignFrame)
2434 boolean result = false;
2435 if (treeFile == null)
2437 treeFile = applet.getParameter("treeFile");
2440 if (treeFile != null)
2444 treeFile = setProtocolState(treeFile);
2445 NewickFile fin = new NewickFile(treeFile, protocol);
2448 if (fin.getTree() != null)
2450 alignFrame.loadTree(fin, treeFile);
2452 dbgMsg("Successfully imported tree.");
2456 dbgMsg("Tree parameter did not resolve to a valid tree.");
2458 } catch (Exception ex)
2460 ex.printStackTrace();
2467 * Discovers whether the given file is in the Applet Archive
2473 boolean inArchive(String file)
2475 // This might throw a security exception in certain browsers
2476 // Netscape Communicator for instance.
2479 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2482 System.err.println("Resource '" + file + "' was "
2483 + (rtn ? "" : "not") + " located by classloader.");
2486 } catch (Exception ex)
2488 System.out.println("Exception checking resources: " + file + " "
2495 * If the file is not already in URL format, tries to locate it by resolving
2501 String addProtocol(final String file)
2503 if (file.indexOf("://") == -1)
2506 * Try relative to document base
2508 String url = applet.resolveUrlForLocalOrAbsolute(file,
2514 System.err.println("Prepended document base for resource: '"
2521 * Try relative to codebase
2523 url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2528 System.err.println("Prepended codebase for resource: '" + file
2536 * Not resolved, leave unchanged
2542 * Returns true if an input stream can be opened on the specified URL, else
2548 private boolean urlExists(String url)
2550 InputStream is = null;
2553 is = new URL(url).openStream();
2558 } catch (Exception x)
2568 } catch (IOException e)
2579 * @return the default alignFrame acted on by the public applet methods. May
2580 * return null with an error message on System.err indicating the
2583 public AlignFrame getDefaultTargetFrame()
2585 if (currentAlignFrame != null)
2587 return currentAlignFrame;
2589 if (initialAlignFrame != null)
2591 return initialAlignFrame;
2594 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2599 * separator used for separatorList
2601 protected String separator = "" + ((char) 0x00AC); // the default used to be
2602 // '|' but many sequence
2603 // IDS include pipes.
2606 * set to enable the URL based javascript execution mechanism
2608 public boolean jsfallbackEnabled = false;
2611 * parse the string into a list
2614 * @return elements separated by separator
2616 public String[] separatorListToArray(String list)
2618 return separatorListToArray(list, separator);
2622 * parse the string into a list
2626 * @return elements separated by separator
2628 public String[] separatorListToArray(String list, String separator)
2630 // note separator local variable intentionally masks object field
2631 int seplen = separator.length();
2632 if (list == null || list.equals("") || list.equals(separator))
2636 java.util.Vector jv = new Vector();
2638 while ((pos = list.indexOf(separator, cp)) > cp)
2640 jv.addElement(list.substring(cp, pos));
2643 if (cp < list.length())
2645 String c = list.substring(cp);
2646 if (!c.equals(separator))
2653 String[] v = new String[jv.size()];
2654 for (int i = 0; i < v.length; i++)
2656 v[i] = (String) jv.elementAt(i);
2658 jv.removeAllElements();
2661 System.err.println("Array from '" + separator
2662 + "' separated List:\n" + v.length);
2663 for (int i = 0; i < v.length; i++)
2665 System.err.println("item " + i + " '" + v[i] + "'");
2672 System.err.println("Empty Array from '" + separator
2673 + "' separated List");
2679 * concatenate the list with separator
2682 * @return concatenated string
2684 public String arrayToSeparatorList(String[] list)
2686 return arrayToSeparatorList(list, separator);
2690 * concatenate the list with separator
2694 * @return concatenated string
2696 public String arrayToSeparatorList(String[] list, String separator)
2698 StringBuffer v = new StringBuffer();
2699 if (list != null && list.length > 0)
2701 for (int i = 0, iSize = list.length; i < iSize; i++)
2703 if (list[i] != null)
2707 v.append(separator);
2714 System.err.println("Returning '" + separator
2715 + "' separated List:\n");
2716 System.err.println(v);
2718 return v.toString();
2722 System.err.println("Returning empty '" + separator
2723 + "' separated List\n");
2725 return "" + separator;
2731 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2733 public String getFeatureGroups()
2735 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2736 .getFeatureGroups());
2744 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2747 public String getFeatureGroupsOn(AlignFrame alf)
2749 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2756 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2758 public String getFeatureGroupsOfState(boolean visible)
2760 return arrayToSeparatorList(getDefaultTargetFrame()
2761 .getFeatureGroupsOfState(visible));
2768 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2769 * .AlignFrame, boolean)
2771 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2773 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2779 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2780 * AlignFrame, java.lang.String, boolean)
2782 public void setFeatureGroupStateOn(final AlignFrame alf,
2783 final String groups, boolean state)
2785 final boolean st = state;// !(state==null || state.equals("") ||
2786 // state.toLowerCase().equals("false"));
2787 java.awt.EventQueue.invokeLater(new Runnable()
2792 alf.setFeatureGroupState(separatorListToArray(groups), st);
2800 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2803 public void setFeatureGroupState(String groups, boolean state)
2805 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2811 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2813 public String getSeparator()
2821 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2823 public void setSeparator(String separator)
2825 if (separator == null || separator.length() < 1)
2828 separator = "" + ((char) 0x00AC);
2830 this.separator = separator;
2833 System.err.println("Default Separator now: '" + separator + "'");
2840 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2841 * java.lang.String, java.lang.String, java.lang.String)
2843 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2844 String pdbEntryString, String pdbFile)
2846 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2849 protected void setAlignPdbStructures(boolean alignPdbStructures)
2851 this.alignPdbStructures = alignPdbStructures;
2854 public boolean isAlignPdbStructures()
2856 return alignPdbStructures;
2861 // callInitCallback();
2864 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2866 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2868 public void setJsMessageSet(String messageclass, String viewId,
2869 String[] colcommands)
2871 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2874 msgset = new Hashtable<String, String[]>();
2875 jsmessages.put(messageclass, msgset);
2877 msgset.put(viewId, colcommands);
2878 long[] l = new long[colcommands.length];
2879 for (int i = 0; i < colcommands.length; i++)
2881 l[i] = colcommands[i].hashCode();
2883 jshashes.put(messageclass + "|" + viewId, l);
2889 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2892 public String getJsMessage(String messageclass, String viewId)
2894 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2897 String[] msgs = msgset.get(viewId);
2900 for (int i = 0; i < msgs.length; i++)
2902 if (msgs[i] != null)
2914 public boolean isJsMessageSetChanged(String string, String string2,
2915 String[] colcommands)
2917 long[] l = jshashes.get(string + "|" + string2);
2918 if (l == null && colcommands != null)
2922 for (int i = 0; i < colcommands.length; i++)
2924 if (l[i] != colcommands[i].hashCode())
2932 private Vector jsExecQueue = new Vector();
2934 public Vector getJsExecQueue()
2939 public void setExecutor(JSFunctionExec jsFunctionExec2)
2941 jsFunctionExec = jsFunctionExec2;
2945 * return the given colour value parameter or the given default if parameter
2952 public Color getDefaultColourParameter(String colparam, Color defcolour)
2954 String colprop = getParameter(colparam);
2955 if (colprop == null || colprop.trim().length() == 0)
2959 Color col = ColourSchemeProperty.getAWTColorFromName(colprop);
2964 col = new UserColourScheme(colprop).findColour('A');
2965 } catch (Exception ex)
2967 System.err.println("Couldn't parse '" + colprop
2968 + "' as a colour for " + colparam);
2972 return (col == null) ? defcolour : col;
2976 public void openJalviewHelpUrl()
2978 if (helpUrl == null || helpUrl.trim().length() < 5)
2980 helpUrl = "http://www.jalview.org/help.html";
2982 showURL(helpUrl, "HELP");
2986 * form a complete URL given a path to a resource and a reference location on
2990 * - an absolute path on the same server as localref or a document
2991 * located relative to localref
2993 * - a URL on the same server as url
2994 * @return a complete URL for the resource located by url
2996 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2998 String codebase = localref.toString();
2999 // BH removing file name and query
3000 int pt = codebase.indexOf("?");
3002 pt = codebase.length();
3003 codebase = codebase.substring(0, pt);
3004 codebase = codebase.substring(0, codebase.lastIndexOf("/") + 1);
3005 // codebase is now http://...xxx/
3006 if (url.indexOf("/") == 0 && !localref.getProtocol().equals("file"))
3007 { // http:// https:// we do NOT allow going to the root file system directory!
3008 pt = codebase.indexOf("/", 8);
3009 return codebase.substring(0, pt) + url;
3011 return codebase + url;
3015 * open a URL in the browser - resolving it according to relative refs and
3016 * coping with javascript: protocol if necessary.
3021 public void showURL(String url, String target)
3025 if (url.indexOf(":") == -1)
3027 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
3029 // Should really use docbase, not codebase.
3031 url = resolveUrlForLocalOrAbsolute(
3033 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
3038 .println("Show url (prepended "
3040 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
3048 System.err.println("Show url: " + url);
3051 if (url.indexOf("javascript:") == 0)
3053 // no target for the javascript context
3054 getAppletContext().showDocument(new java.net.URL(url));
3058 getAppletContext().showDocument(new java.net.URL(url), target);
3060 } catch (Exception ex)
3062 ex.printStackTrace();
3067 * bind structures in a viewer to any matching sequences in an alignFrame (use
3068 * sequenceIds to limit scope of search to specific sequences)
3072 * @param sequenceIds
3073 * @return TODO: consider making an exception structure for indicating when
3074 * binding fails public SequenceStructureBinding
3075 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
3078 * if (sequenceIds != null && sequenceIds.length() > 0) { return
3079 * alFrame.addStructureViewInstance(viewer,
3080 * separatorListToArray(sequenceIds)); } else { return
3081 * alFrame.addStructureViewInstance(viewer, null); } // return null; }