Author: echatellier Date: 2013-02-06 14:57:53 +0100 (Wed, 06 Feb 2013) New Revision: 80 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/80 Log: Improve molecule viewer and editor Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/search/SearchPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java trunk/cantharella.web/src/main/webapp/js/molviewer.js Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-06 13:20:16 UTC (rev 79) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-06 13:57:53 UTC (rev 80) @@ -108,7 +108,7 @@ add(new Label("Molecule.nomCommun", new PropertyModel<String>(moleculeModel, "nomCommun")).add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.familleChimique", new PropertyModel<String>(moleculeModel, "familleChimique")).add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.formuleDevMol", new PropertyModel<String>(moleculeModel, "formuleDevMol")).add(new ReplaceEmptyLabelBehavior()) - .add(new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol")))); + .add(new MoleculeViewBehavior(new PropertyModel<String>(moleculeModel, "formuleDevMol"), 500, 300))); add(new Label("Molecule.nomIupca", new PropertyModel<String>(moleculeModel, "nomIupca")).add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.formuleBrute", new PropertyModel<String>(moleculeModel, "formuleBrute")).add(new ReplaceEmptyLabelBehavior())); add(new Label("Molecule.masseMolaire", new DisplayDecimalPropertyModel(moleculeModel, "masseMolaire", DecimalDisplFormat.SMALL, getLocale())).add(new ReplaceEmptyLabelBehavior())); Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/search/SearchPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/search/SearchPage.java 2013-02-06 13:20:16 UTC (rev 79) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/search/SearchPage.java 2013-02-06 13:57:53 UTC (rev 80) @@ -104,7 +104,7 @@ protected SearchService searchService; /** Nombre d'extraits affichés dans la colonne de résumés des extraits. */ - private static int MAX_EXTRAITS_DISPLAY = 4; + private static final int MAX_EXTRAITS_DISPLAY = 4; /** * Constructor. Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java 2013-02-06 13:20:16 UTC (rev 79) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/behaviors/MoleculeViewBehavior.java 2013-02-06 13:57:53 UTC (rev 80) @@ -41,13 +41,32 @@ */ public class MoleculeViewBehavior extends AttributeModifier { + /** Canvas width. */ + protected int width; + + /** Canvas height. */ + protected int height; + /** + * Constructor with default canvas size. + * + * @param replaceModel replace model + */ + public MoleculeViewBehavior(IModel<?> replaceModel) { + this(replaceModel, 100, 100); + } + + /** * Constructor. * * @param replaceModel replace model + * @param width canvas width + * @param height canvas height */ - public MoleculeViewBehavior(IModel<?> replaceModel) { + public MoleculeViewBehavior(IModel<?> replaceModel, int width, int height) { super("formula", replaceModel); + this.width = width; + this.height = height; } /** {@inheritDoc} */ @@ -84,7 +103,7 @@ response.write(JavaScriptUtils.SCRIPT_OPEN_TAG); - response.write("addViewerMolecule('"+id+"');"); + response.write("addViewerMolecule('"+id+"', " + width + "," + height + ");"); response.write(JavaScriptUtils.SCRIPT_CLOSE_TAG); } Modified: trunk/cantharella.web/src/main/webapp/js/molviewer.js =================================================================== --- trunk/cantharella.web/src/main/webapp/js/molviewer.js 2013-02-06 13:20:16 UTC (rev 79) +++ trunk/cantharella.web/src/main/webapp/js/molviewer.js 2013-02-06 13:57:53 UTC (rev 80) @@ -20,7 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -function addViewerMolecule(tagId) { +function addViewerMolecule(tagId, width, height) { if (tagId) { tagId = '#' + tagId.replace( /(:|\.)/g, "\\$1" ); } else { @@ -35,7 +35,7 @@ $(formulaTag).replaceWith("<canvas id='"+id+"'/>"); //initialize component and set visual specifications - var viewerCanvas = new ChemDoodle.ViewerCanvas(id, 100, 100); + var viewerCanvas = new ChemDoodle.ViewerCanvas(id, width, height); viewerCanvas.specs.bonds_width_2D = .6; viewerCanvas.specs.bonds_saturationWidth_2D = .18; viewerCanvas.specs.bonds_hashSpacing_2D = 2.5; @@ -44,7 +44,13 @@ viewerCanvas.specs.atoms_displayTerminalCarbonLabels_2D = true; var formula = ChemDoodle.readMOL(formulaString); + + // function to scale molecul to canvas + var size = formula.getDimension(); + var scale = Math.min(viewerCanvas.width/size.x, viewerCanvas.height/size.y); viewerCanvas.loadMolecule(formula); + viewerCanvas.specs.scale = scale*.8; + viewerCanvas.repaint(); }); }
participants (1)
-
echatellier@users.forge.codelutin.com