2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.bin;
\r
20 import jalview.api.StructureSelectionManagerProvider;
\r
21 import jalview.appletgui.AlignFrame;
\r
22 import jalview.appletgui.AlignViewport;
\r
23 import jalview.appletgui.EmbmenuFrame;
\r
24 import jalview.appletgui.FeatureSettings;
\r
25 import jalview.datamodel.Alignment;
\r
26 import jalview.datamodel.AlignmentI;
\r
27 import jalview.datamodel.AlignmentOrder;
\r
28 import jalview.datamodel.ColumnSelection;
\r
29 import jalview.datamodel.PDBEntry;
\r
30 import jalview.datamodel.Sequence;
\r
31 import jalview.datamodel.SequenceGroup;
\r
32 import jalview.datamodel.SequenceI;
\r
33 import jalview.io.AnnotationFile;
\r
34 import jalview.io.AppletFormatAdapter;
\r
35 import jalview.io.FileParse;
\r
36 import jalview.io.IdentifyFile;
\r
37 import jalview.io.JnetAnnotationMaker;
\r
38 import jalview.javascript.JSFunctionExec;
\r
39 import jalview.javascript.JalviewLiteJsApi;
\r
40 import jalview.javascript.JsCallBack;
\r
41 import jalview.structure.SelectionListener;
\r
42 import jalview.structure.StructureSelectionManager;
\r
44 import java.applet.Applet;
\r
45 import java.awt.Button;
\r
46 import java.awt.Color;
\r
47 import java.awt.Component;
\r
48 import java.awt.EventQueue;
\r
49 import java.awt.Font;
\r
50 import java.awt.Frame;
\r
51 import java.awt.Graphics;
\r
52 import java.awt.event.ActionEvent;
\r
53 import java.awt.event.WindowAdapter;
\r
54 import java.awt.event.WindowEvent;
\r
55 import java.io.BufferedReader;
\r
56 import java.io.InputStreamReader;
\r
57 import java.net.URL;
\r
58 import java.util.Hashtable;
\r
59 import java.util.StringTokenizer;
\r
60 import java.util.Vector;
\r
62 import netscape.javascript.JSObject;
\r
65 * Jalview Applet. Runs in Java 1.18 runtime
\r
68 * @version $Revision: 1.92 $
\r
70 public class JalviewLite extends Applet implements
\r
71 StructureSelectionManagerProvider, JalviewLiteJsApi
\r
74 public StructureSelectionManager getStructureSelectionManager()
\r
76 return StructureSelectionManager.getStructureSelectionManager(this);
\r
79 // /////////////////////////////////////////
\r
80 // The following public methods maybe called
\r
81 // externally, eg via javascript in HTML page
\r
85 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
\r
87 public String getSelectedSequences()
\r
89 return getSelectedSequencesFrom(getDefaultTargetFrame());
\r
95 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
\r
97 public String getSelectedSequences(String sep)
\r
99 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
\r
106 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
\r
109 public String getSelectedSequencesFrom(AlignFrame alf)
\r
111 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
\r
118 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
\r
119 * .AlignFrame, java.lang.String)
\r
121 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
\r
123 StringBuffer result = new StringBuffer("");
\r
124 if (sep == null || sep.length() == 0)
\r
126 sep = separator; // "+0x00AC;
\r
128 if (alf.viewport.getSelectionGroup() != null)
\r
130 SequenceI[] seqs = alf.viewport.getSelectionGroup()
\r
131 .getSequencesInOrder(alf.viewport.getAlignment());
\r
133 for (int i = 0; i < seqs.length; i++)
\r
135 result.append(seqs[i].getName());
\r
136 result.append(sep);
\r
140 return result.toString();
\r
146 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
\r
147 * java.lang.String, java.lang.String)
\r
149 public void highlight(String sequenceId, String position,
\r
150 String alignedPosition)
\r
152 highlightIn(getDefaultTargetFrame(), sequenceId, position,
\r
159 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
\r
160 * java.lang.String, java.lang.String, java.lang.String)
\r
162 public void highlightIn(final AlignFrame alf, final String sequenceId,
\r
163 final String position, final String alignedPosition)
\r
165 // TODO: could try to highlight in all alignments if alf==null
\r
166 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
167 alf.viewport.getAlignment().getSequencesArray());
\r
168 final SequenceI sq = matcher.findIdMatch(sequenceId);
\r
174 apos = new Integer(position).intValue();
\r
176 } catch (NumberFormatException ex)
\r
180 final StructureSelectionManagerProvider me = this;
\r
181 final int pos = apos;
\r
182 // use vamsas listener to broadcast to all listeners in scope
\r
183 if (alignedPosition != null
\r
184 && (alignedPosition.trim().length() == 0 || alignedPosition
\r
185 .toLowerCase().indexOf("false") > -1))
\r
187 java.awt.EventQueue.invokeLater(new Runnable()
\r
192 StructureSelectionManager.getStructureSelectionManager(me)
\r
193 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
\r
199 java.awt.EventQueue.invokeLater(new Runnable()
\r
204 StructureSelectionManager.getStructureSelectionManager(me)
\r
205 .mouseOverVamsasSequence(sq, pos, null);
\r
215 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
\r
216 * java.lang.String)
\r
218 public void select(String sequenceIds, String columns)
\r
220 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
\r
226 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
\r
227 * java.lang.String, java.lang.String)
\r
229 public void select(String sequenceIds, String columns, String sep)
\r
231 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
\r
237 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
\r
238 * java.lang.String, java.lang.String)
\r
240 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
\r
242 selectIn(alf, sequenceIds, columns, separator);
\r
248 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
\r
249 * java.lang.String, java.lang.String, java.lang.String)
\r
251 public void selectIn(final AlignFrame alf, String sequenceIds,
\r
252 String columns, String sep)
\r
254 if (sep == null || sep.length() == 0)
\r
262 System.err.println("Selecting region using separator string '"
\r
263 + separator + "'");
\r
267 String[] ids = separatorListToArray(sequenceIds, sep);
\r
268 String[] cols = separatorListToArray(columns, sep);
\r
269 final SequenceGroup sel = new SequenceGroup();
\r
270 final ColumnSelection csel = new ColumnSelection();
\r
271 AlignmentI al = alf.viewport.getAlignment();
\r
272 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
273 alf.viewport.getAlignment().getSequencesArray());
\r
274 int start = 0, end = al.getWidth(), alw = al.getWidth();
\r
275 boolean seqsfound = true;
\r
276 if (ids != null && ids.length > 0)
\r
279 for (int i = 0; i < ids.length; i++)
\r
281 if (ids[i].trim().length() == 0)
\r
285 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
289 sel.addSequence(sq, false);
\r
293 boolean inseqpos = false;
\r
294 if (cols != null && cols.length > 0)
\r
296 boolean seset = false;
\r
297 for (int i = 0; i < cols.length; i++)
\r
299 String cl = cols[i].trim();
\r
300 if (cl.length() == 0)
\r
305 if ((p = cl.indexOf("-")) > -1)
\r
307 int from = -1, to = -1;
\r
310 from = new Integer(cl.substring(0, p)).intValue();
\r
312 } catch (NumberFormatException ex)
\r
315 .println("ERROR: Couldn't parse first integer in range element column selection string '"
\r
316 + cl + "' - format is 'from-to'");
\r
321 to = new Integer(cl.substring(p + 1)).intValue();
\r
323 } catch (NumberFormatException ex)
\r
326 .println("ERROR: Couldn't parse second integer in range element column selection string '"
\r
327 + cl + "' - format is 'from-to'");
\r
330 if (from >= 0 && to >= 0)
\r
347 // comment to prevent range extension
\r
357 for (int r = from; r <= to; r++)
\r
359 if (r >= 0 && r < alw)
\r
361 csel.addElement(r);
\r
366 System.err.println("Range '" + cl + "' deparsed as [" + from
\r
372 System.err.println("ERROR: Invalid Range '" + cl
\r
373 + "' deparsed as [" + from + "," + to + "]");
\r
381 r = new Integer(cl).intValue();
\r
383 } catch (NumberFormatException ex)
\r
385 if (cl.toLowerCase().equals("sequence"))
\r
387 // we are in the dataset sequence's coordinate frame.
\r
393 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
\r
398 if (r >= 0 && r <= alw)
\r
408 // comment to prevent range extension
\r
418 csel.addElement(r);
\r
421 System.err.println("Point selection '" + cl
\r
422 + "' deparsed as [" + r + "]");
\r
427 System.err.println("ERROR: Invalid Point selection '" + cl
\r
428 + "' deparsed as [" + r + "]");
\r
435 // we only propagate the selection when it was the null selection, or the
\r
436 // given sequences were found in the alignment.
\r
437 if (inseqpos && sel.getSize() > 0)
\r
439 // assume first sequence provides reference frame ?
\r
440 SequenceI rs = sel.getSequenceAt(0);
\r
441 start = rs.findIndex(start);
\r
442 end = rs.findIndex(end);
\r
445 Vector cs = csel.getSelected();
\r
447 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
\r
449 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
\r
454 sel.setStartRes(start);
\r
455 sel.setEndRes(end);
\r
456 EventQueue.invokeLater(new Runnable()
\r
461 alf.select(sel, csel);
\r
471 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
\r
472 * String, java.lang.String)
\r
474 public String getSelectedSequencesAsAlignment(String format, String suffix)
\r
476 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
\r
484 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
\r
485 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
487 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
\r
488 String format, String suffix)
\r
492 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
493 if (alf.viewport.getSelectionGroup() != null)
\r
495 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
\r
496 // method now returns a full copy of sequence data
\r
497 // TODO consider using getSequenceSelection instead here
\r
498 String reply = new AppletFormatAdapter().formatSequences(format,
\r
499 new Alignment(alf.viewport.getSelectionAsNewSequence()),
\r
503 } catch (Exception ex)
\r
505 ex.printStackTrace();
\r
506 return "Error retrieving alignment in " + format + " format. ";
\r
514 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
\r
516 public String getAlignmentOrder()
\r
518 return getAlignmentOrderFrom(getDefaultTargetFrame());
\r
525 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
\r
528 public String getAlignmentOrderFrom(AlignFrame alf)
\r
530 return getAlignmentOrderFrom(alf, separator);
\r
537 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
\r
538 * , java.lang.String)
\r
540 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
\r
542 AlignmentI alorder = alf.getAlignViewport().getAlignment();
\r
543 String[] order = new String[alorder.getHeight()];
\r
544 for (int i = 0; i < order.length; i++)
\r
546 order[i] = alorder.getSequenceAt(i).getName();
\r
548 return arrayToSeparatorList(order);
\r
554 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
\r
555 * java.lang.String)
\r
557 public String orderBy(String order, String undoName)
\r
559 return orderBy(order, undoName, separator);
\r
565 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
\r
566 * java.lang.String, java.lang.String)
\r
568 public String orderBy(String order, String undoName, String sep)
\r
570 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
\r
577 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
\r
578 * java.lang.String, java.lang.String, java.lang.String)
\r
580 public String orderAlignmentBy(AlignFrame alf, String order,
\r
581 String undoName, String sep)
\r
583 String[] ids = separatorListToArray(order, sep);
\r
584 SequenceI[] sqs = null;
\r
585 if (ids != null && ids.length > 0)
\r
587 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
588 alf.viewport.getAlignment().getSequencesArray());
\r
590 sqs = new SequenceI[ids.length];
\r
591 for (int i = 0; i < ids.length; i++)
\r
593 if (ids[i].trim().length() == 0)
\r
597 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
605 SequenceI[] sqq = new SequenceI[s];
\r
606 System.arraycopy(sqs, 0, sqq, 0, s);
\r
619 final AlignmentOrder aorder = new AlignmentOrder(sqs);
\r
621 if (undoName != null && undoName.trim().length() == 0)
\r
625 final String _undoName = undoName;
\r
626 // TODO: deal with synchronization here: cannot raise any events until after
\r
627 // this has returned.
\r
628 return alf.sortBy(aorder, _undoName) ? "true" : "";
\r
634 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
\r
636 public String getAlignment(String format)
\r
638 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
\r
645 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
\r
646 * java.lang.String)
\r
648 public String getAlignmentFrom(AlignFrame alf, String format)
\r
650 return getAlignmentFrom(alf, format, "true");
\r
656 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
\r
657 * java.lang.String)
\r
659 public String getAlignment(String format, String suffix)
\r
661 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
\r
668 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
\r
669 * java.lang.String, java.lang.String)
\r
671 public String getAlignmentFrom(AlignFrame alf, String format,
\r
676 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
678 String reply = new AppletFormatAdapter().formatSequences(format,
\r
679 alf.viewport.getAlignment(), seqlimits);
\r
681 } catch (Exception ex)
\r
683 ex.printStackTrace();
\r
684 return "Error retrieving alignment in " + format + " format. ";
\r
691 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
\r
693 public void loadAnnotation(String annotation)
\r
695 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
\r
702 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
\r
703 * , java.lang.String)
\r
705 public void loadAnnotationFrom(AlignFrame alf, String annotation)
\r
707 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
\r
708 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
\r
710 alf.alignPanel.fontChanged();
\r
711 alf.alignPanel.setScrollValues(0, 0);
\r
715 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
\r
722 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
\r
724 public void loadFeatures(String features, boolean autoenabledisplay)
\r
726 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
\r
733 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
\r
734 * , java.lang.String)
\r
736 public boolean loadFeaturesFrom(AlignFrame alf, String features,
\r
737 boolean autoenabledisplay)
\r
739 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
\r
740 autoenabledisplay);
\r
746 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
\r
748 public String getFeatures(String format)
\r
750 return getFeaturesFrom(getDefaultTargetFrame(), format);
\r
757 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
\r
758 * java.lang.String)
\r
760 public String getFeaturesFrom(AlignFrame alf, String format)
\r
762 return alf.outputFeatures(false, format);
\r
768 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
\r
770 public String getAnnotation()
\r
772 return getAnnotationFrom(getDefaultTargetFrame());
\r
779 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
\r
782 public String getAnnotationFrom(AlignFrame alf)
\r
784 return alf.outputAnnotations(false);
\r
790 * @see jalview.bin.JalviewLiteJsApi#newView()
\r
792 public AlignFrame newView()
\r
794 return newViewFrom(getDefaultTargetFrame());
\r
800 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
\r
802 public AlignFrame newView(String name)
\r
804 return newViewFrom(getDefaultTargetFrame(), name);
\r
810 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
\r
812 public AlignFrame newViewFrom(AlignFrame alf)
\r
814 return alf.newView(null);
\r
820 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
\r
821 * java.lang.String)
\r
823 public AlignFrame newViewFrom(AlignFrame alf, String name)
\r
825 return alf.newView(name);
\r
831 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
\r
832 * java.lang.String)
\r
834 public AlignFrame loadAlignment(String text, String title)
\r
836 Alignment al = null;
\r
838 String format = new IdentifyFile().Identify(text,
\r
839 AppletFormatAdapter.PASTE);
\r
842 al = new AppletFormatAdapter().readFile(text,
\r
843 AppletFormatAdapter.PASTE, format);
\r
844 if (al.getHeight() > 0)
\r
846 return new AlignFrame(al, this, title, false);
\r
848 } catch (java.io.IOException ex)
\r
850 ex.printStackTrace();
\r
858 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
\r
860 public void setMouseoverListener(String listener)
\r
862 setMouseoverListener(currentAlignFrame, listener);
\r
865 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
\r
871 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
\r
872 * , java.lang.String)
\r
874 public void setMouseoverListener(AlignFrame af, String listener)
\r
876 if (listener != null)
\r
878 listener = listener.trim();
\r
879 if (listener.length() == 0)
\r
882 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
\r
886 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
\r
887 this, af, listener);
\r
888 javascriptListeners.addElement(mol);
\r
889 StructureSelectionManager.getStructureSelectionManager(this)
\r
890 .addStructureViewerListener(mol);
\r
893 System.err.println("Added a mouseover listener for "
\r
894 + ((af == null) ? "All frames" : "Just views for "
\r
895 + af.getAlignViewport().getSequenceSetId()));
\r
896 System.err.println("There are now " + javascriptListeners.size()
\r
897 + " listeners in total.");
\r
904 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
\r
906 public void setSelectionListener(String listener)
\r
908 setSelectionListener(null, listener);
\r
915 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
\r
916 * , java.lang.String)
\r
918 public void setSelectionListener(AlignFrame af, String listener)
\r
920 if (listener != null)
\r
922 listener = listener.trim();
\r
923 if (listener.length() == 0)
\r
926 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
930 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
\r
931 this, af, listener);
\r
932 javascriptListeners.addElement(mol);
\r
933 StructureSelectionManager.getStructureSelectionManager(this)
\r
934 .addSelectionListener(mol);
\r
937 System.err.println("Added a selection listener for "
\r
938 + ((af == null) ? "All frames" : "Just views for "
\r
939 + af.getAlignViewport().getSequenceSetId()));
\r
940 System.err.println("There are now " + javascriptListeners.size()
\r
941 + " listeners in total.");
\r
948 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
\r
949 * java.lang.String)
\r
951 public void setStructureListener(String listener, String modelSet)
\r
953 if (listener != null)
\r
955 listener = listener.trim();
\r
956 if (listener.length() == 0)
\r
959 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
963 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
\r
964 this, listener, separatorListToArray(modelSet));
\r
965 javascriptListeners.addElement(mol);
\r
966 StructureSelectionManager.getStructureSelectionManager(this)
\r
967 .addStructureViewerListener(mol);
\r
970 System.err.println("Added a javascript structure viewer listener '"
\r
972 System.err.println("There are now " + javascriptListeners.size()
\r
973 + " listeners in total.");
\r
981 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
\r
982 * .AlignFrame, java.lang.String)
\r
984 public void removeJavascriptListener(AlignFrame af, String listener)
\r
986 if (listener != null)
\r
988 listener = listener.trim();
\r
989 if (listener.length() == 0)
\r
994 boolean rprt = false;
\r
995 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
\r
997 Object lstn = javascriptListeners.elementAt(ms);
\r
998 JsCallBack lstner = (JsCallBack) lstn;
\r
999 if ((af == null || lstner.getAlignFrame() == af)
\r
1000 && (listener == null || lstner.getListenerFunction().equals(
\r
1003 javascriptListeners.removeElement(lstner);
\r
1005 if (lstner instanceof SelectionListener)
\r
1007 StructureSelectionManager.getStructureSelectionManager(this)
\r
1008 .removeSelectionListener((SelectionListener) lstner);
\r
1012 StructureSelectionManager.getStructureSelectionManager(this)
\r
1013 .removeStructureViewerListener(lstner, null);
\r
1018 System.err.println("Removed listener '" + listener + "'");
\r
1028 System.err.println("There are now " + javascriptListeners.size()
\r
1029 + " listeners in total.");
\r
1033 public void stop()
\r
1035 System.err.println("Applet " + getName() + " stop().");
\r
1039 public void destroy()
\r
1041 System.err.println("Applet " + getName() + " destroy().");
\r
1045 private void tidyUp()
\r
1048 if (currentAlignFrame != null && currentAlignFrame.viewport != null
\r
1049 && currentAlignFrame.viewport.applet != null)
\r
1051 AlignViewport av = currentAlignFrame.viewport;
\r
1052 currentAlignFrame.closeMenuItem_actionPerformed();
\r
1054 currentAlignFrame = null;
\r
1056 if (javascriptListeners != null)
\r
1058 while (javascriptListeners.size() > 0)
\r
1060 jalview.javascript.JSFunctionExec mol = javascriptListeners
\r
1062 javascriptListeners.removeElement(mol);
\r
1063 if (mol instanceof SelectionListener)
\r
1065 StructureSelectionManager.getStructureSelectionManager(this)
\r
1066 .removeSelectionListener((SelectionListener) mol);
\r
1070 StructureSelectionManager.getStructureSelectionManager(this)
\r
1071 .removeStructureViewerListener(mol, null);
\r
1073 mol.jvlite = null;
\r
1076 if (jsFunctionExec != null)
\r
1078 jsFunctionExec.stopQueue();
\r
1079 jsFunctionExec.jvlite = null;
\r
1081 initialAlignFrame = null;
\r
1082 jsFunctionExec = null;
\r
1083 javascriptListeners = null;
\r
1084 StructureSelectionManager.release(this);
\r
1087 private jalview.javascript.JSFunctionExec jsFunctionExec;
\r
1092 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
\r
1093 * java.lang.String, java.lang.String)
\r
1095 public void mouseOverStructure(final String pdbResNum,
\r
1096 final String chain, final String pdbfile)
\r
1098 final StructureSelectionManagerProvider me = this;
\r
1099 java.awt.EventQueue.invokeLater(new Runnable()
\r
1106 StructureSelectionManager.getStructureSelectionManager(me)
\r
1107 .mouseOverStructure(new Integer(pdbResNum).intValue(),
\r
1111 System.err.println("mouseOver for '" + pdbResNum
\r
1112 + "' in chain '" + chain + "' in structure '" + pdbfile
\r
1115 } catch (NumberFormatException e)
\r
1117 System.err.println("Ignoring invalid residue number string '"
\r
1118 + pdbResNum + "'");
\r
1129 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
\r
1130 * java.lang.String, java.lang.String)
\r
1132 public void scrollViewToIn(final AlignFrame alf, final String topRow,
\r
1133 final String leftHandColumn)
\r
1135 java.awt.EventQueue.invokeLater(new Runnable()
\r
1142 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
\r
1143 leftHandColumn).intValue());
\r
1145 } catch (Exception ex)
\r
1147 System.err.println("Couldn't parse integer arguments (topRow='"
\r
1148 + topRow + "' and leftHandColumn='" + leftHandColumn
\r
1150 ex.printStackTrace();
\r
1160 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
\r
1161 * .AlignFrame, java.lang.String)
\r
1164 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
\r
1167 java.awt.EventQueue.invokeLater(new Runnable()
\r
1174 alf.scrollToRow(new Integer(topRow).intValue());
\r
1176 } catch (Exception ex)
\r
1178 System.err.println("Couldn't parse integer arguments (topRow='"
\r
1180 ex.printStackTrace();
\r
1191 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
\r
1192 * .AlignFrame, java.lang.String)
\r
1195 public void scrollViewToColumnIn(final AlignFrame alf,
\r
1196 final String leftHandColumn)
\r
1198 java.awt.EventQueue.invokeLater(new Runnable()
\r
1206 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
\r
1208 } catch (Exception ex)
\r
1211 .println("Couldn't parse integer arguments (leftHandColumn='"
\r
1212 + leftHandColumn + "')");
\r
1213 ex.printStackTrace();
\r
1220 // //////////////////////////////////////////////
\r
1221 // //////////////////////////////////////////////
\r
1223 public static int lastFrameX = 200;
\r
1225 public static int lastFrameY = 200;
\r
1227 boolean fileFound = true;
\r
1229 String file = "No file";
\r
1231 Button launcher = new Button("Start Jalview");
\r
1234 * The currentAlignFrame is static, it will change if and when the user
\r
1235 * selects a new window. Note that it will *never* point back to the embedded
\r
1236 * AlignFrame if the applet is started as embedded on the page and then
\r
1237 * afterwards a new view is created.
\r
1239 public AlignFrame currentAlignFrame = null;
\r
1242 * This is the first frame to be displayed, and does not change. API calls
\r
1243 * will default to this instance if currentAlignFrame is null.
\r
1245 AlignFrame initialAlignFrame = null;
\r
1247 boolean embedded = false;
\r
1249 private boolean checkForJmol = true;
\r
1251 private boolean checkedForJmol = false; // ensure we don't check for jmol
\r
1253 // every time the app is re-inited
\r
1255 public boolean jmolAvailable = false;
\r
1257 private boolean alignPdbStructures = false;
\r
1260 * use an external structure viewer exclusively (no jmols or MCViews will be
\r
1261 * opened by JalviewLite itself)
\r
1263 public boolean useXtrnalSviewer = false;
\r
1265 public static boolean debug = false;
\r
1267 static String builddate = null, version = null;
\r
1269 private static void initBuildDetails()
\r
1271 if (builddate == null)
\r
1273 builddate = "unknown";
\r
1275 java.net.URL url = JalviewLite.class
\r
1276 .getResource("/.build_properties");
\r
1281 BufferedReader reader = new BufferedReader(new InputStreamReader(
\r
1282 url.openStream()));
\r
1284 while ((line = reader.readLine()) != null)
\r
1286 if (line.indexOf("VERSION") > -1)
\r
1288 version = line.substring(line.indexOf("=") + 1);
\r
1290 if (line.indexOf("BUILD_DATE") > -1)
\r
1292 builddate = line.substring(line.indexOf("=") + 1);
\r
1295 } catch (Exception ex)
\r
1297 ex.printStackTrace();
\r
1303 public static String getBuildDate()
\r
1305 initBuildDetails();
\r
1309 public static String getVersion()
\r
1311 initBuildDetails();
\r
1315 // public JSObject scriptObject = null;
\r
1318 * init method for Jalview Applet
\r
1320 public void init()
\r
1322 // remove any handlers that might be hanging around from an earlier instance
\r
1327 System.err.println("Applet context is '"
\r
1328 + getAppletContext().getClass().toString() + "'");
\r
1330 JSObject scriptObject = JSObject.getWindow(this);
\r
1331 if (debug && scriptObject != null)
\r
1333 System.err.println("Applet has Javascript callback support.");
\r
1336 } catch (Exception ex)
\r
1339 .println("Warning: No JalviewLite javascript callbacks available.");
\r
1342 ex.printStackTrace();
\r
1346 * turn on extra applet debugging
\r
1348 String dbg = getParameter("debug");
\r
1351 debug = dbg.toLowerCase().equals("true");
\r
1356 System.err.println("JalviewLite Version " + getVersion());
\r
1357 System.err.println("Build Date : " + getBuildDate());
\r
1360 String externalsviewer = getParameter("externalstructureviewer");
\r
1361 if (externalsviewer != null)
\r
1363 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
\r
1367 * if true disable the check for jmol
\r
1369 String chkforJmol = getParameter("nojmol");
\r
1370 if (chkforJmol != null)
\r
1372 checkForJmol = !chkforJmol.equals("true");
\r
1375 * get the separator parameter if present
\r
1377 String sep = getParameter("separator");
\r
1380 if (sep.length() > 0)
\r
1385 System.err.println("Separator set to '" + separator + "'");
\r
1391 "Invalid separator parameter - must be non-zero length");
\r
1397 String param = getParameter("RGB");
\r
1399 if (param != null)
\r
1403 r = Integer.parseInt(param.substring(0, 2), 16);
\r
1404 g = Integer.parseInt(param.substring(2, 4), 16);
\r
1405 b = Integer.parseInt(param.substring(4, 6), 16);
\r
1406 } catch (Exception ex)
\r
1413 param = getParameter("label");
\r
1414 if (param != null)
\r
1416 launcher.setLabel(param);
\r
1419 setBackground(new Color(r, g, b));
\r
1421 file = getParameter("file");
\r
1425 // Maybe the sequences are added as parameters
\r
1426 StringBuffer data = new StringBuffer("PASTE");
\r
1428 while ((file = getParameter("sequence" + i)) != null)
\r
1430 data.append(file.toString() + "\n");
\r
1433 if (data.length() > 5)
\r
1435 file = data.toString();
\r
1439 final JalviewLite jvapplet = this;
\r
1440 if (getParameter("embedded") != null
\r
1441 && getParameter("embedded").equalsIgnoreCase("true"))
\r
1443 // Launch as embedded applet in page
\r
1445 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1448 else if (file != null)
\r
1450 if (getParameter("showbutton") == null
\r
1451 || !getParameter("showbutton").equalsIgnoreCase("false"))
\r
1453 // Add the JalviewLite 'Button' to the page
\r
1455 launcher.addActionListener(new java.awt.event.ActionListener()
\r
1457 public void actionPerformed(ActionEvent e)
\r
1459 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1466 // Open jalviewLite immediately.
\r
1467 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1473 // jalview initialisation with no alignment. loadAlignment() method can
\r
1474 // still be called to open new alignments.
\r
1476 fileFound = false;
\r
1477 // callInitCallback();
\r
1481 private void callInitCallback()
\r
1483 String initjscallback = getParameter("oninit");
\r
1484 if (initjscallback == null)
\r
1488 initjscallback = initjscallback.trim();
\r
1489 if (initjscallback.length() > 0)
\r
1491 JSObject scriptObject = null;
\r
1494 scriptObject = JSObject.getWindow(this);
\r
1495 } catch (Exception ex)
\r
1499 if (scriptObject != null)
\r
1503 // do onInit with the JS executor thread
\r
1504 new JSFunctionExec(this).executeJavascriptFunction(true,
\r
1505 initjscallback, null, "Calling oninit callback '"
\r
1506 + initjscallback + "'.");
\r
1507 } catch (Exception e)
\r
1509 System.err.println("Exception when executing _oninit callback '"
\r
1510 + initjscallback + "'.");
\r
1511 e.printStackTrace();
\r
1516 System.err.println("Not executing _oninit callback '"
\r
1517 + initjscallback + "' - no scripting allowed.");
\r
1523 * Initialises and displays a new java.awt.Frame
\r
1526 * java.awt.Frame to be displayed
\r
1528 * title of new frame
\r
1530 * width if new frame
\r
1532 * height of new frame
\r
1534 public static void addFrame(final Frame frame, String title, int width,
\r
1537 frame.setLocation(lastFrameX, lastFrameY);
\r
1540 frame.setSize(width, height);
\r
1541 frame.setTitle(title);
\r
1542 frame.addWindowListener(new WindowAdapter()
\r
1544 public void windowClosing(WindowEvent e)
\r
1546 if (frame instanceof AlignFrame)
\r
1548 AlignViewport vp = ((AlignFrame) frame).viewport;
\r
1549 ((AlignFrame) frame).closeMenuItem_actionPerformed();
\r
1550 if (vp.applet.currentAlignFrame == frame)
\r
1552 vp.applet.currentAlignFrame = null;
\r
1560 if (frame instanceof EmbmenuFrame)
\r
1562 ((EmbmenuFrame) frame).destroyMenus();
\r
1564 frame.setMenuBar(null);
\r
1568 public void windowActivated(WindowEvent e)
\r
1570 if (frame instanceof AlignFrame)
\r
1572 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
\r
1575 System.err.println("Activated window " + frame);
\r
1579 super.windowActivated(e);
\r
1582 * Probably not necessary to do this - see TODO above. (non-Javadoc)
\r
1585 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
\r
1588 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
\r
1589 * frame) { currentAlignFrame = null; if (debug) {
\r
1590 * System.err.println("Deactivated window "+frame); } }
\r
1591 * super.windowDeactivated(e); }
\r
1594 frame.setVisible(true);
\r
1598 * This paints the background surrounding the "Launch Jalview button" <br>
\r
1600 * If file given in parameter not found, displays error message
\r
1603 * graphics context
\r
1605 public void paint(Graphics g)
\r
1609 g.setColor(new Color(200, 200, 200));
\r
1610 g.setColor(Color.cyan);
\r
1611 g.fillRect(0, 0, getSize().width, getSize().height);
\r
1612 g.setColor(Color.red);
\r
1613 g.drawString("Jalview can't open file", 5, 15);
\r
1614 g.drawString("\"" + file + "\"", 5, 30);
\r
1616 else if (embedded)
\r
1618 g.setColor(Color.black);
\r
1619 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
1620 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
\r
1621 g.drawString("Loading Data...", 50, getSize().height / 2);
\r
1626 * get all components associated with the applet of the given type
\r
1631 public Vector getAppletWindow(Class class1)
\r
1633 Vector wnds = new Vector();
\r
1634 Component[] cmp = getComponents();
\r
1637 for (int i = 0; i < cmp.length; i++)
\r
1639 if (class1.isAssignableFrom(cmp[i].getClass()))
\r
1641 wnds.addElement(cmp);
\r
1648 class LoadJmolThread extends Thread
\r
1650 private boolean running = false;
\r
1654 if (running || checkedForJmol)
\r
1663 if (!System.getProperty("java.version").startsWith("1.1"))
\r
1665 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
\r
1666 jmolAvailable = true;
\r
1668 if (!jmolAvailable)
\r
1671 .println("Jmol not available - Using MCview for structures");
\r
1673 } catch (java.lang.ClassNotFoundException ex)
\r
1679 jmolAvailable = false;
\r
1683 .println("Skipping Jmol check. Will use MCView (probably)");
\r
1686 checkedForJmol = true;
\r
1690 public boolean notFinished()
\r
1692 return running || !checkedForJmol;
\r
1696 class LoadingThread extends Thread
\r
1699 * State variable: File source
\r
1704 * State variable: protocol for access to file source
\r
1709 * State variable: format of file source
\r
1715 JalviewLite applet;
\r
1717 private void dbgMsg(String msg)
\r
1721 System.err.println(msg);
\r
1726 * update the protocol state variable for accessing the datasource located
\r
1730 * @return possibly updated datasource string
\r
1732 public String setProtocolState(String file)
\r
1734 if (file.startsWith("PASTE"))
\r
1736 file = file.substring(5);
\r
1737 protocol = AppletFormatAdapter.PASTE;
\r
1739 else if (inArchive(file))
\r
1741 protocol = AppletFormatAdapter.CLASSLOADER;
\r
1745 file = addProtocol(file);
\r
1746 protocol = AppletFormatAdapter.URL;
\r
1748 dbgMsg("Protocol identified as '" + protocol + "'");
\r
1752 public LoadingThread(String _file, JalviewLite _applet)
\r
1754 this._file = _file;
\r
1760 LoadJmolThread jmolchecker = new LoadJmolThread();
\r
1761 jmolchecker.start();
\r
1762 while (jmolchecker.notFinished())
\r
1764 // wait around until the Jmol check is complete.
\r
1768 } catch (Exception e)
\r
1774 // applet.callInitCallback();
\r
1777 private void startLoading()
\r
1779 AlignFrame newAlignFrame;
\r
1780 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
\r
1781 file = setProtocolState(_file);
\r
1783 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
1784 dbgMsg("File identified as '" + format + "'");
\r
1785 dbgMsg("Loading started.");
\r
1786 Alignment al = null;
\r
1789 al = new AppletFormatAdapter().readFile(file, protocol, format);
\r
1790 } catch (java.io.IOException ex)
\r
1792 dbgMsg("File load exception.");
\r
1793 ex.printStackTrace();
\r
1798 FileParse fp = new FileParse(file, protocol);
\r
1800 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
\r
1801 + protocol + ")");
\r
1802 while ((ln = fp.nextLine()) != null)
\r
1806 dbgMsg(">>>Dump finished.");
\r
1807 } catch (Exception e)
\r
1810 .println("Exception when trying to dump the content of the file parameter.");
\r
1811 e.printStackTrace();
\r
1815 if ((al != null) && (al.getHeight() > 0))
\r
1817 dbgMsg("Successfully loaded file.");
\r
1818 newAlignFrame = new AlignFrame(al, applet, file, embedded);
\r
1819 if (initialAlignFrame == null)
\r
1821 initialAlignFrame = newAlignFrame;
\r
1823 // update the focus.
\r
1824 currentAlignFrame = newAlignFrame;
\r
1826 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
\r
1828 newAlignFrame.setTitle("Sequences from "
\r
1829 + applet.getDocumentBase());
\r
1832 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
1834 String treeFile = applet.getParameter("tree");
\r
1835 if (treeFile == null)
\r
1837 treeFile = applet.getParameter("treeFile");
\r
1840 if (treeFile != null)
\r
1844 treeFile = setProtocolState(treeFile);
\r
1846 * if (inArchive(treeFile)) { protocol =
\r
1847 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
\r
1848 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
\r
1850 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
\r
1855 if (fin.getTree() != null)
\r
1857 newAlignFrame.loadTree(fin, treeFile);
\r
1858 dbgMsg("Successfuly imported tree.");
\r
1862 dbgMsg("Tree parameter did not resolve to a valid tree.");
\r
1864 } catch (Exception ex)
\r
1866 ex.printStackTrace();
\r
1871 * Try to load T-Coffee score file
\r
1873 String sScoreFile = applet.getParameter("scoreFile");
\r
1874 if (sScoreFile != null && !"".equals(sScoreFile))
\r
1881 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
\r
1883 if (!newAlignFrame.loadScoreFile(sScoreFile))
\r
1886 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
\r
1887 + sScoreFile + "')");
\r
1889 } catch (Exception e)
\r
1891 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
\r
1892 sScoreFile, e.getMessage());
\r
1896 // ///////////////////////////
\r
1897 // modify display of features
\r
1898 // we do this before any features have been loaded, ensuring any hidden
\r
1899 // groups are hidden when features first displayed
\r
1901 // hide specific groups
\r
1903 String param = applet.getParameter("hidefeaturegroups");
\r
1904 if (param != null)
\r
1906 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
\r
1908 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
\r
1910 // show specific groups
\r
1911 param = applet.getParameter("showfeaturegroups");
\r
1912 if (param != null)
\r
1914 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
\r
1916 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
\r
1918 // and now load features
\r
1919 param = applet.getParameter("features");
\r
1920 if (param != null)
\r
1922 param = setProtocolState(param);
\r
1924 newAlignFrame.parseFeaturesFile(param, protocol);
\r
1927 param = applet.getParameter("showFeatureSettings");
\r
1928 if (param != null && param.equalsIgnoreCase("true"))
\r
1930 newAlignFrame.viewport.showSequenceFeatures(true);
\r
1931 new FeatureSettings(newAlignFrame.alignPanel);
\r
1934 param = applet.getParameter("annotations");
\r
1935 if (param != null)
\r
1937 param = setProtocolState(param);
\r
1939 if (new AnnotationFile().readAnnotationFile(
\r
1940 newAlignFrame.viewport.getAlignment(), param, protocol))
\r
1942 newAlignFrame.alignPanel.fontChanged();
\r
1943 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1948 .println("Annotations were not added from annotation file '"
\r
1954 param = applet.getParameter("jnetfile");
\r
1955 if (param != null)
\r
1959 param = setProtocolState(param);
\r
1960 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
\r
1962 JnetAnnotationMaker.add_annotation(predictions,
\r
1963 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
\r
1971 newAlignFrame.alignPanel.fontChanged();
\r
1972 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1973 } catch (Exception ex)
\r
1975 ex.printStackTrace();
\r
1979 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
\r
1980 * - related to JAL-434
\r
1982 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
\r
1985 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
\r
1986 * PDB|1GAQ|1GAQ|C">
\r
1988 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
\r
1990 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
\r
1993 int pdbFileCount = 0;
\r
1994 // Accumulate pdbs here if they are heading for the same view (if
\r
1995 // alignPdbStructures is true)
\r
1996 Vector pdbs = new Vector();
\r
1997 // create a lazy matcher if we're asked to
\r
1998 jalview.analysis.SequenceIdMatcher matcher = (applet
\r
1999 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
\r
2000 newAlignFrame.getAlignViewport().getAlignment()
\r
2001 .getSequencesArray()) : null;
\r
2005 if (pdbFileCount > 0)
\r
2007 param = applet.getParameter("PDBFILE" + pdbFileCount);
\r
2011 param = applet.getParameter("PDBFILE");
\r
2014 if (param != null)
\r
2016 PDBEntry pdb = new PDBEntry();
\r
2019 SequenceI[] seqs = null;
\r
2020 String[] chains = null;
\r
2022 StringTokenizer st = new StringTokenizer(param, " ");
\r
2024 if (st.countTokens() < 2)
\r
2026 String sequence = applet.getParameter("PDBSEQ");
\r
2027 if (sequence != null)
\r
2028 seqs = new SequenceI[]
\r
2029 { matcher == null ? (Sequence) newAlignFrame
\r
2030 .getAlignViewport().getAlignment()
\r
2031 .findName(sequence) : matcher.findIdMatch(sequence) };
\r
2036 param = st.nextToken();
\r
2037 Vector tmp = new Vector();
\r
2038 Vector tmp2 = new Vector();
\r
2040 while (st.hasMoreTokens())
\r
2042 seqstring = st.nextToken();
\r
2043 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
\r
2044 if (st2.countTokens() > 1)
\r
2046 // This is the chain
\r
2047 tmp2.addElement(st2.nextToken());
\r
2048 seqstring = st2.nextToken();
\r
2050 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
\r
2051 .getAlignViewport().getAlignment()
\r
2052 .findName(seqstring) : matcher
\r
2053 .findIdMatch(seqstring));
\r
2056 seqs = new SequenceI[tmp.size()];
\r
2057 tmp.copyInto(seqs);
\r
2058 if (tmp2.size() == tmp.size())
\r
2060 chains = new String[tmp2.size()];
\r
2061 tmp2.copyInto(chains);
\r
2064 param = setProtocolState(param);
\r
2066 if (// !jmolAvailable
\r
2068 protocol == AppletFormatAdapter.CLASSLOADER
\r
2069 && !useXtrnalSviewer)
\r
2071 // Re: JAL-357 : the bug isn't a problem if we are using an
\r
2072 // external viewer!
\r
2073 // TODO: verify this Re:
\r
2074 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
\r
2075 // This exception preserves the current behaviour where, even if
\r
2076 // the local pdb file was identified in the class loader
\r
2077 protocol = AppletFormatAdapter.URL; // this is probably NOT
\r
2079 param = addProtocol(param); //
\r
2082 pdb.setFile(param);
\r
2086 for (int i = 0; i < seqs.length; i++)
\r
2088 if (seqs[i] != null)
\r
2090 ((Sequence) seqs[i]).addPDBId(pdb);
\r
2094 if (JalviewLite.debug)
\r
2096 // this may not really be a problem but we give a warning
\r
2099 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
\r
2105 if (!alignPdbStructures)
\r
2107 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
\r
2112 pdbs.addElement(new Object[]
\r
2113 { pdb, seqs, chains, new String(protocol) });
\r
2119 } while (param != null || pdbFileCount < 10);
\r
2120 if (pdbs.size() > 0)
\r
2122 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
\r
2123 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
\r
2124 String[][] chains = new String[pdbs.size()][];
\r
2125 String[] protocols = new String[pdbs.size()];
\r
2126 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
\r
2128 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
\r
2129 pdb[pdbsi] = (PDBEntry) o[0];
\r
2130 seqs[pdbsi] = (SequenceI[]) o[1];
\r
2131 chains[pdbsi] = (String[]) o[2];
\r
2132 protocols[pdbsi] = (String) o[3];
\r
2134 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
\r
2141 fileFound = false;
\r
2142 applet.remove(launcher);
\r
2145 callInitCallback();
\r
2149 * Discovers whether the given file is in the Applet Archive
\r
2155 boolean inArchive(String file)
\r
2157 // This might throw a security exception in certain browsers
\r
2158 // Netscape Communicator for instance.
\r
2161 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
\r
2164 System.err.println("Resource '" + file + "' was "
\r
2165 + (rtn ? "" : "not") + " located by classloader.");
\r
2168 } catch (Exception ex)
\r
2170 System.out.println("Exception checking resources: " + file + " "
\r
2176 String addProtocol(String file)
\r
2178 if (file.indexOf("://") == -1)
\r
2180 String fl = applet.resolveUrlForLocalOrAbsolute(file,
\r
2181 getDocumentBase());
\r
2184 if (new java.net.URL(fl).openStream() != null)
\r
2188 System.err.println("Prepended document base for resource: '"
\r
2193 } catch (Exception x)
\r
2197 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
\r
2200 if (new java.net.URL(fl).openStream() != null)
\r
2204 System.err.println("Prepended codebase for resource: '"
\r
2209 } catch (Exception x)
\r
2221 * @return the default alignFrame acted on by the public applet methods. May
\r
2222 * return null with an error message on System.err indicating the
\r
2225 public AlignFrame getDefaultTargetFrame()
\r
2227 if (currentAlignFrame != null)
\r
2229 return currentAlignFrame;
\r
2231 if (initialAlignFrame != null)
\r
2233 return initialAlignFrame;
\r
2236 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
\r
2241 * separator used for separatorList
\r
2243 protected String separator = "" + ((char) 0x00AC); // the default used to be
\r
2244 // '|' but many sequence
\r
2245 // IDS include pipes.
\r
2248 * set to enable the URL based javascript execution mechanism
\r
2250 public boolean jsfallbackEnabled = false;
\r
2253 * parse the string into a list
\r
2256 * @return elements separated by separator
\r
2258 public String[] separatorListToArray(String list)
\r
2260 return separatorListToArray(list, separator);
\r
2264 * parse the string into a list
\r
2267 * @param separator
\r
2268 * @return elements separated by separator
\r
2270 public String[] separatorListToArray(String list, String separator)
\r
2272 // note separator local variable intentionally masks object field
\r
2273 int seplen = separator.length();
\r
2274 if (list == null || list.equals("") || list.equals(separator))
\r
2276 java.util.Vector jv = new Vector();
\r
2278 while ((pos = list.indexOf(separator, cp)) > cp)
\r
2280 jv.addElement(list.substring(cp, pos));
\r
2281 cp = pos + seplen;
\r
2283 if (cp < list.length())
\r
2285 String c = list.substring(cp);
\r
2286 if (!c.equals(separator))
\r
2291 if (jv.size() > 0)
\r
2293 String[] v = new String[jv.size()];
\r
2294 for (int i = 0; i < v.length; i++)
\r
2296 v[i] = (String) jv.elementAt(i);
\r
2298 jv.removeAllElements();
\r
2301 System.err.println("Array from '" + separator
\r
2302 + "' separated List:\n" + v.length);
\r
2303 for (int i = 0; i < v.length; i++)
\r
2305 System.err.println("item " + i + " '" + v[i] + "'");
\r
2312 System.err.println("Empty Array from '" + separator
\r
2313 + "' separated List");
\r
2319 * concatenate the list with separator
\r
2322 * @return concatenated string
\r
2324 public String arrayToSeparatorList(String[] list)
\r
2326 return arrayToSeparatorList(list, separator);
\r
2330 * concatenate the list with separator
\r
2333 * @param separator
\r
2334 * @return concatenated string
\r
2336 public String arrayToSeparatorList(String[] list, String separator)
\r
2338 StringBuffer v = new StringBuffer();
\r
2339 if (list != null && list.length > 0)
\r
2341 for (int i = 0, iSize = list.length; i < iSize; i++)
\r
2343 if (list[i] != null)
\r
2347 v.append(separator);
\r
2349 v.append(list[i]);
\r
2354 System.err.println("Returning '" + separator
\r
2355 + "' separated List:\n");
\r
2356 System.err.println(v);
\r
2358 return v.toString();
\r
2362 System.err.println("Returning empty '" + separator
\r
2363 + "' separated List\n");
\r
2365 return "" + separator;
\r
2371 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
\r
2373 public String getFeatureGroups()
\r
2375 String lst = arrayToSeparatorList(getDefaultTargetFrame()
\r
2376 .getFeatureGroups());
\r
2384 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
\r
2387 public String getFeatureGroupsOn(AlignFrame alf)
\r
2389 String lst = arrayToSeparatorList(alf.getFeatureGroups());
\r
2396 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
\r
2398 public String getFeatureGroupsOfState(boolean visible)
\r
2400 return arrayToSeparatorList(getDefaultTargetFrame()
\r
2401 .getFeatureGroupsOfState(visible));
\r
2408 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
\r
2409 * .AlignFrame, boolean)
\r
2411 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
\r
2413 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
\r
2419 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
\r
2420 * AlignFrame, java.lang.String, boolean)
\r
2422 public void setFeatureGroupStateOn(final AlignFrame alf,
\r
2423 final String groups, boolean state)
\r
2425 final boolean st = state;// !(state==null || state.equals("") ||
\r
2426 // state.toLowerCase().equals("false"));
\r
2427 java.awt.EventQueue.invokeLater(new Runnable()
\r
2432 alf.setFeatureGroupState(separatorListToArray(groups), st);
\r
2440 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
\r
2443 public void setFeatureGroupState(String groups, boolean state)
\r
2445 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
\r
2451 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
\r
2453 public String getSeparator()
\r
2461 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
\r
2463 public void setSeparator(String separator)
\r
2465 if (separator == null || separator.length() < 1)
\r
2467 // reset to default
\r
2468 separator = "" + ((char) 0x00AC);
\r
2470 this.separator = separator;
\r
2473 System.err.println("Default Separator now: '" + separator + "'");
\r
2478 * get boolean value of applet parameter 'name' and return default if
\r
2479 * parameter is not set
\r
2482 * name of paremeter
\r
2484 * the value to return otherwise
\r
2485 * @return true or false
\r
2487 public boolean getDefaultParameter(String name, boolean def)
\r
2490 if ((stn = getParameter(name)) == null)
\r
2494 if (stn.toLowerCase().equals("true"))
\r
2504 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
\r
2505 * java.lang.String, java.lang.String, java.lang.String)
\r
2507 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
\r
2508 String pdbEntryString, String pdbFile)
\r
2510 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
\r
2513 protected void setAlignPdbStructures(boolean alignPdbStructures)
\r
2515 this.alignPdbStructures = alignPdbStructures;
\r
2518 public boolean isAlignPdbStructures()
\r
2520 return alignPdbStructures;
\r
2523 public void start()
\r
2525 // callInitCallback();
\r
2528 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
\r
2530 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
\r
2532 public void setJsMessageSet(String messageclass, String viewId,
\r
2533 String[] colcommands)
\r
2535 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
\r
2536 if (msgset == null)
\r
2538 msgset = new Hashtable<String, String[]>();
\r
2539 jsmessages.put(messageclass, msgset);
\r
2541 msgset.put(viewId, colcommands);
\r
2542 long[] l = new long[colcommands.length];
\r
2543 for (int i = 0; i < colcommands.length; i++)
\r
2545 l[i] = colcommands[i].hashCode();
\r
2547 jshashes.put(messageclass + "|" + viewId, l);
\r
2553 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
\r
2554 * java.lang.String)
\r
2556 public String getJsMessage(String messageclass, String viewId)
\r
2558 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
\r
2559 if (msgset != null)
\r
2561 String[] msgs = msgset.get(viewId);
\r
2564 for (int i = 0; i < msgs.length; i++)
\r
2566 if (msgs[i] != null)
\r
2568 String m = msgs[i];
\r
2578 public boolean isJsMessageSetChanged(String string, String string2,
\r
2579 String[] colcommands)
\r
2581 long[] l = jshashes.get(string + "|" + string2);
\r
2582 if (l == null && colcommands != null)
\r
2586 for (int i = 0; i < colcommands.length; i++)
\r
2588 if (l[i] != colcommands[i].hashCode())
\r
2596 private Vector jsExecQueue = new Vector();
\r
2598 public Vector getJsExecQueue()
\r
2600 return jsExecQueue;
\r
2603 public void setExecutor(JSFunctionExec jsFunctionExec2)
\r
2605 jsFunctionExec = jsFunctionExec2;
\r
2609 * return the given colour value parameter or the given default if parameter
\r
2613 * @param defcolour
\r
2616 public Color getDefaultColourParameter(String colparam, Color defcolour)
\r
2618 String colprop = getParameter(colparam);
\r
2619 if (colprop == null || colprop.trim().length() == 0)
\r
2623 Color col = jalview.schemes.ColourSchemeProperty
\r
2624 .getAWTColorFromName(colprop);
\r
2629 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
\r
2630 } catch (Exception ex)
\r
2632 System.err.println("Couldn't parse '" + colprop
\r
2633 + "' as a colour for " + colparam);
\r
2637 return (col == null) ? defcolour : col;
\r
2641 public void openJalviewHelpUrl()
\r
2643 String helpUrl = getParameter("jalviewhelpurl");
\r
2644 if (helpUrl == null || helpUrl.trim().length() < 5)
\r
2646 helpUrl = "http://www.jalview.org/help.html";
\r
2648 showURL(helpUrl, "HELP");
\r
2652 * form a complete URL given a path to a resource and a reference location on
\r
2656 * - an absolute path on the same server as localref or a document
\r
2657 * located relative to localref
\r
2659 * - a URL on the same server as url
\r
2660 * @return a complete URL for the resource located by url
\r
2662 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
\r
2664 String codebase = localref.toString();
\r
2665 if (url.indexOf("/") == 0)
\r
2667 url = codebase.substring(0, codebase.length()
\r
2668 - localref.getFile().length())
\r
2673 url = localref + url;
\r
2679 * open a URL in the browser - resolving it according to relative refs and
\r
2680 * coping with javascript: protocol if necessary.
\r
2685 public void showURL(String url, String target)
\r
2689 if (url.indexOf(":") == -1)
\r
2691 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
\r
2693 // Should really use docbase, not codebase.
\r
2695 url = resolveUrlForLocalOrAbsolute(
\r
2697 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
\r
2702 .println("Show url (prepended "
\r
2704 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
\r
2712 System.err.println("Show url: " + url);
\r
2715 if (url.indexOf("javascript:") == 0)
\r
2717 // no target for the javascript context
\r
2718 getAppletContext().showDocument(new java.net.URL(url));
\r
2722 getAppletContext().showDocument(new java.net.URL(url), target);
\r
2724 } catch (Exception ex)
\r
2726 ex.printStackTrace();
\r
2731 * bind structures in a viewer to any matching sequences in an alignFrame (use
\r
2732 * sequenceIds to limit scope of search to specific sequences)
\r
2736 * @param sequenceIds
\r
2737 * @return TODO: consider making an exception structure for indicating when
\r
2738 * binding fails public SequenceStructureBinding
\r
2739 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
\r
2742 * if (sequenceIds != null && sequenceIds.length() > 0) { return
\r
2743 * alFrame.addStructureViewInstance(viewer,
\r
2744 * separatorListToArray(sequenceIds)); } else { return
\r
2745 * alFrame.addStructureViewInstance(viewer, null); } // return null; }
\r