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.api.StructureSelectionManagerProvider;
24 import jalview.appletgui.AlignFrame;
25 import jalview.appletgui.AlignViewport;
26 import jalview.appletgui.EmbmenuFrame;
27 import jalview.appletgui.FeatureSettings;
28 import jalview.appletgui.SplitFrame;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.AlignmentOrder;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AnnotationFile;
38 import jalview.io.AppletFormatAdapter;
39 import jalview.io.FileParse;
40 import jalview.io.IdentifyFile;
41 import jalview.io.JPredFile;
42 import jalview.io.JnetAnnotationMaker;
43 import jalview.io.NewickFile;
44 import jalview.javascript.JSFunctionExec;
45 import jalview.javascript.JalviewLiteJsApi;
46 import jalview.javascript.JsCallBack;
47 import jalview.structure.SelectionListener;
48 import jalview.structure.StructureSelectionManager;
49 import jalview.util.MessageManager;
51 import java.applet.Applet;
52 import java.awt.Button;
53 import java.awt.Color;
54 import java.awt.Component;
55 import java.awt.EventQueue;
57 import java.awt.Frame;
58 import java.awt.Graphics;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.WindowAdapter;
61 import java.awt.event.WindowEvent;
62 import java.io.BufferedReader;
63 import java.io.IOException;
64 import java.io.InputStream;
65 import java.io.InputStreamReader;
67 import java.util.Hashtable;
68 import java.util.List;
69 import java.util.StringTokenizer;
70 import java.util.Vector;
72 import netscape.javascript.JSObject;
75 * Jalview Applet. Runs in Java 1.18 runtime
78 * @version $Revision: 1.92 $
80 public class JalviewLite extends Applet implements
81 StructureSelectionManagerProvider, JalviewLiteJsApi
84 private static final String TRUE = "true";
86 private static final String FALSE = "false";
88 public StructureSelectionManager getStructureSelectionManager()
90 return StructureSelectionManager.getStructureSelectionManager(this);
93 // /////////////////////////////////////////
94 // The following public methods maybe called
95 // externally, eg via javascript in HTML page
99 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
101 public String getSelectedSequences()
103 return getSelectedSequencesFrom(getDefaultTargetFrame());
109 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
111 public String getSelectedSequences(String sep)
113 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
120 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
123 public String getSelectedSequencesFrom(AlignFrame alf)
125 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
132 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
133 * .AlignFrame, java.lang.String)
135 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
137 StringBuffer result = new StringBuffer("");
138 if (sep == null || sep.length() == 0)
140 sep = separator; // "+0x00AC;
142 if (alf.viewport.getSelectionGroup() != null)
144 SequenceI[] seqs = alf.viewport.getSelectionGroup()
145 .getSequencesInOrder(alf.viewport.getAlignment());
147 for (int i = 0; i < seqs.length; i++)
149 result.append(seqs[i].getName());
154 return result.toString();
160 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
161 * java.lang.String, java.lang.String)
163 public void highlight(String sequenceId, String position,
164 String alignedPosition)
166 highlightIn(getDefaultTargetFrame(), sequenceId, position,
173 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
174 * java.lang.String, java.lang.String, java.lang.String)
176 public void highlightIn(final AlignFrame alf, final String sequenceId,
177 final String position, final String alignedPosition)
179 // TODO: could try to highlight in all alignments if alf==null
180 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
181 alf.viewport.getAlignment().getSequencesArray());
182 final SequenceI sq = matcher.findIdMatch(sequenceId);
188 apos = new Integer(position).intValue();
190 } catch (NumberFormatException ex)
194 final StructureSelectionManagerProvider me = this;
195 final int pos = apos;
196 // use vamsas listener to broadcast to all listeners in scope
197 if (alignedPosition != null
198 && (alignedPosition.trim().length() == 0 || alignedPosition
199 .toLowerCase().indexOf("false") > -1))
201 java.awt.EventQueue.invokeLater(new Runnable()
206 StructureSelectionManager.getStructureSelectionManager(me)
207 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
213 java.awt.EventQueue.invokeLater(new Runnable()
218 StructureSelectionManager.getStructureSelectionManager(me)
219 .mouseOverVamsasSequence(sq, pos, null);
229 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
232 public void select(String sequenceIds, String columns)
234 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
240 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
241 * java.lang.String, java.lang.String)
243 public void select(String sequenceIds, String columns, String sep)
245 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
251 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
252 * java.lang.String, java.lang.String)
254 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
256 selectIn(alf, sequenceIds, columns, separator);
262 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
263 * java.lang.String, java.lang.String, java.lang.String)
265 public void selectIn(final AlignFrame alf, String sequenceIds,
266 String columns, String sep)
268 if (sep == null || sep.length() == 0)
276 System.err.println("Selecting region using separator string '"
281 String[] ids = separatorListToArray(sequenceIds, sep);
282 String[] cols = separatorListToArray(columns, sep);
283 final SequenceGroup sel = new SequenceGroup();
284 final ColumnSelection csel = new ColumnSelection();
285 AlignmentI al = alf.viewport.getAlignment();
286 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
287 alf.viewport.getAlignment().getSequencesArray());
288 int start = 0, end = al.getWidth(), alw = al.getWidth();
289 boolean seqsfound = true;
290 if (ids != null && ids.length > 0)
293 for (int i = 0; i < ids.length; i++)
295 if (ids[i].trim().length() == 0)
299 SequenceI sq = matcher.findIdMatch(ids[i]);
303 sel.addSequence(sq, false);
307 boolean inseqpos = false;
308 if (cols != null && cols.length > 0)
310 boolean seset = false;
311 for (int i = 0; i < cols.length; i++)
313 String cl = cols[i].trim();
314 if (cl.length() == 0)
319 if ((p = cl.indexOf("-")) > -1)
321 int from = -1, to = -1;
324 from = new Integer(cl.substring(0, p)).intValue();
326 } catch (NumberFormatException ex)
329 .println("ERROR: Couldn't parse first integer in range element column selection string '"
330 + cl + "' - format is 'from-to'");
335 to = new Integer(cl.substring(p + 1)).intValue();
337 } catch (NumberFormatException ex)
340 .println("ERROR: Couldn't parse second integer in range element column selection string '"
341 + cl + "' - format is 'from-to'");
344 if (from >= 0 && to >= 0)
361 // comment to prevent range extension
371 for (int r = from; r <= to; r++)
373 if (r >= 0 && r < alw)
380 System.err.println("Range '" + cl + "' deparsed as [" + from
386 System.err.println("ERROR: Invalid Range '" + cl
387 + "' deparsed as [" + from + "," + to + "]");
395 r = new Integer(cl).intValue();
397 } catch (NumberFormatException ex)
399 if (cl.toLowerCase().equals("sequence"))
401 // we are in the dataset sequence's coordinate frame.
407 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
412 if (r >= 0 && r <= alw)
422 // comment to prevent range extension
435 System.err.println("Point selection '" + cl
436 + "' deparsed as [" + r + "]");
441 System.err.println("ERROR: Invalid Point selection '" + cl
442 + "' deparsed as [" + r + "]");
449 // we only propagate the selection when it was the null selection, or the
450 // given sequences were found in the alignment.
451 if (inseqpos && sel.getSize() > 0)
453 // assume first sequence provides reference frame ?
454 SequenceI rs = sel.getSequenceAt(0);
455 start = rs.findIndex(start);
456 end = rs.findIndex(end);
459 List<Integer> cs = csel.getSelected();
461 for (Integer selectedCol : cs)
463 csel.addElement(rs.findIndex(selectedCol));
467 sel.setStartRes(start);
469 EventQueue.invokeLater(new Runnable()
474 alf.select(sel, csel);
484 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
485 * String, java.lang.String)
487 public String getSelectedSequencesAsAlignment(String format, String suffix)
489 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
497 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
498 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
500 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
501 String format, String suffix)
505 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
506 if (alf.viewport.getSelectionGroup() != null)
508 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
509 // method now returns a full copy of sequence data
510 // TODO consider using getSequenceSelection instead here
511 String reply = new AppletFormatAdapter().formatSequences(format,
512 new Alignment(alf.viewport.getSelectionAsNewSequence()),
516 } catch (Exception ex)
518 ex.printStackTrace();
519 return "Error retrieving alignment in " + format + " format. ";
527 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
529 public String getAlignmentOrder()
531 return getAlignmentOrderFrom(getDefaultTargetFrame());
538 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
541 public String getAlignmentOrderFrom(AlignFrame alf)
543 return getAlignmentOrderFrom(alf, separator);
550 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
551 * , java.lang.String)
553 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
555 AlignmentI alorder = alf.getAlignViewport().getAlignment();
556 String[] order = new String[alorder.getHeight()];
557 for (int i = 0; i < order.length; i++)
559 order[i] = alorder.getSequenceAt(i).getName();
561 return arrayToSeparatorList(order);
567 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
570 public String orderBy(String order, String undoName)
572 return orderBy(order, undoName, separator);
578 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
579 * java.lang.String, java.lang.String)
581 public String orderBy(String order, String undoName, String sep)
583 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
590 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
591 * java.lang.String, java.lang.String, java.lang.String)
593 public String orderAlignmentBy(AlignFrame alf, String order,
594 String undoName, String sep)
596 String[] ids = separatorListToArray(order, sep);
597 SequenceI[] sqs = null;
598 if (ids != null && ids.length > 0)
600 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
601 alf.viewport.getAlignment().getSequencesArray());
603 sqs = new SequenceI[ids.length];
604 for (int i = 0; i < ids.length; i++)
606 if (ids[i].trim().length() == 0)
610 SequenceI sq = matcher.findIdMatch(ids[i]);
618 SequenceI[] sqq = new SequenceI[s];
619 System.arraycopy(sqs, 0, sqq, 0, s);
632 final AlignmentOrder aorder = new AlignmentOrder(sqs);
634 if (undoName != null && undoName.trim().length() == 0)
638 final String _undoName = undoName;
639 // TODO: deal with synchronization here: cannot raise any events until after
640 // this has returned.
641 return alf.sortBy(aorder, _undoName) ? TRUE : "";
647 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
649 public String getAlignment(String format)
651 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
658 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
661 public String getAlignmentFrom(AlignFrame alf, String format)
663 return getAlignmentFrom(alf, format, TRUE);
669 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
672 public String getAlignment(String format, String suffix)
674 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
681 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
682 * java.lang.String, java.lang.String)
684 public String getAlignmentFrom(AlignFrame alf, String format,
689 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
691 String reply = new AppletFormatAdapter().formatSequences(format,
692 alf.viewport.getAlignment(), seqlimits);
694 } catch (Exception ex)
696 ex.printStackTrace();
697 return "Error retrieving alignment in " + format + " format. ";
704 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
706 public void loadAnnotation(String annotation)
708 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
715 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
716 * , java.lang.String)
718 public void loadAnnotationFrom(AlignFrame alf, String annotation)
720 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
721 annotation, AppletFormatAdapter.PASTE))
723 alf.alignPanel.fontChanged();
724 alf.alignPanel.setScrollValues(0, 0);
728 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
735 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
737 public void loadFeatures(String features, boolean autoenabledisplay)
739 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
746 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
747 * , java.lang.String)
749 public boolean loadFeaturesFrom(AlignFrame alf, String features,
750 boolean autoenabledisplay)
752 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
759 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
761 public String getFeatures(String format)
763 return getFeaturesFrom(getDefaultTargetFrame(), format);
770 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
773 public String getFeaturesFrom(AlignFrame alf, String format)
775 return alf.outputFeatures(false, format);
781 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
783 public String getAnnotation()
785 return getAnnotationFrom(getDefaultTargetFrame());
792 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
795 public String getAnnotationFrom(AlignFrame alf)
797 return alf.outputAnnotations(false);
803 * @see jalview.bin.JalviewLiteJsApi#newView()
805 public AlignFrame newView()
807 return newViewFrom(getDefaultTargetFrame());
813 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
815 public AlignFrame newView(String name)
817 return newViewFrom(getDefaultTargetFrame(), name);
823 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
825 public AlignFrame newViewFrom(AlignFrame alf)
827 return alf.newView(null);
833 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
836 public AlignFrame newViewFrom(AlignFrame alf, String name)
838 return alf.newView(name);
844 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
847 public AlignFrame loadAlignment(String text, String title)
849 AlignmentI al = null;
851 String format = new IdentifyFile().Identify(text,
852 AppletFormatAdapter.PASTE);
855 al = new AppletFormatAdapter().readFile(text,
856 AppletFormatAdapter.PASTE, format);
857 if (al.getHeight() > 0)
859 return new AlignFrame(al, this, title, false);
861 } catch (java.io.IOException ex)
863 ex.printStackTrace();
871 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
873 public void setMouseoverListener(String listener)
875 setMouseoverListener(currentAlignFrame, listener);
878 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
884 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
885 * , java.lang.String)
887 public void setMouseoverListener(AlignFrame af, String listener)
889 if (listener != null)
891 listener = listener.trim();
892 if (listener.length() == 0)
895 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
899 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
901 javascriptListeners.addElement(mol);
902 StructureSelectionManager.getStructureSelectionManager(this)
903 .addStructureViewerListener(mol);
906 System.err.println("Added a mouseover listener for "
907 + ((af == null) ? "All frames" : "Just views for "
908 + af.getAlignViewport().getSequenceSetId()));
909 System.err.println("There are now " + javascriptListeners.size()
910 + " listeners in total.");
917 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
919 public void setSelectionListener(String listener)
921 setSelectionListener(null, listener);
928 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
929 * , java.lang.String)
931 public void setSelectionListener(AlignFrame af, String listener)
933 if (listener != null)
935 listener = listener.trim();
936 if (listener.length() == 0)
939 .println("jalview Javascript error: Ignoring empty function for selection listener.");
943 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
945 javascriptListeners.addElement(mol);
946 StructureSelectionManager.getStructureSelectionManager(this)
947 .addSelectionListener(mol);
950 System.err.println("Added a selection listener for "
951 + ((af == null) ? "All frames" : "Just views for "
952 + af.getAlignViewport().getSequenceSetId()));
953 System.err.println("There are now " + javascriptListeners.size()
954 + " listeners in total.");
961 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
964 public void setStructureListener(String listener, String modelSet)
966 if (listener != null)
968 listener = listener.trim();
969 if (listener.length() == 0)
972 .println("jalview Javascript error: Ignoring empty function for selection listener.");
976 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
977 this, listener, separatorListToArray(modelSet));
978 javascriptListeners.addElement(mol);
979 StructureSelectionManager.getStructureSelectionManager(this)
980 .addStructureViewerListener(mol);
983 System.err.println("Added a javascript structure viewer listener '"
985 System.err.println("There are now " + javascriptListeners.size()
986 + " listeners in total.");
994 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
995 * .AlignFrame, java.lang.String)
997 public void removeJavascriptListener(AlignFrame af, String listener)
999 if (listener != null)
1001 listener = listener.trim();
1002 if (listener.length() == 0)
1007 boolean rprt = false;
1008 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1010 Object lstn = javascriptListeners.elementAt(ms);
1011 JsCallBack lstner = (JsCallBack) lstn;
1012 if ((af == null || lstner.getAlignFrame() == af)
1013 && (listener == null || lstner.getListenerFunction().equals(
1016 javascriptListeners.removeElement(lstner);
1018 if (lstner instanceof SelectionListener)
1020 StructureSelectionManager.getStructureSelectionManager(this)
1021 .removeSelectionListener((SelectionListener) lstner);
1025 StructureSelectionManager.getStructureSelectionManager(this)
1026 .removeStructureViewerListener(lstner, null);
1031 System.err.println("Removed listener '" + listener + "'");
1041 System.err.println("There are now " + javascriptListeners.size()
1042 + " listeners in total.");
1048 System.err.println("Applet " + getName() + " stop().");
1052 public void destroy()
1054 System.err.println("Applet " + getName() + " destroy().");
1058 private void tidyUp()
1061 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1062 && currentAlignFrame.viewport.applet != null)
1064 AlignViewport av = currentAlignFrame.viewport;
1065 currentAlignFrame.closeMenuItem_actionPerformed();
1067 currentAlignFrame = null;
1069 if (javascriptListeners != null)
1071 while (javascriptListeners.size() > 0)
1073 jalview.javascript.JSFunctionExec mol = javascriptListeners
1075 javascriptListeners.removeElement(mol);
1076 if (mol instanceof SelectionListener)
1078 StructureSelectionManager.getStructureSelectionManager(this)
1079 .removeSelectionListener((SelectionListener) mol);
1083 StructureSelectionManager.getStructureSelectionManager(this)
1084 .removeStructureViewerListener(mol, null);
1089 if (jsFunctionExec != null)
1091 jsFunctionExec.stopQueue();
1092 jsFunctionExec.jvlite = null;
1094 initialAlignFrame = null;
1095 jsFunctionExec = null;
1096 javascriptListeners = null;
1097 StructureSelectionManager.release(this);
1100 private jalview.javascript.JSFunctionExec jsFunctionExec;
1105 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1106 * java.lang.String, java.lang.String)
1108 public void mouseOverStructure(final String pdbResNum,
1109 final String chain, final String pdbfile)
1111 final StructureSelectionManagerProvider me = this;
1112 java.awt.EventQueue.invokeLater(new Runnable()
1119 StructureSelectionManager.getStructureSelectionManager(me)
1120 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1124 System.err.println("mouseOver for '" + pdbResNum
1125 + "' in chain '" + chain + "' in structure '" + pdbfile
1128 } catch (NumberFormatException e)
1130 System.err.println("Ignoring invalid residue number string '"
1142 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1143 * java.lang.String, java.lang.String)
1145 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1146 final String leftHandColumn)
1148 java.awt.EventQueue.invokeLater(new Runnable()
1155 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1156 leftHandColumn).intValue());
1158 } catch (Exception ex)
1160 System.err.println("Couldn't parse integer arguments (topRow='"
1161 + topRow + "' and leftHandColumn='" + leftHandColumn
1163 ex.printStackTrace();
1173 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1174 * .AlignFrame, java.lang.String)
1177 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1180 java.awt.EventQueue.invokeLater(new Runnable()
1187 alf.scrollToRow(new Integer(topRow).intValue());
1189 } catch (Exception ex)
1191 System.err.println("Couldn't parse integer arguments (topRow='"
1193 ex.printStackTrace();
1204 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1205 * .AlignFrame, java.lang.String)
1208 public void scrollViewToColumnIn(final AlignFrame alf,
1209 final String leftHandColumn)
1211 java.awt.EventQueue.invokeLater(new Runnable()
1219 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1221 } catch (Exception ex)
1224 .println("Couldn't parse integer arguments (leftHandColumn='"
1225 + leftHandColumn + "')");
1226 ex.printStackTrace();
1233 // //////////////////////////////////////////////
1234 // //////////////////////////////////////////////
1236 public static int lastFrameX = 200;
1238 public static int lastFrameY = 200;
1240 boolean fileFound = true;
1242 String file = "No file";
1244 String file2 = null;
1246 Button launcher = new Button(
1247 MessageManager.getString("label.start_jalview"));
1250 * The currentAlignFrame is static, it will change if and when the user
1251 * selects a new window. Note that it will *never* point back to the embedded
1252 * AlignFrame if the applet is started as embedded on the page and then
1253 * afterwards a new view is created.
1255 public AlignFrame currentAlignFrame = null;
1258 * This is the first frame to be displayed, and does not change. API calls
1259 * will default to this instance if currentAlignFrame is null.
1261 AlignFrame initialAlignFrame = null;
1263 boolean embedded = false;
1265 private boolean checkForJmol = true;
1267 private boolean checkedForJmol = false; // ensure we don't check for jmol
1269 // every time the app is re-inited
1271 public boolean jmolAvailable = false;
1273 private boolean alignPdbStructures = false;
1276 * use an external structure viewer exclusively (no jmols or MCViews will be
1277 * opened by JalviewLite itself)
1279 public boolean useXtrnalSviewer = false;
1281 public static boolean debug = false;
1283 static String builddate = null, version = null, installation = null;
1285 private static void initBuildDetails()
1287 if (builddate == null)
1289 builddate = "unknown";
1291 installation = "Webstart";
1292 java.net.URL url = JalviewLite.class
1293 .getResource("/.build_properties");
1298 BufferedReader reader = new BufferedReader(new InputStreamReader(
1301 while ((line = reader.readLine()) != null)
1303 if (line.indexOf("VERSION") > -1)
1305 version = line.substring(line.indexOf("=") + 1);
1307 if (line.indexOf("BUILD_DATE") > -1)
1309 builddate = line.substring(line.indexOf("=") + 1);
1311 if (line.indexOf("INSTALLATION") > -1)
1313 installation = line.substring(line.indexOf("=") + 1);
1316 } catch (Exception ex)
1318 ex.printStackTrace();
1324 public static String getBuildDate()
1330 public static String getInstallation()
1333 return installation;
1336 public static String getVersion()
1342 // public JSObject scriptObject = null;
1345 * init method for Jalview Applet
1349 // remove any handlers that might be hanging around from an earlier instance
1354 System.err.println("Applet context is '"
1355 + getAppletContext().getClass().toString() + "'");
1357 JSObject scriptObject = JSObject.getWindow(this);
1358 if (debug && scriptObject != null)
1360 System.err.println("Applet has Javascript callback support.");
1363 } catch (Exception ex)
1366 .println("Warning: No JalviewLite javascript callbacks available.");
1369 ex.printStackTrace();
1373 * turn on extra applet debugging
1375 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1379 System.err.println("JalviewLite Version " + getVersion());
1380 System.err.println("Build Date : " + getBuildDate());
1381 System.err.println("Installation : " + getInstallation());
1384 String externalsviewer = getParameter("externalstructureviewer");
1385 if (externalsviewer != null)
1387 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1391 * if true disable the check for jmol
1393 String chkforJmol = getParameter("nojmol");
1394 if (chkforJmol != null)
1396 checkForJmol = !chkforJmol.equals(TRUE);
1399 * get the separator parameter if present
1401 String sep = getParameter("separator");
1404 if (sep.length() > 0)
1409 System.err.println("Separator set to '" + separator + "'");
1414 throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
1420 String param = getParameter("RGB");
1426 r = Integer.parseInt(param.substring(0, 2), 16);
1427 g = Integer.parseInt(param.substring(2, 4), 16);
1428 b = Integer.parseInt(param.substring(4, 6), 16);
1429 } catch (Exception ex)
1436 param = getParameter("label");
1439 launcher.setLabel(param);
1442 setBackground(new Color(r, g, b));
1444 file = getParameter("file");
1448 // Maybe the sequences are added as parameters
1449 StringBuffer data = new StringBuffer("PASTE");
1451 while ((file = getParameter("sequence" + i)) != null)
1453 data.append(file.toString() + "\n");
1456 if (data.length() > 5)
1458 file = data.toString();
1461 if (TRUE.equalsIgnoreCase(getParameter("enableSplitFrame")))
1463 file2 = getParameter("file2");
1466 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
1469 LoadingThread loader = new LoadingThread(file, file2, this);
1472 else if (file != null)
1475 * Start the applet immediately or show a button to start it
1477 if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
1479 LoadingThread loader = new LoadingThread(file, file2, this);
1485 launcher.addActionListener(new java.awt.event.ActionListener()
1487 public void actionPerformed(ActionEvent e)
1489 LoadingThread loader = new LoadingThread(file, file2,
1498 // jalview initialisation with no alignment. loadAlignment() method can
1499 // still be called to open new alignments.
1506 private void initLiveConnect()
1508 // try really hard to get the liveConnect thing working
1509 boolean notFailed = false;
1511 while (!notFailed && tries < 10)
1515 System.err.println("LiveConnect request thread going to sleep.");
1519 Thread.sleep(700 * (1 + tries));
1520 } catch (InterruptedException q)
1526 System.err.println("LiveConnect request thread woken up.");
1530 JSObject scriptObject = JSObject.getWindow(this);
1531 if (scriptObject.eval("navigator") != null)
1535 } catch (Exception jsex)
1537 System.err.println("Attempt " + tries
1538 + " to access LiveConnect javascript failed.");
1543 private void callInitCallback()
1545 String initjscallback = getParameter("oninit");
1546 if (initjscallback == null)
1550 initjscallback = initjscallback.trim();
1551 if (initjscallback.length() > 0)
1553 JSObject scriptObject = null;
1556 scriptObject = JSObject.getWindow(this);
1557 } catch (Exception ex)
1561 // try really hard to let the browser plugin know we want liveconnect
1564 if (scriptObject != null)
1568 // do onInit with the JS executor thread
1569 new JSFunctionExec(this).executeJavascriptFunction(true,
1570 initjscallback, null, "Calling oninit callback '"
1571 + initjscallback + "'.");
1572 } catch (Exception e)
1574 System.err.println("Exception when executing _oninit callback '"
1575 + initjscallback + "'.");
1576 e.printStackTrace();
1581 System.err.println("Not executing _oninit callback '"
1582 + initjscallback + "' - no scripting allowed.");
1588 * Initialises and displays a new java.awt.Frame
1591 * java.awt.Frame to be displayed
1593 * title of new frame
1595 * width if new frame
1597 * height of new frame
1599 public static void addFrame(final Frame frame, String title, int width,
1602 frame.setLocation(lastFrameX, lastFrameY);
1605 frame.setSize(width, height);
1606 frame.setTitle(title);
1607 frame.addWindowListener(new WindowAdapter()
1609 public void windowClosing(WindowEvent e)
1611 if (frame instanceof AlignFrame)
1613 AlignViewport vp = ((AlignFrame) frame).viewport;
1614 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1615 if (vp.applet.currentAlignFrame == frame)
1617 vp.applet.currentAlignFrame = null;
1625 if (frame instanceof EmbmenuFrame)
1627 ((EmbmenuFrame) frame).destroyMenus();
1629 frame.setMenuBar(null);
1633 public void windowActivated(WindowEvent e)
1635 if (frame instanceof AlignFrame)
1637 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1640 System.err.println("Activated window " + frame);
1644 super.windowActivated(e);
1647 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1650 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1653 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1654 * frame) { currentAlignFrame = null; if (debug) {
1655 * System.err.println("Deactivated window "+frame); } }
1656 * super.windowDeactivated(e); }
1659 frame.setVisible(true);
1663 * This paints the background surrounding the "Launch Jalview button" <br>
1665 * If file given in parameter not found, displays error message
1670 public void paint(Graphics g)
1674 g.setColor(new Color(200, 200, 200));
1675 g.setColor(Color.cyan);
1676 g.fillRect(0, 0, getSize().width, getSize().height);
1677 g.setColor(Color.red);
1679 MessageManager.getString("label.jalview_cannot_open_file"),
1681 g.drawString("\"" + file + "\"", 5, 30);
1685 g.setColor(Color.black);
1686 g.setFont(new Font("Arial", Font.BOLD, 24));
1687 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1688 getSize().height / 2 - 30);
1689 g.drawString(MessageManager.getString("label.loading_data") + "...",
1690 50, getSize().height / 2);
1695 * get all components associated with the applet of the given type
1700 public Vector getAppletWindow(Class class1)
1702 Vector wnds = new Vector();
1703 Component[] cmp = getComponents();
1706 for (int i = 0; i < cmp.length; i++)
1708 if (class1.isAssignableFrom(cmp[i].getClass()))
1710 wnds.addElement(cmp);
1717 class LoadJmolThread extends Thread
1719 private boolean running = false;
1723 if (running || checkedForJmol)
1732 if (!System.getProperty("java.version").startsWith("1.1"))
1734 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1735 jmolAvailable = true;
1740 .println("Jmol not available - Using MCview for structures");
1742 } catch (java.lang.ClassNotFoundException ex)
1748 jmolAvailable = false;
1752 .println("Skipping Jmol check. Will use MCView (probably)");
1755 checkedForJmol = true;
1759 public boolean notFinished()
1761 return running || !checkedForJmol;
1765 class LoadingThread extends Thread
1768 * State variable: protocol for access to file source
1772 String _file; // alignment file or URL spec
1774 String _file2; // second alignment file or URL spec
1778 private void dbgMsg(String msg)
1780 if (JalviewLite.debug)
1782 System.err.println(msg);
1787 * update the protocol state variable for accessing the datasource located
1791 * @return possibly updated datasource string
1793 public String setProtocolState(String file)
1795 if (file.startsWith("PASTE"))
1797 file = file.substring(5);
1798 protocol = AppletFormatAdapter.PASTE;
1800 else if (inArchive(file))
1802 protocol = AppletFormatAdapter.CLASSLOADER;
1806 file = addProtocol(file);
1807 protocol = AppletFormatAdapter.URL;
1809 dbgMsg("Protocol identified as '" + protocol + "'");
1813 public LoadingThread(String file, String file2, JalviewLite _applet)
1816 this._file2 = file2;
1822 LoadJmolThread jmolchecker = new LoadJmolThread();
1823 jmolchecker.start();
1824 while (jmolchecker.notFinished())
1826 // wait around until the Jmol check is complete.
1830 } catch (Exception e)
1835 // applet.callInitCallback();
1839 * Load the alignment and any related files as specified by applet
1842 private void startLoading()
1844 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1846 dbgMsg("Loading started.");
1848 AlignFrame newAlignFrame = readAlignment(_file);
1849 AlignFrame newAlignFrame2 = readAlignment(_file2);
1850 if (newAlignFrame != null)
1852 addToDisplay(newAlignFrame, newAlignFrame2);
1853 loadTree(newAlignFrame);
1855 loadScoreFile(newAlignFrame);
1857 loadFeatures(newAlignFrame);
1859 loadAnnotations(newAlignFrame);
1861 loadJnetFile(newAlignFrame);
1863 loadPdbFiles(newAlignFrame);
1868 applet.remove(launcher);
1875 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1880 public void addToDisplay(AlignFrame af, AlignFrame af2)
1884 af.addToDisplay(embedded);
1888 SplitFrame sf = new SplitFrame(af, af2);
1889 sf.addToDisplay(embedded, JalviewLite.this);
1894 * Read the alignment file (from URL, text 'paste', or archive by
1899 protected AlignFrame readAlignment(String fileParam)
1901 if (fileParam == null)
1905 String resolvedFile = setProtocolState(fileParam);
1906 String format = new IdentifyFile().Identify(resolvedFile, protocol);
1907 dbgMsg("File identified as '" + format + "'");
1908 AlignmentI al = null;
1911 al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
1912 if ((al != null) && (al.getHeight() > 0))
1914 dbgMsg("Successfully loaded file.");
1915 al.setDataset(null);
1916 AlignFrame newAlignFrame = new AlignFrame(al, applet,
1917 resolvedFile, embedded, false);
1918 newAlignFrame.setTitle(resolvedFile);
1919 if (initialAlignFrame == null)
1921 initialAlignFrame = newAlignFrame;
1923 // update the focus.
1924 currentAlignFrame = newAlignFrame;
1926 if (protocol == AppletFormatAdapter.PASTE)
1928 newAlignFrame.setTitle(MessageManager.formatMessage(
1929 "label.sequences_from", new Object[]
1930 { applet.getDocumentBase().toString() }));
1933 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1934 "label.successfully_loaded_file", new Object[]
1937 return newAlignFrame;
1939 } catch (java.io.IOException ex)
1941 dbgMsg("File load exception.");
1942 ex.printStackTrace();
1947 FileParse fp = new FileParse(resolvedFile, protocol);
1949 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
1951 while ((ln = fp.nextLine()) != null)
1955 dbgMsg(">>>Dump finished.");
1956 } catch (Exception e)
1959 .println("Exception when trying to dump the content of the file parameter.");
1960 e.printStackTrace();
1968 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
1974 protected boolean loadPdbFiles(AlignFrame alignFrame)
1976 boolean result = false;
1978 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
1979 * related to JAL-434
1982 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1985 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1988 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1990 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1993 int pdbFileCount = 0;
1994 // Accumulate pdbs here if they are heading for the same view (if
1995 // alignPdbStructures is true)
1996 Vector pdbs = new Vector();
1997 // create a lazy matcher if we're asked to
1998 jalview.analysis.SequenceIdMatcher matcher = (applet
1999 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2000 alignFrame.getAlignViewport().getAlignment()
2001 .getSequencesArray()) : null;
2006 if (pdbFileCount > 0)
2008 param = applet.getParameter("PDBFILE" + pdbFileCount);
2012 param = applet.getParameter("PDBFILE");
2017 PDBEntry pdb = new PDBEntry();
2020 SequenceI[] seqs = null;
2021 String[] chains = null;
2023 StringTokenizer st = new StringTokenizer(param, " ");
2025 if (st.countTokens() < 2)
2027 String sequence = applet.getParameter("PDBSEQ");
2028 if (sequence != null)
2030 seqs = new SequenceI[]
2031 { matcher == null ? (Sequence) alignFrame.getAlignViewport()
2032 .getAlignment().findName(sequence) : matcher
2033 .findIdMatch(sequence) };
2039 param = st.nextToken();
2040 Vector tmp = new Vector();
2041 Vector tmp2 = new Vector();
2043 while (st.hasMoreTokens())
2045 seqstring = st.nextToken();
2046 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2047 if (st2.countTokens() > 1)
2049 // This is the chain
2050 tmp2.addElement(st2.nextToken());
2051 seqstring = st2.nextToken();
2053 tmp.addElement(matcher == null ? (Sequence) alignFrame
2054 .getAlignViewport().getAlignment()
2055 .findName(seqstring) : matcher.findIdMatch(seqstring));
2058 seqs = new SequenceI[tmp.size()];
2060 if (tmp2.size() == tmp.size())
2062 chains = new String[tmp2.size()];
2063 tmp2.copyInto(chains);
2066 param = setProtocolState(param);
2068 if (// !jmolAvailable
2070 protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
2072 // Re: JAL-357 : the bug isn't a problem if we are using an
2074 // TODO: verify this Re:
2075 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2076 // This exception preserves the current behaviour where, even if
2077 // the local pdb file was identified in the class loader
2078 protocol = AppletFormatAdapter.URL; // this is probably NOT
2080 param = addProtocol(param); //
2087 for (int i = 0; i < seqs.length; i++)
2089 if (seqs[i] != null)
2091 ((Sequence) seqs[i]).addPDBId(pdb);
2092 StructureSelectionManager.getStructureSelectionManager(
2093 applet).registerPDBEntry(pdb);
2097 if (JalviewLite.debug)
2099 // this may not really be a problem but we give a warning
2102 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2108 if (!alignPdbStructures)
2110 alignFrame.newStructureView(applet, pdb, seqs, chains,
2115 pdbs.addElement(new Object[]
2116 { pdb, seqs, chains, new String(protocol) });
2122 } while (param != null || pdbFileCount < 10);
2123 if (pdbs.size() > 0)
2125 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2126 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2127 String[][] chains = new String[pdbs.size()][];
2128 String[] protocols = new String[pdbs.size()];
2129 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2131 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2132 pdb[pdbsi] = (PDBEntry) o[0];
2133 seqs[pdbsi] = (SequenceI[]) o[1];
2134 chains[pdbsi] = (String[]) o[2];
2135 protocols[pdbsi] = (String) o[3];
2137 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2145 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2151 protected boolean loadJnetFile(AlignFrame alignFrame)
2153 boolean result = false;
2154 String param = applet.getParameter("jnetfile");
2159 param = setProtocolState(param);
2160 JPredFile predictions = new JPredFile(param, protocol);
2161 JnetAnnotationMaker.add_annotation(predictions,
2162 alignFrame.viewport.getAlignment(), 0, false);
2163 // false == do not add sequence profile from concise output
2164 SequenceI repseq = alignFrame.viewport.getAlignment()
2166 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2167 ColumnSelection cs = new ColumnSelection();
2168 cs.hideInsertionsFor(repseq);
2169 alignFrame.viewport.setColumnSelection(cs);
2170 alignFrame.alignPanel.fontChanged();
2171 alignFrame.alignPanel.setScrollValues(0, 0);
2173 } catch (Exception ex)
2175 ex.printStackTrace();
2182 * Load annotations if specified by parameter. Returns true if loaded, else
2188 protected boolean loadAnnotations(AlignFrame alignFrame)
2190 boolean result = false;
2191 String param = applet.getParameter("annotations");
2194 param = setProtocolState(param);
2196 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2199 alignFrame.alignPanel.fontChanged();
2200 alignFrame.alignPanel.setScrollValues(0, 0);
2206 .println("Annotations were not added from annotation file '"
2214 * Load features file and view settings as specified by parameters. Returns
2215 * true if features were loaded, else false.
2220 protected boolean loadFeatures(AlignFrame alignFrame)
2222 boolean result = false;
2223 // ///////////////////////////
2224 // modify display of features
2225 // we do this before any features have been loaded, ensuring any hidden
2226 // groups are hidden when features first displayed
2228 // hide specific groups
2230 String param = applet.getParameter("hidefeaturegroups");
2233 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2234 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2236 // show specific groups
2237 param = applet.getParameter("showfeaturegroups");
2240 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2241 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2243 // and now load features
2244 param = applet.getParameter("features");
2247 param = setProtocolState(param);
2249 result = alignFrame.parseFeaturesFile(param, protocol);
2252 param = applet.getParameter("showFeatureSettings");
2253 if (param != null && param.equalsIgnoreCase(TRUE))
2255 alignFrame.viewport.setShowSequenceFeatures(true);
2256 new FeatureSettings(alignFrame.alignPanel);
2262 * Load a score file if specified by parameter. Returns true if file was
2263 * loaded, else false.
2267 protected boolean loadScoreFile(AlignFrame alignFrame)
2269 boolean result = false;
2270 String sScoreFile = applet.getParameter("scoreFile");
2271 if (sScoreFile != null && !"".equals(sScoreFile))
2278 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2280 result = alignFrame.loadScoreFile(sScoreFile);
2284 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2285 + sScoreFile + "')");
2287 } catch (Exception e)
2289 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2290 sScoreFile, e.getMessage());
2297 * Load a tree for the alignment if specified by parameter. Returns true if
2298 * a tree was loaded, else false.
2303 protected boolean loadTree(AlignFrame alignFrame)
2305 boolean result = false;
2306 String treeFile = applet.getParameter("tree");
2307 if (treeFile == null)
2309 treeFile = applet.getParameter("treeFile");
2312 if (treeFile != null)
2316 treeFile = setProtocolState(treeFile);
2317 NewickFile fin = new NewickFile(treeFile, protocol);
2320 if (fin.getTree() != null)
2322 alignFrame.loadTree(fin, treeFile);
2324 dbgMsg("Successfully imported tree.");
2328 dbgMsg("Tree parameter did not resolve to a valid tree.");
2330 } catch (Exception ex)
2332 ex.printStackTrace();
2339 * Discovers whether the given file is in the Applet Archive
2345 boolean inArchive(String file)
2347 // This might throw a security exception in certain browsers
2348 // Netscape Communicator for instance.
2351 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2354 System.err.println("Resource '" + file + "' was "
2355 + (rtn ? "" : "not") + " located by classloader.");
2358 } catch (Exception ex)
2360 System.out.println("Exception checking resources: " + file + " "
2367 * If the file is not already in URL format, tries to locate it by resolving
2373 String addProtocol(final String file)
2375 if (file.indexOf("://") == -1)
2378 * Try relative to document base
2380 String url = applet.resolveUrlForLocalOrAbsolute(file,
2386 System.err.println("Prepended document base for resource: '"
2393 * Try relative to codebase
2395 url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2400 System.err.println("Prepended codebase for resource: '" + file
2408 * Not resolved, leave unchanged
2414 * Returns true if an input stream can be opened on the specified URL, else
2420 private boolean urlExists(String url)
2422 InputStream is = null;
2425 is = new URL(url).openStream();
2430 } catch (Exception x)
2440 } catch (IOException e)
2451 * @return the default alignFrame acted on by the public applet methods. May
2452 * return null with an error message on System.err indicating the
2455 public AlignFrame getDefaultTargetFrame()
2457 if (currentAlignFrame != null)
2459 return currentAlignFrame;
2461 if (initialAlignFrame != null)
2463 return initialAlignFrame;
2466 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2471 * separator used for separatorList
2473 protected String separator = "" + ((char) 0x00AC); // the default used to be
2474 // '|' but many sequence
2475 // IDS include pipes.
2478 * set to enable the URL based javascript execution mechanism
2480 public boolean jsfallbackEnabled = false;
2483 * parse the string into a list
2486 * @return elements separated by separator
2488 public String[] separatorListToArray(String list)
2490 return separatorListToArray(list, separator);
2494 * parse the string into a list
2498 * @return elements separated by separator
2500 public String[] separatorListToArray(String list, String separator)
2502 // note separator local variable intentionally masks object field
2503 int seplen = separator.length();
2504 if (list == null || list.equals("") || list.equals(separator))
2508 java.util.Vector jv = new Vector();
2510 while ((pos = list.indexOf(separator, cp)) > cp)
2512 jv.addElement(list.substring(cp, pos));
2515 if (cp < list.length())
2517 String c = list.substring(cp);
2518 if (!c.equals(separator))
2525 String[] v = new String[jv.size()];
2526 for (int i = 0; i < v.length; i++)
2528 v[i] = (String) jv.elementAt(i);
2530 jv.removeAllElements();
2533 System.err.println("Array from '" + separator
2534 + "' separated List:\n" + v.length);
2535 for (int i = 0; i < v.length; i++)
2537 System.err.println("item " + i + " '" + v[i] + "'");
2544 System.err.println("Empty Array from '" + separator
2545 + "' separated List");
2551 * concatenate the list with separator
2554 * @return concatenated string
2556 public String arrayToSeparatorList(String[] list)
2558 return arrayToSeparatorList(list, separator);
2562 * concatenate the list with separator
2566 * @return concatenated string
2568 public String arrayToSeparatorList(String[] list, String separator)
2570 StringBuffer v = new StringBuffer();
2571 if (list != null && list.length > 0)
2573 for (int i = 0, iSize = list.length; i < iSize; i++)
2575 if (list[i] != null)
2579 v.append(separator);
2586 System.err.println("Returning '" + separator
2587 + "' separated List:\n");
2588 System.err.println(v);
2590 return v.toString();
2594 System.err.println("Returning empty '" + separator
2595 + "' separated List\n");
2597 return "" + separator;
2603 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2605 public String getFeatureGroups()
2607 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2608 .getFeatureGroups());
2616 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2619 public String getFeatureGroupsOn(AlignFrame alf)
2621 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2628 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2630 public String getFeatureGroupsOfState(boolean visible)
2632 return arrayToSeparatorList(getDefaultTargetFrame()
2633 .getFeatureGroupsOfState(visible));
2640 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2641 * .AlignFrame, boolean)
2643 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2645 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2651 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2652 * AlignFrame, java.lang.String, boolean)
2654 public void setFeatureGroupStateOn(final AlignFrame alf,
2655 final String groups, boolean state)
2657 final boolean st = state;// !(state==null || state.equals("") ||
2658 // state.toLowerCase().equals("false"));
2659 java.awt.EventQueue.invokeLater(new Runnable()
2664 alf.setFeatureGroupState(separatorListToArray(groups), st);
2672 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2675 public void setFeatureGroupState(String groups, boolean state)
2677 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2683 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2685 public String getSeparator()
2693 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2695 public void setSeparator(String separator)
2697 if (separator == null || separator.length() < 1)
2700 separator = "" + ((char) 0x00AC);
2702 this.separator = separator;
2705 System.err.println("Default Separator now: '" + separator + "'");
2710 * get boolean value of applet parameter 'name' and return default if
2711 * parameter is not set
2716 * the value to return otherwise
2717 * @return true or false
2719 public boolean getDefaultParameter(String name, boolean def)
2722 if ((stn = getParameter(name)) == null)
2726 if (stn.toLowerCase().equals(TRUE))
2736 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2737 * java.lang.String, java.lang.String, java.lang.String)
2739 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2740 String pdbEntryString, String pdbFile)
2742 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2745 protected void setAlignPdbStructures(boolean alignPdbStructures)
2747 this.alignPdbStructures = alignPdbStructures;
2750 public boolean isAlignPdbStructures()
2752 return alignPdbStructures;
2757 // callInitCallback();
2760 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2762 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2764 public void setJsMessageSet(String messageclass, String viewId,
2765 String[] colcommands)
2767 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2770 msgset = new Hashtable<String, String[]>();
2771 jsmessages.put(messageclass, msgset);
2773 msgset.put(viewId, colcommands);
2774 long[] l = new long[colcommands.length];
2775 for (int i = 0; i < colcommands.length; i++)
2777 l[i] = colcommands[i].hashCode();
2779 jshashes.put(messageclass + "|" + viewId, l);
2785 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2788 public String getJsMessage(String messageclass, String viewId)
2790 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2793 String[] msgs = msgset.get(viewId);
2796 for (int i = 0; i < msgs.length; i++)
2798 if (msgs[i] != null)
2810 public boolean isJsMessageSetChanged(String string, String string2,
2811 String[] colcommands)
2813 long[] l = jshashes.get(string + "|" + string2);
2814 if (l == null && colcommands != null)
2818 for (int i = 0; i < colcommands.length; i++)
2820 if (l[i] != colcommands[i].hashCode())
2828 private Vector jsExecQueue = new Vector();
2830 public Vector getJsExecQueue()
2835 public void setExecutor(JSFunctionExec jsFunctionExec2)
2837 jsFunctionExec = jsFunctionExec2;
2841 * return the given colour value parameter or the given default if parameter
2848 public Color getDefaultColourParameter(String colparam, Color defcolour)
2850 String colprop = getParameter(colparam);
2851 if (colprop == null || colprop.trim().length() == 0)
2855 Color col = jalview.schemes.ColourSchemeProperty
2856 .getAWTColorFromName(colprop);
2861 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2862 } catch (Exception ex)
2864 System.err.println("Couldn't parse '" + colprop
2865 + "' as a colour for " + colparam);
2869 return (col == null) ? defcolour : col;
2873 public void openJalviewHelpUrl()
2875 String helpUrl = getParameter("jalviewhelpurl");
2876 if (helpUrl == null || helpUrl.trim().length() < 5)
2878 helpUrl = "http://www.jalview.org/help.html";
2880 showURL(helpUrl, "HELP");
2884 * form a complete URL given a path to a resource and a reference location on
2888 * - an absolute path on the same server as localref or a document
2889 * located relative to localref
2891 * - a URL on the same server as url
2892 * @return a complete URL for the resource located by url
2894 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2896 String codebase = localref.toString();
2897 if (url.indexOf("/") == 0)
2899 url = codebase.substring(0, codebase.length()
2900 - localref.getFile().length())
2905 url = localref + url;
2911 * open a URL in the browser - resolving it according to relative refs and
2912 * coping with javascript: protocol if necessary.
2917 public void showURL(String url, String target)
2921 if (url.indexOf(":") == -1)
2923 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2925 // Should really use docbase, not codebase.
2927 url = resolveUrlForLocalOrAbsolute(
2929 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2934 .println("Show url (prepended "
2936 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2944 System.err.println("Show url: " + url);
2947 if (url.indexOf("javascript:") == 0)
2949 // no target for the javascript context
2950 getAppletContext().showDocument(new java.net.URL(url));
2954 getAppletContext().showDocument(new java.net.URL(url), target);
2956 } catch (Exception ex)
2958 ex.printStackTrace();
2963 * bind structures in a viewer to any matching sequences in an alignFrame (use
2964 * sequenceIds to limit scope of search to specific sequences)
2968 * @param sequenceIds
2969 * @return TODO: consider making an exception structure for indicating when
2970 * binding fails public SequenceStructureBinding
2971 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2974 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2975 * alFrame.addStructureViewInstance(viewer,
2976 * separatorListToArray(sequenceIds)); } else { return
2977 * alFrame.addStructureViewInstance(viewer, null); } // return null; }