2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.api.StructureSelectionManagerProvider;
22 import jalview.appletgui.AlignFrame;
23 import jalview.appletgui.AlignViewport;
24 import jalview.appletgui.EmbmenuFrame;
25 import jalview.appletgui.FeatureSettings;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.AlignmentOrder;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.AnnotationFile;
35 import jalview.io.AppletFormatAdapter;
36 import jalview.io.FileParse;
37 import jalview.io.IdentifyFile;
38 import jalview.io.JnetAnnotationMaker;
39 import jalview.javascript.JSFunctionExec;
40 import jalview.javascript.JalviewLiteJsApi;
41 import jalview.javascript.JsCallBack;
42 import jalview.structure.SelectionListener;
43 import jalview.structure.StructureSelectionManager;
44 import jalview.util.MessageManager;
46 import java.applet.Applet;
47 import java.awt.Button;
48 import java.awt.Color;
49 import java.awt.Component;
50 import java.awt.EventQueue;
52 import java.awt.Frame;
53 import java.awt.Graphics;
54 import java.awt.event.ActionEvent;
55 import java.awt.event.WindowAdapter;
56 import java.awt.event.WindowEvent;
57 import java.io.BufferedReader;
58 import java.io.InputStreamReader;
60 import java.util.Hashtable;
61 import java.util.StringTokenizer;
62 import java.util.Vector;
64 import netscape.javascript.JSException;
65 import netscape.javascript.JSObject;
68 * Jalview Applet. Runs in Java 1.18 runtime
71 * @version $Revision: 1.92 $
73 public class JalviewLite extends Applet implements
74 StructureSelectionManagerProvider, JalviewLiteJsApi
77 public StructureSelectionManager getStructureSelectionManager()
79 return StructureSelectionManager.getStructureSelectionManager(this);
82 // /////////////////////////////////////////
83 // The following public methods maybe called
84 // externally, eg via javascript in HTML page
88 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
90 public String getSelectedSequences()
92 return getSelectedSequencesFrom(getDefaultTargetFrame());
98 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
100 public String getSelectedSequences(String sep)
102 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
109 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
112 public String getSelectedSequencesFrom(AlignFrame alf)
114 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
121 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
122 * .AlignFrame, java.lang.String)
124 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
126 StringBuffer result = new StringBuffer("");
127 if (sep == null || sep.length() == 0)
129 sep = separator; // "+0x00AC;
131 if (alf.viewport.getSelectionGroup() != null)
133 SequenceI[] seqs = alf.viewport.getSelectionGroup()
134 .getSequencesInOrder(alf.viewport.getAlignment());
136 for (int i = 0; i < seqs.length; i++)
138 result.append(seqs[i].getName());
143 return result.toString();
149 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
150 * java.lang.String, java.lang.String)
152 public void highlight(String sequenceId, String position,
153 String alignedPosition)
155 highlightIn(getDefaultTargetFrame(), sequenceId, position,
162 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
163 * java.lang.String, java.lang.String, java.lang.String)
165 public void highlightIn(final AlignFrame alf, final String sequenceId,
166 final String position, final String alignedPosition)
168 // TODO: could try to highlight in all alignments if alf==null
169 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
170 alf.viewport.getAlignment().getSequencesArray());
171 final SequenceI sq = matcher.findIdMatch(sequenceId);
177 apos = new Integer(position).intValue();
179 } catch (NumberFormatException ex)
183 final StructureSelectionManagerProvider me = this;
184 final int pos = apos;
185 // use vamsas listener to broadcast to all listeners in scope
186 if (alignedPosition != null
187 && (alignedPosition.trim().length() == 0 || alignedPosition
188 .toLowerCase().indexOf("false") > -1))
190 java.awt.EventQueue.invokeLater(new Runnable()
195 StructureSelectionManager.getStructureSelectionManager(me)
196 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
202 java.awt.EventQueue.invokeLater(new Runnable()
207 StructureSelectionManager.getStructureSelectionManager(me)
208 .mouseOverVamsasSequence(sq, pos, null);
218 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
221 public void select(String sequenceIds, String columns)
223 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
229 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
230 * java.lang.String, java.lang.String)
232 public void select(String sequenceIds, String columns, String sep)
234 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
240 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
241 * java.lang.String, java.lang.String)
243 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
245 selectIn(alf, sequenceIds, columns, separator);
251 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
252 * java.lang.String, java.lang.String, java.lang.String)
254 public void selectIn(final AlignFrame alf, String sequenceIds,
255 String columns, String sep)
257 if (sep == null || sep.length() == 0)
265 System.err.println("Selecting region using separator string '"
270 String[] ids = separatorListToArray(sequenceIds, sep);
271 String[] cols = separatorListToArray(columns, sep);
272 final SequenceGroup sel = new SequenceGroup();
273 final ColumnSelection csel = new ColumnSelection();
274 AlignmentI al = alf.viewport.getAlignment();
275 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
276 alf.viewport.getAlignment().getSequencesArray());
277 int start = 0, end = al.getWidth(), alw = al.getWidth();
278 boolean seqsfound = true;
279 if (ids != null && ids.length > 0)
282 for (int i = 0; i < ids.length; i++)
284 if (ids[i].trim().length() == 0)
288 SequenceI sq = matcher.findIdMatch(ids[i]);
292 sel.addSequence(sq, false);
296 boolean inseqpos = false;
297 if (cols != null && cols.length > 0)
299 boolean seset = false;
300 for (int i = 0; i < cols.length; i++)
302 String cl = cols[i].trim();
303 if (cl.length() == 0)
308 if ((p = cl.indexOf("-")) > -1)
310 int from = -1, to = -1;
313 from = new Integer(cl.substring(0, p)).intValue();
315 } catch (NumberFormatException ex)
318 .println("ERROR: Couldn't parse first integer in range element column selection string '"
319 + cl + "' - format is 'from-to'");
324 to = new Integer(cl.substring(p + 1)).intValue();
326 } catch (NumberFormatException ex)
329 .println("ERROR: Couldn't parse second integer in range element column selection string '"
330 + cl + "' - format is 'from-to'");
333 if (from >= 0 && to >= 0)
350 // comment to prevent range extension
360 for (int r = from; r <= to; r++)
362 if (r >= 0 && r < alw)
369 System.err.println("Range '" + cl + "' deparsed as [" + from
375 System.err.println("ERROR: Invalid Range '" + cl
376 + "' deparsed as [" + from + "," + to + "]");
384 r = new Integer(cl).intValue();
386 } catch (NumberFormatException ex)
388 if (cl.toLowerCase().equals("sequence"))
390 // we are in the dataset sequence's coordinate frame.
396 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
401 if (r >= 0 && r <= alw)
411 // comment to prevent range extension
424 System.err.println("Point selection '" + cl
425 + "' deparsed as [" + r + "]");
430 System.err.println("ERROR: Invalid Point selection '" + cl
431 + "' deparsed as [" + r + "]");
438 // we only propagate the selection when it was the null selection, or the
439 // given sequences were found in the alignment.
440 if (inseqpos && sel.getSize() > 0)
442 // assume first sequence provides reference frame ?
443 SequenceI rs = sel.getSequenceAt(0);
444 start = rs.findIndex(start);
445 end = rs.findIndex(end);
448 Vector cs = csel.getSelected();
450 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
452 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
457 sel.setStartRes(start);
459 EventQueue.invokeLater(new Runnable()
464 alf.select(sel, csel);
474 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
475 * String, java.lang.String)
477 public String getSelectedSequencesAsAlignment(String format, String suffix)
479 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
487 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
488 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
490 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
491 String format, String suffix)
495 boolean seqlimits = suffix.equalsIgnoreCase("true");
496 if (alf.viewport.getSelectionGroup() != null)
498 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
499 // method now returns a full copy of sequence data
500 // TODO consider using getSequenceSelection instead here
501 String reply = new AppletFormatAdapter().formatSequences(format,
502 new Alignment(alf.viewport.getSelectionAsNewSequence()),
506 } catch (Exception ex)
508 ex.printStackTrace();
509 return "Error retrieving alignment in " + format + " format. ";
517 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
519 public String getAlignmentOrder()
521 return getAlignmentOrderFrom(getDefaultTargetFrame());
528 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
531 public String getAlignmentOrderFrom(AlignFrame alf)
533 return getAlignmentOrderFrom(alf, separator);
540 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
541 * , java.lang.String)
543 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
545 AlignmentI alorder = alf.getAlignViewport().getAlignment();
546 String[] order = new String[alorder.getHeight()];
547 for (int i = 0; i < order.length; i++)
549 order[i] = alorder.getSequenceAt(i).getName();
551 return arrayToSeparatorList(order);
557 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
560 public String orderBy(String order, String undoName)
562 return orderBy(order, undoName, separator);
568 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
569 * java.lang.String, java.lang.String)
571 public String orderBy(String order, String undoName, String sep)
573 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
580 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
581 * java.lang.String, java.lang.String, java.lang.String)
583 public String orderAlignmentBy(AlignFrame alf, String order,
584 String undoName, String sep)
586 String[] ids = separatorListToArray(order, sep);
587 SequenceI[] sqs = null;
588 if (ids != null && ids.length > 0)
590 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
591 alf.viewport.getAlignment().getSequencesArray());
593 sqs = new SequenceI[ids.length];
594 for (int i = 0; i < ids.length; i++)
596 if (ids[i].trim().length() == 0)
600 SequenceI sq = matcher.findIdMatch(ids[i]);
608 SequenceI[] sqq = new SequenceI[s];
609 System.arraycopy(sqs, 0, sqq, 0, s);
622 final AlignmentOrder aorder = new AlignmentOrder(sqs);
624 if (undoName != null && undoName.trim().length() == 0)
628 final String _undoName = undoName;
629 // TODO: deal with synchronization here: cannot raise any events until after
630 // this has returned.
631 return alf.sortBy(aorder, _undoName) ? "true" : "";
637 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
639 public String getAlignment(String format)
641 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
648 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
651 public String getAlignmentFrom(AlignFrame alf, String format)
653 return getAlignmentFrom(alf, format, "true");
659 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
662 public String getAlignment(String format, String suffix)
664 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
671 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
672 * java.lang.String, java.lang.String)
674 public String getAlignmentFrom(AlignFrame alf, String format,
679 boolean seqlimits = suffix.equalsIgnoreCase("true");
681 String reply = new AppletFormatAdapter().formatSequences(format,
682 alf.viewport.getAlignment(), seqlimits);
684 } catch (Exception ex)
686 ex.printStackTrace();
687 return "Error retrieving alignment in " + format + " format. ";
694 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
696 public void loadAnnotation(String annotation)
698 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
705 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
706 * , java.lang.String)
708 public void loadAnnotationFrom(AlignFrame alf, String annotation)
710 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
711 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
713 alf.alignPanel.fontChanged();
714 alf.alignPanel.setScrollValues(0, 0);
718 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
725 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
727 public void loadFeatures(String features, boolean autoenabledisplay)
729 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
736 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
737 * , java.lang.String)
739 public boolean loadFeaturesFrom(AlignFrame alf, String features,
740 boolean autoenabledisplay)
742 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
749 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
751 public String getFeatures(String format)
753 return getFeaturesFrom(getDefaultTargetFrame(), format);
760 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
763 public String getFeaturesFrom(AlignFrame alf, String format)
765 return alf.outputFeatures(false, format);
771 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
773 public String getAnnotation()
775 return getAnnotationFrom(getDefaultTargetFrame());
782 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
785 public String getAnnotationFrom(AlignFrame alf)
787 return alf.outputAnnotations(false);
793 * @see jalview.bin.JalviewLiteJsApi#newView()
795 public AlignFrame newView()
797 return newViewFrom(getDefaultTargetFrame());
803 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
805 public AlignFrame newView(String name)
807 return newViewFrom(getDefaultTargetFrame(), name);
813 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
815 public AlignFrame newViewFrom(AlignFrame alf)
817 return alf.newView(null);
823 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
826 public AlignFrame newViewFrom(AlignFrame alf, String name)
828 return alf.newView(name);
834 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
837 public AlignFrame loadAlignment(String text, String title)
841 String format = new IdentifyFile().Identify(text,
842 AppletFormatAdapter.PASTE);
845 al = new AppletFormatAdapter().readFile(text,
846 AppletFormatAdapter.PASTE, format);
847 if (al.getHeight() > 0)
849 return new AlignFrame(al, this, title, false);
851 } catch (java.io.IOException ex)
853 ex.printStackTrace();
861 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
863 public void setMouseoverListener(String listener)
865 setMouseoverListener(currentAlignFrame, listener);
868 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
874 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
875 * , java.lang.String)
877 public void setMouseoverListener(AlignFrame af, String listener)
879 if (listener != null)
881 listener = listener.trim();
882 if (listener.length() == 0)
885 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
889 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
891 javascriptListeners.addElement(mol);
892 StructureSelectionManager.getStructureSelectionManager(this)
893 .addStructureViewerListener(mol);
896 System.err.println("Added a mouseover listener for "
897 + ((af == null) ? "All frames" : "Just views for "
898 + af.getAlignViewport().getSequenceSetId()));
899 System.err.println("There are now " + javascriptListeners.size()
900 + " listeners in total.");
907 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
909 public void setSelectionListener(String listener)
911 setSelectionListener(null, listener);
918 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
919 * , java.lang.String)
921 public void setSelectionListener(AlignFrame af, String listener)
923 if (listener != null)
925 listener = listener.trim();
926 if (listener.length() == 0)
929 .println("jalview Javascript error: Ignoring empty function for selection listener.");
933 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
935 javascriptListeners.addElement(mol);
936 StructureSelectionManager.getStructureSelectionManager(this)
937 .addSelectionListener(mol);
940 System.err.println("Added a selection listener for "
941 + ((af == null) ? "All frames" : "Just views for "
942 + af.getAlignViewport().getSequenceSetId()));
943 System.err.println("There are now " + javascriptListeners.size()
944 + " listeners in total.");
951 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
954 public void setStructureListener(String listener, String modelSet)
956 if (listener != null)
958 listener = listener.trim();
959 if (listener.length() == 0)
962 .println("jalview Javascript error: Ignoring empty function for selection listener.");
966 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
967 this, listener, separatorListToArray(modelSet));
968 javascriptListeners.addElement(mol);
969 StructureSelectionManager.getStructureSelectionManager(this)
970 .addStructureViewerListener(mol);
973 System.err.println("Added a javascript structure viewer listener '"
975 System.err.println("There are now " + javascriptListeners.size()
976 + " listeners in total.");
984 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
985 * .AlignFrame, java.lang.String)
987 public void removeJavascriptListener(AlignFrame af, String listener)
989 if (listener != null)
991 listener = listener.trim();
992 if (listener.length() == 0)
997 boolean rprt = false;
998 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1000 Object lstn = javascriptListeners.elementAt(ms);
1001 JsCallBack lstner = (JsCallBack) lstn;
1002 if ((af == null || lstner.getAlignFrame() == af)
1003 && (listener == null || lstner.getListenerFunction().equals(
1006 javascriptListeners.removeElement(lstner);
1008 if (lstner instanceof SelectionListener)
1010 StructureSelectionManager.getStructureSelectionManager(this)
1011 .removeSelectionListener((SelectionListener) lstner);
1015 StructureSelectionManager.getStructureSelectionManager(this)
1016 .removeStructureViewerListener(lstner, null);
1021 System.err.println("Removed listener '" + listener + "'");
1031 System.err.println("There are now " + javascriptListeners.size()
1032 + " listeners in total.");
1038 System.err.println("Applet " + getName() + " stop().");
1042 public void destroy()
1044 System.err.println("Applet " + getName() + " destroy().");
1048 private void tidyUp()
1051 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1052 && currentAlignFrame.viewport.applet != null)
1054 AlignViewport av = currentAlignFrame.viewport;
1055 currentAlignFrame.closeMenuItem_actionPerformed();
1057 currentAlignFrame = null;
1059 if (javascriptListeners != null)
1061 while (javascriptListeners.size() > 0)
1063 jalview.javascript.JSFunctionExec mol = javascriptListeners
1065 javascriptListeners.removeElement(mol);
1066 if (mol instanceof SelectionListener)
1068 StructureSelectionManager.getStructureSelectionManager(this)
1069 .removeSelectionListener((SelectionListener) mol);
1073 StructureSelectionManager.getStructureSelectionManager(this)
1074 .removeStructureViewerListener(mol, null);
1079 if (jsFunctionExec != null)
1081 jsFunctionExec.stopQueue();
1082 jsFunctionExec.jvlite = null;
1084 initialAlignFrame = null;
1085 jsFunctionExec = null;
1086 javascriptListeners = null;
1087 StructureSelectionManager.release(this);
1090 private jalview.javascript.JSFunctionExec jsFunctionExec;
1095 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1096 * java.lang.String, java.lang.String)
1098 public void mouseOverStructure(final String pdbResNum,
1099 final String chain, final String pdbfile)
1101 final StructureSelectionManagerProvider me = this;
1102 java.awt.EventQueue.invokeLater(new Runnable()
1109 StructureSelectionManager.getStructureSelectionManager(me)
1110 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1114 System.err.println("mouseOver for '" + pdbResNum
1115 + "' in chain '" + chain + "' in structure '" + pdbfile
1118 } catch (NumberFormatException e)
1120 System.err.println("Ignoring invalid residue number string '"
1132 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1133 * java.lang.String, java.lang.String)
1135 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1136 final String leftHandColumn)
1138 java.awt.EventQueue.invokeLater(new Runnable()
1145 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1146 leftHandColumn).intValue());
1148 } catch (Exception ex)
1150 System.err.println("Couldn't parse integer arguments (topRow='"
1151 + topRow + "' and leftHandColumn='" + leftHandColumn
1153 ex.printStackTrace();
1163 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1164 * .AlignFrame, java.lang.String)
1167 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1170 java.awt.EventQueue.invokeLater(new Runnable()
1177 alf.scrollToRow(new Integer(topRow).intValue());
1179 } catch (Exception ex)
1181 System.err.println("Couldn't parse integer arguments (topRow='"
1183 ex.printStackTrace();
1194 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1195 * .AlignFrame, java.lang.String)
1198 public void scrollViewToColumnIn(final AlignFrame alf,
1199 final String leftHandColumn)
1201 java.awt.EventQueue.invokeLater(new Runnable()
1209 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1211 } catch (Exception ex)
1214 .println("Couldn't parse integer arguments (leftHandColumn='"
1215 + leftHandColumn + "')");
1216 ex.printStackTrace();
1223 // //////////////////////////////////////////////
1224 // //////////////////////////////////////////////
1226 public static int lastFrameX = 200;
1228 public static int lastFrameY = 200;
1230 boolean fileFound = true;
1232 String file = "No file";
1234 Button launcher = new Button("Start Jalview");
1237 * The currentAlignFrame is static, it will change if and when the user
1238 * selects a new window. Note that it will *never* point back to the embedded
1239 * AlignFrame if the applet is started as embedded on the page and then
1240 * afterwards a new view is created.
1242 public AlignFrame currentAlignFrame = null;
1245 * This is the first frame to be displayed, and does not change. API calls
1246 * will default to this instance if currentAlignFrame is null.
1248 AlignFrame initialAlignFrame = null;
1250 boolean embedded = false;
1252 private boolean checkForJmol = true;
1254 private boolean checkedForJmol = false; // ensure we don't check for jmol
1256 // every time the app is re-inited
1258 public boolean jmolAvailable = false;
1260 private boolean alignPdbStructures = false;
1263 * use an external structure viewer exclusively (no jmols or MCViews will be
1264 * opened by JalviewLite itself)
1266 public boolean useXtrnalSviewer = false;
1268 public static boolean debug = false;
1270 static String builddate = null, version = null;
1272 private static void initBuildDetails()
1274 if (builddate == null)
1276 builddate = "unknown";
1278 java.net.URL url = JalviewLite.class
1279 .getResource("/.build_properties");
1284 BufferedReader reader = new BufferedReader(new InputStreamReader(
1287 while ((line = reader.readLine()) != null)
1289 if (line.indexOf("VERSION") > -1)
1291 version = line.substring(line.indexOf("=") + 1);
1293 if (line.indexOf("BUILD_DATE") > -1)
1295 builddate = line.substring(line.indexOf("=") + 1);
1298 } catch (Exception ex)
1300 ex.printStackTrace();
1306 public static String getBuildDate()
1312 public static String getVersion()
1318 // public JSObject scriptObject = null;
1321 * init method for Jalview Applet
1325 // remove any handlers that might be hanging around from an earlier instance
1330 System.err.println("Applet context is '"
1331 + getAppletContext().getClass().toString() + "'");
1333 JSObject scriptObject = JSObject.getWindow(this);
1334 if (debug && scriptObject != null)
1336 System.err.println("Applet has Javascript callback support.");
1339 } catch (Exception ex)
1342 .println("Warning: No JalviewLite javascript callbacks available.");
1345 ex.printStackTrace();
1349 * turn on extra applet debugging
1351 String dbg = getParameter("debug");
1354 debug = dbg.toLowerCase().equals("true");
1359 System.err.println("JalviewLite Version " + getVersion());
1360 System.err.println("Build Date : " + getBuildDate());
1363 String externalsviewer = getParameter("externalstructureviewer");
1364 if (externalsviewer != null)
1366 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1370 * if true disable the check for jmol
1372 String chkforJmol = getParameter("nojmol");
1373 if (chkforJmol != null)
1375 checkForJmol = !chkforJmol.equals("true");
1378 * get the separator parameter if present
1380 String sep = getParameter("separator");
1383 if (sep.length() > 0)
1388 System.err.println("Separator set to '" + separator + "'");
1394 "Invalid separator parameter - must be non-zero length");
1400 String param = getParameter("RGB");
1406 r = Integer.parseInt(param.substring(0, 2), 16);
1407 g = Integer.parseInt(param.substring(2, 4), 16);
1408 b = Integer.parseInt(param.substring(4, 6), 16);
1409 } catch (Exception ex)
1416 param = getParameter("label");
1419 launcher.setLabel(param);
1422 setBackground(new Color(r, g, b));
1424 file = getParameter("file");
1428 // Maybe the sequences are added as parameters
1429 StringBuffer data = new StringBuffer("PASTE");
1431 while ((file = getParameter("sequence" + i)) != null)
1433 data.append(file.toString() + "\n");
1436 if (data.length() > 5)
1438 file = data.toString();
1442 final JalviewLite jvapplet = this;
1443 if (getParameter("embedded") != null
1444 && getParameter("embedded").equalsIgnoreCase("true"))
1446 // Launch as embedded applet in page
1448 LoadingThread loader = new LoadingThread(file, jvapplet);
1451 else if (file != null)
1453 if (getParameter("showbutton") == null
1454 || !getParameter("showbutton").equalsIgnoreCase("false"))
1456 // Add the JalviewLite 'Button' to the page
1458 launcher.addActionListener(new java.awt.event.ActionListener()
1460 public void actionPerformed(ActionEvent e)
1462 LoadingThread loader = new LoadingThread(file, jvapplet);
1469 // Open jalviewLite immediately.
1470 LoadingThread loader = new LoadingThread(file, jvapplet);
1476 // jalview initialisation with no alignment. loadAlignment() method can
1477 // still be called to open new alignments.
1483 private void initLiveConnect()
1485 // try really hard to get the liveConnect thing working
1486 boolean notFailed=false;
1488 while (notFailed && tries<10) {
1491 System.err.println("LiveConnect request thread going to sleep.");
1494 Thread.sleep(700*(1+tries));
1496 catch (InterruptedException q) {};
1499 System.err.println("LiveConnect request thread woken up.");
1502 JSObject scriptObject = JSObject.getWindow(this);
1503 if (scriptObject.eval("navigator")!=null)
1507 } catch (JSException jsex)
1509 System.err.println("Attempt "+tries+" to access LiveConnect javascript failed.");
1513 private void callInitCallback()
1515 String initjscallback = getParameter("oninit");
1516 if (initjscallback == null)
1520 initjscallback = initjscallback.trim();
1521 if (initjscallback.length() > 0)
1523 JSObject scriptObject = null;
1526 scriptObject = JSObject.getWindow(this);
1527 } catch (Exception ex)
1531 // try really hard to let the browser plugin know we want liveconnect
1534 if (scriptObject != null)
1538 // do onInit with the JS executor thread
1539 new JSFunctionExec(this).executeJavascriptFunction(true,
1540 initjscallback, null, "Calling oninit callback '"
1541 + initjscallback + "'.");
1542 } catch (Exception e)
1544 System.err.println("Exception when executing _oninit callback '"
1545 + initjscallback + "'.");
1546 e.printStackTrace();
1551 System.err.println("Not executing _oninit callback '"
1552 + initjscallback + "' - no scripting allowed.");
1558 * Initialises and displays a new java.awt.Frame
1561 * java.awt.Frame to be displayed
1563 * title of new frame
1565 * width if new frame
1567 * height of new frame
1569 public static void addFrame(final Frame frame, String title, int width,
1572 frame.setLocation(lastFrameX, lastFrameY);
1575 frame.setSize(width, height);
1576 frame.setTitle(title);
1577 frame.addWindowListener(new WindowAdapter()
1579 public void windowClosing(WindowEvent e)
1581 if (frame instanceof AlignFrame)
1583 AlignViewport vp = ((AlignFrame) frame).viewport;
1584 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1585 if (vp.applet.currentAlignFrame == frame)
1587 vp.applet.currentAlignFrame = null;
1595 if (frame instanceof EmbmenuFrame)
1597 ((EmbmenuFrame) frame).destroyMenus();
1599 frame.setMenuBar(null);
1603 public void windowActivated(WindowEvent e)
1605 if (frame instanceof AlignFrame)
1607 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1610 System.err.println("Activated window " + frame);
1614 super.windowActivated(e);
1617 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1620 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1623 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1624 * frame) { currentAlignFrame = null; if (debug) {
1625 * System.err.println("Deactivated window "+frame); } }
1626 * super.windowDeactivated(e); }
1629 frame.setVisible(true);
1633 * This paints the background surrounding the "Launch Jalview button" <br>
1635 * If file given in parameter not found, displays error message
1640 public void paint(Graphics g)
1644 g.setColor(new Color(200, 200, 200));
1645 g.setColor(Color.cyan);
1646 g.fillRect(0, 0, getSize().width, getSize().height);
1647 g.setColor(Color.red);
1648 g.drawString(MessageManager.getString("label.jalview_cannot_open_file"), 5, 15);
1649 g.drawString("\"" + file + "\"", 5, 30);
1653 g.setColor(Color.black);
1654 g.setFont(new Font("Arial", Font.BOLD, 24));
1655 g.drawString(MessageManager.getString("label.jalview_applet"), 50, getSize().height / 2 - 30);
1656 g.drawString(MessageManager.getString("label.loading_data") + "...", 50, getSize().height / 2);
1661 * get all components associated with the applet of the given type
1666 public Vector getAppletWindow(Class class1)
1668 Vector wnds = new Vector();
1669 Component[] cmp = getComponents();
1672 for (int i = 0; i < cmp.length; i++)
1674 if (class1.isAssignableFrom(cmp[i].getClass()))
1676 wnds.addElement(cmp);
1683 class LoadJmolThread extends Thread
1685 private boolean running = false;
1689 if (running || checkedForJmol)
1698 if (!System.getProperty("java.version").startsWith("1.1"))
1700 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1701 jmolAvailable = true;
1706 .println("Jmol not available - Using MCview for structures");
1708 } catch (java.lang.ClassNotFoundException ex)
1714 jmolAvailable = false;
1718 .println("Skipping Jmol check. Will use MCView (probably)");
1721 checkedForJmol = true;
1725 public boolean notFinished()
1727 return running || !checkedForJmol;
1731 class LoadingThread extends Thread
1734 * State variable: File source
1739 * State variable: protocol for access to file source
1744 * State variable: format of file source
1752 private void dbgMsg(String msg)
1756 System.err.println(msg);
1761 * update the protocol state variable for accessing the datasource located
1765 * @return possibly updated datasource string
1767 public String setProtocolState(String file)
1769 if (file.startsWith("PASTE"))
1771 file = file.substring(5);
1772 protocol = AppletFormatAdapter.PASTE;
1774 else if (inArchive(file))
1776 protocol = AppletFormatAdapter.CLASSLOADER;
1780 file = addProtocol(file);
1781 protocol = AppletFormatAdapter.URL;
1783 dbgMsg("Protocol identified as '" + protocol + "'");
1787 public LoadingThread(String _file, JalviewLite _applet)
1795 LoadJmolThread jmolchecker = new LoadJmolThread();
1796 jmolchecker.start();
1797 while (jmolchecker.notFinished())
1799 // wait around until the Jmol check is complete.
1803 } catch (Exception e)
1809 // applet.callInitCallback();
1812 private void startLoading()
1814 AlignFrame newAlignFrame;
1815 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1816 file = setProtocolState(_file);
1818 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1819 dbgMsg("File identified as '" + format + "'");
1820 dbgMsg("Loading started.");
1821 Alignment al = null;
1824 al = new AppletFormatAdapter().readFile(file, protocol, format);
1825 } catch (java.io.IOException ex)
1827 dbgMsg("File load exception.");
1828 ex.printStackTrace();
1833 FileParse fp = new FileParse(file, protocol);
1835 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1837 while ((ln = fp.nextLine()) != null)
1841 dbgMsg(">>>Dump finished.");
1842 } catch (Exception e)
1845 .println("Exception when trying to dump the content of the file parameter.");
1846 e.printStackTrace();
1850 if ((al != null) && (al.getHeight() > 0))
1852 dbgMsg("Successfully loaded file.");
1853 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1854 if (initialAlignFrame == null)
1856 initialAlignFrame = newAlignFrame;
1858 // update the focus.
1859 currentAlignFrame = newAlignFrame;
1861 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1863 newAlignFrame.setTitle(MessageManager.formatMessage("label.sequences_from", new String[]{applet.getDocumentBase().toString()}));
1866 newAlignFrame.statusBar.setText(MessageManager.formatMessage("label.successfully_loaded_file", new String []{file}));
1868 String treeFile = applet.getParameter("tree");
1869 if (treeFile == null)
1871 treeFile = applet.getParameter("treeFile");
1874 if (treeFile != null)
1878 treeFile = setProtocolState(treeFile);
1880 * if (inArchive(treeFile)) { protocol =
1881 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1882 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1884 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1889 if (fin.getTree() != null)
1891 newAlignFrame.loadTree(fin, treeFile);
1892 dbgMsg("Successfuly imported tree.");
1896 dbgMsg("Tree parameter did not resolve to a valid tree.");
1898 } catch (Exception ex)
1900 ex.printStackTrace();
1905 * Try to load T-Coffee score file
1907 String sScoreFile = applet.getParameter("scoreFile");
1908 if (sScoreFile != null && !"".equals(sScoreFile))
1915 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
1917 if (!newAlignFrame.loadScoreFile(sScoreFile))
1920 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
1921 + sScoreFile + "')");
1923 } catch (Exception e)
1925 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
1926 sScoreFile, e.getMessage());
1930 // ///////////////////////////
1931 // modify display of features
1932 // we do this before any features have been loaded, ensuring any hidden
1933 // groups are hidden when features first displayed
1935 // hide specific groups
1937 String param = applet.getParameter("hidefeaturegroups");
1940 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1942 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1944 // show specific groups
1945 param = applet.getParameter("showfeaturegroups");
1948 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1950 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1952 // and now load features
1953 param = applet.getParameter("features");
1956 param = setProtocolState(param);
1958 newAlignFrame.parseFeaturesFile(param, protocol);
1961 param = applet.getParameter("showFeatureSettings");
1962 if (param != null && param.equalsIgnoreCase("true"))
1964 newAlignFrame.viewport.showSequenceFeatures(true);
1965 new FeatureSettings(newAlignFrame.alignPanel);
1968 param = applet.getParameter("annotations");
1971 param = setProtocolState(param);
1973 if (new AnnotationFile().readAnnotationFile(
1974 newAlignFrame.viewport.getAlignment(), param, protocol))
1976 newAlignFrame.alignPanel.fontChanged();
1977 newAlignFrame.alignPanel.setScrollValues(0, 0);
1982 .println("Annotations were not added from annotation file '"
1988 param = applet.getParameter("jnetfile");
1993 param = setProtocolState(param);
1994 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
1996 JnetAnnotationMaker.add_annotation(predictions,
1997 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
2005 newAlignFrame.alignPanel.fontChanged();
2006 newAlignFrame.alignPanel.setScrollValues(0, 0);
2007 } catch (Exception ex)
2009 ex.printStackTrace();
2013 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
2014 * - related to JAL-434
2016 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2019 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2022 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2024 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2027 int pdbFileCount = 0;
2028 // Accumulate pdbs here if they are heading for the same view (if
2029 // alignPdbStructures is true)
2030 Vector pdbs = new Vector();
2031 // create a lazy matcher if we're asked to
2032 jalview.analysis.SequenceIdMatcher matcher = (applet
2033 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2034 newAlignFrame.getAlignViewport().getAlignment()
2035 .getSequencesArray()) : null;
2039 if (pdbFileCount > 0)
2041 param = applet.getParameter("PDBFILE" + pdbFileCount);
2045 param = applet.getParameter("PDBFILE");
2050 PDBEntry pdb = new PDBEntry();
2053 SequenceI[] seqs = null;
2054 String[] chains = null;
2056 StringTokenizer st = new StringTokenizer(param, " ");
2058 if (st.countTokens() < 2)
2060 String sequence = applet.getParameter("PDBSEQ");
2061 if (sequence != null)
2062 seqs = new SequenceI[]
2063 { matcher == null ? (Sequence) newAlignFrame
2064 .getAlignViewport().getAlignment()
2065 .findName(sequence) : matcher.findIdMatch(sequence) };
2070 param = st.nextToken();
2071 Vector tmp = new Vector();
2072 Vector tmp2 = new Vector();
2074 while (st.hasMoreTokens())
2076 seqstring = st.nextToken();
2077 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2078 if (st2.countTokens() > 1)
2080 // This is the chain
2081 tmp2.addElement(st2.nextToken());
2082 seqstring = st2.nextToken();
2084 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
2085 .getAlignViewport().getAlignment()
2086 .findName(seqstring) : matcher
2087 .findIdMatch(seqstring));
2090 seqs = new SequenceI[tmp.size()];
2092 if (tmp2.size() == tmp.size())
2094 chains = new String[tmp2.size()];
2095 tmp2.copyInto(chains);
2098 param = setProtocolState(param);
2100 if (// !jmolAvailable
2102 protocol == AppletFormatAdapter.CLASSLOADER
2103 && !useXtrnalSviewer)
2105 // Re: JAL-357 : the bug isn't a problem if we are using an
2107 // TODO: verify this Re:
2108 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2109 // This exception preserves the current behaviour where, even if
2110 // the local pdb file was identified in the class loader
2111 protocol = AppletFormatAdapter.URL; // this is probably NOT
2113 param = addProtocol(param); //
2120 for (int i = 0; i < seqs.length; i++)
2122 if (seqs[i] != null)
2124 ((Sequence) seqs[i]).addPDBId(pdb);
2128 if (JalviewLite.debug)
2130 // this may not really be a problem but we give a warning
2133 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2139 if (!alignPdbStructures)
2141 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
2146 pdbs.addElement(new Object[]
2147 { pdb, seqs, chains, new String(protocol) });
2153 } while (param != null || pdbFileCount < 10);
2154 if (pdbs.size() > 0)
2156 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2157 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2158 String[][] chains = new String[pdbs.size()][];
2159 String[] protocols = new String[pdbs.size()];
2160 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2162 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2163 pdb[pdbsi] = (PDBEntry) o[0];
2164 seqs[pdbsi] = (SequenceI[]) o[1];
2165 chains[pdbsi] = (String[]) o[2];
2166 protocols[pdbsi] = (String) o[3];
2168 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
2176 applet.remove(launcher);
2183 * Discovers whether the given file is in the Applet Archive
2189 boolean inArchive(String file)
2191 // This might throw a security exception in certain browsers
2192 // Netscape Communicator for instance.
2195 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2198 System.err.println("Resource '" + file + "' was "
2199 + (rtn ? "" : "not") + " located by classloader.");
2202 } catch (Exception ex)
2204 System.out.println("Exception checking resources: " + file + " "
2210 String addProtocol(String file)
2212 if (file.indexOf("://") == -1)
2214 String fl = applet.resolveUrlForLocalOrAbsolute(file,
2218 if (new java.net.URL(fl).openStream() != null)
2222 System.err.println("Prepended document base for resource: '"
2227 } catch (Exception x)
2231 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2234 if (new java.net.URL(fl).openStream() != null)
2238 System.err.println("Prepended codebase for resource: '"
2243 } catch (Exception x)
2255 * @return the default alignFrame acted on by the public applet methods. May
2256 * return null with an error message on System.err indicating the
2259 public AlignFrame getDefaultTargetFrame()
2261 if (currentAlignFrame != null)
2263 return currentAlignFrame;
2265 if (initialAlignFrame != null)
2267 return initialAlignFrame;
2270 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2275 * separator used for separatorList
2277 protected String separator = "" + ((char) 0x00AC); // the default used to be
2278 // '|' but many sequence
2279 // IDS include pipes.
2282 * set to enable the URL based javascript execution mechanism
2284 public boolean jsfallbackEnabled = false;
2287 * parse the string into a list
2290 * @return elements separated by separator
2292 public String[] separatorListToArray(String list)
2294 return separatorListToArray(list, separator);
2298 * parse the string into a list
2302 * @return elements separated by separator
2304 public String[] separatorListToArray(String list, String separator)
2306 // note separator local variable intentionally masks object field
2307 int seplen = separator.length();
2308 if (list == null || list.equals("") || list.equals(separator))
2310 java.util.Vector jv = new Vector();
2312 while ((pos = list.indexOf(separator, cp)) > cp)
2314 jv.addElement(list.substring(cp, pos));
2317 if (cp < list.length())
2319 String c = list.substring(cp);
2320 if (!c.equals(separator))
2327 String[] v = new String[jv.size()];
2328 for (int i = 0; i < v.length; i++)
2330 v[i] = (String) jv.elementAt(i);
2332 jv.removeAllElements();
2335 System.err.println("Array from '" + separator
2336 + "' separated List:\n" + v.length);
2337 for (int i = 0; i < v.length; i++)
2339 System.err.println("item " + i + " '" + v[i] + "'");
2346 System.err.println("Empty Array from '" + separator
2347 + "' separated List");
2353 * concatenate the list with separator
2356 * @return concatenated string
2358 public String arrayToSeparatorList(String[] list)
2360 return arrayToSeparatorList(list, separator);
2364 * concatenate the list with separator
2368 * @return concatenated string
2370 public String arrayToSeparatorList(String[] list, String separator)
2372 StringBuffer v = new StringBuffer();
2373 if (list != null && list.length > 0)
2375 for (int i = 0, iSize = list.length; i < iSize; i++)
2377 if (list[i] != null)
2381 v.append(separator);
2388 System.err.println("Returning '" + separator
2389 + "' separated List:\n");
2390 System.err.println(v);
2392 return v.toString();
2396 System.err.println("Returning empty '" + separator
2397 + "' separated List\n");
2399 return "" + separator;
2405 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2407 public String getFeatureGroups()
2409 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2410 .getFeatureGroups());
2418 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2421 public String getFeatureGroupsOn(AlignFrame alf)
2423 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2430 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2432 public String getFeatureGroupsOfState(boolean visible)
2434 return arrayToSeparatorList(getDefaultTargetFrame()
2435 .getFeatureGroupsOfState(visible));
2442 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2443 * .AlignFrame, boolean)
2445 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2447 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2453 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2454 * AlignFrame, java.lang.String, boolean)
2456 public void setFeatureGroupStateOn(final AlignFrame alf,
2457 final String groups, boolean state)
2459 final boolean st = state;// !(state==null || state.equals("") ||
2460 // state.toLowerCase().equals("false"));
2461 java.awt.EventQueue.invokeLater(new Runnable()
2466 alf.setFeatureGroupState(separatorListToArray(groups), st);
2474 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2477 public void setFeatureGroupState(String groups, boolean state)
2479 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2485 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2487 public String getSeparator()
2495 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2497 public void setSeparator(String separator)
2499 if (separator == null || separator.length() < 1)
2502 separator = "" + ((char) 0x00AC);
2504 this.separator = separator;
2507 System.err.println("Default Separator now: '" + separator + "'");
2512 * get boolean value of applet parameter 'name' and return default if
2513 * parameter is not set
2518 * the value to return otherwise
2519 * @return true or false
2521 public boolean getDefaultParameter(String name, boolean def)
2524 if ((stn = getParameter(name)) == null)
2528 if (stn.toLowerCase().equals("true"))
2538 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2539 * java.lang.String, java.lang.String, java.lang.String)
2541 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2542 String pdbEntryString, String pdbFile)
2544 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2547 protected void setAlignPdbStructures(boolean alignPdbStructures)
2549 this.alignPdbStructures = alignPdbStructures;
2552 public boolean isAlignPdbStructures()
2554 return alignPdbStructures;
2559 // callInitCallback();
2562 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2564 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2566 public void setJsMessageSet(String messageclass, String viewId,
2567 String[] colcommands)
2569 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2572 msgset = new Hashtable<String, String[]>();
2573 jsmessages.put(messageclass, msgset);
2575 msgset.put(viewId, colcommands);
2576 long[] l = new long[colcommands.length];
2577 for (int i = 0; i < colcommands.length; i++)
2579 l[i] = colcommands[i].hashCode();
2581 jshashes.put(messageclass + "|" + viewId, l);
2587 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2590 public String getJsMessage(String messageclass, String viewId)
2592 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2595 String[] msgs = msgset.get(viewId);
2598 for (int i = 0; i < msgs.length; i++)
2600 if (msgs[i] != null)
2612 public boolean isJsMessageSetChanged(String string, String string2,
2613 String[] colcommands)
2615 long[] l = jshashes.get(string + "|" + string2);
2616 if (l == null && colcommands != null)
2620 for (int i = 0; i < colcommands.length; i++)
2622 if (l[i] != colcommands[i].hashCode())
2630 private Vector jsExecQueue = new Vector();
2632 public Vector getJsExecQueue()
2637 public void setExecutor(JSFunctionExec jsFunctionExec2)
2639 jsFunctionExec = jsFunctionExec2;
2643 * return the given colour value parameter or the given default if parameter
2650 public Color getDefaultColourParameter(String colparam, Color defcolour)
2652 String colprop = getParameter(colparam);
2653 if (colprop == null || colprop.trim().length() == 0)
2657 Color col = jalview.schemes.ColourSchemeProperty
2658 .getAWTColorFromName(colprop);
2663 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2664 } catch (Exception ex)
2666 System.err.println("Couldn't parse '" + colprop
2667 + "' as a colour for " + colparam);
2671 return (col == null) ? defcolour : col;
2675 public void openJalviewHelpUrl()
2677 String helpUrl = getParameter("jalviewhelpurl");
2678 if (helpUrl == null || helpUrl.trim().length() < 5)
2680 helpUrl = "http://www.jalview.org/help.html";
2682 showURL(helpUrl, "HELP");
2686 * form a complete URL given a path to a resource and a reference location on
2690 * - an absolute path on the same server as localref or a document
2691 * located relative to localref
2693 * - a URL on the same server as url
2694 * @return a complete URL for the resource located by url
2696 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2698 String codebase = localref.toString();
2699 if (url.indexOf("/") == 0)
2701 url = codebase.substring(0, codebase.length()
2702 - localref.getFile().length())
2707 url = localref + url;
2713 * open a URL in the browser - resolving it according to relative refs and
2714 * coping with javascript: protocol if necessary.
2719 public void showURL(String url, String target)
2723 if (url.indexOf(":") == -1)
2725 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2727 // Should really use docbase, not codebase.
2729 url = resolveUrlForLocalOrAbsolute(
2731 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2736 .println("Show url (prepended "
2738 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2746 System.err.println("Show url: " + url);
2749 if (url.indexOf("javascript:") == 0)
2751 // no target for the javascript context
2752 getAppletContext().showDocument(new java.net.URL(url));
2756 getAppletContext().showDocument(new java.net.URL(url), target);
2758 } catch (Exception ex)
2760 ex.printStackTrace();
2765 * bind structures in a viewer to any matching sequences in an alignFrame (use
2766 * sequenceIds to limit scope of search to specific sequences)
2770 * @param sequenceIds
2771 * @return TODO: consider making an exception structure for indicating when
2772 * binding fails public SequenceStructureBinding
2773 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2776 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2777 * alFrame.addStructureViewInstance(viewer,
2778 * separatorListToArray(sequenceIds)); } else { return
2779 * alFrame.addStructureViewInstance(viewer, null); } // return null; }