X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalviewLite.java;h=4d45f8ca70d418a6da7a742a85b842d6eaaaeff8;hb=a3a998f2eb05edbf4bdb22cf2f5449d742001ee7;hp=c9977fd0d30d24080354498a06054b080d374aa1;hpb=2c53eb970a6611d2d422df744044b579ef31f490;p=jalview.git diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index c9977fd..4d45f8c 100755 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -48,9 +48,9 @@ public class JalviewLite */ public String getSelectedSequences() { - return getSelectedSequences(currentAlignFrame); + return getSelectedSequencesFrom(getDefaultTargetFrame()); } - public String getSelectedSequences(AlignFrame alf) + public String getSelectedSequencesFrom(AlignFrame alf) { StringBuffer result = new StringBuffer(""); @@ -71,17 +71,17 @@ public class JalviewLite public String getAlignment(String format) { - return getAlignment(currentAlignFrame, format, "true"); + return getAlignmentFrom(getDefaultTargetFrame(), format, "true"); } - public String getAlignment(AlignFrame alf, String format) + public String getAlignmentFrom(AlignFrame alf, String format) { - return getAlignment(alf, format, "true"); + return getAlignmentFrom(alf, format, "true"); } public String getAlignment(String format, String suffix) { - return getAlignment(currentAlignFrame, format, suffix); + return getAlignmentFrom(getDefaultTargetFrame(), format, suffix); } - public String getAlignment(AlignFrame alf, String format, String suffix) + public String getAlignmentFrom(AlignFrame alf, String format, String suffix) { try { @@ -100,9 +100,9 @@ public class JalviewLite public void loadAnnotation(String annotation) { - loadAnnotation(currentAlignFrame, annotation); + loadAnnotationFrom(getDefaultTargetFrame(), annotation); } - public void loadAnnotation(AlignFrame alf, String annotation) + public void loadAnnotationFrom(AlignFrame alf, String annotation) { if (new AnnotationFile().readAnnotationFile( alf.getAlignViewport().getAlignment(), annotation, @@ -119,34 +119,34 @@ public class JalviewLite public String getFeatures(String format) { - return getFeatures(currentAlignFrame, format); + return getFeaturesFrom(getDefaultTargetFrame(), format); } - public String getFeatures(AlignFrame alf, String format) + public String getFeaturesFrom(AlignFrame alf, String format) { return alf.outputFeatures(false, format); } public String getAnnotation() { - return getAnnotation(currentAlignFrame); + return getAnnotationFrom(getDefaultTargetFrame()); } - public String getAnnotation(AlignFrame alf) + public String getAnnotationFrom(AlignFrame alf) { return alf.outputAnnotations(false); } public AlignFrame newView() { - return newView(currentAlignFrame); + return newViewFrom(getDefaultTargetFrame()); } public AlignFrame newView(String name) { - return newView(currentAlignFrame, name); + return newViewFrom(getDefaultTargetFrame(), name); } - public AlignFrame newView(AlignFrame alf) + public AlignFrame newViewFrom(AlignFrame alf) { return alf.newView(null); } - public AlignFrame newView(AlignFrame alf, String name) + public AlignFrame newViewFrom(AlignFrame alf, String name) { return alf.newView(name); } @@ -188,11 +188,18 @@ public class JalviewLite String file = "No file"; Button launcher = new Button("Start Jalview"); - //The currentAlignFrame is static, it will change - //if and when the user selects a new window + /** + * The currentAlignFrame is static, it will change + * if and when the user selects a new window. + * Note that it will *never* point back to the embedded AlignFrame + * if the applet is started as embedded on the page and then afterwards a new view is created. + */ public static AlignFrame currentAlignFrame; - //This is the first frame to be displayed, and does not change + /** + * This is the first frame to be displayed, and does not change. + * API calls will default to this instance if currentAlignFrame is null. + */ AlignFrame initialAlignFrame; boolean embedded = false; @@ -210,6 +217,22 @@ public class JalviewLite { debug = dbg.toLowerCase().equals("true"); } + /** + * get the separator parameter if present + */ + String sep = getParameter("separator"); + if (sep!=null) + { + if (sep.length()>0) + { separator = sep; + if (debug) + { + System.err.println("Separator set to '"+separator+"'"); + } + } else { + throw new Error("Invalid separator parameter - must be non-zero length"); + } + } int r = 255; int g = 255; int b = 255; @@ -320,10 +343,14 @@ public class JalviewLite } lastFrameX -= 40; lastFrameY -= 40; + if (frame instanceof EmbmenuFrame) + { + ((EmbmenuFrame) frame).destroyMenus(); + } frame.setMenuBar(null); frame.dispose(); } - + public void windowActivated(WindowEvent e) { if (frame instanceof AlignFrame) @@ -334,8 +361,26 @@ public class JalviewLite System.err.println("Activated window "+frame); } } + // be good. + super.windowActivated(e); } - + /* Probably not necessary to do this - see TODO above. + * (non-Javadoc) + * @see java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent) + * + public void windowDeactivated(WindowEvent e) + { + if (currentAlignFrame == frame) + { + currentAlignFrame = null; + if (debug) + { + System.err.println("Deactivated window "+frame); + } + } + super.windowDeactivated(e); + } + */ }); frame.setVisible(true); } @@ -449,18 +494,18 @@ public class JalviewLite } if ( (al != null) && (al.getHeight() > 0)) { - currentAlignFrame = new AlignFrame(al, + initialAlignFrame = new AlignFrame(al, applet, file, embedded); + // update the focus. + currentAlignFrame = initialAlignFrame; if (protocol == jalview.io.AppletFormatAdapter.PASTE) { currentAlignFrame.setTitle("Sequences from " + getDocumentBase()); } - initialAlignFrame = currentAlignFrame; - currentAlignFrame.statusBar.setText("Successfully loaded file " + file); String treeFile = applet.getParameter("tree"); @@ -727,17 +772,43 @@ public class JalviewLite return file; } } - - public String[] tabbedListToArray(String list) + /** + * @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("\t",cp))>cp) + while ((pos=list.indexOf(separator,cp))>cp) { jv.addElement(list.substring(cp,pos)); - cp = pos+1; + cp = pos+seplen; } if (cp0) { String[] v = new String[jv.size()]; - jv.copyInto(v); + for (int i=0; i