2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.api.StructureSelectionManagerProvider;
22 import jalview.appletgui.AlignFrame;
23 import jalview.appletgui.AlignViewport;
24 import jalview.appletgui.EmbmenuFrame;
25 import jalview.appletgui.FeatureSettings;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.AlignmentOrder;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.AnnotationFile;
35 import jalview.io.AppletFormatAdapter;
36 import jalview.io.FileParse;
37 import jalview.io.IdentifyFile;
38 import jalview.io.JnetAnnotationMaker;
39 import jalview.javascript.JSFunctionExec;
40 import jalview.javascript.JalviewLiteJsApi;
41 import jalview.javascript.JsCallBack;
42 import jalview.structure.SelectionListener;
43 import jalview.structure.StructureSelectionManager;
44 import jalview.util.MessageManager;
46 import java.applet.Applet;
47 import java.awt.Button;
48 import java.awt.Color;
49 import java.awt.Component;
50 import java.awt.EventQueue;
52 import java.awt.Frame;
53 import java.awt.Graphics;
54 import java.awt.event.ActionEvent;
55 import java.awt.event.WindowAdapter;
56 import java.awt.event.WindowEvent;
57 import java.io.BufferedReader;
58 import java.io.InputStreamReader;
60 import java.util.Hashtable;
61 import java.util.StringTokenizer;
62 import java.util.Vector;
64 import netscape.javascript.JSObject;
67 * Jalview Applet. Runs in Java 1.18 runtime
70 * @version $Revision: 1.92 $
72 public class JalviewLite extends Applet implements
73 StructureSelectionManagerProvider, JalviewLiteJsApi
76 public StructureSelectionManager getStructureSelectionManager()
78 return StructureSelectionManager.getStructureSelectionManager(this);
81 // /////////////////////////////////////////
82 // The following public methods maybe called
83 // externally, eg via javascript in HTML page
87 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
89 public String getSelectedSequences()
91 return getSelectedSequencesFrom(getDefaultTargetFrame());
97 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
99 public String getSelectedSequences(String sep)
101 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
108 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
111 public String getSelectedSequencesFrom(AlignFrame alf)
113 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
120 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
121 * .AlignFrame, java.lang.String)
123 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
125 StringBuffer result = new StringBuffer("");
126 if (sep == null || sep.length() == 0)
128 sep = separator; // "+0x00AC;
130 if (alf.viewport.getSelectionGroup() != null)
132 SequenceI[] seqs = alf.viewport.getSelectionGroup()
133 .getSequencesInOrder(alf.viewport.getAlignment());
135 for (int i = 0; i < seqs.length; i++)
137 result.append(seqs[i].getName());
142 return result.toString();
148 * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
149 * java.lang.String, java.lang.String)
151 public void highlight(String sequenceId, String position,
152 String alignedPosition)
154 highlightIn(getDefaultTargetFrame(), sequenceId, position,
161 * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
162 * java.lang.String, java.lang.String, java.lang.String)
164 public void highlightIn(final AlignFrame alf, final String sequenceId,
165 final String position, final String alignedPosition)
167 // TODO: could try to highlight in all alignments if alf==null
168 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
169 alf.viewport.getAlignment().getSequencesArray());
170 final SequenceI sq = matcher.findIdMatch(sequenceId);
176 apos = new Integer(position).intValue();
178 } catch (NumberFormatException ex)
182 final StructureSelectionManagerProvider me = this;
183 final int pos = apos;
184 // use vamsas listener to broadcast to all listeners in scope
185 if (alignedPosition != null
186 && (alignedPosition.trim().length() == 0 || alignedPosition
187 .toLowerCase().indexOf("false") > -1))
189 java.awt.EventQueue.invokeLater(new Runnable()
194 StructureSelectionManager.getStructureSelectionManager(me)
195 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
201 java.awt.EventQueue.invokeLater(new Runnable()
206 StructureSelectionManager.getStructureSelectionManager(me)
207 .mouseOverVamsasSequence(sq, pos, null);
217 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
220 public void select(String sequenceIds, String columns)
222 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
228 * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
229 * java.lang.String, java.lang.String)
231 public void select(String sequenceIds, String columns, String sep)
233 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
239 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
240 * java.lang.String, java.lang.String)
242 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
244 selectIn(alf, sequenceIds, columns, separator);
250 * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
251 * java.lang.String, java.lang.String, java.lang.String)
253 public void selectIn(final AlignFrame alf, String sequenceIds,
254 String columns, String sep)
256 if (sep == null || sep.length() == 0)
264 System.err.println("Selecting region using separator string '"
269 String[] ids = separatorListToArray(sequenceIds, sep);
270 String[] cols = separatorListToArray(columns, sep);
271 final SequenceGroup sel = new SequenceGroup();
272 final ColumnSelection csel = new ColumnSelection();
273 AlignmentI al = alf.viewport.getAlignment();
274 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
275 alf.viewport.getAlignment().getSequencesArray());
276 int start = 0, end = al.getWidth(), alw = al.getWidth();
277 boolean seqsfound = true;
278 if (ids != null && ids.length > 0)
281 for (int i = 0; i < ids.length; i++)
283 if (ids[i].trim().length() == 0)
287 SequenceI sq = matcher.findIdMatch(ids[i]);
291 sel.addSequence(sq, false);
295 boolean inseqpos = false;
296 if (cols != null && cols.length > 0)
298 boolean seset = false;
299 for (int i = 0; i < cols.length; i++)
301 String cl = cols[i].trim();
302 if (cl.length() == 0)
307 if ((p = cl.indexOf("-")) > -1)
309 int from = -1, to = -1;
312 from = new Integer(cl.substring(0, p)).intValue();
314 } catch (NumberFormatException ex)
317 .println("ERROR: Couldn't parse first integer in range element column selection string '"
318 + cl + "' - format is 'from-to'");
323 to = new Integer(cl.substring(p + 1)).intValue();
325 } catch (NumberFormatException ex)
328 .println("ERROR: Couldn't parse second integer in range element column selection string '"
329 + cl + "' - format is 'from-to'");
332 if (from >= 0 && to >= 0)
349 // comment to prevent range extension
359 for (int r = from; r <= to; r++)
361 if (r >= 0 && r < alw)
368 System.err.println("Range '" + cl + "' deparsed as [" + from
374 System.err.println("ERROR: Invalid Range '" + cl
375 + "' deparsed as [" + from + "," + to + "]");
383 r = new Integer(cl).intValue();
385 } catch (NumberFormatException ex)
387 if (cl.toLowerCase().equals("sequence"))
389 // we are in the dataset sequence's coordinate frame.
395 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
400 if (r >= 0 && r <= alw)
410 // comment to prevent range extension
423 System.err.println("Point selection '" + cl
424 + "' deparsed as [" + r + "]");
429 System.err.println("ERROR: Invalid Point selection '" + cl
430 + "' deparsed as [" + r + "]");
437 // we only propagate the selection when it was the null selection, or the
438 // given sequences were found in the alignment.
439 if (inseqpos && sel.getSize() > 0)
441 // assume first sequence provides reference frame ?
442 SequenceI rs = sel.getSequenceAt(0);
443 start = rs.findIndex(start);
444 end = rs.findIndex(end);
447 Vector cs = csel.getSelected();
449 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
451 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
456 sel.setStartRes(start);
458 EventQueue.invokeLater(new Runnable()
463 alf.select(sel, csel);
473 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
474 * String, java.lang.String)
476 public String getSelectedSequencesAsAlignment(String format, String suffix)
478 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
486 * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
487 * .appletgui.AlignFrame, java.lang.String, java.lang.String)
489 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
490 String format, String suffix)
494 boolean seqlimits = suffix.equalsIgnoreCase("true");
495 if (alf.viewport.getSelectionGroup() != null)
497 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
498 // method now returns a full copy of sequence data
499 // TODO consider using getSequenceSelection instead here
500 String reply = new AppletFormatAdapter().formatSequences(format,
501 new Alignment(alf.viewport.getSelectionAsNewSequence()),
505 } catch (Exception ex)
507 ex.printStackTrace();
508 return "Error retrieving alignment in " + format + " format. ";
516 * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
518 public String getAlignmentOrder()
520 return getAlignmentOrderFrom(getDefaultTargetFrame());
527 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
530 public String getAlignmentOrderFrom(AlignFrame alf)
532 return getAlignmentOrderFrom(alf, separator);
539 * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
540 * , java.lang.String)
542 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
544 AlignmentI alorder = alf.getAlignViewport().getAlignment();
545 String[] order = new String[alorder.getHeight()];
546 for (int i = 0; i < order.length; i++)
548 order[i] = alorder.getSequenceAt(i).getName();
550 return arrayToSeparatorList(order);
556 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
559 public String orderBy(String order, String undoName)
561 return orderBy(order, undoName, separator);
567 * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
568 * java.lang.String, java.lang.String)
570 public String orderBy(String order, String undoName, String sep)
572 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
579 * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
580 * java.lang.String, java.lang.String, java.lang.String)
582 public String orderAlignmentBy(AlignFrame alf, String order,
583 String undoName, String sep)
585 String[] ids = separatorListToArray(order, sep);
586 SequenceI[] sqs = null;
587 if (ids != null && ids.length > 0)
589 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
590 alf.viewport.getAlignment().getSequencesArray());
592 sqs = new SequenceI[ids.length];
593 for (int i = 0; i < ids.length; i++)
595 if (ids[i].trim().length() == 0)
599 SequenceI sq = matcher.findIdMatch(ids[i]);
607 SequenceI[] sqq = new SequenceI[s];
608 System.arraycopy(sqs, 0, sqq, 0, s);
621 final AlignmentOrder aorder = new AlignmentOrder(sqs);
623 if (undoName != null && undoName.trim().length() == 0)
627 final String _undoName = undoName;
628 // TODO: deal with synchronization here: cannot raise any events until after
629 // this has returned.
630 return alf.sortBy(aorder, _undoName) ? "true" : "";
636 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
638 public String getAlignment(String format)
640 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
647 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
650 public String getAlignmentFrom(AlignFrame alf, String format)
652 return getAlignmentFrom(alf, format, "true");
658 * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String,
661 public String getAlignment(String format, String suffix)
663 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
670 * jalview.bin.JalviewLiteJsApi#getAlignmentFrom(jalview.appletgui.AlignFrame,
671 * java.lang.String, java.lang.String)
673 public String getAlignmentFrom(AlignFrame alf, String format,
678 boolean seqlimits = suffix.equalsIgnoreCase("true");
680 String reply = new AppletFormatAdapter().formatSequences(format,
681 alf.viewport.getAlignment(), seqlimits);
683 } catch (Exception ex)
685 ex.printStackTrace();
686 return "Error retrieving alignment in " + format + " format. ";
693 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
695 public void loadAnnotation(String annotation)
697 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
704 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
705 * , java.lang.String)
707 public void loadAnnotationFrom(AlignFrame alf, String annotation)
709 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
710 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
712 alf.alignPanel.fontChanged();
713 alf.alignPanel.setScrollValues(0, 0);
717 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
724 * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
726 public void loadFeatures(String features, boolean autoenabledisplay)
728 loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
735 * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
736 * , java.lang.String)
738 public boolean loadFeaturesFrom(AlignFrame alf, String features,
739 boolean autoenabledisplay)
741 return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
748 * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
750 public String getFeatures(String format)
752 return getFeaturesFrom(getDefaultTargetFrame(), format);
759 * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
762 public String getFeaturesFrom(AlignFrame alf, String format)
764 return alf.outputFeatures(false, format);
770 * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
772 public String getAnnotation()
774 return getAnnotationFrom(getDefaultTargetFrame());
781 * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
784 public String getAnnotationFrom(AlignFrame alf)
786 return alf.outputAnnotations(false);
792 * @see jalview.bin.JalviewLiteJsApi#newView()
794 public AlignFrame newView()
796 return newViewFrom(getDefaultTargetFrame());
802 * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
804 public AlignFrame newView(String name)
806 return newViewFrom(getDefaultTargetFrame(), name);
812 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
814 public AlignFrame newViewFrom(AlignFrame alf)
816 return alf.newView(null);
822 * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
825 public AlignFrame newViewFrom(AlignFrame alf, String name)
827 return alf.newView(name);
833 * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
836 public AlignFrame loadAlignment(String text, String title)
840 String format = new IdentifyFile().Identify(text,
841 AppletFormatAdapter.PASTE);
844 al = new AppletFormatAdapter().readFile(text,
845 AppletFormatAdapter.PASTE, format);
846 if (al.getHeight() > 0)
848 return new AlignFrame(al, this, title, false);
850 } catch (java.io.IOException ex)
852 ex.printStackTrace();
860 * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
862 public void setMouseoverListener(String listener)
864 setMouseoverListener(currentAlignFrame, listener);
867 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
873 * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
874 * , java.lang.String)
876 public void setMouseoverListener(AlignFrame af, String listener)
878 if (listener != null)
880 listener = listener.trim();
881 if (listener.length() == 0)
884 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
888 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
890 javascriptListeners.addElement(mol);
891 StructureSelectionManager.getStructureSelectionManager(this)
892 .addStructureViewerListener(mol);
895 System.err.println("Added a mouseover listener for "
896 + ((af == null) ? "All frames" : "Just views for "
897 + af.getAlignViewport().getSequenceSetId()));
898 System.err.println("There are now " + javascriptListeners.size()
899 + " listeners in total.");
906 * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
908 public void setSelectionListener(String listener)
910 setSelectionListener(null, listener);
917 * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
918 * , java.lang.String)
920 public void setSelectionListener(AlignFrame af, String listener)
922 if (listener != null)
924 listener = listener.trim();
925 if (listener.length() == 0)
928 .println("jalview Javascript error: Ignoring empty function for selection listener.");
932 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
934 javascriptListeners.addElement(mol);
935 StructureSelectionManager.getStructureSelectionManager(this)
936 .addSelectionListener(mol);
939 System.err.println("Added a selection listener for "
940 + ((af == null) ? "All frames" : "Just views for "
941 + af.getAlignViewport().getSequenceSetId()));
942 System.err.println("There are now " + javascriptListeners.size()
943 + " listeners in total.");
950 * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
953 public void setStructureListener(String listener, String modelSet)
955 if (listener != null)
957 listener = listener.trim();
958 if (listener.length() == 0)
961 .println("jalview Javascript error: Ignoring empty function for selection listener.");
965 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
966 this, listener, separatorListToArray(modelSet));
967 javascriptListeners.addElement(mol);
968 StructureSelectionManager.getStructureSelectionManager(this)
969 .addStructureViewerListener(mol);
972 System.err.println("Added a javascript structure viewer listener '"
974 System.err.println("There are now " + javascriptListeners.size()
975 + " listeners in total.");
983 * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
984 * .AlignFrame, java.lang.String)
986 public void removeJavascriptListener(AlignFrame af, String listener)
988 if (listener != null)
990 listener = listener.trim();
991 if (listener.length() == 0)
996 boolean rprt = false;
997 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
999 Object lstn = javascriptListeners.elementAt(ms);
1000 JsCallBack lstner = (JsCallBack) lstn;
1001 if ((af == null || lstner.getAlignFrame() == af)
1002 && (listener == null || lstner.getListenerFunction().equals(
1005 javascriptListeners.removeElement(lstner);
1007 if (lstner instanceof SelectionListener)
1009 StructureSelectionManager.getStructureSelectionManager(this)
1010 .removeSelectionListener((SelectionListener) lstner);
1014 StructureSelectionManager.getStructureSelectionManager(this)
1015 .removeStructureViewerListener(lstner, null);
1020 System.err.println("Removed listener '" + listener + "'");
1030 System.err.println("There are now " + javascriptListeners.size()
1031 + " listeners in total.");
1037 System.err.println("Applet " + getName() + " stop().");
1041 public void destroy()
1043 System.err.println("Applet " + getName() + " destroy().");
1047 private void tidyUp()
1050 if (currentAlignFrame != null && currentAlignFrame.viewport != null
1051 && currentAlignFrame.viewport.applet != null)
1053 AlignViewport av = currentAlignFrame.viewport;
1054 currentAlignFrame.closeMenuItem_actionPerformed();
1056 currentAlignFrame = null;
1058 if (javascriptListeners != null)
1060 while (javascriptListeners.size() > 0)
1062 jalview.javascript.JSFunctionExec mol = javascriptListeners
1064 javascriptListeners.removeElement(mol);
1065 if (mol instanceof SelectionListener)
1067 StructureSelectionManager.getStructureSelectionManager(this)
1068 .removeSelectionListener((SelectionListener) mol);
1072 StructureSelectionManager.getStructureSelectionManager(this)
1073 .removeStructureViewerListener(mol, null);
1078 if (jsFunctionExec != null)
1080 jsFunctionExec.stopQueue();
1081 jsFunctionExec.jvlite = null;
1083 initialAlignFrame = null;
1084 jsFunctionExec = null;
1085 javascriptListeners = null;
1086 StructureSelectionManager.release(this);
1089 private jalview.javascript.JSFunctionExec jsFunctionExec;
1094 * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
1095 * java.lang.String, java.lang.String)
1097 public void mouseOverStructure(final String pdbResNum,
1098 final String chain, final String pdbfile)
1100 final StructureSelectionManagerProvider me = this;
1101 java.awt.EventQueue.invokeLater(new Runnable()
1108 StructureSelectionManager.getStructureSelectionManager(me)
1109 .mouseOverStructure(new Integer(pdbResNum).intValue(),
1113 System.err.println("mouseOver for '" + pdbResNum
1114 + "' in chain '" + chain + "' in structure '" + pdbfile
1117 } catch (NumberFormatException e)
1119 System.err.println("Ignoring invalid residue number string '"
1131 * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
1132 * java.lang.String, java.lang.String)
1134 public void scrollViewToIn(final AlignFrame alf, final String topRow,
1135 final String leftHandColumn)
1137 java.awt.EventQueue.invokeLater(new Runnable()
1144 alf.scrollTo(new Integer(topRow).intValue(), new Integer(
1145 leftHandColumn).intValue());
1147 } catch (Exception ex)
1149 System.err.println("Couldn't parse integer arguments (topRow='"
1150 + topRow + "' and leftHandColumn='" + leftHandColumn
1152 ex.printStackTrace();
1162 * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
1163 * .AlignFrame, java.lang.String)
1166 public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
1169 java.awt.EventQueue.invokeLater(new Runnable()
1176 alf.scrollToRow(new Integer(topRow).intValue());
1178 } catch (Exception ex)
1180 System.err.println("Couldn't parse integer arguments (topRow='"
1182 ex.printStackTrace();
1193 * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
1194 * .AlignFrame, java.lang.String)
1197 public void scrollViewToColumnIn(final AlignFrame alf,
1198 final String leftHandColumn)
1200 java.awt.EventQueue.invokeLater(new Runnable()
1208 alf.scrollToColumn(new Integer(leftHandColumn).intValue());
1210 } catch (Exception ex)
1213 .println("Couldn't parse integer arguments (leftHandColumn='"
1214 + leftHandColumn + "')");
1215 ex.printStackTrace();
1222 // //////////////////////////////////////////////
1223 // //////////////////////////////////////////////
1225 public static int lastFrameX = 200;
1227 public static int lastFrameY = 200;
1229 boolean fileFound = true;
1231 String file = "No file";
1233 Button launcher = new Button("Start Jalview");
1236 * The currentAlignFrame is static, it will change if and when the user
1237 * selects a new window. Note that it will *never* point back to the embedded
1238 * AlignFrame if the applet is started as embedded on the page and then
1239 * afterwards a new view is created.
1241 public AlignFrame currentAlignFrame = null;
1244 * This is the first frame to be displayed, and does not change. API calls
1245 * will default to this instance if currentAlignFrame is null.
1247 AlignFrame initialAlignFrame = null;
1249 boolean embedded = false;
1251 private boolean checkForJmol = true;
1253 private boolean checkedForJmol = false; // ensure we don't check for jmol
1255 // every time the app is re-inited
1257 public boolean jmolAvailable = false;
1259 private boolean alignPdbStructures = false;
1262 * use an external structure viewer exclusively (no jmols or MCViews will be
1263 * opened by JalviewLite itself)
1265 public boolean useXtrnalSviewer = false;
1267 public static boolean debug = false;
1269 static String builddate = null, version = null;
1271 private static void initBuildDetails()
1273 if (builddate == null)
1275 builddate = "unknown";
1277 java.net.URL url = JalviewLite.class
1278 .getResource("/.build_properties");
1283 BufferedReader reader = new BufferedReader(new InputStreamReader(
1286 while ((line = reader.readLine()) != null)
1288 if (line.indexOf("VERSION") > -1)
1290 version = line.substring(line.indexOf("=") + 1);
1292 if (line.indexOf("BUILD_DATE") > -1)
1294 builddate = line.substring(line.indexOf("=") + 1);
1297 } catch (Exception ex)
1299 ex.printStackTrace();
1305 public static String getBuildDate()
1311 public static String getVersion()
1317 // public JSObject scriptObject = null;
1320 * init method for Jalview Applet
1324 // remove any handlers that might be hanging around from an earlier instance
1329 System.err.println("Applet context is '"
1330 + getAppletContext().getClass().toString() + "'");
1332 JSObject scriptObject = JSObject.getWindow(this);
1333 if (debug && scriptObject != null)
1335 System.err.println("Applet has Javascript callback support.");
1338 } catch (Exception ex)
1341 .println("Warning: No JalviewLite javascript callbacks available.");
1344 ex.printStackTrace();
1348 * turn on extra applet debugging
1350 String dbg = getParameter("debug");
1353 debug = dbg.toLowerCase().equals("true");
1358 System.err.println("JalviewLite Version " + getVersion());
1359 System.err.println("Build Date : " + getBuildDate());
1362 String externalsviewer = getParameter("externalstructureviewer");
1363 if (externalsviewer != null)
1365 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
1369 * if true disable the check for jmol
1371 String chkforJmol = getParameter("nojmol");
1372 if (chkforJmol != null)
1374 checkForJmol = !chkforJmol.equals("true");
1377 * get the separator parameter if present
1379 String sep = getParameter("separator");
1382 if (sep.length() > 0)
1387 System.err.println("Separator set to '" + separator + "'");
1393 "Invalid separator parameter - must be non-zero length");
1399 String param = getParameter("RGB");
1405 r = Integer.parseInt(param.substring(0, 2), 16);
1406 g = Integer.parseInt(param.substring(2, 4), 16);
1407 b = Integer.parseInt(param.substring(4, 6), 16);
1408 } catch (Exception ex)
1415 param = getParameter("label");
1418 launcher.setLabel(param);
1421 setBackground(new Color(r, g, b));
1423 file = getParameter("file");
1427 // Maybe the sequences are added as parameters
1428 StringBuffer data = new StringBuffer("PASTE");
1430 while ((file = getParameter("sequence" + i)) != null)
1432 data.append(file.toString() + "\n");
1435 if (data.length() > 5)
1437 file = data.toString();
1441 final JalviewLite jvapplet = this;
1442 if (getParameter("embedded") != null
1443 && getParameter("embedded").equalsIgnoreCase("true"))
1445 // Launch as embedded applet in page
1447 LoadingThread loader = new LoadingThread(file, jvapplet);
1450 else if (file != null)
1452 if (getParameter("showbutton") == null
1453 || !getParameter("showbutton").equalsIgnoreCase("false"))
1455 // Add the JalviewLite 'Button' to the page
1457 launcher.addActionListener(new java.awt.event.ActionListener()
1459 public void actionPerformed(ActionEvent e)
1461 LoadingThread loader = new LoadingThread(file, jvapplet);
1468 // Open jalviewLite immediately.
1469 LoadingThread loader = new LoadingThread(file, jvapplet);
1475 // jalview initialisation with no alignment. loadAlignment() method can
1476 // still be called to open new alignments.
1483 private void callInitCallback()
1485 String initjscallback = getParameter("oninit");
1486 if (initjscallback == null)
1490 initjscallback = initjscallback.trim();
1491 if (initjscallback.length() > 0)
1493 JSObject scriptObject = null;
1496 scriptObject = JSObject.getWindow(this);
1497 } catch (Exception ex)
1501 if (scriptObject != null)
1505 // do onInit with the JS executor thread
1506 new JSFunctionExec(this).executeJavascriptFunction(true,
1507 initjscallback, null, "Calling oninit callback '"
1508 + initjscallback + "'.");
1509 } catch (Exception e)
1511 System.err.println("Exception when executing _oninit callback '"
1512 + initjscallback + "'.");
1513 e.printStackTrace();
1518 System.err.println("Not executing _oninit callback '"
1519 + initjscallback + "' - no scripting allowed.");
1525 * Initialises and displays a new java.awt.Frame
1528 * java.awt.Frame to be displayed
1530 * title of new frame
1532 * width if new frame
1534 * height of new frame
1536 public static void addFrame(final Frame frame, String title, int width,
1539 frame.setLocation(lastFrameX, lastFrameY);
1542 frame.setSize(width, height);
1543 frame.setTitle(title);
1544 frame.addWindowListener(new WindowAdapter()
1546 public void windowClosing(WindowEvent e)
1548 if (frame instanceof AlignFrame)
1550 AlignViewport vp = ((AlignFrame) frame).viewport;
1551 ((AlignFrame) frame).closeMenuItem_actionPerformed();
1552 if (vp.applet.currentAlignFrame == frame)
1554 vp.applet.currentAlignFrame = null;
1562 if (frame instanceof EmbmenuFrame)
1564 ((EmbmenuFrame) frame).destroyMenus();
1566 frame.setMenuBar(null);
1570 public void windowActivated(WindowEvent e)
1572 if (frame instanceof AlignFrame)
1574 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
1577 System.err.println("Activated window " + frame);
1581 super.windowActivated(e);
1584 * Probably not necessary to do this - see TODO above. (non-Javadoc)
1587 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
1590 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
1591 * frame) { currentAlignFrame = null; if (debug) {
1592 * System.err.println("Deactivated window "+frame); } }
1593 * super.windowDeactivated(e); }
1596 frame.setVisible(true);
1600 * This paints the background surrounding the "Launch Jalview button" <br>
1602 * If file given in parameter not found, displays error message
1607 public void paint(Graphics g)
1611 g.setColor(new Color(200, 200, 200));
1612 g.setColor(Color.cyan);
1613 g.fillRect(0, 0, getSize().width, getSize().height);
1614 g.setColor(Color.red);
1615 g.drawString(MessageManager.getString("label.jalview_cannot_open_file"), 5, 15);
1616 g.drawString("\"" + file + "\"", 5, 30);
1620 g.setColor(Color.black);
1621 g.setFont(new Font("Arial", Font.BOLD, 24));
1622 g.drawString(MessageManager.getString("label.jalview_applet"), 50, getSize().height / 2 - 30);
1623 g.drawString(MessageManager.getString("label.loading_data") + "...", 50, getSize().height / 2);
1628 * get all components associated with the applet of the given type
1633 public Vector getAppletWindow(Class class1)
1635 Vector wnds = new Vector();
1636 Component[] cmp = getComponents();
1639 for (int i = 0; i < cmp.length; i++)
1641 if (class1.isAssignableFrom(cmp[i].getClass()))
1643 wnds.addElement(cmp);
1650 class LoadJmolThread extends Thread
1652 private boolean running = false;
1656 if (running || checkedForJmol)
1665 if (!System.getProperty("java.version").startsWith("1.1"))
1667 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1668 jmolAvailable = true;
1673 .println("Jmol not available - Using MCview for structures");
1675 } catch (java.lang.ClassNotFoundException ex)
1681 jmolAvailable = false;
1685 .println("Skipping Jmol check. Will use MCView (probably)");
1688 checkedForJmol = true;
1692 public boolean notFinished()
1694 return running || !checkedForJmol;
1698 class LoadingThread extends Thread
1701 * State variable: File source
1706 * State variable: protocol for access to file source
1711 * State variable: format of file source
1719 private void dbgMsg(String msg)
1723 System.err.println(msg);
1728 * update the protocol state variable for accessing the datasource located
1732 * @return possibly updated datasource string
1734 public String setProtocolState(String file)
1736 if (file.startsWith("PASTE"))
1738 file = file.substring(5);
1739 protocol = AppletFormatAdapter.PASTE;
1741 else if (inArchive(file))
1743 protocol = AppletFormatAdapter.CLASSLOADER;
1747 file = addProtocol(file);
1748 protocol = AppletFormatAdapter.URL;
1750 dbgMsg("Protocol identified as '" + protocol + "'");
1754 public LoadingThread(String _file, JalviewLite _applet)
1762 LoadJmolThread jmolchecker = new LoadJmolThread();
1763 jmolchecker.start();
1764 while (jmolchecker.notFinished())
1766 // wait around until the Jmol check is complete.
1770 } catch (Exception e)
1776 // applet.callInitCallback();
1779 private void startLoading()
1781 AlignFrame newAlignFrame;
1782 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1783 file = setProtocolState(_file);
1785 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1786 dbgMsg("File identified as '" + format + "'");
1787 dbgMsg("Loading started.");
1788 Alignment al = null;
1791 al = new AppletFormatAdapter().readFile(file, protocol, format);
1792 } catch (java.io.IOException ex)
1794 dbgMsg("File load exception.");
1795 ex.printStackTrace();
1800 FileParse fp = new FileParse(file, protocol);
1802 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1804 while ((ln = fp.nextLine()) != null)
1808 dbgMsg(">>>Dump finished.");
1809 } catch (Exception e)
1812 .println("Exception when trying to dump the content of the file parameter.");
1813 e.printStackTrace();
1817 if ((al != null) && (al.getHeight() > 0))
1819 dbgMsg("Successfully loaded file.");
1820 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1821 if (initialAlignFrame == null)
1823 initialAlignFrame = newAlignFrame;
1825 // update the focus.
1826 currentAlignFrame = newAlignFrame;
1828 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1830 newAlignFrame.setTitle(MessageManager.formatMessage("label.sequences_from", new String[]{applet.getDocumentBase().toString()}));
1833 newAlignFrame.statusBar.setText(MessageManager.formatMessage("label.successfully_loaded_file", new String []{file}));
1835 String treeFile = applet.getParameter("tree");
1836 if (treeFile == null)
1838 treeFile = applet.getParameter("treeFile");
1841 if (treeFile != null)
1845 treeFile = setProtocolState(treeFile);
1847 * if (inArchive(treeFile)) { protocol =
1848 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1849 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1851 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1856 if (fin.getTree() != null)
1858 newAlignFrame.loadTree(fin, treeFile);
1859 dbgMsg("Successfuly imported tree.");
1863 dbgMsg("Tree parameter did not resolve to a valid tree.");
1865 } catch (Exception ex)
1867 ex.printStackTrace();
1872 * Try to load T-Coffee score file
1874 String sScoreFile = applet.getParameter("scoreFile");
1875 if (sScoreFile != null && !"".equals(sScoreFile))
1882 .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
1884 if (!newAlignFrame.loadScoreFile(sScoreFile))
1887 .println("Failed to parse T-COFFEE parameter as a valid score file ('"
1888 + sScoreFile + "')");
1890 } catch (Exception e)
1892 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
1893 sScoreFile, e.getMessage());
1897 // ///////////////////////////
1898 // modify display of features
1899 // we do this before any features have been loaded, ensuring any hidden
1900 // groups are hidden when features first displayed
1902 // hide specific groups
1904 String param = applet.getParameter("hidefeaturegroups");
1907 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1909 // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1911 // show specific groups
1912 param = applet.getParameter("showfeaturegroups");
1915 newAlignFrame.setFeatureGroupState(separatorListToArray(param),
1917 // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1919 // and now load features
1920 param = applet.getParameter("features");
1923 param = setProtocolState(param);
1925 newAlignFrame.parseFeaturesFile(param, protocol);
1928 param = applet.getParameter("showFeatureSettings");
1929 if (param != null && param.equalsIgnoreCase("true"))
1931 newAlignFrame.viewport.showSequenceFeatures(true);
1932 new FeatureSettings(newAlignFrame.alignPanel);
1935 param = applet.getParameter("annotations");
1938 param = setProtocolState(param);
1940 if (new AnnotationFile().readAnnotationFile(
1941 newAlignFrame.viewport.getAlignment(), param, protocol))
1943 newAlignFrame.alignPanel.fontChanged();
1944 newAlignFrame.alignPanel.setScrollValues(0, 0);
1949 .println("Annotations were not added from annotation file '"
1955 param = applet.getParameter("jnetfile");
1960 param = setProtocolState(param);
1961 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
1963 JnetAnnotationMaker.add_annotation(predictions,
1964 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
1972 newAlignFrame.alignPanel.fontChanged();
1973 newAlignFrame.alignPanel.setScrollValues(0, 0);
1974 } catch (Exception ex)
1976 ex.printStackTrace();
1980 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
1981 * - related to JAL-434
1983 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1986 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1989 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1991 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1994 int pdbFileCount = 0;
1995 // Accumulate pdbs here if they are heading for the same view (if
1996 // alignPdbStructures is true)
1997 Vector pdbs = new Vector();
1998 // create a lazy matcher if we're asked to
1999 jalview.analysis.SequenceIdMatcher matcher = (applet
2000 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
2001 newAlignFrame.getAlignViewport().getAlignment()
2002 .getSequencesArray()) : null;
2006 if (pdbFileCount > 0)
2008 param = applet.getParameter("PDBFILE" + pdbFileCount);
2012 param = applet.getParameter("PDBFILE");
2017 PDBEntry pdb = new PDBEntry();
2020 SequenceI[] seqs = null;
2021 String[] chains = null;
2023 StringTokenizer st = new StringTokenizer(param, " ");
2025 if (st.countTokens() < 2)
2027 String sequence = applet.getParameter("PDBSEQ");
2028 if (sequence != null)
2029 seqs = new SequenceI[]
2030 { matcher == null ? (Sequence) newAlignFrame
2031 .getAlignViewport().getAlignment()
2032 .findName(sequence) : matcher.findIdMatch(sequence) };
2037 param = st.nextToken();
2038 Vector tmp = new Vector();
2039 Vector tmp2 = new Vector();
2041 while (st.hasMoreTokens())
2043 seqstring = st.nextToken();
2044 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
2045 if (st2.countTokens() > 1)
2047 // This is the chain
2048 tmp2.addElement(st2.nextToken());
2049 seqstring = st2.nextToken();
2051 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
2052 .getAlignViewport().getAlignment()
2053 .findName(seqstring) : matcher
2054 .findIdMatch(seqstring));
2057 seqs = new SequenceI[tmp.size()];
2059 if (tmp2.size() == tmp.size())
2061 chains = new String[tmp2.size()];
2062 tmp2.copyInto(chains);
2065 param = setProtocolState(param);
2067 if (// !jmolAvailable
2069 protocol == AppletFormatAdapter.CLASSLOADER
2070 && !useXtrnalSviewer)
2072 // Re: JAL-357 : the bug isn't a problem if we are using an
2074 // TODO: verify this Re:
2075 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
2076 // This exception preserves the current behaviour where, even if
2077 // the local pdb file was identified in the class loader
2078 protocol = AppletFormatAdapter.URL; // this is probably NOT
2080 param = addProtocol(param); //
2087 for (int i = 0; i < seqs.length; i++)
2089 if (seqs[i] != null)
2091 ((Sequence) seqs[i]).addPDBId(pdb);
2095 if (JalviewLite.debug)
2097 // this may not really be a problem but we give a warning
2100 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
2106 if (!alignPdbStructures)
2108 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
2113 pdbs.addElement(new Object[]
2114 { pdb, seqs, chains, new String(protocol) });
2120 } while (param != null || pdbFileCount < 10);
2121 if (pdbs.size() > 0)
2123 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
2124 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
2125 String[][] chains = new String[pdbs.size()][];
2126 String[] protocols = new String[pdbs.size()];
2127 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
2129 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
2130 pdb[pdbsi] = (PDBEntry) o[0];
2131 seqs[pdbsi] = (SequenceI[]) o[1];
2132 chains[pdbsi] = (String[]) o[2];
2133 protocols[pdbsi] = (String) o[3];
2135 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
2143 applet.remove(launcher);
2150 * Discovers whether the given file is in the Applet Archive
2156 boolean inArchive(String file)
2158 // This might throw a security exception in certain browsers
2159 // Netscape Communicator for instance.
2162 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
2165 System.err.println("Resource '" + file + "' was "
2166 + (rtn ? "" : "not") + " located by classloader.");
2169 } catch (Exception ex)
2171 System.out.println("Exception checking resources: " + file + " "
2177 String addProtocol(String file)
2179 if (file.indexOf("://") == -1)
2181 String fl = applet.resolveUrlForLocalOrAbsolute(file,
2185 if (new java.net.URL(fl).openStream() != null)
2189 System.err.println("Prepended document base for resource: '"
2194 } catch (Exception x)
2198 fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
2201 if (new java.net.URL(fl).openStream() != null)
2205 System.err.println("Prepended codebase for resource: '"
2210 } catch (Exception x)
2222 * @return the default alignFrame acted on by the public applet methods. May
2223 * return null with an error message on System.err indicating the
2226 public AlignFrame getDefaultTargetFrame()
2228 if (currentAlignFrame != null)
2230 return currentAlignFrame;
2232 if (initialAlignFrame != null)
2234 return initialAlignFrame;
2237 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
2242 * separator used for separatorList
2244 protected String separator = "" + ((char) 0x00AC); // the default used to be
2245 // '|' but many sequence
2246 // IDS include pipes.
2249 * set to enable the URL based javascript execution mechanism
2251 public boolean jsfallbackEnabled = false;
2254 * parse the string into a list
2257 * @return elements separated by separator
2259 public String[] separatorListToArray(String list)
2261 return separatorListToArray(list, separator);
2265 * parse the string into a list
2269 * @return elements separated by separator
2271 public String[] separatorListToArray(String list, String separator)
2273 // note separator local variable intentionally masks object field
2274 int seplen = separator.length();
2275 if (list == null || list.equals("") || list.equals(separator))
2277 java.util.Vector jv = new Vector();
2279 while ((pos = list.indexOf(separator, cp)) > cp)
2281 jv.addElement(list.substring(cp, pos));
2284 if (cp < list.length())
2286 String c = list.substring(cp);
2287 if (!c.equals(separator))
2294 String[] v = new String[jv.size()];
2295 for (int i = 0; i < v.length; i++)
2297 v[i] = (String) jv.elementAt(i);
2299 jv.removeAllElements();
2302 System.err.println("Array from '" + separator
2303 + "' separated List:\n" + v.length);
2304 for (int i = 0; i < v.length; i++)
2306 System.err.println("item " + i + " '" + v[i] + "'");
2313 System.err.println("Empty Array from '" + separator
2314 + "' separated List");
2320 * concatenate the list with separator
2323 * @return concatenated string
2325 public String arrayToSeparatorList(String[] list)
2327 return arrayToSeparatorList(list, separator);
2331 * concatenate the list with separator
2335 * @return concatenated string
2337 public String arrayToSeparatorList(String[] list, String separator)
2339 StringBuffer v = new StringBuffer();
2340 if (list != null && list.length > 0)
2342 for (int i = 0, iSize = list.length; i < iSize; i++)
2344 if (list[i] != null)
2348 v.append(separator);
2355 System.err.println("Returning '" + separator
2356 + "' separated List:\n");
2357 System.err.println(v);
2359 return v.toString();
2363 System.err.println("Returning empty '" + separator
2364 + "' separated List\n");
2366 return "" + separator;
2372 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroups()
2374 public String getFeatureGroups()
2376 String lst = arrayToSeparatorList(getDefaultTargetFrame()
2377 .getFeatureGroups());
2385 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOn(jalview.appletgui.AlignFrame
2388 public String getFeatureGroupsOn(AlignFrame alf)
2390 String lst = arrayToSeparatorList(alf.getFeatureGroups());
2397 * @see jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfState(boolean)
2399 public String getFeatureGroupsOfState(boolean visible)
2401 return arrayToSeparatorList(getDefaultTargetFrame()
2402 .getFeatureGroupsOfState(visible));
2409 * jalview.bin.JalviewLiteJsApi#getFeatureGroupsOfStateOn(jalview.appletgui
2410 * .AlignFrame, boolean)
2412 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2414 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
2420 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupStateOn(jalview.appletgui.
2421 * AlignFrame, java.lang.String, boolean)
2423 public void setFeatureGroupStateOn(final AlignFrame alf,
2424 final String groups, boolean state)
2426 final boolean st = state;// !(state==null || state.equals("") ||
2427 // state.toLowerCase().equals("false"));
2428 java.awt.EventQueue.invokeLater(new Runnable()
2433 alf.setFeatureGroupState(separatorListToArray(groups), st);
2441 * @see jalview.bin.JalviewLiteJsApi#setFeatureGroupState(java.lang.String,
2444 public void setFeatureGroupState(String groups, boolean state)
2446 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
2452 * @see jalview.bin.JalviewLiteJsApi#getSeparator()
2454 public String getSeparator()
2462 * @see jalview.bin.JalviewLiteJsApi#setSeparator(java.lang.String)
2464 public void setSeparator(String separator)
2466 if (separator == null || separator.length() < 1)
2469 separator = "" + ((char) 0x00AC);
2471 this.separator = separator;
2474 System.err.println("Default Separator now: '" + separator + "'");
2479 * get boolean value of applet parameter 'name' and return default if
2480 * parameter is not set
2485 * the value to return otherwise
2486 * @return true or false
2488 public boolean getDefaultParameter(String name, boolean def)
2491 if ((stn = getParameter(name)) == null)
2495 if (stn.toLowerCase().equals("true"))
2505 * @see jalview.bin.JalviewLiteJsApi#addPdbFile(jalview.appletgui.AlignFrame,
2506 * java.lang.String, java.lang.String, java.lang.String)
2508 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
2509 String pdbEntryString, String pdbFile)
2511 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
2514 protected void setAlignPdbStructures(boolean alignPdbStructures)
2516 this.alignPdbStructures = alignPdbStructures;
2519 public boolean isAlignPdbStructures()
2521 return alignPdbStructures;
2526 // callInitCallback();
2529 private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
2531 private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
2533 public void setJsMessageSet(String messageclass, String viewId,
2534 String[] colcommands)
2536 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2539 msgset = new Hashtable<String, String[]>();
2540 jsmessages.put(messageclass, msgset);
2542 msgset.put(viewId, colcommands);
2543 long[] l = new long[colcommands.length];
2544 for (int i = 0; i < colcommands.length; i++)
2546 l[i] = colcommands[i].hashCode();
2548 jshashes.put(messageclass + "|" + viewId, l);
2554 * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
2557 public String getJsMessage(String messageclass, String viewId)
2559 Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
2562 String[] msgs = msgset.get(viewId);
2565 for (int i = 0; i < msgs.length; i++)
2567 if (msgs[i] != null)
2579 public boolean isJsMessageSetChanged(String string, String string2,
2580 String[] colcommands)
2582 long[] l = jshashes.get(string + "|" + string2);
2583 if (l == null && colcommands != null)
2587 for (int i = 0; i < colcommands.length; i++)
2589 if (l[i] != colcommands[i].hashCode())
2597 private Vector jsExecQueue = new Vector();
2599 public Vector getJsExecQueue()
2604 public void setExecutor(JSFunctionExec jsFunctionExec2)
2606 jsFunctionExec = jsFunctionExec2;
2610 * return the given colour value parameter or the given default if parameter
2617 public Color getDefaultColourParameter(String colparam, Color defcolour)
2619 String colprop = getParameter(colparam);
2620 if (colprop == null || colprop.trim().length() == 0)
2624 Color col = jalview.schemes.ColourSchemeProperty
2625 .getAWTColorFromName(colprop);
2630 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
2631 } catch (Exception ex)
2633 System.err.println("Couldn't parse '" + colprop
2634 + "' as a colour for " + colparam);
2638 return (col == null) ? defcolour : col;
2642 public void openJalviewHelpUrl()
2644 String helpUrl = getParameter("jalviewhelpurl");
2645 if (helpUrl == null || helpUrl.trim().length() < 5)
2647 helpUrl = "http://www.jalview.org/help.html";
2649 showURL(helpUrl, "HELP");
2653 * form a complete URL given a path to a resource and a reference location on
2657 * - an absolute path on the same server as localref or a document
2658 * located relative to localref
2660 * - a URL on the same server as url
2661 * @return a complete URL for the resource located by url
2663 private String resolveUrlForLocalOrAbsolute(String url, URL localref)
2665 String codebase = localref.toString();
2666 if (url.indexOf("/") == 0)
2668 url = codebase.substring(0, codebase.length()
2669 - localref.getFile().length())
2674 url = localref + url;
2680 * open a URL in the browser - resolving it according to relative refs and
2681 * coping with javascript: protocol if necessary.
2686 public void showURL(String url, String target)
2690 if (url.indexOf(":") == -1)
2692 // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
2694 // Should really use docbase, not codebase.
2696 url = resolveUrlForLocalOrAbsolute(
2698 prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
2703 .println("Show url (prepended "
2705 + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
2713 System.err.println("Show url: " + url);
2716 if (url.indexOf("javascript:") == 0)
2718 // no target for the javascript context
2719 getAppletContext().showDocument(new java.net.URL(url));
2723 getAppletContext().showDocument(new java.net.URL(url), target);
2725 } catch (Exception ex)
2727 ex.printStackTrace();
2732 * bind structures in a viewer to any matching sequences in an alignFrame (use
2733 * sequenceIds to limit scope of search to specific sequences)
2737 * @param sequenceIds
2738 * @return TODO: consider making an exception structure for indicating when
2739 * binding fails public SequenceStructureBinding
2740 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
2743 * if (sequenceIds != null && sequenceIds.length() > 0) { return
2744 * alFrame.addStructureViewInstance(viewer,
2745 * separatorListToArray(sequenceIds)); } else { return
2746 * alFrame.addStructureViewInstance(viewer, null); } // return null; }