2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.api.StructureSelectionManagerProvider;
21 import jalview.appletgui.AlignFrame;
22 import jalview.appletgui.AlignViewport;
23 import jalview.appletgui.EmbmenuFrame;
24 import jalview.appletgui.FeatureSettings;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.AlignmentOrder;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.io.AnnotationFile;
34 import jalview.io.AppletFormatAdapter;
35 import jalview.io.FileParse;
36 import jalview.io.IdentifyFile;
37 import jalview.io.JnetAnnotationMaker;
38 import jalview.javascript.JSFunctionExec;
39 import jalview.javascript.JalviewLiteJsApi;
40 import jalview.javascript.JsCallBack;
41 import jalview.structure.SelectionListener;
42 import jalview.structure.StructureSelectionManager;
43 import jalview.util.MessageManager;
45 import java.applet.Applet;
46 import java.awt.Button;
47 import java.awt.Color;
48 import java.awt.Component;
49 import java.awt.EventQueue;
51 import java.awt.Frame;
52 import java.awt.Graphics;
53 import java.awt.event.ActionEvent;
54 import java.awt.event.WindowAdapter;
55 import java.awt.event.WindowEvent;
56 import java.io.BufferedReader;
57 import java.io.InputStreamReader;
59 import java.util.Hashtable;
60 import java.util.StringTokenizer;
61 import java.util.Vector;
63 import netscape.javascript.JSObject;
66 * Jalview Applet. Runs in Java 1.18 runtime
69 * @version $Revision: 1.92 $
71 public class JalviewLite extends Applet implements
72 StructureSelectionManagerProvider, JalviewLiteJsApi
75 public StructureSelectionManager getStructureSelectionManager()
77 return StructureSelectionManager.getStructureSelectionManager(this);
80 // /////////////////////////////////////////
81 // The following public methods maybe called
82 // externally, eg via javascript in HTML page
86 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
88 public String getSelectedSequences()
90 return getSelectedSequencesFrom(getDefaultTargetFrame());
96 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
98 public String getSelectedSequences(String sep)
100 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
107 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
110 public String getSelectedSequencesFrom(AlignFrame alf)
112 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
119 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
120 * .AlignFrame, java.lang.String)
122 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
124 StringBuffer result = new StringBuffer("");
125 if (sep == null || sep.length() == 0)
127 sep = separator; // "+0x00AC;
129 if (alf.viewport.getSelectionGroup() != null)
131 SequenceI[] seqs = alf.viewport.getSelectionGroup()
132 .getSequencesInOrder(alf.viewport.getAlignment());
134 for (int i = 0; i < seqs.length; i++)
136 result.append(seqs[i].getName());
141 return result.toString();
147 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
148 * java.lang.String, java.lang.String)
150 public void highlight(String sequenceId, String position,
151 String alignedPosition)
153 highlightIn(getDefaultTargetFrame(), sequenceId, position,
160 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
161 * java.lang.String, java.lang.String, java.lang.String)
163 public void highlightIn(final AlignFrame alf, final String sequenceId,
164 final String position, final String alignedPosition)
166 // TODO: could try to highlight in all alignments if alf==null
167 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
168 alf.viewport.getAlignment().getSequencesArray());
169 final SequenceI sq = matcher.findIdMatch(sequenceId);
175 apos = new Integer(position).intValue();
177 } catch (NumberFormatException ex)
181 final StructureSelectionManagerProvider me = this;
182 final int pos = apos;
183 // use vamsas listener to broadcast to all listeners in scope
184 if (alignedPosition != null
185 && (alignedPosition.trim().length() == 0 || alignedPosition
186 .toLowerCase().indexOf("false") > -1))
188 java.awt.EventQueue.invokeLater(new Runnable()
193 StructureSelectionManager.getStructureSelectionManager(me)
194 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
200 java.awt.EventQueue.invokeLater(new Runnable()
205 StructureSelectionManager.getStructureSelectionManager(me)
206 .mouseOverVamsasSequence(sq, pos, null);
216 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
219 public void select(String sequenceIds, String columns)
221 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
227 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
228 * java.lang.String, java.lang.String)
230 public void select(String sequenceIds, String columns, String sep)
232 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
238 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
239 * java.lang.String, java.lang.String)
241 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
243 selectIn(alf, sequenceIds, columns, separator);
249 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
250 * java.lang.String, java.lang.String, java.lang.String)
252 public void selectIn(final AlignFrame alf, String sequenceIds,
253 String columns, String sep)
255 if (sep == null || sep.length() == 0)
263 System.err.println("Selecting region using separator string '"
268 String[] ids = separatorListToArray(sequenceIds, sep);
269 String[] cols = separatorListToArray(columns, sep);
270 final SequenceGroup sel = new SequenceGroup();
271 final ColumnSelection csel = new ColumnSelection();
272 AlignmentI al = alf.viewport.getAlignment();
273 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
274 alf.viewport.getAlignment().getSequencesArray());
275 int start = 0, end = al.getWidth(), alw = al.getWidth();
276 boolean seqsfound = true;
277 if (ids != null && ids.length > 0)
280 for (int i = 0; i < ids.length; i++)
282 if (ids[i].trim().length() == 0)
286 SequenceI sq = matcher.findIdMatch(ids[i]);
290 sel.addSequence(sq, false);
294 boolean inseqpos = false;
295 if (cols != null && cols.length > 0)
297 boolean seset = false;
298 for (int i = 0; i < cols.length; i++)
300 String cl = cols[i].trim();
301 if (cl.length() == 0)
306 if ((p = cl.indexOf("-")) > -1)
308 int from = -1, to = -1;
311 from = new Integer(cl.substring(0, p)).intValue();
313 } catch (NumberFormatException ex)
316 .println("ERROR: Couldn't parse first integer in range element column selection string '"
317 + cl + "' - format is 'from-to'");
322 to = new Integer(cl.substring(p + 1)).intValue();
324 } catch (NumberFormatException ex)
327 .println("ERROR: Couldn't parse second integer in range element column selection string '"
328 + cl + "' - format is 'from-to'");
331 if (from >= 0 && to >= 0)
348 // comment to prevent range extension
358 for (int r = from; r <= to; r++)
360 if (r >= 0 && r < alw)
367 System.err.println("Range '" + cl + "' deparsed as [" + from
373 System.err.println("ERROR: Invalid Range '" + cl
374 + "' deparsed as [" + from + "," + to + "]");
382 r = new Integer(cl).intValue();
384 } catch (NumberFormatException ex)
386 if (cl.toLowerCase().equals("sequence"))
388 // we are in the dataset sequence's coordinate frame.
394 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
399 if (r >= 0 && r <= alw)
409 // comment to prevent range extension
422 System.err.println("Point selection '" + cl
423 + "' deparsed as [" + r + "]");
428 System.err.println("ERROR: Invalid Point selection '" + cl
429 + "' deparsed as [" + r + "]");
436 // we only propagate the selection when it was the null selection, or the
437 // given sequences were found in the alignment.
438 if (inseqpos && sel.getSize() > 0)
440 // assume first sequence provides reference frame ?
441 SequenceI rs = sel.getSequenceAt(0);
442 start = rs.findIndex(start);
443 end = rs.findIndex(end);
446 Vector cs = csel.getSelected();
448 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
450 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
455 sel.setStartRes(start);
457 EventQueue.invokeLater(new Runnable()
462 alf.select(sel, csel);
472 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
473 * String, java.lang.String)
475 public String getSelectedSequencesAsAlignment(String format, String suffix)
477 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
485 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
486 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
488 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
489 String format, String suffix)
493 boolean seqlimits = suffix.equalsIgnoreCase("true");
494 if (alf.viewport.getSelectionGroup() != null)
496 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
497 // method now returns a full copy of sequence data
498 // TODO consider using getSequenceSelection instead here
499 String reply = new AppletFormatAdapter().formatSequences(format,
500 new Alignment(alf.viewport.getSelectionAsNewSequence()),
504 } catch (Exception ex)
506 ex.printStackTrace();
507 return "Error retrieving alignment in " + format + " format. ";
515 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
517 public String getAlignmentOrder()
519 return getAlignmentOrderFrom(getDefaultTargetFrame());
526 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
529 public String getAlignmentOrderFrom(AlignFrame alf)
531 return getAlignmentOrderFrom(alf, separator);
538 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
539 * , java.lang.String)
541 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
543 AlignmentI alorder = alf.getAlignViewport().getAlignment();
544 String[] order = new String[alorder.getHeight()];
545 for (int i = 0; i < order.length; i++)
547 order[i] = alorder.getSequenceAt(i).getName();
549 return arrayToSeparatorList(order);
555 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
558 public String orderBy(String order, String undoName)
560 return orderBy(order, undoName, separator);
566 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
567 * java.lang.String, java.lang.String)
569 public String orderBy(String order, String undoName, String sep)
571 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
578 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
579 * java.lang.String, java.lang.String, java.lang.String)
581 public String orderAlignmentBy(AlignFrame alf, String order,
582 String undoName, String sep)
584 String[] ids = separatorListToArray(order, sep);
585 SequenceI[] sqs = null;
586 if (ids != null && ids.length > 0)
588 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
589 alf.viewport.getAlignment().getSequencesArray());
591 sqs = new SequenceI[ids.length];
592 for (int i = 0; i < ids.length; i++)
594 if (ids[i].trim().length() == 0)
598 SequenceI sq = matcher.findIdMatch(ids[i]);
606 SequenceI[] sqq = new SequenceI[s];
607 System.arraycopy(sqs, 0, sqq, 0, s);
620 final AlignmentOrder aorder = new AlignmentOrder(sqs);
622 if (undoName != null && undoName.trim().length() == 0)
626 final String _undoName = undoName;
627 // TODO: deal with synchronization here: cannot raise any events until after
628 // this has returned.
629 return alf.sortBy(aorder, _undoName) ? "true" : "";
635 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
637 public String getAlignment(String format)
639 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
646 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
649 public String getAlignmentFrom(AlignFrame alf, String format)
651 return getAlignmentFrom(alf, format, "true");
657 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
660 public String getAlignment(String format, String suffix)
662 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
669 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
670 * java.lang.String, java.lang.String)
672 public String getAlignmentFrom(AlignFrame alf, String format,
677 boolean seqlimits = suffix.equalsIgnoreCase("true");
679 String reply = new AppletFormatAdapter().formatSequences(format,
680 alf.viewport.getAlignment(), seqlimits);
682 } catch (Exception ex)
684 ex.printStackTrace();
685 return "Error retrieving alignment in " + format + " format. ";
692 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
694 public void loadAnnotation(String annotation)
696 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
703 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
704 * , java.lang.String)
706 public void loadAnnotationFrom(AlignFrame alf, String annotation)
708 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
709 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
711 alf.alignPanel.fontChanged();
712 alf.alignPanel.setScrollValues(0, 0);
716 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
723 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
725 public void loadFeatures(String features, boolean autoenabledisplay)
727 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
734 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
735 * , java.lang.String)
737 public boolean loadFeaturesFrom(AlignFrame alf, String features,
738 boolean autoenabledisplay)
740 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
747 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
749 public String getFeatures(String format)
751 return getFeaturesFrom(getDefaultTargetFrame(), format);
758 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
761 public String getFeaturesFrom(AlignFrame alf, String format)
763 return alf.outputFeatures(false, format);
769 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
771 public String getAnnotation()
773 return getAnnotationFrom(getDefaultTargetFrame());
780 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
783 public String getAnnotationFrom(AlignFrame alf)
785 return alf.outputAnnotations(false);
791 * @see jalview.bin.JalviewLiteJsApi#newView()
793 public AlignFrame newView()
795 return newViewFrom(getDefaultTargetFrame());
801 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
803 public AlignFrame newView(String name)
805 return newViewFrom(getDefaultTargetFrame(), name);
811 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
813 public AlignFrame newViewFrom(AlignFrame alf)
815 return alf.newView(null);
821 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
824 public AlignFrame newViewFrom(AlignFrame alf, String name)
826 return alf.newView(name);
832 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
835 public AlignFrame loadAlignment(String text, String title)
839 String format = new IdentifyFile().Identify(text,
840 AppletFormatAdapter.PASTE);
843 al = new AppletFormatAdapter().readFile(text,
844 AppletFormatAdapter.PASTE, format);
845 if (al.getHeight() > 0)
847 return new AlignFrame(al, this, title, false);
849 } catch (java.io.IOException ex)
851 ex.printStackTrace();
859 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
861 public void setMouseoverListener(String listener)
863 setMouseoverListener(currentAlignFrame, listener);
866 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
872 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
873 * , java.lang.String)
875 public void setMouseoverListener(AlignFrame af, String listener)
877 if (listener != null)
879 listener = listener.trim();
880 if (listener.length() == 0)
883 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
887 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
889 javascriptListeners.addElement(mol);
890 StructureSelectionManager.getStructureSelectionManager(this)
891 .addStructureViewerListener(mol);
894 System.err.println("Added a mouseover listener for "
895 + ((af == null) ? "All frames" : "Just views for "
896 + af.getAlignViewport().getSequenceSetId()));
897 System.err.println("There are now " + javascriptListeners.size()
898 + " listeners in total.");
905 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
907 public void setSelectionListener(String listener)
909 setSelectionListener(null, listener);
916 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
917 * , java.lang.String)
919 public void setSelectionListener(AlignFrame af, String listener)
921 if (listener != null)
923 listener = listener.trim();
924 if (listener.length() == 0)
927 .println("jalview Javascript error: Ignoring empty function for selection listener.");
931 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
933 javascriptListeners.addElement(mol);
934 StructureSelectionManager.getStructureSelectionManager(this)
935 .addSelectionListener(mol);
938 System.err.println("Added a selection listener for "
939 + ((af == null) ? "All frames" : "Just views for "
940 + af.getAlignViewport().getSequenceSetId()));
941 System.err.println("There are now " + javascriptListeners.size()
942 + " listeners in total.");
949 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
952 public void setStructureListener(String listener, String modelSet)
954 if (listener != null)
956 listener = listener.trim();
957 if (listener.length() == 0)
960 .println("jalview Javascript error: Ignoring empty function for selection listener.");
964 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
965 this, listener, separatorListToArray(modelSet));
966 javascriptListeners.addElement(mol);
967 StructureSelectionManager.getStructureSelectionManager(this)
968 .addStructureViewerListener(mol);
971 System.err.println("Added a javascript structure viewer listener '"
973 System.err.println("There are now " + javascriptListeners.size()
974 + " listeners in total.");
982 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
983 * .AlignFrame, java.lang.String)
985 public void removeJavascriptListener(AlignFrame af, String listener)
987 if (listener != null)
989 listener = listener.trim();
990 if (listener.length() == 0)
995 boolean rprt = false;
996 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
998 Object lstn = javascriptListeners.elementAt(ms);
999 JsCallBack lstner = (JsCallBack) lstn;
1000 if ((af == null || lstner.getAlignFrame() == af)
1001 && (listener == null || lstner.getListenerFunction().equals(
1004 javascriptListeners.removeElement(lstner);
1006 if (lstner instanceof SelectionListener)
1008 StructureSelectionManager.getStructureSelectionManager(this)
1009 .removeSelectionListener((SelectionListener) lstner);
1013 StructureSelectionManager.getStructureSelectionManager(this)
1014 .removeStructureViewerListener(lstner, null);
1019 System.err.println("Removed listener '" + listener + "'");
1029 System.err.println("There are now " + javascriptListeners.size()
1030 + " listeners in total.");
1036 System.err.println("Applet " + getName() + " stop().");
1040 public void destroy()
1042 System.err.println("Applet " + getName() + " destroy().");
1046 private void tidyUp()
1049 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1050 && currentAlignFrame.viewport.applet != null)
1052 AlignViewport av = currentAlignFrame.viewport;
1053 currentAlignFrame.closeMenuItem_actionPerformed();
1055 currentAlignFrame = null;
1057 if (javascriptListeners != null)
1059 while (javascriptListeners.size() > 0)
1061 jalview.javascript.JSFunctionExec mol = javascriptListeners
1063 javascriptListeners.removeElement(mol);
1064 if (mol instanceof SelectionListener)
1066 StructureSelectionManager.getStructureSelectionManager(this)
1067 .removeSelectionListener((SelectionListener) mol);
1071 StructureSelectionManager.getStructureSelectionManager(this)
1072 .removeStructureViewerListener(mol, null);
1077 if (jsFunctionExec != null)
1079 jsFunctionExec.stopQueue();
1080 jsFunctionExec.jvlite = null;
1082 initialAlignFrame = null;
1083 jsFunctionExec = null;
1084 javascriptListeners = null;
1085 StructureSelectionManager.release(this);
1088 private jalview.javascript.JSFunctionExec jsFunctionExec;
1093 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1094 * java.lang.String, java.lang.String)
1096 public void mouseOverStructure(final String pdbResNum,
1097 final String chain, final String pdbfile)
1099 final StructureSelectionManagerProvider me = this;
1100 java.awt.EventQueue.invokeLater(new Runnable()
1107 StructureSelectionManager.getStructureSelectionManager(me)
1108 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1112 System.err.println("mouseOver for '" + pdbResNum
1113 + "' in chain '" + chain + "' in structure '" + pdbfile
1116 } catch (NumberFormatException e)
1118 System.err.println("Ignoring invalid residue number string '"
1130 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1131 * java.lang.String, java.lang.String)
1133 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1134 final String leftHandColumn)
1136 java.awt.EventQueue.invokeLater(new Runnable()
1143 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1144 leftHandColumn).intValue());
1146 } catch (Exception ex)
1148 System.err.println("Couldn't parse integer arguments (topRow='"
1149 + topRow + "' and leftHandColumn='" + leftHandColumn
1151 ex.printStackTrace();
1161 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1162 * .AlignFrame, java.lang.String)
1165 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1168 java.awt.EventQueue.invokeLater(new Runnable()
1175 alf.scrollToRow(new Integer(topRow).intValue());
1177 } catch (Exception ex)
1179 System.err.println("Couldn't parse integer arguments (topRow='"
1181 ex.printStackTrace();
1192 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1193 * .AlignFrame, java.lang.String)
1196 public void scrollViewToColumnIn(final AlignFrame alf,
1197 final String leftHandColumn)
1199 java.awt.EventQueue.invokeLater(new Runnable()
1207 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1209 } catch (Exception ex)
1212 .println("Couldn't parse integer arguments (leftHandColumn='"
1213 + leftHandColumn + "')");
1214 ex.printStackTrace();
1221 // //////////////////////////////////////////////
1222 // //////////////////////////////////////////////
1224 public static int lastFrameX = 200;
1226 public static int lastFrameY = 200;
1228 boolean fileFound = true;
1230 String file = "No file";
1232 Button launcher = new Button("Start Jalview");
1235 * The currentAlignFrame is static, it will change if and when the user
1236 * selects a new window. Note that it will *never* point back to the embedded
1237 * AlignFrame if the applet is started as embedded on the page and then
1238 * afterwards a new view is created.
1240 public AlignFrame currentAlignFrame = null;
1243 * This is the first frame to be displayed, and does not change. API calls
1244 * will default to this instance if currentAlignFrame is null.
1246 AlignFrame initialAlignFrame = null;
1248 boolean embedded = false;
1250 private boolean checkForJmol = true;
1252 private boolean checkedForJmol = false; // ensure we don't check for jmol
1254 // every time the app is re-inited
1256 public boolean jmolAvailable = false;
1258 private boolean alignPdbStructures = false;
1261 * use an external structure viewer exclusively (no jmols or MCViews will be
1262 * opened by JalviewLite itself)
1264 public boolean useXtrnalSviewer = false;
1266 public static boolean debug = false;
1268 static String builddate = null, version = null;
1270 private static void initBuildDetails()
1272 if (builddate == null)
1274 builddate = "unknown";
1276 java.net.URL url = JalviewLite.class
1277 .getResource("/.build_properties");
1282 BufferedReader reader = new BufferedReader(new InputStreamReader(
1285 while ((line = reader.readLine()) != null)
1287 if (line.indexOf("VERSION") > -1)
1289 version = line.substring(line.indexOf("=") + 1);
1291 if (line.indexOf("BUILD_DATE") > -1)
1293 builddate = line.substring(line.indexOf("=") + 1);
1296 } catch (Exception ex)
1298 ex.printStackTrace();
1304 public static String getBuildDate()
1310 public static String getVersion()
1316 // public JSObject scriptObject = null;
1319 * init method for Jalview Applet
1323 // remove any handlers that might be hanging around from an earlier instance
1328 System.err.println("Applet context is '"
1329 + getAppletContext().getClass().toString() + "'");
1331 JSObject scriptObject = JSObject.getWindow(this);
1332 if (debug && scriptObject != null)
1334 System.err.println("Applet has Javascript callback support.");
1337 } catch (Exception ex)
1340 .println("Warning: No JalviewLite javascript callbacks available.");
1343 ex.printStackTrace();
1347 * turn on extra applet debugging
1349 String dbg = getParameter("debug");
1352 debug = dbg.toLowerCase().equals("true");
1357 System.err.println("JalviewLite Version " + getVersion());
1358 System.err.println("Build Date : " + getBuildDate());
1361 String externalsviewer = getParameter("externalstructureviewer");
1362 if (externalsviewer != null)
1364 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1368 * if true disable the check for jmol
1370 String chkforJmol = getParameter("nojmol");
1371 if (chkforJmol != null)
1373 checkForJmol = !chkforJmol.equals("true");
1376 * get the separator parameter if present
1378 String sep = getParameter("separator");
1381 if (sep.length() > 0)
1386 System.err.println("Separator set to '" + separator + "'");
1392 "Invalid separator parameter - must be non-zero length");
1398 String param = getParameter("RGB");
1404 r = Integer.parseInt(param.substring(0, 2), 16);
1405 g = Integer.parseInt(param.substring(2, 4), 16);
1406 b = Integer.parseInt(param.substring(4, 6), 16);
1407 } catch (Exception ex)
1414 param = getParameter("label");
1417 launcher.setLabel(param);
1420 setBackground(new Color(r, g, b));
1422 file = getParameter("file");
1426 // Maybe the sequences are added as parameters
1427 StringBuffer data = new StringBuffer("PASTE");
1429 while ((file = getParameter("sequence" + i)) != null)
1431 data.append(file.toString() + "\n");
1434 if (data.length() > 5)
1436 file = data.toString();
1440 final JalviewLite jvapplet = this;
1441 if (getParameter("embedded") != null
1442 && getParameter("embedded").equalsIgnoreCase("true"))
1444 // Launch as embedded applet in page
1446 LoadingThread loader = new LoadingThread(file, jvapplet);
1449 else if (file != null)
1451 if (getParameter("showbutton") == null
1452 || !getParameter("showbutton").equalsIgnoreCase("false"))
1454 // Add the JalviewLite 'Button' to the page
1456 launcher.addActionListener(new java.awt.event.ActionListener()
1458 public void actionPerformed(ActionEvent e)
1460 LoadingThread loader = new LoadingThread(file, jvapplet);
1467 // Open jalviewLite immediately.
1468 LoadingThread loader = new LoadingThread(file, jvapplet);
1474 // jalview initialisation with no alignment. loadAlignment() method can
1475 // still be called to open new alignments.
1482 private void callInitCallback()
1484 String initjscallback = getParameter("oninit");
1485 if (initjscallback == null)
1489 initjscallback = initjscallback.trim();
1490 if (initjscallback.length() > 0)
1492 JSObject scriptObject = null;
1495 scriptObject = JSObject.getWindow(this);
1496 } catch (Exception ex)
1500 if (scriptObject != null)
1504 // do onInit with the JS executor thread
1505 new JSFunctionExec(this).executeJavascriptFunction(true,
1506 initjscallback, null, "Calling oninit callback '"
1507 + initjscallback + "'.");
1508 } catch (Exception e)
1510 System.err.println("Exception when executing _oninit callback '"
1511 + initjscallback + "'.");
1512 e.printStackTrace();
1517 System.err.println("Not executing _oninit callback '"
1518 + initjscallback + "' - no scripting allowed.");
1524 * Initialises and displays a new java.awt.Frame
1527 * java.awt.Frame to be displayed
1529 * title of new frame
1531 * width if new frame
1533 * height of new frame
1535 public static void addFrame(final Frame frame, String title, int width,
1538 frame.setLocation(lastFrameX, lastFrameY);
1541 frame.setSize(width, height);
1542 frame.setTitle(title);
1543 frame.addWindowListener(new WindowAdapter()
1545 public void windowClosing(WindowEvent e)
1547 if (frame instanceof AlignFrame)
1549 AlignViewport vp = ((AlignFrame) frame).viewport;
1550 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1551 if (vp.applet.currentAlignFrame == frame)
1553 vp.applet.currentAlignFrame = null;
1561 if (frame instanceof EmbmenuFrame)
1563 ((EmbmenuFrame) frame).destroyMenus();
1565 frame.setMenuBar(null);
1569 public void windowActivated(WindowEvent e)
1571 if (frame instanceof AlignFrame)
1573 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1576 System.err.println("Activated window " + frame);
1580 super.windowActivated(e);
1583 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1586 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1589 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1590 * frame) { currentAlignFrame = null; if (debug) {
1591 * System.err.println("Deactivated window "+frame); } }
1592 * super.windowDeactivated(e); }
1595 frame.setVisible(true);
1599 * This paints the background surrounding the "Launch Jalview button" <br>
1601 * If file given in parameter not found, displays error message
1606 public void paint(Graphics g)
1610 g.setColor(new Color(200, 200, 200));
1611 g.setColor(Color.cyan);
1612 g.fillRect(0, 0, getSize().width, getSize().height);
1613 g.setColor(Color.red);
1614 g.drawString(MessageManager.getString("label.jalview_cannot_open_file"), 5, 15);
1615 g.drawString("\"" + file + "\"", 5, 30);
1619 g.setColor(Color.black);
1620 g.setFont(new Font("Arial", Font.BOLD, 24));
1621 g.drawString(MessageManager.getString("label.jalview_applet"), 50, getSize().height / 2 - 30);
1622 g.drawString(MessageManager.getString("label.loading_data") + "...", 50, getSize().height / 2);
1627 * get all components associated with the applet of the given type
1632 public Vector getAppletWindow(Class class1)
1634 Vector wnds = new Vector();
1635 Component[] cmp = getComponents();
1638 for (int i = 0; i < cmp.length; i++)
1640 if (class1.isAssignableFrom(cmp[i].getClass()))
1642 wnds.addElement(cmp);
1649 class LoadJmolThread extends Thread
1651 private boolean running = false;
1655 if (running || checkedForJmol)
1664 if (!System.getProperty("java.version").startsWith("1.1"))
1666 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1667 jmolAvailable = true;
1672 .println("Jmol not available - Using MCview for structures");
1674 } catch (java.lang.ClassNotFoundException ex)
1680 jmolAvailable = false;
1684 .println("Skipping Jmol check. Will use MCView (probably)");
1687 checkedForJmol = true;
1691 public boolean notFinished()
1693 return running || !checkedForJmol;
1697 class LoadingThread extends Thread
1700 * State variable: File source
1705 * State variable: protocol for access to file source
1710 * State variable: format of file source
1718 private void dbgMsg(String msg)
1722 System.err.println(msg);
1727 * update the protocol state variable for accessing the datasource located
1731 * @return possibly updated datasource string
1733 public String setProtocolState(String file)
1735 if (file.startsWith("PASTE"))
1737 file = file.substring(5);
1738 protocol = AppletFormatAdapter.PASTE;
1740 else if (inArchive(file))
1742 protocol = AppletFormatAdapter.CLASSLOADER;
1746 file = addProtocol(file);
1747 protocol = AppletFormatAdapter.URL;
1749 dbgMsg("Protocol identified as '" + protocol + "'");
1753 public LoadingThread(String _file, JalviewLite _applet)
1761 LoadJmolThread jmolchecker = new LoadJmolThread();
1762 jmolchecker.start();
1763 while (jmolchecker.notFinished())
1765 // wait around until the Jmol check is complete.
1769 } catch (Exception e)
1775 // applet.callInitCallback();
1778 private void startLoading()
1780 AlignFrame newAlignFrame;
1781 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1782 file = setProtocolState(_file);
1784 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1785 dbgMsg("File identified as '" + format + "'");
1786 dbgMsg("Loading started.");
1787 Alignment al = null;
1790 al = new AppletFormatAdapter().readFile(file, protocol, format);
1791 } catch (java.io.IOException ex)
1793 dbgMsg("File load exception.");
1794 ex.printStackTrace();
1799 FileParse fp = new FileParse(file, protocol);
1801 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1803 while ((ln = fp.nextLine()) != null)
1807 dbgMsg(">>>Dump finished.");
1808 } catch (Exception e)
1811 .println("Exception when trying to dump the content of the file parameter.");
1812 e.printStackTrace();
1816 if ((al != null) && (al.getHeight() > 0))
1818 dbgMsg("Successfully loaded file.");
1819 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1820 if (initialAlignFrame == null)
1822 initialAlignFrame = newAlignFrame;
1824 // update the focus.
1825 currentAlignFrame = newAlignFrame;
1827 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1829 newAlignFrame.setTitle(MessageManager.formatMessage("label.sequences_from", new String[]{applet.getDocumentBase().toString()}));
1832 newAlignFrame.statusBar.setText(MessageManager.formatMessage("label.successfully_loaded_file", new String []{file}));
1834 String treeFile = applet.getParameter("tree");
1835 if (treeFile == null)
1837 treeFile = applet.getParameter("treeFile");
1840 if (treeFile != null)
1844 treeFile = setProtocolState(treeFile);
1846 * if (inArchive(treeFile)) { protocol =
1847 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1848 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1850 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1855 if (fin.getTree() != null)
1857 newAlignFrame.loadTree(fin, treeFile);
1858 dbgMsg("Successfuly imported tree.");
1862 dbgMsg("Tree parameter did not resolve to a valid tree.");
1864 } catch (Exception ex)
1866 ex.printStackTrace();
1871 * Try to load T-Coffee score file
1873 String sScoreFile = applet.getParameter("scoreFile");
1874 if (sScoreFile != null && !"".equals(sScoreFile))
1881 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
1883 if (!newAlignFrame.loadScoreFile(sScoreFile))
1886 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
1887 + sScoreFile + "')");
1889 } catch (Exception e)
1891 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
1892 sScoreFile, e.getMessage());
1896 // ///////////////////////////
1897 // modify display of features
1898 // we do this before any features have been loaded, ensuring any hidden
1899 // groups are hidden when features first displayed
1901 // hide specific groups
1903 String param = applet.getParameter("hidefeaturegroups");
1906 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1908 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1910 // show specific groups
1911 param = applet.getParameter("showfeaturegroups");
1914 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1916 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1918 // and now load features
1919 param = applet.getParameter("features");
1922 param = setProtocolState(param);
1924 newAlignFrame.parseFeaturesFile(param, protocol);
1927 param = applet.getParameter("showFeatureSettings");
1928 if (param != null && param.equalsIgnoreCase("true"))
1930 newAlignFrame.viewport.showSequenceFeatures(true);
1931 new FeatureSettings(newAlignFrame.alignPanel);
1934 param = applet.getParameter("annotations");
1937 param = setProtocolState(param);
1939 if (new AnnotationFile().readAnnotationFile(
1940 newAlignFrame.viewport.getAlignment(), param, protocol))
1942 newAlignFrame.alignPanel.fontChanged();
1943 newAlignFrame.alignPanel.setScrollValues(0, 0);
1948 .println("Annotations were not added from annotation file '"
1954 param = applet.getParameter("jnetfile");
1959 param = setProtocolState(param);
1960 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
1962 JnetAnnotationMaker.add_annotation(predictions,
1963 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
1971 newAlignFrame.alignPanel.fontChanged();
1972 newAlignFrame.alignPanel.setScrollValues(0, 0);
1973 } catch (Exception ex)
1975 ex.printStackTrace();
1979 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
1980 * - related to JAL-434
1982 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1985 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1988 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1990 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1993 int pdbFileCount = 0;
1994 // Accumulate pdbs here if they are heading for the same view (if
1995 // alignPdbStructures is true)
1996 Vector pdbs = new Vector();
1997 // create a lazy matcher if we're asked to
1998 jalview.analysis.SequenceIdMatcher matcher = (applet
1999 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2000 newAlignFrame.getAlignViewport().getAlignment()
2001 .getSequencesArray()) : null;
2005 if (pdbFileCount > 0)
2007 param = applet.getParameter("PDBFILE" + pdbFileCount);
2011 param = applet.getParameter("PDBFILE");
2016 PDBEntry pdb = new PDBEntry();
2019 SequenceI[] seqs = null;
2020 String[] chains = null;
2022 StringTokenizer st = new StringTokenizer(param, " ");
2024 if (st.countTokens() < 2)
2026 String sequence = applet.getParameter("PDBSEQ");
2027 if (sequence != null)
2028 seqs = new SequenceI[]
2029 { matcher == null ? (Sequence) newAlignFrame
2030 .getAlignViewport().getAlignment()
2031 .findName(sequence) : matcher.findIdMatch(sequence) };
2036 param = st.nextToken();
2037 Vector tmp = new Vector();
2038 Vector tmp2 = new Vector();
2040 while (st.hasMoreTokens())
2042 seqstring = st.nextToken();
2043 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2044 if (st2.countTokens() > 1)
2046 // This is the chain
2047 tmp2.addElement(st2.nextToken());
2048 seqstring = st2.nextToken();
2050 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
2051 .getAlignViewport().getAlignment()
2052 .findName(seqstring) : matcher
2053 .findIdMatch(seqstring));
2056 seqs = new SequenceI[tmp.size()];
2058 if (tmp2.size() == tmp.size())
2060 chains = new String[tmp2.size()];
2061 tmp2.copyInto(chains);
2064 param = setProtocolState(param);
2066 if (// !jmolAvailable
2068 protocol == AppletFormatAdapter.CLASSLOADER
2069 && !useXtrnalSviewer)
2071 // Re: JAL-357 : the bug isn't a problem if we are using an
2073 // TODO: verify this Re:
2074 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2075 // This exception preserves the current behaviour where, even if
2076 // the local pdb file was identified in the class loader
2077 protocol = AppletFormatAdapter.URL; // this is probably NOT
2079 param = addProtocol(param); //
2086 for (int i = 0; i < seqs.length; i++)
2088 if (seqs[i] != null)
2090 ((Sequence) seqs[i]).addPDBId(pdb);
2094 if (JalviewLite.debug)
2096 // this may not really be a problem but we give a warning
2099 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2105 if (!alignPdbStructures)
2107 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
2112 pdbs.addElement(new Object[]
2113 { pdb, seqs, chains, new String(protocol) });
2119 } while (param != null || pdbFileCount < 10);
2120 if (pdbs.size() > 0)
2122 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2123 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2124 String[][] chains = new String[pdbs.size()][];
2125 String[] protocols = new String[pdbs.size()];
2126 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2128 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2129 pdb[pdbsi] = (PDBEntry) o[0];
2130 seqs[pdbsi] = (SequenceI[]) o[1];
2131 chains[pdbsi] = (String[]) o[2];
2132 protocols[pdbsi] = (String) o[3];
2134 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
2142 applet.remove(launcher);
2149 * Discovers whether the given file is in the Applet Archive
2155 boolean inArchive(String file)
2157 // This might throw a security exception in certain browsers
2158 // Netscape Communicator for instance.
2161 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2164 System.err.println("Resource '" + file + "' was "
2165 + (rtn ? "" : "not") + " located by classloader.");
2168 } catch (Exception ex)
2170 System.out.println("Exception checking resources: " + file + " "
2176 String addProtocol(String file)
2178 if (file.indexOf("://") == -1)
2180 String fl = applet.resolveUrlForLocalOrAbsolute(file,
2184 if (new java.net.URL(fl).openStream() != null)
2188 System.err.println("Prepended document base for resource: '"
2193 } catch (Exception x)
2197 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2200 if (new java.net.URL(fl).openStream() != null)
2204 System.err.println("Prepended codebase for resource: '"
2209 } catch (Exception x)
2221 * @return the default alignFrame acted on by the public applet methods. May
2222 * return null with an error message on System.err indicating the
2225 public AlignFrame getDefaultTargetFrame()
2227 if (currentAlignFrame != null)
2229 return currentAlignFrame;
2231 if (initialAlignFrame != null)
2233 return initialAlignFrame;
2236 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2241 * separator used for separatorList
2243 protected String separator = "" + ((char) 0x00AC); // the default used to be
2244 // '|' but many sequence
2245 // IDS include pipes.
2248 * set to enable the URL based javascript execution mechanism
2250 public boolean jsfallbackEnabled = false;
2253 * parse the string into a list
2256 * @return elements separated by separator
2258 public String[] separatorListToArray(String list)
2260 return separatorListToArray(list, separator);
2264 * parse the string into a list
2268 * @return elements separated by separator
2270 public String[] separatorListToArray(String list, String separator)
2272 // note separator local variable intentionally masks object field
2273 int seplen = separator.length();
2274 if (list == null || list.equals("") || list.equals(separator))
2276 java.util.Vector jv = new Vector();
2278 while ((pos = list.indexOf(separator, cp)) > cp)
2280 jv.addElement(list.substring(cp, pos));
2283 if (cp < list.length())
2285 String c = list.substring(cp);
2286 if (!c.equals(separator))
2293 String[] v = new String[jv.size()];
2294 for (int i = 0; i < v.length; i++)
2296 v[i] = (String) jv.elementAt(i);
2298 jv.removeAllElements();
2301 System.err.println("Array from '" + separator
2302 + "' separated List:\n" + v.length);
2303 for (int i = 0; i < v.length; i++)
2305 System.err.println("item " + i + " '" + v[i] + "'");
2312 System.err.println("Empty Array from '" + separator
2313 + "' separated List");
2319 * concatenate the list with separator
2322 * @return concatenated string
2324 public String arrayToSeparatorList(String[] list)
2326 return arrayToSeparatorList(list, separator);
2330 * concatenate the list with separator
2334 * @return concatenated string
2336 public String arrayToSeparatorList(String[] list, String separator)
2338 StringBuffer v = new StringBuffer();
2339 if (list != null && list.length > 0)
2341 for (int i = 0, iSize = list.length; i < iSize; i++)
2343 if (list[i] != null)
2347 v.append(separator);
2354 System.err.println("Returning '" + separator
2355 + "' separated List:\n");
2356 System.err.println(v);
2358 return v.toString();
2362 System.err.println("Returning empty '" + separator
2363 + "' separated List\n");
2365 return "" + separator;
2371 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2373 public String getFeatureGroups()
2375 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2376 .getFeatureGroups());
2384 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2387 public String getFeatureGroupsOn(AlignFrame alf)
2389 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2396 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2398 public String getFeatureGroupsOfState(boolean visible)
2400 return arrayToSeparatorList(getDefaultTargetFrame()
2401 .getFeatureGroupsOfState(visible));
2408 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2409 * .AlignFrame, boolean)
2411 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2413 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2419 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2420 * AlignFrame, java.lang.String, boolean)
2422 public void setFeatureGroupStateOn(final AlignFrame alf,
2423 final String groups, boolean state)
2425 final boolean st = state;// !(state==null || state.equals("") ||
2426 // state.toLowerCase().equals("false"));
2427 java.awt.EventQueue.invokeLater(new Runnable()
2432 alf.setFeatureGroupState(separatorListToArray(groups), st);
2440 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2443 public void setFeatureGroupState(String groups, boolean state)
2445 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2451 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2453 public String getSeparator()
2461 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2463 public void setSeparator(String separator)
2465 if (separator == null || separator.length() < 1)
2468 separator = "" + ((char) 0x00AC);
2470 this.separator = separator;
2473 System.err.println("Default Separator now: '" + separator + "'");
2478 * get boolean value of applet parameter 'name' and return default if
2479 * parameter is not set
2484 * the value to return otherwise
2485 * @return true or false
2487 public boolean getDefaultParameter(String name, boolean def)
2490 if ((stn = getParameter(name)) == null)
2494 if (stn.toLowerCase().equals("true"))
2504 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2505 * java.lang.String, java.lang.String, java.lang.String)
2507 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2508 String pdbEntryString, String pdbFile)
2510 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2513 protected void setAlignPdbStructures(boolean alignPdbStructures)
2515 this.alignPdbStructures = alignPdbStructures;
2518 public boolean isAlignPdbStructures()
2520 return alignPdbStructures;
2525 // callInitCallback();
2528 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2530 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2532 public void setJsMessageSet(String messageclass, String viewId,
2533 String[] colcommands)
2535 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2538 msgset = new Hashtable<String, String[]>();
2539 jsmessages.put(messageclass, msgset);
2541 msgset.put(viewId, colcommands);
2542 long[] l = new long[colcommands.length];
2543 for (int i = 0; i < colcommands.length; i++)
2545 l[i] = colcommands[i].hashCode();
2547 jshashes.put(messageclass + "|" + viewId, l);
2553 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2556 public String getJsMessage(String messageclass, String viewId)
2558 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2561 String[] msgs = msgset.get(viewId);
2564 for (int i = 0; i < msgs.length; i++)
2566 if (msgs[i] != null)
2578 public boolean isJsMessageSetChanged(String string, String string2,
2579 String[] colcommands)
2581 long[] l = jshashes.get(string + "|" + string2);
2582 if (l == null && colcommands != null)
2586 for (int i = 0; i < colcommands.length; i++)
2588 if (l[i] != colcommands[i].hashCode())
2596 private Vector jsExecQueue = new Vector();
2598 public Vector getJsExecQueue()
2603 public void setExecutor(JSFunctionExec jsFunctionExec2)
2605 jsFunctionExec = jsFunctionExec2;
2609 * return the given colour value parameter or the given default if parameter
2616 public Color getDefaultColourParameter(String colparam, Color defcolour)
2618 String colprop = getParameter(colparam);
2619 if (colprop == null || colprop.trim().length() == 0)
2623 Color col = jalview.schemes.ColourSchemeProperty
2624 .getAWTColorFromName(colprop);
2629 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2630 } catch (Exception ex)
2632 System.err.println("Couldn't parse '" + colprop
2633 + "' as a colour for " + colparam);
2637 return (col == null) ? defcolour : col;
2641 public void openJalviewHelpUrl()
2643 String helpUrl = getParameter("jalviewhelpurl");
2644 if (helpUrl == null || helpUrl.trim().length() < 5)
2646 helpUrl = "http://www.jalview.org/help.html";
2648 showURL(helpUrl, "HELP");
2652 * form a complete URL given a path to a resource and a reference location on
2656 * - an absolute path on the same server as localref or a document
2657 * located relative to localref
2659 * - a URL on the same server as url
2660 * @return a complete URL for the resource located by url
2662 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2664 String codebase = localref.toString();
2665 if (url.indexOf("/") == 0)
2667 url = codebase.substring(0, codebase.length()
2668 - localref.getFile().length())
2673 url = localref + url;
2679 * open a URL in the browser - resolving it according to relative refs and
2680 * coping with javascript: protocol if necessary.
2685 public void showURL(String url, String target)
2689 if (url.indexOf(":") == -1)
2691 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2693 // Should really use docbase, not codebase.
2695 url = resolveUrlForLocalOrAbsolute(
2697 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2702 .println("Show url (prepended "
2704 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2712 System.err.println("Show url: " + url);
2715 if (url.indexOf("javascript:") == 0)
2717 // no target for the javascript context
2718 getAppletContext().showDocument(new java.net.URL(url));
2722 getAppletContext().showDocument(new java.net.URL(url), target);
2724 } catch (Exception ex)
2726 ex.printStackTrace();
2731 * bind structures in a viewer to any matching sequences in an alignFrame (use
2732 * sequenceIds to limit scope of search to specific sequences)
2736 * @param sequenceIds
2737 * @return TODO: consider making an exception structure for indicating when
2738 * binding fails public SequenceStructureBinding
2739 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2742 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2743 * alFrame.addStructureViewInstance(viewer,
2744 * separatorListToArray(sequenceIds)); } else { return
2745 * alFrame.addStructureViewInstance(viewer, null); } // return null; }