2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentUtils;
24 import jalview.api.AlignFrameI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.JalviewApp;
27 import jalview.api.StructureSelectionManagerProvider;
28 import jalview.appletgui.AlignFrame;
29 import jalview.appletgui.AlignViewport;
30 import jalview.appletgui.EmbmenuFrame;
31 import jalview.appletgui.FeatureSettings;
32 import jalview.appletgui.SplitFrame;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentOrder;
36 import jalview.datamodel.ColumnSelection;
37 import jalview.datamodel.HiddenColumns;
38 import jalview.datamodel.PDBEntry;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.AnnotationFile;
42 import jalview.io.AppletFormatAdapter;
43 import jalview.io.DataSourceType;
44 import jalview.io.FileFormatI;
45 import jalview.io.FileFormats;
46 import jalview.io.FileParse;
47 import jalview.io.IdentifyFile;
48 import jalview.io.NewickFile;
49 import jalview.javascript.JSFunctionExec;
50 import jalview.javascript.JalviewLiteJsApi;
51 import jalview.javascript.JsCallBack;
52 import jalview.javascript.MouseOverStructureListener;
53 import jalview.renderer.seqfeatures.FeatureRenderer;
54 import jalview.structure.SelectionListener;
55 import jalview.structure.SelectionSource;
56 import jalview.structure.StructureSelectionManager;
57 import jalview.structure.VamsasSource;
58 import jalview.util.ColorUtils;
59 import jalview.util.MessageManager;
60 import jalview.viewmodel.AlignmentViewport;
62 import java.applet.Applet;
63 import java.awt.Button;
64 import java.awt.Color;
65 import java.awt.Component;
66 import java.awt.EventQueue;
68 import java.awt.Frame;
69 import java.awt.Graphics;
70 import java.awt.event.ActionEvent;
71 import java.awt.event.WindowAdapter;
72 import java.awt.event.WindowEvent;
73 import java.io.BufferedReader;
74 import java.io.IOException;
75 import java.io.InputStreamReader;
77 import java.util.ArrayList;
78 import java.util.Hashtable;
79 import java.util.List;
80 import java.util.Vector;
82 import netscape.javascript.JSObject;
85 * Jalview Applet. Runs in Java 1.18 runtime
88 * @version $Revision: 1.92 $
90 @SuppressWarnings("serial")
91 public class JalviewLite extends Applet
92 implements StructureSelectionManagerProvider, JalviewLiteJsApi,
98 appLoader = new JalviewAppLoader(debug);
100 private static final String TRUE = "true";
102 private static final String FALSE = "false";
104 public StructureSelectionManager getStructureSelectionManager()
106 return StructureSelectionManager.getStructureSelectionManager(this);
110 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
115 // /////////////////////////////////////////
116 // The following public methods may be called
117 // externally, eg via javascript in HTML page
121 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
124 public String getSelectedSequences()
126 return getSelectedSequencesFrom(getDefaultTargetFrame());
132 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
135 public String getSelectedSequences(String sep)
137 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
144 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
148 public String getSelectedSequencesFrom(AlignFrameI alf)
150 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
157 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
158 * .AlignFrame, java.lang.String)
161 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
163 StringBuffer result = new StringBuffer("");
164 if (sep == null || sep.length() == 0)
166 sep = separator; // "+0x00AC;
168 if (((AlignFrame) alf).viewport.getSelectionGroup() != null)
170 SequenceI[] seqs = ((AlignFrame) alf).viewport.getSelectionGroup()
171 .getSequencesInOrder(
172 ((AlignFrame) alf).viewport.getAlignment());
174 for (int i = 0; i < seqs.length; i++)
176 result.append(seqs[i].getName());
181 return result.toString();
187 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
188 * java.lang.String, java.lang.String)
191 public void highlight(String sequenceId, String position,
192 String alignedPosition)
194 highlightIn(getDefaultTargetFrame(), sequenceId, position,
201 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
202 * java.lang.String, java.lang.String, java.lang.String)
205 public void highlightIn(final AlignFrameI alf, final String sequenceId,
206 final String position, final String alignedPosition)
208 // TODO: could try to highlight in all alignments if alf==null
209 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
210 ((AlignFrame) alf).viewport.getAlignment().getSequencesArray());
211 final SequenceI sq = matcher.findIdMatch(sequenceId);
217 apos = new Integer(position).intValue();
219 } catch (NumberFormatException ex)
223 final StructureSelectionManagerProvider me = this;
224 final int pos = apos;
225 // use vamsas listener to broadcast to all listeners in scope
226 if (alignedPosition != null && (alignedPosition.trim().length() == 0
227 || alignedPosition.toLowerCase().indexOf("false") > -1))
229 java.awt.EventQueue.invokeLater(new Runnable()
234 StructureSelectionManager.getStructureSelectionManager(me)
235 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
241 java.awt.EventQueue.invokeLater(new Runnable()
246 StructureSelectionManager.getStructureSelectionManager(me)
247 .mouseOverVamsasSequence(sq, pos, null);
257 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
261 public void select(String sequenceIds, String columns)
263 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
269 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
270 * java.lang.String, java.lang.String)
273 public void select(String sequenceIds, String columns, String sep)
275 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
281 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
282 * java.lang.String, java.lang.String)
285 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
287 selectIn(alf, sequenceIds, columns, separator);
293 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
294 * java.lang.String, java.lang.String, java.lang.String)
297 public void selectIn(final AlignFrameI alf, String sequenceIds,
298 String columns, String sep)
300 if (sep == null || sep.length() == 0)
308 System.err.println("Selecting region using separator string '"
313 String[] ids = JalviewAppLoader.separatorListToArray(sequenceIds, sep);
314 String[] cols = JalviewAppLoader.separatorListToArray(columns, sep);
315 final SequenceGroup sel = new SequenceGroup();
316 final ColumnSelection csel = new ColumnSelection();
317 AlignmentI al = ((AlignFrame) alf).viewport.getAlignment();
318 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
319 ((AlignFrame) alf).viewport.getAlignment().getSequencesArray());
320 int start = 0, end = al.getWidth(), alw = al.getWidth();
321 boolean seqsfound = true;
322 if (ids != null && ids.length > 0)
325 for (int i = 0; i < ids.length; i++)
327 if (ids[i].trim().length() == 0)
331 SequenceI sq = matcher.findIdMatch(ids[i]);
335 sel.addSequence(sq, false);
339 boolean inseqpos = false;
340 if (cols != null && cols.length > 0)
342 boolean seset = false;
343 for (int i = 0; i < cols.length; i++)
345 String cl = cols[i].trim();
346 if (cl.length() == 0)
351 if ((p = cl.indexOf("-")) > -1)
353 int from = -1, to = -1;
356 from = new Integer(cl.substring(0, p)).intValue();
358 } catch (NumberFormatException ex)
361 "ERROR: Couldn't parse first integer in range element column selection string '"
362 + cl + "' - format is 'from-to'");
367 to = new Integer(cl.substring(p + 1)).intValue();
369 } catch (NumberFormatException ex)
372 "ERROR: Couldn't parse second integer in range element column selection string '"
373 + cl + "' - format is 'from-to'");
376 if (from >= 0 && to >= 0)
393 // comment to prevent range extension
403 for (int r = from; r <= to; r++)
405 if (r >= 0 && r < alw)
412 System.err.println("Range '" + cl + "' deparsed as [" + from
418 System.err.println("ERROR: Invalid Range '" + cl
419 + "' deparsed as [" + from + "," + to + "]");
427 r = new Integer(cl).intValue();
429 } catch (NumberFormatException ex)
431 if (cl.toLowerCase().equals("sequence"))
433 // we are in the dataset sequence's coordinate frame.
439 "ERROR: Couldn't parse integer from point selection element of column selection string '"
444 if (r >= 0 && r <= alw)
454 // comment to prevent range extension
467 System.err.println("Point selection '" + cl
468 + "' deparsed as [" + r + "]");
473 System.err.println("ERROR: Invalid Point selection '" + cl
474 + "' deparsed as [" + r + "]");
481 // we only propagate the selection when it was the null selection, or the
482 // given sequences were found in the alignment.
483 if (inseqpos && sel.getSize() > 0)
485 // assume first sequence provides reference frame ?
486 SequenceI rs = sel.getSequenceAt(0);
487 start = rs.findIndex(start);
488 end = rs.findIndex(end);
489 List<Integer> cs = new ArrayList<>(csel.getSelected());
491 for (Integer selectedCol : cs)
493 csel.addElement(rs.findIndex(selectedCol));
496 sel.setStartRes(start);
498 EventQueue.invokeLater(new Runnable()
503 ((AlignFrame) alf).select(sel, csel, ((AlignFrame) alf)
504 .getAlignViewport().getAlignment().getHiddenColumns());
514 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
515 * String, java.lang.String)
518 public String getSelectedSequencesAsAlignment(String format,
521 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
529 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
530 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
533 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
534 String format, String suffix)
538 FileFormatI theFormat = FileFormats.getInstance().forName(format);
539 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
540 if (((AlignFrame) alf).viewport.getSelectionGroup() != null)
542 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
543 // method now returns a full copy of sequence data
544 // TODO consider using getSequenceSelection instead here
545 String reply = new AppletFormatAdapter().formatSequences(theFormat,
546 new Alignment(((AlignFrame) alf).viewport
547 .getSelectionAsNewSequence()),
551 } catch (IllegalArgumentException ex)
553 ex.printStackTrace();
554 return "Error retrieving alignment, possibly invalid format specifier: "
563 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
566 public String getAlignmentOrder()
568 return getAlignmentOrderFrom(getDefaultTargetFrame());
575 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
579 public String getAlignmentOrderFrom(AlignFrameI alf)
581 return getAlignmentOrderFrom(alf, separator);
588 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
589 * , java.lang.String)
592 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
594 AlignmentI alorder = ((AlignFrame) alf).getAlignViewport()
596 String[] order = new String[alorder.getHeight()];
597 for (int i = 0; i < order.length; i++)
599 order[i] = alorder.getSequenceAt(i).getName();
601 return arrayToSeparatorList(order);
607 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
611 public String orderBy(String order, String undoName)
613 return orderBy(order, undoName, separator);
619 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
620 * java.lang.String, java.lang.String)
623 public String orderBy(String order, String undoName, String sep)
625 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
632 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
633 * java.lang.String, java.lang.String, java.lang.String)
636 public String orderAlignmentBy(AlignFrameI alf, String order,
637 String undoName, String sep)
639 String[] ids = JalviewAppLoader.separatorListToArray(order, sep);
640 SequenceI[] sqs = null;
641 if (ids != null && ids.length > 0)
643 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
644 ((AlignFrame) alf).viewport.getAlignment()
645 .getSequencesArray());
647 sqs = new SequenceI[ids.length];
648 for (int i = 0; i < ids.length; i++)
650 if (ids[i].trim().length() == 0)
654 SequenceI sq = matcher.findIdMatch(ids[i]);
662 SequenceI[] sqq = new SequenceI[s];
663 System.arraycopy(sqs, 0, sqq, 0, s);
676 final AlignmentOrder aorder = new AlignmentOrder(sqs);
678 if (undoName != null && undoName.trim().length() == 0)
682 final String _undoName = undoName;
683 // TODO: deal with synchronization here: cannot raise any events until after
684 // this has returned.
685 return ((AlignFrame) alf).sortBy(aorder, _undoName) ? TRUE : "";
691 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
694 public String getAlignment(String format)
696 return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
703 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
707 public String getAlignmentFrom(AlignFrameI alf, String format)
709 return getAlignmentFrom(alf, format, TRUE);
715 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
719 public String getAlignment(String format, String suffix)
721 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
728 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
729 * java.lang.String, java.lang.String)
732 public String getAlignmentFrom(AlignFrameI alf, String format,
737 boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
739 FileFormatI theFormat = FileFormats.getInstance().forName(format);
740 String reply = new AppletFormatAdapter().formatSequences(theFormat,
741 ((AlignFrame) alf).viewport.getAlignment(), seqlimits);
743 } catch (IllegalArgumentException ex)
745 ex.printStackTrace();
746 return "Error retrieving alignment, possibly invalid format specifier: "
754 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
757 public void loadAnnotation(String annotation)
759 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
766 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
767 * , java.lang.String)
770 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
772 if (new AnnotationFile().annotateAlignmentView(
773 ((AlignFrame) alf).getAlignViewport(),
774 annotation, DataSourceType.PASTE))
776 ((AlignFrame) alf).alignPanel.fontChanged();
777 ((AlignFrame) alf).alignPanel.setScrollValues(0, 0);
781 ((AlignFrame) alf).parseFeaturesFile(annotation,
782 DataSourceType.PASTE);
789 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
792 public void loadFeatures(String features, boolean autoenabledisplay)
794 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
801 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
802 * , java.lang.String)
805 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
806 boolean autoenabledisplay)
808 return ((AlignFrame) alf).parseFeaturesFile(features,
809 DataSourceType.PASTE,
816 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
819 public String getFeatures(String format)
821 return getFeaturesFrom(getDefaultTargetFrame(), format);
828 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
832 public String getFeaturesFrom(AlignFrameI alf, String format)
834 return ((AlignFrame) alf).outputFeatures(false, format);
840 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
843 public String getAnnotation()
845 return getAnnotationFrom(getDefaultTargetFrame());
852 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
856 public String getAnnotationFrom(AlignFrameI alf)
858 return ((AlignFrame) alf).outputAnnotations(false);
864 * @see jalview.bin.JalviewLiteJsApi#newView()
867 public AlignFrame newView()
869 return newViewFrom(getDefaultTargetFrame());
875 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
878 public AlignFrame newView(String name)
880 return newViewFrom(getDefaultTargetFrame(), name);
886 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
889 public AlignFrame newViewFrom(AlignFrameI alf)
891 return ((AlignFrame) alf).newView(null);
897 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
901 public AlignFrame newViewFrom(AlignFrameI alf, String name)
903 return ((AlignFrame) alf).newView(name);
909 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
913 public AlignFrame loadAlignment(String text, String title)
915 AlignmentI al = null;
919 FileFormatI format = new IdentifyFile().identify(text,
920 DataSourceType.PASTE);
921 al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
923 if (al.getHeight() > 0)
925 return new AlignFrame(al, this, title, false);
927 } catch (IOException ex)
929 ex.printStackTrace();
937 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
940 public void setMouseoverListener(String listener)
942 setMouseoverListener(currentAlignFrame, listener);
945 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<>();
951 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
952 * , java.lang.String)
955 public void setMouseoverListener(AlignFrameI af, String listener)
957 if (listener != null)
959 listener = listener.trim();
960 if (listener.length() == 0)
963 "jalview Javascript error: Ignoring empty function for mouseover listener.");
967 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
968 this, (AlignFrame) af, listener, debug);
969 javascriptListeners.addElement(mol);
970 StructureSelectionManager.getStructureSelectionManager(this)
971 .addStructureViewerListener(mol);
974 System.err.println("Added a mouseover listener for "
975 + ((af == null) ? "All frames"
977 + ((AlignFrame) af).getAlignViewport()
978 .getSequenceSetId()));
979 System.err.println("There are now " + javascriptListeners.size()
980 + " listeners in total.");
987 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
990 public void setSelectionListener(String listener)
992 setSelectionListener(null, listener);
999 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
1000 * , java.lang.String)
1003 public void setSelectionListener(AlignFrameI af, String listener)
1005 if (listener != null)
1007 listener = listener.trim();
1008 if (listener.length() == 0)
1011 "jalview Javascript error: Ignoring empty function for selection listener.");
1015 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
1016 this, (AlignFrame) af, listener, debug);
1017 javascriptListeners.addElement(mol);
1018 StructureSelectionManager.getStructureSelectionManager(this)
1019 .addSelectionListener(mol);
1022 System.err.println("Added a selection listener for "
1023 + ((af == null) ? "All frames"
1025 + ((AlignFrame) af).getAlignViewport()
1026 .getSequenceSetId()));
1027 System.err.println("There are now " + javascriptListeners.size()
1028 + " listeners in total.");
1033 * Callable from javascript to register a javascript function to pass events
1034 * to a structure viewer.
1037 * the name of a javascript function
1039 * a token separated list of PDB file names listened for
1040 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
1044 public void setStructureListener(String listener, String modelSet)
1046 if (listener != null)
1048 listener = listener.trim();
1049 if (listener.length() == 0)
1052 "jalview Javascript error: Ignoring empty function for selection listener.");
1056 MouseOverStructureListener mol = new MouseOverStructureListener(this,
1057 listener, separatorListToArray(modelSet), debug);
1058 javascriptListeners.addElement(mol);
1059 StructureSelectionManager.getStructureSelectionManager(this)
1060 .addStructureViewerListener(mol);
1063 System.err.println("Added a javascript structure viewer listener '"
1065 System.err.println("There are now " + javascriptListeners.size()
1066 + " listeners in total.");
1074 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
1075 * .AlignFrame, java.lang.String)
1078 public void removeJavascriptListener(AlignFrameI af, String listener)
1080 if (listener != null)
1082 listener = listener.trim();
1083 if (listener.length() == 0)
1088 boolean rprt = false;
1089 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
1091 Object lstn = javascriptListeners.elementAt(ms);
1092 JsCallBack lstner = (JsCallBack) lstn;
1093 if ((af == null || lstner.getAlignFrame() == af) && (listener == null
1094 || lstner.getListenerFunction().equals(listener)))
1096 javascriptListeners.removeElement(lstner);
1098 if (lstner instanceof SelectionListener)
1100 StructureSelectionManager.getStructureSelectionManager(this)
1101 .removeSelectionListener((SelectionListener) lstner);
1105 StructureSelectionManager.getStructureSelectionManager(this)
1106 .removeStructureViewerListener(lstner, null);
1111 System.err.println("Removed listener '" + listener + "'");
1121 System.err.println("There are now " + javascriptListeners.size()
1122 + " listeners in total.");
1129 System.err.println("Applet " + getName() + " stop().");
1134 public void destroy()
1136 System.err.println("Applet " + getName() + " destroy().");
1140 private void tidyUp()
1143 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1144 && currentAlignFrame.viewport.applet != null)
1146 AlignViewport av = currentAlignFrame.viewport;
1147 currentAlignFrame.closeMenuItem_actionPerformed();
1149 currentAlignFrame = null;
1151 if (javascriptListeners != null)
1153 while (javascriptListeners.size() > 0)
1155 jalview.javascript.JSFunctionExec mol = javascriptListeners
1157 javascriptListeners.removeElement(mol);
1158 if (mol instanceof SelectionListener)
1160 StructureSelectionManager.getStructureSelectionManager(this)
1161 .removeSelectionListener((SelectionListener) mol);
1165 StructureSelectionManager.getStructureSelectionManager(this)
1166 .removeStructureViewerListener(mol, null);
1171 if (jsFunctionExec != null)
1173 jsFunctionExec.tidyUp();
1174 jsFunctionExec = null;
1176 initialAlignFrame = null;
1177 javascriptListeners = null;
1178 StructureSelectionManager.release(this);
1181 private jalview.javascript.JSFunctionExec jsFunctionExec;
1186 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1187 * java.lang.String, java.lang.String)
1190 public void mouseOverStructure(final String pdbResNum, final String chain,
1191 final String pdbfile)
1193 final StructureSelectionManagerProvider me = this;
1194 java.awt.EventQueue.invokeLater(new Runnable()
1201 StructureSelectionManager.getStructureSelectionManager(me)
1202 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1207 .println("mouseOver for '" + pdbResNum + "' in chain '"
1208 + chain + "' in structure '" + pdbfile + "'");
1210 } catch (NumberFormatException e)
1212 System.err.println("Ignoring invalid residue number string '"
1224 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1225 * java.lang.String, java.lang.String)
1228 public void scrollViewToIn(final AlignFrameI alf, final String topRow,
1229 final String leftHandColumn)
1231 java.awt.EventQueue.invokeLater(new Runnable()
1238 ((AlignFrame) alf).scrollTo(new Integer(topRow).intValue(),
1239 new Integer(leftHandColumn).intValue());
1241 } catch (Exception ex)
1243 System.err.println("Couldn't parse integer arguments (topRow='"
1244 + topRow + "' and leftHandColumn='" + leftHandColumn
1246 ex.printStackTrace();
1256 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1257 * .AlignFrame, java.lang.String)
1260 public void scrollViewToRowIn(final AlignFrameI alf, final String topRow)
1263 java.awt.EventQueue.invokeLater(new Runnable()
1270 ((AlignFrame) alf).scrollToRow(new Integer(topRow).intValue());
1272 } catch (Exception ex)
1274 System.err.println("Couldn't parse integer arguments (topRow='"
1276 ex.printStackTrace();
1287 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1288 * .AlignFrame, java.lang.String)
1291 public void scrollViewToColumnIn(final AlignFrameI alf,
1292 final String leftHandColumn)
1294 java.awt.EventQueue.invokeLater(new Runnable()
1303 .scrollToColumn(new Integer(leftHandColumn).intValue());
1305 } catch (Exception ex)
1308 "Couldn't parse integer arguments (leftHandColumn='"
1309 + leftHandColumn + "')");
1310 ex.printStackTrace();
1317 // //////////////////////////////////////////////
1318 // //////////////////////////////////////////////
1320 public static int lastFrameX = 200;
1322 public static int lastFrameY = 200;
1324 boolean fileFound = true;
1326 String file = "No file";
1328 String file2 = null;
1330 Button launcher = new Button(
1331 MessageManager.getString("label.start_jalview"));
1334 * The currentAlignFrame is static, it will change if and when the user
1335 * selects a new window. Note that it will *never* point back to the embedded
1336 * AlignFrame if the applet is started as embedded on the page and then
1337 * afterwards a new view is created.
1339 public AlignFrame currentAlignFrame = null;
1342 * This is the first frame to be displayed, and does not change. API calls
1343 * will default to this instance if currentAlignFrame is null.
1345 AlignFrame initialAlignFrame = null;
1347 boolean embedded = false;
1349 boolean checkForJmol = true;
1351 boolean checkedForJmol = false; // ensure we don't check for jmol
1353 // every time the app is re-inited
1355 public boolean jmolAvailable = false;
1357 private boolean alignPdbStructures = false;
1360 * use an external structure viewer exclusively (no jmols or mc_views will be
1361 * opened by JalviewLite itself)
1363 public boolean useXtrnalSviewer = false;
1365 public JalviewAppLoader appLoader;
1367 public AlignFrame loaderFrame;
1369 public static boolean debug = false;
1371 static String builddate = null, version = null, installation = null;
1373 private static void initBuildDetails()
1375 if (builddate == null)
1377 builddate = "unknown";
1379 installation = "applet";
1380 java.net.URL url = JalviewLite.class
1381 .getResource("/.build_properties");
1386 BufferedReader reader = new BufferedReader(
1387 new InputStreamReader(url.openStream()));
1389 while ((line = reader.readLine()) != null)
1391 if (line.indexOf("VERSION") > -1)
1393 version = line.substring(line.indexOf("=") + 1);
1395 if (line.indexOf("BUILD_DATE") > -1)
1397 builddate = line.substring(line.indexOf("=") + 1);
1399 if (line.indexOf("INSTALLATION") > -1)
1401 installation = line.substring(line.indexOf("=") + 1);
1404 } catch (Exception ex)
1406 ex.printStackTrace();
1412 public static String getBuildDate()
1418 public static String getInstallation()
1421 return installation;
1424 public static String getVersion()
1430 // public JSObject scriptObject = null;
1433 * init method for Jalview Applet
1438 debug = TRUE.equalsIgnoreCase(getParameter("debug"));
1443 System.err.println("Applet context is '"
1444 + getAppletContext().getClass().toString() + "'");
1446 JSObject scriptObject = JSObject.getWindow(this);
1447 if (debug && scriptObject != null)
1449 System.err.println("Applet has Javascript callback support.");
1452 } catch (Exception ex)
1455 "Warning: No JalviewLite javascript callbacks available.");
1458 ex.printStackTrace();
1464 System.err.println("JalviewLite Version " + getVersion());
1465 System.err.println("Build Date : " + getBuildDate());
1466 System.err.println("Installation : " + getInstallation());
1468 String externalsviewer = getParameter("externalstructureviewer");
1469 if (externalsviewer != null)
1471 useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
1474 * if true disable the check for jmol
1476 String chkforJmol = getParameter("nojmol");
1477 if (chkforJmol != null)
1479 checkForJmol = !chkforJmol.equals(TRUE);
1482 * get the separator parameter if present
1484 String sep = getParameter("separator");
1487 if (sep.length() > 0)
1492 System.err.println("Separator set to '" + separator + "'");
1497 throw new Error(MessageManager
1498 .getString("error.invalid_separator_parameter"));
1507 String param = getParameter("RGB");
1513 r = Integer.parseInt(param.substring(0, 2), 16);
1514 g = Integer.parseInt(param.substring(2, 4), 16);
1515 b = Integer.parseInt(param.substring(4, 6), 16);
1516 } catch (Exception ex)
1523 setBackground(new Color(r, g, b));
1525 param = getParameter("label");
1528 launcher.setLabel(param);
1531 file = getParameter("file");
1535 file = appLoader.getPastedSequence(this);
1537 if (getDefaultParameter("enableSplitFrame", true))
1539 file2 = getParameter("file2");
1542 embedded = (TRUE.equalsIgnoreCase(getParameter("embedded"))
1544 && FALSE.equalsIgnoreCase(getParameter("showbutton")));
1549 else if (file == null)
1551 // jalview initialisation with no alignment. loadAlignment() method can
1552 // still be called to open new alignments.
1560 launcher.addActionListener(new java.awt.event.ActionListener()
1563 public void actionPerformed(ActionEvent e)
1571 protected void startLoading()
1573 LoadingThread loader = new LoadingThread(file, file2, this);
1577 private void initLiveConnect()
1579 // try really hard to get the liveConnect thing working
1580 boolean notFailed = false;
1582 while (!notFailed && tries < 10)
1586 System.err.println("LiveConnect request thread going to sleep.");
1590 Thread.sleep(700 * (1 + tries));
1591 } catch (InterruptedException q)
1597 System.err.println("LiveConnect request thread woken up.");
1601 JSObject scriptObject = JSObject.getWindow(this);
1602 if (scriptObject.eval("navigator") != null)
1606 } catch (Exception jsex)
1608 System.err.println("Attempt " + tries
1609 + " to access LiveConnect javascript failed.");
1614 void callInitCallback()
1616 String initjscallback = getParameter("oninit");
1617 if (initjscallback == null)
1621 initjscallback = initjscallback.trim();
1622 if (initjscallback.length() > 0)
1624 JSObject scriptObject = null;
1627 scriptObject = JSObject.getWindow(this);
1628 } catch (Exception ex)
1632 // try really hard to let the browser plugin know we want liveconnect
1635 if (scriptObject != null)
1639 // do onInit with the JS executor thread
1640 new JSFunctionExec(this, debug).executeJavascriptFunction(true,
1641 initjscallback, null,
1642 "Calling oninit callback '" + initjscallback + "'.");
1643 } catch (Exception e)
1645 System.err.println("Exception when executing _oninit callback '"
1646 + initjscallback + "'.");
1647 e.printStackTrace();
1652 System.err.println("Not executing _oninit callback '"
1653 + initjscallback + "' - no scripting allowed.");
1659 * Initialises and displays a new java.awt.Frame
1662 * java.awt.Frame to be displayed
1664 * title of new frame
1666 * width if new frame
1668 * height of new frame
1670 public static void addFrame(final Frame frame, String title, int width,
1673 frame.setLocation(lastFrameX, lastFrameY);
1676 frame.setSize(width, height);
1677 frame.setTitle(title);
1678 frame.addWindowListener(new WindowAdapter()
1681 public void windowClosing(WindowEvent e)
1683 if (frame instanceof AlignFrame)
1685 AlignViewport vp = ((AlignFrame) frame).viewport;
1686 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1687 if (vp.applet.currentAlignFrame == frame)
1689 vp.applet.currentAlignFrame = null;
1697 if (frame instanceof EmbmenuFrame)
1699 ((EmbmenuFrame) frame).destroyMenus();
1701 frame.setMenuBar(null);
1706 public void windowActivated(WindowEvent e)
1708 if (frame instanceof AlignFrame)
1710 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1713 System.err.println("Activated window " + frame);
1717 super.windowActivated(e);
1720 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1723 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1726 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1727 * frame) { currentAlignFrame = null; if (debug) {
1728 * System.err.println("Deactivated window "+frame); } }
1729 * super.windowDeactivated(e); }
1732 frame.setVisible(true);
1736 * This paints the background surrounding the "Launch Jalview button" <br>
1738 * If file given in parameter not found, displays error message
1744 public void paint(Graphics g)
1748 g.setColor(new Color(200, 200, 200));
1749 g.setColor(Color.cyan);
1750 g.fillRect(0, 0, getSize().width, getSize().height);
1751 g.setColor(Color.red);
1753 MessageManager.getString("label.jalview_cannot_open_file"), 5,
1755 g.drawString("\"" + file + "\"", 5, 30);
1759 g.setColor(Color.black);
1760 g.setFont(new Font("Arial", Font.BOLD, 24));
1761 g.drawString(MessageManager.getString("label.jalview_applet"), 50,
1762 getSize().height / 2 - 30);
1763 g.drawString(MessageManager.getString("label.loading_data") + "...",
1764 50, getSize().height / 2);
1769 * get all components associated with the applet of the given type
1774 public Vector getAppletWindow(Class class1)
1776 Vector wnds = new Vector();
1777 Component[] cmp = getComponents();
1780 for (int i = 0; i < cmp.length; i++)
1782 if (class1.isAssignableFrom(cmp[i].getClass()))
1784 wnds.addElement(cmp);
1791 class LoadJmolThread extends Thread
1793 private boolean running = false;
1798 if (running || checkedForJmol)
1807 if (!System.getProperty("java.version").startsWith("1.1"))
1809 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1810 jmolAvailable = true;
1815 "Jmol not available - Using mc_view for structures");
1817 } catch (java.lang.ClassNotFoundException ex)
1823 jmolAvailable = false;
1827 "Skipping Jmol check. Will use mc_view (probably)");
1830 checkedForJmol = true;
1834 public boolean notFinished()
1836 return running || !checkedForJmol;
1840 class LoadingThread extends Thread
1843 * State variable: protocol for access to file source
1845 DataSourceType protocol;
1847 String _file; // alignment file or URL spec
1849 String _file2; // second alignment file or URL spec
1853 public void dbgMsg(String msg)
1855 if (JalviewLite.debug)
1857 System.err.println(msg);
1862 * update the protocol state variable for accessing the datasource located
1866 * @return possibly updated datasource string
1868 public String resolveFileProtocol(String path)
1871 String[] ret = new String[] { path };
1872 protocol = JalviewAppLoader.resolveFileProtocol(applet, ret);
1876 public LoadingThread(String file, String file2, JalviewLite _applet)
1879 this._file2 = file2;
1886 LoadJmolThread jmolchecker = new LoadJmolThread();
1887 jmolchecker.start();
1888 while (jmolchecker.notFinished())
1890 // wait around until the Jmol check is complete.
1894 } catch (Exception e)
1899 // applet.callInitCallback();
1903 * Load the alignment and any related files as specified by applet
1906 private void startLoading()
1908 dbgMsg("Loading thread started with:\n>>file\n" + _file
1911 dbgMsg("Loading started.");
1913 AlignFrame newAlignFrame = readAlignment(_file);
1914 AlignFrame newAlignFrame2 = readAlignment(_file2);
1915 if (newAlignFrame != null)
1917 addToDisplay(newAlignFrame, newAlignFrame2);
1918 applet.loaderFrame = newAlignFrame;
1919 appLoader.load(applet);
1924 applet.remove(launcher);
1931 * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
1936 public void addToDisplay(AlignFrame af, AlignFrame af2)
1940 AlignmentI al1 = af.viewport.getAlignment();
1941 AlignmentI al2 = af2.viewport.getAlignment();
1942 AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
1943 AlignmentI prot = al1.isNucleotide() ? al2 : al1;
1944 if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
1947 SplitFrame sf = new SplitFrame(af, af2);
1948 sf.addToDisplay(embedded, JalviewLite.this);
1953 String msg = "Could not map any sequence in " + af2.getTitle()
1955 + (al1.isNucleotide() ? "protein product" : "cDNA")
1956 + " for " + af.getTitle();
1957 System.err.println(msg);
1961 af.addToDisplay(embedded);
1965 * Read the alignment file (from URL, text 'paste', or archive by
1970 protected AlignFrame readAlignment(String fileParam)
1972 if (fileParam == null)
1976 String resolvedFile = resolveFileProtocol(fileParam);
1977 AlignmentI al = null;
1980 FileFormatI format = new IdentifyFile().identify(resolvedFile,
1982 dbgMsg("File identified as '" + format + "'");
1983 al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
1985 if ((al != null) && (al.getHeight() > 0))
1987 dbgMsg("Successfully loaded file.");
1988 al.setDataset(null);
1989 AlignFrame newAlignFrame = new AlignFrame(al, applet,
1990 resolvedFile, embedded, false);
1991 newAlignFrame.setTitle(resolvedFile);
1992 if (initialAlignFrame == null)
1994 initialAlignFrame = newAlignFrame;
1996 // update the focus.
1997 currentAlignFrame = newAlignFrame;
1999 if (protocol == DataSourceType.PASTE)
2001 newAlignFrame.setTitle(MessageManager
2002 .formatMessage("label.sequences_from", new Object[]
2003 { applet.getDocumentBase().toString() }));
2006 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
2007 "label.successfully_loaded_file", new Object[]
2010 return newAlignFrame;
2012 } catch (java.io.IOException ex)
2014 dbgMsg("File load exception.");
2015 ex.printStackTrace();
2020 FileParse fp = new FileParse(resolvedFile, protocol);
2022 dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
2024 while ((ln = fp.nextLine()) != null)
2028 dbgMsg(">>>Dump finished.");
2029 } catch (Exception e)
2032 "Exception when trying to dump the content of the file parameter.");
2033 e.printStackTrace();
2043 * @return the default alignFrame acted on by the public applet methods. May
2044 * return null with an error message on System.err indicating the
2047 public AlignFrame getDefaultTargetFrame()
2049 if (currentAlignFrame != null)
2051 return currentAlignFrame;
2053 if (initialAlignFrame != null)
2055 return initialAlignFrame;
2058 "Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2063 * separator used for separatorList
2065 protected String separator = "" + ((char) 0x00AC); // the default used to be
2066 // '|' but many sequence
2067 // IDS include pipes.
2070 * set to enable the URL based javascript execution mechanism
2072 private boolean jsfallbackEnabled = false;
2075 * parse the string into a list
2078 * @return elements separated by separator
2081 public String[] separatorListToArray(String list)
2083 return JalviewAppLoader.separatorListToArray(list, separator);
2087 * concatenate the list with separator
2090 * @return concatenated string
2093 public String arrayToSeparatorList(String[] list)
2095 return JalviewAppLoader.arrayToSeparatorList(list, separator);
2101 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2104 public String getFeatureGroups()
2106 String lst = arrayToSeparatorList(
2107 getDefaultTargetFrame().getFeatureGroups());
2115 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2119 public String getFeatureGroupsOn(AlignFrameI alf)
2121 String lst = arrayToSeparatorList(
2122 ((AlignFrame) alf).getFeatureGroups());
2129 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2132 public String getFeatureGroupsOfState(boolean visible)
2134 return arrayToSeparatorList(
2135 getDefaultTargetFrame().getFeatureGroupsOfState(visible));
2142 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2143 * .AlignFrame, boolean)
2146 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
2148 return arrayToSeparatorList(
2149 ((AlignFrame) alf).getFeatureGroupsOfState(visible));
2155 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2156 * AlignFrame, java.lang.String, boolean)
2159 public void setFeatureGroupStateOn(final AlignFrameI alf,
2160 final String groups, boolean state)
2162 final boolean st = state;// !(state==null || state.equals("") ||
2163 // state.toLowerCase().equals("false"));
2164 java.awt.EventQueue.invokeLater(new Runnable()
2170 .setFeatureGroupState(separatorListToArray(groups), st);
2178 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2182 public void setFeatureGroupState(String groups, boolean state)
2184 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2190 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2193 public String getSeparator()
2201 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2204 public void setSeparator(String separator)
2206 if (separator == null || separator.length() < 1)
2209 separator = "" + ((char) 0x00AC);
2211 this.separator = separator;
2214 System.err.println("Default Separator now: '" + separator + "'");
2219 * get boolean value of applet parameter 'name' and return default if
2220 * parameter is not set
2225 * the value to return otherwise
2226 * @return true or false
2229 public boolean getDefaultParameter(String name, boolean def)
2232 if ((stn = getParameter(name)) == null)
2236 if (TRUE.equalsIgnoreCase(stn))
2246 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2247 * java.lang.String, java.lang.String, java.lang.String)
2250 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
2251 String pdbEntryString, String pdbFile)
2253 return ((AlignFrame) alFrame).addPdbFile(sequenceId, pdbEntryString,
2258 public void setAlignPdbStructures(boolean alignPdbStructures)
2260 this.alignPdbStructures = alignPdbStructures;
2263 public boolean isAlignPdbStructures()
2265 return alignPdbStructures;
2271 // callInitCallback();
2274 private Hashtable<String, int[]> jshashes = new Hashtable<>();
2276 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<>();
2280 public Hashtable<String, int[]> getJSHashes()
2286 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
2291 private Vector<Runnable> jsExecQueue = new Vector<>();
2294 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
2296 jsFunctionExec = exec;
2300 // public void setExecutor(JSFunctionExec jsFunctionExec2)
2302 // jsFunctionExec = jsFunctionExec2;
2306 * return the given colour value parameter or the given default if parameter
2313 public Color getDefaultColourParameter(String colparam, Color defcolour)
2315 String colprop = getParameter(colparam);
2316 if (colprop == null || colprop.trim().length() == 0)
2320 Color col = ColorUtils.parseColourString(colprop);
2323 System.err.println("Couldn't parse '" + colprop + "' as a colour for "
2326 return (col == null) ? defcolour : col;
2329 public void openJalviewHelpUrl()
2331 String helpUrl = getParameter("jalviewhelpurl");
2332 if (helpUrl == null || helpUrl.trim().length() < 5)
2334 helpUrl = "http://www.jalview.org/help.html";
2336 showURL(helpUrl, "HELP");
2340 * open a URL in the browser - resolving it according to relative refs and
2341 * coping with javascript: protocol if necessary.
2346 public void showURL(String url, String target)
2350 if (url.indexOf(":") == -1)
2352 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2354 // Should really use docbase, not codebase.
2356 url = JalviewAppLoader.resolveUrlForLocalOrAbsolute(url,
2357 prepend = getDefaultParameter("resolvetocodebase", false)
2359 : getDocumentBase());
2362 System.err.println("Show url (prepended " + prepend
2363 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2371 System.err.println("Show url: " + url);
2374 if (url.indexOf("javascript:") == 0)
2376 // no target for the javascript context
2377 getAppletContext().showDocument(new java.net.URL(url));
2381 getAppletContext().showDocument(new java.net.URL(url), target);
2383 } catch (Exception ex)
2385 ex.printStackTrace();
2390 public AlignViewportI getViewport()
2392 return loaderFrame.getAlignViewport();
2396 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
2397 String[] chains, DataSourceType protocol)
2399 loaderFrame.newStructureView(this, pdb, seqs, chains,
2404 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
2405 String[][] chains, String[] protocols)
2407 loaderFrame.alignedStructureView(this, pdb, seqs, chains, protocols);
2411 public void updateForAnnotations()
2413 loaderFrame.alignPanel.fontChanged();
2414 loaderFrame.alignPanel.setScrollValues(0, 0);
2418 public void setFeatureGroupState(String[] groups, boolean state)
2420 loaderFrame.setFeatureGroupState(groups, state);
2424 public boolean parseFeaturesFile(String param, DataSourceType protocol)
2426 return loaderFrame.parseFeaturesFile(param, protocol);
2430 public void newFeatureSettings()
2432 getViewport().setShowSequenceFeatures(true);
2433 new FeatureSettings(loaderFrame.alignPanel);
2437 public boolean loadScoreFile(String sScoreFile) throws IOException
2439 return loaderFrame.loadScoreFile(sScoreFile);
2443 public void loadTree(NewickFile tree, String treeFile) throws IOException
2445 loaderFrame.loadTree(tree, treeFile);
2449 public boolean isJsfallbackEnabled()
2451 return jsfallbackEnabled;
2455 public JSObject getJSObject()
2457 return JSObject.getWindow(this);
2461 public void updateColoursFromMouseOver(Object source,
2462 MouseOverStructureListener listener)
2467 public Object[] getSelectionForListener(SequenceGroup seqsel, ColumnSelection colsel,
2468 HiddenColumns hidden, SelectionSource source, Object alignFrame)
2470 // System.err.println("Testing selection event relay to
2471 // jsfunction:"+_listener);
2473 AlignFrame src = (AlignFrame) alignFrame;
2476 if (source instanceof jalview.appletgui.AlignViewport
2477 && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source)
2479 // should be valid if it just generated an event!
2480 src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame;
2484 String[] seqs = new String[] {};
2485 String[] cols = new String[] {};
2486 int strt = 0, end = (src == null) ? -1
2487 : src.alignPanel.av.getAlignment().getWidth();
2488 if (seqsel != null && seqsel.getSize() > 0)
2490 seqs = new String[seqsel.getSize()];
2491 for (int i = 0; i < seqs.length; i++)
2493 seqs[i] = seqsel.getSequenceAt(i).getName();
2495 if (strt < seqsel.getStartRes())
2497 strt = seqsel.getStartRes();
2499 if (end == -1 || end > seqsel.getEndRes())
2501 end = seqsel.getEndRes();
2504 if (colsel != null && !colsel.isEmpty())
2508 end = colsel.getMax() + 1;
2510 cols = new String[colsel.getSelected().size()];
2511 for (int i = 0; i < cols.length; i++)
2513 cols[i] = "" + (1 + colsel.getSelected().get(i).intValue());
2518 if (seqsel != null && seqsel.getSize() > 0)
2520 // send a valid range, otherwise we send the empty selection
2521 cols = new String[2];
2522 cols[0] = "" + (1 + strt) + "-" + (1 + end);
2526 { src, setid, arrayToSeparatorList(seqs), arrayToSeparatorList(cols) };
2530 public String getJsMessage(String messageclass, String viewId)
2532 return JSFunctionExec.getJsMessage(messageclass, viewId, this);
2536 public Object getFrameForSource(VamsasSource source)
2540 if (source instanceof jalview.appletgui.AlignViewport
2541 && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source)
2543 // should be valid if it just generated an event!
2544 return ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame;
2547 // TODO: ensure that if '_af' is specified along with a handler
2548 // function, then only events from that alignFrame are sent to that
2555 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
2557 return new jalview.appletgui.FeatureRenderer((AlignmentViewport) vp);
2561 public String getSelectedSequencesAsAlignment(String format,
2564 // TODO Auto-generated method stub
2569 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
2570 String format, boolean suffix)
2572 // TODO Auto-generated method stub
2577 // * bind structures in a viewer to any matching sequences in an alignFrame
2579 // * sequenceIds to limit scope of search to specific sequences)
2583 // * @param sequenceIds
2584 // * @return TODO: consider making an exception structure for indicating when
2585 // * binding fails public SequenceStructureBinding
2586 // * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2589 // * if (sequenceIds != null && sequenceIds.length() > 0) { return
2590 // * alFrame.addStructureViewInstance(viewer,
2591 // * separatorListToArray(sequenceIds)); } else { return
2592 // * alFrame.addStructureViewInstance(viewer, null); } // return null; }