+
+ /**
+ * @return the default alignFrame acted on by the public applet methods. May
+ * return null with an error message on System.err indicating the
+ * fact.
+ */
+ protected AlignFrame getDefaultTargetFrame()
+ {
+ if (currentAlignFrame != null)
+ {
+ return currentAlignFrame;
+ }
+ if (initialAlignFrame != null)
+ {
+ return initialAlignFrame;
+ }
+ System.err
+ .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
+ return null;
+ }
+
+ /**
+ * separator used for separatorList
+ */
+ protected String separator = "|"; // this is a safe(ish) separator - tabs
+
+ // don't work for firefox
+
+ /**
+ * parse the string into a list
+ *
+ * @param list
+ * @return elements separated by separator
+ */
+ public String[] separatorListToArray(String list)
+ {
+ int seplen = separator.length();
+ if (list == null || list.equals(""))
+ return null;
+ java.util.Vector jv = new Vector();
+ int cp = 0, pos;
+ while ((pos = list.indexOf(separator, cp)) > cp)
+ {
+ jv.addElement(list.substring(cp, pos));
+ cp = pos + seplen;
+ }
+ if (cp < list.length())
+ {
+ jv.addElement(list.substring(cp));
+ }
+ if (jv.size() > 0)
+ {
+ String[] v = new String[jv.size()];
+ for (int i = 0; i < v.length; i++)
+ {
+ v[i] = (String) jv.elementAt(i);
+ }
+ jv.removeAllElements();
+ if (debug)
+ {
+ System.err.println("Array from '" + separator
+ + "' separated List:\n" + v.length);
+ for (int i = 0; i < v.length; i++)
+ {
+ System.err.println("item " + i + " '" + v[i] + "'");
+ }
+ }
+ return v;
+ }
+ if (debug)
+ {
+ System.err.println("Empty Array from '" + separator
+ + "' separated List");
+ }
+ return null;
+ }
+
+ /**
+ * concatenate the list with separator
+ *
+ * @param list
+ * @return concatenated string
+ */
+ public String arrayToSeparatorList(String[] list)
+ {
+ StringBuffer v = new StringBuffer();
+ if (list != null && list.length>0)
+ {
+ for (int i = 0, iSize = list.length - 1; i < iSize; i++)
+ {
+ if (list[i] != null)
+ {
+ v.append(list[i]);
+ }
+ v.append(separator);
+ }
+ if (list[list.length - 1] != null)
+ {
+ v.append(list[list.length - 1]);
+ }
+ if (debug)
+ {
+ System.err.println("Returning '" + separator
+ + "' separated List:\n");
+ System.err.println(v);
+ }
+ return v.toString();
+ }
+ if (debug)
+ {
+ System.err.println("Returning empty '" + separator
+ + "' separated List\n");
+ }
+ return "";
+ }
+
+ /**
+ * @return
+ * @see jalview.appletgui.AlignFrame#getFeatureGroups()
+ */
+ public String getFeatureGroups()
+ {
+ String lst = arrayToSeparatorList(getDefaultTargetFrame()
+ .getFeatureGroups());
+ return lst;
+ }
+
+ /**
+ * @param alf
+ * alignframe to get feature groups on
+ * @return
+ * @see jalview.appletgui.AlignFrame#getFeatureGroups()
+ */
+ public String getFeatureGroupsOn(AlignFrame alf)
+ {
+ String lst = arrayToSeparatorList(alf.getFeatureGroups());
+ return lst;
+ }
+
+ /**
+ * @param visible
+ * @return
+ * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
+ */
+ public String getFeatureGroupsOfState(boolean visible)
+ {
+ return arrayToSeparatorList(getDefaultTargetFrame()
+ .getFeatureGroupsOfState(visible));
+ }
+
+ /**
+ * @param alf
+ * align frame to get groups of state visible
+ * @param visible
+ * @return
+ * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
+ */
+ public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
+ {
+ return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
+ }
+
+ /**
+ * @param groups
+ * tab separated list of group names
+ * @param state
+ * true or false
+ * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
+ * boolean)
+ */
+ public void setFeatureGroupStateOn(AlignFrame alf, String groups,
+ boolean state)
+ {
+ boolean st = state;// !(state==null || state.equals("") ||
+ // state.toLowerCase().equals("false"));
+ alf.setFeatureGroupState(separatorListToArray(groups), st);
+ }
+
+ public void setFeatureGroupState(String groups, boolean state)
+ {
+ setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
+ }
+
+ /**
+ * List separator string
+ *
+ * @return the separator
+ */
+ public String getSeparator()
+ {
+ return separator;
+ }
+
+ /**
+ * List separator string
+ *
+ * @param separator
+ * the separator to set
+ */
+ public void setSeparator(String separator)
+ {
+ this.separator = separator;
+ }
+
+ /**
+ * get boolean value of applet parameter 'name' and return default if
+ * parameter is not set
+ *
+ * @param name
+ * name of paremeter
+ * @param def
+ * the value to return otherwise
+ * @return true or false
+ */
+ public boolean getDefaultParameter(String name, boolean def)
+ {
+ String stn;
+ if ((stn = getParameter(name)) == null)
+ {
+ return def;
+ }
+ if (stn.toLowerCase().equals("true"))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * bind a pdb file to a sequence in the given alignFrame.
+ *
+ * @param alFrame
+ * - null or specific alignFrame. This specifies the dataset that
+ * will be searched for a seuqence called sequenceId
+ * @param sequenceId
+ * - sequenceId within the dataset.
+ * @param pdbEntryString
+ * - the short name for the PDB file
+ * @param pdbFile
+ * - pdb file - either a URL or a valid PDB file.
+ * @return true if binding was as success TODO: consider making an exception
+ * structure for indicating when PDB parsing or seqeunceId location
+ * fails.
+ */
+ public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
+ String pdbEntryString, String pdbFile)
+ {
+ return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
+ }
+
+ protected void setAlignPdbStructures(boolean alignPdbStructures)
+ {
+ this.alignPdbStructures = alignPdbStructures;
+ }
+
+ public boolean isAlignPdbStructures()
+ {
+ return alignPdbStructures;
+ }
+
+ /**
+ * get all components associated with the applet of the given type
+ * @param class1
+ * @return
+ */
+ public Vector getAppletWindow(Class class1)
+ {
+ Vector wnds = new Vector();
+ Component[] cmp = getComponents();
+ if (cmp!=null)
+ {
+ for (int i=0;i<cmp.length;i++)
+ {
+ if (class1.isAssignableFrom(cmp[i].getClass()))
+ {
+ wnds.addElement(cmp);
+ }
+ }}
+ return wnds;
+ }
+
+
+ /**
+ * bind structures in a viewer to any matching sequences in an alignFrame (use
+ * sequenceIds to limit scope of search to specific sequences)
+ *
+ * @param alFrame
+ * @param viewer
+ * @param sequenceIds
+ * @return TODO: consider making an exception structure for indicating when
+ * binding fails
+ public SequenceStructureBinding addStructureViewInstance(
+ AlignFrame alFrame, Object viewer, String sequenceIds)
+ {
+
+ if (sequenceIds != null && sequenceIds.length() > 0)
+ {
+ return alFrame.addStructureViewInstance(viewer,
+ separatorListToArray(sequenceIds));
+ }
+ else
+ {
+ return alFrame.addStructureViewInstance(viewer, null);
+ }
+ // return null;
+ }
+ */