2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.datamodel.Alignment;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AlignmentOrder;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.PDBEntry;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.io.AnnotationFile;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.FileParse;
39 import jalview.io.IdentifyFile;
40 import jalview.io.JnetAnnotationMaker;
41 import jalview.javascript.JSFunctionExec;
42 import jalview.javascript.JalviewLiteJsApi;
43 import jalview.javascript.JsCallBack;
44 import jalview.structure.SelectionListener;
45 import jalview.structure.StructureSelectionManager;
46 import jalview.util.MessageManager;
48 import java.applet.Applet;
49 import java.awt.Button;
50 import java.awt.Color;
51 import java.awt.Component;
52 import java.awt.EventQueue;
54 import java.awt.Frame;
55 import java.awt.Graphics;
56 import java.awt.event.ActionEvent;
57 import java.awt.event.WindowAdapter;
58 import java.awt.event.WindowEvent;
59 import java.io.BufferedReader;
60 import java.io.InputStreamReader;
62 import java.util.Hashtable;
63 import java.util.StringTokenizer;
64 import java.util.Vector;
66 import netscape.javascript.JSException;
67 import netscape.javascript.JSObject;
70 * Jalview Applet. Runs in Java 1.18 runtime
73 * @version $Revision: 1.92 $
75 public class JalviewLite extends Applet implements
76 StructureSelectionManagerProvider, JalviewLiteJsApi
79 public StructureSelectionManager getStructureSelectionManager()
81 return StructureSelectionManager.getStructureSelectionManager(this);
84 // /////////////////////////////////////////
85 // The following public methods maybe called
86 // externally, eg via javascript in HTML page
90 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
92 public String getSelectedSequences()
94 return getSelectedSequencesFrom(getDefaultTargetFrame());
100 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
102 public String getSelectedSequences(String sep)
104 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
111 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
114 public String getSelectedSequencesFrom(AlignFrame alf)
116 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
123 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
124 * .AlignFrame, java.lang.String)
126 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
128 StringBuffer result = new StringBuffer("");
129 if (sep == null || sep.length() == 0)
131 sep = separator; // "+0x00AC;
133 if (alf.viewport.getSelectionGroup() != null)
135 SequenceI[] seqs = alf.viewport.getSelectionGroup()
136 .getSequencesInOrder(alf.viewport.getAlignment());
138 for (int i = 0; i < seqs.length; i++)
140 result.append(seqs[i].getName());
145 return result.toString();
151 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
152 * java.lang.String, java.lang.String)
154 public void highlight(String sequenceId, String position,
155 String alignedPosition)
157 highlightIn(getDefaultTargetFrame(), sequenceId, position,
164 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
165 * java.lang.String, java.lang.String, java.lang.String)
167 public void highlightIn(final AlignFrame alf, final String sequenceId,
168 final String position, final String alignedPosition)
170 // TODO: could try to highlight in all alignments if alf==null
171 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
172 alf.viewport.getAlignment().getSequencesArray());
173 final SequenceI sq = matcher.findIdMatch(sequenceId);
179 apos = new Integer(position).intValue();
181 } catch (NumberFormatException ex)
185 final StructureSelectionManagerProvider me = this;
186 final int pos = apos;
187 // use vamsas listener to broadcast to all listeners in scope
188 if (alignedPosition != null
189 && (alignedPosition.trim().length() == 0 || alignedPosition
190 .toLowerCase().indexOf("false") > -1))
192 java.awt.EventQueue.invokeLater(new Runnable()
197 StructureSelectionManager.getStructureSelectionManager(me)
198 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
204 java.awt.EventQueue.invokeLater(new Runnable()
209 StructureSelectionManager.getStructureSelectionManager(me)
210 .mouseOverVamsasSequence(sq, pos, null);
220 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
223 public void select(String sequenceIds, String columns)
225 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
231 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
232 * java.lang.String, java.lang.String)
234 public void select(String sequenceIds, String columns, String sep)
236 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
242 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
243 * java.lang.String, java.lang.String)
245 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
247 selectIn(alf, sequenceIds, columns, separator);
253 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
254 * java.lang.String, java.lang.String, java.lang.String)
256 public void selectIn(final AlignFrame alf, String sequenceIds,
257 String columns, String sep)
259 if (sep == null || sep.length() == 0)
267 System.err.println("Selecting region using separator string '"
272 String[] ids = separatorListToArray(sequenceIds, sep);
273 String[] cols = separatorListToArray(columns, sep);
274 final SequenceGroup sel = new SequenceGroup();
275 final ColumnSelection csel = new ColumnSelection();
276 AlignmentI al = alf.viewport.getAlignment();
277 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
278 alf.viewport.getAlignment().getSequencesArray());
279 int start = 0, end = al.getWidth(), alw = al.getWidth();
280 boolean seqsfound = true;
281 if (ids != null && ids.length > 0)
284 for (int i = 0; i < ids.length; i++)
286 if (ids[i].trim().length() == 0)
290 SequenceI sq = matcher.findIdMatch(ids[i]);
294 sel.addSequence(sq, false);
298 boolean inseqpos = false;
299 if (cols != null && cols.length > 0)
301 boolean seset = false;
302 for (int i = 0; i < cols.length; i++)
304 String cl = cols[i].trim();
305 if (cl.length() == 0)
310 if ((p = cl.indexOf("-")) > -1)
312 int from = -1, to = -1;
315 from = new Integer(cl.substring(0, p)).intValue();
317 } catch (NumberFormatException ex)
320 .println("ERROR: Couldn't parse first integer in range element column selection string '"
321 + cl + "' - format is 'from-to'");
326 to = new Integer(cl.substring(p + 1)).intValue();
328 } catch (NumberFormatException ex)
331 .println("ERROR: Couldn't parse second integer in range element column selection string '"
332 + cl + "' - format is 'from-to'");
335 if (from >= 0 && to >= 0)
352 // comment to prevent range extension
362 for (int r = from; r <= to; r++)
364 if (r >= 0 && r < alw)
371 System.err.println("Range '" + cl + "' deparsed as [" + from
377 System.err.println("ERROR: Invalid Range '" + cl
378 + "' deparsed as [" + from + "," + to + "]");
386 r = new Integer(cl).intValue();
388 } catch (NumberFormatException ex)
390 if (cl.toLowerCase().equals("sequence"))
392 // we are in the dataset sequence's coordinate frame.
398 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
403 if (r >= 0 && r <= alw)
413 // comment to prevent range extension
426 System.err.println("Point selection '" + cl
427 + "' deparsed as [" + r + "]");
432 System.err.println("ERROR: Invalid Point selection '" + cl
433 + "' deparsed as [" + r + "]");
440 // we only propagate the selection when it was the null selection, or the
441 // given sequences were found in the alignment.
442 if (inseqpos && sel.getSize() > 0)
444 // assume first sequence provides reference frame ?
445 SequenceI rs = sel.getSequenceAt(0);
446 start = rs.findIndex(start);
447 end = rs.findIndex(end);
450 Vector cs = csel.getSelected();
452 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
454 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
459 sel.setStartRes(start);
461 EventQueue.invokeLater(new Runnable()
466 alf.select(sel, csel);
476 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
477 * String, java.lang.String)
479 public String getSelectedSequencesAsAlignment(String format, String suffix)
481 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
489 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
490 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
492 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
493 String format, String suffix)
497 boolean seqlimits = suffix.equalsIgnoreCase("true");
498 if (alf.viewport.getSelectionGroup() != null)
500 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
501 // method now returns a full copy of sequence data
502 // TODO consider using getSequenceSelection instead here
503 String reply = new AppletFormatAdapter().formatSequences(format,
504 new Alignment(alf.viewport.getSelectionAsNewSequence()),
508 } catch (Exception ex)
510 ex.printStackTrace();
511 return "Error retrieving alignment in " + format + " format. ";
519 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
521 public String getAlignmentOrder()
523 return getAlignmentOrderFrom(getDefaultTargetFrame());
530 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
533 public String getAlignmentOrderFrom(AlignFrame alf)
535 return getAlignmentOrderFrom(alf, separator);
542 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
543 * , java.lang.String)
545 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
547 AlignmentI alorder = alf.getAlignViewport().getAlignment();
548 String[] order = new String[alorder.getHeight()];
549 for (int i = 0; i < order.length; i++)
551 order[i] = alorder.getSequenceAt(i).getName();
553 return arrayToSeparatorList(order);
559 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
562 public String orderBy(String order, String undoName)
564 return orderBy(order, undoName, separator);
570 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
571 * java.lang.String, java.lang.String)
573 public String orderBy(String order, String undoName, String sep)
575 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
582 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
583 * java.lang.String, java.lang.String, java.lang.String)
585 public String orderAlignmentBy(AlignFrame alf, String order,
586 String undoName, String sep)
588 String[] ids = separatorListToArray(order, sep);
589 SequenceI[] sqs = null;
590 if (ids != null && ids.length > 0)
592 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
593 alf.viewport.getAlignment().getSequencesArray());
595 sqs = new SequenceI[ids.length];
596 for (int i = 0; i < ids.length; i++)
598 if (ids[i].trim().length() == 0)
602 SequenceI sq = matcher.findIdMatch(ids[i]);
610 SequenceI[] sqq = new SequenceI[s];
611 System.arraycopy(sqs, 0, sqq, 0, s);
624 final AlignmentOrder aorder = new AlignmentOrder(sqs);
626 if (undoName != null && undoName.trim().length() == 0)
630 final String _undoName = undoName;
631 // TODO: deal with synchronization here: cannot raise any events until after
632 // this has returned.
633 return alf.sortBy(aorder, _undoName) ? "true" : "";
639 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
641 public String getAlignment(String format)
643 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
650 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
653 public String getAlignmentFrom(AlignFrame alf, String format)
655 return getAlignmentFrom(alf, format, "true");
661 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
664 public String getAlignment(String format, String suffix)
666 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
673 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
674 * java.lang.String, java.lang.String)
676 public String getAlignmentFrom(AlignFrame alf, String format,
681 boolean seqlimits = suffix.equalsIgnoreCase("true");
683 String reply = new AppletFormatAdapter().formatSequences(format,
684 alf.viewport.getAlignment(), seqlimits);
686 } catch (Exception ex)
688 ex.printStackTrace();
689 return "Error retrieving alignment in " + format + " format. ";
696 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
698 public void loadAnnotation(String annotation)
700 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
707 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
708 * , java.lang.String)
710 public void loadAnnotationFrom(AlignFrame alf, String annotation)
712 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
713 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
715 alf.alignPanel.fontChanged();
716 alf.alignPanel.setScrollValues(0, 0);
720 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
727 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
729 public void loadFeatures(String features, boolean autoenabledisplay)
731 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
738 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
739 * , java.lang.String)
741 public boolean loadFeaturesFrom(AlignFrame alf, String features,
742 boolean autoenabledisplay)
744 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
751 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
753 public String getFeatures(String format)
755 return getFeaturesFrom(getDefaultTargetFrame(), format);
762 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
765 public String getFeaturesFrom(AlignFrame alf, String format)
767 return alf.outputFeatures(false, format);
773 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
775 public String getAnnotation()
777 return getAnnotationFrom(getDefaultTargetFrame());
784 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
787 public String getAnnotationFrom(AlignFrame alf)
789 return alf.outputAnnotations(false);
795 * @see jalview.bin.JalviewLiteJsApi#newView()
797 public AlignFrame newView()
799 return newViewFrom(getDefaultTargetFrame());
805 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
807 public AlignFrame newView(String name)
809 return newViewFrom(getDefaultTargetFrame(), name);
815 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
817 public AlignFrame newViewFrom(AlignFrame alf)
819 return alf.newView(null);
825 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
828 public AlignFrame newViewFrom(AlignFrame alf, String name)
830 return alf.newView(name);
836 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
839 public AlignFrame loadAlignment(String text, String title)
843 String format = new IdentifyFile().Identify(text,
844 AppletFormatAdapter.PASTE);
847 al = new AppletFormatAdapter().readFile(text,
848 AppletFormatAdapter.PASTE, format);
849 if (al.getHeight() > 0)
851 return new AlignFrame(al, this, title, false);
853 } catch (java.io.IOException ex)
855 ex.printStackTrace();
863 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
865 public void setMouseoverListener(String listener)
867 setMouseoverListener(currentAlignFrame, listener);
870 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
876 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
877 * , java.lang.String)
879 public void setMouseoverListener(AlignFrame af, String listener)
881 if (listener != null)
883 listener = listener.trim();
884 if (listener.length() == 0)
887 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
891 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
893 javascriptListeners.addElement(mol);
894 StructureSelectionManager.getStructureSelectionManager(this)
895 .addStructureViewerListener(mol);
898 System.err.println("Added a mouseover listener for "
899 + ((af == null) ? "All frames" : "Just views for "
900 + af.getAlignViewport().getSequenceSetId()));
901 System.err.println("There are now " + javascriptListeners.size()
902 + " listeners in total.");
909 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
911 public void setSelectionListener(String listener)
913 setSelectionListener(null, listener);
920 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
921 * , java.lang.String)
923 public void setSelectionListener(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 selection listener.");
935 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
937 javascriptListeners.addElement(mol);
938 StructureSelectionManager.getStructureSelectionManager(this)
939 .addSelectionListener(mol);
942 System.err.println("Added a selection 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#setStructureListener(java.lang.String,
956 public void setStructureListener(String listener, String modelSet)
958 if (listener != null)
960 listener = listener.trim();
961 if (listener.length() == 0)
964 .println("jalview Javascript error: Ignoring empty function for selection listener.");
968 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
969 this, listener, separatorListToArray(modelSet));
970 javascriptListeners.addElement(mol);
971 StructureSelectionManager.getStructureSelectionManager(this)
972 .addStructureViewerListener(mol);
975 System.err.println("Added a javascript structure viewer listener '"
977 System.err.println("There are now " + javascriptListeners.size()
978 + " listeners in total.");
986 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
987 * .AlignFrame, java.lang.String)
989 public void removeJavascriptListener(AlignFrame af, String listener)
991 if (listener != null)
993 listener = listener.trim();
994 if (listener.length() == 0)
999 boolean rprt = false;
1000 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1002 Object lstn = javascriptListeners.elementAt(ms);
1003 JsCallBack lstner = (JsCallBack) lstn;
1004 if ((af == null || lstner.getAlignFrame() == af)
1005 && (listener == null || lstner.getListenerFunction().equals(
1008 javascriptListeners.removeElement(lstner);
1010 if (lstner instanceof SelectionListener)
1012 StructureSelectionManager.getStructureSelectionManager(this)
1013 .removeSelectionListener((SelectionListener) lstner);
1017 StructureSelectionManager.getStructureSelectionManager(this)
1018 .removeStructureViewerListener(lstner, null);
1023 System.err.println("Removed listener '" + listener + "'");
1033 System.err.println("There are now " + javascriptListeners.size()
1034 + " listeners in total.");
1040 System.err.println("Applet " + getName() + " stop().");
1044 public void destroy()
1046 System.err.println("Applet " + getName() + " destroy().");
1050 private void tidyUp()
1053 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1054 && currentAlignFrame.viewport.applet != null)
1056 AlignViewport av = currentAlignFrame.viewport;
1057 currentAlignFrame.closeMenuItem_actionPerformed();
1059 currentAlignFrame = null;
1061 if (javascriptListeners != null)
1063 while (javascriptListeners.size() > 0)
1065 jalview.javascript.JSFunctionExec mol = javascriptListeners
1067 javascriptListeners.removeElement(mol);
1068 if (mol instanceof SelectionListener)
1070 StructureSelectionManager.getStructureSelectionManager(this)
1071 .removeSelectionListener((SelectionListener) mol);
1075 StructureSelectionManager.getStructureSelectionManager(this)
1076 .removeStructureViewerListener(mol, null);
1081 if (jsFunctionExec != null)
1083 jsFunctionExec.stopQueue();
1084 jsFunctionExec.jvlite = null;
1086 initialAlignFrame = null;
1087 jsFunctionExec = null;
1088 javascriptListeners = null;
1089 StructureSelectionManager.release(this);
1092 private jalview.javascript.JSFunctionExec jsFunctionExec;
1097 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1098 * java.lang.String, java.lang.String)
1100 public void mouseOverStructure(final String pdbResNum,
1101 final String chain, final String pdbfile)
1103 final StructureSelectionManagerProvider me = this;
1104 java.awt.EventQueue.invokeLater(new Runnable()
1111 StructureSelectionManager.getStructureSelectionManager(me)
1112 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1116 System.err.println("mouseOver for '" + pdbResNum
1117 + "' in chain '" + chain + "' in structure '" + pdbfile
1120 } catch (NumberFormatException e)
1122 System.err.println("Ignoring invalid residue number string '"
1134 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1135 * java.lang.String, java.lang.String)
1137 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1138 final String leftHandColumn)
1140 java.awt.EventQueue.invokeLater(new Runnable()
1147 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1148 leftHandColumn).intValue());
1150 } catch (Exception ex)
1152 System.err.println("Couldn't parse integer arguments (topRow='"
1153 + topRow + "' and leftHandColumn='" + leftHandColumn
1155 ex.printStackTrace();
1165 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1166 * .AlignFrame, java.lang.String)
1169 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1172 java.awt.EventQueue.invokeLater(new Runnable()
1179 alf.scrollToRow(new Integer(topRow).intValue());
1181 } catch (Exception ex)
1183 System.err.println("Couldn't parse integer arguments (topRow='"
1185 ex.printStackTrace();
1196 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1197 * .AlignFrame, java.lang.String)
1200 public void scrollViewToColumnIn(final AlignFrame alf,
1201 final String leftHandColumn)
1203 java.awt.EventQueue.invokeLater(new Runnable()
1211 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1213 } catch (Exception ex)
1216 .println("Couldn't parse integer arguments (leftHandColumn='"
1217 + leftHandColumn + "')");
1218 ex.printStackTrace();
1225 // //////////////////////////////////////////////
1226 // //////////////////////////////////////////////
1228 public static int lastFrameX = 200;
1230 public static int lastFrameY = 200;
1232 boolean fileFound = true;
1234 String file = "No file";
1236 Button launcher = new Button("Start Jalview");
1239 * The currentAlignFrame is static, it will change if and when the user
1240 * selects a new window. Note that it will *never* point back to the embedded
1241 * AlignFrame if the applet is started as embedded on the page and then
1242 * afterwards a new view is created.
1244 public AlignFrame currentAlignFrame = null;
1247 * This is the first frame to be displayed, and does not change. API calls
1248 * will default to this instance if currentAlignFrame is null.
1250 AlignFrame initialAlignFrame = null;
1252 boolean embedded = false;
1254 private boolean checkForJmol = true;
1256 private boolean checkedForJmol = false; // ensure we don't check for jmol
1258 // every time the app is re-inited
1260 public boolean jmolAvailable = false;
1262 private boolean alignPdbStructures = false;
1265 * use an external structure viewer exclusively (no jmols or MCViews will be
1266 * opened by JalviewLite itself)
1268 public boolean useXtrnalSviewer = false;
1270 public static boolean debug = false;
1272 static String builddate = null, version = null;
1274 private static void initBuildDetails()
1276 if (builddate == null)
1278 builddate = "unknown";
1280 java.net.URL url = JalviewLite.class
1281 .getResource("/.build_properties");
1286 BufferedReader reader = new BufferedReader(new InputStreamReader(
1289 while ((line = reader.readLine()) != null)
1291 if (line.indexOf("VERSION") > -1)
1293 version = line.substring(line.indexOf("=") + 1);
1295 if (line.indexOf("BUILD_DATE") > -1)
1297 builddate = line.substring(line.indexOf("=") + 1);
1300 } catch (Exception ex)
1302 ex.printStackTrace();
1308 public static String getBuildDate()
1314 public static String getVersion()
1320 // public JSObject scriptObject = null;
1323 * init method for Jalview Applet
1327 // remove any handlers that might be hanging around from an earlier instance
1332 System.err.println("Applet context is '"
1333 + getAppletContext().getClass().toString() + "'");
1335 JSObject scriptObject = JSObject.getWindow(this);
1336 if (debug && scriptObject != null)
1338 System.err.println("Applet has Javascript callback support.");
1341 } catch (Exception ex)
1344 .println("Warning: No JalviewLite javascript callbacks available.");
1347 ex.printStackTrace();
1351 * turn on extra applet debugging
1353 String dbg = getParameter("debug");
1356 debug = dbg.toLowerCase().equals("true");
1361 System.err.println("JalviewLite Version " + getVersion());
1362 System.err.println("Build Date : " + getBuildDate());
1365 String externalsviewer = getParameter("externalstructureviewer");
1366 if (externalsviewer != null)
1368 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1372 * if true disable the check for jmol
1374 String chkforJmol = getParameter("nojmol");
1375 if (chkforJmol != null)
1377 checkForJmol = !chkforJmol.equals("true");
1380 * get the separator parameter if present
1382 String sep = getParameter("separator");
1385 if (sep.length() > 0)
1390 System.err.println("Separator set to '" + separator + "'");
1395 throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
1401 String param = getParameter("RGB");
1407 r = Integer.parseInt(param.substring(0, 2), 16);
1408 g = Integer.parseInt(param.substring(2, 4), 16);
1409 b = Integer.parseInt(param.substring(4, 6), 16);
1410 } catch (Exception ex)
1417 param = getParameter("label");
1420 launcher.setLabel(param);
1423 setBackground(new Color(r, g, b));
1425 file = getParameter("file");
1429 // Maybe the sequences are added as parameters
1430 StringBuffer data = new StringBuffer("PASTE");
1432 while ((file = getParameter("sequence" + i)) != null)
1434 data.append(file.toString() + "\n");
1437 if (data.length() > 5)
1439 file = data.toString();
1443 final JalviewLite jvapplet = this;
1444 if (getParameter("embedded") != null
1445 && getParameter("embedded").equalsIgnoreCase("true"))
1447 // Launch as embedded applet in page
1449 LoadingThread loader = new LoadingThread(file, jvapplet);
1452 else if (file != null)
1454 if (getParameter("showbutton") == null
1455 || !getParameter("showbutton").equalsIgnoreCase("false"))
1457 // Add the JalviewLite 'Button' to the page
1459 launcher.addActionListener(new java.awt.event.ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 LoadingThread loader = new LoadingThread(file, jvapplet);
1470 // Open jalviewLite immediately.
1471 LoadingThread loader = new LoadingThread(file, jvapplet);
1477 // jalview initialisation with no alignment. loadAlignment() method can
1478 // still be called to open new alignments.
1485 private void initLiveConnect()
1487 // try really hard to get the liveConnect thing working
1488 boolean notFailed = false;
1490 while (!notFailed && tries < 10)
1494 System.err.println("LiveConnect request thread going to sleep.");
1498 Thread.sleep(700 * (1 + tries));
1499 } catch (InterruptedException q)
1505 System.err.println("LiveConnect request thread woken up.");
1509 JSObject scriptObject = JSObject.getWindow(this);
1510 if (scriptObject.eval("navigator") != null)
1514 } catch (JSException jsex)
1516 System.err.println("Attempt " + tries
1517 + " to access LiveConnect javascript failed.");
1522 private void callInitCallback()
1524 String initjscallback = getParameter("oninit");
1525 if (initjscallback == null)
1529 initjscallback = initjscallback.trim();
1530 if (initjscallback.length() > 0)
1532 JSObject scriptObject = null;
1535 scriptObject = JSObject.getWindow(this);
1536 } catch (Exception ex)
1540 // try really hard to let the browser plugin know we want liveconnect
1543 if (scriptObject != null)
1547 // do onInit with the JS executor thread
1548 new JSFunctionExec(this).executeJavascriptFunction(true,
1549 initjscallback, null, "Calling oninit callback '"
1550 + initjscallback + "'.");
1551 } catch (Exception e)
1553 System.err.println("Exception when executing _oninit callback '"
1554 + initjscallback + "'.");
1555 e.printStackTrace();
1560 System.err.println("Not executing _oninit callback '"
1561 + initjscallback + "' - no scripting allowed.");
1567 * Initialises and displays a new java.awt.Frame
1570 * java.awt.Frame to be displayed
1572 * title of new frame
1574 * width if new frame
1576 * height of new frame
1578 public static void addFrame(final Frame frame, String title, int width,
1581 frame.setLocation(lastFrameX, lastFrameY);
1584 frame.setSize(width, height);
1585 frame.setTitle(title);
1586 frame.addWindowListener(new WindowAdapter()
1588 public void windowClosing(WindowEvent e)
1590 if (frame instanceof AlignFrame)
1592 AlignViewport vp = ((AlignFrame) frame).viewport;
1593 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1594 if (vp.applet.currentAlignFrame == frame)
1596 vp.applet.currentAlignFrame = null;
1604 if (frame instanceof EmbmenuFrame)
1606 ((EmbmenuFrame) frame).destroyMenus();
1608 frame.setMenuBar(null);
1612 public void windowActivated(WindowEvent e)
1614 if (frame instanceof AlignFrame)
1616 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1619 System.err.println("Activated window " + frame);
1623 super.windowActivated(e);
1626 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1629 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1632 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1633 * frame) { currentAlignFrame = null; if (debug) {
1634 * System.err.println("Deactivated window "+frame); } }
1635 * super.windowDeactivated(e); }
1638 frame.setVisible(true);
1642 * This paints the background surrounding the "Launch Jalview button" <br>
1644 * If file given in parameter not found, displays error message
1649 public void paint(Graphics g)
1653 g.setColor(new Color(200, 200, 200));
1654 g.setColor(Color.cyan);
1655 g.fillRect(0, 0, getSize().width, getSize().height);
1656 g.setColor(Color.red);
1658 MessageManager.getString("label.jalview_cannot_open_file"),
1660 g.drawString("\"" + file + "\"", 5, 30);
1664 g.setColor(Color.black);
1665 g.setFont(new Font("Arial", Font.BOLD, 24));
1666 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1667 getSize().height / 2 - 30);
1668 g.drawString(MessageManager.getString("label.loading_data") + "...",
1669 50, getSize().height / 2);
1674 * get all components associated with the applet of the given type
1679 public Vector getAppletWindow(Class class1)
1681 Vector wnds = new Vector();
1682 Component[] cmp = getComponents();
1685 for (int i = 0; i < cmp.length; i++)
1687 if (class1.isAssignableFrom(cmp[i].getClass()))
1689 wnds.addElement(cmp);
1696 class LoadJmolThread extends Thread
1698 private boolean running = false;
1702 if (running || checkedForJmol)
1711 if (!System.getProperty("java.version").startsWith("1.1"))
1713 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1714 jmolAvailable = true;
1719 .println("Jmol not available - Using MCview for structures");
1721 } catch (java.lang.ClassNotFoundException ex)
1727 jmolAvailable = false;
1731 .println("Skipping Jmol check. Will use MCView (probably)");
1734 checkedForJmol = true;
1738 public boolean notFinished()
1740 return running || !checkedForJmol;
1744 class LoadingThread extends Thread
1747 * State variable: File source
1752 * State variable: protocol for access to file source
1757 * State variable: format of file source
1765 private void dbgMsg(String msg)
1769 System.err.println(msg);
1774 * update the protocol state variable for accessing the datasource located
1778 * @return possibly updated datasource string
1780 public String setProtocolState(String file)
1782 if (file.startsWith("PASTE"))
1784 file = file.substring(5);
1785 protocol = AppletFormatAdapter.PASTE;
1787 else if (inArchive(file))
1789 protocol = AppletFormatAdapter.CLASSLOADER;
1793 file = addProtocol(file);
1794 protocol = AppletFormatAdapter.URL;
1796 dbgMsg("Protocol identified as '" + protocol + "'");
1800 public LoadingThread(String _file, JalviewLite _applet)
1808 LoadJmolThread jmolchecker = new LoadJmolThread();
1809 jmolchecker.start();
1810 while (jmolchecker.notFinished())
1812 // wait around until the Jmol check is complete.
1816 } catch (Exception e)
1822 // applet.callInitCallback();
1825 private void startLoading()
1827 AlignFrame newAlignFrame;
1828 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1829 file = setProtocolState(_file);
1831 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1832 dbgMsg("File identified as '" + format + "'");
1833 dbgMsg("Loading started.");
1834 Alignment al = null;
1837 al = new AppletFormatAdapter().readFile(file, protocol, format);
1838 } catch (java.io.IOException ex)
1840 dbgMsg("File load exception.");
1841 ex.printStackTrace();
1846 FileParse fp = new FileParse(file, protocol);
1848 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1850 while ((ln = fp.nextLine()) != null)
1854 dbgMsg(">>>Dump finished.");
1855 } catch (Exception e)
1858 .println("Exception when trying to dump the content of the file parameter.");
1859 e.printStackTrace();
1863 if ((al != null) && (al.getHeight() > 0))
1865 dbgMsg("Successfully loaded file.");
1866 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1867 if (initialAlignFrame == null)
1869 initialAlignFrame = newAlignFrame;
1871 // update the focus.
1872 currentAlignFrame = newAlignFrame;
1874 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1876 newAlignFrame.setTitle(MessageManager.formatMessage(
1877 "label.sequences_from", new String[]
1878 { applet.getDocumentBase().toString() }));
1881 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1882 "label.successfully_loaded_file", new String[]
1885 String treeFile = applet.getParameter("tree");
1886 if (treeFile == null)
1888 treeFile = applet.getParameter("treeFile");
1891 if (treeFile != null)
1895 treeFile = setProtocolState(treeFile);
1897 * if (inArchive(treeFile)) { protocol =
1898 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1899 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1901 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1906 if (fin.getTree() != null)
1908 newAlignFrame.loadTree(fin, treeFile);
1909 dbgMsg("Successfuly imported tree.");
1913 dbgMsg("Tree parameter did not resolve to a valid tree.");
1915 } catch (Exception ex)
1917 ex.printStackTrace();
1922 * Try to load T-Coffee score file
1924 String sScoreFile = applet.getParameter("scoreFile");
1925 if (sScoreFile != null && !"".equals(sScoreFile))
1932 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
1934 if (!newAlignFrame.loadScoreFile(sScoreFile))
1937 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
1938 + sScoreFile + "')");
1940 } catch (Exception e)
1942 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
1943 sScoreFile, e.getMessage());
1947 // ///////////////////////////
1948 // modify display of features
1949 // we do this before any features have been loaded, ensuring any hidden
1950 // groups are hidden when features first displayed
1952 // hide specific groups
1954 String param = applet.getParameter("hidefeaturegroups");
1957 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1959 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1961 // show specific groups
1962 param = applet.getParameter("showfeaturegroups");
1965 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1967 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1969 // and now load features
1970 param = applet.getParameter("features");
1973 param = setProtocolState(param);
1975 newAlignFrame.parseFeaturesFile(param, protocol);
1978 param = applet.getParameter("showFeatureSettings");
1979 if (param != null && param.equalsIgnoreCase("true"))
1981 newAlignFrame.viewport.showSequenceFeatures(true);
1982 new FeatureSettings(newAlignFrame.alignPanel);
1985 param = applet.getParameter("annotations");
1988 param = setProtocolState(param);
1990 if (new AnnotationFile().readAnnotationFile(
1991 newAlignFrame.viewport.getAlignment(), param, protocol))
1993 newAlignFrame.alignPanel.fontChanged();
1994 newAlignFrame.alignPanel.setScrollValues(0, 0);
1999 .println("Annotations were not added from annotation file '"
2005 param = applet.getParameter("jnetfile");
2010 param = setProtocolState(param);
2011 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
2013 JnetAnnotationMaker.add_annotation(predictions,
2014 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
2022 newAlignFrame.alignPanel.fontChanged();
2023 newAlignFrame.alignPanel.setScrollValues(0, 0);
2024 } catch (Exception ex)
2026 ex.printStackTrace();
2030 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
2031 * - related to JAL-434
2033 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2036 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2039 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2041 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2044 int pdbFileCount = 0;
2045 // Accumulate pdbs here if they are heading for the same view (if
2046 // alignPdbStructures is true)
2047 Vector pdbs = new Vector();
2048 // create a lazy matcher if we're asked to
2049 jalview.analysis.SequenceIdMatcher matcher = (applet
2050 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2051 newAlignFrame.getAlignViewport().getAlignment()
2052 .getSequencesArray()) : null;
2056 if (pdbFileCount > 0)
2058 param = applet.getParameter("PDBFILE" + pdbFileCount);
2062 param = applet.getParameter("PDBFILE");
2067 PDBEntry pdb = new PDBEntry();
2070 SequenceI[] seqs = null;
2071 String[] chains = null;
2073 StringTokenizer st = new StringTokenizer(param, " ");
2075 if (st.countTokens() < 2)
2077 String sequence = applet.getParameter("PDBSEQ");
2078 if (sequence != null)
2080 seqs = new SequenceI[]
2081 { matcher == null ? (Sequence) newAlignFrame
2082 .getAlignViewport().getAlignment()
2083 .findName(sequence) : matcher.findIdMatch(sequence) };
2089 param = st.nextToken();
2090 Vector tmp = new Vector();
2091 Vector tmp2 = new Vector();
2093 while (st.hasMoreTokens())
2095 seqstring = st.nextToken();
2096 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2097 if (st2.countTokens() > 1)
2099 // This is the chain
2100 tmp2.addElement(st2.nextToken());
2101 seqstring = st2.nextToken();
2103 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
2104 .getAlignViewport().getAlignment()
2105 .findName(seqstring) : matcher
2106 .findIdMatch(seqstring));
2109 seqs = new SequenceI[tmp.size()];
2111 if (tmp2.size() == tmp.size())
2113 chains = new String[tmp2.size()];
2114 tmp2.copyInto(chains);
2117 param = setProtocolState(param);
2119 if (// !jmolAvailable
2121 protocol == AppletFormatAdapter.CLASSLOADER
2122 && !useXtrnalSviewer)
2124 // Re: JAL-357 : the bug isn't a problem if we are using an
2126 // TODO: verify this Re:
2127 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2128 // This exception preserves the current behaviour where, even if
2129 // the local pdb file was identified in the class loader
2130 protocol = AppletFormatAdapter.URL; // this is probably NOT
2132 param = addProtocol(param); //
2139 for (int i = 0; i < seqs.length; i++)
2141 if (seqs[i] != null)
2143 ((Sequence) seqs[i]).addPDBId(pdb);
2144 StructureSelectionManager.getStructureSelectionManager(
2145 applet).registerPDBEntry(pdb);
2149 if (JalviewLite.debug)
2151 // this may not really be a problem but we give a warning
2154 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2160 if (!alignPdbStructures)
2162 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
2167 pdbs.addElement(new Object[]
2168 { pdb, seqs, chains, new String(protocol) });
2174 } while (param != null || pdbFileCount < 10);
2175 if (pdbs.size() > 0)
2177 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2178 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2179 String[][] chains = new String[pdbs.size()][];
2180 String[] protocols = new String[pdbs.size()];
2181 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2183 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2184 pdb[pdbsi] = (PDBEntry) o[0];
2185 seqs[pdbsi] = (SequenceI[]) o[1];
2186 chains[pdbsi] = (String[]) o[2];
2187 protocols[pdbsi] = (String) o[3];
2189 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
2197 applet.remove(launcher);
2204 * Discovers whether the given file is in the Applet Archive
2210 boolean inArchive(String file)
2212 // This might throw a security exception in certain browsers
2213 // Netscape Communicator for instance.
2216 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2219 System.err.println("Resource '" + file + "' was "
2220 + (rtn ? "" : "not") + " located by classloader.");
2223 } catch (Exception ex)
2225 System.out.println("Exception checking resources: " + file + " "
2231 String addProtocol(String file)
2233 if (file.indexOf("://") == -1)
2235 String fl = applet.resolveUrlForLocalOrAbsolute(file,
2239 if (new java.net.URL(fl).openStream() != null)
2243 System.err.println("Prepended document base for resource: '"
2248 } catch (Exception x)
2252 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2255 if (new java.net.URL(fl).openStream() != null)
2259 System.err.println("Prepended codebase for resource: '"
2264 } catch (Exception x)
2276 * @return the default alignFrame acted on by the public applet methods. May
2277 * return null with an error message on System.err indicating the
2280 public AlignFrame getDefaultTargetFrame()
2282 if (currentAlignFrame != null)
2284 return currentAlignFrame;
2286 if (initialAlignFrame != null)
2288 return initialAlignFrame;
2291 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2296 * separator used for separatorList
2298 protected String separator = "" + ((char) 0x00AC); // the default used to be
2299 // '|' but many sequence
2300 // IDS include pipes.
2303 * set to enable the URL based javascript execution mechanism
2305 public boolean jsfallbackEnabled = false;
2308 * parse the string into a list
2311 * @return elements separated by separator
2313 public String[] separatorListToArray(String list)
2315 return separatorListToArray(list, separator);
2319 * parse the string into a list
2323 * @return elements separated by separator
2325 public String[] separatorListToArray(String list, String separator)
2327 // note separator local variable intentionally masks object field
2328 int seplen = separator.length();
2329 if (list == null || list.equals("") || list.equals(separator))
2333 java.util.Vector jv = new Vector();
2335 while ((pos = list.indexOf(separator, cp)) > cp)
2337 jv.addElement(list.substring(cp, pos));
2340 if (cp < list.length())
2342 String c = list.substring(cp);
2343 if (!c.equals(separator))
2350 String[] v = new String[jv.size()];
2351 for (int i = 0; i < v.length; i++)
2353 v[i] = (String) jv.elementAt(i);
2355 jv.removeAllElements();
2358 System.err.println("Array from '" + separator
2359 + "' separated List:\n" + v.length);
2360 for (int i = 0; i < v.length; i++)
2362 System.err.println("item " + i + " '" + v[i] + "'");
2369 System.err.println("Empty Array from '" + separator
2370 + "' separated List");
2376 * concatenate the list with separator
2379 * @return concatenated string
2381 public String arrayToSeparatorList(String[] list)
2383 return arrayToSeparatorList(list, separator);
2387 * concatenate the list with separator
2391 * @return concatenated string
2393 public String arrayToSeparatorList(String[] list, String separator)
2395 StringBuffer v = new StringBuffer();
2396 if (list != null && list.length > 0)
2398 for (int i = 0, iSize = list.length; i < iSize; i++)
2400 if (list[i] != null)
2404 v.append(separator);
2411 System.err.println("Returning '" + separator
2412 + "' separated List:\n");
2413 System.err.println(v);
2415 return v.toString();
2419 System.err.println("Returning empty '" + separator
2420 + "' separated List\n");
2422 return "" + separator;
2428 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2430 public String getFeatureGroups()
2432 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2433 .getFeatureGroups());
2441 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2444 public String getFeatureGroupsOn(AlignFrame alf)
2446 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2453 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2455 public String getFeatureGroupsOfState(boolean visible)
2457 return arrayToSeparatorList(getDefaultTargetFrame()
2458 .getFeatureGroupsOfState(visible));
2465 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2466 * .AlignFrame, boolean)
2468 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2470 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2476 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2477 * AlignFrame, java.lang.String, boolean)
2479 public void setFeatureGroupStateOn(final AlignFrame alf,
2480 final String groups, boolean state)
2482 final boolean st = state;// !(state==null || state.equals("") ||
2483 // state.toLowerCase().equals("false"));
2484 java.awt.EventQueue.invokeLater(new Runnable()
2489 alf.setFeatureGroupState(separatorListToArray(groups), st);
2497 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2500 public void setFeatureGroupState(String groups, boolean state)
2502 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2508 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2510 public String getSeparator()
2518 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2520 public void setSeparator(String separator)
2522 if (separator == null || separator.length() < 1)
2525 separator = "" + ((char) 0x00AC);
2527 this.separator = separator;
2530 System.err.println("Default Separator now: '" + separator + "'");
2535 * get boolean value of applet parameter 'name' and return default if
2536 * parameter is not set
2541 * the value to return otherwise
2542 * @return true or false
2544 public boolean getDefaultParameter(String name, boolean def)
2547 if ((stn = getParameter(name)) == null)
2551 if (stn.toLowerCase().equals("true"))
2561 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2562 * java.lang.String, java.lang.String, java.lang.String)
2564 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2565 String pdbEntryString, String pdbFile)
2567 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2570 protected void setAlignPdbStructures(boolean alignPdbStructures)
2572 this.alignPdbStructures = alignPdbStructures;
2575 public boolean isAlignPdbStructures()
2577 return alignPdbStructures;
2582 // callInitCallback();
2585 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2587 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2589 public void setJsMessageSet(String messageclass, String viewId,
2590 String[] colcommands)
2592 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2595 msgset = new Hashtable<String, String[]>();
2596 jsmessages.put(messageclass, msgset);
2598 msgset.put(viewId, colcommands);
2599 long[] l = new long[colcommands.length];
2600 for (int i = 0; i < colcommands.length; i++)
2602 l[i] = colcommands[i].hashCode();
2604 jshashes.put(messageclass + "|" + viewId, l);
2610 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2613 public String getJsMessage(String messageclass, String viewId)
2615 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2618 String[] msgs = msgset.get(viewId);
2621 for (int i = 0; i < msgs.length; i++)
2623 if (msgs[i] != null)
2635 public boolean isJsMessageSetChanged(String string, String string2,
2636 String[] colcommands)
2638 long[] l = jshashes.get(string + "|" + string2);
2639 if (l == null && colcommands != null)
2643 for (int i = 0; i < colcommands.length; i++)
2645 if (l[i] != colcommands[i].hashCode())
2653 private Vector jsExecQueue = new Vector();
2655 public Vector getJsExecQueue()
2660 public void setExecutor(JSFunctionExec jsFunctionExec2)
2662 jsFunctionExec = jsFunctionExec2;
2666 * return the given colour value parameter or the given default if parameter
2673 public Color getDefaultColourParameter(String colparam, Color defcolour)
2675 String colprop = getParameter(colparam);
2676 if (colprop == null || colprop.trim().length() == 0)
2680 Color col = jalview.schemes.ColourSchemeProperty
2681 .getAWTColorFromName(colprop);
2686 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2687 } catch (Exception ex)
2689 System.err.println("Couldn't parse '" + colprop
2690 + "' as a colour for " + colparam);
2694 return (col == null) ? defcolour : col;
2698 public void openJalviewHelpUrl()
2700 String helpUrl = getParameter("jalviewhelpurl");
2701 if (helpUrl == null || helpUrl.trim().length() < 5)
2703 helpUrl = "http://www.jalview.org/help.html";
2705 showURL(helpUrl, "HELP");
2709 * form a complete URL given a path to a resource and a reference location on
2713 * - an absolute path on the same server as localref or a document
2714 * located relative to localref
2716 * - a URL on the same server as url
2717 * @return a complete URL for the resource located by url
2719 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2721 String codebase = localref.toString();
2722 if (url.indexOf("/") == 0)
2724 url = codebase.substring(0, codebase.length()
2725 - localref.getFile().length())
2730 url = localref + url;
2736 * open a URL in the browser - resolving it according to relative refs and
2737 * coping with javascript: protocol if necessary.
2742 public void showURL(String url, String target)
2746 if (url.indexOf(":") == -1)
2748 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2750 // Should really use docbase, not codebase.
2752 url = resolveUrlForLocalOrAbsolute(
2754 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2759 .println("Show url (prepended "
2761 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2769 System.err.println("Show url: " + url);
2772 if (url.indexOf("javascript:") == 0)
2774 // no target for the javascript context
2775 getAppletContext().showDocument(new java.net.URL(url));
2779 getAppletContext().showDocument(new java.net.URL(url), target);
2781 } catch (Exception ex)
2783 ex.printStackTrace();
2788 * bind structures in a viewer to any matching sequences in an alignFrame (use
2789 * sequenceIds to limit scope of search to specific sequences)
2793 * @param sequenceIds
2794 * @return TODO: consider making an exception structure for indicating when
2795 * binding fails public SequenceStructureBinding
2796 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2799 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2800 * alFrame.addStructureViewInstance(viewer,
2801 * separatorListToArray(sequenceIds)); } else { return
2802 * alFrame.addStructureViewInstance(viewer, null); } // return null; }