From: hansonr Date: Sun, 6 Oct 2019 10:41:22 +0000 (+0200) Subject: JAL-3451 JalviewJS embedded mode not resizing X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cb51e62fe2166b236ef488e0a8f35081fcd71388;p=jalview.git JAL-3451 JalviewJS embedded mode not resizing - adds Platform.getDimIfEmbedded(frame, defaultWidth, defaultHeight) - implemented for AlignFrame, TreePanel, and PCAPanel --- diff --git a/site-resources/jalview_embedded_example1.html b/site-resources/jalview_embedded_example1.html index 7163d57..0e0c418 100644 --- a/site-resources/jalview_embedded_example1.html +++ b/site-resources/jalview_embedded_example1.html @@ -4,6 +4,10 @@ Embedded JalviewJS Example 1 @@ -116,19 +122,16 @@ jalview-strucddtureviewer-div 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. -
add the 3D structure
+
- - - + +
This is System.out. clear it
Add ?j2snocore to URL to see full class list; ?j2sdebug to use uncompressed j2s/core files
get _j2sClassList.txt
+ diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index f59c37f..3d80589 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -1643,6 +1643,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public String getSelectedSequencesFrom(AlignFrameI alf) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return getSelectedSequencesFrom(alf, null); } @@ -1654,6 +1658,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public String getSelectedSequencesFrom(AlignFrameI alf, String sep) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.getSelectedSequencesFrom(alf, sep); } @@ -1666,7 +1674,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public void highlight(String sequenceId, String position, String alignedPosition) { - highlightIn(getCurrentAlignFrame(), sequenceId, position, + highlightIn(null, sequenceId, position, alignedPosition); } @@ -1674,6 +1682,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public void highlightIn(AlignFrameI alf, String sequenceId, String position, String alignedPosition) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } appLoader.highlightIn(alf, sequenceId, position, alignedPosition); } @@ -1686,7 +1698,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public void select(String sequenceIds, String columns, String sep) { - selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep); + selectIn(null, sequenceIds, columns, sep); } @Override @@ -1699,6 +1711,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public void selectIn(AlignFrameI alf, String sequenceIds, String columns, String sep) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } appLoader.selectIn(alf, sequenceIds, columns, sep); } @@ -1706,7 +1722,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public String getSelectedSequencesAsAlignment(String format, String suffix) { - return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(), + return getSelectedSequencesAsAlignmentFrom(null, format, suffix); } @@ -1714,6 +1730,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf, String format, String sep) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep); } @@ -1732,6 +1752,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public String getAlignmentOrderFrom(AlignFrameI alf, String sep) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.getAlignmentOrderFrom(alf, sep); } @@ -1751,6 +1775,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public String orderAlignmentBy(AlignFrameI alf, String order, String undoName, String sep) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.orderAlignmentBy(alf, order, undoName, sep); } @@ -1788,6 +1816,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public void loadAnnotationFrom(AlignFrameI alf, String annotation) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } appLoader.loadAnnotationFrom(alf, annotation); } @@ -1801,43 +1833,55 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi 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 @@ -1849,6 +1893,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public AlignFrameI newViewFrom(AlignFrameI alf, String name) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.newViewFrom(alf, name); } @@ -1863,6 +1911,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public boolean addPdbFile(AlignFrameI alFrame, String sequenceId, String pdbEntryString, String pdbFile) { + if (alFrame == null) + { + alFrame = getCurrentAlignFrame(); + } return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString, pdbFile); } @@ -1871,56 +1923,80 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi 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 @@ -1955,7 +2031,11 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public Object openTreePanel(AlignFrame af, String treeType, String modelName) - { + { // JalviewJS api + if (af == null) + { + af = getCurrentAlignFrame(); + } return CalculationChooser.openTreePanel(af, treeType, modelName, null); } @@ -1971,6 +2051,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi @Override public Object openPcaPanel(AlignFrame af, String modelName) { + if (af == null) + { + af = getCurrentAlignFrame(); + } return CalculationChooser.openPcaPanel(af, modelName, null); } @@ -1978,7 +2062,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public String getSelectedSequencesAsAlignment(String format, boolean suffix) { - return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(), + return getSelectedSequencesAsAlignmentFrom(null, format, suffix); } @@ -1986,6 +2070,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf, String format, boolean suffix) { + if (alf == null) + { + alf = getCurrentAlignFrame(); + } return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, "" + suffix); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0b84e9b..0271506 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3393,13 +3393,11 @@ public class AlignFrame extends GAlignFrame // 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); @@ -3778,7 +3776,8 @@ public class AlignFrame extends GAlignFrame frameTitle += this.title; - Desktop.addInternalFrame(tp, frameTitle, 600, 500); + Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500); + Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height); } /** @@ -4130,15 +4129,24 @@ public class AlignFrame extends GAlignFrame 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) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 4eff90a..85ec3aecf 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -964,7 +964,8 @@ public class Desktop extends GDesktop 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); diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index bec8aae..bebc7f0 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -36,6 +36,7 @@ import jalview.jbgui.GPCAPanel; 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; @@ -200,11 +201,13 @@ public class PCAPanel extends GPCAPanel 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; } diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index cadc253..186f786 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -150,6 +150,7 @@ import jalview.xml.binding.jalview.ThresholdType; 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; @@ -4997,23 +4998,23 @@ public class Jalview2XML } AlignFrame loadViewport(String file, List JSEQ, - List hiddenSeqs, AlignmentI al, - JalviewModel jm, Viewport view, String uniqueSeqSetId, - String viewId, List autoAlan) + List hiddenSeqs, AlignmentI al, JalviewModel jm, + Viewport view, String uniqueSeqSetId, String viewId, + List 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); @@ -5091,9 +5092,8 @@ public class Jalview2XML 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())); @@ -5179,9 +5179,8 @@ public class Jalview2XML 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); @@ -5202,13 +5201,13 @@ public class Jalview2XML .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 featureColours = new Hashtable<>(); Map 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(); @@ -5220,8 +5219,8 @@ public class Jalview2XML .getMatcherSet(); if (filters != null) { - FeatureMatcherSetI filter = Jalview2XML - .parseFilter(featureType, filters); + FeatureMatcherSetI filter = Jalview2XML.parseFilter(featureType, + filters); if (!filter.isEmpty()) { fr.setFeatureFilter(featureType, filter); @@ -5253,8 +5252,7 @@ public class Jalview2XML 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( @@ -5288,8 +5286,7 @@ public class Jalview2XML } else { - featureColours.put(featureType, - new FeatureColour(maxColour)); + featureColours.put(featureType, new FeatureColour(maxColour)); } renderOrder[fs] = featureType; if (setting.getOrder() != null) @@ -5357,8 +5354,9 @@ public class Jalview2XML 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); @@ -6469,8 +6467,10 @@ public class Jalview2XML 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) { diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index fba669b..11f7988 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -23,6 +23,7 @@ package jalview.util; 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; @@ -40,6 +41,7 @@ import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JComponent; import javax.swing.SwingUtilities; import org.json.simple.parser.JSONParser; @@ -836,7 +838,26 @@ public class Platform */ } - 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); + } /** * @@ -853,7 +874,7 @@ public class Platform { return null; } - return (/** swingjs@j2sNative || frame.ui.getEmbedded(type) */ + return (/** @j2sNative frame.ui.getEmbedded$S(type) || */ null); }