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.EventQueue;
\r
49 import java.awt.Font;
\r
50 import java.awt.Frame;
\r
51 import java.awt.Graphics;
\r
52 import java.awt.event.ActionEvent;
\r
53 import java.awt.event.WindowAdapter;
\r
54 import java.awt.event.WindowEvent;
\r
55 import java.io.BufferedReader;
\r
56 import java.io.InputStreamReader;
\r
57 import java.net.URL;
\r
58 import java.util.Hashtable;
\r
59 import java.util.StringTokenizer;
\r
60 import java.util.Vector;
\r
62 import netscape.javascript.JSObject;
\r
65 * Jalview Applet. Runs in Java 1.18 runtime
\r
68 * @version $Revision: 1.92 $
\r
70 public class JalviewLite extends Applet implements
\r
71 StructureSelectionManagerProvider, JalviewLiteJsApi
\r
74 public StructureSelectionManager getStructureSelectionManager()
\r
76 return StructureSelectionManager.getStructureSelectionManager(this);
\r
79 // /////////////////////////////////////////
\r
80 // The following public methods maybe called
\r
81 // externally, eg via javascript in HTML page
\r
85 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
\r
87 public String getSelectedSequences()
\r
89 return getSelectedSequencesFrom(getDefaultTargetFrame());
\r
95 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
\r
97 public String getSelectedSequences(String sep)
\r
99 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
\r
106 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
\r
109 public String getSelectedSequencesFrom(AlignFrame alf)
\r
111 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
\r
118 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
\r
119 * .AlignFrame, java.lang.String)
\r
121 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
\r
123 StringBuffer result = new StringBuffer("");
\r
124 if (sep == null || sep.length() == 0)
\r
126 sep = separator; // "+0x00AC;
\r
128 if (alf.viewport.getSelectionGroup() != null)
\r
130 SequenceI[] seqs = alf.viewport.getSelectionGroup()
\r
131 .getSequencesInOrder(alf.viewport.getAlignment());
\r
133 for (int i = 0; i < seqs.length; i++)
\r
135 result.append(seqs[i].getName());
\r
136 result.append(sep);
\r
140 return result.toString();
\r
146 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
\r
147 * java.lang.String, java.lang.String)
\r
149 public void highlight(String sequenceId, String position,
\r
150 String alignedPosition)
\r
152 highlightIn(getDefaultTargetFrame(), sequenceId, position,
\r
159 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
\r
160 * java.lang.String, java.lang.String, java.lang.String)
\r
162 public void highlightIn(final AlignFrame alf, final String sequenceId,
\r
163 final String position, final String alignedPosition)
\r
165 // TODO: could try to highlight in all alignments if alf==null
\r
166 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
167 alf.viewport.getAlignment().getSequencesArray());
\r
168 final SequenceI sq = matcher.findIdMatch(sequenceId);
\r
174 apos = new Integer(position).intValue();
\r
176 } catch (NumberFormatException ex)
\r
180 final StructureSelectionManagerProvider me = this;
\r
181 final int pos = apos;
\r
182 // use vamsas listener to broadcast to all listeners in scope
\r
183 if (alignedPosition != null
\r
184 && (alignedPosition.trim().length() == 0 || alignedPosition
\r
185 .toLowerCase().indexOf("false") > -1))
\r
187 java.awt.EventQueue.invokeLater(new Runnable()
\r
192 StructureSelectionManager.getStructureSelectionManager(me)
\r
193 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
\r
199 java.awt.EventQueue.invokeLater(new Runnable()
\r
204 StructureSelectionManager.getStructureSelectionManager(me)
\r
205 .mouseOverVamsasSequence(sq, pos, null);
\r
215 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
\r
216 * java.lang.String)
\r
218 public void select(String sequenceIds, String columns)
\r
220 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
\r
226 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
\r
227 * java.lang.String, java.lang.String)
\r
229 public void select(String sequenceIds, String columns, String sep)
\r
231 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
\r
237 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
\r
238 * java.lang.String, java.lang.String)
\r
240 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
\r
242 selectIn(alf, sequenceIds, columns, separator);
\r
248 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
\r
249 * java.lang.String, java.lang.String, java.lang.String)
\r
251 public void selectIn(final AlignFrame alf, String sequenceIds,
\r
252 String columns, String sep)
\r
254 if (sep == null || sep.length() == 0)
\r
262 System.err.println("Selecting region using separator string '"
\r
263 + separator + "'");
\r
267 String[] ids = separatorListToArray(sequenceIds, sep);
\r
268 String[] cols = separatorListToArray(columns, sep);
\r
269 final SequenceGroup sel = new SequenceGroup();
\r
270 final ColumnSelection csel = new ColumnSelection();
\r
271 AlignmentI al = alf.viewport.getAlignment();
\r
272 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
273 alf.viewport.getAlignment().getSequencesArray());
\r
274 int start = 0, end = al.getWidth(), alw = al.getWidth();
\r
275 boolean seqsfound = true;
\r
276 if (ids != null && ids.length > 0)
\r
279 for (int i = 0; i < ids.length; i++)
\r
281 if (ids[i].trim().length() == 0)
\r
285 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
289 sel.addSequence(sq, false);
\r
293 boolean inseqpos = false;
\r
294 if (cols != null && cols.length > 0)
\r
296 boolean seset = false;
\r
297 for (int i = 0; i < cols.length; i++)
\r
299 String cl = cols[i].trim();
\r
300 if (cl.length() == 0)
\r
305 if ((p = cl.indexOf("-")) > -1)
\r
307 int from = -1, to = -1;
\r
310 from = new Integer(cl.substring(0, p)).intValue();
\r
312 } catch (NumberFormatException ex)
\r
315 .println("ERROR: Couldn't parse first integer in range element column selection string '"
\r
316 + cl + "' - format is 'from-to'");
\r
321 to = new Integer(cl.substring(p + 1)).intValue();
\r
323 } catch (NumberFormatException ex)
\r
326 .println("ERROR: Couldn't parse second integer in range element column selection string '"
\r
327 + cl + "' - format is 'from-to'");
\r
330 if (from >= 0 && to >= 0)
\r
347 // comment to prevent range extension
\r
357 for (int r = from; r <= to; r++)
\r
359 if (r >= 0 && r < alw)
\r
361 csel.addElement(r);
\r
366 System.err.println("Range '" + cl + "' deparsed as [" + from
\r
372 System.err.println("ERROR: Invalid Range '" + cl
\r
373 + "' deparsed as [" + from + "," + to + "]");
\r
381 r = new Integer(cl).intValue();
\r
383 } catch (NumberFormatException ex)
\r
385 if (cl.toLowerCase().equals("sequence"))
\r
387 // we are in the dataset sequence's coordinate frame.
\r
393 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
\r
398 if (r >= 0 && r <= alw)
\r
408 // comment to prevent range extension
\r
418 csel.addElement(r);
\r
421 System.err.println("Point selection '" + cl
\r
422 + "' deparsed as [" + r + "]");
\r
427 System.err.println("ERROR: Invalid Point selection '" + cl
\r
428 + "' deparsed as [" + r + "]");
\r
435 // we only propagate the selection when it was the null selection, or the
\r
436 // given sequences were found in the alignment.
\r
437 if (inseqpos && sel.getSize() > 0)
\r
439 // assume first sequence provides reference frame ?
\r
440 SequenceI rs = sel.getSequenceAt(0);
\r
441 start = rs.findIndex(start);
\r
442 end = rs.findIndex(end);
\r
445 Vector cs = csel.getSelected();
\r
447 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
\r
449 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
\r
454 sel.setStartRes(start);
\r
455 sel.setEndRes(end);
\r
456 EventQueue.invokeLater(new Runnable()
\r
461 alf.select(sel, csel);
\r
471 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
\r
472 * String, java.lang.String)
\r
474 public String getSelectedSequencesAsAlignment(String format, String suffix)
\r
476 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
\r
484 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
\r
485 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
\r
487 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
\r
488 String format, String suffix)
\r
492 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
493 if (alf.viewport.getSelectionGroup() != null)
\r
495 String reply = new AppletFormatAdapter().formatSequences(format,
\r
496 new Alignment(alf.viewport.getSelectionAsNewSequence()),
\r
500 } catch (Exception ex)
\r
502 ex.printStackTrace();
\r
503 return "Error retrieving alignment in " + format + " format. ";
\r
511 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
\r
513 public String getAlignmentOrder()
\r
515 return getAlignmentOrderFrom(getDefaultTargetFrame());
\r
522 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
\r
525 public String getAlignmentOrderFrom(AlignFrame alf)
\r
527 return getAlignmentOrderFrom(alf, separator);
\r
534 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
\r
535 * , java.lang.String)
\r
537 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
\r
539 AlignmentI alorder = alf.getAlignViewport().getAlignment();
\r
540 String[] order = new String[alorder.getHeight()];
\r
541 for (int i = 0; i < order.length; i++)
\r
543 order[i] = alorder.getSequenceAt(i).getName();
\r
545 return arrayToSeparatorList(order);
\r
551 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
\r
552 * java.lang.String)
\r
554 public String orderBy(String order, String undoName)
\r
556 return orderBy(order, undoName, separator);
\r
562 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
\r
563 * java.lang.String, java.lang.String)
\r
565 public String orderBy(String order, String undoName, String sep)
\r
567 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
\r
574 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
\r
575 * java.lang.String, java.lang.String, java.lang.String)
\r
577 public String orderAlignmentBy(AlignFrame alf, String order,
\r
578 String undoName, String sep)
\r
580 String[] ids = separatorListToArray(order, sep);
\r
581 SequenceI[] sqs = null;
\r
582 if (ids != null && ids.length > 0)
\r
584 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
585 alf.viewport.getAlignment().getSequencesArray());
\r
587 sqs = new SequenceI[ids.length];
\r
588 for (int i = 0; i < ids.length; i++)
\r
590 if (ids[i].trim().length() == 0)
\r
594 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
602 SequenceI[] sqq = new SequenceI[s];
\r
603 System.arraycopy(sqs, 0, sqq, 0, s);
\r
616 final AlignmentOrder aorder = new AlignmentOrder(sqs);
\r
618 if (undoName != null && undoName.trim().length() == 0)
\r
622 final String _undoName = undoName;
\r
623 // TODO: deal with synchronization here: cannot raise any events until after
\r
624 // this has returned.
\r
625 return alf.sortBy(aorder, _undoName) ? "true" : "";
\r
631 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
\r
633 public String getAlignment(String format)
\r
635 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
\r
642 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
\r
643 * java.lang.String)
\r
645 public String getAlignmentFrom(AlignFrame alf, String format)
\r
647 return getAlignmentFrom(alf, format, "true");
\r
653 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
\r
654 * java.lang.String)
\r
656 public String getAlignment(String format, String suffix)
\r
658 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
\r
665 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
\r
666 * java.lang.String, java.lang.String)
\r
668 public String getAlignmentFrom(AlignFrame alf, String format,
\r
673 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
675 String reply = new AppletFormatAdapter().formatSequences(format,
\r
676 alf.viewport.getAlignment(), seqlimits);
\r
678 } catch (Exception ex)
\r
680 ex.printStackTrace();
\r
681 return "Error retrieving alignment in " + format + " format. ";
\r
688 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
\r
690 public void loadAnnotation(String annotation)
\r
692 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
\r
699 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
\r
700 * , java.lang.String)
\r
702 public void loadAnnotationFrom(AlignFrame alf, String annotation)
\r
704 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
\r
705 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
\r
707 alf.alignPanel.fontChanged();
\r
708 alf.alignPanel.setScrollValues(0, 0);
\r
712 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
\r
719 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
\r
721 public String getFeatures(String format)
\r
723 return getFeaturesFrom(getDefaultTargetFrame(), format);
\r
730 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
\r
731 * java.lang.String)
\r
733 public String getFeaturesFrom(AlignFrame alf, String format)
\r
735 return alf.outputFeatures(false, format);
\r
741 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
\r
743 public String getAnnotation()
\r
745 return getAnnotationFrom(getDefaultTargetFrame());
\r
752 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
\r
755 public String getAnnotationFrom(AlignFrame alf)
\r
757 return alf.outputAnnotations(false);
\r
763 * @see jalview.bin.JalviewLiteJsApi#newView()
\r
765 public AlignFrame newView()
\r
767 return newViewFrom(getDefaultTargetFrame());
\r
773 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
\r
775 public AlignFrame newView(String name)
\r
777 return newViewFrom(getDefaultTargetFrame(), name);
\r
783 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
\r
785 public AlignFrame newViewFrom(AlignFrame alf)
\r
787 return alf.newView(null);
\r
793 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
\r
794 * java.lang.String)
\r
796 public AlignFrame newViewFrom(AlignFrame alf, String name)
\r
798 return alf.newView(name);
\r
804 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
\r
805 * java.lang.String)
\r
807 public AlignFrame loadAlignment(String text, String title)
\r
809 Alignment al = null;
\r
811 String format = new IdentifyFile().Identify(text,
\r
812 AppletFormatAdapter.PASTE);
\r
815 al = new AppletFormatAdapter().readFile(text,
\r
816 AppletFormatAdapter.PASTE, format);
\r
817 if (al.getHeight() > 0)
\r
819 return new AlignFrame(al, this, title, false);
\r
821 } catch (java.io.IOException ex)
\r
823 ex.printStackTrace();
\r
831 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
\r
833 public void setMouseoverListener(String listener)
\r
835 setMouseoverListener(currentAlignFrame, listener);
\r
838 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
\r
844 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
\r
845 * , java.lang.String)
\r
847 public void setMouseoverListener(AlignFrame af, String listener)
\r
849 if (listener != null)
\r
851 listener = listener.trim();
\r
852 if (listener.length() == 0)
\r
855 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
\r
859 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
\r
860 this, af, listener);
\r
861 javascriptListeners.addElement(mol);
\r
862 StructureSelectionManager.getStructureSelectionManager(this)
\r
863 .addStructureViewerListener(mol);
\r
866 System.err.println("Added a mouseover listener for "
\r
867 + ((af == null) ? "All frames" : "Just views for "
\r
868 + af.getAlignViewport().getSequenceSetId()));
\r
869 System.err.println("There are now " + javascriptListeners.size()
\r
870 + " listeners in total.");
\r
877 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
\r
879 public void setSelectionListener(String listener)
\r
881 setSelectionListener(null, listener);
\r
888 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
\r
889 * , java.lang.String)
\r
891 public void setSelectionListener(AlignFrame af, String listener)
\r
893 if (listener != null)
\r
895 listener = listener.trim();
\r
896 if (listener.length() == 0)
\r
899 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
903 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
\r
904 this, af, listener);
\r
905 javascriptListeners.addElement(mol);
\r
906 StructureSelectionManager.getStructureSelectionManager(this)
\r
907 .addSelectionListener(mol);
\r
910 System.err.println("Added a selection listener for "
\r
911 + ((af == null) ? "All frames" : "Just views for "
\r
912 + af.getAlignViewport().getSequenceSetId()));
\r
913 System.err.println("There are now " + javascriptListeners.size()
\r
914 + " listeners in total.");
\r
921 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
\r
922 * java.lang.String)
\r
924 public void setStructureListener(String listener, String modelSet)
\r
926 if (listener != null)
\r
928 listener = listener.trim();
\r
929 if (listener.length() == 0)
\r
932 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
936 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
\r
937 this, listener, separatorListToArray(modelSet));
\r
938 javascriptListeners.addElement(mol);
\r
939 StructureSelectionManager.getStructureSelectionManager(this)
\r
940 .addStructureViewerListener(mol);
\r
943 System.err.println("Added a javascript structure viewer listener '"
\r
945 System.err.println("There are now " + javascriptListeners.size()
\r
946 + " listeners in total.");
\r
954 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
\r
955 * .AlignFrame, java.lang.String)
\r
957 public void removeJavascriptListener(AlignFrame af, String listener)
\r
959 if (listener != null)
\r
961 listener = listener.trim();
\r
962 if (listener.length() == 0)
\r
967 boolean rprt = false;
\r
968 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
\r
970 Object lstn = javascriptListeners.elementAt(ms);
\r
971 JsCallBack lstner = (JsCallBack) lstn;
\r
972 if ((af == null || lstner.getAlignFrame() == af)
\r
973 && (listener == null || lstner.getListenerFunction().equals(
\r
976 javascriptListeners.removeElement(lstner);
\r
978 if (lstner instanceof SelectionListener)
\r
980 StructureSelectionManager.getStructureSelectionManager(this)
\r
981 .removeSelectionListener((SelectionListener) lstner);
\r
985 StructureSelectionManager.getStructureSelectionManager(this)
\r
986 .removeStructureViewerListener(lstner, null);
\r
991 System.err.println("Removed listener '" + listener + "'");
\r
1001 System.err.println("There are now " + javascriptListeners.size()
\r
1002 + " listeners in total.");
\r
1006 public void stop()
\r
1008 System.err.println("Applet " + getName() + " stop().");
\r
1012 public void destroy()
\r
1014 System.err.println("Applet " + getName() + " destroy().");
\r
1018 private void tidyUp()
\r
1021 if (currentAlignFrame != null && currentAlignFrame.viewport != null
\r
1022 && currentAlignFrame.viewport.applet != null)
\r
1024 AlignViewport av = currentAlignFrame.viewport;
\r
1025 currentAlignFrame.closeMenuItem_actionPerformed();
\r
1027 currentAlignFrame = null;
\r
1029 if (javascriptListeners != null)
\r
1031 while (javascriptListeners.size() > 0)
\r
1033 jalview.javascript.JSFunctionExec mol = javascriptListeners
\r
1035 javascriptListeners.removeElement(mol);
\r
1036 if (mol instanceof SelectionListener)
\r
1038 StructureSelectionManager.getStructureSelectionManager(this)
\r
1039 .removeSelectionListener((SelectionListener) mol);
\r
1043 StructureSelectionManager.getStructureSelectionManager(this)
\r
1044 .removeStructureViewerListener(mol, null);
\r
1046 mol.jvlite = null;
\r
1049 if (jsFunctionExec != null)
\r
1051 jsFunctionExec.stopQueue();
\r
1052 jsFunctionExec.jvlite = null;
\r
1054 initialAlignFrame = null;
\r
1055 jsFunctionExec = null;
\r
1056 javascriptListeners = null;
\r
1057 StructureSelectionManager.release(this);
\r
1060 private jalview.javascript.JSFunctionExec jsFunctionExec;
\r
1065 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
\r
1066 * java.lang.String, java.lang.String)
\r
1068 public void mouseOverStructure(final String pdbResNum,
\r
1069 final String chain, final String pdbfile)
\r
1071 final StructureSelectionManagerProvider me = this;
\r
1072 java.awt.EventQueue.invokeLater(new Runnable()
\r
1079 StructureSelectionManager.getStructureSelectionManager(me)
\r
1080 .mouseOverStructure(new Integer(pdbResNum).intValue(),
\r
1084 System.err.println("mouseOver for '" + pdbResNum
\r
1085 + "' in chain '" + chain + "' in structure '" + pdbfile
\r
1088 } catch (NumberFormatException e)
\r
1090 System.err.println("Ignoring invalid residue number string '"
\r
1091 + pdbResNum + "'");
\r
1102 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
\r
1103 * java.lang.String, java.lang.String)
\r
1105 public void scrollViewToIn(final AlignFrame alf, final String topRow,
\r
1106 final String leftHandColumn)
\r
1108 java.awt.EventQueue.invokeLater(new Runnable()
\r
1115 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
\r
1116 leftHandColumn).intValue());
\r
1118 } catch (Exception ex)
\r
1120 System.err.println("Couldn't parse integer arguments (topRow='"
\r
1121 + topRow + "' and leftHandColumn='" + leftHandColumn
\r
1123 ex.printStackTrace();
\r
1133 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
\r
1134 * .AlignFrame, java.lang.String)
\r
1137 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
\r
1140 java.awt.EventQueue.invokeLater(new Runnable()
\r
1147 alf.scrollToRow(new Integer(topRow).intValue());
\r
1149 } catch (Exception ex)
\r
1151 System.err.println("Couldn't parse integer arguments (topRow='"
\r
1153 ex.printStackTrace();
\r
1164 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
\r
1165 * .AlignFrame, java.lang.String)
\r
1168 public void scrollViewToColumnIn(final AlignFrame alf,
\r
1169 final String leftHandColumn)
\r
1171 java.awt.EventQueue.invokeLater(new Runnable()
\r
1179 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
\r
1181 } catch (Exception ex)
\r
1184 .println("Couldn't parse integer arguments (leftHandColumn='"
\r
1185 + leftHandColumn + "')");
\r
1186 ex.printStackTrace();
\r
1193 // //////////////////////////////////////////////
\r
1194 // //////////////////////////////////////////////
\r
1196 public static int lastFrameX = 200;
\r
1198 public static int lastFrameY = 200;
\r
1200 boolean fileFound = true;
\r
1202 String file = "No file";
\r
1204 Button launcher = new Button("Start Jalview");
\r
1207 * The currentAlignFrame is static, it will change if and when the user
\r
1208 * selects a new window. Note that it will *never* point back to the embedded
\r
1209 * AlignFrame if the applet is started as embedded on the page and then
\r
1210 * afterwards a new view is created.
\r
1212 public AlignFrame currentAlignFrame = null;
\r
1215 * This is the first frame to be displayed, and does not change. API calls
\r
1216 * will default to this instance if currentAlignFrame is null.
\r
1218 AlignFrame initialAlignFrame = null;
\r
1220 boolean embedded = false;
\r
1222 private boolean checkForJmol = true;
\r
1224 private boolean checkedForJmol = false; // ensure we don't check for jmol
\r
1226 // every time the app is re-inited
\r
1228 public boolean jmolAvailable = false;
\r
1230 private boolean alignPdbStructures = false;
\r
1233 * use an external structure viewer exclusively (no jmols or MCViews will be
\r
1234 * opened by JalviewLite itself)
\r
1236 public boolean useXtrnalSviewer = false;
\r
1238 public static boolean debug = false;
\r
1240 static String builddate = null, version = null;
\r
1242 private static void initBuildDetails()
\r
1244 if (builddate == null)
\r
1246 builddate = "unknown";
\r
1248 java.net.URL url = JalviewLite.class
\r
1249 .getResource("/.build_properties");
\r
1254 BufferedReader reader = new BufferedReader(new InputStreamReader(
\r
1255 url.openStream()));
\r
1257 while ((line = reader.readLine()) != null)
\r
1259 if (line.indexOf("VERSION") > -1)
\r
1261 version = line.substring(line.indexOf("=") + 1);
\r
1263 if (line.indexOf("BUILD_DATE") > -1)
\r
1265 builddate = line.substring(line.indexOf("=") + 1);
\r
1268 } catch (Exception ex)
\r
1270 ex.printStackTrace();
\r
1276 public static String getBuildDate()
\r
1278 initBuildDetails();
\r
1282 public static String getVersion()
\r
1284 initBuildDetails();
\r
1288 // public JSObject scriptObject = null;
\r
1291 * init method for Jalview Applet
\r
1293 public void init()
\r
1295 // remove any handlers that might be hanging around from an earlier instance
\r
1300 System.err.println("Applet context is '"
\r
1301 + getAppletContext().getClass().toString() + "'");
\r
1303 JSObject scriptObject = JSObject.getWindow(this);
\r
1304 if (debug && scriptObject != null)
\r
1306 System.err.println("Applet has Javascript callback support.");
\r
1309 } catch (Exception ex)
\r
1312 .println("Warning: No JalviewLite javascript callbacks available.");
\r
1315 ex.printStackTrace();
\r
1319 * turn on extra applet debugging
\r
1321 String dbg = getParameter("debug");
\r
1324 debug = dbg.toLowerCase().equals("true");
\r
1329 System.err.println("JalviewLite Version " + getVersion());
\r
1330 System.err.println("Build Date : " + getBuildDate());
\r
1333 String externalsviewer = getParameter("externalstructureviewer");
\r
1334 if (externalsviewer != null)
\r
1336 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
\r
1340 * if true disable the check for jmol
\r
1342 String chkforJmol = getParameter("nojmol");
\r
1343 if (chkforJmol != null)
\r
1345 checkForJmol = !chkforJmol.equals("true");
\r
1348 * get the separator parameter if present
\r
1350 String sep = getParameter("separator");
\r
1353 if (sep.length() > 0)
\r
1358 System.err.println("Separator set to '" + separator + "'");
\r
1364 "Invalid separator parameter - must be non-zero length");
\r
1370 String param = getParameter("RGB");
\r
1372 if (param != null)
\r
1376 r = Integer.parseInt(param.substring(0, 2), 16);
\r
1377 g = Integer.parseInt(param.substring(2, 4), 16);
\r
1378 b = Integer.parseInt(param.substring(4, 6), 16);
\r
1379 } catch (Exception ex)
\r
1386 param = getParameter("label");
\r
1387 if (param != null)
\r
1389 launcher.setLabel(param);
\r
1392 setBackground(new Color(r, g, b));
\r
1394 file = getParameter("file");
\r
1398 // Maybe the sequences are added as parameters
\r
1399 StringBuffer data = new StringBuffer("PASTE");
\r
1401 while ((file = getParameter("sequence" + i)) != null)
\r
1403 data.append(file.toString() + "\n");
\r
1406 if (data.length() > 5)
\r
1408 file = data.toString();
\r
1412 final JalviewLite jvapplet = this;
\r
1413 if (getParameter("embedded") != null
\r
1414 && getParameter("embedded").equalsIgnoreCase("true"))
\r
1416 // Launch as embedded applet in page
\r
1418 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1421 else if (file != null)
\r
1423 if (getParameter("showbutton") == null
\r
1424 || !getParameter("showbutton").equalsIgnoreCase("false"))
\r
1426 // Add the JalviewLite 'Button' to the page
\r
1428 launcher.addActionListener(new java.awt.event.ActionListener()
\r
1430 public void actionPerformed(ActionEvent e)
\r
1432 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1439 // Open jalviewLite immediately.
\r
1440 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1446 // jalview initialisation with no alignment. loadAlignment() method can
\r
1447 // still be called to open new alignments.
\r
1449 fileFound = false;
\r
1450 // callInitCallback();
\r
1454 private void callInitCallback()
\r
1456 String initjscallback = getParameter("oninit");
\r
1457 if (initjscallback == null)
\r
1461 initjscallback = initjscallback.trim();
\r
1462 if (initjscallback.length() > 0)
\r
1464 JSObject scriptObject = null;
\r
1467 scriptObject = JSObject.getWindow(this);
\r
1468 } catch (Exception ex)
\r
1472 if (scriptObject != null)
\r
1476 // do onInit with the JS executor thread
\r
1477 new JSFunctionExec(this).executeJavascriptFunction(true,
\r
1478 initjscallback, null, "Calling oninit callback '"
\r
1479 + initjscallback + "'.");
\r
1480 } catch (Exception e)
\r
1482 System.err.println("Exception when executing _oninit callback '"
\r
1483 + initjscallback + "'.");
\r
1484 e.printStackTrace();
\r
1489 System.err.println("Not executing _oninit callback '"
\r
1490 + initjscallback + "' - no scripting allowed.");
\r
1496 * Initialises and displays a new java.awt.Frame
\r
1499 * java.awt.Frame to be displayed
\r
1501 * title of new frame
\r
1503 * width if new frame
\r
1505 * height of new frame
\r
1507 public static void addFrame(final Frame frame, String title, int width,
\r
1510 frame.setLocation(lastFrameX, lastFrameY);
\r
1513 frame.setSize(width, height);
\r
1514 frame.setTitle(title);
\r
1515 frame.addWindowListener(new WindowAdapter()
\r
1517 public void windowClosing(WindowEvent e)
\r
1519 if (frame instanceof AlignFrame)
\r
1521 AlignViewport vp = ((AlignFrame) frame).viewport;
\r
1522 ((AlignFrame) frame).closeMenuItem_actionPerformed();
\r
1523 if (vp.applet.currentAlignFrame == frame)
\r
1525 vp.applet.currentAlignFrame = null;
\r
1533 if (frame instanceof EmbmenuFrame)
\r
1535 ((EmbmenuFrame) frame).destroyMenus();
\r
1537 frame.setMenuBar(null);
\r
1541 public void windowActivated(WindowEvent e)
\r
1543 if (frame instanceof AlignFrame)
\r
1545 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
\r
1548 System.err.println("Activated window " + frame);
\r
1552 super.windowActivated(e);
\r
1555 * Probably not necessary to do this - see TODO above. (non-Javadoc)
\r
1558 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
\r
1561 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
\r
1562 * frame) { currentAlignFrame = null; if (debug) {
\r
1563 * System.err.println("Deactivated window "+frame); } }
\r
1564 * super.windowDeactivated(e); }
\r
1567 frame.setVisible(true);
\r
1571 * This paints the background surrounding the "Launch Jalview button" <br>
\r
1573 * If file given in parameter not found, displays error message
\r
1576 * graphics context
\r
1578 public void paint(Graphics g)
\r
1582 g.setColor(new Color(200, 200, 200));
\r
1583 g.setColor(Color.cyan);
\r
1584 g.fillRect(0, 0, getSize().width, getSize().height);
\r
1585 g.setColor(Color.red);
\r
1586 g.drawString("Jalview can't open file", 5, 15);
\r
1587 g.drawString("\"" + file + "\"", 5, 30);
\r
1589 else if (embedded)
\r
1591 g.setColor(Color.black);
\r
1592 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
1593 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
\r
1594 g.drawString("Loading Data...", 50, getSize().height / 2);
\r
1599 * get all components associated with the applet of the given type
\r
1604 public Vector getAppletWindow(Class class1)
\r
1606 Vector wnds = new Vector();
\r
1607 Component[] cmp = getComponents();
\r
1610 for (int i = 0; i < cmp.length; i++)
\r
1612 if (class1.isAssignableFrom(cmp[i].getClass()))
\r
1614 wnds.addElement(cmp);
\r
1621 class LoadJmolThread extends Thread
\r
1623 private boolean running = false;
\r
1627 if (running || checkedForJmol)
\r
1636 if (!System.getProperty("java.version").startsWith("1.1"))
\r
1638 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
\r
1639 jmolAvailable = true;
\r
1641 if (!jmolAvailable)
\r
1644 .println("Jmol not available - Using MCview for structures");
\r
1646 } catch (java.lang.ClassNotFoundException ex)
\r
1652 jmolAvailable = false;
\r
1656 .println("Skipping Jmol check. Will use MCView (probably)");
\r
1659 checkedForJmol = true;
\r
1663 public boolean notFinished()
\r
1665 return running || !checkedForJmol;
\r
1669 class LoadingThread extends Thread
\r
1672 * State variable: File source
\r
1677 * State variable: protocol for access to file source
\r
1682 * State variable: format of file source
\r
1688 JalviewLite applet;
\r
1690 private void dbgMsg(String msg)
\r
1694 System.err.println(msg);
\r
1699 * update the protocol state variable for accessing the datasource located
\r
1703 * @return possibly updated datasource string
\r
1705 public String setProtocolState(String file)
\r
1707 if (file.startsWith("PASTE"))
\r
1709 file = file.substring(5);
\r
1710 protocol = AppletFormatAdapter.PASTE;
\r
1712 else if (inArchive(file))
\r
1714 protocol = AppletFormatAdapter.CLASSLOADER;
\r
1718 file = addProtocol(file);
\r
1719 protocol = AppletFormatAdapter.URL;
\r
1721 dbgMsg("Protocol identified as '" + protocol + "'");
\r
1725 public LoadingThread(String _file, JalviewLite _applet)
\r
1727 this._file = _file;
\r
1733 LoadJmolThread jmolchecker = new LoadJmolThread();
\r
1734 jmolchecker.start();
\r
1735 while (jmolchecker.notFinished())
\r
1737 // wait around until the Jmol check is complete.
\r
1741 } catch (Exception e)
\r
1747 // applet.callInitCallback();
\r
1750 private void startLoading()
\r
1752 AlignFrame newAlignFrame;
\r
1753 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
\r
1754 file = setProtocolState(_file);
\r
1756 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
1757 dbgMsg("File identified as '" + format + "'");
\r
1758 dbgMsg("Loading started.");
\r
1759 Alignment al = null;
\r
1762 al = new AppletFormatAdapter().readFile(file, protocol, format);
\r
1763 } catch (java.io.IOException ex)
\r
1765 dbgMsg("File load exception.");
\r
1766 ex.printStackTrace();
\r
1771 FileParse fp = new FileParse(file, protocol);
\r
1773 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
\r
1774 + protocol + ")");
\r
1775 while ((ln = fp.nextLine()) != null)
\r
1779 dbgMsg(">>>Dump finished.");
\r
1780 } catch (Exception e)
\r
1783 .println("Exception when trying to dump the content of the file parameter.");
\r
1784 e.printStackTrace();
\r
1788 if ((al != null) && (al.getHeight() > 0))
\r
1790 dbgMsg("Successfully loaded file.");
\r
1791 newAlignFrame = new AlignFrame(al, applet, file, embedded);
\r
1792 if (initialAlignFrame == null)
\r
1794 initialAlignFrame = newAlignFrame;
\r
1796 // update the focus.
\r
1797 currentAlignFrame = newAlignFrame;
\r
1799 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
\r
1801 newAlignFrame.setTitle("Sequences from "
\r
1802 + applet.getDocumentBase());
\r
1805 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
1807 String treeFile = applet.getParameter("tree");
\r
1808 if (treeFile == null)
\r
1810 treeFile = applet.getParameter("treeFile");
\r
1813 if (treeFile != null)
\r
1817 treeFile = setProtocolState(treeFile);
\r
1819 * if (inArchive(treeFile)) { protocol =
\r
1820 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
\r
1821 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
\r
1823 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
\r
1828 if (fin.getTree() != null)
\r
1830 newAlignFrame.loadTree(fin, treeFile);
\r
1831 dbgMsg("Successfuly imported tree.");
\r
1835 dbgMsg("Tree parameter did not resolve to a valid tree.");
\r
1837 } catch (Exception ex)
\r
1839 ex.printStackTrace();
\r
1843 String param = applet.getParameter("features");
\r
1844 if (param != null)
\r
1846 param = setProtocolState(param);
\r
1848 newAlignFrame.parseFeaturesFile(param, protocol);
\r
1851 param = applet.getParameter("showFeatureSettings");
\r
1852 if (param != null && param.equalsIgnoreCase("true"))
\r
1854 newAlignFrame.viewport.showSequenceFeatures(true);
\r
1855 new FeatureSettings(newAlignFrame.alignPanel);
\r
1858 param = applet.getParameter("annotations");
\r
1859 if (param != null)
\r
1861 param = setProtocolState(param);
\r
1863 if (new AnnotationFile().readAnnotationFile(
\r
1864 newAlignFrame.viewport.getAlignment(), param, protocol))
\r
1866 newAlignFrame.alignPanel.fontChanged();
\r
1867 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1872 .println("Annotations were not added from annotation file '"
\r
1878 param = applet.getParameter("jnetfile");
\r
1879 if (param != null)
\r
1883 param = setProtocolState(param);
\r
1884 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
\r
1886 JnetAnnotationMaker.add_annotation(predictions,
\r
1887 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
\r
1895 newAlignFrame.alignPanel.fontChanged();
\r
1896 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1897 } catch (Exception ex)
\r
1899 ex.printStackTrace();
\r
1903 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
\r
1904 * - related to JAL-434
\r
1906 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
\r
1909 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
\r
1910 * PDB|1GAQ|1GAQ|C">
\r
1912 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
\r
1914 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
\r
1917 int pdbFileCount = 0;
\r
1918 // Accumulate pdbs here if they are heading for the same view (if
\r
1919 // alignPdbStructures is true)
\r
1920 Vector pdbs = new Vector();
\r
1921 // create a lazy matcher if we're asked to
\r
1922 jalview.analysis.SequenceIdMatcher matcher = (applet
\r
1923 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
\r
1924 newAlignFrame.getAlignViewport().getAlignment()
\r
1925 .getSequencesArray()) : null;
\r
1929 if (pdbFileCount > 0)
\r
1931 param = applet.getParameter("PDBFILE" + pdbFileCount);
\r
1935 param = applet.getParameter("PDBFILE");
\r
1938 if (param != null)
\r
1940 PDBEntry pdb = new PDBEntry();
\r
1943 SequenceI[] seqs = null;
\r
1944 String[] chains = null;
\r
1946 StringTokenizer st = new StringTokenizer(param, " ");
\r
1948 if (st.countTokens() < 2)
\r
1950 String sequence = applet.getParameter("PDBSEQ");
\r
1951 if (sequence != null)
\r
1952 seqs = new SequenceI[]
\r
1953 { matcher == null ? (Sequence) newAlignFrame
\r
1954 .getAlignViewport().getAlignment()
\r
1955 .findName(sequence) : matcher.findIdMatch(sequence) };
\r
1960 param = st.nextToken();
\r
1961 Vector tmp = new Vector();
\r
1962 Vector tmp2 = new Vector();
\r
1964 while (st.hasMoreTokens())
\r
1966 seqstring = st.nextToken();
\r
1967 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
\r
1968 if (st2.countTokens() > 1)
\r
1970 // This is the chain
\r
1971 tmp2.addElement(st2.nextToken());
\r
1972 seqstring = st2.nextToken();
\r
1974 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
\r
1975 .getAlignViewport().getAlignment()
\r
1976 .findName(seqstring) : matcher
\r
1977 .findIdMatch(seqstring));
\r
1980 seqs = new SequenceI[tmp.size()];
\r
1981 tmp.copyInto(seqs);
\r
1982 if (tmp2.size() == tmp.size())
\r
1984 chains = new String[tmp2.size()];
\r
1985 tmp2.copyInto(chains);
\r
1988 param = setProtocolState(param);
\r
1990 if (// !jmolAvailable
\r
1992 protocol == AppletFormatAdapter.CLASSLOADER
\r
1993 && !useXtrnalSviewer)
\r
1995 // Re: JAL-357 : the bug isn't a problem if we are using an
\r
1996 // external viewer!
\r
1997 // TODO: verify this Re:
\r
1998 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
\r
1999 // This exception preserves the current behaviour where, even if
\r
2000 // the local pdb file was identified in the class loader
\r
2001 protocol = AppletFormatAdapter.URL; // this is probably NOT
\r
2003 param = addProtocol(param); //
\r
2006 pdb.setFile(param);
\r
2010 for (int i = 0; i < seqs.length; i++)
\r
2012 if (seqs[i] != null)
\r
2014 ((Sequence) seqs[i]).addPDBId(pdb);
\r
2018 if (JalviewLite.debug)
\r
2020 // this may not really be a problem but we give a warning
\r
2023 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
\r
2029 if (!alignPdbStructures)
\r
2031 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
\r
2036 pdbs.addElement(new Object[]
\r
2037 { pdb, seqs, chains, new String(protocol) });
\r
2043 } while (param != null || pdbFileCount < 10);
\r
2044 if (pdbs.size() > 0)
\r
2046 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
\r
2047 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
\r
2048 String[][] chains = new String[pdbs.size()][];
\r
2049 String[] protocols = new String[pdbs.size()];
\r
2050 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
\r
2052 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
\r
2053 pdb[pdbsi] = (PDBEntry) o[0];
\r
2054 seqs[pdbsi] = (SequenceI[]) o[1];
\r
2055 chains[pdbsi] = (String[]) o[2];
\r
2056 protocols[pdbsi] = (String) o[3];
\r
2058 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
\r
2062 // ///////////////////////////
\r
2063 // modify display of features
\r
2065 // hide specific groups
\r
2066 param = applet.getParameter("hidefeaturegroups");
\r
2067 if (param != null)
\r
2069 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
\r
2071 // show specific groups
\r
2072 param = applet.getParameter("showfeaturegroups");
\r
2073 if (param != null)
\r
2075 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
\r
2080 fileFound = false;
\r
2081 applet.remove(launcher);
\r
2084 callInitCallback();
\r
2088 * Discovers whether the given file is in the Applet Archive
\r
2094 boolean inArchive(String file)
\r
2096 // This might throw a security exception in certain browsers
\r
2097 // Netscape Communicator for instance.
\r
2100 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
\r
2103 System.err.println("Resource '" + file + "' was "
\r
2104 + (rtn ? "" : "not") + " located by classloader.");
\r
2107 } catch (Exception ex)
\r
2109 System.out.println("Exception checking resources: " + file + " "
\r
2115 String addProtocol(String file)
\r
2117 if (file.indexOf("://") == -1)
\r
2119 String fl = applet.resolveUrlForLocalOrAbsolute(file,
\r
2120 getDocumentBase());
\r
2123 if (new java.net.URL(fl).openStream() != null)
\r
2127 System.err.println("Prepended document base for resource: '"
\r
2132 } catch (Exception x)
\r
2136 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
\r
2139 if (new java.net.URL(fl).openStream() != null)
\r
2143 System.err.println("Prepended codebase for resource: '"
\r
2148 } catch (Exception x)
\r
2160 * @return the default alignFrame acted on by the public applet methods. May
\r
2161 * return null with an error message on System.err indicating the
\r
2164 public AlignFrame getDefaultTargetFrame()
\r
2166 if (currentAlignFrame != null)
\r
2168 return currentAlignFrame;
\r
2170 if (initialAlignFrame != null)
\r
2172 return initialAlignFrame;
\r
2175 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
\r
2180 * separator used for separatorList
\r
2182 protected String separator = "" + ((char) 0x00AC); // the default used to be
\r
2183 // '|' but many sequence
\r
2184 // IDS include pipes.
\r
2187 * set to enable the URL based javascript execution mechanism
\r
2189 public boolean jsfallbackEnabled = false;
\r
2192 * parse the string into a list
\r
2195 * @return elements separated by separator
\r
2197 public String[] separatorListToArray(String list)
\r
2199 return separatorListToArray(list, separator);
\r
2203 * parse the string into a list
\r
2206 * @param separator
\r
2207 * @return elements separated by separator
\r
2209 public String[] separatorListToArray(String list, String separator)
\r
2211 // note separator local variable intentionally masks object field
\r
2212 int seplen = separator.length();
\r
2213 if (list == null || list.equals("") || list.equals(separator))
\r
2215 java.util.Vector jv = new Vector();
\r
2217 while ((pos = list.indexOf(separator, cp)) > cp)
\r
2219 jv.addElement(list.substring(cp, pos));
\r
2220 cp = pos + seplen;
\r
2222 if (cp < list.length())
\r
2224 String c = list.substring(cp);
\r
2225 if (!c.equals(separator))
\r
2230 if (jv.size() > 0)
\r
2232 String[] v = new String[jv.size()];
\r
2233 for (int i = 0; i < v.length; i++)
\r
2235 v[i] = (String) jv.elementAt(i);
\r
2237 jv.removeAllElements();
\r
2240 System.err.println("Array from '" + separator
\r
2241 + "' separated List:\n" + v.length);
\r
2242 for (int i = 0; i < v.length; i++)
\r
2244 System.err.println("item " + i + " '" + v[i] + "'");
\r
2251 System.err.println("Empty Array from '" + separator
\r
2252 + "' separated List");
\r
2258 * concatenate the list with separator
\r
2261 * @return concatenated string
\r
2263 public String arrayToSeparatorList(String[] list)
\r
2265 return arrayToSeparatorList(list, separator);
\r
2269 * concatenate the list with separator
\r
2272 * @param separator
\r
2273 * @return concatenated string
\r
2275 public String arrayToSeparatorList(String[] list, String separator)
\r
2277 StringBuffer v = new StringBuffer();
\r
2278 if (list != null && list.length > 0)
\r
2280 for (int i = 0, iSize = list.length; i < iSize; i++)
\r
2282 if (list[i] != null)
\r
2286 v.append(separator);
\r
2288 v.append(list[i]);
\r
2293 System.err.println("Returning '" + separator
\r
2294 + "' separated List:\n");
\r
2295 System.err.println(v);
\r
2297 return v.toString();
\r
2301 System.err.println("Returning empty '" + separator
\r
2302 + "' separated List\n");
\r
2304 return "" + separator;
\r
2310 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
\r
2312 public String getFeatureGroups()
\r
2314 String lst = arrayToSeparatorList(getDefaultTargetFrame()
\r
2315 .getFeatureGroups());
\r
2323 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
\r
2326 public String getFeatureGroupsOn(AlignFrame alf)
\r
2328 String lst = arrayToSeparatorList(alf.getFeatureGroups());
\r
2335 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
\r
2337 public String getFeatureGroupsOfState(boolean visible)
\r
2339 return arrayToSeparatorList(getDefaultTargetFrame()
\r
2340 .getFeatureGroupsOfState(visible));
\r
2347 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
\r
2348 * .AlignFrame, boolean)
\r
2350 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
\r
2352 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
\r
2358 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
\r
2359 * AlignFrame, java.lang.String, boolean)
\r
2361 public void setFeatureGroupStateOn(final AlignFrame alf,
\r
2362 final String groups, boolean state)
\r
2364 final boolean st = state;// !(state==null || state.equals("") ||
\r
2365 // state.toLowerCase().equals("false"));
\r
2366 java.awt.EventQueue.invokeLater(new Runnable()
\r
2371 alf.setFeatureGroupState(separatorListToArray(groups), st);
\r
2379 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
\r
2382 public void setFeatureGroupState(String groups, boolean state)
\r
2384 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
\r
2390 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
\r
2392 public String getSeparator()
\r
2400 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
\r
2402 public void setSeparator(String separator)
\r
2404 if (separator == null || separator.length() < 1)
\r
2406 // reset to default
\r
2407 separator = "" + ((char) 0x00AC);
\r
2409 this.separator = separator;
\r
2412 System.err.println("Default Separator now: '" + separator + "'");
\r
2417 * get boolean value of applet parameter 'name' and return default if
\r
2418 * parameter is not set
\r
2421 * name of paremeter
\r
2423 * the value to return otherwise
\r
2424 * @return true or false
\r
2426 public boolean getDefaultParameter(String name, boolean def)
\r
2429 if ((stn = getParameter(name)) == null)
\r
2433 if (stn.toLowerCase().equals("true"))
\r
2443 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
\r
2444 * java.lang.String, java.lang.String, java.lang.String)
\r
2446 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
\r
2447 String pdbEntryString, String pdbFile)
\r
2449 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
\r
2452 protected void setAlignPdbStructures(boolean alignPdbStructures)
\r
2454 this.alignPdbStructures = alignPdbStructures;
\r
2457 public boolean isAlignPdbStructures()
\r
2459 return alignPdbStructures;
\r
2462 public void start()
\r
2464 // callInitCallback();
\r
2467 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
\r
2469 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
\r
2471 public void setJsMessageSet(String messageclass, String viewId,
\r
2472 String[] colcommands)
\r
2474 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
\r
2475 if (msgset == null)
\r
2477 msgset = new Hashtable<String, String[]>();
\r
2478 jsmessages.put(messageclass, msgset);
\r
2480 msgset.put(viewId, colcommands);
\r
2481 long[] l = new long[colcommands.length];
\r
2482 for (int i = 0; i < colcommands.length; i++)
\r
2484 l[i] = colcommands[i].hashCode();
\r
2486 jshashes.put(messageclass + "|" + viewId, l);
\r
2492 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
\r
2493 * java.lang.String)
\r
2495 public String getJsMessage(String messageclass, String viewId)
\r
2497 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
\r
2498 if (msgset != null)
\r
2500 String[] msgs = msgset.get(viewId);
\r
2503 for (int i = 0; i < msgs.length; i++)
\r
2505 if (msgs[i] != null)
\r
2507 String m = msgs[i];
\r
2517 public boolean isJsMessageSetChanged(String string, String string2,
\r
2518 String[] colcommands)
\r
2520 long[] l = jshashes.get(string + "|" + string2);
\r
2521 if (l == null && colcommands != null)
\r
2525 for (int i = 0; i < colcommands.length; i++)
\r
2527 if (l[i] != colcommands[i].hashCode())
\r
2535 private Vector jsExecQueue = new Vector();
\r
2537 public Vector getJsExecQueue()
\r
2539 return jsExecQueue;
\r
2542 public void setExecutor(JSFunctionExec jsFunctionExec2)
\r
2544 jsFunctionExec = jsFunctionExec2;
\r
2548 * return the given colour value parameter or the given default if parameter
\r
2552 * @param defcolour
\r
2555 public Color getDefaultColourParameter(String colparam, Color defcolour)
\r
2557 String colprop = getParameter(colparam);
\r
2558 if (colprop == null || colprop.trim().length() == 0)
\r
2562 Color col = jalview.schemes.ColourSchemeProperty
\r
2563 .getAWTColorFromName(colprop);
\r
2568 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
\r
2569 } catch (Exception ex)
\r
2571 System.err.println("Couldn't parse '" + colprop
\r
2572 + "' as a colour for " + colparam);
\r
2576 return (col == null) ? defcolour : col;
\r
2580 public void openJalviewHelpUrl()
\r
2582 String helpUrl = getParameter("jalviewhelpurl");
\r
2583 if (helpUrl == null || helpUrl.trim().length() < 5)
\r
2585 helpUrl = "http://www.jalview.org/help.html";
\r
2587 showURL(helpUrl, "HELP");
\r
2591 * form a complete URL given a path to a resource and a reference location on
\r
2595 * - an absolute path on the same server as localref or a document
\r
2596 * located relative to localref
\r
2598 * - a URL on the same server as url
\r
2599 * @return a complete URL for the resource located by url
\r
2601 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
\r
2603 String codebase = localref.toString();
\r
2604 if (url.indexOf("/") == 0)
\r
2606 url = codebase.substring(0, codebase.length()
\r
2607 - localref.getFile().length())
\r
2612 url = localref + url;
\r
2618 * open a URL in the browser - resolving it according to relative refs and
\r
2619 * coping with javascript: protocol if necessary.
\r
2624 public void showURL(String url, String target)
\r
2628 if (url.indexOf(":") == -1)
\r
2630 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
\r
2632 // Should really use docbase, not codebase.
\r
2634 url = resolveUrlForLocalOrAbsolute(
\r
2636 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
\r
2641 .println("Show url (prepended "
\r
2643 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
\r
2651 System.err.println("Show url: " + url);
\r
2654 if (url.indexOf("javascript:") == 0)
\r
2656 // no target for the javascript context
\r
2657 getAppletContext().showDocument(new java.net.URL(url));
\r
2661 getAppletContext().showDocument(new java.net.URL(url), target);
\r
2663 } catch (Exception ex)
\r
2665 ex.printStackTrace();
\r
2670 * bind structures in a viewer to any matching sequences in an alignFrame (use
\r
2671 * sequenceIds to limit scope of search to specific sequences)
\r
2675 * @param sequenceIds
\r
2676 * @return TODO: consider making an exception structure for indicating when
\r
2677 * binding fails public SequenceStructureBinding
\r
2678 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
\r
2681 * if (sequenceIds != null && sequenceIds.length() > 0) { return
\r
2682 * alFrame.addStructureViewInstance(viewer,
\r
2683 * separatorListToArray(sequenceIds)); } else { return
\r
2684 * alFrame.addStructureViewInstance(viewer, null); } // return null; }
\r