2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
\r
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.bin;
\r
20 import jalview.api.StructureSelectionManagerProvider;
\r
21 import jalview.appletgui.AlignFrame;
\r
22 import jalview.appletgui.AlignViewport;
\r
23 import jalview.appletgui.EmbmenuFrame;
\r
24 import jalview.appletgui.FeatureSettings;
\r
25 import jalview.datamodel.Alignment;
\r
26 import jalview.datamodel.AlignmentI;
\r
27 import jalview.datamodel.AlignmentOrder;
\r
28 import jalview.datamodel.ColumnSelection;
\r
29 import jalview.datamodel.PDBEntry;
\r
30 import jalview.datamodel.Sequence;
\r
31 import jalview.datamodel.SequenceGroup;
\r
32 import jalview.datamodel.SequenceI;
\r
33 import jalview.io.AnnotationFile;
\r
34 import jalview.io.AppletFormatAdapter;
\r
35 import jalview.io.FileParse;
\r
36 import jalview.io.IdentifyFile;
\r
37 import jalview.io.JnetAnnotationMaker;
\r
38 import jalview.javascript.JSFunctionExec;
\r
39 import jalview.javascript.JsCallBack;
\r
40 import jalview.structure.SelectionListener;
\r
41 import jalview.structure.StructureSelectionManager;
\r
43 import java.applet.Applet;
\r
44 import java.awt.Button;
\r
45 import java.awt.Color;
\r
46 import java.awt.Component;
\r
47 import java.awt.Font;
\r
48 import java.awt.Frame;
\r
49 import java.awt.Graphics;
\r
50 import java.awt.event.ActionEvent;
\r
51 import java.awt.event.WindowAdapter;
\r
52 import java.awt.event.WindowEvent;
\r
53 import java.io.BufferedReader;
\r
54 import java.io.InputStreamReader;
\r
55 import java.util.Hashtable;
\r
56 import java.util.StringTokenizer;
\r
57 import java.util.Vector;
\r
59 import netscape.javascript.JSObject;
\r
62 * Jalview Applet. Runs in Java 1.18 runtime
\r
65 * @version $Revision: 1.92 $
\r
67 public class JalviewLite extends Applet implements StructureSelectionManagerProvider
\r
70 // /////////////////////////////////////////
\r
71 // The following public methods maybe called
\r
72 // externally, eg via javascript in HTML page
\r
74 * @return String list of selected sequence IDs, each terminated by the
\r
75 * 'boolean not' character (""+0x00AC) or (¬)
\r
77 public String getSelectedSequences()
\r
79 return getSelectedSequencesFrom(getDefaultTargetFrame());
\r
84 * separator string or null for default
\r
85 * @return String list of selected sequence IDs, each terminated by given
\r
88 public String getSelectedSequences(String sep)
\r
90 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
\r
95 * alignframe containing selection
\r
96 * @return String list of selected sequence IDs, each terminated by current
\r
97 * default separator sequence
\r
100 public String getSelectedSequencesFrom(AlignFrame alf)
\r
102 return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
\r
106 * get list of selected sequence IDs separated by given separator
\r
109 * window containing selection
\r
111 * separator string to use - default is 'boolean not'
\r
112 * @return String list of selected sequence IDs, each terminated by the given
\r
115 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
\r
117 StringBuffer result = new StringBuffer("");
\r
118 if (sep == null || sep.length() == 0)
\r
120 sep = separator; // "+0x00AC;
\r
122 if (alf.viewport.getSelectionGroup() != null)
\r
124 SequenceI[] seqs = alf.viewport.getSelectionGroup()
\r
125 .getSequencesInOrder(alf.viewport.getAlignment());
\r
127 for (int i = 0; i < seqs.length; i++)
\r
129 result.append(seqs[i].getName());
\r
130 result.append(sep);
\r
134 return result.toString();
\r
139 * @param sequenceId
\r
140 * id of sequence to highlight
\r
142 * integer position [ tobe implemented or range ] on sequence
\r
143 * @param alignedPosition
\r
144 * true/false/empty string - indicate if position is an alignment
\r
145 * column or unaligned sequence position
\r
147 public void highlight(String sequenceId, String position,
\r
148 String alignedPosition)
\r
150 highlightIn(getDefaultTargetFrame(), sequenceId, position,
\r
156 * @param sequenceId
\r
157 * id of sequence to highlight
\r
159 * integer position [ tobe implemented or range ] on sequence
\r
160 * @param alignedPosition
\r
161 * false, blank or something else - indicate if position is an
\r
162 * alignment column or unaligned sequence position
\r
164 public void highlightIn(AlignFrame alf, String sequenceId,
\r
165 String position, String alignedPosition)
\r
167 // TODO: could try to highlight in all alignments if alf==null
\r
168 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
169 alf.viewport.getAlignment().getSequencesArray());
\r
170 SequenceI sq = matcher.findIdMatch(sequenceId);
\r
173 int pos, apos = -1;
\r
176 apos = new Integer(position).intValue();
\r
178 } catch (NumberFormatException ex)
\r
182 // use vamsas listener to broadcast to all listeners in scope
\r
183 if (alignedPosition != null
\r
184 && (alignedPosition.trim().length() == 0 || alignedPosition
\r
185 .toLowerCase().indexOf("false") > -1))
\r
187 StructureSelectionManager.getStructureSelectionManager(this)
\r
188 .mouseOverVamsasSequence(sq, sq.findIndex(apos), null);
\r
192 StructureSelectionManager.getStructureSelectionManager(this)
\r
193 .mouseOverVamsasSequence(sq, apos, null);
\r
200 * select regions of the currrent alignment frame
\r
202 * @param sequenceIds
\r
203 * String separated list of sequence ids or empty string
\r
205 * String separated list { column range or column, ..} or empty
\r
208 public void select(String sequenceIds, String columns)
\r
210 selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
\r
214 * select regions of the currrent alignment frame
\r
217 * String separated list { column range, seq1...seqn sequence ids }
\r
219 * separator between toselect fields
\r
221 public void select(String sequenceIds, String columns, String sep)
\r
223 selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
\r
227 * select regions of the given alignment frame
\r
231 * String separated list { column range, seq1...seqn sequence ids }
\r
233 * separator between toselect fields
\r
235 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
\r
237 selectIn(alf, sequenceIds, columns, separator);
\r
241 * select regions of the given alignment frame
\r
245 * String separated list { column range, seq1...seqn sequence ids }
\r
247 * separator between toselect fields
\r
249 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
\r
252 if (sep == null || sep.length() == 0)
\r
260 System.err.println("Selecting region using separator string '"
\r
261 + separator + "'");
\r
265 String[] ids = separatorListToArray(sequenceIds, sep);
\r
266 String[] cols = separatorListToArray(columns, sep);
\r
267 SequenceGroup sel = new SequenceGroup();
\r
268 ColumnSelection csel = new ColumnSelection();
\r
269 AlignmentI al = alf.viewport.getAlignment();
\r
270 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
271 alf.viewport.getAlignment().getSequencesArray());
\r
272 int start = 0, end = al.getWidth(), alw = al.getWidth();
\r
273 boolean seqsfound = true;
\r
274 if (ids != null && ids.length > 0)
\r
277 for (int i = 0; i < ids.length; i++)
\r
279 if (ids[i].trim().length() == 0)
\r
283 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
287 sel.addSequence(sq, false);
\r
291 boolean inseqpos = false;
\r
292 if (cols != null && cols.length > 0)
\r
294 boolean seset = false;
\r
295 for (int i = 0; i < cols.length; i++)
\r
297 String cl = cols[i].trim();
\r
298 if (cl.length() == 0)
\r
303 if ((p = cl.indexOf("-")) > -1)
\r
305 int from = -1, to = -1;
\r
308 from = new Integer(cl.substring(0, p)).intValue();
\r
310 } catch (NumberFormatException ex)
\r
313 .println("ERROR: Couldn't parse first integer in range element column selection string '"
\r
314 + cl + "' - format is 'from-to'");
\r
319 to = new Integer(cl.substring(p + 1)).intValue();
\r
321 } catch (NumberFormatException ex)
\r
324 .println("ERROR: Couldn't parse second integer in range element column selection string '"
\r
325 + cl + "' - format is 'from-to'");
\r
328 if (from >= 0 && to >= 0)
\r
345 // comment to prevent range extension
\r
355 for (int r = from; r <= to; r++)
\r
357 if (r >= 0 && r < alw)
\r
359 csel.addElement(r);
\r
364 System.err.println("Range '" + cl + "' deparsed as [" + from
\r
370 System.err.println("ERROR: Invalid Range '" + cl
\r
371 + "' deparsed as [" + from + "," + to + "]");
\r
379 r = new Integer(cl).intValue();
\r
381 } catch (NumberFormatException ex)
\r
383 if (cl.toLowerCase().equals("sequence"))
\r
385 // we are in the dataset sequence's coordinate frame.
\r
391 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
\r
396 if (r >= 0 && r <= alw)
\r
406 // comment to prevent range extension
\r
416 csel.addElement(r);
\r
419 System.err.println("Point selection '" + cl
\r
420 + "' deparsed as [" + r + "]");
\r
425 System.err.println("ERROR: Invalid Point selection '" + cl
\r
426 + "' deparsed as [" + r + "]");
\r
433 // we only propagate the selection when it was the null selection, or the
\r
434 // given sequences were found in the alignment.
\r
435 if (inseqpos && sel.getSize() > 0)
\r
437 // assume first sequence provides reference frame ?
\r
438 SequenceI rs = sel.getSequenceAt(0);
\r
439 start = rs.findIndex(start);
\r
440 end = rs.findIndex(end);
\r
443 Vector cs = csel.getSelected();
\r
445 for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
\r
447 csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
\r
452 sel.setStartRes(start);
\r
453 sel.setEndRes(end);
\r
454 alf.select(sel, csel);
\r
459 * get sequences selected in current alignFrame and return their alignment in
\r
460 * format 'format' either with or without suffix
\r
463 * - where selection is
\r
465 * - format of alignment file
\r
467 * - "true" to append /start-end string to each sequence ID
\r
468 * @return selected sequences as flat file or empty string if there was no
\r
469 * current selection
\r
471 public String getSelectedSequencesAsAlignment(String format, String suffix)
\r
473 return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
\r
478 * get sequences selected in alf and return their alignment in format 'format'
\r
479 * either with or without suffix
\r
482 * - where selection is
\r
484 * - format of alignment file
\r
486 * - "true" to append /start-end string to each sequence ID
\r
487 * @return selected sequences as flat file or empty string if there was no
\r
488 * current selection
\r
490 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
\r
491 String format, String suffix)
\r
495 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
496 if (alf.viewport.getSelectionGroup() != null)
\r
498 String reply = new AppletFormatAdapter().formatSequences(format,
\r
499 new Alignment(alf.viewport.getSelectionAsNewSequence()),
\r
503 } catch (Exception ex)
\r
505 ex.printStackTrace();
\r
506 return "Error retrieving alignment in " + format + " format. ";
\r
511 public String getAlignmentOrder()
\r
513 return getAlignmentOrderFrom(getDefaultTargetFrame());
\r
516 public String getAlignmentOrderFrom(AlignFrame alf)
\r
518 return getAlignmentOrderFrom(alf, separator);
\r
521 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
\r
523 AlignmentI alorder = alf.getAlignViewport().getAlignment();
\r
524 String[] order = new String[alorder.getHeight()];
\r
525 for (int i = 0; i < order.length; i++)
\r
527 order[i] = alorder.getSequenceAt(i).getName();
\r
529 return arrayToSeparatorList(order);
\r
532 public String orderBy(String order, String undoName)
\r
534 return orderBy(order, undoName, separator);
\r
537 public String orderBy(String order, String undoName, String sep)
\r
539 return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
\r
542 public String orderAlignmentBy(AlignFrame alf, String order,
\r
543 String undoName, String sep)
\r
545 String[] ids = separatorListToArray(order, sep);
\r
546 SequenceI[] sqs = null;
\r
547 if (ids != null && ids.length > 0)
\r
549 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
\r
550 alf.viewport.getAlignment().getSequencesArray());
\r
552 sqs = new SequenceI[ids.length];
\r
553 for (int i = 0; i < ids.length; i++)
\r
555 if (ids[i].trim().length() == 0)
\r
559 SequenceI sq = matcher.findIdMatch(ids[i]);
\r
567 SequenceI[] sqq = new SequenceI[s];
\r
568 System.arraycopy(sqs, 0, sqq, 0, s);
\r
581 AlignmentOrder aorder = new AlignmentOrder(sqs);
\r
583 if (undoName != null && undoName.trim().length() == 0)
\r
588 return alf.sortBy(aorder, undoName) ? "true" : "";
\r
591 public String getAlignment(String format)
\r
593 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
\r
596 public String getAlignmentFrom(AlignFrame alf, String format)
\r
598 return getAlignmentFrom(alf, format, "true");
\r
601 public String getAlignment(String format, String suffix)
\r
603 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
\r
606 public String getAlignmentFrom(AlignFrame alf, String format,
\r
611 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
613 String reply = new AppletFormatAdapter().formatSequences(format,
\r
614 alf.viewport.getAlignment(), seqlimits);
\r
616 } catch (Exception ex)
\r
618 ex.printStackTrace();
\r
619 return "Error retrieving alignment in " + format + " format. ";
\r
623 public void loadAnnotation(String annotation)
\r
625 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
\r
628 public void loadAnnotationFrom(AlignFrame alf, String annotation)
\r
630 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
\r
631 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
\r
633 alf.alignPanel.fontChanged();
\r
634 alf.alignPanel.setScrollValues(0, 0);
\r
638 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
\r
642 public String getFeatures(String format)
\r
644 return getFeaturesFrom(getDefaultTargetFrame(), format);
\r
647 public String getFeaturesFrom(AlignFrame alf, String format)
\r
649 return alf.outputFeatures(false, format);
\r
652 public String getAnnotation()
\r
654 return getAnnotationFrom(getDefaultTargetFrame());
\r
657 public String getAnnotationFrom(AlignFrame alf)
\r
659 return alf.outputAnnotations(false);
\r
662 public AlignFrame newView()
\r
664 return newViewFrom(getDefaultTargetFrame());
\r
667 public AlignFrame newView(String name)
\r
669 return newViewFrom(getDefaultTargetFrame(), name);
\r
672 public AlignFrame newViewFrom(AlignFrame alf)
\r
674 return alf.newView(null);
\r
677 public AlignFrame newViewFrom(AlignFrame alf, String name)
\r
679 return alf.newView(name);
\r
685 * alignment file as a string
\r
688 * @return null or new alignment frame
\r
690 public AlignFrame loadAlignment(String text, String title)
\r
692 Alignment al = null;
\r
694 String format = new IdentifyFile().Identify(text,
\r
695 AppletFormatAdapter.PASTE);
\r
698 al = new AppletFormatAdapter().readFile(text,
\r
699 AppletFormatAdapter.PASTE, format);
\r
700 if (al.getHeight() > 0)
\r
702 return new AlignFrame(al, this, title, false);
\r
704 } catch (java.io.IOException ex)
\r
706 ex.printStackTrace();
\r
711 public void setMouseoverListener(String listener)
\r
713 setMouseoverListener(currentAlignFrame, listener);
\r
716 private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
\r
718 public void setMouseoverListener(AlignFrame af, String listener)
\r
720 if (listener != null)
\r
722 listener = listener.trim();
\r
723 if (listener.length() == 0)
\r
726 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
\r
730 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
\r
731 this, af, listener);
\r
732 javascriptListeners.addElement(mol);
\r
733 StructureSelectionManager.getStructureSelectionManager(this)
\r
734 .addStructureViewerListener(mol);
\r
737 System.err.println("Added a mouseover listener for "
\r
738 + ((af == null) ? "All frames" : "Just views for "
\r
739 + af.getAlignViewport().getSequenceSetId()));
\r
740 System.err.println("There are now " + javascriptListeners.size()
\r
741 + " listeners in total.");
\r
745 public void setSelectionListener(String listener)
\r
747 setSelectionListener(null, listener);
\r
750 public void setSelectionListener(AlignFrame af, String listener)
\r
752 if (listener != null)
\r
754 listener = listener.trim();
\r
755 if (listener.length() == 0)
\r
758 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
762 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
\r
763 this, af, listener);
\r
764 javascriptListeners.addElement(mol);
\r
765 StructureSelectionManager.getStructureSelectionManager(this)
\r
766 .addSelectionListener(mol);
\r
769 System.err.println("Added a selection listener for "
\r
770 + ((af == null) ? "All frames" : "Just views for "
\r
771 + af.getAlignViewport().getSequenceSetId()));
\r
772 System.err.println("There are now " + javascriptListeners.size()
\r
773 + " listeners in total.");
\r
777 public void setStructureListener(String listener, String modelSet)
\r
779 if (listener != null)
\r
781 listener = listener.trim();
\r
782 if (listener.length() == 0)
\r
785 .println("jalview Javascript error: Ignoring empty function for selection listener.");
\r
789 jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(
\r
790 this, listener, separatorListToArray(modelSet));
\r
791 javascriptListeners.addElement(mol);
\r
792 StructureSelectionManager.getStructureSelectionManager(this)
\r
793 .addStructureViewerListener(mol);
\r
796 System.err.println("Added a javascript structure viewer listener '"
\r
798 System.err.println("There are now " + javascriptListeners.size()
\r
799 + " listeners in total.");
\r
804 * remove any callback using the given listener function and associated with
\r
805 * the given alignFrame (or null for all callbacks)
\r
812 public void removeJavascriptListener(AlignFrame af, String listener)
\r
814 if (listener != null)
\r
816 listener = listener.trim();
\r
817 if (listener.length() == 0)
\r
822 boolean rprt = false;
\r
823 for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
\r
825 Object lstn = javascriptListeners.elementAt(ms);
\r
826 JsCallBack lstner = (JsCallBack) lstn;
\r
827 if ((af == null || lstner.getAlignFrame() == af)
\r
828 && (listener == null || lstner.getListenerFunction().equals(
\r
831 javascriptListeners.removeElement(lstner);
\r
833 if (lstner instanceof SelectionListener)
\r
835 StructureSelectionManager.getStructureSelectionManager(this)
\r
836 .removeSelectionListener((SelectionListener) lstner);
\r
840 StructureSelectionManager.getStructureSelectionManager(this)
\r
841 .removeStructureViewerListener(lstner, null);
\r
846 System.err.println("Removed listener '" + listener + "'");
\r
856 System.err.println("There are now " + javascriptListeners.size()
\r
857 + " listeners in total.");
\r
863 System.err.println("Applet "+getName()+" stop().");
\r
866 public void destroy()
\r
868 System.err.println("Applet "+getName()+" destroy().");
\r
871 private void tidyUp()
\r
874 if (currentAlignFrame!=null && currentAlignFrame.viewport!=null
\r
875 && currentAlignFrame.viewport.applet!=null)
\r
877 AlignViewport av = currentAlignFrame.viewport;
\r
878 currentAlignFrame.closeMenuItem_actionPerformed();
\r
880 currentAlignFrame=null;
\r
882 if (javascriptListeners != null)
\r
884 while (javascriptListeners.size() > 0)
\r
886 jalview.javascript.JSFunctionExec mol = javascriptListeners.elementAt(0);
\r
887 javascriptListeners.removeElement(mol);
\r
888 if (mol instanceof SelectionListener)
\r
890 StructureSelectionManager.getStructureSelectionManager(this)
\r
891 .removeSelectionListener((SelectionListener) mol);
\r
895 StructureSelectionManager.getStructureSelectionManager(this)
\r
896 .removeStructureViewerListener(mol, null);
\r
901 if (jsFunctionExec!=null) {
\r
902 jsFunctionExec.stopQueue();
\r
903 jsFunctionExec.jvlite=null;
\r
905 initialAlignFrame=null;
\r
906 jsFunctionExec = null;
\r
907 javascriptListeners=null;
\r
908 StructureSelectionManager.release(this);
\r
910 private jalview.javascript.JSFunctionExec jsFunctionExec;
\r
912 * send a mouseover message to all the alignment windows associated with the
\r
913 * given residue in the pdbfile
\r
919 public void mouseOverStructure(String pdbResNum, String chain,
\r
924 StructureSelectionManager.getStructureSelectionManager(this)
\r
925 .mouseOverStructure(new Integer(pdbResNum).intValue(), chain,
\r
929 System.err.println("mouseOver for '" + pdbResNum + "' in chain '"
\r
930 + chain + "' in structure '" + pdbfile + "'");
\r
932 } catch (NumberFormatException e)
\r
934 System.err.println("Ignoring invalid residue number string '"
\r
935 + pdbResNum + "'");
\r
939 * adjust horizontal/vertical scroll to the make the given location the top left hand corner for given current view
\r
943 * @param leftHandColumn
\r
945 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
\r
948 alf.scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue());
\r
950 } catch (Exception ex)
\r
952 System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"' and leftHandColumn='"+leftHandColumn+"'");
\r
953 ex.printStackTrace();
\r
957 // //////////////////////////////////////////////
\r
958 // //////////////////////////////////////////////
\r
960 public static int lastFrameX = 200;
\r
962 public static int lastFrameY = 200;
\r
964 boolean fileFound = true;
\r
966 String file = "No file";
\r
968 Button launcher = new Button("Start Jalview");
\r
971 * The currentAlignFrame is static, it will change if and when the user
\r
972 * selects a new window. Note that it will *never* point back to the embedded
\r
973 * AlignFrame if the applet is started as embedded on the page and then
\r
974 * afterwards a new view is created.
\r
976 public AlignFrame currentAlignFrame = null;
\r
979 * This is the first frame to be displayed, and does not change. API calls
\r
980 * will default to this instance if currentAlignFrame is null.
\r
982 AlignFrame initialAlignFrame = null;
\r
984 boolean embedded = false;
\r
986 private boolean checkForJmol = true;
\r
988 private boolean checkedForJmol = false; // ensure we don't check for jmol
\r
990 // every time the app is re-inited
\r
992 public boolean jmolAvailable = false;
\r
994 private boolean alignPdbStructures = false;
\r
997 * use an external structure viewer exclusively (no jmols or MCViews will be
\r
998 * opened by JalviewLite itself)
\r
1000 public boolean useXtrnalSviewer = false;
\r
1002 public static boolean debug = false;
\r
1004 static String builddate = null, version = null;
\r
1006 private static void initBuildDetails()
\r
1008 if (builddate == null)
\r
1010 builddate = "unknown";
\r
1012 java.net.URL url = JalviewLite.class
\r
1013 .getResource("/.build_properties");
\r
1018 BufferedReader reader = new BufferedReader(new InputStreamReader(
\r
1019 url.openStream()));
\r
1021 while ((line = reader.readLine()) != null)
\r
1023 if (line.indexOf("VERSION") > -1)
\r
1025 version = line.substring(line.indexOf("=") + 1);
\r
1027 if (line.indexOf("BUILD_DATE") > -1)
\r
1029 builddate = line.substring(line.indexOf("=") + 1);
\r
1032 } catch (Exception ex)
\r
1034 ex.printStackTrace();
\r
1040 public static String getBuildDate()
\r
1042 initBuildDetails();
\r
1046 public static String getVersion()
\r
1048 initBuildDetails();
\r
1052 // public JSObject scriptObject = null;
\r
1055 * init method for Jalview Applet
\r
1057 public void init()
\r
1059 // remove any handlers that might be hanging around from an earlier instance
\r
1064 System.err.println("Applet context is '"
\r
1065 + getAppletContext().getClass().toString() + "'");
\r
1067 JSObject scriptObject = JSObject.getWindow(this);
\r
1068 if (debug && scriptObject != null)
\r
1070 System.err.println("Applet has Javascript callback support.");
\r
1073 } catch (Exception ex)
\r
1076 .println("Warning: No JalviewLite javascript callbacks available.");
\r
1079 ex.printStackTrace();
\r
1083 * turn on extra applet debugging
\r
1085 String dbg = getParameter("debug");
\r
1088 debug = dbg.toLowerCase().equals("true");
\r
1093 System.err.println("JalviewLite Version " + getVersion());
\r
1094 System.err.println("Build Date : " + getBuildDate());
\r
1097 String externalsviewer = getParameter("externalstructureviewer");
\r
1098 if (externalsviewer != null)
\r
1100 useXtrnalSviewer = externalsviewer.trim().toLowerCase()
\r
1104 * if true disable the check for jmol
\r
1106 String chkforJmol = getParameter("nojmol");
\r
1107 if (chkforJmol != null)
\r
1109 checkForJmol = !chkforJmol.equals("true");
\r
1112 * get the separator parameter if present
\r
1114 String sep = getParameter("separator");
\r
1117 if (sep.length() > 0)
\r
1122 System.err.println("Separator set to '" + separator + "'");
\r
1128 "Invalid separator parameter - must be non-zero length");
\r
1134 String param = getParameter("RGB");
\r
1136 if (param != null)
\r
1140 r = Integer.parseInt(param.substring(0, 2), 16);
\r
1141 g = Integer.parseInt(param.substring(2, 4), 16);
\r
1142 b = Integer.parseInt(param.substring(4, 6), 16);
\r
1143 } catch (Exception ex)
\r
1150 param = getParameter("label");
\r
1151 if (param != null)
\r
1153 launcher.setLabel(param);
\r
1156 setBackground(new Color(r, g, b));
\r
1158 file = getParameter("file");
\r
1162 // Maybe the sequences are added as parameters
\r
1163 StringBuffer data = new StringBuffer("PASTE");
\r
1165 while ((file = getParameter("sequence" + i)) != null)
\r
1167 data.append(file.toString() + "\n");
\r
1170 if (data.length() > 5)
\r
1172 file = data.toString();
\r
1176 final JalviewLite jvapplet = this;
\r
1177 if (getParameter("embedded") != null
\r
1178 && getParameter("embedded").equalsIgnoreCase("true"))
\r
1180 // Launch as embedded applet in page
\r
1182 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1185 else if (file != null)
\r
1187 if (getParameter("showbutton") == null
\r
1188 || !getParameter("showbutton").equalsIgnoreCase("false"))
\r
1190 // Add the JalviewLite 'Button' to the page
\r
1192 launcher.addActionListener(new java.awt.event.ActionListener()
\r
1194 public void actionPerformed(ActionEvent e)
\r
1196 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1203 // Open jalviewLite immediately.
\r
1204 LoadingThread loader = new LoadingThread(file, jvapplet);
\r
1210 // jalview initialisation with no alignment. loadAlignment() method can
\r
1211 // still be called to open new alignments.
\r
1213 fileFound = false;
\r
1214 // callInitCallback();
\r
1218 private void callInitCallback()
\r
1220 String initjscallback = getParameter("oninit");
\r
1221 if (initjscallback == null)
\r
1225 initjscallback = initjscallback.trim();
\r
1226 if (initjscallback.length() > 0)
\r
1228 JSObject scriptObject = null;
\r
1231 scriptObject = JSObject.getWindow(this);
\r
1232 } catch (Exception ex)
\r
1236 if (scriptObject != null)
\r
1240 // do onInit with the JS executor thread
\r
1241 new JSFunctionExec(this).executeJavascriptFunction(true,
\r
1242 initjscallback, null, "Calling oninit callback '"
\r
1243 + initjscallback + "'.");
\r
1244 } catch (Exception e)
\r
1246 System.err.println("Exception when executing _oninit callback '"
\r
1247 + initjscallback + "'.");
\r
1248 e.printStackTrace();
\r
1253 System.err.println("Not executing _oninit callback '"
\r
1254 + initjscallback + "' - no scripting allowed.");
\r
1260 * Initialises and displays a new java.awt.Frame
\r
1263 * java.awt.Frame to be displayed
\r
1265 * title of new frame
\r
1267 * width if new frame
\r
1269 * height of new frame
\r
1271 public static void addFrame(final Frame frame, String title, int width,
\r
1274 frame.setLocation(lastFrameX, lastFrameY);
\r
1277 frame.setSize(width, height);
\r
1278 frame.setTitle(title);
\r
1279 frame.addWindowListener(new WindowAdapter()
\r
1281 public void windowClosing(WindowEvent e)
\r
1283 if (frame instanceof AlignFrame)
\r
1285 AlignViewport vp = ((AlignFrame) frame).viewport;
\r
1286 ((AlignFrame) frame).closeMenuItem_actionPerformed();
\r
1287 if (vp.applet.currentAlignFrame == frame)
\r
1289 vp.applet.currentAlignFrame = null;
\r
1297 if (frame instanceof EmbmenuFrame)
\r
1299 ((EmbmenuFrame) frame).destroyMenus();
\r
1301 frame.setMenuBar(null);
\r
1305 public void windowActivated(WindowEvent e)
\r
1307 if (frame instanceof AlignFrame)
\r
1309 ((AlignFrame) frame).viewport.applet.currentAlignFrame = (AlignFrame) frame;
\r
1312 System.err.println("Activated window " + frame);
\r
1316 super.windowActivated(e);
\r
1319 * Probably not necessary to do this - see TODO above. (non-Javadoc)
\r
1322 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
\r
1325 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
\r
1326 * frame) { currentAlignFrame = null; if (debug) {
\r
1327 * System.err.println("Deactivated window "+frame); } }
\r
1328 * super.windowDeactivated(e); }
\r
1331 frame.setVisible(true);
\r
1335 * This paints the background surrounding the "Launch Jalview button" <br>
\r
1337 * If file given in parameter not found, displays error message
\r
1340 * graphics context
\r
1342 public void paint(Graphics g)
\r
1346 g.setColor(new Color(200, 200, 200));
\r
1347 g.setColor(Color.cyan);
\r
1348 g.fillRect(0, 0, getSize().width, getSize().height);
\r
1349 g.setColor(Color.red);
\r
1350 g.drawString("Jalview can't open file", 5, 15);
\r
1351 g.drawString("\"" + file + "\"", 5, 30);
\r
1353 else if (embedded)
\r
1355 g.setColor(Color.black);
\r
1356 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
1357 g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
\r
1358 g.drawString("Loading Data...", 50, getSize().height / 2);
\r
1363 * get all components associated with the applet of the given type
\r
1368 public Vector getAppletWindow(Class class1)
\r
1370 Vector wnds = new Vector();
\r
1371 Component[] cmp = getComponents();
\r
1374 for (int i = 0; i < cmp.length; i++)
\r
1376 if (class1.isAssignableFrom(cmp[i].getClass()))
\r
1378 wnds.addElement(cmp);
\r
1385 class LoadJmolThread extends Thread
\r
1387 private boolean running = false;
\r
1391 if (running || checkedForJmol)
\r
1400 if (!System.getProperty("java.version").startsWith("1.1"))
\r
1402 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
\r
1403 jmolAvailable = true;
\r
1405 if (!jmolAvailable)
\r
1408 .println("Jmol not available - Using MCview for structures");
\r
1410 } catch (java.lang.ClassNotFoundException ex)
\r
1416 jmolAvailable = false;
\r
1420 .println("Skipping Jmol check. Will use MCView (probably)");
\r
1423 checkedForJmol = true;
\r
1427 public boolean notFinished()
\r
1429 return running || !checkedForJmol;
\r
1433 class LoadingThread extends Thread
\r
1436 * State variable: File source
\r
1441 * State variable: protocol for access to file source
\r
1446 * State variable: format of file source
\r
1452 JalviewLite applet;
\r
1454 private void dbgMsg(String msg)
\r
1458 System.err.println(msg);
\r
1463 * update the protocol state variable for accessing the datasource located
\r
1467 * @return possibly updated datasource string
\r
1469 public String setProtocolState(String file)
\r
1471 if (file.startsWith("PASTE"))
\r
1473 file = file.substring(5);
\r
1474 protocol = AppletFormatAdapter.PASTE;
\r
1476 else if (inArchive(file))
\r
1478 protocol = AppletFormatAdapter.CLASSLOADER;
\r
1482 file = addProtocol(file);
\r
1483 protocol = AppletFormatAdapter.URL;
\r
1485 dbgMsg("Protocol identified as '" + protocol + "'");
\r
1489 public LoadingThread(String _file, JalviewLite _applet)
\r
1491 this._file = _file;
\r
1497 LoadJmolThread jmolchecker = new LoadJmolThread();
\r
1498 jmolchecker.start();
\r
1499 while (jmolchecker.notFinished())
\r
1501 // wait around until the Jmol check is complete.
\r
1505 } catch (Exception e)
\r
1511 // applet.callInitCallback();
\r
1514 private void startLoading()
\r
1516 AlignFrame newAlignFrame;
\r
1517 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
\r
1518 file = setProtocolState(_file);
\r
1520 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
1521 dbgMsg("File identified as '" + format + "'");
\r
1522 dbgMsg("Loading started.");
\r
1523 Alignment al = null;
\r
1526 al = new AppletFormatAdapter().readFile(file, protocol, format);
\r
1527 } catch (java.io.IOException ex)
\r
1529 dbgMsg("File load exception.");
\r
1530 ex.printStackTrace();
\r
1535 FileParse fp = new FileParse(file, protocol);
\r
1537 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
\r
1538 + protocol + ")");
\r
1539 while ((ln = fp.nextLine()) != null)
\r
1543 dbgMsg(">>>Dump finished.");
\r
1544 } catch (Exception e)
\r
1547 .println("Exception when trying to dump the content of the file parameter.");
\r
1548 e.printStackTrace();
\r
1552 if ((al != null) && (al.getHeight() > 0))
\r
1554 dbgMsg("Successfully loaded file.");
\r
1555 newAlignFrame = new AlignFrame(al, applet, file, embedded);
\r
1556 if (initialAlignFrame == null)
\r
1558 initialAlignFrame = newAlignFrame;
\r
1560 // update the focus.
\r
1561 currentAlignFrame = newAlignFrame;
\r
1563 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
\r
1565 newAlignFrame.setTitle("Sequences from "
\r
1566 + applet.getDocumentBase());
\r
1569 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
1571 String treeFile = applet.getParameter("tree");
\r
1572 if (treeFile == null)
\r
1574 treeFile = applet.getParameter("treeFile");
\r
1577 if (treeFile != null)
\r
1581 treeFile = setProtocolState(treeFile);
\r
1583 * if (inArchive(treeFile)) { protocol =
\r
1584 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
\r
1585 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
\r
1587 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
\r
1592 if (fin.getTree() != null)
\r
1594 newAlignFrame.loadTree(fin, treeFile);
\r
1595 dbgMsg("Successfuly imported tree.");
\r
1599 dbgMsg("Tree parameter did not resolve to a valid tree.");
\r
1601 } catch (Exception ex)
\r
1603 ex.printStackTrace();
\r
1607 String param = applet.getParameter("features");
\r
1608 if (param != null)
\r
1610 param = setProtocolState(param);
\r
1612 newAlignFrame.parseFeaturesFile(param, protocol);
\r
1615 param = applet.getParameter("showFeatureSettings");
\r
1616 if (param != null && param.equalsIgnoreCase("true"))
\r
1618 newAlignFrame.viewport.showSequenceFeatures(true);
\r
1619 new FeatureSettings(newAlignFrame.alignPanel);
\r
1622 param = applet.getParameter("annotations");
\r
1623 if (param != null)
\r
1625 param = setProtocolState(param);
\r
1627 if (new AnnotationFile().readAnnotationFile(
\r
1628 newAlignFrame.viewport.getAlignment(), param, protocol))
\r
1630 newAlignFrame.alignPanel.fontChanged();
\r
1631 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1636 .println("Annotations were not added from annotation file '"
\r
1642 param = applet.getParameter("jnetfile");
\r
1643 if (param != null)
\r
1647 param = setProtocolState(param);
\r
1648 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
\r
1650 JnetAnnotationMaker.add_annotation(predictions,
\r
1651 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
\r
1659 newAlignFrame.alignPanel.fontChanged();
\r
1660 newAlignFrame.alignPanel.setScrollValues(0, 0);
\r
1661 } catch (Exception ex)
\r
1663 ex.printStackTrace();
\r
1667 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
\r
1668 * - related to JAL-434
\r
1670 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
\r
1673 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
\r
1674 * PDB|1GAQ|1GAQ|C">
\r
1676 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
\r
1678 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
\r
1681 int pdbFileCount = 0;
\r
1682 // Accumulate pdbs here if they are heading for the same view (if
\r
1683 // alignPdbStructures is true)
\r
1684 Vector pdbs = new Vector();
\r
1685 // create a lazy matcher if we're asked to
\r
1686 jalview.analysis.SequenceIdMatcher matcher = (applet
\r
1687 .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
\r
1688 newAlignFrame.getAlignViewport().getAlignment()
\r
1689 .getSequencesArray()) : null;
\r
1693 if (pdbFileCount > 0)
\r
1695 param = applet.getParameter("PDBFILE" + pdbFileCount);
\r
1699 param = applet.getParameter("PDBFILE");
\r
1702 if (param != null)
\r
1704 PDBEntry pdb = new PDBEntry();
\r
1707 SequenceI[] seqs = null;
\r
1708 String[] chains = null;
\r
1710 StringTokenizer st = new StringTokenizer(param, " ");
\r
1712 if (st.countTokens() < 2)
\r
1714 String sequence = applet.getParameter("PDBSEQ");
\r
1715 if (sequence != null)
\r
1716 seqs = new SequenceI[]
\r
1717 { matcher == null ? (Sequence) newAlignFrame
\r
1718 .getAlignViewport().getAlignment()
\r
1719 .findName(sequence) : matcher.findIdMatch(sequence) };
\r
1724 param = st.nextToken();
\r
1725 Vector tmp = new Vector();
\r
1726 Vector tmp2 = new Vector();
\r
1728 while (st.hasMoreTokens())
\r
1730 seqstring = st.nextToken();
\r
1731 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
\r
1732 if (st2.countTokens() > 1)
\r
1734 // This is the chain
\r
1735 tmp2.addElement(st2.nextToken());
\r
1736 seqstring = st2.nextToken();
\r
1738 tmp.addElement(matcher == null ? (Sequence) newAlignFrame
\r
1739 .getAlignViewport().getAlignment()
\r
1740 .findName(seqstring) : matcher
\r
1741 .findIdMatch(seqstring));
\r
1744 seqs = new SequenceI[tmp.size()];
\r
1745 tmp.copyInto(seqs);
\r
1746 if (tmp2.size() == tmp.size())
\r
1748 chains = new String[tmp2.size()];
\r
1749 tmp2.copyInto(chains);
\r
1752 param = setProtocolState(param);
\r
1754 if (// !jmolAvailable
\r
1756 protocol == AppletFormatAdapter.CLASSLOADER
\r
1757 && !useXtrnalSviewer)
\r
1759 // Re: JAL-357 : the bug isn't a problem if we are using an
\r
1760 // external viewer!
\r
1761 // TODO: verify this Re:
\r
1762 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
\r
1763 // This exception preserves the current behaviour where, even if
\r
1764 // the local pdb file was identified in the class loader
\r
1765 protocol = AppletFormatAdapter.URL; // this is probably NOT
\r
1767 param = addProtocol(param); //
\r
1770 pdb.setFile(param);
\r
1774 for (int i = 0; i < seqs.length; i++)
\r
1776 if (seqs[i] != null)
\r
1778 ((Sequence) seqs[i]).addPDBId(pdb);
\r
1782 if (JalviewLite.debug)
\r
1784 // this may not really be a problem but we give a warning
\r
1787 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
\r
1793 if (!alignPdbStructures)
\r
1795 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
\r
1800 pdbs.addElement(new Object[]
\r
1801 { pdb, seqs, chains, new String(protocol) });
\r
1807 } while (param != null || pdbFileCount < 10);
\r
1808 if (pdbs.size() > 0)
\r
1810 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
\r
1811 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
\r
1812 String[][] chains = new String[pdbs.size()][];
\r
1813 String[] protocols = new String[pdbs.size()];
\r
1814 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
\r
1816 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
\r
1817 pdb[pdbsi] = (PDBEntry) o[0];
\r
1818 seqs[pdbsi] = (SequenceI[]) o[1];
\r
1819 chains[pdbsi] = (String[]) o[2];
\r
1820 protocols[pdbsi] = (String) o[3];
\r
1822 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
\r
1826 // ///////////////////////////
\r
1827 // modify display of features
\r
1829 // hide specific groups
\r
1830 param = applet.getParameter("hidefeaturegroups");
\r
1831 if (param != null)
\r
1833 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
\r
1835 // show specific groups
\r
1836 param = applet.getParameter("showfeaturegroups");
\r
1837 if (param != null)
\r
1839 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
\r
1844 fileFound = false;
\r
1845 applet.remove(launcher);
\r
1848 callInitCallback();
\r
1852 * Discovers whether the given file is in the Applet Archive
\r
1858 boolean inArchive(String file)
\r
1860 // This might throw a security exception in certain browsers
\r
1861 // Netscape Communicator for instance.
\r
1864 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
\r
1867 System.err.println("Resource '" + file + "' was "
\r
1868 + (rtn ? "" : "not") + " located by classloader.");
\r
1871 } catch (Exception ex)
\r
1873 System.out.println("Exception checking resources: " + file + " "
\r
1879 String addProtocol(String file)
\r
1881 if (file.indexOf("://") == -1)
\r
1883 String fl = applet.getDocumentBase() + file;
\r
1886 if (new java.net.URL(fl).openStream() != null)
\r
1890 System.err.println("Prepended document base for resource: '"
\r
1895 } catch (Exception x)
\r
1899 fl = applet.getCodeBase() + file;
\r
1902 if (new java.net.URL(fl).openStream() != null)
\r
1908 System.err.println("Prepended codebase for resource: '"
\r
1914 } catch (Exception x)
\r
1926 * @return the default alignFrame acted on by the public applet methods. May
\r
1927 * return null with an error message on System.err indicating the
\r
1930 public AlignFrame getDefaultTargetFrame()
\r
1932 if (currentAlignFrame != null)
\r
1934 return currentAlignFrame;
\r
1936 if (initialAlignFrame != null)
\r
1938 return initialAlignFrame;
\r
1941 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
\r
1946 * separator used for separatorList
\r
1948 protected String separator = "" + ((char) 0x00AC); // the default used to be
\r
1949 // '|' but many sequence
\r
1950 // IDS include pipes.
\r
1953 * set to enable the URL based javascript execution mechanism
\r
1955 public boolean jsfallbackEnabled=false;
\r
1958 * parse the string into a list
\r
1961 * @return elements separated by separator
\r
1963 public String[] separatorListToArray(String list)
\r
1965 return separatorListToArray(list, separator);
\r
1969 * parse the string into a list
\r
1972 * @param separator
\r
1973 * @return elements separated by separator
\r
1975 public String[] separatorListToArray(String list, String separator)
\r
1977 // note separator local variable intentionally masks object field
\r
1978 int seplen = separator.length();
\r
1979 if (list == null || list.equals("") || list.equals(separator))
\r
1981 java.util.Vector jv = new Vector();
\r
1983 while ((pos = list.indexOf(separator, cp)) > cp)
\r
1985 jv.addElement(list.substring(cp, pos));
\r
1986 cp = pos + seplen;
\r
1988 if (cp < list.length())
\r
1990 String c = list.substring(cp);
\r
1991 if (!c.equals(separator))
\r
1996 if (jv.size() > 0)
\r
1998 String[] v = new String[jv.size()];
\r
1999 for (int i = 0; i < v.length; i++)
\r
2001 v[i] = (String) jv.elementAt(i);
\r
2003 jv.removeAllElements();
\r
2006 System.err.println("Array from '" + separator
\r
2007 + "' separated List:\n" + v.length);
\r
2008 for (int i = 0; i < v.length; i++)
\r
2010 System.err.println("item " + i + " '" + v[i] + "'");
\r
2017 System.err.println("Empty Array from '" + separator
\r
2018 + "' separated List");
\r
2024 * concatenate the list with separator
\r
2027 * @return concatenated string
\r
2029 public String arrayToSeparatorList(String[] list)
\r
2031 return arrayToSeparatorList(list, separator);
\r
2035 * concatenate the list with separator
\r
2038 * @param separator
\r
2039 * @return concatenated string
\r
2041 public String arrayToSeparatorList(String[] list, String separator)
\r
2043 StringBuffer v = new StringBuffer();
\r
2044 if (list != null && list.length > 0)
\r
2046 for (int i = 0, iSize = list.length; i < iSize; i++)
\r
2048 if (list[i] != null)
\r
2052 v.append(separator);
\r
2054 v.append(list[i]);
\r
2059 System.err.println("Returning '" + separator
\r
2060 + "' separated List:\n");
\r
2061 System.err.println(v);
\r
2063 return v.toString();
\r
2067 System.err.println("Returning empty '" + separator
\r
2068 + "' separated List\n");
\r
2070 return "" + separator;
\r
2075 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
\r
2077 public String getFeatureGroups()
\r
2079 String lst = arrayToSeparatorList(getDefaultTargetFrame()
\r
2080 .getFeatureGroups());
\r
2086 * alignframe to get feature groups on
\r
2088 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
\r
2090 public String getFeatureGroupsOn(AlignFrame alf)
\r
2092 String lst = arrayToSeparatorList(alf.getFeatureGroups());
\r
2099 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
\r
2101 public String getFeatureGroupsOfState(boolean visible)
\r
2103 return arrayToSeparatorList(getDefaultTargetFrame()
\r
2104 .getFeatureGroupsOfState(visible));
\r
2109 * align frame to get groups of state visible
\r
2112 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
\r
2114 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
\r
2116 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
\r
2121 * tab separated list of group names
\r
2124 * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
\r
2127 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
\r
2130 boolean st = state;// !(state==null || state.equals("") ||
\r
2131 // state.toLowerCase().equals("false"));
\r
2132 alf.setFeatureGroupState(separatorListToArray(groups), st);
\r
2135 public void setFeatureGroupState(String groups, boolean state)
\r
2137 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
\r
2141 * List separator string
\r
2143 * @return the separator
\r
2145 public String getSeparator()
\r
2151 * List separator string
\r
2153 * @param separator
\r
2154 * the separator to set. empty string will reset separator to default
\r
2156 public void setSeparator(String separator)
\r
2158 if (separator == null || separator.length() < 1)
\r
2160 // reset to default
\r
2161 separator = "" + ((char) 0x00AC);
\r
2163 this.separator = separator;
\r
2166 System.err.println("Default Separator now: '" + separator + "'");
\r
2171 * get boolean value of applet parameter 'name' and return default if
\r
2172 * parameter is not set
\r
2175 * name of paremeter
\r
2177 * the value to return otherwise
\r
2178 * @return true or false
\r
2180 public boolean getDefaultParameter(String name, boolean def)
\r
2183 if ((stn = getParameter(name)) == null)
\r
2187 if (stn.toLowerCase().equals("true"))
\r
2195 * bind a pdb file to a sequence in the given alignFrame.
\r
2198 * - null or specific alignFrame. This specifies the dataset that
\r
2199 * will be searched for a seuqence called sequenceId
\r
2200 * @param sequenceId
\r
2201 * - sequenceId within the dataset.
\r
2202 * @param pdbEntryString
\r
2203 * - the short name for the PDB file
\r
2205 * - pdb file - either a URL or a valid PDB file.
\r
2206 * @return true if binding was as success TODO: consider making an exception
\r
2207 * structure for indicating when PDB parsing or sequenceId location
\r
2210 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
\r
2211 String pdbEntryString, String pdbFile)
\r
2213 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
\r
2216 protected void setAlignPdbStructures(boolean alignPdbStructures)
\r
2218 this.alignPdbStructures = alignPdbStructures;
\r
2221 public boolean isAlignPdbStructures()
\r
2223 return alignPdbStructures;
\r
2226 public void start()
\r
2228 // callInitCallback();
\r
2230 private Hashtable<String,long[]> jshashes=new Hashtable<String,long[]>();
\r
2231 private Hashtable<String,Hashtable<String,String[]>> jsmessages=new Hashtable<String,Hashtable<String,String[]>>();
\r
2232 public void setJsMessageSet(String messageclass, String viewId,
\r
2233 String[] colcommands)
\r
2235 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2238 msgset=new Hashtable<String,String[]>();
\r
2239 jsmessages.put(messageclass, msgset);
\r
2241 msgset.put(viewId, colcommands);
\r
2242 long[] l = new long[colcommands.length];
\r
2243 for (int i=0;i<colcommands.length;i++) { l[i] = colcommands[i].hashCode();}
\r
2244 jshashes.put(messageclass+"|"+viewId,l);
\r
2246 public String getJsMessage(String messageclass, String viewId)
\r
2248 Hashtable<String,String[]> msgset = jsmessages.get(messageclass);
\r
2251 String[] msgs = msgset.get(viewId);
\r
2254 for (int i=0;i<msgs.length;i++) {
\r
2255 if (msgs[i]!=null) {
\r
2256 String m = msgs[i];
\r
2266 public boolean isJsMessageSetChanged(String string, String string2,
\r
2267 String[] colcommands)
\r
2269 long[] l=jshashes.get(string+"|"+string2);
\r
2270 if (l==null && colcommands!=null)
\r
2274 for (int i=0;i<colcommands.length;i++) { if (l[i] != colcommands[i].hashCode()) { return true; }}
\r
2278 private Vector jsExecQueue=new Vector();
\r
2279 public Vector getJsExecQueue()
\r
2281 return jsExecQueue;
\r
2284 public void setExecutor(JSFunctionExec jsFunctionExec2)
\r
2286 jsFunctionExec=jsFunctionExec2;
\r
2290 * bind structures in a viewer to any matching sequences in an alignFrame (use
\r
2291 * sequenceIds to limit scope of search to specific sequences)
\r
2295 * @param sequenceIds
\r
2296 * @return TODO: consider making an exception structure for indicating when
\r
2297 * binding fails public SequenceStructureBinding
\r
2298 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
\r
2301 * if (sequenceIds != null && sequenceIds.length() > 0) { return
\r
2302 * alFrame.addStructureViewInstance(viewer,
\r
2303 * separatorListToArray(sequenceIds)); } else { return
\r
2304 * alFrame.addStructureViewInstance(viewer, null); } // return null; }
\r