2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentUtils;
24 import jalview.api.StructureSelectionManagerProvider;
25 import jalview.appletgui.AlignFrame;
26 import jalview.appletgui.AlignViewport;
27 import jalview.appletgui.EmbmenuFrame;
28 import jalview.appletgui.FeatureSettings;
29 import jalview.appletgui.SplitFrame;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AlignmentOrder;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.AnnotationFile;
39 import jalview.io.AppletFormatAdapter;
40 import jalview.io.FileParse;
41 import jalview.io.IdentifyFile;
42 import jalview.io.JPredFile;
43 import jalview.io.JnetAnnotationMaker;
44 import jalview.io.NewickFile;
45 import jalview.javascript.JSFunctionExec;
46 import jalview.javascript.JalviewLiteJsApi;
47 import jalview.javascript.JsCallBack;
48 import jalview.javascript.MouseOverStructureListener;
49 import jalview.structure.SelectionListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.util.HttpUtils;
52 import jalview.util.MessageManager;
54 import java.applet.Applet;
55 import java.awt.Button;
56 import java.awt.Color;
57 import java.awt.Component;
58 import java.awt.EventQueue;
60 import java.awt.Frame;
61 import java.awt.Graphics;
62 import java.awt.event.ActionEvent;
63 import java.awt.event.WindowAdapter;
64 import java.awt.event.WindowEvent;
65 import java.io.BufferedReader;
66 import java.io.InputStreamReader;
68 import java.util.ArrayList;
69 import java.util.Hashtable;
70 import java.util.List;
71 import java.util.StringTokenizer;
72 import java.util.Vector;
74 import netscape.javascript.JSObject;
77 * Jalview Applet. Runs in Java 1.18 runtime
80 * @version $Revision: 1.92 $
82 public class JalviewLite extends Applet implements
83 StructureSelectionManagerProvider, JalviewLiteJsApi
86 private static final String TRUE = "true";
88 private static final String FALSE = "false";
90 public StructureSelectionManager getStructureSelectionManager()
92 return StructureSelectionManager.getStructureSelectionManager(this);
95 // /////////////////////////////////////////
96 // The following public methods may be called
97 // externally, eg via javascript in HTML page
101 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
103 public String getSelectedSequences()
105 return getSelectedSequencesFrom(getDefaultTargetFrame());
111 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
113 public String getSelectedSequences(String sep)
115 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
122 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
125 public String getSelectedSequencesFrom(AlignFrame alf)
127 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
134 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
135 * .AlignFrame, java.lang.String)
137 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
139 StringBuffer result = new StringBuffer("");
140 if (sep == null || sep.length() == 0)
142 sep = separator; // "+0x00AC;
144 if (alf.viewport.getSelectionGroup() != null)
146 SequenceI[] seqs = alf.viewport.getSelectionGroup()
147 .getSequencesInOrder(alf.viewport.getAlignment());
149 for (int i = 0; i < seqs.length; i++)
151 result.append(seqs[i].getName());
156 return result.toString();
162 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
163 * java.lang.String, java.lang.String)
165 public void highlight(String sequenceId, String position,
166 String alignedPosition)
168 highlightIn(getDefaultTargetFrame(), sequenceId, position,
175 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
176 * java.lang.String, java.lang.String, java.lang.String)
178 public void highlightIn(final AlignFrame alf, final String sequenceId,
179 final String position, final String alignedPosition)
181 // TODO: could try to highlight in all alignments if alf==null
182 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
183 alf.viewport.getAlignment().getSequencesArray());
184 final SequenceI sq = matcher.findIdMatch(sequenceId);
190 apos = new Integer(position).intValue();
192 } catch (NumberFormatException ex)
196 final StructureSelectionManagerProvider me = this;
197 final int pos = apos;
198 // use vamsas listener to broadcast to all listeners in scope
199 if (alignedPosition != null
200 && (alignedPosition.trim().length() == 0 || alignedPosition
201 .toLowerCase().indexOf("false") > -1))
203 java.awt.EventQueue.invokeLater(new Runnable()
208 StructureSelectionManager.getStructureSelectionManager(me)
209 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
215 java.awt.EventQueue.invokeLater(new Runnable()
220 StructureSelectionManager.getStructureSelectionManager(me)
221 .mouseOverVamsasSequence(sq, pos, null);
231 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
234 public void select(String sequenceIds, String columns)
236 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
242 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
243 * java.lang.String, java.lang.String)
245 public void select(String sequenceIds, String columns, String sep)
247 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
253 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
254 * java.lang.String, java.lang.String)
256 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
258 selectIn(alf, sequenceIds, columns, separator);
264 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
265 * java.lang.String, java.lang.String, java.lang.String)
267 public void selectIn(final AlignFrame alf, String sequenceIds,
268 String columns, String sep)
270 if (sep == null || sep.length() == 0)
278 System.err.println("Selecting region using separator string '"
283 String[] ids = separatorListToArray(sequenceIds, sep);
284 String[] cols = separatorListToArray(columns, sep);
285 final SequenceGroup sel = new SequenceGroup();
286 final ColumnSelection csel = new ColumnSelection();
287 AlignmentI al = alf.viewport.getAlignment();
288 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
289 alf.viewport.getAlignment().getSequencesArray());
290 int start = 0, end = al.getWidth(), alw = al.getWidth();
291 boolean seqsfound = true;
292 if (ids != null && ids.length > 0)
295 for (int i = 0; i < ids.length; i++)
297 if (ids[i].trim().length() == 0)
301 SequenceI sq = matcher.findIdMatch(ids[i]);
305 sel.addSequence(sq, false);
309 boolean inseqpos = false;
310 if (cols != null && cols.length > 0)
312 boolean seset = false;
313 for (int i = 0; i < cols.length; i++)
315 String cl = cols[i].trim();
316 if (cl.length() == 0)
321 if ((p = cl.indexOf("-")) > -1)
323 int from = -1, to = -1;
326 from = new Integer(cl.substring(0, p)).intValue();
328 } catch (NumberFormatException ex)
331 .println("ERROR: Couldn't parse first integer in range element column selection string '"
332 + cl + "' - format is 'from-to'");
337 to = new Integer(cl.substring(p + 1)).intValue();
339 } catch (NumberFormatException ex)
342 .println("ERROR: Couldn't parse second integer in range element column selection string '"
343 + cl + "' - format is 'from-to'");
346 if (from >= 0 && to >= 0)
363 // comment to prevent range extension
373 for (int r = from; r <= to; r++)
375 if (r >= 0 && r < alw)
382 System.err.println("Range '" + cl + "' deparsed as [" + from
388 System.err.println("ERROR: Invalid Range '" + cl
389 + "' deparsed as [" + from + "," + to + "]");
397 r = new Integer(cl).intValue();
399 } catch (NumberFormatException ex)
401 if (cl.toLowerCase().equals("sequence"))
403 // we are in the dataset sequence's coordinate frame.
409 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
414 if (r >= 0 && r <= alw)
424 // comment to prevent range extension
437 System.err.println("Point selection '" + cl
438 + "' deparsed as [" + r + "]");
443 System.err.println("ERROR: Invalid Point selection '" + cl
444 + "' deparsed as [" + r + "]");
451 // we only propagate the selection when it was the null selection, or the
452 // given sequences were found in the alignment.
453 if (inseqpos && sel.getSize() > 0)
455 // assume first sequence provides reference frame ?
456 SequenceI rs = sel.getSequenceAt(0);
457 start = rs.findIndex(start);
458 end = rs.findIndex(end);
461 List<Integer> cs = csel.getSelected();
463 for (Integer selectedCol : cs)
465 csel.addElement(rs.findIndex(selectedCol));
469 sel.setStartRes(start);
471 EventQueue.invokeLater(new Runnable()
476 alf.select(sel, csel);
486 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
487 * String, java.lang.String)
489 public String getSelectedSequencesAsAlignment(String format, String suffix)
491 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
499 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
500 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
502 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
503 String format, String suffix)
507 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
508 if (alf.viewport.getSelectionGroup() != null)
510 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
511 // method now returns a full copy of sequence data
512 // TODO consider using getSequenceSelection instead here
513 String reply = new AppletFormatAdapter().formatSequences(format,
514 new Alignment(alf.viewport.getSelectionAsNewSequence()),
518 } catch (Exception ex)
520 ex.printStackTrace();
521 return "Error retrieving alignment in " + format + " format. ";
529 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
531 public String getAlignmentOrder()
533 return getAlignmentOrderFrom(getDefaultTargetFrame());
540 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
543 public String getAlignmentOrderFrom(AlignFrame alf)
545 return getAlignmentOrderFrom(alf, separator);
552 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
553 * , java.lang.String)
555 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
557 AlignmentI alorder = alf.getAlignViewport().getAlignment();
558 String[] order = new String[alorder.getHeight()];
559 for (int i = 0; i < order.length; i++)
561 order[i] = alorder.getSequenceAt(i).getName();
563 return arrayToSeparatorList(order);
569 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
572 public String orderBy(String order, String undoName)
574 return orderBy(order, undoName, separator);
580 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
581 * java.lang.String, java.lang.String)
583 public String orderBy(String order, String undoName, String sep)
585 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
592 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
593 * java.lang.String, java.lang.String, java.lang.String)
595 public String orderAlignmentBy(AlignFrame alf, String order,
596 String undoName, String sep)
598 String[] ids = separatorListToArray(order, sep);
599 SequenceI[] sqs = null;
600 if (ids != null && ids.length > 0)
602 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
603 alf.viewport.getAlignment().getSequencesArray());
605 sqs = new SequenceI[ids.length];
606 for (int i = 0; i < ids.length; i++)
608 if (ids[i].trim().length() == 0)
612 SequenceI sq = matcher.findIdMatch(ids[i]);
620 SequenceI[] sqq = new SequenceI[s];
621 System.arraycopy(sqs, 0, sqq, 0, s);
634 final AlignmentOrder aorder = new AlignmentOrder(sqs);
636 if (undoName != null && undoName.trim().length() == 0)
640 final String _undoName = undoName;
641 // TODO: deal with synchronization here: cannot raise any events until after
642 // this has returned.
643 return alf.sortBy(aorder, _undoName) ? TRUE : "";
649 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
651 public String getAlignment(String format)
653 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
660 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
663 public String getAlignmentFrom(AlignFrame alf, String format)
665 return getAlignmentFrom(alf, format, TRUE);
671 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
674 public String getAlignment(String format, String suffix)
676 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
683 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
684 * java.lang.String, java.lang.String)
686 public String getAlignmentFrom(AlignFrame alf, String format,
691 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
693 String reply = new AppletFormatAdapter().formatSequences(format,
694 alf.viewport.getAlignment(), seqlimits);
696 } catch (Exception ex)
698 ex.printStackTrace();
699 return "Error retrieving alignment in " + format + " format. ";
706 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
708 public void loadAnnotation(String annotation)
710 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
717 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
718 * , java.lang.String)
720 public void loadAnnotationFrom(AlignFrame alf, String annotation)
722 if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
723 annotation, AppletFormatAdapter.PASTE))
725 alf.alignPanel.fontChanged();
726 alf.alignPanel.setScrollValues(0, 0);
730 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
737 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
739 public void loadFeatures(String features, boolean autoenabledisplay)
741 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
748 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
749 * , java.lang.String)
751 public boolean loadFeaturesFrom(AlignFrame alf, String features,
752 boolean autoenabledisplay)
754 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
761 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
763 public String getFeatures(String format)
765 return getFeaturesFrom(getDefaultTargetFrame(), format);
772 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
775 public String getFeaturesFrom(AlignFrame alf, String format)
777 return alf.outputFeatures(false, format);
783 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
785 public String getAnnotation()
787 return getAnnotationFrom(getDefaultTargetFrame());
794 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
797 public String getAnnotationFrom(AlignFrame alf)
799 return alf.outputAnnotations(false);
805 * @see jalview.bin.JalviewLiteJsApi#newView()
807 public AlignFrame newView()
809 return newViewFrom(getDefaultTargetFrame());
815 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
817 public AlignFrame newView(String name)
819 return newViewFrom(getDefaultTargetFrame(), name);
825 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
827 public AlignFrame newViewFrom(AlignFrame alf)
829 return alf.newView(null);
835 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
838 public AlignFrame newViewFrom(AlignFrame alf, String name)
840 return alf.newView(name);
846 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
849 public AlignFrame loadAlignment(String text, String title)
851 AlignmentI al = null;
853 String format = new IdentifyFile().identify(text,
854 AppletFormatAdapter.PASTE);
857 al = new AppletFormatAdapter().readFile(text,
858 AppletFormatAdapter.PASTE, format);
859 if (al.getHeight() > 0)
861 return new AlignFrame(al, this, title, false);
863 } catch (java.io.IOException ex)
865 ex.printStackTrace();
873 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
875 public void setMouseoverListener(String listener)
877 setMouseoverListener(currentAlignFrame, listener);
880 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
886 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
887 * , java.lang.String)
889 public void setMouseoverListener(AlignFrame af, String listener)
891 if (listener != null)
893 listener = listener.trim();
894 if (listener.length() == 0)
897 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
901 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
903 javascriptListeners.addElement(mol);
904 StructureSelectionManager.getStructureSelectionManager(this)
905 .addStructureViewerListener(mol);
908 System.err.println("Added a mouseover listener for "
909 + ((af == null) ? "All frames" : "Just views for "
910 + af.getAlignViewport().getSequenceSetId()));
911 System.err.println("There are now " + javascriptListeners.size()
912 + " listeners in total.");
919 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
921 public void setSelectionListener(String listener)
923 setSelectionListener(null, listener);
930 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
931 * , java.lang.String)
933 public void setSelectionListener(AlignFrame af, String listener)
935 if (listener != null)
937 listener = listener.trim();
938 if (listener.length() == 0)
941 .println("jalview Javascript error: Ignoring empty function for selection listener.");
945 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
947 javascriptListeners.addElement(mol);
948 StructureSelectionManager.getStructureSelectionManager(this)
949 .addSelectionListener(mol);
952 System.err.println("Added a selection listener for "
953 + ((af == null) ? "All frames" : "Just views for "
954 + af.getAlignViewport().getSequenceSetId()));
955 System.err.println("There are now " + javascriptListeners.size()
956 + " listeners in total.");
961 * Callable from javascript to register a javascript function to pass events
962 * to a structure viewer.
965 * the name of a javascript function
967 * a token separated list of PDB file names listened for
968 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
971 public void setStructureListener(String listener, String modelSet)
973 if (listener != null)
975 listener = listener.trim();
976 if (listener.length() == 0)
979 .println("jalview Javascript error: Ignoring empty function for selection listener.");
983 MouseOverStructureListener mol = new MouseOverStructureListener(this,
984 listener, separatorListToArray(modelSet));
985 javascriptListeners.addElement(mol);
986 StructureSelectionManager.getStructureSelectionManager(this)
987 .addStructureViewerListener(mol);
990 System.err.println("Added a javascript structure viewer listener '"
992 System.err.println("There are now " + javascriptListeners.size()
993 + " listeners in total.");
1001 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
1002 * .AlignFrame, java.lang.String)
1004 public void removeJavascriptListener(AlignFrame af, String listener)
1006 if (listener != null)
1008 listener = listener.trim();
1009 if (listener.length() == 0)
1014 boolean rprt = false;
1015 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1017 Object lstn = javascriptListeners.elementAt(ms);
1018 JsCallBack lstner = (JsCallBack) lstn;
1019 if ((af == null || lstner.getAlignFrame() == af)
1020 && (listener == null || lstner.getListenerFunction().equals(
1023 javascriptListeners.removeElement(lstner);
1025 if (lstner instanceof SelectionListener)
1027 StructureSelectionManager.getStructureSelectionManager(this)
1028 .removeSelectionListener((SelectionListener) lstner);
1032 StructureSelectionManager.getStructureSelectionManager(this)
1033 .removeStructureViewerListener(lstner, null);
1038 System.err.println("Removed listener '" + listener + "'");
1048 System.err.println("There are now " + javascriptListeners.size()
1049 + " listeners in total.");
1055 System.err.println("Applet " + getName() + " stop().");
1059 public void destroy()
1061 System.err.println("Applet " + getName() + " destroy().");
1065 private void tidyUp()
1068 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1069 && currentAlignFrame.viewport.applet != null)
1071 AlignViewport av = currentAlignFrame.viewport;
1072 currentAlignFrame.closeMenuItem_actionPerformed();
1074 currentAlignFrame = null;
1076 if (javascriptListeners != null)
1078 while (javascriptListeners.size() > 0)
1080 jalview.javascript.JSFunctionExec mol = javascriptListeners
1082 javascriptListeners.removeElement(mol);
1083 if (mol instanceof SelectionListener)
1085 StructureSelectionManager.getStructureSelectionManager(this)
1086 .removeSelectionListener((SelectionListener) mol);
1090 StructureSelectionManager.getStructureSelectionManager(this)
1091 .removeStructureViewerListener(mol, null);
1096 if (jsFunctionExec != null)
1098 jsFunctionExec.stopQueue();
1099 jsFunctionExec.jvlite = null;
1101 initialAlignFrame = null;
1102 jsFunctionExec = null;
1103 javascriptListeners = null;
1104 StructureSelectionManager.release(this);
1107 private jalview.javascript.JSFunctionExec jsFunctionExec;
1112 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1113 * java.lang.String, java.lang.String)
1115 public void mouseOverStructure(final String pdbResNum,
1116 final String chain, final String pdbfile)
1118 final StructureSelectionManagerProvider me = this;
1119 java.awt.EventQueue.invokeLater(new Runnable()
1126 StructureSelectionManager.getStructureSelectionManager(me)
1127 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1131 System.err.println("mouseOver for '" + pdbResNum
1132 + "' in chain '" + chain + "' in structure '" + pdbfile
1135 } catch (NumberFormatException e)
1137 System.err.println("Ignoring invalid residue number string '"
1149 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1150 * java.lang.String, java.lang.String)
1152 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1153 final String leftHandColumn)
1155 java.awt.EventQueue.invokeLater(new Runnable()
1162 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1163 leftHandColumn).intValue());
1165 } catch (Exception ex)
1167 System.err.println("Couldn't parse integer arguments (topRow='"
1168 + topRow + "' and leftHandColumn='" + leftHandColumn
1170 ex.printStackTrace();
1180 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1181 * .AlignFrame, java.lang.String)
1184 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1187 java.awt.EventQueue.invokeLater(new Runnable()
1194 alf.scrollToRow(new Integer(topRow).intValue());
1196 } catch (Exception ex)
1198 System.err.println("Couldn't parse integer arguments (topRow='"
1200 ex.printStackTrace();
1211 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1212 * .AlignFrame, java.lang.String)
1215 public void scrollViewToColumnIn(final AlignFrame alf,
1216 final String leftHandColumn)
1218 java.awt.EventQueue.invokeLater(new Runnable()
1226 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1228 } catch (Exception ex)
1231 .println("Couldn't parse integer arguments (leftHandColumn='"
1232 + leftHandColumn + "')");
1233 ex.printStackTrace();
1240 // //////////////////////////////////////////////
1241 // //////////////////////////////////////////////
1243 public static int lastFrameX = 200;
1245 public static int lastFrameY = 200;
1247 boolean fileFound = true;
1249 String file = "No file";
1251 String file2 = null;
1253 Button launcher = new Button(
1254 MessageManager.getString("label.start_jalview"));
1257 * The currentAlignFrame is static, it will change if and when the user
1258 * selects a new window. Note that it will *never* point back to the embedded
1259 * AlignFrame if the applet is started as embedded on the page and then
1260 * afterwards a new view is created.
1262 public AlignFrame currentAlignFrame = null;
1265 * This is the first frame to be displayed, and does not change. API calls
1266 * will default to this instance if currentAlignFrame is null.
1268 AlignFrame initialAlignFrame = null;
1270 boolean embedded = false;
1272 private boolean checkForJmol = true;
1274 private boolean checkedForJmol = false; // ensure we don't check for jmol
1276 // every time the app is re-inited
1278 public boolean jmolAvailable = false;
1280 private boolean alignPdbStructures = false;
1283 * use an external structure viewer exclusively (no jmols or MCViews will be
1284 * opened by JalviewLite itself)
1286 public boolean useXtrnalSviewer = false;
1288 public static boolean debug = false;
1290 static String builddate = null, version = null, installation = null;
1292 private static void initBuildDetails()
1294 if (builddate == null)
1296 builddate = "unknown";
1298 installation = "applet";
1299 java.net.URL url = JalviewLite.class
1300 .getResource("/.build_properties");
1305 BufferedReader reader = new BufferedReader(new InputStreamReader(
1308 while ((line = reader.readLine()) != null)
1310 if (line.indexOf("VERSION") > -1)
1312 version = line.substring(line.indexOf("=") + 1);
1314 if (line.indexOf("BUILD_DATE") > -1)
1316 builddate = line.substring(line.indexOf("=") + 1);
1318 if (line.indexOf("INSTALLATION") > -1)
1320 installation = line.substring(line.indexOf("=") + 1);
1323 } catch (Exception ex)
1325 ex.printStackTrace();
1331 public static String getBuildDate()
1337 public static String getInstallation()
1340 return installation;
1343 public static String getVersion()
1349 // public JSObject scriptObject = null;
1352 * init method for Jalview Applet
1357 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1362 System.err.println("Applet context is '"
1363 + getAppletContext().getClass().toString() + "'");
1365 JSObject scriptObject = JSObject.getWindow(this);
1366 if (debug && scriptObject != null)
1368 System.err.println("Applet has Javascript callback support.");
1371 } catch (Exception ex)
1374 .println("Warning: No JalviewLite javascript callbacks available.");
1377 ex.printStackTrace();
1383 System.err.println("JalviewLite Version " + getVersion());
1384 System.err.println("Build Date : " + getBuildDate());
1385 System.err.println("Installation : " + getInstallation());
1387 String externalsviewer = getParameter("externalstructureviewer");
1388 if (externalsviewer != null)
1390 useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
1393 * if true disable the check for jmol
1395 String chkforJmol = getParameter("nojmol");
1396 if (chkforJmol != null)
1398 checkForJmol = !chkforJmol.equals(TRUE);
1401 * get the separator parameter if present
1403 String sep = getParameter("separator");
1406 if (sep.length() > 0)
1411 System.err.println("Separator set to '" + separator + "'");
1418 .getString("error.invalid_separator_parameter"));
1424 String param = getParameter("RGB");
1430 r = Integer.parseInt(param.substring(0, 2), 16);
1431 g = Integer.parseInt(param.substring(2, 4), 16);
1432 b = Integer.parseInt(param.substring(4, 6), 16);
1433 } catch (Exception ex)
1440 param = getParameter("label");
1443 launcher.setLabel(param);
1446 setBackground(new Color(r, g, b));
1448 file = getParameter("file");
1452 // Maybe the sequences are added as parameters
1453 StringBuffer data = new StringBuffer("PASTE");
1455 while ((file = getParameter("sequence" + i)) != null)
1457 data.append(file.toString() + "\n");
1460 if (data.length() > 5)
1462 file = data.toString();
1465 if (getDefaultParameter("enableSplitFrame", true))
1467 file2 = getParameter("file2");
1470 embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
1473 LoadingThread loader = new LoadingThread(file, file2, this);
1476 else if (file != null)
1479 * Start the applet immediately or show a button to start it
1481 if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
1483 LoadingThread loader = new LoadingThread(file, file2, this);
1489 launcher.addActionListener(new java.awt.event.ActionListener()
1491 public void actionPerformed(ActionEvent e)
1493 LoadingThread loader = new LoadingThread(file, file2,
1502 // jalview initialisation with no alignment. loadAlignment() method can
1503 // still be called to open new alignments.
1510 private void initLiveConnect()
1512 // try really hard to get the liveConnect thing working
1513 boolean notFailed = false;
1515 while (!notFailed && tries < 10)
1519 System.err.println("LiveConnect request thread going to sleep.");
1523 Thread.sleep(700 * (1 + tries));
1524 } catch (InterruptedException q)
1530 System.err.println("LiveConnect request thread woken up.");
1534 JSObject scriptObject = JSObject.getWindow(this);
1535 if (scriptObject.eval("navigator") != null)
1539 } catch (Exception jsex)
1541 System.err.println("Attempt " + tries
1542 + " to access LiveConnect javascript failed.");
1547 private void callInitCallback()
1549 String initjscallback = getParameter("oninit");
1550 if (initjscallback == null)
1554 initjscallback = initjscallback.trim();
1555 if (initjscallback.length() > 0)
1557 JSObject scriptObject = null;
1560 scriptObject = JSObject.getWindow(this);
1561 } catch (Exception ex)
1565 // try really hard to let the browser plugin know we want liveconnect
1568 if (scriptObject != null)
1572 // do onInit with the JS executor thread
1573 new JSFunctionExec(this).executeJavascriptFunction(true,
1574 initjscallback, null, "Calling oninit callback '"
1575 + initjscallback + "'.");
1576 } catch (Exception e)
1578 System.err.println("Exception when executing _oninit callback '"
1579 + initjscallback + "'.");
1580 e.printStackTrace();
1585 System.err.println("Not executing _oninit callback '"
1586 + initjscallback + "' - no scripting allowed.");
1592 * Initialises and displays a new java.awt.Frame
1595 * java.awt.Frame to be displayed
1597 * title of new frame
1599 * width if new frame
1601 * height of new frame
1603 public static void addFrame(final Frame frame, String title, int width,
1606 frame.setLocation(lastFrameX, lastFrameY);
1609 frame.setSize(width, height);
1610 frame.setTitle(title);
1611 frame.addWindowListener(new WindowAdapter()
1613 public void windowClosing(WindowEvent e)
1615 if (frame instanceof AlignFrame)
1617 AlignViewport vp = ((AlignFrame) frame).viewport;
1618 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1619 if (vp.applet.currentAlignFrame == frame)
1621 vp.applet.currentAlignFrame = null;
1629 if (frame instanceof EmbmenuFrame)
1631 ((EmbmenuFrame) frame).destroyMenus();
1633 frame.setMenuBar(null);
1637 public void windowActivated(WindowEvent e)
1639 if (frame instanceof AlignFrame)
1641 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1644 System.err.println("Activated window " + frame);
1648 super.windowActivated(e);
1651 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1654 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1657 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1658 * frame) { currentAlignFrame = null; if (debug) {
1659 * System.err.println("Deactivated window "+frame); } }
1660 * super.windowDeactivated(e); }
1663 frame.setVisible(true);
1667 * This paints the background surrounding the "Launch Jalview button" <br>
1669 * If file given in parameter not found, displays error message
1674 public void paint(Graphics g)
1678 g.setColor(new Color(200, 200, 200));
1679 g.setColor(Color.cyan);
1680 g.fillRect(0, 0, getSize().width, getSize().height);
1681 g.setColor(Color.red);
1683 MessageManager.getString("label.jalview_cannot_open_file"),
1685 g.drawString("\"" + file + "\"", 5, 30);
1689 g.setColor(Color.black);
1690 g.setFont(new Font("Arial", Font.BOLD, 24));
1691 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1692 getSize().height / 2 - 30);
1693 g.drawString(MessageManager.getString("label.loading_data") + "...",
1694 50, getSize().height / 2);
1699 * get all components associated with the applet of the given type
1704 public Vector getAppletWindow(Class class1)
1706 Vector wnds = new Vector();
1707 Component[] cmp = getComponents();
1710 for (int i = 0; i < cmp.length; i++)
1712 if (class1.isAssignableFrom(cmp[i].getClass()))
1714 wnds.addElement(cmp);
1721 class LoadJmolThread extends Thread
1723 private boolean running = false;
1727 if (running || checkedForJmol)
1736 if (!System.getProperty("java.version").startsWith("1.1"))
1738 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1739 jmolAvailable = true;
1744 .println("Jmol not available - Using MCview for structures");
1746 } catch (java.lang.ClassNotFoundException ex)
1752 jmolAvailable = false;
1756 .println("Skipping Jmol check. Will use MCView (probably)");
1759 checkedForJmol = true;
1763 public boolean notFinished()
1765 return running || !checkedForJmol;
1769 class LoadingThread extends Thread
1772 * State variable: protocol for access to file source
1776 String _file; // alignment file or URL spec
1778 String _file2; // second alignment file or URL spec
1782 private void dbgMsg(String msg)
1784 if (JalviewLite.debug)
1786 System.err.println(msg);
1791 * update the protocol state variable for accessing the datasource located
1795 * @return possibly updated datasource string
1797 public String resolveFileProtocol(String path)
1802 if (path.startsWith("PASTE"))
1804 protocol = AppletFormatAdapter.PASTE;
1805 return path.substring(5);
1811 if (path.indexOf("://") != -1)
1813 protocol = AppletFormatAdapter.URL;
1818 * try relative to document root
1820 URL documentBase = getDocumentBase();
1821 String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
1822 if (HttpUtils.isValidUrl(withDocBase))
1826 System.err.println("Prepended document base '" + documentBase
1827 + "' to make: '" + withDocBase + "'");
1829 protocol = AppletFormatAdapter.URL;
1834 * try relative to codebase (if different to document base)
1836 URL codeBase = getCodeBase();
1837 String withCodeBase = applet.resolveUrlForLocalOrAbsolute(path,
1839 if (!withCodeBase.equals(withDocBase)
1840 && HttpUtils.isValidUrl(withCodeBase))
1842 protocol = AppletFormatAdapter.URL;
1845 System.err.println("Prepended codebase '" + codeBase
1846 + "' to make: '" + withCodeBase + "'");
1848 return withCodeBase;
1852 * try locating by classloader; try this last so files in the directory
1853 * are resolved using document base
1855 if (inArchive(path))
1857 protocol = AppletFormatAdapter.CLASSLOADER;
1862 public LoadingThread(String file, String file2, JalviewLite _applet)
1865 this._file2 = file2;
1871 LoadJmolThread jmolchecker = new LoadJmolThread();
1872 jmolchecker.start();
1873 while (jmolchecker.notFinished())
1875 // wait around until the Jmol check is complete.
1879 } catch (Exception e)
1884 // applet.callInitCallback();
1888 * Load the alignment and any related files as specified by applet
1891 private void startLoading()
1893 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1895 dbgMsg("Loading started.");
1897 AlignFrame newAlignFrame = readAlignment(_file);
1898 AlignFrame newAlignFrame2 = readAlignment(_file2);
1899 if (newAlignFrame != null)
1901 addToDisplay(newAlignFrame, newAlignFrame2);
1902 loadTree(newAlignFrame);
1904 loadScoreFile(newAlignFrame);
1906 loadFeatures(newAlignFrame);
1908 loadAnnotations(newAlignFrame);
1910 loadJnetFile(newAlignFrame);
1912 loadPdbFiles(newAlignFrame);
1917 applet.remove(launcher);
1924 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1929 public void addToDisplay(AlignFrame af, AlignFrame af2)
1933 AlignmentI al1 = af.viewport.getAlignment();
1934 AlignmentI al2 = af2.viewport.getAlignment();
1935 AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
1936 AlignmentI prot = al1.isNucleotide() ? al2 : al1;
1937 if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
1940 SplitFrame sf = new SplitFrame(af, af2);
1941 sf.addToDisplay(embedded, JalviewLite.this);
1946 String msg = "Could not map any sequence in " + af2.getTitle()
1948 + (al1.isNucleotide() ? "protein product" : "cDNA")
1949 + " for " + af.getTitle();
1950 System.err.println(msg);
1954 af.addToDisplay(embedded);
1958 * Read the alignment file (from URL, text 'paste', or archive by
1963 protected AlignFrame readAlignment(String fileParam)
1965 if (fileParam == null)
1969 String resolvedFile = resolveFileProtocol(fileParam);
1970 String format = new IdentifyFile().identify(resolvedFile, protocol);
1971 dbgMsg("File identified as '" + format + "'");
1972 AlignmentI al = null;
1975 al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
1977 if ((al != null) && (al.getHeight() > 0))
1979 dbgMsg("Successfully loaded file.");
1980 al.setDataset(null);
1981 AlignFrame newAlignFrame = new AlignFrame(al, applet,
1982 resolvedFile, embedded, false);
1983 newAlignFrame.setTitle(resolvedFile);
1984 if (initialAlignFrame == null)
1986 initialAlignFrame = newAlignFrame;
1988 // update the focus.
1989 currentAlignFrame = newAlignFrame;
1991 if (protocol == AppletFormatAdapter.PASTE)
1993 newAlignFrame.setTitle(MessageManager.formatMessage(
1994 "label.sequences_from", new Object[] { applet
1995 .getDocumentBase().toString() }));
1998 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
1999 "label.successfully_loaded_file",
2000 new Object[] { resolvedFile }));
2002 return newAlignFrame;
2004 } catch (java.io.IOException ex)
2006 dbgMsg("File load exception.");
2007 ex.printStackTrace();
2012 FileParse fp = new FileParse(resolvedFile, protocol);
2014 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
2016 while ((ln = fp.nextLine()) != null)
2020 dbgMsg(">>>Dump finished.");
2021 } catch (Exception e)
2024 .println("Exception when trying to dump the content of the file parameter.");
2025 e.printStackTrace();
2033 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
2039 protected boolean loadPdbFiles(AlignFrame alignFrame)
2041 boolean result = false;
2043 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
2044 * related to JAL-434
2047 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
2050 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
2053 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
2055 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
2058 int pdbFileCount = 0;
2059 // Accumulate pdbs here if they are heading for the same view (if
2060 // alignPdbStructures is true)
2061 Vector pdbs = new Vector();
2062 // create a lazy matcher if we're asked to
2063 jalview.analysis.SequenceIdMatcher matcher = (applet
2064 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2065 alignFrame.getAlignViewport().getAlignment()
2066 .getSequencesArray()) : null;
2071 if (pdbFileCount > 0)
2073 param = applet.getParameter("PDBFILE" + pdbFileCount);
2077 param = applet.getParameter("PDBFILE");
2082 PDBEntry pdb = new PDBEntry();
2085 SequenceI[] seqs = null;
2086 String[] chains = null;
2088 StringTokenizer st = new StringTokenizer(param, " ");
2090 if (st.countTokens() < 2)
2092 String sequence = applet.getParameter("PDBSEQ");
2093 if (sequence != null)
2095 seqs = new SequenceI[] { matcher == null ? (Sequence) alignFrame
2096 .getAlignViewport().getAlignment().findName(sequence)
2097 : matcher.findIdMatch(sequence) };
2103 param = st.nextToken();
2104 List<SequenceI> tmp = new ArrayList<SequenceI>();
2105 List<String> tmp2 = new ArrayList<String>();
2107 while (st.hasMoreTokens())
2109 seqstring = st.nextToken();
2110 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2111 if (st2.countTokens() > 1)
2113 // This is the chain
2114 tmp2.add(st2.nextToken());
2115 seqstring = st2.nextToken();
2117 tmp.add(matcher == null ? (Sequence) alignFrame
2118 .getAlignViewport().getAlignment()
2119 .findName(seqstring) : matcher.findIdMatch(seqstring));
2122 seqs = tmp.toArray(new SequenceI[tmp.size()]);
2123 if (tmp2.size() == tmp.size())
2125 chains = tmp2.toArray(new String[tmp2.size()]);
2128 param = resolveFileProtocol(param);
2129 // TODO check JAL-357 for files in a jar (CLASSLOADER)
2134 for (int i = 0; i < seqs.length; i++)
2136 if (seqs[i] != null)
2138 ((Sequence) seqs[i]).addPDBId(pdb);
2139 StructureSelectionManager.getStructureSelectionManager(
2140 applet).registerPDBEntry(pdb);
2144 if (JalviewLite.debug)
2146 // this may not really be a problem but we give a warning
2149 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2155 if (!alignPdbStructures)
2157 alignFrame.newStructureView(applet, pdb, seqs, chains,
2162 pdbs.addElement(new Object[] { pdb, seqs, chains,
2163 new String(protocol) });
2169 } while (param != null || pdbFileCount < 10);
2170 if (pdbs.size() > 0)
2172 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2173 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2174 String[][] chains = new String[pdbs.size()][];
2175 String[] protocols = new String[pdbs.size()];
2176 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2178 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2179 pdb[pdbsi] = (PDBEntry) o[0];
2180 seqs[pdbsi] = (SequenceI[]) o[1];
2181 chains[pdbsi] = (String[]) o[2];
2182 protocols[pdbsi] = (String) o[3];
2184 alignFrame.alignedStructureView(applet, pdb, seqs, chains,
2192 * Load in a Jnetfile if specified by parameter. Returns true if loaded,
2198 protected boolean loadJnetFile(AlignFrame alignFrame)
2200 boolean result = false;
2201 String param = applet.getParameter("jnetfile");
2206 param = resolveFileProtocol(param);
2207 JPredFile predictions = new JPredFile(param, protocol);
2208 JnetAnnotationMaker.add_annotation(predictions,
2209 alignFrame.viewport.getAlignment(), 0, false);
2210 // false == do not add sequence profile from concise output
2211 SequenceI repseq = alignFrame.viewport.getAlignment()
2213 alignFrame.viewport.getAlignment().setSeqrep(repseq);
2214 ColumnSelection cs = new ColumnSelection();
2215 cs.hideInsertionsFor(repseq);
2216 alignFrame.viewport.setColumnSelection(cs);
2217 alignFrame.alignPanel.fontChanged();
2218 alignFrame.alignPanel.setScrollValues(0, 0);
2220 } catch (Exception ex)
2222 ex.printStackTrace();
2229 * Load annotations if specified by parameter. Returns true if loaded, else
2235 protected boolean loadAnnotations(AlignFrame alignFrame)
2237 boolean result = false;
2238 String param = applet.getParameter("annotations");
2241 param = resolveFileProtocol(param);
2243 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
2246 alignFrame.alignPanel.fontChanged();
2247 alignFrame.alignPanel.setScrollValues(0, 0);
2253 .println("Annotations were not added from annotation file '"
2261 * Load features file and view settings as specified by parameters. Returns
2262 * true if features were loaded, else false.
2267 protected boolean loadFeatures(AlignFrame alignFrame)
2269 boolean result = false;
2270 // ///////////////////////////
2271 // modify display of features
2272 // we do this before any features have been loaded, ensuring any hidden
2273 // groups are hidden when features first displayed
2275 // hide specific groups
2277 String param = applet.getParameter("hidefeaturegroups");
2280 alignFrame.setFeatureGroupState(separatorListToArray(param), false);
2281 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
2283 // show specific groups
2284 param = applet.getParameter("showfeaturegroups");
2287 alignFrame.setFeatureGroupState(separatorListToArray(param), true);
2288 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
2290 // and now load features
2291 param = applet.getParameter("features");
2294 param = resolveFileProtocol(param);
2296 result = alignFrame.parseFeaturesFile(param, protocol);
2299 param = applet.getParameter("showFeatureSettings");
2300 if (param != null && param.equalsIgnoreCase(TRUE))
2302 alignFrame.viewport.setShowSequenceFeatures(true);
2303 new FeatureSettings(alignFrame.alignPanel);
2309 * Load a score file if specified by parameter. Returns true if file was
2310 * loaded, else false.
2314 protected boolean loadScoreFile(AlignFrame alignFrame)
2316 boolean result = false;
2317 String sScoreFile = applet.getParameter("scoreFile");
2318 if (sScoreFile != null && !"".equals(sScoreFile))
2325 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
2327 result = alignFrame.loadScoreFile(sScoreFile);
2331 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
2332 + sScoreFile + "')");
2334 } catch (Exception e)
2336 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
2337 sScoreFile, e.getMessage());
2344 * Load a tree for the alignment if specified by parameter. Returns true if
2345 * a tree was loaded, else false.
2350 protected boolean loadTree(AlignFrame alignFrame)
2352 boolean result = false;
2353 String treeFile = applet.getParameter("tree");
2354 if (treeFile == null)
2356 treeFile = applet.getParameter("treeFile");
2359 if (treeFile != null)
2363 treeFile = resolveFileProtocol(treeFile);
2364 NewickFile fin = new NewickFile(treeFile, protocol);
2367 if (fin.getTree() != null)
2369 alignFrame.loadTree(fin, treeFile);
2371 dbgMsg("Successfully imported tree.");
2375 dbgMsg("Tree parameter did not resolve to a valid tree.");
2377 } catch (Exception ex)
2379 ex.printStackTrace();
2386 * Discovers whether the given file is in the Applet Archive
2392 boolean inArchive(String f)
2394 // This might throw a security exception in certain browsers
2395 // Netscape Communicator for instance.
2398 boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
2401 System.err.println("Resource '" + f + "' was "
2402 + (rtn ? "" : "not ") + "located by classloader.");
2405 } catch (Exception ex)
2407 System.out.println("Exception checking resources: " + f + " " + ex);
2414 * @return the default alignFrame acted on by the public applet methods. May
2415 * return null with an error message on System.err indicating the
2418 public AlignFrame getDefaultTargetFrame()
2420 if (currentAlignFrame != null)
2422 return currentAlignFrame;
2424 if (initialAlignFrame != null)
2426 return initialAlignFrame;
2429 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2434 * separator used for separatorList
2436 protected String separator = "" + ((char) 0x00AC); // the default used to be
2437 // '|' but many sequence
2438 // IDS include pipes.
2441 * set to enable the URL based javascript execution mechanism
2443 public boolean jsfallbackEnabled = false;
2446 * parse the string into a list
2449 * @return elements separated by separator
2451 public String[] separatorListToArray(String list)
2453 return separatorListToArray(list, separator);
2457 * parse the string into a list
2461 * @return elements separated by separator
2463 public static String[] separatorListToArray(String list, String separator)
2465 // TODO use StringUtils version (slightly different...)
2466 int seplen = separator.length();
2467 if (list == null || list.equals("") || list.equals(separator))
2471 java.util.Vector jv = new Vector();
2473 while ((pos = list.indexOf(separator, cp)) > cp)
2475 jv.addElement(list.substring(cp, pos));
2478 if (cp < list.length())
2480 String c = list.substring(cp);
2481 if (!c.equals(separator))
2488 String[] v = new String[jv.size()];
2489 for (int i = 0; i < v.length; i++)
2491 v[i] = (String) jv.elementAt(i);
2493 jv.removeAllElements();
2496 System.err.println("Array from '" + separator
2497 + "' separated List:\n" + v.length);
2498 for (int i = 0; i < v.length; i++)
2500 System.err.println("item " + i + " '" + v[i] + "'");
2507 System.err.println("Empty Array from '" + separator
2508 + "' separated List");
2514 * concatenate the list with separator
2517 * @return concatenated string
2519 public String arrayToSeparatorList(String[] list)
2521 return arrayToSeparatorList(list, separator);
2525 * concatenate the list with separator
2529 * @return concatenated string
2531 public static String arrayToSeparatorList(String[] list, String separator)
2533 // TODO use StringUtils version
2534 StringBuffer v = new StringBuffer();
2535 if (list != null && list.length > 0)
2537 for (int i = 0, iSize = list.length; i < iSize; i++)
2539 if (list[i] != null)
2543 v.append(separator);
2550 System.err.println("Returning '" + separator
2551 + "' separated List:\n");
2552 System.err.println(v);
2554 return v.toString();
2558 System.err.println("Returning empty '" + separator
2559 + "' separated List\n");
2561 return "" + separator;
2567 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2569 public String getFeatureGroups()
2571 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2572 .getFeatureGroups());
2580 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2583 public String getFeatureGroupsOn(AlignFrame alf)
2585 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2592 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2594 public String getFeatureGroupsOfState(boolean visible)
2596 return arrayToSeparatorList(getDefaultTargetFrame()
2597 .getFeatureGroupsOfState(visible));
2604 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2605 * .AlignFrame, boolean)
2607 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2609 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2615 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2616 * AlignFrame, java.lang.String, boolean)
2618 public void setFeatureGroupStateOn(final AlignFrame alf,
2619 final String groups, boolean state)
2621 final boolean st = state;// !(state==null || state.equals("") ||
2622 // state.toLowerCase().equals("false"));
2623 java.awt.EventQueue.invokeLater(new Runnable()
2628 alf.setFeatureGroupState(separatorListToArray(groups), st);
2636 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2639 public void setFeatureGroupState(String groups, boolean state)
2641 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2647 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2649 public String getSeparator()
2657 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2659 public void setSeparator(String separator)
2661 if (separator == null || separator.length() < 1)
2664 separator = "" + ((char) 0x00AC);
2666 this.separator = separator;
2669 System.err.println("Default Separator now: '" + separator + "'");
2674 * get boolean value of applet parameter 'name' and return default if
2675 * parameter is not set
2680 * the value to return otherwise
2681 * @return true or false
2683 public boolean getDefaultParameter(String name, boolean def)
2686 if ((stn = getParameter(name)) == null)
2690 if (TRUE.equalsIgnoreCase(stn))
2700 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2701 * java.lang.String, java.lang.String, java.lang.String)
2703 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2704 String pdbEntryString, String pdbFile)
2706 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2709 protected void setAlignPdbStructures(boolean alignPdbStructures)
2711 this.alignPdbStructures = alignPdbStructures;
2714 public boolean isAlignPdbStructures()
2716 return alignPdbStructures;
2721 // callInitCallback();
2724 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2726 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2728 public void setJsMessageSet(String messageclass, String viewId,
2729 String[] colcommands)
2731 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2734 msgset = new Hashtable<String, String[]>();
2735 jsmessages.put(messageclass, msgset);
2737 msgset.put(viewId, colcommands);
2738 long[] l = new long[colcommands.length];
2739 for (int i = 0; i < colcommands.length; i++)
2741 l[i] = colcommands[i].hashCode();
2743 jshashes.put(messageclass + "|" + viewId, l);
2749 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2752 public String getJsMessage(String messageclass, String viewId)
2754 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2757 String[] msgs = msgset.get(viewId);
2760 for (int i = 0; i < msgs.length; i++)
2762 if (msgs[i] != null)
2774 public boolean isJsMessageSetChanged(String string, String string2,
2775 String[] colcommands)
2777 long[] l = jshashes.get(string + "|" + string2);
2778 if (l == null && colcommands != null)
2782 for (int i = 0; i < colcommands.length; i++)
2784 if (l[i] != colcommands[i].hashCode())
2792 private Vector jsExecQueue = new Vector();
2794 public Vector getJsExecQueue()
2799 public void setExecutor(JSFunctionExec jsFunctionExec2)
2801 jsFunctionExec = jsFunctionExec2;
2805 * return the given colour value parameter or the given default if parameter
2812 public Color getDefaultColourParameter(String colparam, Color defcolour)
2814 String colprop = getParameter(colparam);
2815 if (colprop == null || colprop.trim().length() == 0)
2819 Color col = jalview.schemes.ColourSchemeProperty
2820 .getAWTColorFromName(colprop);
2825 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2826 } catch (Exception ex)
2828 System.err.println("Couldn't parse '" + colprop
2829 + "' as a colour for " + colparam);
2833 return (col == null) ? defcolour : col;
2837 public void openJalviewHelpUrl()
2839 String helpUrl = getParameter("jalviewhelpurl");
2840 if (helpUrl == null || helpUrl.trim().length() < 5)
2842 helpUrl = "http://www.jalview.org/help.html";
2844 showURL(helpUrl, "HELP");
2848 * form a complete URL given a path to a resource and a reference location on
2852 * - an absolute path on the same server as localref or a document
2853 * located relative to localref
2855 * - a URL on the same server as url
2856 * @return a complete URL for the resource located by url
2858 private String resolveUrlForLocalOrAbsolute(String targetPath,
2861 String resolvedPath = "";
2862 if (targetPath.startsWith("/"))
2864 String codebase = localref.toString();
2865 String localfile = localref.getFile();
2866 resolvedPath = codebase.substring(0,
2867 codebase.length() - localfile.length())
2869 return resolvedPath;
2873 * get URL path and strip off any trailing file e.g.
2874 * www.jalview.org/examples/index.html#applets?a=b is trimmed to
2875 * www.jalview.org/examples/
2877 String urlPath = localref.toString();
2878 String directoryPath = urlPath;
2879 int lastSeparator = directoryPath.lastIndexOf("/");
2880 if (lastSeparator > 0)
2882 directoryPath = directoryPath.substring(0, lastSeparator + 1);
2885 if (targetPath.startsWith("/"))
2888 * construct absolute URL to a file on the server - this is not allowed?
2890 // String localfile = localref.getFile();
2891 // resolvedPath = urlPath.substring(0,
2892 // urlPath.length() - localfile.length())
2894 resolvedPath = directoryPath + targetPath.substring(1);
2898 resolvedPath = directoryPath + targetPath;
2902 System.err.println("resolveUrlForLocalOrAbsolute returning "
2905 return resolvedPath;
2909 * open a URL in the browser - resolving it according to relative refs and
2910 * coping with javascript: protocol if necessary.
2915 public void showURL(String url, String target)
2919 if (url.indexOf(":") == -1)
2921 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2923 // Should really use docbase, not codebase.
2925 url = resolveUrlForLocalOrAbsolute(
2927 prepend = getDefaultParameter("resolvetocodebase", false) ? getCodeBase()
2928 : getDocumentBase());
2932 .println("Show url (prepended "
2934 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2942 System.err.println("Show url: " + url);
2945 if (url.indexOf("javascript:") == 0)
2947 // no target for the javascript context
2948 getAppletContext().showDocument(new java.net.URL(url));
2952 getAppletContext().showDocument(new java.net.URL(url), target);
2954 } catch (Exception ex)
2956 ex.printStackTrace();
2961 * bind structures in a viewer to any matching sequences in an alignFrame (use
2962 * sequenceIds to limit scope of search to specific sequences)
2966 * @param sequenceIds
2967 * @return TODO: consider making an exception structure for indicating when
2968 * binding fails public SequenceStructureBinding
2969 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2972 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2973 * alFrame.addStructureViewInstance(viewer,
2974 * separatorListToArray(sequenceIds)); } else { return
2975 * alFrame.addStructureViewInstance(viewer, null); } // return null; }