2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
\r
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.Font;
\r
49 import java.awt.Frame;
\r
50 import java.awt.Graphics;
\r
51 import java.awt.event.ActionEvent;
\r
52 import java.awt.event.WindowAdapter;
\r
53 import java.awt.event.WindowEvent;
\r
54 import java.io.BufferedReader;
\r
55 import java.io.InputStreamReader;
\r
56 import java.net.URL;
\r
57 import java.util.Hashtable;
\r
58 import java.util.StringTokenizer;
\r
59 import java.util.Vector;
\r
61 import netscape.javascript.JSObject;
\r
64 * Jalview Applet. Runs in Java 1.18 runtime
\r
67 * @version $Revision: 1.92 $
\r
69 public class JalviewLite extends Applet implements StructureSelectionManagerProvider, JalviewLiteJsApi
\r
72 // /////////////////////////////////////////
\r
73 // The following public methods maybe called
\r
74 // externally, eg via javascript in HTML page
\r
76 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
\r
78 public String getSelectedSequences()
\r
80 return getSelectedSequencesFrom(getDefaultTargetFrame());
\r
84 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
\r
86 public String getSelectedSequences(String sep)
\r
88 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
\r
92 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui.AlignFrame)
\r
94 public String getSelectedSequencesFrom(AlignFrame alf)
\r
96 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
\r
100 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
102 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
\r
104 StringBuffer result = new StringBuffer("");
\r
105 if (sep == null || sep.length() == 0)
\r
107 sep = separator; // "+0x00AC;
\r
109 if (alf.viewport.getSelectionGroup() != null)
\r
111 SequenceI[] seqs = alf.viewport.getSelectionGroup()
\r
112 .getSequencesInOrder(alf.viewport.getAlignment());
\r
114 for (int i = 0; i < seqs.length; i++)
\r
116 result.append(seqs[i].getName());
\r
117 result.append(sep);
\r
121 return result.toString();
\r
125 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String, java.lang.String, java.lang.String)
\r
127 public void highlight(String sequenceId, String position,
\r
128 String alignedPosition)
\r
130 highlightIn(getDefaultTargetFrame(), sequenceId, position,
\r
135 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
137 public void highlightIn(AlignFrame alf, String sequenceId,
\r
138 String position, String alignedPosition)
\r
140 // TODO: could try to highlight in all alignments if alf==null
\r
141 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
142 alf.viewport.getAlignment().getSequencesArray());
\r
143 SequenceI sq = matcher.findIdMatch(sequenceId);
\r
146 int pos, apos = -1;
\r
149 apos = new Integer(position).intValue();
\r
151 } catch (NumberFormatException ex)
\r
155 // use vamsas listener to broadcast to all listeners in scope
\r
156 if (alignedPosition != null
\r
157 && (alignedPosition.trim().length() == 0 || alignedPosition
\r
158 .toLowerCase().indexOf("false") > -1))
\r
160 StructureSelectionManager.getStructureSelectionManager(this)
\r
161 .mouseOverVamsasSequence(sq, sq.findIndex(apos), null);
\r
165 StructureSelectionManager.getStructureSelectionManager(this)
\r
166 .mouseOverVamsasSequence(sq, apos, null);
\r
173 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String, java.lang.String)
\r
175 public void select(String sequenceIds, String columns)
\r
177 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
\r
181 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String, java.lang.String, java.lang.String)
\r
183 public void select(String sequenceIds, String columns, String sep)
\r
185 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
\r
189 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
191 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
\r
193 selectIn(alf, sequenceIds, columns, separator);
\r
197 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
199 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
\r
202 if (sep == null || sep.length() == 0)
\r
210 System.err.println("Selecting region using separator string '"
\r
211 + separator + "'");
\r
215 String[] ids = separatorListToArray(sequenceIds, sep);
\r
216 String[] cols = separatorListToArray(columns, sep);
\r
217 SequenceGroup sel = new SequenceGroup();
\r
218 ColumnSelection csel = new ColumnSelection();
\r
219 AlignmentI al = alf.viewport.getAlignment();
\r
220 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
221 alf.viewport.getAlignment().getSequencesArray());
\r
222 int start = 0, end = al.getWidth(), alw = al.getWidth();
\r
223 boolean seqsfound = true;
\r
224 if (ids != null && ids.length > 0)
\r
227 for (int i = 0; i < ids.length; i++)
\r
229 if (ids[i].trim().length() == 0)
\r
233 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
237 sel.addSequence(sq, false);
\r
241 boolean inseqpos = false;
\r
242 if (cols != null && cols.length > 0)
\r
244 boolean seset = false;
\r
245 for (int i = 0; i < cols.length; i++)
\r
247 String cl = cols[i].trim();
\r
248 if (cl.length() == 0)
\r
253 if ((p = cl.indexOf("-")) > -1)
\r
255 int from = -1, to = -1;
\r
258 from = new Integer(cl.substring(0, p)).intValue();
\r
260 } catch (NumberFormatException ex)
\r
263 .println("ERROR: Couldn't parse first integer in range element column selection string '"
\r
264 + cl + "' - format is 'from-to'");
\r
269 to = new Integer(cl.substring(p + 1)).intValue();
\r
271 } catch (NumberFormatException ex)
\r
274 .println("ERROR: Couldn't parse second integer in range element column selection string '"
\r
275 + cl + "' - format is 'from-to'");
\r
278 if (from >= 0 && to >= 0)
\r
295 // comment to prevent range extension
\r
305 for (int r = from; r <= to; r++)
\r
307 if (r >= 0 && r < alw)
\r
309 csel.addElement(r);
\r
314 System.err.println("Range '" + cl + "' deparsed as [" + from
\r
320 System.err.println("ERROR: Invalid Range '" + cl
\r
321 + "' deparsed as [" + from + "," + to + "]");
\r
329 r = new Integer(cl).intValue();
\r
331 } catch (NumberFormatException ex)
\r
333 if (cl.toLowerCase().equals("sequence"))
\r
335 // we are in the dataset sequence's coordinate frame.
\r
341 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
\r
346 if (r >= 0 && r <= alw)
\r
356 // comment to prevent range extension
\r
366 csel.addElement(r);
\r
369 System.err.println("Point selection '" + cl
\r
370 + "' deparsed as [" + r + "]");
\r
375 System.err.println("ERROR: Invalid Point selection '" + cl
\r
376 + "' deparsed as [" + r + "]");
\r
383 // we only propagate the selection when it was the null selection, or the
\r
384 // given sequences were found in the alignment.
\r
385 if (inseqpos && sel.getSize() > 0)
\r
387 // assume first sequence provides reference frame ?
\r
388 SequenceI rs = sel.getSequenceAt(0);
\r
389 start = rs.findIndex(start);
\r
390 end = rs.findIndex(end);
\r
393 Vector cs = csel.getSelected();
\r
395 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
\r
397 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
\r
402 sel.setStartRes(start);
\r
403 sel.setEndRes(end);
\r
404 alf.select(sel, csel);
\r
409 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.String, java.lang.String)
\r
411 public String getSelectedSequencesAsAlignment(String format, String suffix)
\r
413 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
\r
418 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
420 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
\r
421 String format, String suffix)
\r
425 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
426 if (alf.viewport.getSelectionGroup() != null)
\r
428 String reply = new AppletFormatAdapter().formatSequences(format,
\r
429 new Alignment(alf.viewport.getSelectionAsNewSequence()),
\r
433 } catch (Exception ex)
\r
435 ex.printStackTrace();
\r
436 return "Error retrieving alignment in " + format + " format. ";
\r
442 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
\r
444 public String getAlignmentOrder()
\r
446 return getAlignmentOrderFrom(getDefaultTargetFrame());
\r
450 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame)
\r
452 public String getAlignmentOrderFrom(AlignFrame alf)
\r
454 return getAlignmentOrderFrom(alf, separator);
\r
458 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
460 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
\r
462 AlignmentI alorder = alf.getAlignViewport().getAlignment();
\r
463 String[] order = new String[alorder.getHeight()];
\r
464 for (int i = 0; i < order.length; i++)
\r
466 order[i] = alorder.getSequenceAt(i).getName();
\r
468 return arrayToSeparatorList(order);
\r
472 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String, java.lang.String)
\r
474 public String orderBy(String order, String undoName)
\r
476 return orderBy(order, undoName, separator);
\r
480 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String, java.lang.String, java.lang.String)
\r
482 public String orderBy(String order, String undoName, String sep)
\r
484 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
\r
488 * @see jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
490 public String orderAlignmentBy(AlignFrame alf, String order,
\r
491 String undoName, String sep)
\r
493 String[] ids = separatorListToArray(order, sep);
\r
494 SequenceI[] sqs = null;
\r
495 if (ids != null && ids.length > 0)
\r
497 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
498 alf.viewport.getAlignment().getSequencesArray());
\r
500 sqs = new SequenceI[ids.length];
\r
501 for (int i = 0; i < ids.length; i++)
\r
503 if (ids[i].trim().length() == 0)
\r
507 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
515 SequenceI[] sqq = new SequenceI[s];
\r
516 System.arraycopy(sqs, 0, sqq, 0, s);
\r
529 AlignmentOrder aorder = new AlignmentOrder(sqs);
\r
531 if (undoName != null && undoName.trim().length() == 0)
\r
536 return alf.sortBy(aorder, undoName) ? "true" : "";
\r
540 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
\r
542 public String getAlignment(String format)
\r
544 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
\r
548 * @see jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
550 public String getAlignmentFrom(AlignFrame alf, String format)
\r
552 return getAlignmentFrom(alf, format, "true");
\r
556 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String, java.lang.String)
\r
558 public String getAlignment(String format, String suffix)
\r
560 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
\r
564 * @see jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
566 public String getAlignmentFrom(AlignFrame alf, String format,
\r
571 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
573 String reply = new AppletFormatAdapter().formatSequences(format,
\r
574 alf.viewport.getAlignment(), seqlimits);
\r
576 } catch (Exception ex)
\r
578 ex.printStackTrace();
\r
579 return "Error retrieving alignment in " + format + " format. ";
\r
584 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
\r
586 public void loadAnnotation(String annotation)
\r
588 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
\r
592 * @see jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
594 public void loadAnnotationFrom(AlignFrame alf, String annotation)
\r
596 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
\r
597 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
\r
599 alf.alignPanel.fontChanged();
\r
600 alf.alignPanel.setScrollValues(0, 0);
\r
604 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
\r
609 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
\r
611 public String getFeatures(String format)
\r
613 return getFeaturesFrom(getDefaultTargetFrame(), format);
\r
617 * @see jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
619 public String getFeaturesFrom(AlignFrame alf, String format)
\r
621 return alf.outputFeatures(false, format);
\r
625 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
\r
627 public String getAnnotation()
\r
629 return getAnnotationFrom(getDefaultTargetFrame());
\r
633 * @see jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame)
\r
635 public String getAnnotationFrom(AlignFrame alf)
\r
637 return alf.outputAnnotations(false);
\r
641 * @see jalview.bin.JalviewLiteJsApi#newView()
\r
643 public AlignFrame newView()
\r
645 return newViewFrom(getDefaultTargetFrame());
\r
649 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
\r
651 public AlignFrame newView(String name)
\r
653 return newViewFrom(getDefaultTargetFrame(), name);
\r
657 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
\r
659 public AlignFrame newViewFrom(AlignFrame alf)
\r
661 return alf.newView(null);
\r
665 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
667 public AlignFrame newViewFrom(AlignFrame alf, String name)
\r
669 return alf.newView(name);
\r
673 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String, java.lang.String)
\r
675 public AlignFrame loadAlignment(String text, String title)
\r
677 Alignment al = null;
\r
679 String format = new IdentifyFile().Identify(text,
\r
680 AppletFormatAdapter.PASTE);
\r
683 al = new AppletFormatAdapter().readFile(text,
\r
684 AppletFormatAdapter.PASTE, format);
\r
685 if (al.getHeight() > 0)
\r
687 return new AlignFrame(al, this, title, false);
\r
689 } catch (java.io.IOException ex)
\r
691 ex.printStackTrace();
\r
697 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
\r
699 public void setMouseoverListener(String listener)
\r
701 setMouseoverListener(currentAlignFrame, listener);
\r
704 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
\r
707 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
709 public void setMouseoverListener(AlignFrame af, String listener)
\r
711 if (listener != null)
\r
713 listener = listener.trim();
\r
714 if (listener.length() == 0)
\r
717 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
\r
721 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
\r
722 this, af, listener);
\r
723 javascriptListeners.addElement(mol);
\r
724 StructureSelectionManager.getStructureSelectionManager(this)
\r
725 .addStructureViewerListener(mol);
\r
728 System.err.println("Added a mouseover listener for "
\r
729 + ((af == null) ? "All frames" : "Just views for "
\r
730 + af.getAlignViewport().getSequenceSetId()));
\r
731 System.err.println("There are now " + javascriptListeners.size()
\r
732 + " listeners in total.");
\r
737 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
\r
739 public void setSelectionListener(String listener)
\r
741 setSelectionListener(null, listener);
\r
745 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
747 public void setSelectionListener(AlignFrame af, String listener)
\r
749 if (listener != null)
\r
751 listener = listener.trim();
\r
752 if (listener.length() == 0)
\r
755 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
759 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
\r
760 this, af, listener);
\r
761 javascriptListeners.addElement(mol);
\r
762 StructureSelectionManager.getStructureSelectionManager(this)
\r
763 .addSelectionListener(mol);
\r
766 System.err.println("Added a selection listener for "
\r
767 + ((af == null) ? "All frames" : "Just views for "
\r
768 + af.getAlignViewport().getSequenceSetId()));
\r
769 System.err.println("There are now " + javascriptListeners.size()
\r
770 + " listeners in total.");
\r
775 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String, java.lang.String)
\r
777 public void setStructureListener(String listener, String modelSet)
\r
779 if (listener != null)
\r
781 listener = listener.trim();
\r
782 if (listener.length() == 0)
\r
785 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
789 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
\r
790 this, listener, separatorListToArray(modelSet));
\r
791 javascriptListeners.addElement(mol);
\r
792 StructureSelectionManager.getStructureSelectionManager(this)
\r
793 .addStructureViewerListener(mol);
\r
796 System.err.println("Added a javascript structure viewer listener '"
\r
798 System.err.println("There are now " + javascriptListeners.size()
\r
799 + " listeners in total.");
\r
804 * @see jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
806 public void removeJavascriptListener(AlignFrame af, String listener)
\r
808 if (listener != null)
\r
810 listener = listener.trim();
\r
811 if (listener.length() == 0)
\r
816 boolean rprt = false;
\r
817 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
\r
819 Object lstn = javascriptListeners.elementAt(ms);
\r
820 JsCallBack lstner = (JsCallBack) lstn;
\r
821 if ((af == null || lstner.getAlignFrame() == af)
\r
822 && (listener == null || lstner.getListenerFunction().equals(
\r
825 javascriptListeners.removeElement(lstner);
\r
827 if (lstner instanceof SelectionListener)
\r
829 StructureSelectionManager.getStructureSelectionManager(this)
\r
830 .removeSelectionListener((SelectionListener) lstner);
\r
834 StructureSelectionManager.getStructureSelectionManager(this)
\r
835 .removeStructureViewerListener(lstner, null);
\r
840 System.err.println("Removed listener '" + listener + "'");
\r
850 System.err.println("There are now " + javascriptListeners.size()
\r
851 + " listeners in total.");
\r
857 System.err.println("Applet "+getName()+" stop().");
\r
860 public void destroy()
\r
862 System.err.println("Applet "+getName()+" destroy().");
\r
865 private void tidyUp()
\r
868 if (currentAlignFrame!=null && currentAlignFrame.viewport!=null
\r
869 && currentAlignFrame.viewport.applet!=null)
\r
871 AlignViewport av = currentAlignFrame.viewport;
\r
872 currentAlignFrame.closeMenuItem_actionPerformed();
\r
874 currentAlignFrame=null;
\r
876 if (javascriptListeners != null)
\r
878 while (javascriptListeners.size() > 0)
\r
880 jalview.javascript.JSFunctionExec mol = javascriptListeners.elementAt(0);
\r
881 javascriptListeners.removeElement(mol);
\r
882 if (mol instanceof SelectionListener)
\r
884 StructureSelectionManager.getStructureSelectionManager(this)
\r
885 .removeSelectionListener((SelectionListener) mol);
\r
889 StructureSelectionManager.getStructureSelectionManager(this)
\r
890 .removeStructureViewerListener(mol, null);
\r
895 if (jsFunctionExec!=null) {
\r
896 jsFunctionExec.stopQueue();
\r
897 jsFunctionExec.jvlite=null;
\r
899 initialAlignFrame=null;
\r
900 jsFunctionExec = null;
\r
901 javascriptListeners=null;
\r
902 StructureSelectionManager.release(this);
\r
904 private jalview.javascript.JSFunctionExec jsFunctionExec;
\r
906 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String, java.lang.String, java.lang.String)
\r
908 public void mouseOverStructure(String pdbResNum, String chain,
\r
913 StructureSelectionManager.getStructureSelectionManager(this)
\r
914 .mouseOverStructure(new Integer(pdbResNum).intValue(), chain,
\r
918 System.err.println("mouseOver for '" + pdbResNum + "' in chain '"
\r
919 + chain + "' in structure '" + pdbfile + "'");
\r
921 } catch (NumberFormatException e)
\r
923 System.err.println("Ignoring invalid residue number string '"
\r
924 + pdbResNum + "'");
\r
928 * @see jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
930 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
\r
933 alf.scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue());
\r
935 } catch (Exception ex)
\r
937 System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"' and leftHandColumn='"+leftHandColumn+"'");
\r
938 ex.printStackTrace();
\r
942 // //////////////////////////////////////////////
\r
943 // //////////////////////////////////////////////
\r
945 public static int lastFrameX = 200;
\r
947 public static int lastFrameY = 200;
\r
949 boolean fileFound = true;
\r
951 String file = "No file";
\r
953 Button launcher = new Button("Start Jalview");
\r
956 * The currentAlignFrame is static, it will change if and when the user
\r
957 * selects a new window. Note that it will *never* point back to the embedded
\r
958 * AlignFrame if the applet is started as embedded on the page and then
\r
959 * afterwards a new view is created.
\r
961 public AlignFrame currentAlignFrame = null;
\r
964 * This is the first frame to be displayed, and does not change. API calls
\r
965 * will default to this instance if currentAlignFrame is null.
\r
967 AlignFrame initialAlignFrame = null;
\r
969 boolean embedded = false;
\r
971 private boolean checkForJmol = true;
\r
973 private boolean checkedForJmol = false; // ensure we don't check for jmol
\r
975 // every time the app is re-inited
\r
977 public boolean jmolAvailable = false;
\r
979 private boolean alignPdbStructures = false;
\r
982 * use an external structure viewer exclusively (no jmols or MCViews will be
\r
983 * opened by JalviewLite itself)
\r
985 public boolean useXtrnalSviewer = false;
\r
987 public static boolean debug = false;
\r
989 static String builddate = null, version = null;
\r
991 private static void initBuildDetails()
\r
993 if (builddate == null)
\r
995 builddate = "unknown";
\r
997 java.net.URL url = JalviewLite.class
\r
998 .getResource("/.build_properties");
\r
1003 BufferedReader reader = new BufferedReader(new InputStreamReader(
\r
1004 url.openStream()));
\r
1006 while ((line = reader.readLine()) != null)
\r
1008 if (line.indexOf("VERSION") > -1)
\r
1010 version = line.substring(line.indexOf("=") + 1);
\r
1012 if (line.indexOf("BUILD_DATE") > -1)
\r
1014 builddate = line.substring(line.indexOf("=") + 1);
\r
1017 } catch (Exception ex)
\r
1019 ex.printStackTrace();
\r
1025 public static String getBuildDate()
\r
1027 initBuildDetails();
\r
1031 public static String getVersion()
\r
1033 initBuildDetails();
\r
1037 // public JSObject scriptObject = null;
\r
1040 * init method for Jalview Applet
\r
1042 public void init()
\r
1044 // remove any handlers that might be hanging around from an earlier instance
\r
1049 System.err.println("Applet context is '"
\r
1050 + getAppletContext().getClass().toString() + "'");
\r
1052 JSObject scriptObject = JSObject.getWindow(this);
\r
1053 if (debug && scriptObject != null)
\r
1055 System.err.println("Applet has Javascript callback support.");
\r
1058 } catch (Exception ex)
\r
1061 .println("Warning: No JalviewLite javascript callbacks available.");
\r
1064 ex.printStackTrace();
\r
1068 * turn on extra applet debugging
\r
1070 String dbg = getParameter("debug");
\r
1073 debug = dbg.toLowerCase().equals("true");
\r
1078 System.err.println("JalviewLite Version " + getVersion());
\r
1079 System.err.println("Build Date : " + getBuildDate());
\r
1082 String externalsviewer = getParameter("externalstructureviewer");
\r
1083 if (externalsviewer != null)
\r
1085 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
\r
1089 * if true disable the check for jmol
\r
1091 String chkforJmol = getParameter("nojmol");
\r
1092 if (chkforJmol != null)
\r
1094 checkForJmol = !chkforJmol.equals("true");
\r
1097 * get the separator parameter if present
\r
1099 String sep = getParameter("separator");
\r
1102 if (sep.length() > 0)
\r
1107 System.err.println("Separator set to '" + separator + "'");
\r
1113 "Invalid separator parameter - must be non-zero length");
\r
1119 String param = getParameter("RGB");
\r
1121 if (param != null)
\r
1125 r = Integer.parseInt(param.substring(0, 2), 16);
\r
1126 g = Integer.parseInt(param.substring(2, 4), 16);
\r
1127 b = Integer.parseInt(param.substring(4, 6), 16);
\r
1128 } catch (Exception ex)
\r
1135 param = getParameter("label");
\r
1136 if (param != null)
\r
1138 launcher.setLabel(param);
\r
1141 setBackground(new Color(r, g, b));
\r
1143 file = getParameter("file");
\r
1147 // Maybe the sequences are added as parameters
\r
1148 StringBuffer data = new StringBuffer("PASTE");
\r
1150 while ((file = getParameter("sequence" + i)) != null)
\r
1152 data.append(file.toString() + "\n");
\r
1155 if (data.length() > 5)
\r
1157 file = data.toString();
\r
1161 final JalviewLite jvapplet = this;
\r
1162 if (getParameter("embedded") != null
\r
1163 && getParameter("embedded").equalsIgnoreCase("true"))
\r
1165 // Launch as embedded applet in page
\r
1167 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1170 else if (file != null)
\r
1172 if (getParameter("showbutton") == null
\r
1173 || !getParameter("showbutton").equalsIgnoreCase("false"))
\r
1175 // Add the JalviewLite 'Button' to the page
\r
1177 launcher.addActionListener(new java.awt.event.ActionListener()
\r
1179 public void actionPerformed(ActionEvent e)
\r
1181 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1188 // Open jalviewLite immediately.
\r
1189 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1195 // jalview initialisation with no alignment. loadAlignment() method can
\r
1196 // still be called to open new alignments.
\r
1198 fileFound = false;
\r
1199 // callInitCallback();
\r
1203 private void callInitCallback()
\r
1205 String initjscallback = getParameter("oninit");
\r
1206 if (initjscallback == null)
\r
1210 initjscallback = initjscallback.trim();
\r
1211 if (initjscallback.length() > 0)
\r
1213 JSObject scriptObject = null;
\r
1216 scriptObject = JSObject.getWindow(this);
\r
1217 } catch (Exception ex)
\r
1221 if (scriptObject != null)
\r
1225 // do onInit with the JS executor thread
\r
1226 new JSFunctionExec(this).executeJavascriptFunction(true,
\r
1227 initjscallback, null, "Calling oninit callback '"
\r
1228 + initjscallback + "'.");
\r
1229 } catch (Exception e)
\r
1231 System.err.println("Exception when executing _oninit callback '"
\r
1232 + initjscallback + "'.");
\r
1233 e.printStackTrace();
\r
1238 System.err.println("Not executing _oninit callback '"
\r
1239 + initjscallback + "' - no scripting allowed.");
\r
1245 * Initialises and displays a new java.awt.Frame
\r
1248 * java.awt.Frame to be displayed
\r
1250 * title of new frame
\r
1252 * width if new frame
\r
1254 * height of new frame
\r
1256 public static void addFrame(final Frame frame, String title, int width,
\r
1259 frame.setLocation(lastFrameX, lastFrameY);
\r
1262 frame.setSize(width, height);
\r
1263 frame.setTitle(title);
\r
1264 frame.addWindowListener(new WindowAdapter()
\r
1266 public void windowClosing(WindowEvent e)
\r
1268 if (frame instanceof AlignFrame)
\r
1270 AlignViewport vp = ((AlignFrame) frame).viewport;
\r
1271 ((AlignFrame) frame).closeMenuItem_actionPerformed();
\r
1272 if (vp.applet.currentAlignFrame == frame)
\r
1274 vp.applet.currentAlignFrame = null;
\r
1282 if (frame instanceof EmbmenuFrame)
\r
1284 ((EmbmenuFrame) frame).destroyMenus();
\r
1286 frame.setMenuBar(null);
\r
1290 public void windowActivated(WindowEvent e)
\r
1292 if (frame instanceof AlignFrame)
\r
1294 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
\r
1297 System.err.println("Activated window " + frame);
\r
1301 super.windowActivated(e);
\r
1304 * Probably not necessary to do this - see TODO above. (non-Javadoc)
\r
1307 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
\r
1310 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
\r
1311 * frame) { currentAlignFrame = null; if (debug) {
\r
1312 * System.err.println("Deactivated window "+frame); } }
\r
1313 * super.windowDeactivated(e); }
\r
1316 frame.setVisible(true);
\r
1320 * This paints the background surrounding the "Launch Jalview button" <br>
\r
1322 * If file given in parameter not found, displays error message
\r
1325 * graphics context
\r
1327 public void paint(Graphics g)
\r
1331 g.setColor(new Color(200, 200, 200));
\r
1332 g.setColor(Color.cyan);
\r
1333 g.fillRect(0, 0, getSize().width, getSize().height);
\r
1334 g.setColor(Color.red);
\r
1335 g.drawString("Jalview can't open file", 5, 15);
\r
1336 g.drawString("\"" + file + "\"", 5, 30);
\r
1338 else if (embedded)
\r
1340 g.setColor(Color.black);
\r
1341 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
1342 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
\r
1343 g.drawString("Loading Data...", 50, getSize().height / 2);
\r
1348 * get all components associated with the applet of the given type
\r
1353 public Vector getAppletWindow(Class class1)
\r
1355 Vector wnds = new Vector();
\r
1356 Component[] cmp = getComponents();
\r
1359 for (int i = 0; i < cmp.length; i++)
\r
1361 if (class1.isAssignableFrom(cmp[i].getClass()))
\r
1363 wnds.addElement(cmp);
\r
1370 class LoadJmolThread extends Thread
\r
1372 private boolean running = false;
\r
1376 if (running || checkedForJmol)
\r
1385 if (!System.getProperty("java.version").startsWith("1.1"))
\r
1387 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
\r
1388 jmolAvailable = true;
\r
1390 if (!jmolAvailable)
\r
1393 .println("Jmol not available - Using MCview for structures");
\r
1395 } catch (java.lang.ClassNotFoundException ex)
\r
1401 jmolAvailable = false;
\r
1405 .println("Skipping Jmol check. Will use MCView (probably)");
\r
1408 checkedForJmol = true;
\r
1412 public boolean notFinished()
\r
1414 return running || !checkedForJmol;
\r
1418 class LoadingThread extends Thread
\r
1421 * State variable: File source
\r
1426 * State variable: protocol for access to file source
\r
1431 * State variable: format of file source
\r
1437 JalviewLite applet;
\r
1439 private void dbgMsg(String msg)
\r
1443 System.err.println(msg);
\r
1448 * update the protocol state variable for accessing the datasource located
\r
1452 * @return possibly updated datasource string
\r
1454 public String setProtocolState(String file)
\r
1456 if (file.startsWith("PASTE"))
\r
1458 file = file.substring(5);
\r
1459 protocol = AppletFormatAdapter.PASTE;
\r
1461 else if (inArchive(file))
\r
1463 protocol = AppletFormatAdapter.CLASSLOADER;
\r
1467 file = addProtocol(file);
\r
1468 protocol = AppletFormatAdapter.URL;
\r
1470 dbgMsg("Protocol identified as '" + protocol + "'");
\r
1474 public LoadingThread(String _file, JalviewLite _applet)
\r
1476 this._file = _file;
\r
1482 LoadJmolThread jmolchecker = new LoadJmolThread();
\r
1483 jmolchecker.start();
\r
1484 while (jmolchecker.notFinished())
\r
1486 // wait around until the Jmol check is complete.
\r
1490 } catch (Exception e)
\r
1496 // applet.callInitCallback();
\r
1499 private void startLoading()
\r
1501 AlignFrame newAlignFrame;
\r
1502 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
\r
1503 file = setProtocolState(_file);
\r
1505 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
1506 dbgMsg("File identified as '" + format + "'");
\r
1507 dbgMsg("Loading started.");
\r
1508 Alignment al = null;
\r
1511 al = new AppletFormatAdapter().readFile(file, protocol, format);
\r
1512 } catch (java.io.IOException ex)
\r
1514 dbgMsg("File load exception.");
\r
1515 ex.printStackTrace();
\r
1520 FileParse fp = new FileParse(file, protocol);
\r
1522 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
\r
1523 + protocol + ")");
\r
1524 while ((ln = fp.nextLine()) != null)
\r
1528 dbgMsg(">>>Dump finished.");
\r
1529 } catch (Exception e)
\r
1532 .println("Exception when trying to dump the content of the file parameter.");
\r
1533 e.printStackTrace();
\r
1537 if ((al != null) && (al.getHeight() > 0))
\r
1539 dbgMsg("Successfully loaded file.");
\r
1540 newAlignFrame = new AlignFrame(al, applet, file, embedded);
\r
1541 if (initialAlignFrame == null)
\r
1543 initialAlignFrame = newAlignFrame;
\r
1545 // update the focus.
\r
1546 currentAlignFrame = newAlignFrame;
\r
1548 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
\r
1550 newAlignFrame.setTitle("Sequences from "
\r
1551 + applet.getDocumentBase());
\r
1554 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
1556 String treeFile = applet.getParameter("tree");
\r
1557 if (treeFile == null)
\r
1559 treeFile = applet.getParameter("treeFile");
\r
1562 if (treeFile != null)
\r
1566 treeFile = setProtocolState(treeFile);
\r
1568 * if (inArchive(treeFile)) { protocol =
\r
1569 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
\r
1570 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
\r
1572 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
\r
1577 if (fin.getTree() != null)
\r
1579 newAlignFrame.loadTree(fin, treeFile);
\r
1580 dbgMsg("Successfuly imported tree.");
\r
1584 dbgMsg("Tree parameter did not resolve to a valid tree.");
\r
1586 } catch (Exception ex)
\r
1588 ex.printStackTrace();
\r
1592 String param = applet.getParameter("features");
\r
1593 if (param != null)
\r
1595 param = setProtocolState(param);
\r
1597 newAlignFrame.parseFeaturesFile(param, protocol);
\r
1600 param = applet.getParameter("showFeatureSettings");
\r
1601 if (param != null && param.equalsIgnoreCase("true"))
\r
1603 newAlignFrame.viewport.showSequenceFeatures(true);
\r
1604 new FeatureSettings(newAlignFrame.alignPanel);
\r
1607 param = applet.getParameter("annotations");
\r
1608 if (param != null)
\r
1610 param = setProtocolState(param);
\r
1612 if (new AnnotationFile().readAnnotationFile(
\r
1613 newAlignFrame.viewport.getAlignment(), param, protocol))
\r
1615 newAlignFrame.alignPanel.fontChanged();
\r
1616 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1621 .println("Annotations were not added from annotation file '"
\r
1627 param = applet.getParameter("jnetfile");
\r
1628 if (param != null)
\r
1632 param = setProtocolState(param);
\r
1633 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
\r
1635 JnetAnnotationMaker.add_annotation(predictions,
\r
1636 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
\r
1644 newAlignFrame.alignPanel.fontChanged();
\r
1645 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1646 } catch (Exception ex)
\r
1648 ex.printStackTrace();
\r
1652 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
\r
1653 * - related to JAL-434
\r
1655 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
\r
1658 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
\r
1659 * PDB|1GAQ|1GAQ|C">
\r
1661 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
\r
1663 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
\r
1666 int pdbFileCount = 0;
\r
1667 // Accumulate pdbs here if they are heading for the same view (if
\r
1668 // alignPdbStructures is true)
\r
1669 Vector pdbs = new Vector();
\r
1670 // create a lazy matcher if we're asked to
\r
1671 jalview.analysis.SequenceIdMatcher matcher = (applet
\r
1672 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
\r
1673 newAlignFrame.getAlignViewport().getAlignment()
\r
1674 .getSequencesArray()) : null;
\r
1678 if (pdbFileCount > 0)
\r
1680 param = applet.getParameter("PDBFILE" + pdbFileCount);
\r
1684 param = applet.getParameter("PDBFILE");
\r
1687 if (param != null)
\r
1689 PDBEntry pdb = new PDBEntry();
\r
1692 SequenceI[] seqs = null;
\r
1693 String[] chains = null;
\r
1695 StringTokenizer st = new StringTokenizer(param, " ");
\r
1697 if (st.countTokens() < 2)
\r
1699 String sequence = applet.getParameter("PDBSEQ");
\r
1700 if (sequence != null)
\r
1701 seqs = new SequenceI[]
\r
1702 { matcher == null ? (Sequence) newAlignFrame
\r
1703 .getAlignViewport().getAlignment()
\r
1704 .findName(sequence) : matcher.findIdMatch(sequence) };
\r
1709 param = st.nextToken();
\r
1710 Vector tmp = new Vector();
\r
1711 Vector tmp2 = new Vector();
\r
1713 while (st.hasMoreTokens())
\r
1715 seqstring = st.nextToken();
\r
1716 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
\r
1717 if (st2.countTokens() > 1)
\r
1719 // This is the chain
\r
1720 tmp2.addElement(st2.nextToken());
\r
1721 seqstring = st2.nextToken();
\r
1723 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
\r
1724 .getAlignViewport().getAlignment()
\r
1725 .findName(seqstring) : matcher
\r
1726 .findIdMatch(seqstring));
\r
1729 seqs = new SequenceI[tmp.size()];
\r
1730 tmp.copyInto(seqs);
\r
1731 if (tmp2.size() == tmp.size())
\r
1733 chains = new String[tmp2.size()];
\r
1734 tmp2.copyInto(chains);
\r
1737 param = setProtocolState(param);
\r
1739 if (// !jmolAvailable
\r
1741 protocol == AppletFormatAdapter.CLASSLOADER
\r
1742 && !useXtrnalSviewer)
\r
1744 // Re: JAL-357 : the bug isn't a problem if we are using an
\r
1745 // external viewer!
\r
1746 // TODO: verify this Re:
\r
1747 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
\r
1748 // This exception preserves the current behaviour where, even if
\r
1749 // the local pdb file was identified in the class loader
\r
1750 protocol = AppletFormatAdapter.URL; // this is probably NOT
\r
1752 param = addProtocol(param); //
\r
1755 pdb.setFile(param);
\r
1759 for (int i = 0; i < seqs.length; i++)
\r
1761 if (seqs[i] != null)
\r
1763 ((Sequence) seqs[i]).addPDBId(pdb);
\r
1767 if (JalviewLite.debug)
\r
1769 // this may not really be a problem but we give a warning
\r
1772 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
\r
1778 if (!alignPdbStructures)
\r
1780 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
\r
1785 pdbs.addElement(new Object[]
\r
1786 { pdb, seqs, chains, new String(protocol) });
\r
1792 } while (param != null || pdbFileCount < 10);
\r
1793 if (pdbs.size() > 0)
\r
1795 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
\r
1796 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
\r
1797 String[][] chains = new String[pdbs.size()][];
\r
1798 String[] protocols = new String[pdbs.size()];
\r
1799 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
\r
1801 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
\r
1802 pdb[pdbsi] = (PDBEntry) o[0];
\r
1803 seqs[pdbsi] = (SequenceI[]) o[1];
\r
1804 chains[pdbsi] = (String[]) o[2];
\r
1805 protocols[pdbsi] = (String) o[3];
\r
1807 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
\r
1811 // ///////////////////////////
\r
1812 // modify display of features
\r
1814 // hide specific groups
\r
1815 param = applet.getParameter("hidefeaturegroups");
\r
1816 if (param != null)
\r
1818 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
\r
1820 // show specific groups
\r
1821 param = applet.getParameter("showfeaturegroups");
\r
1822 if (param != null)
\r
1824 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
\r
1829 fileFound = false;
\r
1830 applet.remove(launcher);
\r
1833 callInitCallback();
\r
1837 * Discovers whether the given file is in the Applet Archive
\r
1843 boolean inArchive(String file)
\r
1845 // This might throw a security exception in certain browsers
\r
1846 // Netscape Communicator for instance.
\r
1849 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
\r
1852 System.err.println("Resource '" + file + "' was "
\r
1853 + (rtn ? "" : "not") + " located by classloader.");
\r
1856 } catch (Exception ex)
\r
1858 System.out.println("Exception checking resources: " + file + " "
\r
1864 String addProtocol(String file)
\r
1866 if (file.indexOf("://") == -1)
\r
1868 String fl = applet.resolveUrlForLocalOrAbsolute(file, getDocumentBase());
\r
1871 if (new java.net.URL(fl).openStream() != null)
\r
1875 System.err.println("Prepended document base for resource: '"
\r
1880 } catch (Exception x)
\r
1884 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
\r
1887 if (new java.net.URL(fl).openStream() != null)
\r
1891 System.err.println("Prepended codebase for resource: '"
\r
1896 } catch (Exception x)
\r
1908 * @return the default alignFrame acted on by the public applet methods. May
\r
1909 * return null with an error message on System.err indicating the
\r
1912 public AlignFrame getDefaultTargetFrame()
\r
1914 if (currentAlignFrame != null)
\r
1916 return currentAlignFrame;
\r
1918 if (initialAlignFrame != null)
\r
1920 return initialAlignFrame;
\r
1923 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
\r
1928 * separator used for separatorList
\r
1930 protected String separator = "" + ((char) 0x00AC); // the default used to be
\r
1931 // '|' but many sequence
\r
1932 // IDS include pipes.
\r
1935 * set to enable the URL based javascript execution mechanism
\r
1937 public boolean jsfallbackEnabled=false;
\r
1940 * parse the string into a list
\r
1943 * @return elements separated by separator
\r
1945 public String[] separatorListToArray(String list)
\r
1947 return separatorListToArray(list, separator);
\r
1951 * parse the string into a list
\r
1954 * @param separator
\r
1955 * @return elements separated by separator
\r
1957 public String[] separatorListToArray(String list, String separator)
\r
1959 // note separator local variable intentionally masks object field
\r
1960 int seplen = separator.length();
\r
1961 if (list == null || list.equals("") || list.equals(separator))
\r
1963 java.util.Vector jv = new Vector();
\r
1965 while ((pos = list.indexOf(separator, cp)) > cp)
\r
1967 jv.addElement(list.substring(cp, pos));
\r
1968 cp = pos + seplen;
\r
1970 if (cp < list.length())
\r
1972 String c = list.substring(cp);
\r
1973 if (!c.equals(separator))
\r
1978 if (jv.size() > 0)
\r
1980 String[] v = new String[jv.size()];
\r
1981 for (int i = 0; i < v.length; i++)
\r
1983 v[i] = (String) jv.elementAt(i);
\r
1985 jv.removeAllElements();
\r
1988 System.err.println("Array from '" + separator
\r
1989 + "' separated List:\n" + v.length);
\r
1990 for (int i = 0; i < v.length; i++)
\r
1992 System.err.println("item " + i + " '" + v[i] + "'");
\r
1999 System.err.println("Empty Array from '" + separator
\r
2000 + "' separated List");
\r
2006 * concatenate the list with separator
\r
2009 * @return concatenated string
\r
2011 public String arrayToSeparatorList(String[] list)
\r
2013 return arrayToSeparatorList(list, separator);
\r
2017 * concatenate the list with separator
\r
2020 * @param separator
\r
2021 * @return concatenated string
\r
2023 public String arrayToSeparatorList(String[] list, String separator)
\r
2025 StringBuffer v = new StringBuffer();
\r
2026 if (list != null && list.length > 0)
\r
2028 for (int i = 0, iSize = list.length; i < iSize; i++)
\r
2030 if (list[i] != null)
\r
2034 v.append(separator);
\r
2036 v.append(list[i]);
\r
2041 System.err.println("Returning '" + separator
\r
2042 + "' separated List:\n");
\r
2043 System.err.println(v);
\r
2045 return v.toString();
\r
2049 System.err.println("Returning empty '" + separator
\r
2050 + "' separated List\n");
\r
2052 return "" + separator;
\r
2056 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
\r
2058 public String getFeatureGroups()
\r
2060 String lst = arrayToSeparatorList(getDefaultTargetFrame()
\r
2061 .getFeatureGroups());
\r
2066 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame)
\r
2068 public String getFeatureGroupsOn(AlignFrame alf)
\r
2070 String lst = arrayToSeparatorList(alf.getFeatureGroups());
\r
2075 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
\r
2077 public String getFeatureGroupsOfState(boolean visible)
\r
2079 return arrayToSeparatorList(getDefaultTargetFrame()
\r
2080 .getFeatureGroupsOfState(visible));
\r
2084 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui.AlignFrame, boolean)
\r
2086 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
\r
2088 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
\r
2092 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.AlignFrame, java.lang.String, boolean)
\r
2094 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
\r
2097 boolean st = state;// !(state==null || state.equals("") ||
\r
2098 // state.toLowerCase().equals("false"));
\r
2099 alf.setFeatureGroupState(separatorListToArray(groups), st);
\r
2103 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String, boolean)
\r
2105 public void setFeatureGroupState(String groups, boolean state)
\r
2107 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
\r
2111 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
\r
2113 public String getSeparator()
\r
2119 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
\r
2121 public void setSeparator(String separator)
\r
2123 if (separator == null || separator.length() < 1)
\r
2125 // reset to default
\r
2126 separator = "" + ((char) 0x00AC);
\r
2128 this.separator = separator;
\r
2131 System.err.println("Default Separator now: '" + separator + "'");
\r
2136 * get boolean value of applet parameter 'name' and return default if
\r
2137 * parameter is not set
\r
2140 * name of paremeter
\r
2142 * the value to return otherwise
\r
2143 * @return true or false
\r
2145 public boolean getDefaultParameter(String name, boolean def)
\r
2148 if ((stn = getParameter(name)) == null)
\r
2152 if (stn.toLowerCase().equals("true"))
\r
2160 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
2162 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
\r
2163 String pdbEntryString, String pdbFile)
\r
2165 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
\r
2168 protected void setAlignPdbStructures(boolean alignPdbStructures)
\r
2170 this.alignPdbStructures = alignPdbStructures;
\r
2173 public boolean isAlignPdbStructures()
\r
2175 return alignPdbStructures;
\r
2178 public void start()
\r
2180 // callInitCallback();
\r
2182 private Hashtable<String,long[]> jshashes=new Hashtable<String,long[]>();
\r
2183 private Hashtable<String,Hashtable<String,String[]>> jsmessages=new Hashtable<String,Hashtable<String,String[]>>();
\r
2184 public void setJsMessageSet(String messageclass, String viewId,
\r
2185 String[] colcommands)
\r
2187 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2190 msgset=new Hashtable<String,String[]>();
\r
2191 jsmessages.put(messageclass, msgset);
\r
2193 msgset.put(viewId, colcommands);
\r
2194 long[] l = new long[colcommands.length];
\r
2195 for (int i=0;i<colcommands.length;i++) { l[i] = colcommands[i].hashCode();}
\r
2196 jshashes.put(messageclass+"|"+viewId,l);
\r
2199 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String, java.lang.String)
\r
2201 public String getJsMessage(String messageclass, String viewId)
\r
2203 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2206 String[] msgs = msgset.get(viewId);
\r
2209 for (int i=0;i<msgs.length;i++) {
\r
2210 if (msgs[i]!=null) {
\r
2211 String m = msgs[i];
\r
2221 public boolean isJsMessageSetChanged(String string, String string2,
\r
2222 String[] colcommands)
\r
2224 long[] l=jshashes.get(string+"|"+string2);
\r
2225 if (l==null && colcommands!=null)
\r
2229 for (int i=0;i<colcommands.length;i++) { if (l[i] != colcommands[i].hashCode()) { return true; }}
\r
2233 private Vector jsExecQueue=new Vector();
\r
2234 public Vector getJsExecQueue()
\r
2236 return jsExecQueue;
\r
2239 public void setExecutor(JSFunctionExec jsFunctionExec2)
\r
2241 jsFunctionExec=jsFunctionExec2;
\r
2245 * return the given colour value parameter or the given default if parameter not given
\r
2247 * @param defcolour
\r
2250 public Color getDefaultColourParameter(String colparam, Color defcolour)
\r
2252 String colprop = getParameter(colparam);
\r
2253 if (colprop==null || colprop.trim().length()==0)
\r
2257 Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
\r
2261 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
\r
2262 } catch (Exception ex)
\r
2264 System.err.println("Couldn't parse '"+colprop+"' as a colour for "+colparam);
\r
2268 return (col==null) ? defcolour: col;
\r
2272 public void openJalviewHelpUrl()
\r
2274 String helpUrl=getParameter("jalviewhelpurl");
\r
2275 if (helpUrl==null || helpUrl.trim().length()<5)
\r
2277 helpUrl="http://www.jalview.org/help.html";
\r
2279 showURL(helpUrl, "HELP");
\r
2283 * form a complete URL given a path to a resource and a reference location on the same server
\r
2284 * @param url - an absolute path on the same server as localref or a document located relative to localref
\r
2285 * @param localref - a URL on the same server as url
\r
2286 * @return a complete URL for the resource located by url
\r
2288 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
\r
2290 String codebase = localref.toString();
\r
2291 if (url.indexOf("/") == 0)
\r
2293 url = codebase.substring(0, codebase.length()
\r
2294 - localref.getFile().length())
\r
2299 url = localref + url;
\r
2305 * open a URL in the browser - resolving it according to relative refs and coping with javascript: protocol if necessary.
\r
2309 public void showURL(String url, String target)
\r
2313 if (url.indexOf(":") == -1)
\r
2315 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
\r
2317 // Should really use docbase, not codebase.
\r
2319 url = resolveUrlForLocalOrAbsolute(url, prepend=getDefaultParameter("resolvetocodebase", false) ? getDocumentBase() : getCodeBase());
\r
2321 System.err.println("Show url (prepended "+prepend+" - toggle resolvetocodebase if code/docbase resolution is wrong): " + url);
\r
2327 System.err.println("Show url: " + url);
\r
2330 if (url.indexOf("javascript:") == 0)
\r
2332 // no target for the javascript context
\r
2333 getAppletContext().showDocument(
\r
2334 new java.net.URL(url));
\r
2338 getAppletContext().showDocument(
\r
2339 new java.net.URL(url), target);
\r
2341 } catch (Exception ex)
\r
2343 ex.printStackTrace();
\r
2348 * bind structures in a viewer to any matching sequences in an alignFrame (use
\r
2349 * sequenceIds to limit scope of search to specific sequences)
\r
2353 * @param sequenceIds
\r
2354 * @return TODO: consider making an exception structure for indicating when
\r
2355 * binding fails public SequenceStructureBinding
\r
2356 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
\r
2359 * if (sequenceIds != null && sequenceIds.length() > 0) { return
\r
2360 * alFrame.addStructureViewInstance(viewer,
\r
2361 * separatorListToArray(sequenceIds)); } else { return
\r
2362 * alFrame.addStructureViewInstance(viewer, null); } // return null; }
\r