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.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.javascript.JsSelectionSender;
49 import jalview.javascript.MouseOverListener;
50 import jalview.javascript.MouseOverStructureListener;
51 import jalview.schemes.ColourSchemeProperty;
52 import jalview.schemes.UserColourScheme;
53 import jalview.structure.SelectionListener;
54 import jalview.structure.StructureSelectionManager;
55 import jalview.util.MessageManager;
57 import java.applet.Applet;
58 import java.awt.Button;
59 import java.awt.Color;
60 import java.awt.Component;
61 import java.awt.EventQueue;
63 import java.awt.Frame;
64 import java.awt.Graphics;
65 import java.awt.event.ActionEvent;
66 import java.awt.event.WindowAdapter;
67 import java.awt.event.WindowEvent;
68 import java.io.BufferedReader;
69 import java.io.IOException;
70 import java.io.InputStream;
71 import java.io.InputStreamReader;
73 import java.util.Hashtable;
74 import java.util.List;
75 import java.util.StringTokenizer;
76 import java.util.Vector;
78 import netscape.javascript.JSException;
79 import netscape.javascript.JSObject;
82 * Jalview Applet. Runs in Java 1.18 runtime
85 * @version $Revision: 1.92 $
87 public class JalviewLite extends Applet implements
88 StructureSelectionManagerProvider, JalviewLiteJsApi
91 private static final String TRUE = "true";
93 private static final String FALSE = "false";
95 public StructureSelectionManager getStructureSelectionManager()
97 return StructureSelectionManager.getStructureSelectionManager(this);
100 // /////////////////////////////////////////
101 // The following public methods maybe called
102 // externally, eg via javascript in HTML page
106 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
108 public String getSelectedSequences()
110 return getSelectedSequencesFrom(getDefaultTargetFrame());
116 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
118 public String getSelectedSequences(String sep)
120 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
127 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
130 public String getSelectedSequencesFrom(AlignFrame alf)
132 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
139 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
140 * .AlignFrame, java.lang.String)
142 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
144 StringBuffer result = new StringBuffer("");
145 if (sep == null || sep.length() == 0)
147 sep = separator; // "+0x00AC;
149 if (alf.viewport.getSelectionGroup() != null)
151 SequenceI[] seqs = alf.viewport.getSelectionGroup()
152 .getSequencesInOrder(alf.viewport.getAlignment());
154 for (int i = 0; i < seqs.length; i++)
156 result.append(seqs[i].getName());
161 return result.toString();
167 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
168 * java.lang.String, java.lang.String)
170 public void highlight(String sequenceId, String position,
171 String alignedPosition)
173 highlightIn(getDefaultTargetFrame(), sequenceId, position,
180 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
181 * java.lang.String, java.lang.String, java.lang.String)
183 public void highlightIn(final AlignFrame alf, final String sequenceId,
184 final String position, final String alignedPosition)
186 // TODO: could try to highlight in all alignments if alf==null
187 SequenceIdMatcher matcher = new SequenceIdMatcher(
188 alf.viewport.getAlignment().getSequencesArray());
189 final SequenceI sq = matcher.findIdMatch(sequenceId);
195 apos = new Integer(position).intValue();
197 } catch (NumberFormatException ex)
201 final StructureSelectionManagerProvider me = this;
202 final int pos = apos;
203 // use vamsas listener to broadcast to all listeners in scope
204 if (alignedPosition != null
205 && (alignedPosition.trim().length() == 0 || alignedPosition
206 .toLowerCase().indexOf("false") > -1))
208 java.awt.EventQueue.invokeLater(new Runnable()
213 StructureSelectionManager.getStructureSelectionManager(me)
214 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
220 java.awt.EventQueue.invokeLater(new Runnable()
225 StructureSelectionManager.getStructureSelectionManager(me)
226 .mouseOverVamsasSequence(sq, pos, null);
236 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
239 public void select(String sequenceIds, String columns)
241 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
247 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
248 * java.lang.String, java.lang.String)
250 public void select(String sequenceIds, String columns, String sep)
252 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
258 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
259 * java.lang.String, java.lang.String)
261 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
263 selectIn(alf, sequenceIds, columns, separator);
269 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
270 * java.lang.String, java.lang.String, java.lang.String)
272 public void selectIn(final AlignFrame alf, String sequenceIds,
273 String columns, String sep)
275 if (sep == null || sep.length() == 0)
283 System.err.println("Selecting region using separator string '"
288 String[] ids = separatorListToArray(sequenceIds, sep);
289 String[] cols = separatorListToArray(columns, sep);
290 final SequenceGroup sel = new SequenceGroup();
291 final ColumnSelection csel = new ColumnSelection();
292 AlignmentI al = alf.viewport.getAlignment();
293 SequenceIdMatcher matcher = new SequenceIdMatcher(
294 alf.viewport.getAlignment().getSequencesArray());
295 int start = 0, end = al.getWidth(), alw = al.getWidth();
296 boolean seqsfound = true;
297 if (ids != null && ids.length > 0)
300 for (int i = 0; i < ids.length; i++)
302 if (ids[i].trim().length() == 0)
306 SequenceI sq = matcher.findIdMatch(ids[i]);
310 sel.addSequence(sq, false);
314 boolean inseqpos = false;
315 if (cols != null && cols.length > 0)
317 boolean seset = false;
318 for (int i = 0; i < cols.length; i++)
320 String cl = cols[i].trim();
321 if (cl.length() == 0)
326 if ((p = cl.indexOf("-")) > -1)
328 int from = -1, to = -1;
331 from = new Integer(cl.substring(0, p)).intValue();
333 } catch (NumberFormatException ex)
336 .println("ERROR: Couldn't parse first integer in range element column selection string '"
337 + cl + "' - format is 'from-to'");
342 to = new Integer(cl.substring(p + 1)).intValue();
344 } catch (NumberFormatException ex)
347 .println("ERROR: Couldn't parse second integer in range element column selection string '"
348 + cl + "' - format is 'from-to'");
351 if (from >= 0 && to >= 0)
368 // comment to prevent range extension
378 for (int r = from; r <= to; r++)
380 if (r >= 0 && r < alw)
387 System.err.println("Range '" + cl + "' deparsed as [" + from
393 System.err.println("ERROR: Invalid Range '" + cl
394 + "' deparsed as [" + from + "," + to + "]");
402 r = new Integer(cl).intValue();
404 } catch (NumberFormatException ex)
406 if (cl.toLowerCase().equals("sequence"))
408 // we are in the dataset sequence's coordinate frame.
414 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
419 if (r >= 0 && r <= alw)
429 // comment to prevent range extension
442 System.err.println("Point selection '" + cl
443 + "' deparsed as [" + r + "]");
448 System.err.println("ERROR: Invalid Point selection '" + cl
449 + "' deparsed as [" + r + "]");
456 // we only propagate the selection when it was the null selection, or the
457 // given sequences were found in the alignment.
458 if (inseqpos && sel.getSize() > 0)
460 // assume first sequence provides reference frame ?
461 SequenceI rs = sel.getSequenceAt(0);
462 start = rs.findIndex(start);
463 end = rs.findIndex(end);
466 List<Integer> cs = csel.getSelected();
468 for (Integer selectedCol : cs)
470 csel.addElement(rs.findIndex(selectedCol));
474 sel.setStartRes(start);
476 EventQueue.invokeLater(new Runnable()
481 alf.select(sel, csel);
491 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
492 * String, java.lang.String)
494 public String getSelectedSequencesAsAlignment(String format, String suffix)
496 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
504 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
505 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
507 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
508 String format, String suffix)
512 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
513 if (alf.viewport.getSelectionGroup() != null)
515 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
516 // method now returns a full copy of sequence data
517 // TODO consider using getSequenceSelection instead here
518 String reply = new AppletFormatAdapter().formatSequences(format,
519 new Alignment(alf.viewport.getSelectionAsNewSequence()),
523 } catch (Exception ex)
525 ex.printStackTrace();
526 return "Error retrieving alignment in " + format + " format. ";
534 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
536 public String getAlignmentOrder()
538 return getAlignmentOrderFrom(getDefaultTargetFrame());
545 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
548 public String getAlignmentOrderFrom(AlignFrame alf)
550 return getAlignmentOrderFrom(alf, separator);
557 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
558 * , java.lang.String)
560 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
562 AlignmentI alorder = alf.getAlignViewport().getAlignment();
563 String[] order = new String[alorder.getHeight()];
564 for (int i = 0; i < order.length; i++)
566 order[i] = alorder.getSequenceAt(i).getName();
568 return arrayToSeparatorList(order);
574 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
577 public String orderBy(String order, String undoName)
579 return orderBy(order, undoName, separator);
585 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
586 * java.lang.String, java.lang.String)
588 public String orderBy(String order, String undoName, String sep)
590 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
597 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
598 * java.lang.String, java.lang.String, java.lang.String)
600 public String orderAlignmentBy(AlignFrame alf, String order,
601 String undoName, String sep)
603 String[] ids = separatorListToArray(order, sep);
604 SequenceI[] sqs = null;
605 if (ids != null && ids.length > 0)
607 SequenceIdMatcher matcher = new SequenceIdMatcher(
608 alf.viewport.getAlignment().getSequencesArray());
610 sqs = new SequenceI[ids.length];
611 for (int i = 0; i < ids.length; i++)
613 if (ids[i].trim().length() == 0)
617 SequenceI sq = matcher.findIdMatch(ids[i]);
625 SequenceI[] sqq = new SequenceI[s];
626 System.arraycopy(sqs, 0, sqq, 0, s);
639 final AlignmentOrder aorder = new AlignmentOrder(sqs);
641 if (undoName != null && undoName.trim().length() == 0)
645 final String _undoName = undoName;
646 // TODO: deal with synchronization here: cannot raise any events until after
647 // this has returned.
648 return alf.sortBy(aorder, _undoName) ? TRUE : "";
654 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
656 public String getAlignment(String format)
658 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
665 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
668 public String getAlignmentFrom(AlignFrame alf, String format)
670 return getAlignmentFrom(alf, format, TRUE);
676 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
679 public String getAlignment(String format, String suffix)
681 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
688 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
689 * java.lang.String, java.lang.String)
691 public String getAlignmentFrom(AlignFrame alf, String format,
696 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
698 String reply = new AppletFormatAdapter().formatSequences(format,
699 alf.viewport.getAlignment(), seqlimits);
701 } catch (Exception ex)
703 ex.printStackTrace();
704 return "Error retrieving alignment in " + format + " format. ";
711 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
713 public void loadAnnotation(String annotation)
715 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
722 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
723 * , java.lang.String)
725 public void loadAnnotationFrom(AlignFrame alf, String annotation)
727 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
728 annotation, AppletFormatAdapter.PASTE))
730 alf.alignPanel.fontChanged();
731 alf.alignPanel.setScrollValues(0, 0);
735 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
742 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
744 public void loadFeatures(String features, boolean autoenabledisplay)
746 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
753 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
754 * , java.lang.String)
756 public boolean loadFeaturesFrom(AlignFrame alf, String features,
757 boolean autoenabledisplay)
759 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
766 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
768 public String getFeatures(String format)
770 return getFeaturesFrom(getDefaultTargetFrame(), format);
777 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
780 public String getFeaturesFrom(AlignFrame alf, String format)
782 return alf.outputFeatures(false, format);
788 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
790 public String getAnnotation()
792 return getAnnotationFrom(getDefaultTargetFrame());
799 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
802 public String getAnnotationFrom(AlignFrame alf)
804 return alf.outputAnnotations(false);
810 * @see jalview.bin.JalviewLiteJsApi#newView()
812 public AlignFrame newView()
814 return newViewFrom(getDefaultTargetFrame());
820 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
822 public AlignFrame newView(String name)
824 return newViewFrom(getDefaultTargetFrame(), name);
830 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
832 public AlignFrame newViewFrom(AlignFrame alf)
834 return alf.newView(null);
840 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
843 public AlignFrame newViewFrom(AlignFrame alf, String name)
845 return alf.newView(name);
851 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
854 public AlignFrame loadAlignment(String text, String title)
856 AlignmentI al = null;
858 String format = new IdentifyFile().Identify(text,
859 AppletFormatAdapter.PASTE);
862 al = new AppletFormatAdapter().readFile(text,
863 AppletFormatAdapter.PASTE, format);
864 if (al.getHeight() > 0)
866 return new AlignFrame(al, this, title, false);
868 } catch (java.io.IOException ex)
870 ex.printStackTrace();
878 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
880 public void setMouseoverListener(String listener)
882 setMouseoverListener(currentAlignFrame, listener);
885 private Vector<JSFunctionExec> javascriptListeners = new Vector<JSFunctionExec>();
891 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
892 * , java.lang.String)
894 public void setMouseoverListener(AlignFrame af, String listener)
896 if (listener != null)
898 listener = listener.trim();
899 if (listener.length() == 0)
902 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
906 MouseOverListener mol = new MouseOverListener(
908 javascriptListeners.addElement(mol);
909 StructureSelectionManager.getStructureSelectionManager(this)
910 .addStructureViewerListener(mol);
913 System.err.println("Added a mouseover listener for "
914 + ((af == null) ? "All frames" : "Just views for "
915 + af.getAlignViewport().getSequenceSetId()));
916 System.err.println("There are now " + javascriptListeners.size()
917 + " listeners in total.");
924 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
926 public void setSelectionListener(String listener)
928 setSelectionListener(null, listener);
935 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
936 * , java.lang.String)
938 public void setSelectionListener(AlignFrame af, String listener)
940 if (listener != null)
942 listener = listener.trim();
943 if (listener.length() == 0)
946 .println("jalview Javascript error: Ignoring empty function for selection listener.");
950 JsSelectionSender mol = new JsSelectionSender(this, af, listener);
951 javascriptListeners.addElement(mol);
952 StructureSelectionManager.getStructureSelectionManager(this)
953 .addSelectionListener(mol);
956 System.err.println("Added a selection listener for "
957 + ((af == null) ? "All frames" : "Just views for "
958 + af.getAlignViewport().getSequenceSetId()));
959 System.err.println("There are now " + javascriptListeners.size()
960 + " listeners in total.");
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 MouseOverStructureListener mol = new 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 JSFunctionExec mol = javascriptListeners.elementAt(0);
1080 javascriptListeners.removeElement(mol);
1081 if (mol instanceof SelectionListener)
1083 StructureSelectionManager.getStructureSelectionManager(this)
1084 .removeSelectionListener((SelectionListener) mol);
1088 StructureSelectionManager.getStructureSelectionManager(this)
1089 .removeStructureViewerListener(mol, null);
1094 if (jsFunctionExec != null)
1096 jsFunctionExec.stopQueue();
1097 jsFunctionExec.jvlite = null;
1099 initialAlignFrame = null;
1100 jsFunctionExec = null;
1101 javascriptListeners = null;
1102 StructureSelectionManager.release(this);
1105 private JSFunctionExec jsFunctionExec;
1110 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1111 * java.lang.String, java.lang.String)
1113 public void mouseOverStructure(final String pdbResNum,
1114 final String chain, final String pdbfile)
1116 final StructureSelectionManagerProvider me = this;
1117 java.awt.EventQueue.invokeLater(new Runnable()
1124 StructureSelectionManager.getStructureSelectionManager(me)
1125 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1129 System.err.println("mouseOver for '" + pdbResNum
1130 + "' in chain '" + chain + "' in structure '" + pdbfile
1133 } catch (NumberFormatException e)
1135 System.err.println("Ignoring invalid residue number string '"
1147 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1148 * java.lang.String, java.lang.String)
1150 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1151 final String leftHandColumn)
1153 java.awt.EventQueue.invokeLater(new Runnable()
1160 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1161 leftHandColumn).intValue());
1163 } catch (Exception ex)
1165 System.err.println("Couldn't parse integer arguments (topRow='"
1166 + topRow + "' and leftHandColumn='" + leftHandColumn
1168 ex.printStackTrace();
1178 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1179 * .AlignFrame, java.lang.String)
1182 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1185 java.awt.EventQueue.invokeLater(new Runnable()
1192 alf.scrollToRow(new Integer(topRow).intValue());
1194 } catch (Exception ex)
1196 System.err.println("Couldn't parse integer arguments (topRow='"
1198 ex.printStackTrace();
1209 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1210 * .AlignFrame, java.lang.String)
1213 public void scrollViewToColumnIn(final AlignFrame alf,
1214 final String leftHandColumn)
1216 java.awt.EventQueue.invokeLater(new Runnable()
1224 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1226 } catch (Exception ex)
1229 .println("Couldn't parse integer arguments (leftHandColumn='"
1230 + leftHandColumn + "')");
1231 ex.printStackTrace();
1238 // //////////////////////////////////////////////
1239 // //////////////////////////////////////////////
1241 public static int lastFrameX = 200;
1243 public static int lastFrameY = 200;
1245 boolean fileFound = true;
1247 String file = "No file";
1249 String file2 = null;
1251 Button launcher = new Button(
1252 MessageManager.getString("label.start_jalview"));
1255 * The currentAlignFrame is static, it will change if and when the user
1256 * selects a new window. Note that it will *never* point back to the embedded
1257 * AlignFrame if the applet is started as embedded on the page and then
1258 * afterwards a new view is created.
1260 public AlignFrame currentAlignFrame = null;
1263 * This is the first frame to be displayed, and does not change. API calls
1264 * will default to this instance if currentAlignFrame is null.
1266 AlignFrame initialAlignFrame = null;
1268 boolean embedded = false;
1270 private boolean checkForJmol = true;
1272 private boolean checkedForJmol = false; // ensure we don't check for jmol
1274 // every time the app is re-inited
1276 public boolean jmolAvailable = false;
1278 private boolean alignPdbStructures = false;
1281 * use an external structure viewer exclusively (no jmols or MCViews will be
1282 * opened by JalviewLite itself)
1284 public boolean useXtrnalSviewer = false;
1286 public static boolean debug = false;
1288 static String builddate = null, version = null, installation = null;
1290 private static void initBuildDetails()
1292 if (builddate == null)
1294 builddate = "unknown";
1296 installation = "Webstart";
1297 java.net.URL url = JalviewLite.class
1298 .getResource("/.build_properties");
1303 BufferedReader reader = new BufferedReader(new InputStreamReader(
1306 while ((line = reader.readLine()) != null)
1308 if (line.indexOf("VERSION") > -1)
1310 version = line.substring(line.indexOf("=") + 1);
1312 if (line.indexOf("BUILD_DATE") > -1)
1314 builddate = line.substring(line.indexOf("=") + 1);
1316 if (line.indexOf("INSTALLATION") > -1)
1318 installation = line.substring(line.indexOf("=") + 1);
1321 } catch (Exception ex)
1323 ex.printStackTrace();
1329 public static String getBuildDate()
1335 public static String getInstallation()
1338 return installation;
1341 public static String getVersion()
1347 // public JSObject scriptObject = null;
1350 * init method for Jalview Applet
1354 // remove any handlers that might be hanging around from an earlier instance
1359 System.err.println("Applet context is '"
1360 + getAppletContext().getClass().toString() + "'");
1362 JSObject scriptObject = JSObject.getWindow(this);
1363 if (debug && scriptObject != null)
1365 System.err.println("Applet has Javascript callback support.");
1368 } catch (Exception ex)
1371 .println("Warning: No JalviewLite javascript callbacks available.");
1374 ex.printStackTrace();
1378 * turn on extra applet debugging
1380 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1384 System.err.println("JalviewLite Version " + getVersion());
1385 System.err.println("Build Date : " + getBuildDate());
1386 System.err.println("Installation : " + getInstallation());
1389 String externalsviewer = getParameter("externalstructureviewer");
1390 if (externalsviewer != null)
1392 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1396 * if true disable the check for jmol
1398 String chkforJmol = getParameter("nojmol");
1399 if (chkforJmol != null)
1401 checkForJmol = !chkforJmol.equals(TRUE);
1404 * get the separator parameter if present
1406 String sep = getParameter("separator");
1409 if (sep.length() > 0)
1414 System.err.println("Separator set to '" + separator + "'");
1419 throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
1425 String param = getParameter("RGB");
1431 r = Integer.parseInt(param.substring(0, 2), 16);
1432 g = Integer.parseInt(param.substring(2, 4), 16);
1433 b = Integer.parseInt(param.substring(4, 6), 16);
1434 } catch (Exception ex)
1441 param = getParameter("label");
1444 launcher.setLabel(param);
1447 setBackground(new Color(r, g, b));
1449 file = getParameter("file");
1453 // Maybe the sequences are added as parameters
1454 StringBuffer data = new StringBuffer("PASTE");
1456 while ((file = getParameter("sequence" + i)) != null)
1458 data.append(file.toString() + "\n");
1461 if (data.length() > 5)
1463 file = data.toString();
1466 if (TRUE.equalsIgnoreCase(getParameter("enableSplitFrame")))
1468 file2 = getParameter("file2");
1471 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
1474 LoadingThread loader = new LoadingThread(file, file2, this);
1477 else if (file != null)
1480 * Start the applet immediately or show a button to start it
1482 if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
1484 LoadingThread loader = new LoadingThread(file, file2, this);
1490 launcher.addActionListener(new java.awt.event.ActionListener()
1492 public void actionPerformed(ActionEvent e)
1494 LoadingThread loader = new LoadingThread(file, file2,
1503 // jalview initialisation with no alignment. loadAlignment() method can
1504 // still be called to open new alignments.
1511 private void initLiveConnect()
1513 // try really hard to get the liveConnect thing working
1514 boolean notFailed = false;
1516 while (!notFailed && tries < 10)
1520 System.err.println("LiveConnect request thread going to sleep.");
1524 Thread.sleep(700 * (1 + tries));
1525 } catch (InterruptedException q)
1531 System.err.println("LiveConnect request thread woken up.");
1535 JSObject scriptObject = JSObject.getWindow(this);
1536 if (scriptObject.eval("navigator") != null)
1540 } catch (JSException jsex)
1542 System.err.println("Attempt " + tries
1543 + " to access LiveConnect javascript failed.");
1548 private void callInitCallback()
1550 String initjscallback = getParameter("oninit");
1551 if (initjscallback == null)
1555 initjscallback = initjscallback.trim();
1556 if (initjscallback.length() > 0)
1558 JSObject scriptObject = null;
1561 scriptObject = JSObject.getWindow(this);
1562 } catch (Exception ex)
1566 // try really hard to let the browser plugin know we want liveconnect
1569 if (scriptObject != null)
1573 // do onInit with the JS executor thread
1574 new JSFunctionExec(this).executeJavascriptFunction(true,
1575 initjscallback, null, "Calling oninit callback '"
1576 + initjscallback + "'.");
1577 } catch (Exception e)
1579 System.err.println("Exception when executing _oninit callback '"
1580 + initjscallback + "'.");
1581 e.printStackTrace();
1586 System.err.println("Not executing _oninit callback '"
1587 + initjscallback + "' - no scripting allowed.");
1593 * Initialises and displays a new java.awt.Frame
1596 * java.awt.Frame to be displayed
1598 * title of new frame
1600 * width if new frame
1602 * height of new frame
1604 public static void addFrame(final Frame frame, String title, int width,
1607 frame.setLocation(lastFrameX, lastFrameY);
1610 frame.setSize(width, height);
1611 frame.setTitle(title);
1612 frame.addWindowListener(new WindowAdapter()
1614 public void windowClosing(WindowEvent e)
1616 if (frame instanceof AlignFrame)
1618 AlignViewport vp = ((AlignFrame) frame).viewport;
1619 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1620 if (vp.applet.currentAlignFrame == frame)
1622 vp.applet.currentAlignFrame = null;
1630 if (frame instanceof EmbmenuFrame)
1632 ((EmbmenuFrame) frame).destroyMenus();
1634 frame.setMenuBar(null);
1638 public void windowActivated(WindowEvent e)
1640 if (frame instanceof AlignFrame)
1642 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1645 System.err.println("Activated window " + frame);
1649 super.windowActivated(e);
1652 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1655 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1658 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1659 * frame) { currentAlignFrame = null; if (debug) {
1660 * System.err.println("Deactivated window "+frame); } }
1661 * super.windowDeactivated(e); }
1664 frame.setVisible(true);
1668 * This paints the background surrounding the "Launch Jalview button" <br>
1670 * If file given in parameter not found, displays error message
1675 public void paint(Graphics g)
1679 g.setColor(new Color(200, 200, 200));
1680 g.setColor(Color.cyan);
1681 g.fillRect(0, 0, getSize().width, getSize().height);
1682 g.setColor(Color.red);
1684 MessageManager.getString("label.jalview_cannot_open_file"),
1686 g.drawString("\"" + file + "\"", 5, 30);
1690 g.setColor(Color.black);
1691 g.setFont(new Font("Arial", Font.BOLD, 24));
1692 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1693 getSize().height / 2 - 30);
1694 g.drawString(MessageManager.getString("label.loading_data") + "...",
1695 50, getSize().height / 2);
1700 * get all components associated with the applet of the given type
1705 public Vector getAppletWindow(Class class1)
1707 Vector wnds = new Vector();
1708 Component[] cmp = getComponents();
1711 for (int i = 0; i < cmp.length; i++)
1713 if (class1.isAssignableFrom(cmp[i].getClass()))
1715 wnds.addElement(cmp);
1722 class LoadJmolThread extends Thread
1724 private boolean running = false;
1728 if (running || checkedForJmol)
1737 if (!System.getProperty("java.version").startsWith("1.1"))
1739 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1740 jmolAvailable = true;
1745 .println("Jmol not available - Using MCview for structures");
1747 } catch (java.lang.ClassNotFoundException ex)
1753 jmolAvailable = false;
1757 .println("Skipping Jmol check. Will use MCView (probably)");
1760 checkedForJmol = true;
1764 public boolean notFinished()
1766 return running || !checkedForJmol;
1770 class LoadingThread extends Thread
1773 * State variable: protocol for access to file source
1777 String _file; // alignment file or URL spec
1779 String _file2; // second alignment file or URL spec
1783 private void dbgMsg(String msg)
1785 if (JalviewLite.debug)
1787 System.err.println(msg);
1792 * update the protocol state variable for accessing the datasource located
1796 * @return possibly updated datasource string
1798 public String setProtocolState(String file)
1800 if (file.startsWith("PASTE"))
1802 file = file.substring(5);
1803 protocol = AppletFormatAdapter.PASTE;
1805 else if (inArchive(file))
1807 protocol = AppletFormatAdapter.CLASSLOADER;
1811 file = addProtocol(file);
1812 protocol = AppletFormatAdapter.URL;
1814 dbgMsg("Protocol identified as '" + protocol + "'");
1818 public LoadingThread(String file, String file2, JalviewLite _applet)
1821 this._file2 = file2;
1827 LoadJmolThread jmolchecker = new LoadJmolThread();
1828 jmolchecker.start();
1829 while (jmolchecker.notFinished())
1831 // wait around until the Jmol check is complete.
1835 } catch (Exception e)
1840 // applet.callInitCallback();
1844 * Load the alignment and any related files as specified by applet
1847 private void startLoading()
1849 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1851 dbgMsg("Loading started.");
1853 AlignFrame newAlignFrame = readAlignment(_file);
1854 AlignFrame newAlignFrame2 = readAlignment(_file2);
1855 if (newAlignFrame != null)
1857 addToDisplay(newAlignFrame, newAlignFrame2);
1858 loadTree(newAlignFrame);
1860 loadScoreFile(newAlignFrame);
1862 loadFeatures(newAlignFrame);
1864 loadAnnotations(newAlignFrame);
1866 loadJnetFile(newAlignFrame);
1868 loadPdbFiles(newAlignFrame);
1873 applet.remove(launcher);
1880 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1885 public void addToDisplay(AlignFrame af, AlignFrame af2)
1889 af.addToDisplay(embedded);
1893 SplitFrame sf = new SplitFrame(af, af2);
1894 sf.addToDisplay(embedded, JalviewLite.this);
1899 * Read the alignment file (from URL, text 'paste', or archive by
1904 protected AlignFrame readAlignment(String fileParam)
1906 if (fileParam == null)
1910 String resolvedFile = setProtocolState(fileParam);
1911 String format = new IdentifyFile().Identify(resolvedFile, protocol);
1912 dbgMsg("File identified as '" + format + "'");
1913 AlignmentI al = null;
1916 al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
1917 if ((al != null) && (al.getHeight() > 0))
1919 dbgMsg("Successfully loaded file.");
1920 al.setDataset(null);
1921 AlignFrame newAlignFrame = new AlignFrame(al, applet,
1922 resolvedFile, embedded, false);
1923 newAlignFrame.setTitle(resolvedFile);
1924 if (initialAlignFrame == null)
1926 initialAlignFrame = newAlignFrame;
1928 // update the focus.
1929 currentAlignFrame = newAlignFrame;
1931 if (protocol == AppletFormatAdapter.PASTE)
1933 newAlignFrame.setTitle(MessageManager.formatMessage(
1934 "label.sequences_from", new Object[]
1935 { applet.getDocumentBase().toString() }));
1938 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1939 "label.successfully_loaded_file", new Object[]
1942 return newAlignFrame;
1944 } catch (java.io.IOException ex)
1946 dbgMsg("File load exception.");
1947 ex.printStackTrace();
1952 FileParse fp = new FileParse(resolvedFile, protocol);
1954 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
1956 while ((ln = fp.nextLine()) != null)
1960 dbgMsg(">>>Dump finished.");
1961 } catch (Exception e)
1964 .println("Exception when trying to dump the content of the file parameter.");
1965 e.printStackTrace();
1973 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
1979 protected boolean loadPdbFiles(AlignFrame alignFrame)
1981 boolean result = false;
1983 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
1984 * related to JAL-434
1987 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1990 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1993 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1995 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1998 int pdbFileCount = 0;
1999 // Accumulate pdbs here if they are heading for the same view (if
2000 // alignPdbStructures is true)
2001 Vector pdbs = new Vector();
2002 // create a lazy matcher if we're asked to
2003 SequenceIdMatcher matcher = (applet.getDefaultParameter(
2004 "relaxedidmatch", false)) ? new SequenceIdMatcher(
2005 alignFrame.getAlignViewport().getAlignment()
2006 .getSequencesArray()) : null;
2011 if (pdbFileCount > 0)
2013 param = applet.getParameter("PDBFILE" + pdbFileCount);
2017 param = applet.getParameter("PDBFILE");
2022 PDBEntry pdb = new PDBEntry();
2025 SequenceI[] seqs = null;
2026 String[] chains = null;
2028 StringTokenizer st = new StringTokenizer(param, " ");
2030 if (st.countTokens() < 2)
2032 String sequence = applet.getParameter("PDBSEQ");
2033 if (sequence != null)
2035 seqs = new SequenceI[]
2036 { matcher == null ? (Sequence) alignFrame.getAlignViewport()
2037 .getAlignment().findName(sequence) : matcher
2038 .findIdMatch(sequence) };
2044 param = st.nextToken();
2045 Vector tmp = new Vector();
2046 Vector tmp2 = new Vector();
2048 while (st.hasMoreTokens())
2050 seqstring = st.nextToken();
2051 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2052 if (st2.countTokens() > 1)
2054 // This is the chain
2055 tmp2.addElement(st2.nextToken());
2056 seqstring = st2.nextToken();
2058 tmp.addElement(matcher == null ? (Sequence) alignFrame
2059 .getAlignViewport().getAlignment()
2060 .findName(seqstring) : matcher.findIdMatch(seqstring));
2063 seqs = new SequenceI[tmp.size()];
2065 if (tmp2.size() == tmp.size())
2067 chains = new String[tmp2.size()];
2068 tmp2.copyInto(chains);
2071 param = setProtocolState(param);
2073 if (// !jmolAvailable
2075 protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
2077 // Re: JAL-357 : the bug isn't a problem if we are using an
2079 // TODO: verify this Re:
2080 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2081 // This exception preserves the current behaviour where, even if
2082 // the local pdb file was identified in the class loader
2083 protocol = AppletFormatAdapter.URL; // this is probably NOT
2085 param = addProtocol(param); //
2092 for (int i = 0; i < seqs.length; i++)
2094 if (seqs[i] != null)
2096 ((Sequence) seqs[i]).addPDBId(pdb);
2097 StructureSelectionManager.getStructureSelectionManager(
2098 applet).registerPDBEntry(pdb);
2102 if (JalviewLite.debug)
2104 // this may not really be a problem but we give a warning
2107 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2113 if (!alignPdbStructures)
2115 alignFrame.newStructureView(applet, pdb, seqs, chains,
2120 pdbs.addElement(new Object[]
2121 { pdb, seqs, chains, new String(protocol) });
2127 } while (param != null || pdbFileCount < 10);
2128 if (pdbs.size() > 0)
2130 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2131 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2132 String[][] chains = new String[pdbs.size()][];
2133 String[] protocols = new String[pdbs.size()];
2134 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2136 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2137 pdb[pdbsi] = (PDBEntry) o[0];
2138 seqs[pdbsi] = (SequenceI[]) o[1];
2139 chains[pdbsi] = (String[]) o[2];
2140 protocols[pdbsi] = (String) o[3];
2142 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2150 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2156 protected boolean loadJnetFile(AlignFrame alignFrame)
2158 boolean result = false;
2159 String param = applet.getParameter("jnetfile");
2164 param = setProtocolState(param);
2165 JPredFile predictions = new JPredFile(param, protocol);
2166 JnetAnnotationMaker.add_annotation(predictions,
2167 alignFrame.viewport.getAlignment(), 0, false);
2168 // false == do not add sequence profile from concise output
2169 SequenceI repseq = alignFrame.viewport.getAlignment()
2171 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2172 ColumnSelection cs = new ColumnSelection();
2173 cs.hideInsertionsFor(repseq);
2174 alignFrame.viewport.setColumnSelection(cs);
2175 alignFrame.alignPanel.fontChanged();
2176 alignFrame.alignPanel.setScrollValues(0, 0);
2178 } catch (Exception ex)
2180 ex.printStackTrace();
2187 * Load annotations if specified by parameter. Returns true if loaded, else
2193 protected boolean loadAnnotations(AlignFrame alignFrame)
2195 boolean result = false;
2196 String param = applet.getParameter("annotations");
2199 param = setProtocolState(param);
2201 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2204 alignFrame.alignPanel.fontChanged();
2205 alignFrame.alignPanel.setScrollValues(0, 0);
2211 .println("Annotations were not added from annotation file '"
2219 * Load features file and view settings as specified by parameters. Returns
2220 * true if features were loaded, else false.
2225 protected boolean loadFeatures(AlignFrame alignFrame)
2227 boolean result = false;
2228 // ///////////////////////////
2229 // modify display of features
2230 // we do this before any features have been loaded, ensuring any hidden
2231 // groups are hidden when features first displayed
2233 // hide specific groups
2235 String param = applet.getParameter("hidefeaturegroups");
2238 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2239 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2241 // show specific groups
2242 param = applet.getParameter("showfeaturegroups");
2245 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2246 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2248 // and now load features
2249 param = applet.getParameter("features");
2252 param = setProtocolState(param);
2254 result = alignFrame.parseFeaturesFile(param, protocol);
2257 param = applet.getParameter("showFeatureSettings");
2258 if (param != null && param.equalsIgnoreCase(TRUE))
2260 alignFrame.viewport.setShowSequenceFeatures(true);
2261 new FeatureSettings(alignFrame.alignPanel);
2267 * Load a score file if specified by parameter. Returns true if file was
2268 * loaded, else false.
2272 protected boolean loadScoreFile(AlignFrame alignFrame)
2274 boolean result = false;
2275 String sScoreFile = applet.getParameter("scoreFile");
2276 if (sScoreFile != null && !"".equals(sScoreFile))
2283 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2285 result = alignFrame.loadScoreFile(sScoreFile);
2289 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2290 + sScoreFile + "')");
2292 } catch (Exception e)
2294 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2295 sScoreFile, e.getMessage());
2302 * Load a tree for the alignment if specified by parameter. Returns true if
2303 * a tree was loaded, else false.
2308 protected boolean loadTree(AlignFrame alignFrame)
2310 boolean result = false;
2311 String treeFile = applet.getParameter("tree");
2312 if (treeFile == null)
2314 treeFile = applet.getParameter("treeFile");
2317 if (treeFile != null)
2321 treeFile = setProtocolState(treeFile);
2322 NewickFile fin = new NewickFile(treeFile, protocol);
2325 if (fin.getTree() != null)
2327 alignFrame.loadTree(fin, treeFile);
2329 dbgMsg("Successfully imported tree.");
2333 dbgMsg("Tree parameter did not resolve to a valid tree.");
2335 } catch (Exception ex)
2337 ex.printStackTrace();
2344 * Discovers whether the given file is in the Applet Archive
2350 boolean inArchive(String file)
2352 // This might throw a security exception in certain browsers
2353 // Netscape Communicator for instance.
2356 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2359 System.err.println("Resource '" + file + "' was "
2360 + (rtn ? "" : "not") + " located by classloader.");
2363 } catch (Exception ex)
2365 System.out.println("Exception checking resources: " + file + " "
2372 * If the file is not already in URL format, tries to locate it by resolving
2378 String addProtocol(final String file)
2380 if (file.indexOf("://") == -1)
2383 * Try relative to document base
2385 String url = applet.resolveUrlForLocalOrAbsolute(file,
2391 System.err.println("Prepended document base for resource: '"
2398 * Try relative to codebase
2400 url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2405 System.err.println("Prepended codebase for resource: '" + file
2413 * Not resolved, leave unchanged
2419 * Returns true if an input stream can be opened on the specified URL, else
2425 private boolean urlExists(String url)
2427 InputStream is = null;
2430 is = new URL(url).openStream();
2435 } catch (Exception x)
2445 } catch (IOException e)
2456 * @return the default alignFrame acted on by the public applet methods. May
2457 * return null with an error message on System.err indicating the
2460 public AlignFrame getDefaultTargetFrame()
2462 if (currentAlignFrame != null)
2464 return currentAlignFrame;
2466 if (initialAlignFrame != null)
2468 return initialAlignFrame;
2471 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2476 * separator used for separatorList
2478 protected String separator = "" + ((char) 0x00AC); // the default used to be
2479 // '|' but many sequence
2480 // IDS include pipes.
2483 * set to enable the URL based javascript execution mechanism
2485 public boolean jsfallbackEnabled = false;
2488 * parse the string into a list
2491 * @return elements separated by separator
2493 public String[] separatorListToArray(String list)
2495 return separatorListToArray(list, separator);
2499 * parse the string into a list
2503 * @return elements separated by separator
2505 public String[] separatorListToArray(String list, String separator)
2507 // note separator local variable intentionally masks object field
2508 int seplen = separator.length();
2509 if (list == null || list.equals("") || list.equals(separator))
2513 java.util.Vector jv = new Vector();
2515 while ((pos = list.indexOf(separator, cp)) > cp)
2517 jv.addElement(list.substring(cp, pos));
2520 if (cp < list.length())
2522 String c = list.substring(cp);
2523 if (!c.equals(separator))
2530 String[] v = new String[jv.size()];
2531 for (int i = 0; i < v.length; i++)
2533 v[i] = (String) jv.elementAt(i);
2535 jv.removeAllElements();
2538 System.err.println("Array from '" + separator
2539 + "' separated List:\n" + v.length);
2540 for (int i = 0; i < v.length; i++)
2542 System.err.println("item " + i + " '" + v[i] + "'");
2549 System.err.println("Empty Array from '" + separator
2550 + "' separated List");
2556 * concatenate the list with separator
2559 * @return concatenated string
2561 public String arrayToSeparatorList(String[] list)
2563 return arrayToSeparatorList(list, separator);
2567 * concatenate the list with separator
2571 * @return concatenated string
2573 public String arrayToSeparatorList(String[] list, String separator)
2575 StringBuffer v = new StringBuffer();
2576 if (list != null && list.length > 0)
2578 for (int i = 0, iSize = list.length; i < iSize; i++)
2580 if (list[i] != null)
2584 v.append(separator);
2591 System.err.println("Returning '" + separator
2592 + "' separated List:\n");
2593 System.err.println(v);
2595 return v.toString();
2599 System.err.println("Returning empty '" + separator
2600 + "' separated List\n");
2602 return "" + separator;
2608 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2610 public String getFeatureGroups()
2612 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2613 .getFeatureGroups());
2621 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2624 public String getFeatureGroupsOn(AlignFrame alf)
2626 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2633 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2635 public String getFeatureGroupsOfState(boolean visible)
2637 return arrayToSeparatorList(getDefaultTargetFrame()
2638 .getFeatureGroupsOfState(visible));
2645 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2646 * .AlignFrame, boolean)
2648 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2650 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2656 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2657 * AlignFrame, java.lang.String, boolean)
2659 public void setFeatureGroupStateOn(final AlignFrame alf,
2660 final String groups, boolean state)
2662 final boolean st = state;// !(state==null || state.equals("") ||
2663 // state.toLowerCase().equals("false"));
2664 java.awt.EventQueue.invokeLater(new Runnable()
2669 alf.setFeatureGroupState(separatorListToArray(groups), st);
2677 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2680 public void setFeatureGroupState(String groups, boolean state)
2682 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2688 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2690 public String getSeparator()
2698 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2700 public void setSeparator(String separator)
2702 if (separator == null || separator.length() < 1)
2705 separator = "" + ((char) 0x00AC);
2707 this.separator = separator;
2710 System.err.println("Default Separator now: '" + separator + "'");
2715 * get boolean value of applet parameter 'name' and return default if
2716 * parameter is not set
2721 * the value to return otherwise
2722 * @return true or false
2724 public boolean getDefaultParameter(String name, boolean def)
2727 if ((stn = getParameter(name)) == null)
2731 if (stn.toLowerCase().equals(TRUE))
2741 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2742 * java.lang.String, java.lang.String, java.lang.String)
2744 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2745 String pdbEntryString, String pdbFile)
2747 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2750 protected void setAlignPdbStructures(boolean alignPdbStructures)
2752 this.alignPdbStructures = alignPdbStructures;
2755 public boolean isAlignPdbStructures()
2757 return alignPdbStructures;
2762 // callInitCallback();
2765 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2767 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2769 public void setJsMessageSet(String messageclass, String viewId,
2770 String[] colcommands)
2772 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2775 msgset = new Hashtable<String, String[]>();
2776 jsmessages.put(messageclass, msgset);
2778 msgset.put(viewId, colcommands);
2779 long[] l = new long[colcommands.length];
2780 for (int i = 0; i < colcommands.length; i++)
2782 l[i] = colcommands[i].hashCode();
2784 jshashes.put(messageclass + "|" + viewId, l);
2790 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2793 public String getJsMessage(String messageclass, String viewId)
2795 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2798 String[] msgs = msgset.get(viewId);
2801 for (int i = 0; i < msgs.length; i++)
2803 if (msgs[i] != null)
2815 public boolean isJsMessageSetChanged(String string, String string2,
2816 String[] colcommands)
2818 long[] l = jshashes.get(string + "|" + string2);
2819 if (l == null && colcommands != null)
2823 for (int i = 0; i < colcommands.length; i++)
2825 if (l[i] != colcommands[i].hashCode())
2833 private Vector jsExecQueue = new Vector();
2835 public Vector getJsExecQueue()
2840 public void setExecutor(JSFunctionExec jsFunctionExec2)
2842 jsFunctionExec = jsFunctionExec2;
2846 * return the given colour value parameter or the given default if parameter
2853 public Color getDefaultColourParameter(String colparam, Color defcolour)
2855 String colprop = getParameter(colparam);
2856 if (colprop == null || colprop.trim().length() == 0)
2860 Color col = ColourSchemeProperty.getAWTColorFromName(colprop);
2865 col = new UserColourScheme(colprop).findColour('A');
2866 } catch (Exception ex)
2868 System.err.println("Couldn't parse '" + colprop
2869 + "' as a colour for " + colparam);
2873 return (col == null) ? defcolour : col;
2877 public void openJalviewHelpUrl()
2879 String helpUrl = getParameter("jalviewhelpurl");
2880 if (helpUrl == null || helpUrl.trim().length() < 5)
2882 helpUrl = "http://www.jalview.org/help.html";
2884 showURL(helpUrl, "HELP");
2888 * form a complete URL given a path to a resource and a reference location on
2892 * - an absolute path on the same server as localref or a document
2893 * located relative to localref
2895 * - a URL on the same server as url
2896 * @return a complete URL for the resource located by url
2898 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2900 String codebase = localref.toString();
2901 if (url.indexOf("/") == 0)
2903 url = codebase.substring(0, codebase.length()
2904 - localref.getFile().length())
2909 url = localref + url;
2915 * open a URL in the browser - resolving it according to relative refs and
2916 * coping with javascript: protocol if necessary.
2921 public void showURL(String url, String target)
2925 if (url.indexOf(":") == -1)
2927 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2929 // Should really use docbase, not codebase.
2931 url = resolveUrlForLocalOrAbsolute(
2933 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2938 .println("Show url (prepended "
2940 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2948 System.err.println("Show url: " + url);
2951 if (url.indexOf("javascript:") == 0)
2953 // no target for the javascript context
2954 getAppletContext().showDocument(new java.net.URL(url));
2958 getAppletContext().showDocument(new java.net.URL(url), target);
2960 } catch (Exception ex)
2962 ex.printStackTrace();
2967 * bind structures in a viewer to any matching sequences in an alignFrame (use
2968 * sequenceIds to limit scope of search to specific sequences)
2972 * @param sequenceIds
2973 * @return TODO: consider making an exception structure for indicating when
2974 * binding fails public SequenceStructureBinding
2975 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2978 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2979 * alFrame.addStructureViewInstance(viewer,
2980 * separatorListToArray(sequenceIds)); } else { return
2981 * alFrame.addStructureViewInstance(viewer, null); } // return null; }