*/
package jalview.bin;
+import jalview.analysis.AlignmentUtils;
import jalview.api.StructureSelectionManagerProvider;
import jalview.appletgui.AlignFrame;
import jalview.appletgui.AlignViewport;
import java.util.StringTokenizer;
import java.util.Vector;
-import netscape.javascript.JSException;
import netscape.javascript.JSObject;
/**
}
// /////////////////////////////////////////
- // The following public methods maybe called
+ // The following public methods may be called
// externally, eg via javascript in HTML page
/*
* (non-Javadoc)
}
}
- /*
- * (non-Javadoc)
- *
+ /**
+ * Callable from javascript to register a javascript function to pass events
+ * to a structure viewer.
+ *
+ * @param listener
+ * the name of a javascript function
+ * @param modelSet
+ * a token separated list of PDB file names listened for
* @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
- * java.lang.String)
+ * java.lang.String)
*/
public void setStructureListener(String listener, String modelSet)
{
{
builddate = "unknown";
version = "test";
- installation = "Webstart";
+ installation = "applet";
java.net.URL url = JalviewLite.class
.getResource("/.build_properties");
if (url != null)
/**
* init method for Jalview Applet
*/
+ @Override
public void init()
{
- // remove any handlers that might be hanging around from an earlier instance
+ debug = TRUE.equalsIgnoreCase(getParameter("debug"));
try
{
if (debug)
ex.printStackTrace();
}
}
- /**
- * turn on extra applet debugging
- */
- debug = TRUE.equalsIgnoreCase(getParameter("debug"));
+
if (debug)
{
-
System.err.println("JalviewLite Version " + getVersion());
System.err.println("Build Date : " + getBuildDate());
System.err.println("Installation : " + getInstallation());
-
}
String externalsviewer = getParameter("externalstructureviewer");
if (externalsviewer != null)
{
- useXtrnalSviewer = externalsviewer.trim().toLowerCase()
- .equals(TRUE);
+ useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
}
/**
* if true disable the check for jmol
}
else
{
- throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
+ throw new Error(
+ MessageManager
+ .getString("error.invalid_separator_parameter"));
}
}
int r = 255;
file = data.toString();
}
}
- if (TRUE.equalsIgnoreCase(getParameter("enableSplitFrame")))
+ if (getDefaultParameter("enableSplitFrame", true))
{
file2 = getParameter("file2");
}
{
notFailed = true;
}
- } catch (JSException jsex)
+ } catch (Exception jsex)
{
System.err.println("Attempt " + tries
+ " to access LiveConnect javascript failed.");
*/
public void addToDisplay(AlignFrame af, AlignFrame af2)
{
- if (af2 == null)
- {
- af.addToDisplay(embedded);
- }
- else
+ if (af2 != null)
{
- SplitFrame sf = new SplitFrame(af, af2);
- sf.addToDisplay(embedded, JalviewLite.this);
+ AlignmentI al1 = af.viewport.getAlignment();
+ AlignmentI al2 = af2.viewport.getAlignment();
+ AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
+ AlignmentI prot = al1.isNucleotide() ? al2 : al1;
+ if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
+ {
+ al2.alignAs(al1);
+ SplitFrame sf = new SplitFrame(af, af2);
+ sf.addToDisplay(embedded, JalviewLite.this);
+ return;
+ }
+ else
+ {
+ String msg = "Could not map any sequence in " + af2.getTitle()
+ + " as "
+ + (al1.isNucleotide() ? "protein product" : "cDNA")
+ + " for " + af.getTitle();
+ System.err.println(msg);
+ }
}
+
+ af.addToDisplay(embedded);
}
/**
AlignmentI al = null;
try
{
- al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
+ al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
+ format);
if ((al != null) && (al.getHeight() > 0))
{
dbgMsg("Successfully loaded file.");
if (protocol == AppletFormatAdapter.PASTE)
{
newAlignFrame.setTitle(MessageManager.formatMessage(
- "label.sequences_from", new Object[]
- { applet.getDocumentBase().toString() }));
+ "label.sequences_from", new Object[] { applet
+ .getDocumentBase().toString() }));
}
newAlignFrame.statusBar.setText(MessageManager.formatMessage(
- "label.successfully_loaded_file", new Object[]
- { resolvedFile }));
+ "label.successfully_loaded_file",
+ new Object[] { resolvedFile }));
return newAlignFrame;
}
String sequence = applet.getParameter("PDBSEQ");
if (sequence != null)
{
- seqs = new SequenceI[]
- { matcher == null ? (Sequence) alignFrame.getAlignViewport()
- .getAlignment().findName(sequence) : matcher
- .findIdMatch(sequence) };
+ seqs = new SequenceI[] { matcher == null ? (Sequence) alignFrame
+ .getAlignViewport().getAlignment().findName(sequence)
+ : matcher.findIdMatch(sequence) };
}
}
}
else
{
- pdbs.addElement(new Object[]
- { pdb, seqs, chains, new String(protocol) });
+ pdbs.addElement(new Object[] { pdb, seqs, chains,
+ new String(protocol) });
}
}
}
/**
* Discovers whether the given file is in the Applet Archive
*
- * @param file
+ * @param f
* String
* @return boolean
*/
- boolean inArchive(String file)
+ boolean inArchive(String f)
{
// This might throw a security exception in certain browsers
// Netscape Communicator for instance.
try
{
- boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
+ boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
if (debug)
{
- System.err.println("Resource '" + file + "' was "
- + (rtn ? "" : "not") + " located by classloader.");
+ System.err.println("Resource '" + f + "' was "
+ + (rtn ? "" : "not ") + "located by classloader.");
}
return rtn;
} catch (Exception ex)
{
- System.out.println("Exception checking resources: " + file + " "
+ System.out.println("Exception checking resources: " + f + " "
+ ex);
return false;
}
* If the file is not already in URL format, tries to locate it by resolving
* as a URL.
*
- * @param file
+ * @param f
* @return
*/
- String addProtocol(final String file)
+ String addProtocol(final String f)
{
- if (file.indexOf("://") == -1)
+ if (f.indexOf("://") != -1)
{
- /*
- * Try relative to document base
- */
- String url = applet.resolveUrlForLocalOrAbsolute(file,
- getDocumentBase());
- if (urlExists(url))
- {
- if (debug)
- {
- System.err.println("Prepended document base for resource: '"
- + file + "'");
- }
- return url;
- }
+ // already has URL format
+ return f;
+ }
- /*
- * Try relative to codebase
- */
- url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
- if (urlExists(url))
+ /*
+ * Try relative to document base
+ */
+ URL documentBase = getDocumentBase();
+ String url = applet.resolveUrlForLocalOrAbsolute(f, documentBase);
+ if (urlExists(url))
+ {
+ if (debug)
{
- if (debug)
- {
- System.err.println("Prepended codebase for resource: '" + file
- + "'");
- }
- return url;
+ System.err.println("Prepended document base '" + documentBase
+ + "' to make: '" + url + "'");
}
+ return url;
}
/*
- * Not resolved, leave unchanged
+ * Try relative to codebase
*/
- return file;
+ URL codeBase = getCodeBase();
+ url = applet.resolveUrlForLocalOrAbsolute(f, codeBase);
+ if (urlExists(url))
+ {
+ if (debug)
+ {
+ System.err.println("Prepended codebase '" + codeBase
+ + "' to make: '" + url + "'");
+ }
+ return url;
+ }
+
+ return f;
}
/**
* @param separator
* @return elements separated by separator
*/
- public String[] separatorListToArray(String list, String separator)
+ public static String[] separatorListToArray(String list, String separator)
{
- // note separator local variable intentionally masks object field
+ // TODO use StringUtils version (slightly different...)
int seplen = separator.length();
if (list == null || list.equals("") || list.equals(separator))
{
* @param separator
* @return concatenated string
*/
- public String arrayToSeparatorList(String[] list, String separator)
+ public static String arrayToSeparatorList(String[] list, String separator)
{
+ // TODO use StringUtils version
StringBuffer v = new StringBuffer();
if (list != null && list.length > 0)
{
{
return def;
}
- if (stn.toLowerCase().equals(TRUE))
+ if (TRUE.equalsIgnoreCase(stn))
{
return true;
}
String codebase = localref.toString();
if (url.indexOf("/") == 0)
{
- url = codebase.substring(0, codebase.length()
- - localref.getFile().length())
+ String localfile = localref.getFile();
+ url = codebase.substring(0, codebase.length() - localfile.length())
+ url;
}
else
{
url = localref + url;
}
+ if (debug)
+ {
+ System.err.println("URL: " + localref.toString());
+ System.err.println("URL.getFile: " + localref.getFile());
+ System.err.println("URL.getPath: " + localref.getPath());
+ System.err.println("URL.getQuery: " + localref.getQuery());
+ System.err.println("returning " + url);
+ }
return url;
}