This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit dfcc32bece205f2ece91017a710824027416c366 Author: Kevin Morin <morin@codelutin.com> Date: Fri Jan 23 15:37:22 2015 +0100 refs #6453 resize the svg dinacally --- .../content/operation/catches/EditCatchesUI.jaxx | 13 +- .../operation/catches/EditCatchesUIHandler.java | 150 +++++++++++---------- tutti-ui-swing/src/main/resources/EcranResume.svg | 15 ++- 3 files changed, 89 insertions(+), 89 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx index b9d3491..4f285c1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx @@ -113,17 +113,8 @@ public EditCatchesUI(FishingOperationsUI parentUI) { <JTabbedPane id='tabPane' constraints='BorderLayout.CENTER'> <tab id='svgTab'> <JXTitledPanel id='svgTabPane'> - <!--JScrollPane id='svgTabScrollPane'> - <JPanel layout='{new BorderLayout()}' id='svgCanvasPanel'--> - <Table> - <row> - <cell> - <JPanel id='svgCanvasPanel' layout='{new BorderLayout()}'/> - </cell> - </row> - </Table> - <!--/JPanel> - </JScrollPane--> + <JPanel layout='{new BorderLayout()}' id='svgCanvasPanel'> + </JPanel> </JXTitledPanel> </tab> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index 612fa46..746dab7 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -47,16 +47,11 @@ import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.dom.svg.SVGOMRectElement; import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.swing.JSVGCanvas; -import org.apache.batik.swing.JSVGScrollPane; -import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; -import org.apache.batik.swing.gvt.GVTTreeRendererEvent; import org.apache.batik.swing.svg.GVTTreeBuilderAdapter; import org.apache.batik.swing.svg.GVTTreeBuilderEvent; -import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter; -import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; import org.apache.batik.util.RunnableQueue; -import org.apache.batik.util.SVGConstants; import org.apache.batik.util.XMLResourceDescriptor; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTitledPanel; @@ -67,23 +62,13 @@ import org.w3c.dom.Element; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventTarget; -import org.w3c.dom.svg.SVGDocument; -import org.w3c.dom.svg.SVGLength; import org.w3c.dom.svg.SVGRect; -import org.w3c.dom.svg.SVGSVGElement; import org.w3c.dom.svg.SVGStylable; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTabbedPane; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.geom.AffineTransform; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; @@ -234,56 +219,62 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi }); try { - // Parse the barChart.svg file into a Document. - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - URL url = Resource.getURL("EcranResume.svg"); - svgDocument = f.createDocument(url.toString()); - - canvas = new JSVGCanvas(); - ui.getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); - canvas.setRecenterOnResize(true); - - canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { - public void gvtBuildCompleted(GVTTreeBuilderEvent e) { - - TuttiConfiguration config = getConfig(); - WeightUnit catchWeightUnit = WeightUnit.KG; - WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); - WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); - WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, getModel().getCatchTotalComputedOrNotWeight(), catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, getModel().getCatchTotalRejectedComputedOrNotWeight(), catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, getModel().getSpeciesTotalSortedComputedOrNotWeight(), speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, getModel().getBenthosTotalSortedComputedOrNotWeight(), benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, getModel().getMarineLitterTotalComputedOrNotWeight(), marineLitterWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); - - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); + initResumeSvg(); - } - }); - - canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); - canvas.setDocument(svgDocument); - - } catch (IOException e) { + } catch (IOException err) { if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", e); + log.error("error while initializing the resume background", err); } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), e); + getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); } + } + + public void initResumeSvg() throws IOException { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + URL url = Resource.getURL("EcranResume.svg"); + svgDocument = f.createDocument(url.toString()); + + canvas = new JSVGCanvas(); + canvas.setSize(new Dimension(700, 300)); + canvas.setMySize(new Dimension(700, 300)); + + getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + + canvas.setRecenterOnResize(true); + + canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { + public void gvtBuildCompleted(GVTTreeBuilderEvent e) { + + TuttiConfiguration config = getConfig(); + WeightUnit catchWeightUnit = WeightUnit.KG; + WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); + WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); + WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, getModel().getCatchTotalComputedOrNotWeight(), catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, getModel().getCatchTotalRejectedComputedOrNotWeight(), catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, getModel().getSpeciesTotalSortedComputedOrNotWeight(), speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, getModel().getBenthosTotalSortedComputedOrNotWeight(), benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, getModel().getMarineLitterTotalComputedOrNotWeight(), marineLitterWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); + + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + } + }); + + canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); + canvas.setDocument(svgDocument); } protected void initSvgField(String property, WeightUnit weightUnit) { @@ -330,18 +321,33 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi if (computableData == null) { // computed data value + OnDataOrComputedDataValueChangedListener listener = new OnDataOrComputedDataValueChangedListener(property, weightUnit, true, canvas, svgDocument, colorComputedWeights); + EditCatchesUIModel model = getModel(); + String propertyValue = null; + try { + propertyValue = BeanUtils.getProperty(model, property); + + } catch (ReflectiveOperationException e) { + if (log.isErrorEnabled()) { + log.error("Error while getting model's property " + property, e); + } + } + Float value = propertyValue != null ? Float.valueOf(propertyValue) : null; + listener.updateValue(value, true); + model.addPropertyChangeListener(property, listener); - getModel().addPropertyChangeListener(property, new OnDataOrComputedDataValueChangedListener(property, weightUnit, true, canvas, svgDocument, colorComputedWeights)); } else { // data or computed data value - Element element = svgDocument.getElementById(property); EventTarget target = (EventTarget) element; target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); - computableData.addPropertyChangeListener(new OnDataOrComputedDataValueChangedListener(property, weightUnit, false, canvas, svgDocument, colorComputedWeights)); - + OnDataOrComputedDataValueChangedListener listener = new OnDataOrComputedDataValueChangedListener(property, weightUnit, false, canvas, svgDocument, colorComputedWeights); + boolean computed = computableData.getData() == null; + Float value = computableData.getDataOrComputedData(); + listener.updateValue(value, computed); + computableData.addPropertyChangeListener(listener); } } @@ -955,25 +961,25 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } } - updateValue(property, newValue, weightUnit, computedData); + updateValue(newValue, computedData); } - protected void updateValue(final String id, final Float value, final WeightUnit unit, final boolean computed) { + public void updateValue(final Float value, final boolean computed) { getUpdateRunnableQueue().invokeLater (new Runnable() { public void run() { if (log.isDebugEnabled()) { - log.debug("update " + id + " field"); + log.debug("update " + property + " field"); } - Element element = svgDocument.getElementById(id + "Value"); + Element element = svgDocument.getElementById(property + "Value"); if (element == null) { return; } - Element rectElement = svgDocument.getElementById(id + "Rect"); + Element rectElement = svgDocument.getElementById(property + "Rect"); SVGOMRectElement rectElem = (SVGOMRectElement) rectElement; SVGRect bbox = rectElem.getBBox(); Float x = bbox.getX(); @@ -981,7 +987,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi //TODO i18n ? String textContent; if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + unit.getShortLabel(); + textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); } else { textContent = null; } diff --git a/tutti-ui-swing/src/main/resources/EcranResume.svg b/tutti-ui-swing/src/main/resources/EcranResume.svg index efb6873..0c8e16f 100644 --- a/tutti-ui-swing/src/main/resources/EcranResume.svg +++ b/tutti-ui-swing/src/main/resources/EcranResume.svg @@ -9,14 +9,17 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="700" - height="350" + inkscape:version="0.48.3.1 r9886" + sodipodi:docname="EcranResume.svg" + version="1.1" + x="0px" + y="0px" + width="700px" + height="350px" viewport="0 0 700 350" + viewBox="0 0 700 350" id="svg2985" - preserveAspectRatio="xMidYMid" - version="1.1" - inkscape:version="0.48.3.1 r9886" - sodipodi:docname="EcranResume.svg"> + preserveAspectRatio="xMidYMid"> <defs id="defs2987"> <filter -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.