<title>Embedded JalviewJS Example 1</title><meta charset="utf-8" />
<script src="swingjs/swingjs2.js"></script>
<script>
+
+// BH 2019.10.06 adds Tree and Pca functionality
+// BH see issue JAL-3451
+
if (!self.SwingJS)alert('swingjs2.js was not found. It needs to be in swingjs folder in the same directory as ' + document.location.href)
Info = {
code: null,
serverURL: 'https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php',
j2sPath: 'swingjs/j2s',
console:'none',
- allowjavascript: true,
-
- //Jalview-specific:
- // note that desktop-frame-div has been set to display:none
- jalview_SCREEN_WIDTH: 0, // desktop width -- 0 to hide
- jalview_SCREEN_HEIGHT: 0, // desktop height -- 0 to hide
- jalview_SCREEN_X: 10,
- jalview_SCREEN_Y: 10,
- jalview_EMBEDDED: true
-
+ allowjavascript: true
}
jvGet = function(what) {
switch(what) {
case "tree":
- break;
+ testApplet.app.openTreePanel$jalview_gui_AlignFrame$S$S(null, "NJ","BLOSUM62")
+ break;
case "pca":
- break;
+ testApplet.app.openPcaPanel$jalview_gui_AlignFrame$S(null, "BLOSUM62")
+ break;
+ case "3D":
+ break;
}
}
+
+$(document).ready(function() {
+
+ SwingJS.getApplet('testApplet', Info);
+
+});
+
</script>
</head>
<body style="background-image: url(images/coolVeryLightBG.png);">
<td valign=top style="padding:20px;background-color:white" >
One more thing. Let's take a look at the 3D structure of one these proteins. Ferredoxins are important, because they have
iron-sulfur clusters that can accept and deliver electrons in metabolic processes. Let's see if we can find it.
-<br><center><a href="">add the 3D structure</a></center>
+<br><center><button onclick='jvGet("3D")'>add the 3D structure</button>
</td></tr></table>
-<script>
-SwingJS.getApplet('testApplet', Info)
-getClassList = function(){J2S._saveFile('_j2sclasslist.txt', Clazz.ClassFilesLoaded.sort().join('\n'))}
-</script>
-
-
+<!-- debugging (hidden) -->
+<script>getClassList = function(){J2S._saveFile('_j2sclasslist.txt', Clazz.ClassFilesLoaded.sort().join('\n'))}</script>
<div style="display:none;position:absolute;left:900px;top:30px;width:600px;height:300px;">
<div id="sysoutdiv" style="border:1px solid green;width:100%;height:95%;overflow:auto"></div>
This is System.out. <a href="javascript:testApplet._clearConsole()">clear it</a> <br>Add ?j2snocore to URL to see full class list; ?j2sdebug to use uncompressed j2s/core files <br><a href="javascript:getClassList()">get _j2sClassList.txt</a>
</div>
+
</body>
</html>
@Override
public String getSelectedSequencesFrom(AlignFrameI alf)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return getSelectedSequencesFrom(alf, null);
}
@Override
public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getSelectedSequencesFrom(alf, sep);
}
public void highlight(String sequenceId, String position,
String alignedPosition)
{
- highlightIn(getCurrentAlignFrame(), sequenceId, position,
+ highlightIn(null, sequenceId, position,
alignedPosition);
}
public void highlightIn(AlignFrameI alf, String sequenceId,
String position, String alignedPosition)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
}
@Override
public void select(String sequenceIds, String columns, String sep)
{
- selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep);
+ selectIn(null, sequenceIds, columns, sep);
}
@Override
public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
String sep)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.selectIn(alf, sequenceIds, columns, sep);
}
public String getSelectedSequencesAsAlignment(String format,
String suffix)
{
- return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
+ return getSelectedSequencesAsAlignmentFrom(null,
format, suffix);
}
public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
String format, String sep)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
}
@Override
public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getAlignmentOrderFrom(alf, sep);
}
public String orderAlignmentBy(AlignFrameI alf, String order,
String undoName, String sep)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.orderAlignmentBy(alf, order, undoName, sep);
}
@Override
public void loadAnnotationFrom(AlignFrameI alf, String annotation)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.loadAnnotationFrom(alf, annotation);
}
public boolean loadFeaturesFrom(AlignFrameI alf, String features,
boolean autoenabledisplay)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
}
@Override
public String getFeatures(String format)
{
- return getFeaturesFrom(getCurrentAlignFrame(), format);
+ return getFeaturesFrom(null, format);
}
@Override
public String getFeaturesFrom(AlignFrameI alf, String format)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getFeaturesFrom(alf, format);
}
@Override
public String getAnnotation()
{
- return getAnnotationFrom(getCurrentAlignFrame());
+ return getAnnotationFrom(null);
}
@Override
public String getAnnotationFrom(AlignFrameI alf)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getAnnotationFrom(alf);
}
@Override
public AlignFrameI newView()
{
- return newViewFrom(getCurrentAlignFrame(), null);
+ return newViewFrom(null, null);
}
@Override
public AlignFrameI newView(String name)
{
- return newViewFrom(getCurrentAlignFrame(), name);
+ return newViewFrom(null, name);
}
@Override
@Override
public AlignFrameI newViewFrom(AlignFrameI alf, String name)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.newViewFrom(alf, name);
}
public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
String pdbEntryString, String pdbFile)
{
+ if (alFrame == null)
+ {
+ alFrame = getCurrentAlignFrame();
+ }
return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
pdbFile);
}
public void scrollViewToIn(AlignFrameI alf, String topRow,
String leftHandColumn)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
}
@Override
public void scrollViewToRowIn(AlignFrameI alf, String topRow)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.scrollViewToRowIn(alf, topRow);
}
@Override
public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
appLoader.scrollViewToColumnIn(alf, leftHandColumn);
}
@Override
public String getFeatureGroups()
{
- return getFeatureGroupsOn(getCurrentAlignFrame());
+ return getFeatureGroupsOn(null);
}
@Override
public String getFeatureGroupsOn(AlignFrameI alf)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getFeatureGroupsOn(alf);
}
@Override
public String getFeatureGroupsOfState(boolean visible)
{
- return getFeatureGroupsOfStateOn(getCurrentAlignFrame(), visible);
+ return getFeatureGroupsOfStateOn(null, visible);
}
@Override
public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getFeatureGroupsOfStateOn(alf, visible);
}
@Override
- public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
- boolean state)
- {
- setFeatureGroupStateOn(alf, groups, state);
+ public void setFeatureGroupState(String groups, boolean state)
+ { // JalviewLite API
+ setFeatureGroupStateOn(null, groups, state);
}
@Override
- public void setFeatureGroupState(String groups, boolean state)
+ public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
+ boolean state)
{
- appLoader.setFeatureGroupStateOn(getCurrentAlignFrame(), groups, state);
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
+ appLoader.setFeatureGroupStateOn(alf, groups, state);
}
@Override
@Override
public Object openTreePanel(AlignFrame af, String treeType,
String modelName)
- {
+ { // JalviewJS api
+ if (af == null)
+ {
+ af = getCurrentAlignFrame();
+ }
return CalculationChooser.openTreePanel(af, treeType, modelName, null);
}
@Override
public Object openPcaPanel(AlignFrame af, String modelName)
{
+ if (af == null)
+ {
+ af = getCurrentAlignFrame();
+ }
return CalculationChooser.openPcaPanel(af, modelName, null);
}
public String getSelectedSequencesAsAlignment(String format,
boolean suffix)
{
- return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
+ return getSelectedSequencesAsAlignmentFrom(null,
format, suffix);
}
public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
String format, boolean suffix)
{
+ if (alf == null)
+ {
+ alf = getCurrentAlignFrame();
+ }
return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
"" + suffix);
}
// undecorated overview with defined size
frame.setName(Jalview.getAppID("overview"));
//
- Dimension dim = (Dimension) Platform.getEmbeddedAttribute(frame,
- Platform.EMBEDDED_DIM);
+ Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
if (dim != null && dim.width == 0)
{
dim = null; // hidden, not embedded
}
-
OverviewPanel overview = new OverviewPanel(alignPanel, dim);
frame.setContentPane(overview);
frameTitle += this.title;
- Desktop.addInternalFrame(tp, frameTitle, 600, 500);
+ Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
+ Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
}
/**
if (nf.getTree() != null)
{
tp = new TreePanel(alignPanel, nf, treeTitle, input);
-
- tp.setSize(w, h);
+ Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
+ if (dim == null)
+ {
+ dim = new Dimension(w, h);
+ }
+ else
+ {
+ // no offset, either
+ x = 0;
+ }
+ tp.setSize(dim.width, dim.height);
if (x > 0 && y > 0)
{
tp.setLocation(x, y);
}
- Desktop.addInternalFrame(tp, treeTitle, w, h);
+ Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
}
} catch (Exception ex)
{
frame.setIconifiable(resizable);
frame.setOpaque(Platform.isJS());
- if (frame.getX() < 1 && frame.getY() < 1)
+ boolean isEmbedded = (Platform.getDimIfEmbedded(frame, -1, -1) != null);
+ if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1)
{
frame.setLocation(xOffset * openFrameCount,
yOffset * ((openFrameCount - 1) % 10) + yOffset);
import jalview.math.RotatableMatrix.Axis;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.PCAModel;
repaint();
if (getParent() == null)
{
+
+ Dimension dim = Platform.getDimIfEmbedded(this, 475, 450);
Desktop.addInternalFrame(this,
MessageManager.formatMessage("label.calc_title", "PCA",
getPcaModel().getScoreModelName()),
- 475, 450);
- this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
+ dim.width, dim.height);
+ setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
}
working = false;
}
import jalview.xml.binding.jalview.VAMSAS;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.io.BufferedReader;
}
AlignFrame loadViewport(String file, List<JSeq> JSEQ,
- List<SequenceI> hiddenSeqs, AlignmentI al,
- JalviewModel jm, Viewport view, String uniqueSeqSetId,
- String viewId, List<JvAnnotRow> autoAlan)
+ List<SequenceI> hiddenSeqs, AlignmentI al, JalviewModel jm,
+ Viewport view, String uniqueSeqSetId, String viewId,
+ List<JvAnnotRow> autoAlan)
{
AlignFrame af = null;
af = new AlignFrame(al, safeInt(view.getWidth()),
safeInt(view.getHeight()), uniqueSeqSetId, viewId)
-// {
-//
-// @Override
-// protected void processKeyEvent(java.awt.event.KeyEvent e) {
-// System.out.println("Jalview2XML AF " + e);
-// super.processKeyEvent(e);
-//
-// }
-//
-// }
+ // {
+ //
+ // @Override
+ // protected void processKeyEvent(java.awt.event.KeyEvent e) {
+ // System.out.println("Jalview2XML AF " + e);
+ // super.processKeyEvent(e);
+ //
+ // }
+ //
+ // }
;
af.alignPanel.setHoldRepaint(true);
af.setFileName(file, FileFormat.Jalview);
viewport.setColourText(safeBoolean(view.isShowColourText()));
- viewport
- .setConservationSelected(
- safeBoolean(view.isConservationSelected()));
+ viewport.setConservationSelected(
+ safeBoolean(view.isConservationSelected()));
viewport.setIncrement(safeInt(view.getConsThreshold()));
viewport.setShowJVSuffix(safeBoolean(view.isShowFullId()));
viewport.setRightAlignIds(safeBoolean(view.isRightAlignIds()));
af.changeColour(cs);
viewport.setColourAppliesToAllGroups(true);
- viewport
- .setShowSequenceFeatures(
- safeBoolean(view.isShowSequenceFeatures()));
+ viewport.setShowSequenceFeatures(
+ safeBoolean(view.isShowSequenceFeatures()));
viewport.setCentreColumnLabels(view.isCentreColumnLabels());
viewport.setIgnoreGapsConsensus(view.isIgnoreGapsinConsensus(), null);
.getFeatureRenderer();
FeaturesDisplayed fdi;
viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
- String[] renderOrder = new String[jm.getFeatureSettings()
- .getSetting().size()];
+ String[] renderOrder = new String[jm.getFeatureSettings().getSetting()
+ .size()];
Map<String, FeatureColourI> featureColours = new Hashtable<>();
Map<String, Float> featureOrder = new Hashtable<>();
- for (int fs = 0; fs < jm.getFeatureSettings()
- .getSetting().size(); fs++)
+ for (int fs = 0; fs < jm.getFeatureSettings().getSetting()
+ .size(); fs++)
{
Setting setting = jm.getFeatureSettings().getSetting().get(fs);
String featureType = setting.getType();
.getMatcherSet();
if (filters != null)
{
- FeatureMatcherSetI filter = Jalview2XML
- .parseFilter(featureType, filters);
+ FeatureMatcherSetI filter = Jalview2XML.parseFilter(featureType,
+ filters);
if (!filter.isEmpty())
{
fr.setFeatureFilter(featureType, filter);
float max = setting.getMax() == null ? 1f
: setting.getMax().floatValue();
FeatureColourI gc = new FeatureColour(maxColour, minColour,
- maxColour,
- noValueColour, min, max);
+ maxColour, noValueColour, min, max);
if (setting.getAttributeName().size() > 0)
{
gc.setAttributeName(setting.getAttributeName().toArray(
}
else
{
- featureColours.put(featureType,
- new FeatureColour(maxColour));
+ featureColours.put(featureType, new FeatureColour(maxColour));
}
renderOrder[fs] = featureType;
if (setting.getOrder() != null)
String complementaryViewId = view.getComplementId();
if (complementaryViewId == null)
{
- Desktop.addInternalFrame(af, view.getTitle(),
+ Dimension dim = Platform.getDimIfEmbedded(af,
safeInt(view.getWidth()), safeInt(view.getHeight()));
+ Desktop.addInternalFrame(af, view.getTitle(), dim.width, dim.height);
// recompute any autoannotation
af.alignPanel.updateAnnotation(false, true);
reorderAutoannotation(af, al, autoAlan);
axis.getXPos(), axis.getYPos(), axis.getZPos());
}
+ Dimension dim = Platform.getDimIfEmbedded(panel, 475, 450);
Desktop.addInternalFrame(panel, MessageManager.formatMessage(
- "label.calc_title", "PCA", modelName), 475, 450);
+ "label.calc_title", "PCA", modelName), dim.width,
+ dim.height);
}
} catch (Exception ex)
{
import jalview.javascript.json.JSON;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import org.json.simple.parser.JSONParser;
*/
}
- public final static String EMBEDDED_DIM = "dim";
+ /**
+ * Retrieve the object's embedded size from a div's style on a page if
+ * embedded in SwingJS.
+ *
+ * @param frame
+ * JFrame or JInternalFrame
+ * @param defaultWidth
+ * use -1 to return null (no default size)
+ * @param defaultHeight
+ * @return the embedded dimensions or null (no default size or not embedded)
+ */
+ public static Dimension getDimIfEmbedded(JComponent frame,
+ int defaultWidth, int defaultHeight)
+ {
+ Dimension d = /** @j2sNative frame.ui.getEmbedded$S("dim") || */
+ null;
+ return (d == null && defaultWidth >= 0
+ ? new Dimension(defaultWidth, defaultHeight)
+ : d);
+ }
/**
*
{
return null;
}
- return (/** swingjs@j2sNative || frame.ui.getEmbedded(type) */
+ return (/** @j2sNative frame.ui.getEmbedded$S(type) || */
null);
}