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 public StructureSelectionManager getStructureSelectionManager()
\r
74 return StructureSelectionManager.getStructureSelectionManager(this);
\r
76 // /////////////////////////////////////////
\r
77 // The following public methods maybe called
\r
78 // externally, eg via javascript in HTML page
\r
80 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
\r
82 public String getSelectedSequences()
\r
84 return getSelectedSequencesFrom(getDefaultTargetFrame());
\r
88 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
\r
90 public String getSelectedSequences(String sep)
\r
92 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
\r
96 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui.AlignFrame)
\r
98 public String getSelectedSequencesFrom(AlignFrame alf)
\r
100 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
\r
104 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
106 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
\r
108 StringBuffer result = new StringBuffer("");
\r
109 if (sep == null || sep.length() == 0)
\r
111 sep = separator; // "+0x00AC;
\r
113 if (alf.viewport.getSelectionGroup() != null)
\r
115 SequenceI[] seqs = alf.viewport.getSelectionGroup()
\r
116 .getSequencesInOrder(alf.viewport.getAlignment());
\r
118 for (int i = 0; i < seqs.length; i++)
\r
120 result.append(seqs[i].getName());
\r
121 result.append(sep);
\r
125 return result.toString();
\r
129 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String, java.lang.String, java.lang.String)
\r
131 public void highlight(String sequenceId, String position,
\r
132 String alignedPosition)
\r
134 highlightIn(getDefaultTargetFrame(), sequenceId, position,
\r
139 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
141 public void highlightIn(AlignFrame alf, String sequenceId,
\r
142 String position, String alignedPosition)
\r
144 // TODO: could try to highlight in all alignments if alf==null
\r
145 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
146 alf.viewport.getAlignment().getSequencesArray());
\r
147 SequenceI sq = matcher.findIdMatch(sequenceId);
\r
150 int pos, apos = -1;
\r
153 apos = new Integer(position).intValue();
\r
155 } catch (NumberFormatException ex)
\r
159 // use vamsas listener to broadcast to all listeners in scope
\r
160 if (alignedPosition != null
\r
161 && (alignedPosition.trim().length() == 0 || alignedPosition
\r
162 .toLowerCase().indexOf("false") > -1))
\r
164 StructureSelectionManager.getStructureSelectionManager(this)
\r
165 .mouseOverVamsasSequence(sq, sq.findIndex(apos), null);
\r
169 StructureSelectionManager.getStructureSelectionManager(this)
\r
170 .mouseOverVamsasSequence(sq, apos, null);
\r
177 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String, java.lang.String)
\r
179 public void select(String sequenceIds, String columns)
\r
181 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
\r
185 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String, java.lang.String, java.lang.String)
\r
187 public void select(String sequenceIds, String columns, String sep)
\r
189 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
\r
193 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
195 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
\r
197 selectIn(alf, sequenceIds, columns, separator);
\r
201 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
203 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
\r
206 if (sep == null || sep.length() == 0)
\r
214 System.err.println("Selecting region using separator string '"
\r
215 + separator + "'");
\r
219 String[] ids = separatorListToArray(sequenceIds, sep);
\r
220 String[] cols = separatorListToArray(columns, sep);
\r
221 SequenceGroup sel = new SequenceGroup();
\r
222 ColumnSelection csel = new ColumnSelection();
\r
223 AlignmentI al = alf.viewport.getAlignment();
\r
224 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
225 alf.viewport.getAlignment().getSequencesArray());
\r
226 int start = 0, end = al.getWidth(), alw = al.getWidth();
\r
227 boolean seqsfound = true;
\r
228 if (ids != null && ids.length > 0)
\r
231 for (int i = 0; i < ids.length; i++)
\r
233 if (ids[i].trim().length() == 0)
\r
237 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
241 sel.addSequence(sq, false);
\r
245 boolean inseqpos = false;
\r
246 if (cols != null && cols.length > 0)
\r
248 boolean seset = false;
\r
249 for (int i = 0; i < cols.length; i++)
\r
251 String cl = cols[i].trim();
\r
252 if (cl.length() == 0)
\r
257 if ((p = cl.indexOf("-")) > -1)
\r
259 int from = -1, to = -1;
\r
262 from = new Integer(cl.substring(0, p)).intValue();
\r
264 } catch (NumberFormatException ex)
\r
267 .println("ERROR: Couldn't parse first integer in range element column selection string '"
\r
268 + cl + "' - format is 'from-to'");
\r
273 to = new Integer(cl.substring(p + 1)).intValue();
\r
275 } catch (NumberFormatException ex)
\r
278 .println("ERROR: Couldn't parse second integer in range element column selection string '"
\r
279 + cl + "' - format is 'from-to'");
\r
282 if (from >= 0 && to >= 0)
\r
299 // comment to prevent range extension
\r
309 for (int r = from; r <= to; r++)
\r
311 if (r >= 0 && r < alw)
\r
313 csel.addElement(r);
\r
318 System.err.println("Range '" + cl + "' deparsed as [" + from
\r
324 System.err.println("ERROR: Invalid Range '" + cl
\r
325 + "' deparsed as [" + from + "," + to + "]");
\r
333 r = new Integer(cl).intValue();
\r
335 } catch (NumberFormatException ex)
\r
337 if (cl.toLowerCase().equals("sequence"))
\r
339 // we are in the dataset sequence's coordinate frame.
\r
345 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
\r
350 if (r >= 0 && r <= alw)
\r
360 // comment to prevent range extension
\r
370 csel.addElement(r);
\r
373 System.err.println("Point selection '" + cl
\r
374 + "' deparsed as [" + r + "]");
\r
379 System.err.println("ERROR: Invalid Point selection '" + cl
\r
380 + "' deparsed as [" + r + "]");
\r
387 // we only propagate the selection when it was the null selection, or the
\r
388 // given sequences were found in the alignment.
\r
389 if (inseqpos && sel.getSize() > 0)
\r
391 // assume first sequence provides reference frame ?
\r
392 SequenceI rs = sel.getSequenceAt(0);
\r
393 start = rs.findIndex(start);
\r
394 end = rs.findIndex(end);
\r
397 Vector cs = csel.getSelected();
\r
399 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
\r
401 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
\r
406 sel.setStartRes(start);
\r
407 sel.setEndRes(end);
\r
408 alf.select(sel, csel);
\r
413 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.String, java.lang.String)
\r
415 public String getSelectedSequencesAsAlignment(String format, String suffix)
\r
417 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
\r
422 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
424 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
\r
425 String format, String suffix)
\r
429 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
430 if (alf.viewport.getSelectionGroup() != null)
\r
432 String reply = new AppletFormatAdapter().formatSequences(format,
\r
433 new Alignment(alf.viewport.getSelectionAsNewSequence()),
\r
437 } catch (Exception ex)
\r
439 ex.printStackTrace();
\r
440 return "Error retrieving alignment in " + format + " format. ";
\r
446 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
\r
448 public String getAlignmentOrder()
\r
450 return getAlignmentOrderFrom(getDefaultTargetFrame());
\r
454 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame)
\r
456 public String getAlignmentOrderFrom(AlignFrame alf)
\r
458 return getAlignmentOrderFrom(alf, separator);
\r
462 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
464 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
\r
466 AlignmentI alorder = alf.getAlignViewport().getAlignment();
\r
467 String[] order = new String[alorder.getHeight()];
\r
468 for (int i = 0; i < order.length; i++)
\r
470 order[i] = alorder.getSequenceAt(i).getName();
\r
472 return arrayToSeparatorList(order);
\r
476 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String, java.lang.String)
\r
478 public String orderBy(String order, String undoName)
\r
480 return orderBy(order, undoName, separator);
\r
484 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String, java.lang.String, java.lang.String)
\r
486 public String orderBy(String order, String undoName, String sep)
\r
488 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
\r
492 * @see jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
494 public String orderAlignmentBy(AlignFrame alf, String order,
\r
495 String undoName, String sep)
\r
497 String[] ids = separatorListToArray(order, sep);
\r
498 SequenceI[] sqs = null;
\r
499 if (ids != null && ids.length > 0)
\r
501 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
502 alf.viewport.getAlignment().getSequencesArray());
\r
504 sqs = new SequenceI[ids.length];
\r
505 for (int i = 0; i < ids.length; i++)
\r
507 if (ids[i].trim().length() == 0)
\r
511 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
519 SequenceI[] sqq = new SequenceI[s];
\r
520 System.arraycopy(sqs, 0, sqq, 0, s);
\r
533 AlignmentOrder aorder = new AlignmentOrder(sqs);
\r
535 if (undoName != null && undoName.trim().length() == 0)
\r
540 return alf.sortBy(aorder, undoName) ? "true" : "";
\r
544 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
\r
546 public String getAlignment(String format)
\r
548 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
\r
552 * @see jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
554 public String getAlignmentFrom(AlignFrame alf, String format)
\r
556 return getAlignmentFrom(alf, format, "true");
\r
560 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String, java.lang.String)
\r
562 public String getAlignment(String format, String suffix)
\r
564 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
\r
568 * @see jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
570 public String getAlignmentFrom(AlignFrame alf, String format,
\r
575 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
577 String reply = new AppletFormatAdapter().formatSequences(format,
\r
578 alf.viewport.getAlignment(), seqlimits);
\r
580 } catch (Exception ex)
\r
582 ex.printStackTrace();
\r
583 return "Error retrieving alignment in " + format + " format. ";
\r
588 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
\r
590 public void loadAnnotation(String annotation)
\r
592 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
\r
596 * @see jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
598 public void loadAnnotationFrom(AlignFrame alf, String annotation)
\r
600 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
\r
601 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
\r
603 alf.alignPanel.fontChanged();
\r
604 alf.alignPanel.setScrollValues(0, 0);
\r
608 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
\r
613 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
\r
615 public String getFeatures(String format)
\r
617 return getFeaturesFrom(getDefaultTargetFrame(), format);
\r
621 * @see jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
623 public String getFeaturesFrom(AlignFrame alf, String format)
\r
625 return alf.outputFeatures(false, format);
\r
629 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
\r
631 public String getAnnotation()
\r
633 return getAnnotationFrom(getDefaultTargetFrame());
\r
637 * @see jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame)
\r
639 public String getAnnotationFrom(AlignFrame alf)
\r
641 return alf.outputAnnotations(false);
\r
645 * @see jalview.bin.JalviewLiteJsApi#newView()
\r
647 public AlignFrame newView()
\r
649 return newViewFrom(getDefaultTargetFrame());
\r
653 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
\r
655 public AlignFrame newView(String name)
\r
657 return newViewFrom(getDefaultTargetFrame(), name);
\r
661 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
\r
663 public AlignFrame newViewFrom(AlignFrame alf)
\r
665 return alf.newView(null);
\r
669 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame, java.lang.String)
\r
671 public AlignFrame newViewFrom(AlignFrame alf, String name)
\r
673 return alf.newView(name);
\r
677 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String, java.lang.String)
\r
679 public AlignFrame loadAlignment(String text, String title)
\r
681 Alignment al = null;
\r
683 String format = new IdentifyFile().Identify(text,
\r
684 AppletFormatAdapter.PASTE);
\r
687 al = new AppletFormatAdapter().readFile(text,
\r
688 AppletFormatAdapter.PASTE, format);
\r
689 if (al.getHeight() > 0)
\r
691 return new AlignFrame(al, this, title, false);
\r
693 } catch (java.io.IOException ex)
\r
695 ex.printStackTrace();
\r
701 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
\r
703 public void setMouseoverListener(String listener)
\r
705 setMouseoverListener(currentAlignFrame, listener);
\r
708 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
\r
711 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
713 public void setMouseoverListener(AlignFrame af, String listener)
\r
715 if (listener != null)
\r
717 listener = listener.trim();
\r
718 if (listener.length() == 0)
\r
721 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
\r
725 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
\r
726 this, af, listener);
\r
727 javascriptListeners.addElement(mol);
\r
728 StructureSelectionManager.getStructureSelectionManager(this)
\r
729 .addStructureViewerListener(mol);
\r
732 System.err.println("Added a mouseover listener for "
\r
733 + ((af == null) ? "All frames" : "Just views for "
\r
734 + af.getAlignViewport().getSequenceSetId()));
\r
735 System.err.println("There are now " + javascriptListeners.size()
\r
736 + " listeners in total.");
\r
741 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
\r
743 public void setSelectionListener(String listener)
\r
745 setSelectionListener(null, listener);
\r
749 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
751 public void setSelectionListener(AlignFrame af, String listener)
\r
753 if (listener != null)
\r
755 listener = listener.trim();
\r
756 if (listener.length() == 0)
\r
759 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
763 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
\r
764 this, af, listener);
\r
765 javascriptListeners.addElement(mol);
\r
766 StructureSelectionManager.getStructureSelectionManager(this)
\r
767 .addSelectionListener(mol);
\r
770 System.err.println("Added a selection listener for "
\r
771 + ((af == null) ? "All frames" : "Just views for "
\r
772 + af.getAlignViewport().getSequenceSetId()));
\r
773 System.err.println("There are now " + javascriptListeners.size()
\r
774 + " listeners in total.");
\r
779 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String, java.lang.String)
\r
781 public void setStructureListener(String listener, String modelSet)
\r
783 if (listener != null)
\r
785 listener = listener.trim();
\r
786 if (listener.length() == 0)
\r
789 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
793 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
\r
794 this, listener, separatorListToArray(modelSet));
\r
795 javascriptListeners.addElement(mol);
\r
796 StructureSelectionManager.getStructureSelectionManager(this)
\r
797 .addStructureViewerListener(mol);
\r
800 System.err.println("Added a javascript structure viewer listener '"
\r
802 System.err.println("There are now " + javascriptListeners.size()
\r
803 + " listeners in total.");
\r
808 * @see jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui.AlignFrame, java.lang.String)
\r
810 public void removeJavascriptListener(AlignFrame af, String listener)
\r
812 if (listener != null)
\r
814 listener = listener.trim();
\r
815 if (listener.length() == 0)
\r
820 boolean rprt = false;
\r
821 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
\r
823 Object lstn = javascriptListeners.elementAt(ms);
\r
824 JsCallBack lstner = (JsCallBack) lstn;
\r
825 if ((af == null || lstner.getAlignFrame() == af)
\r
826 && (listener == null || lstner.getListenerFunction().equals(
\r
829 javascriptListeners.removeElement(lstner);
\r
831 if (lstner instanceof SelectionListener)
\r
833 StructureSelectionManager.getStructureSelectionManager(this)
\r
834 .removeSelectionListener((SelectionListener) lstner);
\r
838 StructureSelectionManager.getStructureSelectionManager(this)
\r
839 .removeStructureViewerListener(lstner, null);
\r
844 System.err.println("Removed listener '" + listener + "'");
\r
854 System.err.println("There are now " + javascriptListeners.size()
\r
855 + " listeners in total.");
\r
861 System.err.println("Applet "+getName()+" stop().");
\r
864 public void destroy()
\r
866 System.err.println("Applet "+getName()+" destroy().");
\r
869 private void tidyUp()
\r
872 if (currentAlignFrame!=null && currentAlignFrame.viewport!=null
\r
873 && currentAlignFrame.viewport.applet!=null)
\r
875 AlignViewport av = currentAlignFrame.viewport;
\r
876 currentAlignFrame.closeMenuItem_actionPerformed();
\r
878 currentAlignFrame=null;
\r
880 if (javascriptListeners != null)
\r
882 while (javascriptListeners.size() > 0)
\r
884 jalview.javascript.JSFunctionExec mol = javascriptListeners.elementAt(0);
\r
885 javascriptListeners.removeElement(mol);
\r
886 if (mol instanceof SelectionListener)
\r
888 StructureSelectionManager.getStructureSelectionManager(this)
\r
889 .removeSelectionListener((SelectionListener) mol);
\r
893 StructureSelectionManager.getStructureSelectionManager(this)
\r
894 .removeStructureViewerListener(mol, null);
\r
899 if (jsFunctionExec!=null) {
\r
900 jsFunctionExec.stopQueue();
\r
901 jsFunctionExec.jvlite=null;
\r
903 initialAlignFrame=null;
\r
904 jsFunctionExec = null;
\r
905 javascriptListeners=null;
\r
906 StructureSelectionManager.release(this);
\r
908 private jalview.javascript.JSFunctionExec jsFunctionExec;
\r
910 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String, java.lang.String, java.lang.String)
\r
912 public void mouseOverStructure(String pdbResNum, String chain,
\r
917 StructureSelectionManager.getStructureSelectionManager(this)
\r
918 .mouseOverStructure(new Integer(pdbResNum).intValue(), chain,
\r
922 System.err.println("mouseOver for '" + pdbResNum + "' in chain '"
\r
923 + chain + "' in structure '" + pdbfile + "'");
\r
925 } catch (NumberFormatException e)
\r
927 System.err.println("Ignoring invalid residue number string '"
\r
928 + pdbResNum + "'");
\r
932 * @see jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
934 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
\r
937 alf.scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue());
\r
939 } catch (Exception ex)
\r
941 System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"' and leftHandColumn='"+leftHandColumn+"')");
\r
942 ex.printStackTrace();
\r
947 * @see jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui.AlignFrame, java.lang.String)
\r
950 public void scrollViewToRowIn(AlignFrame alf, String topRow)
\r
953 alf.scrollToRow(new Integer(topRow).intValue());
\r
955 } catch (Exception ex)
\r
957 System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"')");
\r
958 ex.printStackTrace();
\r
963 * @see jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui.AlignFrame, java.lang.String)
\r
966 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
\r
970 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
\r
972 } catch (Exception ex)
\r
974 System.err.println("Couldn't parse integer arguments (leftHandColumn='"+leftHandColumn+"')");
\r
975 ex.printStackTrace();
\r
979 // //////////////////////////////////////////////
\r
980 // //////////////////////////////////////////////
\r
982 public static int lastFrameX = 200;
\r
984 public static int lastFrameY = 200;
\r
986 boolean fileFound = true;
\r
988 String file = "No file";
\r
990 Button launcher = new Button("Start Jalview");
\r
993 * The currentAlignFrame is static, it will change if and when the user
\r
994 * selects a new window. Note that it will *never* point back to the embedded
\r
995 * AlignFrame if the applet is started as embedded on the page and then
\r
996 * afterwards a new view is created.
\r
998 public AlignFrame currentAlignFrame = null;
\r
1001 * This is the first frame to be displayed, and does not change. API calls
\r
1002 * will default to this instance if currentAlignFrame is null.
\r
1004 AlignFrame initialAlignFrame = null;
\r
1006 boolean embedded = false;
\r
1008 private boolean checkForJmol = true;
\r
1010 private boolean checkedForJmol = false; // ensure we don't check for jmol
\r
1012 // every time the app is re-inited
\r
1014 public boolean jmolAvailable = false;
\r
1016 private boolean alignPdbStructures = false;
\r
1019 * use an external structure viewer exclusively (no jmols or MCViews will be
\r
1020 * opened by JalviewLite itself)
\r
1022 public boolean useXtrnalSviewer = false;
\r
1024 public static boolean debug = false;
\r
1026 static String builddate = null, version = null;
\r
1028 private static void initBuildDetails()
\r
1030 if (builddate == null)
\r
1032 builddate = "unknown";
\r
1034 java.net.URL url = JalviewLite.class
\r
1035 .getResource("/.build_properties");
\r
1040 BufferedReader reader = new BufferedReader(new InputStreamReader(
\r
1041 url.openStream()));
\r
1043 while ((line = reader.readLine()) != null)
\r
1045 if (line.indexOf("VERSION") > -1)
\r
1047 version = line.substring(line.indexOf("=") + 1);
\r
1049 if (line.indexOf("BUILD_DATE") > -1)
\r
1051 builddate = line.substring(line.indexOf("=") + 1);
\r
1054 } catch (Exception ex)
\r
1056 ex.printStackTrace();
\r
1062 public static String getBuildDate()
\r
1064 initBuildDetails();
\r
1068 public static String getVersion()
\r
1070 initBuildDetails();
\r
1074 // public JSObject scriptObject = null;
\r
1077 * init method for Jalview Applet
\r
1079 public void init()
\r
1081 // remove any handlers that might be hanging around from an earlier instance
\r
1086 System.err.println("Applet context is '"
\r
1087 + getAppletContext().getClass().toString() + "'");
\r
1089 JSObject scriptObject = JSObject.getWindow(this);
\r
1090 if (debug && scriptObject != null)
\r
1092 System.err.println("Applet has Javascript callback support.");
\r
1095 } catch (Exception ex)
\r
1098 .println("Warning: No JalviewLite javascript callbacks available.");
\r
1101 ex.printStackTrace();
\r
1105 * turn on extra applet debugging
\r
1107 String dbg = getParameter("debug");
\r
1110 debug = dbg.toLowerCase().equals("true");
\r
1115 System.err.println("JalviewLite Version " + getVersion());
\r
1116 System.err.println("Build Date : " + getBuildDate());
\r
1119 String externalsviewer = getParameter("externalstructureviewer");
\r
1120 if (externalsviewer != null)
\r
1122 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
\r
1126 * if true disable the check for jmol
\r
1128 String chkforJmol = getParameter("nojmol");
\r
1129 if (chkforJmol != null)
\r
1131 checkForJmol = !chkforJmol.equals("true");
\r
1134 * get the separator parameter if present
\r
1136 String sep = getParameter("separator");
\r
1139 if (sep.length() > 0)
\r
1144 System.err.println("Separator set to '" + separator + "'");
\r
1150 "Invalid separator parameter - must be non-zero length");
\r
1156 String param = getParameter("RGB");
\r
1158 if (param != null)
\r
1162 r = Integer.parseInt(param.substring(0, 2), 16);
\r
1163 g = Integer.parseInt(param.substring(2, 4), 16);
\r
1164 b = Integer.parseInt(param.substring(4, 6), 16);
\r
1165 } catch (Exception ex)
\r
1172 param = getParameter("label");
\r
1173 if (param != null)
\r
1175 launcher.setLabel(param);
\r
1178 setBackground(new Color(r, g, b));
\r
1180 file = getParameter("file");
\r
1184 // Maybe the sequences are added as parameters
\r
1185 StringBuffer data = new StringBuffer("PASTE");
\r
1187 while ((file = getParameter("sequence" + i)) != null)
\r
1189 data.append(file.toString() + "\n");
\r
1192 if (data.length() > 5)
\r
1194 file = data.toString();
\r
1198 final JalviewLite jvapplet = this;
\r
1199 if (getParameter("embedded") != null
\r
1200 && getParameter("embedded").equalsIgnoreCase("true"))
\r
1202 // Launch as embedded applet in page
\r
1204 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1207 else if (file != null)
\r
1209 if (getParameter("showbutton") == null
\r
1210 || !getParameter("showbutton").equalsIgnoreCase("false"))
\r
1212 // Add the JalviewLite 'Button' to the page
\r
1214 launcher.addActionListener(new java.awt.event.ActionListener()
\r
1216 public void actionPerformed(ActionEvent e)
\r
1218 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1225 // Open jalviewLite immediately.
\r
1226 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1232 // jalview initialisation with no alignment. loadAlignment() method can
\r
1233 // still be called to open new alignments.
\r
1235 fileFound = false;
\r
1236 // callInitCallback();
\r
1240 private void callInitCallback()
\r
1242 String initjscallback = getParameter("oninit");
\r
1243 if (initjscallback == null)
\r
1247 initjscallback = initjscallback.trim();
\r
1248 if (initjscallback.length() > 0)
\r
1250 JSObject scriptObject = null;
\r
1253 scriptObject = JSObject.getWindow(this);
\r
1254 } catch (Exception ex)
\r
1258 if (scriptObject != null)
\r
1262 // do onInit with the JS executor thread
\r
1263 new JSFunctionExec(this).executeJavascriptFunction(true,
\r
1264 initjscallback, null, "Calling oninit callback '"
\r
1265 + initjscallback + "'.");
\r
1266 } catch (Exception e)
\r
1268 System.err.println("Exception when executing _oninit callback '"
\r
1269 + initjscallback + "'.");
\r
1270 e.printStackTrace();
\r
1275 System.err.println("Not executing _oninit callback '"
\r
1276 + initjscallback + "' - no scripting allowed.");
\r
1282 * Initialises and displays a new java.awt.Frame
\r
1285 * java.awt.Frame to be displayed
\r
1287 * title of new frame
\r
1289 * width if new frame
\r
1291 * height of new frame
\r
1293 public static void addFrame(final Frame frame, String title, int width,
\r
1296 frame.setLocation(lastFrameX, lastFrameY);
\r
1299 frame.setSize(width, height);
\r
1300 frame.setTitle(title);
\r
1301 frame.addWindowListener(new WindowAdapter()
\r
1303 public void windowClosing(WindowEvent e)
\r
1305 if (frame instanceof AlignFrame)
\r
1307 AlignViewport vp = ((AlignFrame) frame).viewport;
\r
1308 ((AlignFrame) frame).closeMenuItem_actionPerformed();
\r
1309 if (vp.applet.currentAlignFrame == frame)
\r
1311 vp.applet.currentAlignFrame = null;
\r
1319 if (frame instanceof EmbmenuFrame)
\r
1321 ((EmbmenuFrame) frame).destroyMenus();
\r
1323 frame.setMenuBar(null);
\r
1327 public void windowActivated(WindowEvent e)
\r
1329 if (frame instanceof AlignFrame)
\r
1331 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
\r
1334 System.err.println("Activated window " + frame);
\r
1338 super.windowActivated(e);
\r
1341 * Probably not necessary to do this - see TODO above. (non-Javadoc)
\r
1344 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
\r
1347 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
\r
1348 * frame) { currentAlignFrame = null; if (debug) {
\r
1349 * System.err.println("Deactivated window "+frame); } }
\r
1350 * super.windowDeactivated(e); }
\r
1353 frame.setVisible(true);
\r
1357 * This paints the background surrounding the "Launch Jalview button" <br>
\r
1359 * If file given in parameter not found, displays error message
\r
1362 * graphics context
\r
1364 public void paint(Graphics g)
\r
1368 g.setColor(new Color(200, 200, 200));
\r
1369 g.setColor(Color.cyan);
\r
1370 g.fillRect(0, 0, getSize().width, getSize().height);
\r
1371 g.setColor(Color.red);
\r
1372 g.drawString("Jalview can't open file", 5, 15);
\r
1373 g.drawString("\"" + file + "\"", 5, 30);
\r
1375 else if (embedded)
\r
1377 g.setColor(Color.black);
\r
1378 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
1379 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
\r
1380 g.drawString("Loading Data...", 50, getSize().height / 2);
\r
1385 * get all components associated with the applet of the given type
\r
1390 public Vector getAppletWindow(Class class1)
\r
1392 Vector wnds = new Vector();
\r
1393 Component[] cmp = getComponents();
\r
1396 for (int i = 0; i < cmp.length; i++)
\r
1398 if (class1.isAssignableFrom(cmp[i].getClass()))
\r
1400 wnds.addElement(cmp);
\r
1407 class LoadJmolThread extends Thread
\r
1409 private boolean running = false;
\r
1413 if (running || checkedForJmol)
\r
1422 if (!System.getProperty("java.version").startsWith("1.1"))
\r
1424 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
\r
1425 jmolAvailable = true;
\r
1427 if (!jmolAvailable)
\r
1430 .println("Jmol not available - Using MCview for structures");
\r
1432 } catch (java.lang.ClassNotFoundException ex)
\r
1438 jmolAvailable = false;
\r
1442 .println("Skipping Jmol check. Will use MCView (probably)");
\r
1445 checkedForJmol = true;
\r
1449 public boolean notFinished()
\r
1451 return running || !checkedForJmol;
\r
1455 class LoadingThread extends Thread
\r
1458 * State variable: File source
\r
1463 * State variable: protocol for access to file source
\r
1468 * State variable: format of file source
\r
1474 JalviewLite applet;
\r
1476 private void dbgMsg(String msg)
\r
1480 System.err.println(msg);
\r
1485 * update the protocol state variable for accessing the datasource located
\r
1489 * @return possibly updated datasource string
\r
1491 public String setProtocolState(String file)
\r
1493 if (file.startsWith("PASTE"))
\r
1495 file = file.substring(5);
\r
1496 protocol = AppletFormatAdapter.PASTE;
\r
1498 else if (inArchive(file))
\r
1500 protocol = AppletFormatAdapter.CLASSLOADER;
\r
1504 file = addProtocol(file);
\r
1505 protocol = AppletFormatAdapter.URL;
\r
1507 dbgMsg("Protocol identified as '" + protocol + "'");
\r
1511 public LoadingThread(String _file, JalviewLite _applet)
\r
1513 this._file = _file;
\r
1519 LoadJmolThread jmolchecker = new LoadJmolThread();
\r
1520 jmolchecker.start();
\r
1521 while (jmolchecker.notFinished())
\r
1523 // wait around until the Jmol check is complete.
\r
1527 } catch (Exception e)
\r
1533 // applet.callInitCallback();
\r
1536 private void startLoading()
\r
1538 AlignFrame newAlignFrame;
\r
1539 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
\r
1540 file = setProtocolState(_file);
\r
1542 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
1543 dbgMsg("File identified as '" + format + "'");
\r
1544 dbgMsg("Loading started.");
\r
1545 Alignment al = null;
\r
1548 al = new AppletFormatAdapter().readFile(file, protocol, format);
\r
1549 } catch (java.io.IOException ex)
\r
1551 dbgMsg("File load exception.");
\r
1552 ex.printStackTrace();
\r
1557 FileParse fp = new FileParse(file, protocol);
\r
1559 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
\r
1560 + protocol + ")");
\r
1561 while ((ln = fp.nextLine()) != null)
\r
1565 dbgMsg(">>>Dump finished.");
\r
1566 } catch (Exception e)
\r
1569 .println("Exception when trying to dump the content of the file parameter.");
\r
1570 e.printStackTrace();
\r
1574 if ((al != null) && (al.getHeight() > 0))
\r
1576 dbgMsg("Successfully loaded file.");
\r
1577 newAlignFrame = new AlignFrame(al, applet, file, embedded);
\r
1578 if (initialAlignFrame == null)
\r
1580 initialAlignFrame = newAlignFrame;
\r
1582 // update the focus.
\r
1583 currentAlignFrame = newAlignFrame;
\r
1585 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
\r
1587 newAlignFrame.setTitle("Sequences from "
\r
1588 + applet.getDocumentBase());
\r
1591 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
1593 String treeFile = applet.getParameter("tree");
\r
1594 if (treeFile == null)
\r
1596 treeFile = applet.getParameter("treeFile");
\r
1599 if (treeFile != null)
\r
1603 treeFile = setProtocolState(treeFile);
\r
1605 * if (inArchive(treeFile)) { protocol =
\r
1606 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
\r
1607 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
\r
1609 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
\r
1614 if (fin.getTree() != null)
\r
1616 newAlignFrame.loadTree(fin, treeFile);
\r
1617 dbgMsg("Successfuly imported tree.");
\r
1621 dbgMsg("Tree parameter did not resolve to a valid tree.");
\r
1623 } catch (Exception ex)
\r
1625 ex.printStackTrace();
\r
1629 String param = applet.getParameter("features");
\r
1630 if (param != null)
\r
1632 param = setProtocolState(param);
\r
1634 newAlignFrame.parseFeaturesFile(param, protocol);
\r
1637 param = applet.getParameter("showFeatureSettings");
\r
1638 if (param != null && param.equalsIgnoreCase("true"))
\r
1640 newAlignFrame.viewport.showSequenceFeatures(true);
\r
1641 new FeatureSettings(newAlignFrame.alignPanel);
\r
1644 param = applet.getParameter("annotations");
\r
1645 if (param != null)
\r
1647 param = setProtocolState(param);
\r
1649 if (new AnnotationFile().readAnnotationFile(
\r
1650 newAlignFrame.viewport.getAlignment(), param, protocol))
\r
1652 newAlignFrame.alignPanel.fontChanged();
\r
1653 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1658 .println("Annotations were not added from annotation file '"
\r
1664 param = applet.getParameter("jnetfile");
\r
1665 if (param != null)
\r
1669 param = setProtocolState(param);
\r
1670 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
\r
1672 JnetAnnotationMaker.add_annotation(predictions,
\r
1673 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
\r
1681 newAlignFrame.alignPanel.fontChanged();
\r
1682 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1683 } catch (Exception ex)
\r
1685 ex.printStackTrace();
\r
1689 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
\r
1690 * - related to JAL-434
\r
1692 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
\r
1695 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
\r
1696 * PDB|1GAQ|1GAQ|C">
\r
1698 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
\r
1700 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
\r
1703 int pdbFileCount = 0;
\r
1704 // Accumulate pdbs here if they are heading for the same view (if
\r
1705 // alignPdbStructures is true)
\r
1706 Vector pdbs = new Vector();
\r
1707 // create a lazy matcher if we're asked to
\r
1708 jalview.analysis.SequenceIdMatcher matcher = (applet
\r
1709 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
\r
1710 newAlignFrame.getAlignViewport().getAlignment()
\r
1711 .getSequencesArray()) : null;
\r
1715 if (pdbFileCount > 0)
\r
1717 param = applet.getParameter("PDBFILE" + pdbFileCount);
\r
1721 param = applet.getParameter("PDBFILE");
\r
1724 if (param != null)
\r
1726 PDBEntry pdb = new PDBEntry();
\r
1729 SequenceI[] seqs = null;
\r
1730 String[] chains = null;
\r
1732 StringTokenizer st = new StringTokenizer(param, " ");
\r
1734 if (st.countTokens() < 2)
\r
1736 String sequence = applet.getParameter("PDBSEQ");
\r
1737 if (sequence != null)
\r
1738 seqs = new SequenceI[]
\r
1739 { matcher == null ? (Sequence) newAlignFrame
\r
1740 .getAlignViewport().getAlignment()
\r
1741 .findName(sequence) : matcher.findIdMatch(sequence) };
\r
1746 param = st.nextToken();
\r
1747 Vector tmp = new Vector();
\r
1748 Vector tmp2 = new Vector();
\r
1750 while (st.hasMoreTokens())
\r
1752 seqstring = st.nextToken();
\r
1753 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
\r
1754 if (st2.countTokens() > 1)
\r
1756 // This is the chain
\r
1757 tmp2.addElement(st2.nextToken());
\r
1758 seqstring = st2.nextToken();
\r
1760 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
\r
1761 .getAlignViewport().getAlignment()
\r
1762 .findName(seqstring) : matcher
\r
1763 .findIdMatch(seqstring));
\r
1766 seqs = new SequenceI[tmp.size()];
\r
1767 tmp.copyInto(seqs);
\r
1768 if (tmp2.size() == tmp.size())
\r
1770 chains = new String[tmp2.size()];
\r
1771 tmp2.copyInto(chains);
\r
1774 param = setProtocolState(param);
\r
1776 if (// !jmolAvailable
\r
1778 protocol == AppletFormatAdapter.CLASSLOADER
\r
1779 && !useXtrnalSviewer)
\r
1781 // Re: JAL-357 : the bug isn't a problem if we are using an
\r
1782 // external viewer!
\r
1783 // TODO: verify this Re:
\r
1784 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
\r
1785 // This exception preserves the current behaviour where, even if
\r
1786 // the local pdb file was identified in the class loader
\r
1787 protocol = AppletFormatAdapter.URL; // this is probably NOT
\r
1789 param = addProtocol(param); //
\r
1792 pdb.setFile(param);
\r
1796 for (int i = 0; i < seqs.length; i++)
\r
1798 if (seqs[i] != null)
\r
1800 ((Sequence) seqs[i]).addPDBId(pdb);
\r
1804 if (JalviewLite.debug)
\r
1806 // this may not really be a problem but we give a warning
\r
1809 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
\r
1815 if (!alignPdbStructures)
\r
1817 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
\r
1822 pdbs.addElement(new Object[]
\r
1823 { pdb, seqs, chains, new String(protocol) });
\r
1829 } while (param != null || pdbFileCount < 10);
\r
1830 if (pdbs.size() > 0)
\r
1832 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
\r
1833 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
\r
1834 String[][] chains = new String[pdbs.size()][];
\r
1835 String[] protocols = new String[pdbs.size()];
\r
1836 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
\r
1838 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
\r
1839 pdb[pdbsi] = (PDBEntry) o[0];
\r
1840 seqs[pdbsi] = (SequenceI[]) o[1];
\r
1841 chains[pdbsi] = (String[]) o[2];
\r
1842 protocols[pdbsi] = (String) o[3];
\r
1844 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
\r
1848 // ///////////////////////////
\r
1849 // modify display of features
\r
1851 // hide specific groups
\r
1852 param = applet.getParameter("hidefeaturegroups");
\r
1853 if (param != null)
\r
1855 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
\r
1857 // show specific groups
\r
1858 param = applet.getParameter("showfeaturegroups");
\r
1859 if (param != null)
\r
1861 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
\r
1866 fileFound = false;
\r
1867 applet.remove(launcher);
\r
1870 callInitCallback();
\r
1874 * Discovers whether the given file is in the Applet Archive
\r
1880 boolean inArchive(String file)
\r
1882 // This might throw a security exception in certain browsers
\r
1883 // Netscape Communicator for instance.
\r
1886 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
\r
1889 System.err.println("Resource '" + file + "' was "
\r
1890 + (rtn ? "" : "not") + " located by classloader.");
\r
1893 } catch (Exception ex)
\r
1895 System.out.println("Exception checking resources: " + file + " "
\r
1901 String addProtocol(String file)
\r
1903 if (file.indexOf("://") == -1)
\r
1905 String fl = applet.resolveUrlForLocalOrAbsolute(file, getDocumentBase());
\r
1908 if (new java.net.URL(fl).openStream() != null)
\r
1912 System.err.println("Prepended document base for resource: '"
\r
1917 } catch (Exception x)
\r
1921 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
\r
1924 if (new java.net.URL(fl).openStream() != null)
\r
1928 System.err.println("Prepended codebase for resource: '"
\r
1933 } catch (Exception x)
\r
1945 * @return the default alignFrame acted on by the public applet methods. May
\r
1946 * return null with an error message on System.err indicating the
\r
1949 public AlignFrame getDefaultTargetFrame()
\r
1951 if (currentAlignFrame != null)
\r
1953 return currentAlignFrame;
\r
1955 if (initialAlignFrame != null)
\r
1957 return initialAlignFrame;
\r
1960 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
\r
1965 * separator used for separatorList
\r
1967 protected String separator = "" + ((char) 0x00AC); // the default used to be
\r
1968 // '|' but many sequence
\r
1969 // IDS include pipes.
\r
1972 * set to enable the URL based javascript execution mechanism
\r
1974 public boolean jsfallbackEnabled=false;
\r
1977 * parse the string into a list
\r
1980 * @return elements separated by separator
\r
1982 public String[] separatorListToArray(String list)
\r
1984 return separatorListToArray(list, separator);
\r
1988 * parse the string into a list
\r
1991 * @param separator
\r
1992 * @return elements separated by separator
\r
1994 public String[] separatorListToArray(String list, String separator)
\r
1996 // note separator local variable intentionally masks object field
\r
1997 int seplen = separator.length();
\r
1998 if (list == null || list.equals("") || list.equals(separator))
\r
2000 java.util.Vector jv = new Vector();
\r
2002 while ((pos = list.indexOf(separator, cp)) > cp)
\r
2004 jv.addElement(list.substring(cp, pos));
\r
2005 cp = pos + seplen;
\r
2007 if (cp < list.length())
\r
2009 String c = list.substring(cp);
\r
2010 if (!c.equals(separator))
\r
2015 if (jv.size() > 0)
\r
2017 String[] v = new String[jv.size()];
\r
2018 for (int i = 0; i < v.length; i++)
\r
2020 v[i] = (String) jv.elementAt(i);
\r
2022 jv.removeAllElements();
\r
2025 System.err.println("Array from '" + separator
\r
2026 + "' separated List:\n" + v.length);
\r
2027 for (int i = 0; i < v.length; i++)
\r
2029 System.err.println("item " + i + " '" + v[i] + "'");
\r
2036 System.err.println("Empty Array from '" + separator
\r
2037 + "' separated List");
\r
2043 * concatenate the list with separator
\r
2046 * @return concatenated string
\r
2048 public String arrayToSeparatorList(String[] list)
\r
2050 return arrayToSeparatorList(list, separator);
\r
2054 * concatenate the list with separator
\r
2057 * @param separator
\r
2058 * @return concatenated string
\r
2060 public String arrayToSeparatorList(String[] list, String separator)
\r
2062 StringBuffer v = new StringBuffer();
\r
2063 if (list != null && list.length > 0)
\r
2065 for (int i = 0, iSize = list.length; i < iSize; i++)
\r
2067 if (list[i] != null)
\r
2071 v.append(separator);
\r
2073 v.append(list[i]);
\r
2078 System.err.println("Returning '" + separator
\r
2079 + "' separated List:\n");
\r
2080 System.err.println(v);
\r
2082 return v.toString();
\r
2086 System.err.println("Returning empty '" + separator
\r
2087 + "' separated List\n");
\r
2089 return "" + separator;
\r
2093 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
\r
2095 public String getFeatureGroups()
\r
2097 String lst = arrayToSeparatorList(getDefaultTargetFrame()
\r
2098 .getFeatureGroups());
\r
2103 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame)
\r
2105 public String getFeatureGroupsOn(AlignFrame alf)
\r
2107 String lst = arrayToSeparatorList(alf.getFeatureGroups());
\r
2112 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
\r
2114 public String getFeatureGroupsOfState(boolean visible)
\r
2116 return arrayToSeparatorList(getDefaultTargetFrame()
\r
2117 .getFeatureGroupsOfState(visible));
\r
2121 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui.AlignFrame, boolean)
\r
2123 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
\r
2125 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
\r
2129 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.AlignFrame, java.lang.String, boolean)
\r
2131 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
\r
2134 boolean st = state;// !(state==null || state.equals("") ||
\r
2135 // state.toLowerCase().equals("false"));
\r
2136 alf.setFeatureGroupState(separatorListToArray(groups), st);
\r
2140 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String, boolean)
\r
2142 public void setFeatureGroupState(String groups, boolean state)
\r
2144 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
\r
2148 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
\r
2150 public String getSeparator()
\r
2156 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
\r
2158 public void setSeparator(String separator)
\r
2160 if (separator == null || separator.length() < 1)
\r
2162 // reset to default
\r
2163 separator = "" + ((char) 0x00AC);
\r
2165 this.separator = separator;
\r
2168 System.err.println("Default Separator now: '" + separator + "'");
\r
2173 * get boolean value of applet parameter 'name' and return default if
\r
2174 * parameter is not set
\r
2177 * name of paremeter
\r
2179 * the value to return otherwise
\r
2180 * @return true or false
\r
2182 public boolean getDefaultParameter(String name, boolean def)
\r
2185 if ((stn = getParameter(name)) == null)
\r
2189 if (stn.toLowerCase().equals("true"))
\r
2197 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame, java.lang.String, java.lang.String, java.lang.String)
\r
2199 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
\r
2200 String pdbEntryString, String pdbFile)
\r
2202 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
\r
2205 protected void setAlignPdbStructures(boolean alignPdbStructures)
\r
2207 this.alignPdbStructures = alignPdbStructures;
\r
2210 public boolean isAlignPdbStructures()
\r
2212 return alignPdbStructures;
\r
2215 public void start()
\r
2217 // callInitCallback();
\r
2219 private Hashtable<String,long[]> jshashes=new Hashtable<String,long[]>();
\r
2220 private Hashtable<String,Hashtable<String,String[]>> jsmessages=new Hashtable<String,Hashtable<String,String[]>>();
\r
2221 public void setJsMessageSet(String messageclass, String viewId,
\r
2222 String[] colcommands)
\r
2224 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2227 msgset=new Hashtable<String,String[]>();
\r
2228 jsmessages.put(messageclass, msgset);
\r
2230 msgset.put(viewId, colcommands);
\r
2231 long[] l = new long[colcommands.length];
\r
2232 for (int i=0;i<colcommands.length;i++) { l[i] = colcommands[i].hashCode();}
\r
2233 jshashes.put(messageclass+"|"+viewId,l);
\r
2236 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String, java.lang.String)
\r
2238 public String getJsMessage(String messageclass, String viewId)
\r
2240 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2243 String[] msgs = msgset.get(viewId);
\r
2246 for (int i=0;i<msgs.length;i++) {
\r
2247 if (msgs[i]!=null) {
\r
2248 String m = msgs[i];
\r
2258 public boolean isJsMessageSetChanged(String string, String string2,
\r
2259 String[] colcommands)
\r
2261 long[] l=jshashes.get(string+"|"+string2);
\r
2262 if (l==null && colcommands!=null)
\r
2266 for (int i=0;i<colcommands.length;i++) { if (l[i] != colcommands[i].hashCode()) { return true; }}
\r
2270 private Vector jsExecQueue=new Vector();
\r
2271 public Vector getJsExecQueue()
\r
2273 return jsExecQueue;
\r
2276 public void setExecutor(JSFunctionExec jsFunctionExec2)
\r
2278 jsFunctionExec=jsFunctionExec2;
\r
2282 * return the given colour value parameter or the given default if parameter not given
\r
2284 * @param defcolour
\r
2287 public Color getDefaultColourParameter(String colparam, Color defcolour)
\r
2289 String colprop = getParameter(colparam);
\r
2290 if (colprop==null || colprop.trim().length()==0)
\r
2294 Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
\r
2298 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
\r
2299 } catch (Exception ex)
\r
2301 System.err.println("Couldn't parse '"+colprop+"' as a colour for "+colparam);
\r
2305 return (col==null) ? defcolour: col;
\r
2309 public void openJalviewHelpUrl()
\r
2311 String helpUrl=getParameter("jalviewhelpurl");
\r
2312 if (helpUrl==null || helpUrl.trim().length()<5)
\r
2314 helpUrl="http://www.jalview.org/help.html";
\r
2316 showURL(helpUrl, "HELP");
\r
2320 * form a complete URL given a path to a resource and a reference location on the same server
\r
2321 * @param url - an absolute path on the same server as localref or a document located relative to localref
\r
2322 * @param localref - a URL on the same server as url
\r
2323 * @return a complete URL for the resource located by url
\r
2325 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
\r
2327 String codebase = localref.toString();
\r
2328 if (url.indexOf("/") == 0)
\r
2330 url = codebase.substring(0, codebase.length()
\r
2331 - localref.getFile().length())
\r
2336 url = localref + url;
\r
2342 * open a URL in the browser - resolving it according to relative refs and coping with javascript: protocol if necessary.
\r
2346 public void showURL(String url, String target)
\r
2350 if (url.indexOf(":") == -1)
\r
2352 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
\r
2354 // Should really use docbase, not codebase.
\r
2356 url = resolveUrlForLocalOrAbsolute(url, prepend=getDefaultParameter("resolvetocodebase", false) ? getDocumentBase() : getCodeBase());
\r
2358 System.err.println("Show url (prepended "+prepend+" - toggle resolvetocodebase if code/docbase resolution is wrong): " + url);
\r
2364 System.err.println("Show url: " + url);
\r
2367 if (url.indexOf("javascript:") == 0)
\r
2369 // no target for the javascript context
\r
2370 getAppletContext().showDocument(
\r
2371 new java.net.URL(url));
\r
2375 getAppletContext().showDocument(
\r
2376 new java.net.URL(url), target);
\r
2378 } catch (Exception ex)
\r
2380 ex.printStackTrace();
\r
2385 * bind structures in a viewer to any matching sequences in an alignFrame (use
\r
2386 * sequenceIds to limit scope of search to specific sequences)
\r
2390 * @param sequenceIds
\r
2391 * @return TODO: consider making an exception structure for indicating when
\r
2392 * binding fails public SequenceStructureBinding
\r
2393 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
\r
2396 * if (sequenceIds != null && sequenceIds.length() > 0) { return
\r
2397 * alFrame.addStructureViewInstance(viewer,
\r
2398 * separatorListToArray(sequenceIds)); } else { return
\r
2399 * alFrame.addStructureViewInstance(viewer, null); } // return null; }
\r