2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentUtils;
24 import jalview.api.StructureSelectionManagerProvider;
25 import jalview.appletgui.AlignFrame;
26 import jalview.appletgui.AlignViewport;
27 import jalview.appletgui.EmbmenuFrame;
28 import jalview.appletgui.FeatureSettings;
29 import jalview.appletgui.SplitFrame;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AlignmentOrder;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.AnnotationFile;
39 import jalview.io.AppletFormatAdapter;
40 import jalview.io.FileParse;
41 import jalview.io.IdentifyFile;
42 import jalview.io.JPredFile;
43 import jalview.io.JnetAnnotationMaker;
44 import jalview.io.NewickFile;
45 import jalview.javascript.JSFunctionExec;
46 import jalview.javascript.JalviewLiteJsApi;
47 import jalview.javascript.JsCallBack;
48 import jalview.javascript.MouseOverStructureListener;
49 import jalview.structure.SelectionListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.util.HttpUtils;
52 import jalview.util.MessageManager;
54 import java.applet.Applet;
55 import java.awt.Button;
56 import java.awt.Color;
57 import java.awt.Component;
58 import java.awt.EventQueue;
60 import java.awt.Frame;
61 import java.awt.Graphics;
62 import java.awt.event.ActionEvent;
63 import java.awt.event.WindowAdapter;
64 import java.awt.event.WindowEvent;
65 import java.io.BufferedReader;
66 import java.io.InputStreamReader;
68 import java.util.ArrayList;
69 import java.util.Hashtable;
70 import java.util.List;
71 import java.util.StringTokenizer;
72 import java.util.Vector;
74 import netscape.javascript.JSObject;
77 * Jalview Applet. Runs in Java 1.18 runtime
80 * @version $Revision: 1.92 $
82 public class JalviewLite extends Applet implements
83 StructureSelectionManagerProvider, JalviewLiteJsApi
86 private static final String TRUE = "true";
88 private static final String FALSE = "false";
90 public StructureSelectionManager getStructureSelectionManager()
92 return StructureSelectionManager.getStructureSelectionManager(this);
95 // /////////////////////////////////////////
96 // The following public methods may be called
97 // externally, eg via javascript in HTML page
101 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
104 public String getSelectedSequences()
106 return getSelectedSequencesFrom(getDefaultTargetFrame());
112 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
115 public String getSelectedSequences(String sep)
117 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
124 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
128 public String getSelectedSequencesFrom(AlignFrame alf)
130 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
137 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
138 * .AlignFrame, java.lang.String)
141 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
143 StringBuffer result = new StringBuffer("");
144 if (sep == null || sep.length() == 0)
146 sep = separator; // "+0x00AC;
148 if (alf.viewport.getSelectionGroup() != null)
150 SequenceI[] seqs = alf.viewport.getSelectionGroup()
151 .getSequencesInOrder(alf.viewport.getAlignment());
153 for (int i = 0; i < seqs.length; i++)
155 result.append(seqs[i].getName());
160 return result.toString();
166 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
167 * 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)
184 public void highlightIn(final AlignFrame alf, final String sequenceId,
185 final String position, final String alignedPosition)
187 // TODO: could try to highlight in all alignments if alf==null
188 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
189 alf.viewport.getAlignment().getSequencesArray());
190 final SequenceI sq = matcher.findIdMatch(sequenceId);
196 apos = new Integer(position).intValue();
198 } catch (NumberFormatException ex)
202 final StructureSelectionManagerProvider me = this;
203 final int pos = apos;
204 // use vamsas listener to broadcast to all listeners in scope
205 if (alignedPosition != null
206 && (alignedPosition.trim().length() == 0 || alignedPosition
207 .toLowerCase().indexOf("false") > -1))
209 java.awt.EventQueue.invokeLater(new Runnable()
214 StructureSelectionManager.getStructureSelectionManager(me)
215 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
221 java.awt.EventQueue.invokeLater(new Runnable()
226 StructureSelectionManager.getStructureSelectionManager(me)
227 .mouseOverVamsasSequence(sq, pos, null);
237 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
241 public void select(String sequenceIds, String columns)
243 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
249 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
250 * java.lang.String, java.lang.String)
253 public void select(String sequenceIds, String columns, String sep)
255 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
261 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
262 * java.lang.String, java.lang.String)
265 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
267 selectIn(alf, sequenceIds, columns, separator);
273 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
274 * java.lang.String, java.lang.String, java.lang.String)
277 public void selectIn(final AlignFrame alf, String sequenceIds,
278 String columns, String sep)
280 if (sep == null || sep.length() == 0)
288 System.err.println("Selecting region using separator string '"
293 String[] ids = separatorListToArray(sequenceIds, sep);
294 String[] cols = separatorListToArray(columns, sep);
295 final SequenceGroup sel = new SequenceGroup();
296 final ColumnSelection csel = new ColumnSelection();
297 AlignmentI al = alf.viewport.getAlignment();
298 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
299 alf.viewport.getAlignment().getSequencesArray());
300 int start = 0, end = al.getWidth(), alw = al.getWidth();
301 boolean seqsfound = true;
302 if (ids != null && ids.length > 0)
305 for (int i = 0; i < ids.length; i++)
307 if (ids[i].trim().length() == 0)
311 SequenceI sq = matcher.findIdMatch(ids[i]);
315 sel.addSequence(sq, false);
319 boolean inseqpos = false;
320 if (cols != null && cols.length > 0)
322 boolean seset = false;
323 for (int i = 0; i < cols.length; i++)
325 String cl = cols[i].trim();
326 if (cl.length() == 0)
331 if ((p = cl.indexOf("-")) > -1)
333 int from = -1, to = -1;
336 from = new Integer(cl.substring(0, p)).intValue();
338 } catch (NumberFormatException ex)
341 .println("ERROR: Couldn't parse first integer in range element column selection string '"
342 + cl + "' - format is 'from-to'");
347 to = new Integer(cl.substring(p + 1)).intValue();
349 } catch (NumberFormatException ex)
352 .println("ERROR: Couldn't parse second integer in range element column selection string '"
353 + cl + "' - format is 'from-to'");
356 if (from >= 0 && to >= 0)
373 // comment to prevent range extension
383 for (int r = from; r <= to; r++)
385 if (r >= 0 && r < alw)
392 System.err.println("Range '" + cl + "' deparsed as [" + from
398 System.err.println("ERROR: Invalid Range '" + cl
399 + "' deparsed as [" + from + "," + to + "]");
407 r = new Integer(cl).intValue();
409 } catch (NumberFormatException ex)
411 if (cl.toLowerCase().equals("sequence"))
413 // we are in the dataset sequence's coordinate frame.
419 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
424 if (r >= 0 && r <= alw)
434 // comment to prevent range extension
447 System.err.println("Point selection '" + cl
448 + "' deparsed as [" + r + "]");
453 System.err.println("ERROR: Invalid Point selection '" + cl
454 + "' deparsed as [" + r + "]");
461 // we only propagate the selection when it was the null selection, or the
462 // given sequences were found in the alignment.
463 if (inseqpos && sel.getSize() > 0)
465 // assume first sequence provides reference frame ?
466 SequenceI rs = sel.getSequenceAt(0);
467 start = rs.findIndex(start);
468 end = rs.findIndex(end);
469 List<Integer> cs = new ArrayList<Integer>(csel.getSelected());
471 for (Integer selectedCol : cs)
473 csel.addElement(rs.findIndex(selectedCol));
476 sel.setStartRes(start);
478 EventQueue.invokeLater(new Runnable()
483 alf.select(sel, csel);
493 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
494 * String, java.lang.String)
497 public String getSelectedSequencesAsAlignment(String format, String suffix)
499 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
507 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
508 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
511 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
512 String format, String suffix)
516 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
517 if (alf.viewport.getSelectionGroup() != null)
519 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
520 // method now returns a full copy of sequence data
521 // TODO consider using getSequenceSelection instead here
522 String reply = new AppletFormatAdapter().formatSequences(format,
523 new Alignment(alf.viewport.getSelectionAsNewSequence()),
527 } catch (Exception ex)
529 ex.printStackTrace();
530 return "Error retrieving alignment in " + format + " format. ";
538 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
541 public String getAlignmentOrder()
543 return getAlignmentOrderFrom(getDefaultTargetFrame());
550 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
554 public String getAlignmentOrderFrom(AlignFrame alf)
556 return getAlignmentOrderFrom(alf, separator);
563 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
564 * , java.lang.String)
567 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
569 AlignmentI alorder = alf.getAlignViewport().getAlignment();
570 String[] order = new String[alorder.getHeight()];
571 for (int i = 0; i < order.length; i++)
573 order[i] = alorder.getSequenceAt(i).getName();
575 return arrayToSeparatorList(order);
581 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
585 public String orderBy(String order, String undoName)
587 return orderBy(order, undoName, separator);
593 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
594 * java.lang.String, java.lang.String)
597 public String orderBy(String order, String undoName, String sep)
599 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
606 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
607 * java.lang.String, java.lang.String, java.lang.String)
610 public String orderAlignmentBy(AlignFrame alf, String order,
611 String undoName, String sep)
613 String[] ids = separatorListToArray(order, sep);
614 SequenceI[] sqs = null;
615 if (ids != null && ids.length > 0)
617 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
618 alf.viewport.getAlignment().getSequencesArray());
620 sqs = new SequenceI[ids.length];
621 for (int i = 0; i < ids.length; i++)
623 if (ids[i].trim().length() == 0)
627 SequenceI sq = matcher.findIdMatch(ids[i]);
635 SequenceI[] sqq = new SequenceI[s];
636 System.arraycopy(sqs, 0, sqq, 0, s);
649 final AlignmentOrder aorder = new AlignmentOrder(sqs);
651 if (undoName != null && undoName.trim().length() == 0)
655 final String _undoName = undoName;
656 // TODO: deal with synchronization here: cannot raise any events until after
657 // this has returned.
658 return alf.sortBy(aorder, _undoName) ? TRUE : "";
664 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
667 public String getAlignment(String format)
669 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
676 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
680 public String getAlignmentFrom(AlignFrame alf, String format)
682 return getAlignmentFrom(alf, format, TRUE);
688 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
692 public String getAlignment(String format, String suffix)
694 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
701 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
702 * java.lang.String, java.lang.String)
705 public String getAlignmentFrom(AlignFrame alf, String format,
710 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
712 String reply = new AppletFormatAdapter().formatSequences(format,
713 alf.viewport.getAlignment(), seqlimits);
715 } catch (Exception ex)
717 ex.printStackTrace();
718 return "Error retrieving alignment in " + format + " format. ";
725 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
728 public void loadAnnotation(String annotation)
730 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
737 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
738 * , java.lang.String)
741 public void loadAnnotationFrom(AlignFrame alf, String annotation)
743 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
744 annotation, AppletFormatAdapter.PASTE))
746 alf.alignPanel.fontChanged();
747 alf.alignPanel.setScrollValues(0, 0);
751 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
758 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
761 public void loadFeatures(String features, boolean autoenabledisplay)
763 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
770 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
771 * , java.lang.String)
774 public boolean loadFeaturesFrom(AlignFrame alf, String features,
775 boolean autoenabledisplay)
777 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
784 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
787 public String getFeatures(String format)
789 return getFeaturesFrom(getDefaultTargetFrame(), format);
796 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
800 public String getFeaturesFrom(AlignFrame alf, String format)
802 return alf.outputFeatures(false, format);
808 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
811 public String getAnnotation()
813 return getAnnotationFrom(getDefaultTargetFrame());
820 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
824 public String getAnnotationFrom(AlignFrame alf)
826 return alf.outputAnnotations(false);
832 * @see jalview.bin.JalviewLiteJsApi#newView()
835 public AlignFrame newView()
837 return newViewFrom(getDefaultTargetFrame());
843 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
846 public AlignFrame newView(String name)
848 return newViewFrom(getDefaultTargetFrame(), name);
854 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
857 public AlignFrame newViewFrom(AlignFrame alf)
859 return alf.newView(null);
865 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
869 public AlignFrame newViewFrom(AlignFrame alf, String name)
871 return alf.newView(name);
877 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
881 public AlignFrame loadAlignment(String text, String title)
883 AlignmentI al = null;
885 String format = new IdentifyFile().identify(text,
886 AppletFormatAdapter.PASTE);
889 al = new AppletFormatAdapter().readFile(text,
890 AppletFormatAdapter.PASTE, format);
891 if (al.getHeight() > 0)
893 return new AlignFrame(al, this, title, false);
895 } catch (java.io.IOException ex)
897 ex.printStackTrace();
905 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
908 public void setMouseoverListener(String listener)
910 setMouseoverListener(currentAlignFrame, listener);
913 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
919 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
920 * , java.lang.String)
923 public void setMouseoverListener(AlignFrame af, String listener)
925 if (listener != null)
927 listener = listener.trim();
928 if (listener.length() == 0)
931 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
935 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
937 javascriptListeners.addElement(mol);
938 StructureSelectionManager.getStructureSelectionManager(this)
939 .addStructureViewerListener(mol);
942 System.err.println("Added a mouseover listener for "
943 + ((af == null) ? "All frames" : "Just views for "
944 + af.getAlignViewport().getSequenceSetId()));
945 System.err.println("There are now " + javascriptListeners.size()
946 + " listeners in total.");
953 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
956 public void setSelectionListener(String listener)
958 setSelectionListener(null, listener);
965 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
966 * , java.lang.String)
969 public void setSelectionListener(AlignFrame af, String listener)
971 if (listener != null)
973 listener = listener.trim();
974 if (listener.length() == 0)
977 .println("jalview Javascript error: Ignoring empty function for selection listener.");
981 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
983 javascriptListeners.addElement(mol);
984 StructureSelectionManager.getStructureSelectionManager(this)
985 .addSelectionListener(mol);
988 System.err.println("Added a selection listener for "
989 + ((af == null) ? "All frames" : "Just views for "
990 + af.getAlignViewport().getSequenceSetId()));
991 System.err.println("There are now " + javascriptListeners.size()
992 + " listeners in total.");
997 * Callable from javascript to register a javascript function to pass events
998 * to a structure viewer.
1001 * the name of a javascript function
1003 * a token separated list of PDB file names listened for
1004 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
1008 public void setStructureListener(String listener, String modelSet)
1010 if (listener != null)
1012 listener = listener.trim();
1013 if (listener.length() == 0)
1016 .println("jalview Javascript error: Ignoring empty function for selection listener.");
1020 MouseOverStructureListener mol = new MouseOverStructureListener(this,
1021 listener, separatorListToArray(modelSet));
1022 javascriptListeners.addElement(mol);
1023 StructureSelectionManager.getStructureSelectionManager(this)
1024 .addStructureViewerListener(mol);
1027 System.err.println("Added a javascript structure viewer listener '"
1029 System.err.println("There are now " + javascriptListeners.size()
1030 + " listeners in total.");
1038 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
1039 * .AlignFrame, java.lang.String)
1042 public void removeJavascriptListener(AlignFrame af, String listener)
1044 if (listener != null)
1046 listener = listener.trim();
1047 if (listener.length() == 0)
1052 boolean rprt = false;
1053 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1055 Object lstn = javascriptListeners.elementAt(ms);
1056 JsCallBack lstner = (JsCallBack) lstn;
1057 if ((af == null || lstner.getAlignFrame() == af)
1058 && (listener == null || lstner.getListenerFunction().equals(
1061 javascriptListeners.removeElement(lstner);
1063 if (lstner instanceof SelectionListener)
1065 StructureSelectionManager.getStructureSelectionManager(this)
1066 .removeSelectionListener((SelectionListener) lstner);
1070 StructureSelectionManager.getStructureSelectionManager(this)
1071 .removeStructureViewerListener(lstner, null);
1076 System.err.println("Removed listener '" + listener + "'");
1086 System.err.println("There are now " + javascriptListeners.size()
1087 + " listeners in total.");
1094 System.err.println("Applet " + getName() + " stop().");
1099 public void destroy()
1101 System.err.println("Applet " + getName() + " destroy().");
1105 private void tidyUp()
1108 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1109 && currentAlignFrame.viewport.applet != null)
1111 AlignViewport av = currentAlignFrame.viewport;
1112 currentAlignFrame.closeMenuItem_actionPerformed();
1114 currentAlignFrame = null;
1116 if (javascriptListeners != null)
1118 while (javascriptListeners.size() > 0)
1120 jalview.javascript.JSFunctionExec mol = javascriptListeners
1122 javascriptListeners.removeElement(mol);
1123 if (mol instanceof SelectionListener)
1125 StructureSelectionManager.getStructureSelectionManager(this)
1126 .removeSelectionListener((SelectionListener) mol);
1130 StructureSelectionManager.getStructureSelectionManager(this)
1131 .removeStructureViewerListener(mol, null);
1136 if (jsFunctionExec != null)
1138 jsFunctionExec.stopQueue();
1139 jsFunctionExec.jvlite = null;
1141 initialAlignFrame = null;
1142 jsFunctionExec = null;
1143 javascriptListeners = null;
1144 StructureSelectionManager.release(this);
1147 private jalview.javascript.JSFunctionExec jsFunctionExec;
1152 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1153 * java.lang.String, java.lang.String)
1156 public void mouseOverStructure(final String pdbResNum,
1157 final String chain, final String pdbfile)
1159 final StructureSelectionManagerProvider me = this;
1160 java.awt.EventQueue.invokeLater(new Runnable()
1167 StructureSelectionManager.getStructureSelectionManager(me)
1168 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1172 System.err.println("mouseOver for '" + pdbResNum
1173 + "' in chain '" + chain + "' in structure '" + pdbfile
1176 } catch (NumberFormatException e)
1178 System.err.println("Ignoring invalid residue number string '"
1190 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1191 * java.lang.String, java.lang.String)
1194 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1195 final String leftHandColumn)
1197 java.awt.EventQueue.invokeLater(new Runnable()
1204 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1205 leftHandColumn).intValue());
1207 } catch (Exception ex)
1209 System.err.println("Couldn't parse integer arguments (topRow='"
1210 + topRow + "' and leftHandColumn='" + leftHandColumn
1212 ex.printStackTrace();
1222 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1223 * .AlignFrame, java.lang.String)
1226 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1229 java.awt.EventQueue.invokeLater(new Runnable()
1236 alf.scrollToRow(new Integer(topRow).intValue());
1238 } catch (Exception ex)
1240 System.err.println("Couldn't parse integer arguments (topRow='"
1242 ex.printStackTrace();
1253 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1254 * .AlignFrame, java.lang.String)
1257 public void scrollViewToColumnIn(final AlignFrame alf,
1258 final String leftHandColumn)
1260 java.awt.EventQueue.invokeLater(new Runnable()
1268 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1270 } catch (Exception ex)
1273 .println("Couldn't parse integer arguments (leftHandColumn='"
1274 + leftHandColumn + "')");
1275 ex.printStackTrace();
1282 // //////////////////////////////////////////////
1283 // //////////////////////////////////////////////
1285 public static int lastFrameX = 200;
1287 public static int lastFrameY = 200;
1289 boolean fileFound = true;
1291 String file = "No file";
1293 String file2 = null;
1295 Button launcher = new Button(
1296 MessageManager.getString("label.start_jalview"));
1299 * The currentAlignFrame is static, it will change if and when the user
1300 * selects a new window. Note that it will *never* point back to the embedded
1301 * AlignFrame if the applet is started as embedded on the page and then
1302 * afterwards a new view is created.
1304 public AlignFrame currentAlignFrame = null;
1307 * This is the first frame to be displayed, and does not change. API calls
1308 * will default to this instance if currentAlignFrame is null.
1310 AlignFrame initialAlignFrame = null;
1312 boolean embedded = false;
1314 private boolean checkForJmol = true;
1316 private boolean checkedForJmol = false; // ensure we don't check for jmol
1318 // every time the app is re-inited
1320 public boolean jmolAvailable = false;
1322 private boolean alignPdbStructures = false;
1325 * use an external structure viewer exclusively (no jmols or MCViews will be
1326 * opened by JalviewLite itself)
1328 public boolean useXtrnalSviewer = false;
1330 public static boolean debug = false;
1332 static String builddate = null, version = null, installation = null;
1334 private static void initBuildDetails()
1336 if (builddate == null)
1338 builddate = "unknown";
1340 installation = "applet";
1341 java.net.URL url = JalviewLite.class
1342 .getResource("/.build_properties");
1347 BufferedReader reader = new BufferedReader(new InputStreamReader(
1350 while ((line = reader.readLine()) != null)
1352 if (line.indexOf("VERSION") > -1)
1354 version = line.substring(line.indexOf("=") + 1);
1356 if (line.indexOf("BUILD_DATE") > -1)
1358 builddate = line.substring(line.indexOf("=") + 1);
1360 if (line.indexOf("INSTALLATION") > -1)
1362 installation = line.substring(line.indexOf("=") + 1);
1365 } catch (Exception ex)
1367 ex.printStackTrace();
1373 public static String getBuildDate()
1379 public static String getInstallation()
1382 return installation;
1385 public static String getVersion()
1391 // public JSObject scriptObject = null;
1394 * init method for Jalview Applet
1399 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1404 System.err.println("Applet context is '"
1405 + getAppletContext().getClass().toString() + "'");
1407 JSObject scriptObject = JSObject.getWindow(this);
1408 if (debug && scriptObject != null)
1410 System.err.println("Applet has Javascript callback support.");
1413 } catch (Exception ex)
1416 .println("Warning: No JalviewLite javascript callbacks available.");
1419 ex.printStackTrace();
1425 System.err.println("JalviewLite Version " + getVersion());
1426 System.err.println("Build Date : " + getBuildDate());
1427 System.err.println("Installation : " + getInstallation());
1429 String externalsviewer = getParameter("externalstructureviewer");
1430 if (externalsviewer != null)
1432 useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
1435 * if true disable the check for jmol
1437 String chkforJmol = getParameter("nojmol");
1438 if (chkforJmol != null)
1440 checkForJmol = !chkforJmol.equals(TRUE);
1443 * get the separator parameter if present
1445 String sep = getParameter("separator");
1448 if (sep.length() > 0)
1453 System.err.println("Separator set to '" + separator + "'");
1460 .getString("error.invalid_separator_parameter"));
1466 String param = getParameter("RGB");
1472 r = Integer.parseInt(param.substring(0, 2), 16);
1473 g = Integer.parseInt(param.substring(2, 4), 16);
1474 b = Integer.parseInt(param.substring(4, 6), 16);
1475 } catch (Exception ex)
1482 param = getParameter("label");
1485 launcher.setLabel(param);
1488 setBackground(new Color(r, g, b));
1490 file = getParameter("file");
1494 // Maybe the sequences are added as parameters
1495 StringBuffer data = new StringBuffer("PASTE");
1497 while ((file = getParameter("sequence" + i)) != null)
1499 data.append(file.toString() + "\n");
1502 if (data.length() > 5)
1504 file = data.toString();
1507 if (getDefaultParameter("enableSplitFrame", true))
1509 file2 = getParameter("file2");
1512 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
1515 LoadingThread loader = new LoadingThread(file, file2, this);
1518 else if (file != null)
1521 * Start the applet immediately or show a button to start it
1523 if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
1525 LoadingThread loader = new LoadingThread(file, file2, this);
1531 launcher.addActionListener(new java.awt.event.ActionListener()
1534 public void actionPerformed(ActionEvent e)
1536 LoadingThread loader = new LoadingThread(file, file2,
1545 // jalview initialisation with no alignment. loadAlignment() method can
1546 // still be called to open new alignments.
1553 private void initLiveConnect()
1555 // try really hard to get the liveConnect thing working
1556 boolean notFailed = false;
1558 while (!notFailed && tries < 10)
1562 System.err.println("LiveConnect request thread going to sleep.");
1566 Thread.sleep(700 * (1 + tries));
1567 } catch (InterruptedException q)
1573 System.err.println("LiveConnect request thread woken up.");
1577 JSObject scriptObject = JSObject.getWindow(this);
1578 if (scriptObject.eval("navigator") != null)
1582 } catch (Exception jsex)
1584 System.err.println("Attempt " + tries
1585 + " to access LiveConnect javascript failed.");
1590 private void callInitCallback()
1592 String initjscallback = getParameter("oninit");
1593 if (initjscallback == null)
1597 initjscallback = initjscallback.trim();
1598 if (initjscallback.length() > 0)
1600 JSObject scriptObject = null;
1603 scriptObject = JSObject.getWindow(this);
1604 } catch (Exception ex)
1608 // try really hard to let the browser plugin know we want liveconnect
1611 if (scriptObject != null)
1615 // do onInit with the JS executor thread
1616 new JSFunctionExec(this).executeJavascriptFunction(true,
1617 initjscallback, null, "Calling oninit callback '"
1618 + initjscallback + "'.");
1619 } catch (Exception e)
1621 System.err.println("Exception when executing _oninit callback '"
1622 + initjscallback + "'.");
1623 e.printStackTrace();
1628 System.err.println("Not executing _oninit callback '"
1629 + initjscallback + "' - no scripting allowed.");
1635 * Initialises and displays a new java.awt.Frame
1638 * java.awt.Frame to be displayed
1640 * title of new frame
1642 * width if new frame
1644 * height of new frame
1646 public static void addFrame(final Frame frame, String title, int width,
1649 frame.setLocation(lastFrameX, lastFrameY);
1652 frame.setSize(width, height);
1653 frame.setTitle(title);
1654 frame.addWindowListener(new WindowAdapter()
1657 public void windowClosing(WindowEvent e)
1659 if (frame instanceof AlignFrame)
1661 AlignViewport vp = ((AlignFrame) frame).viewport;
1662 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1663 if (vp.applet.currentAlignFrame == frame)
1665 vp.applet.currentAlignFrame = null;
1673 if (frame instanceof EmbmenuFrame)
1675 ((EmbmenuFrame) frame).destroyMenus();
1677 frame.setMenuBar(null);
1682 public void windowActivated(WindowEvent e)
1684 if (frame instanceof AlignFrame)
1686 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1689 System.err.println("Activated window " + frame);
1693 super.windowActivated(e);
1696 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1699 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1702 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1703 * frame) { currentAlignFrame = null; if (debug) {
1704 * System.err.println("Deactivated window "+frame); } }
1705 * super.windowDeactivated(e); }
1708 frame.setVisible(true);
1712 * This paints the background surrounding the "Launch Jalview button" <br>
1714 * If file given in parameter not found, displays error message
1720 public void paint(Graphics g)
1724 g.setColor(new Color(200, 200, 200));
1725 g.setColor(Color.cyan);
1726 g.fillRect(0, 0, getSize().width, getSize().height);
1727 g.setColor(Color.red);
1729 MessageManager.getString("label.jalview_cannot_open_file"),
1731 g.drawString("\"" + file + "\"", 5, 30);
1735 g.setColor(Color.black);
1736 g.setFont(new Font("Arial", Font.BOLD, 24));
1737 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1738 getSize().height / 2 - 30);
1739 g.drawString(MessageManager.getString("label.loading_data") + "...",
1740 50, getSize().height / 2);
1745 * get all components associated with the applet of the given type
1750 public Vector getAppletWindow(Class class1)
1752 Vector wnds = new Vector();
1753 Component[] cmp = getComponents();
1756 for (int i = 0; i < cmp.length; i++)
1758 if (class1.isAssignableFrom(cmp[i].getClass()))
1760 wnds.addElement(cmp);
1767 class LoadJmolThread extends Thread
1769 private boolean running = false;
1774 if (running || checkedForJmol)
1783 if (!System.getProperty("java.version").startsWith("1.1"))
1785 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1786 jmolAvailable = true;
1791 .println("Jmol not available - Using MCview for structures");
1793 } catch (java.lang.ClassNotFoundException ex)
1799 jmolAvailable = false;
1803 .println("Skipping Jmol check. Will use MCView (probably)");
1806 checkedForJmol = true;
1810 public boolean notFinished()
1812 return running || !checkedForJmol;
1816 class LoadingThread extends Thread
1819 * State variable: protocol for access to file source
1823 String _file; // alignment file or URL spec
1825 String _file2; // second alignment file or URL spec
1829 private void dbgMsg(String msg)
1831 if (JalviewLite.debug)
1833 System.err.println(msg);
1838 * update the protocol state variable for accessing the datasource located
1842 * @return possibly updated datasource string
1844 public String resolveFileProtocol(String path)
1849 if (path.startsWith("PASTE"))
1851 protocol = AppletFormatAdapter.PASTE;
1852 return path.substring(5);
1858 if (path.indexOf("://") != -1)
1860 protocol = AppletFormatAdapter.URL;
1865 * try relative to document root
1867 URL documentBase = getDocumentBase();
1868 String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
1869 if (HttpUtils.isValidUrl(withDocBase))
1873 System.err.println("Prepended document base '" + documentBase
1874 + "' to make: '" + withDocBase + "'");
1876 protocol = AppletFormatAdapter.URL;
1881 * try relative to codebase (if different to document base)
1883 URL codeBase = getCodeBase();
1884 String withCodeBase = applet.resolveUrlForLocalOrAbsolute(path,
1886 if (!withCodeBase.equals(withDocBase)
1887 && HttpUtils.isValidUrl(withCodeBase))
1889 protocol = AppletFormatAdapter.URL;
1892 System.err.println("Prepended codebase '" + codeBase
1893 + "' to make: '" + withCodeBase + "'");
1895 return withCodeBase;
1899 * try locating by classloader; try this last so files in the directory
1900 * are resolved using document base
1902 if (inArchive(path))
1904 protocol = AppletFormatAdapter.CLASSLOADER;
1909 public LoadingThread(String file, String file2, JalviewLite _applet)
1912 this._file2 = file2;
1919 LoadJmolThread jmolchecker = new LoadJmolThread();
1920 jmolchecker.start();
1921 while (jmolchecker.notFinished())
1923 // wait around until the Jmol check is complete.
1927 } catch (Exception e)
1932 // applet.callInitCallback();
1936 * Load the alignment and any related files as specified by applet
1939 private void startLoading()
1941 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1943 dbgMsg("Loading started.");
1945 AlignFrame newAlignFrame = readAlignment(_file);
1946 AlignFrame newAlignFrame2 = readAlignment(_file2);
1947 if (newAlignFrame != null)
1949 addToDisplay(newAlignFrame, newAlignFrame2);
1950 loadTree(newAlignFrame);
1952 loadScoreFile(newAlignFrame);
1954 loadFeatures(newAlignFrame);
1956 loadAnnotations(newAlignFrame);
1958 loadJnetFile(newAlignFrame);
1960 loadPdbFiles(newAlignFrame);
1965 applet.remove(launcher);
1972 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1977 public void addToDisplay(AlignFrame af, AlignFrame af2)
1981 AlignmentI al1 = af.viewport.getAlignment();
1982 AlignmentI al2 = af2.viewport.getAlignment();
1983 AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
1984 AlignmentI prot = al1.isNucleotide() ? al2 : al1;
1985 if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
1988 SplitFrame sf = new SplitFrame(af, af2);
1989 sf.addToDisplay(embedded, JalviewLite.this);
1994 String msg = "Could not map any sequence in " + af2.getTitle()
1996 + (al1.isNucleotide() ? "protein product" : "cDNA")
1997 + " for " + af.getTitle();
1998 System.err.println(msg);
2002 af.addToDisplay(embedded);
2006 * Read the alignment file (from URL, text 'paste', or archive by
2011 protected AlignFrame readAlignment(String fileParam)
2013 if (fileParam == null)
2017 String resolvedFile = resolveFileProtocol(fileParam);
2018 String format = new IdentifyFile().identify(resolvedFile, protocol);
2019 dbgMsg("File identified as '" + format + "'");
2020 AlignmentI al = null;
2023 al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
2025 if ((al != null) && (al.getHeight() > 0))
2027 dbgMsg("Successfully loaded file.");
2028 al.setDataset(null);
2029 AlignFrame newAlignFrame = new AlignFrame(al, applet,
2030 resolvedFile, embedded, false);
2031 newAlignFrame.setTitle(resolvedFile);
2032 if (initialAlignFrame == null)
2034 initialAlignFrame = newAlignFrame;
2036 // update the focus.
2037 currentAlignFrame = newAlignFrame;
2039 if (protocol == AppletFormatAdapter.PASTE)
2041 newAlignFrame.setTitle(MessageManager.formatMessage(
2042 "label.sequences_from", new Object[] { applet
2043 .getDocumentBase().toString() }));
2046 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
2047 "label.successfully_loaded_file",
2048 new Object[] { resolvedFile }));
2050 return newAlignFrame;
2052 } catch (java.io.IOException ex)
2054 dbgMsg("File load exception.");
2055 ex.printStackTrace();
2060 FileParse fp = new FileParse(resolvedFile, protocol);
2062 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
2064 while ((ln = fp.nextLine()) != null)
2068 dbgMsg(">>>Dump finished.");
2069 } catch (Exception e)
2072 .println("Exception when trying to dump the content of the file parameter.");
2073 e.printStackTrace();
2081 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
2087 protected boolean loadPdbFiles(AlignFrame alignFrame)
2089 boolean result = false;
2091 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
2092 * related to JAL-434
2095 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2098 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2101 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2103 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2106 int pdbFileCount = 0;
2107 // Accumulate pdbs here if they are heading for the same view (if
2108 // alignPdbStructures is true)
2109 Vector pdbs = new Vector();
2110 // create a lazy matcher if we're asked to
2111 jalview.analysis.SequenceIdMatcher matcher = (applet
2112 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2113 alignFrame.getAlignViewport().getAlignment()
2114 .getSequencesArray()) : null;
2119 if (pdbFileCount > 0)
2121 param = applet.getParameter("PDBFILE" + pdbFileCount);
2125 param = applet.getParameter("PDBFILE");
2130 PDBEntry pdb = new PDBEntry();
2133 SequenceI[] seqs = null;
2134 String[] chains = null;
2136 StringTokenizer st = new StringTokenizer(param, " ");
2138 if (st.countTokens() < 2)
2140 String sequence = applet.getParameter("PDBSEQ");
2141 if (sequence != null)
2143 seqs = new SequenceI[] { matcher == null ? (Sequence) alignFrame
2144 .getAlignViewport().getAlignment().findName(sequence)
2145 : matcher.findIdMatch(sequence) };
2151 param = st.nextToken();
2152 List<SequenceI> tmp = new ArrayList<SequenceI>();
2153 List<String> tmp2 = new ArrayList<String>();
2155 while (st.hasMoreTokens())
2157 seqstring = st.nextToken();
2158 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2159 if (st2.countTokens() > 1)
2161 // This is the chain
2162 tmp2.add(st2.nextToken());
2163 seqstring = st2.nextToken();
2165 tmp.add(matcher == null ? (Sequence) alignFrame
2166 .getAlignViewport().getAlignment()
2167 .findName(seqstring) : matcher.findIdMatch(seqstring));
2170 seqs = tmp.toArray(new SequenceI[tmp.size()]);
2171 if (tmp2.size() == tmp.size())
2173 chains = tmp2.toArray(new String[tmp2.size()]);
2176 param = resolveFileProtocol(param);
2177 // TODO check JAL-357 for files in a jar (CLASSLOADER)
2182 for (int i = 0; i < seqs.length; i++)
2184 if (seqs[i] != null)
2186 ((Sequence) seqs[i]).addPDBId(pdb);
2187 StructureSelectionManager.getStructureSelectionManager(
2188 applet).registerPDBEntry(pdb);
2192 if (JalviewLite.debug)
2194 // this may not really be a problem but we give a warning
2197 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2203 if (!alignPdbStructures)
2205 alignFrame.newStructureView(applet, pdb, seqs, chains,
2210 pdbs.addElement(new Object[] { pdb, seqs, chains,
2211 new String(protocol) });
2217 } while (param != null || pdbFileCount < 10);
2218 if (pdbs.size() > 0)
2220 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2221 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2222 String[][] chains = new String[pdbs.size()][];
2223 String[] protocols = new String[pdbs.size()];
2224 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2226 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2227 pdb[pdbsi] = (PDBEntry) o[0];
2228 seqs[pdbsi] = (SequenceI[]) o[1];
2229 chains[pdbsi] = (String[]) o[2];
2230 protocols[pdbsi] = (String) o[3];
2232 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2240 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2246 protected boolean loadJnetFile(AlignFrame alignFrame)
2248 boolean result = false;
2249 String param = applet.getParameter("jnetfile");
2254 param = resolveFileProtocol(param);
2255 JPredFile predictions = new JPredFile(param, protocol);
2256 JnetAnnotationMaker.add_annotation(predictions,
2257 alignFrame.viewport.getAlignment(), 0, false);
2258 // false == do not add sequence profile from concise output
2259 SequenceI repseq = alignFrame.viewport.getAlignment()
2261 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2262 ColumnSelection cs = new ColumnSelection();
2263 cs.hideInsertionsFor(repseq);
2264 alignFrame.viewport.setColumnSelection(cs);
2265 alignFrame.alignPanel.fontChanged();
2266 alignFrame.alignPanel.setScrollValues(0, 0);
2268 } catch (Exception ex)
2270 ex.printStackTrace();
2277 * Load annotations if specified by parameter. Returns true if loaded, else
2283 protected boolean loadAnnotations(AlignFrame alignFrame)
2285 boolean result = false;
2286 String param = applet.getParameter("annotations");
2289 param = resolveFileProtocol(param);
2291 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2294 alignFrame.alignPanel.fontChanged();
2295 alignFrame.alignPanel.setScrollValues(0, 0);
2301 .println("Annotations were not added from annotation file '"
2309 * Load features file and view settings as specified by parameters. Returns
2310 * true if features were loaded, else false.
2315 protected boolean loadFeatures(AlignFrame alignFrame)
2317 boolean result = false;
2318 // ///////////////////////////
2319 // modify display of features
2320 // we do this before any features have been loaded, ensuring any hidden
2321 // groups are hidden when features first displayed
2323 // hide specific groups
2325 String param = applet.getParameter("hidefeaturegroups");
2328 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2329 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2331 // show specific groups
2332 param = applet.getParameter("showfeaturegroups");
2335 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2336 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2338 // and now load features
2339 param = applet.getParameter("features");
2342 param = resolveFileProtocol(param);
2344 result = alignFrame.parseFeaturesFile(param, protocol);
2347 param = applet.getParameter("showFeatureSettings");
2348 if (param != null && param.equalsIgnoreCase(TRUE))
2350 alignFrame.viewport.setShowSequenceFeatures(true);
2351 new FeatureSettings(alignFrame.alignPanel);
2357 * Load a score file if specified by parameter. Returns true if file was
2358 * loaded, else false.
2362 protected boolean loadScoreFile(AlignFrame alignFrame)
2364 boolean result = false;
2365 String sScoreFile = applet.getParameter("scoreFile");
2366 if (sScoreFile != null && !"".equals(sScoreFile))
2373 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2375 result = alignFrame.loadScoreFile(sScoreFile);
2379 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2380 + sScoreFile + "')");
2382 } catch (Exception e)
2384 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2385 sScoreFile, e.getMessage());
2392 * Load a tree for the alignment if specified by parameter. Returns true if
2393 * a tree was loaded, else false.
2398 protected boolean loadTree(AlignFrame alignFrame)
2400 boolean result = false;
2401 String treeFile = applet.getParameter("tree");
2402 if (treeFile == null)
2404 treeFile = applet.getParameter("treeFile");
2407 if (treeFile != null)
2411 treeFile = resolveFileProtocol(treeFile);
2412 NewickFile fin = new NewickFile(treeFile, protocol);
2415 if (fin.getTree() != null)
2417 alignFrame.loadTree(fin, treeFile);
2419 dbgMsg("Successfully imported tree.");
2423 dbgMsg("Tree parameter did not resolve to a valid tree.");
2425 } catch (Exception ex)
2427 ex.printStackTrace();
2434 * Discovers whether the given file is in the Applet Archive
2440 boolean inArchive(String f)
2442 // This might throw a security exception in certain browsers
2443 // Netscape Communicator for instance.
2446 boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
2449 System.err.println("Resource '" + f + "' was "
2450 + (rtn ? "" : "not ") + "located by classloader.");
2453 } catch (Exception ex)
2455 System.out.println("Exception checking resources: " + f + " " + ex);
2462 * @return the default alignFrame acted on by the public applet methods. May
2463 * return null with an error message on System.err indicating the
2466 public AlignFrame getDefaultTargetFrame()
2468 if (currentAlignFrame != null)
2470 return currentAlignFrame;
2472 if (initialAlignFrame != null)
2474 return initialAlignFrame;
2477 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2482 * separator used for separatorList
2484 protected String separator = "" + ((char) 0x00AC); // the default used to be
2485 // '|' but many sequence
2486 // IDS include pipes.
2489 * set to enable the URL based javascript execution mechanism
2491 public boolean jsfallbackEnabled = false;
2494 * parse the string into a list
2497 * @return elements separated by separator
2499 public String[] separatorListToArray(String list)
2501 return separatorListToArray(list, separator);
2505 * parse the string into a list
2509 * @return elements separated by separator
2511 public static String[] separatorListToArray(String list, String separator)
2513 // TODO use StringUtils version (slightly different...)
2514 int seplen = separator.length();
2515 if (list == null || list.equals("") || list.equals(separator))
2519 java.util.Vector jv = new Vector();
2521 while ((pos = list.indexOf(separator, cp)) > cp)
2523 jv.addElement(list.substring(cp, pos));
2526 if (cp < list.length())
2528 String c = list.substring(cp);
2529 if (!c.equals(separator))
2536 String[] v = new String[jv.size()];
2537 for (int i = 0; i < v.length; i++)
2539 v[i] = (String) jv.elementAt(i);
2541 jv.removeAllElements();
2544 System.err.println("Array from '" + separator
2545 + "' separated List:\n" + v.length);
2546 for (int i = 0; i < v.length; i++)
2548 System.err.println("item " + i + " '" + v[i] + "'");
2555 System.err.println("Empty Array from '" + separator
2556 + "' separated List");
2562 * concatenate the list with separator
2565 * @return concatenated string
2567 public String arrayToSeparatorList(String[] list)
2569 return arrayToSeparatorList(list, separator);
2573 * concatenate the list with separator
2577 * @return concatenated string
2579 public static String arrayToSeparatorList(String[] list, String separator)
2581 // TODO use StringUtils version
2582 StringBuffer v = new StringBuffer();
2583 if (list != null && list.length > 0)
2585 for (int i = 0, iSize = list.length; i < iSize; i++)
2587 if (list[i] != null)
2591 v.append(separator);
2598 System.err.println("Returning '" + separator
2599 + "' separated List:\n");
2600 System.err.println(v);
2602 return v.toString();
2606 System.err.println("Returning empty '" + separator
2607 + "' separated List\n");
2609 return "" + separator;
2615 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2618 public String getFeatureGroups()
2620 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2621 .getFeatureGroups());
2629 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2633 public String getFeatureGroupsOn(AlignFrame alf)
2635 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2642 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2645 public String getFeatureGroupsOfState(boolean visible)
2647 return arrayToSeparatorList(getDefaultTargetFrame()
2648 .getFeatureGroupsOfState(visible));
2655 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2656 * .AlignFrame, boolean)
2659 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2661 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2667 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2668 * AlignFrame, java.lang.String, boolean)
2671 public void setFeatureGroupStateOn(final AlignFrame alf,
2672 final String groups, boolean state)
2674 final boolean st = state;// !(state==null || state.equals("") ||
2675 // state.toLowerCase().equals("false"));
2676 java.awt.EventQueue.invokeLater(new Runnable()
2681 alf.setFeatureGroupState(separatorListToArray(groups), st);
2689 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2693 public void setFeatureGroupState(String groups, boolean state)
2695 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2701 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2704 public String getSeparator()
2712 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2715 public void setSeparator(String separator)
2717 if (separator == null || separator.length() < 1)
2720 separator = "" + ((char) 0x00AC);
2722 this.separator = separator;
2725 System.err.println("Default Separator now: '" + separator + "'");
2730 * get boolean value of applet parameter 'name' and return default if
2731 * parameter is not set
2736 * the value to return otherwise
2737 * @return true or false
2739 public boolean getDefaultParameter(String name, boolean def)
2742 if ((stn = getParameter(name)) == null)
2746 if (TRUE.equalsIgnoreCase(stn))
2756 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2757 * java.lang.String, java.lang.String, java.lang.String)
2760 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2761 String pdbEntryString, String pdbFile)
2763 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2766 protected void setAlignPdbStructures(boolean alignPdbStructures)
2768 this.alignPdbStructures = alignPdbStructures;
2771 public boolean isAlignPdbStructures()
2773 return alignPdbStructures;
2779 // callInitCallback();
2782 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2784 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2786 public void setJsMessageSet(String messageclass, String viewId,
2787 String[] colcommands)
2789 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2792 msgset = new Hashtable<String, String[]>();
2793 jsmessages.put(messageclass, msgset);
2795 msgset.put(viewId, colcommands);
2796 long[] l = new long[colcommands.length];
2797 for (int i = 0; i < colcommands.length; i++)
2799 l[i] = colcommands[i].hashCode();
2801 jshashes.put(messageclass + "|" + viewId, l);
2807 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2811 public String getJsMessage(String messageclass, String viewId)
2813 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2816 String[] msgs = msgset.get(viewId);
2819 for (int i = 0; i < msgs.length; i++)
2821 if (msgs[i] != null)
2833 public boolean isJsMessageSetChanged(String string, String string2,
2834 String[] colcommands)
2836 long[] l = jshashes.get(string + "|" + string2);
2837 if (l == null && colcommands != null)
2841 for (int i = 0; i < colcommands.length; i++)
2843 if (l[i] != colcommands[i].hashCode())
2851 private Vector jsExecQueue = new Vector();
2853 public Vector getJsExecQueue()
2858 public void setExecutor(JSFunctionExec jsFunctionExec2)
2860 jsFunctionExec = jsFunctionExec2;
2864 * return the given colour value parameter or the given default if parameter
2871 public Color getDefaultColourParameter(String colparam, Color defcolour)
2873 String colprop = getParameter(colparam);
2874 if (colprop == null || colprop.trim().length() == 0)
2878 Color col = jalview.schemes.ColourSchemeProperty
2879 .getAWTColorFromName(colprop);
2884 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2885 } catch (Exception ex)
2887 System.err.println("Couldn't parse '" + colprop
2888 + "' as a colour for " + colparam);
2892 return (col == null) ? defcolour : col;
2896 public void openJalviewHelpUrl()
2898 String helpUrl = getParameter("jalviewhelpurl");
2899 if (helpUrl == null || helpUrl.trim().length() < 5)
2901 helpUrl = "http://www.jalview.org/help.html";
2903 showURL(helpUrl, "HELP");
2907 * form a complete URL given a path to a resource and a reference location on
2911 * - an absolute path on the same server as localref or a document
2912 * located relative to localref
2914 * - a URL on the same server as url
2915 * @return a complete URL for the resource located by url
2917 private String resolveUrlForLocalOrAbsolute(String targetPath,
2920 String resolvedPath = "";
2921 if (targetPath.startsWith("/"))
2923 String codebase = localref.toString();
2924 String localfile = localref.getFile();
2925 resolvedPath = codebase.substring(0,
2926 codebase.length() - localfile.length())
2928 return resolvedPath;
2932 * get URL path and strip off any trailing file e.g.
2933 * www.jalview.org/examples/index.html#applets?a=b is trimmed to
2934 * www.jalview.org/examples/
2936 String urlPath = localref.toString();
2937 String directoryPath = urlPath;
2938 int lastSeparator = directoryPath.lastIndexOf("/");
2939 if (lastSeparator > 0)
2941 directoryPath = directoryPath.substring(0, lastSeparator + 1);
2944 if (targetPath.startsWith("/"))
2947 * construct absolute URL to a file on the server - this is not allowed?
2949 // String localfile = localref.getFile();
2950 // resolvedPath = urlPath.substring(0,
2951 // urlPath.length() - localfile.length())
2953 resolvedPath = directoryPath + targetPath.substring(1);
2957 resolvedPath = directoryPath + targetPath;
2961 System.err.println("resolveUrlForLocalOrAbsolute returning "
2964 return resolvedPath;
2968 * open a URL in the browser - resolving it according to relative refs and
2969 * coping with javascript: protocol if necessary.
2974 public void showURL(String url, String target)
2978 if (url.indexOf(":") == -1)
2980 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2982 // Should really use docbase, not codebase.
2984 url = resolveUrlForLocalOrAbsolute(
2986 prepend = getDefaultParameter("resolvetocodebase", false) ? getCodeBase()
2987 : getDocumentBase());
2991 .println("Show url (prepended "
2993 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
3001 System.err.println("Show url: " + url);
3004 if (url.indexOf("javascript:") == 0)
3006 // no target for the javascript context
3007 getAppletContext().showDocument(new java.net.URL(url));
3011 getAppletContext().showDocument(new java.net.URL(url), target);
3013 } catch (Exception ex)
3015 ex.printStackTrace();
3020 * bind structures in a viewer to any matching sequences in an alignFrame (use
3021 * sequenceIds to limit scope of search to specific sequences)
3025 * @param sequenceIds
3026 * @return TODO: consider making an exception structure for indicating when
3027 * binding fails public SequenceStructureBinding
3028 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
3031 * if (sequenceIds != null && sequenceIds.length() > 0) { return
3032 * alFrame.addStructureViewInstance(viewer,
3033 * separatorListToArray(sequenceIds)); } else { return
3034 * alFrame.addStructureViewInstance(viewer, null); } // return null; }