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;
44 import java.applet.Applet;
45 import java.awt.Button;
46 import java.awt.Color;
47 import java.awt.Component;
48 import java.awt.EventQueue;
50 import java.awt.Frame;
51 import java.awt.Graphics;
52 import java.awt.event.ActionEvent;
53 import java.awt.event.WindowAdapter;
54 import java.awt.event.WindowEvent;
55 import java.io.BufferedReader;
56 import java.io.InputStreamReader;
58 import java.util.Hashtable;
59 import java.util.StringTokenizer;
60 import java.util.Vector;
62 import netscape.javascript.JSObject;
65 * Jalview Applet. Runs in Java 1.18 runtime
68 * @version $Revision: 1.92 $
70 public class JalviewLite extends Applet implements
71 StructureSelectionManagerProvider, JalviewLiteJsApi
74 public StructureSelectionManager getStructureSelectionManager()
76 return StructureSelectionManager.getStructureSelectionManager(this);
79 // /////////////////////////////////////////
80 // The following public methods maybe called
81 // externally, eg via javascript in HTML page
85 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
87 public String getSelectedSequences()
89 return getSelectedSequencesFrom(getDefaultTargetFrame());
95 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
97 public String getSelectedSequences(String sep)
99 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
106 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
109 public String getSelectedSequencesFrom(AlignFrame alf)
111 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
118 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
119 * .AlignFrame, java.lang.String)
121 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
123 StringBuffer result = new StringBuffer("");
124 if (sep == null || sep.length() == 0)
126 sep = separator; // "+0x00AC;
128 if (alf.viewport.getSelectionGroup() != null)
130 SequenceI[] seqs = alf.viewport.getSelectionGroup()
131 .getSequencesInOrder(alf.viewport.getAlignment());
133 for (int i = 0; i < seqs.length; i++)
135 result.append(seqs[i].getName());
140 return result.toString();
146 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
147 * java.lang.String, java.lang.String)
149 public void highlight(String sequenceId, String position,
150 String alignedPosition)
152 highlightIn(getDefaultTargetFrame(), sequenceId, position,
159 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
160 * java.lang.String, java.lang.String, java.lang.String)
162 public void highlightIn(final AlignFrame alf, final String sequenceId,
163 final String position, final String alignedPosition)
165 // TODO: could try to highlight in all alignments if alf==null
166 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
167 alf.viewport.getAlignment().getSequencesArray());
168 final SequenceI sq = matcher.findIdMatch(sequenceId);
174 apos = new Integer(position).intValue();
176 } catch (NumberFormatException ex)
180 final StructureSelectionManagerProvider me = this;
181 final int pos = apos;
182 // use vamsas listener to broadcast to all listeners in scope
183 if (alignedPosition != null
184 && (alignedPosition.trim().length() == 0 || alignedPosition
185 .toLowerCase().indexOf("false") > -1))
187 java.awt.EventQueue.invokeLater(new Runnable()
192 StructureSelectionManager.getStructureSelectionManager(me)
193 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
199 java.awt.EventQueue.invokeLater(new Runnable()
204 StructureSelectionManager.getStructureSelectionManager(me)
205 .mouseOverVamsasSequence(sq, pos, null);
215 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
218 public void select(String sequenceIds, String columns)
220 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
226 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
227 * java.lang.String, java.lang.String)
229 public void select(String sequenceIds, String columns, String sep)
231 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
237 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
238 * java.lang.String, java.lang.String)
240 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
242 selectIn(alf, sequenceIds, columns, separator);
248 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
249 * java.lang.String, java.lang.String, java.lang.String)
251 public void selectIn(final AlignFrame alf, String sequenceIds,
252 String columns, String sep)
254 if (sep == null || sep.length() == 0)
262 System.err.println("Selecting region using separator string '"
267 String[] ids = separatorListToArray(sequenceIds, sep);
268 String[] cols = separatorListToArray(columns, sep);
269 final SequenceGroup sel = new SequenceGroup();
270 final ColumnSelection csel = new ColumnSelection();
271 AlignmentI al = alf.viewport.getAlignment();
272 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
273 alf.viewport.getAlignment().getSequencesArray());
274 int start = 0, end = al.getWidth(), alw = al.getWidth();
275 boolean seqsfound = true;
276 if (ids != null && ids.length > 0)
279 for (int i = 0; i < ids.length; i++)
281 if (ids[i].trim().length() == 0)
285 SequenceI sq = matcher.findIdMatch(ids[i]);
289 sel.addSequence(sq, false);
293 boolean inseqpos = false;
294 if (cols != null && cols.length > 0)
296 boolean seset = false;
297 for (int i = 0; i < cols.length; i++)
299 String cl = cols[i].trim();
300 if (cl.length() == 0)
305 if ((p = cl.indexOf("-")) > -1)
307 int from = -1, to = -1;
310 from = new Integer(cl.substring(0, p)).intValue();
312 } catch (NumberFormatException ex)
315 .println("ERROR: Couldn't parse first integer in range element column selection string '"
316 + cl + "' - format is 'from-to'");
321 to = new Integer(cl.substring(p + 1)).intValue();
323 } catch (NumberFormatException ex)
326 .println("ERROR: Couldn't parse second integer in range element column selection string '"
327 + cl + "' - format is 'from-to'");
330 if (from >= 0 && to >= 0)
347 // comment to prevent range extension
357 for (int r = from; r <= to; r++)
359 if (r >= 0 && r < alw)
366 System.err.println("Range '" + cl + "' deparsed as [" + from
372 System.err.println("ERROR: Invalid Range '" + cl
373 + "' deparsed as [" + from + "," + to + "]");
381 r = new Integer(cl).intValue();
383 } catch (NumberFormatException ex)
385 if (cl.toLowerCase().equals("sequence"))
387 // we are in the dataset sequence's coordinate frame.
393 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
398 if (r >= 0 && r <= alw)
408 // comment to prevent range extension
421 System.err.println("Point selection '" + cl
422 + "' deparsed as [" + r + "]");
427 System.err.println("ERROR: Invalid Point selection '" + cl
428 + "' deparsed as [" + r + "]");
435 // we only propagate the selection when it was the null selection, or the
436 // given sequences were found in the alignment.
437 if (inseqpos && sel.getSize() > 0)
439 // assume first sequence provides reference frame ?
440 SequenceI rs = sel.getSequenceAt(0);
441 start = rs.findIndex(start);
442 end = rs.findIndex(end);
445 Vector cs = csel.getSelected();
447 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
449 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
454 sel.setStartRes(start);
456 EventQueue.invokeLater(new Runnable()
461 alf.select(sel, csel);
471 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
472 * String, java.lang.String)
474 public String getSelectedSequencesAsAlignment(String format, String suffix)
476 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
484 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
485 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
487 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
488 String format, String suffix)
492 boolean seqlimits = suffix.equalsIgnoreCase("true");
493 if (alf.viewport.getSelectionGroup() != null)
495 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
496 // method now returns a full copy of sequence data
497 // TODO consider using getSequenceSelection instead here
498 String reply = new AppletFormatAdapter().formatSequences(format,
499 new Alignment(alf.viewport.getSelectionAsNewSequence()),
503 } catch (Exception ex)
505 ex.printStackTrace();
506 return "Error retrieving alignment in " + format + " format. ";
514 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
516 public String getAlignmentOrder()
518 return getAlignmentOrderFrom(getDefaultTargetFrame());
525 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
528 public String getAlignmentOrderFrom(AlignFrame alf)
530 return getAlignmentOrderFrom(alf, separator);
537 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
538 * , java.lang.String)
540 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
542 AlignmentI alorder = alf.getAlignViewport().getAlignment();
543 String[] order = new String[alorder.getHeight()];
544 for (int i = 0; i < order.length; i++)
546 order[i] = alorder.getSequenceAt(i).getName();
548 return arrayToSeparatorList(order);
554 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
557 public String orderBy(String order, String undoName)
559 return orderBy(order, undoName, separator);
565 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
566 * java.lang.String, java.lang.String)
568 public String orderBy(String order, String undoName, String sep)
570 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
577 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
578 * java.lang.String, java.lang.String, java.lang.String)
580 public String orderAlignmentBy(AlignFrame alf, String order,
581 String undoName, String sep)
583 String[] ids = separatorListToArray(order, sep);
584 SequenceI[] sqs = null;
585 if (ids != null && ids.length > 0)
587 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
588 alf.viewport.getAlignment().getSequencesArray());
590 sqs = new SequenceI[ids.length];
591 for (int i = 0; i < ids.length; i++)
593 if (ids[i].trim().length() == 0)
597 SequenceI sq = matcher.findIdMatch(ids[i]);
605 SequenceI[] sqq = new SequenceI[s];
606 System.arraycopy(sqs, 0, sqq, 0, s);
619 final AlignmentOrder aorder = new AlignmentOrder(sqs);
621 if (undoName != null && undoName.trim().length() == 0)
625 final String _undoName = undoName;
626 // TODO: deal with synchronization here: cannot raise any events until after
627 // this has returned.
628 return alf.sortBy(aorder, _undoName) ? "true" : "";
634 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
636 public String getAlignment(String format)
638 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
645 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
648 public String getAlignmentFrom(AlignFrame alf, String format)
650 return getAlignmentFrom(alf, format, "true");
656 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
659 public String getAlignment(String format, String suffix)
661 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
668 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
669 * java.lang.String, java.lang.String)
671 public String getAlignmentFrom(AlignFrame alf, String format,
676 boolean seqlimits = suffix.equalsIgnoreCase("true");
678 String reply = new AppletFormatAdapter().formatSequences(format,
679 alf.viewport.getAlignment(), seqlimits);
681 } catch (Exception ex)
683 ex.printStackTrace();
684 return "Error retrieving alignment in " + format + " format. ";
691 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
693 public void loadAnnotation(String annotation)
695 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
702 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
703 * , java.lang.String)
705 public void loadAnnotationFrom(AlignFrame alf, String annotation)
707 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
708 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
710 alf.alignPanel.fontChanged();
711 alf.alignPanel.setScrollValues(0, 0);
715 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
722 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
724 public void loadFeatures(String features, boolean autoenabledisplay)
726 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
733 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
734 * , java.lang.String)
736 public boolean loadFeaturesFrom(AlignFrame alf, String features,
737 boolean autoenabledisplay)
739 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
746 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
748 public String getFeatures(String format)
750 return getFeaturesFrom(getDefaultTargetFrame(), format);
757 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
760 public String getFeaturesFrom(AlignFrame alf, String format)
762 return alf.outputFeatures(false, format);
768 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
770 public String getAnnotation()
772 return getAnnotationFrom(getDefaultTargetFrame());
779 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
782 public String getAnnotationFrom(AlignFrame alf)
784 return alf.outputAnnotations(false);
790 * @see jalview.bin.JalviewLiteJsApi#newView()
792 public AlignFrame newView()
794 return newViewFrom(getDefaultTargetFrame());
800 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
802 public AlignFrame newView(String name)
804 return newViewFrom(getDefaultTargetFrame(), name);
810 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
812 public AlignFrame newViewFrom(AlignFrame alf)
814 return alf.newView(null);
820 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
823 public AlignFrame newViewFrom(AlignFrame alf, String name)
825 return alf.newView(name);
831 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
834 public AlignFrame loadAlignment(String text, String title)
838 String format = new IdentifyFile().Identify(text,
839 AppletFormatAdapter.PASTE);
842 al = new AppletFormatAdapter().readFile(text,
843 AppletFormatAdapter.PASTE, format);
844 if (al.getHeight() > 0)
846 return new AlignFrame(al, this, title, false);
848 } catch (java.io.IOException ex)
850 ex.printStackTrace();
858 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
860 public void setMouseoverListener(String listener)
862 setMouseoverListener(currentAlignFrame, listener);
865 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
871 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
872 * , java.lang.String)
874 public void setMouseoverListener(AlignFrame af, String listener)
876 if (listener != null)
878 listener = listener.trim();
879 if (listener.length() == 0)
882 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
886 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
888 javascriptListeners.addElement(mol);
889 StructureSelectionManager.getStructureSelectionManager(this)
890 .addStructureViewerListener(mol);
893 System.err.println("Added a mouseover listener for "
894 + ((af == null) ? "All frames" : "Just views for "
895 + af.getAlignViewport().getSequenceSetId()));
896 System.err.println("There are now " + javascriptListeners.size()
897 + " listeners in total.");
904 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
906 public void setSelectionListener(String listener)
908 setSelectionListener(null, listener);
915 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
916 * , java.lang.String)
918 public void setSelectionListener(AlignFrame af, String listener)
920 if (listener != null)
922 listener = listener.trim();
923 if (listener.length() == 0)
926 .println("jalview Javascript error: Ignoring empty function for selection listener.");
930 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
932 javascriptListeners.addElement(mol);
933 StructureSelectionManager.getStructureSelectionManager(this)
934 .addSelectionListener(mol);
937 System.err.println("Added a selection listener for "
938 + ((af == null) ? "All frames" : "Just views for "
939 + af.getAlignViewport().getSequenceSetId()));
940 System.err.println("There are now " + javascriptListeners.size()
941 + " listeners in total.");
948 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
951 public void setStructureListener(String listener, String modelSet)
953 if (listener != null)
955 listener = listener.trim();
956 if (listener.length() == 0)
959 .println("jalview Javascript error: Ignoring empty function for selection listener.");
963 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
964 this, listener, separatorListToArray(modelSet));
965 javascriptListeners.addElement(mol);
966 StructureSelectionManager.getStructureSelectionManager(this)
967 .addStructureViewerListener(mol);
970 System.err.println("Added a javascript structure viewer listener '"
972 System.err.println("There are now " + javascriptListeners.size()
973 + " listeners in total.");
981 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
982 * .AlignFrame, java.lang.String)
984 public void removeJavascriptListener(AlignFrame af, String listener)
986 if (listener != null)
988 listener = listener.trim();
989 if (listener.length() == 0)
994 boolean rprt = false;
995 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
997 Object lstn = javascriptListeners.elementAt(ms);
998 JsCallBack lstner = (JsCallBack) lstn;
999 if ((af == null || lstner.getAlignFrame() == af)
1000 && (listener == null || lstner.getListenerFunction().equals(
1003 javascriptListeners.removeElement(lstner);
1005 if (lstner instanceof SelectionListener)
1007 StructureSelectionManager.getStructureSelectionManager(this)
1008 .removeSelectionListener((SelectionListener) lstner);
1012 StructureSelectionManager.getStructureSelectionManager(this)
1013 .removeStructureViewerListener(lstner, null);
1018 System.err.println("Removed listener '" + listener + "'");
1028 System.err.println("There are now " + javascriptListeners.size()
1029 + " listeners in total.");
1035 System.err.println("Applet " + getName() + " stop().");
1039 public void destroy()
1041 System.err.println("Applet " + getName() + " destroy().");
1045 private void tidyUp()
1048 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1049 && currentAlignFrame.viewport.applet != null)
1051 AlignViewport av = currentAlignFrame.viewport;
1052 currentAlignFrame.closeMenuItem_actionPerformed();
1054 currentAlignFrame = null;
1056 if (javascriptListeners != null)
1058 while (javascriptListeners.size() > 0)
1060 jalview.javascript.JSFunctionExec mol = javascriptListeners
1062 javascriptListeners.removeElement(mol);
1063 if (mol instanceof SelectionListener)
1065 StructureSelectionManager.getStructureSelectionManager(this)
1066 .removeSelectionListener((SelectionListener) mol);
1070 StructureSelectionManager.getStructureSelectionManager(this)
1071 .removeStructureViewerListener(mol, null);
1076 if (jsFunctionExec != null)
1078 jsFunctionExec.stopQueue();
1079 jsFunctionExec.jvlite = null;
1081 initialAlignFrame = null;
1082 jsFunctionExec = null;
1083 javascriptListeners = null;
1084 StructureSelectionManager.release(this);
1087 private jalview.javascript.JSFunctionExec jsFunctionExec;
1092 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1093 * java.lang.String, java.lang.String)
1095 public void mouseOverStructure(final String pdbResNum,
1096 final String chain, final String pdbfile)
1098 final StructureSelectionManagerProvider me = this;
1099 java.awt.EventQueue.invokeLater(new Runnable()
1106 StructureSelectionManager.getStructureSelectionManager(me)
1107 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1111 System.err.println("mouseOver for '" + pdbResNum
1112 + "' in chain '" + chain + "' in structure '" + pdbfile
1115 } catch (NumberFormatException e)
1117 System.err.println("Ignoring invalid residue number string '"
1129 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1130 * java.lang.String, java.lang.String)
1132 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1133 final String leftHandColumn)
1135 java.awt.EventQueue.invokeLater(new Runnable()
1142 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1143 leftHandColumn).intValue());
1145 } catch (Exception ex)
1147 System.err.println("Couldn't parse integer arguments (topRow='"
1148 + topRow + "' and leftHandColumn='" + leftHandColumn
1150 ex.printStackTrace();
1160 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1161 * .AlignFrame, java.lang.String)
1164 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1167 java.awt.EventQueue.invokeLater(new Runnable()
1174 alf.scrollToRow(new Integer(topRow).intValue());
1176 } catch (Exception ex)
1178 System.err.println("Couldn't parse integer arguments (topRow='"
1180 ex.printStackTrace();
1191 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1192 * .AlignFrame, java.lang.String)
1195 public void scrollViewToColumnIn(final AlignFrame alf,
1196 final String leftHandColumn)
1198 java.awt.EventQueue.invokeLater(new Runnable()
1206 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1208 } catch (Exception ex)
1211 .println("Couldn't parse integer arguments (leftHandColumn='"
1212 + leftHandColumn + "')");
1213 ex.printStackTrace();
1220 // //////////////////////////////////////////////
1221 // //////////////////////////////////////////////
1223 public static int lastFrameX = 200;
1225 public static int lastFrameY = 200;
1227 boolean fileFound = true;
1229 String file = "No file";
1231 Button launcher = new Button("Start Jalview");
1234 * The currentAlignFrame is static, it will change if and when the user
1235 * selects a new window. Note that it will *never* point back to the embedded
1236 * AlignFrame if the applet is started as embedded on the page and then
1237 * afterwards a new view is created.
1239 public AlignFrame currentAlignFrame = null;
1242 * This is the first frame to be displayed, and does not change. API calls
1243 * will default to this instance if currentAlignFrame is null.
1245 AlignFrame initialAlignFrame = null;
1247 boolean embedded = false;
1249 private boolean checkForJmol = true;
1251 private boolean checkedForJmol = false; // ensure we don't check for jmol
1253 // every time the app is re-inited
1255 public boolean jmolAvailable = false;
1257 private boolean alignPdbStructures = false;
1260 * use an external structure viewer exclusively (no jmols or MCViews will be
1261 * opened by JalviewLite itself)
1263 public boolean useXtrnalSviewer = false;
1265 public static boolean debug = false;
1267 static String builddate = null, version = null;
1269 private static void initBuildDetails()
1271 if (builddate == null)
1273 builddate = "unknown";
1275 java.net.URL url = JalviewLite.class
1276 .getResource("/.build_properties");
1281 BufferedReader reader = new BufferedReader(new InputStreamReader(
1284 while ((line = reader.readLine()) != null)
1286 if (line.indexOf("VERSION") > -1)
1288 version = line.substring(line.indexOf("=") + 1);
1290 if (line.indexOf("BUILD_DATE") > -1)
1292 builddate = line.substring(line.indexOf("=") + 1);
1295 } catch (Exception ex)
1297 ex.printStackTrace();
1303 public static String getBuildDate()
1309 public static String getVersion()
1315 // public JSObject scriptObject = null;
1318 * init method for Jalview Applet
1322 // remove any handlers that might be hanging around from an earlier instance
1327 System.err.println("Applet context is '"
1328 + getAppletContext().getClass().toString() + "'");
1330 JSObject scriptObject = JSObject.getWindow(this);
1331 if (debug && scriptObject != null)
1333 System.err.println("Applet has Javascript callback support.");
1336 } catch (Exception ex)
1339 .println("Warning: No JalviewLite javascript callbacks available.");
1342 ex.printStackTrace();
1346 * turn on extra applet debugging
1348 String dbg = getParameter("debug");
1351 debug = dbg.toLowerCase().equals("true");
1356 System.err.println("JalviewLite Version " + getVersion());
1357 System.err.println("Build Date : " + getBuildDate());
1360 String externalsviewer = getParameter("externalstructureviewer");
1361 if (externalsviewer != null)
1363 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1367 * if true disable the check for jmol
1369 String chkforJmol = getParameter("nojmol");
1370 if (chkforJmol != null)
1372 checkForJmol = !chkforJmol.equals("true");
1375 * get the separator parameter if present
1377 String sep = getParameter("separator");
1380 if (sep.length() > 0)
1385 System.err.println("Separator set to '" + separator + "'");
1391 "Invalid separator parameter - must be non-zero length");
1397 String param = getParameter("RGB");
1403 r = Integer.parseInt(param.substring(0, 2), 16);
1404 g = Integer.parseInt(param.substring(2, 4), 16);
1405 b = Integer.parseInt(param.substring(4, 6), 16);
1406 } catch (Exception ex)
1413 param = getParameter("label");
1416 launcher.setLabel(param);
1419 setBackground(new Color(r, g, b));
1421 file = getParameter("file");
1425 // Maybe the sequences are added as parameters
1426 StringBuffer data = new StringBuffer("PASTE");
1428 while ((file = getParameter("sequence" + i)) != null)
1430 data.append(file.toString() + "\n");
1433 if (data.length() > 5)
1435 file = data.toString();
1439 final JalviewLite jvapplet = this;
1440 if (getParameter("embedded") != null
1441 && getParameter("embedded").equalsIgnoreCase("true"))
1443 // Launch as embedded applet in page
1445 LoadingThread loader = new LoadingThread(file, jvapplet);
1448 else if (file != null)
1450 if (getParameter("showbutton") == null
1451 || !getParameter("showbutton").equalsIgnoreCase("false"))
1453 // Add the JalviewLite 'Button' to the page
1455 launcher.addActionListener(new java.awt.event.ActionListener()
1457 public void actionPerformed(ActionEvent e)
1459 LoadingThread loader = new LoadingThread(file, jvapplet);
1466 // Open jalviewLite immediately.
1467 LoadingThread loader = new LoadingThread(file, jvapplet);
1473 // jalview initialisation with no alignment. loadAlignment() method can
1474 // still be called to open new alignments.
1481 private void callInitCallback()
1483 String initjscallback = getParameter("oninit");
1484 if (initjscallback == null)
1488 initjscallback = initjscallback.trim();
1489 if (initjscallback.length() > 0)
1491 JSObject scriptObject = null;
1494 scriptObject = JSObject.getWindow(this);
1495 } catch (Exception ex)
1499 if (scriptObject != null)
1503 // do onInit with the JS executor thread
1504 new JSFunctionExec(this).executeJavascriptFunction(true,
1505 initjscallback, null, "Calling oninit callback '"
1506 + initjscallback + "'.");
1507 } catch (Exception e)
1509 System.err.println("Exception when executing _oninit callback '"
1510 + initjscallback + "'.");
1511 e.printStackTrace();
1516 System.err.println("Not executing _oninit callback '"
1517 + initjscallback + "' - no scripting allowed.");
1523 * Initialises and displays a new java.awt.Frame
1526 * java.awt.Frame to be displayed
1528 * title of new frame
1530 * width if new frame
1532 * height of new frame
1534 public static void addFrame(final Frame frame, String title, int width,
1537 frame.setLocation(lastFrameX, lastFrameY);
1540 frame.setSize(width, height);
1541 frame.setTitle(title);
1542 frame.addWindowListener(new WindowAdapter()
1544 public void windowClosing(WindowEvent e)
1546 if (frame instanceof AlignFrame)
1548 AlignViewport vp = ((AlignFrame) frame).viewport;
1549 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1550 if (vp.applet.currentAlignFrame == frame)
1552 vp.applet.currentAlignFrame = null;
1560 if (frame instanceof EmbmenuFrame)
1562 ((EmbmenuFrame) frame).destroyMenus();
1564 frame.setMenuBar(null);
1568 public void windowActivated(WindowEvent e)
1570 if (frame instanceof AlignFrame)
1572 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1575 System.err.println("Activated window " + frame);
1579 super.windowActivated(e);
1582 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1585 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1588 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1589 * frame) { currentAlignFrame = null; if (debug) {
1590 * System.err.println("Deactivated window "+frame); } }
1591 * super.windowDeactivated(e); }
1594 frame.setVisible(true);
1598 * This paints the background surrounding the "Launch Jalview button" <br>
1600 * If file given in parameter not found, displays error message
1605 public void paint(Graphics g)
1609 g.setColor(new Color(200, 200, 200));
1610 g.setColor(Color.cyan);
1611 g.fillRect(0, 0, getSize().width, getSize().height);
1612 g.setColor(Color.red);
1613 g.drawString("Jalview can't open file", 5, 15);
1614 g.drawString("\"" + file + "\"", 5, 30);
1618 g.setColor(Color.black);
1619 g.setFont(new Font("Arial", Font.BOLD, 24));
1620 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
1621 g.drawString("Loading Data...", 50, getSize().height / 2);
1626 * get all components associated with the applet of the given type
1631 public Vector getAppletWindow(Class class1)
1633 Vector wnds = new Vector();
1634 Component[] cmp = getComponents();
1637 for (int i = 0; i < cmp.length; i++)
1639 if (class1.isAssignableFrom(cmp[i].getClass()))
1641 wnds.addElement(cmp);
1648 class LoadJmolThread extends Thread
1650 private boolean running = false;
1654 if (running || checkedForJmol)
1663 if (!System.getProperty("java.version").startsWith("1.1"))
1665 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1666 jmolAvailable = true;
1671 .println("Jmol not available - Using MCview for structures");
1673 } catch (java.lang.ClassNotFoundException ex)
1679 jmolAvailable = false;
1683 .println("Skipping Jmol check. Will use MCView (probably)");
1686 checkedForJmol = true;
1690 public boolean notFinished()
1692 return running || !checkedForJmol;
1696 class LoadingThread extends Thread
1699 * State variable: File source
1704 * State variable: protocol for access to file source
1709 * State variable: format of file source
1717 private void dbgMsg(String msg)
1721 System.err.println(msg);
1726 * update the protocol state variable for accessing the datasource located
1730 * @return possibly updated datasource string
1732 public String setProtocolState(String file)
1734 if (file.startsWith("PASTE"))
1736 file = file.substring(5);
1737 protocol = AppletFormatAdapter.PASTE;
1739 else if (inArchive(file))
1741 protocol = AppletFormatAdapter.CLASSLOADER;
1745 file = addProtocol(file);
1746 protocol = AppletFormatAdapter.URL;
1748 dbgMsg("Protocol identified as '" + protocol + "'");
1752 public LoadingThread(String _file, JalviewLite _applet)
1760 LoadJmolThread jmolchecker = new LoadJmolThread();
1761 jmolchecker.start();
1762 while (jmolchecker.notFinished())
1764 // wait around until the Jmol check is complete.
1768 } catch (Exception e)
1774 // applet.callInitCallback();
1777 private void startLoading()
1779 AlignFrame newAlignFrame;
1780 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1781 file = setProtocolState(_file);
1783 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1784 dbgMsg("File identified as '" + format + "'");
1785 dbgMsg("Loading started.");
1786 Alignment al = null;
1789 al = new AppletFormatAdapter().readFile(file, protocol, format);
1790 } catch (java.io.IOException ex)
1792 dbgMsg("File load exception.");
1793 ex.printStackTrace();
1798 FileParse fp = new FileParse(file, protocol);
1800 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1802 while ((ln = fp.nextLine()) != null)
1806 dbgMsg(">>>Dump finished.");
1807 } catch (Exception e)
1810 .println("Exception when trying to dump the content of the file parameter.");
1811 e.printStackTrace();
1815 if ((al != null) && (al.getHeight() > 0))
1817 dbgMsg("Successfully loaded file.");
1818 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1819 if (initialAlignFrame == null)
1821 initialAlignFrame = newAlignFrame;
1823 // update the focus.
1824 currentAlignFrame = newAlignFrame;
1826 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1828 newAlignFrame.setTitle("Sequences from "
1829 + applet.getDocumentBase());
1832 newAlignFrame.statusBar.setText("Successfully loaded file " + 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; }