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 b6c955c34d2e57f6f6fc71d648c6b8f07736aed2 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 15:19:01 2015 +0100 refs #6538 better handle erors --- .../operation/catches/EditCatchesUIHandler.java | 411 +++++++++++---------- 1 file changed, 214 insertions(+), 197 deletions(-) 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 bd8dc22..e27cc5f 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 @@ -54,6 +54,7 @@ import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; import org.apache.batik.swing.gvt.GVTTreeRendererEvent; +import org.apache.batik.swing.svg.SVGUserAgentAdapter; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; @@ -168,6 +169,21 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi protected Document svgDocument; + protected final SVGUserAgentAdapter ua = new SVGUserAgentAdapter() { + @Override + public void displayError(String message) { + if (log.isErrorEnabled()) { + log.error("Canvas error: " + message); + } + } + @Override + public void displayError(Exception ex) { + if (log.isErrorEnabled()) { + log.error("Canvas error", ex); + } + } + }; + //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @@ -322,15 +338,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi clearSVG(); } if (newIndex == 0 && getUI().isVisible()) { - try { - initResumeSvg(); - - } catch (IOException err) { - if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", err); - } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); - } + initResumeSvg(); } } @@ -407,16 +415,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi @Override public void onShowTab(int currentIndex, int newIndex) { registerValidators(); - - try { - initResumeSvg(); - - } catch (IOException err) { - if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", err); - } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); - } + initResumeSvg(); } @Override @@ -786,129 +785,138 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi //-- Protected methods --// //------------------------------------------------------------------------// - protected 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(1, 1)); - canvas.setMySize(new Dimension(1, 1)); + protected void initResumeSvg() { + try { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + URL url = Resource.getURL("EcranResume.svg"); + svgDocument = f.createDocument(url.toString()); + + // redefine user agent to avoid displaying errors about css + canvas = new JSVGCanvas(ua, true, true); + canvas.setSize(new Dimension(1, 1)); + canvas.setMySize(new Dimension(1, 1)); + + canvas.setRecenterOnResize(true); + + canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { + @Override + public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { + if (log.isDebugEnabled()) { + log.debug("gvtRenderingCompleted"); + } + TuttiConfiguration config = getConfig(); + WeightUnit catchWeightUnit = WeightUnit.KG; + WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); + WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); + WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); + + EditCatchesUIModel model = getModel(); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, + model.getCatchTotalComputedOrNotWeight(), + catchWeightUnit); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + model.getCatchTotalRejectedComputedOrNotWeight(), + catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getSpeciesTotalSortedComputedOrNotWeight(), + speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); + + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getBenthosTotalSortedComputedOrNotWeight(), + benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + speciesWeightUnit, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + benthosWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, + model.getMarineLitterTotalComputedOrNotWeight(), + marineLitterWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); + + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT)); + + initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); + initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); + + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); + + getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + } + }); - canvas.setRecenterOnResize(true); + canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); + canvas.setDocument(svgDocument); - canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { - @Override - public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { - if (log.isDebugEnabled()) { - log.debug("gvtRenderingCompleted"); - } - TuttiConfiguration config = getConfig(); - WeightUnit catchWeightUnit = WeightUnit.KG; - WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); - WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); - WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); - - EditCatchesUIModel model = getModel(); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, - model.getCatchTotalComputedOrNotWeight(), - catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - model.getCatchTotalRejectedComputedOrNotWeight(), - catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - model.getSpeciesTotalSortedComputedOrNotWeight(), - speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); - - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - model.getBenthosTotalSortedComputedOrNotWeight(), - benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - speciesWeightUnit, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - benthosWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, - model.getMarineLitterTotalComputedOrNotWeight(), - marineLitterWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); - - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT)); - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT)); - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT)); - - initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); - initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); - - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); - - getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + } catch (IOException err) { + if (log.isErrorEnabled()) { + log.error("error while initializing the resume background", err); } - }); - - canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); - canvas.setDocument(svgDocument); + getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); + } } protected void initSpeciesCount(final String property) { @@ -917,7 +925,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi log.debug("init " + property + " field"); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { Element labelElement = svgDocument.getElementById(property + "Label"); @@ -958,7 +966,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi log.debug("init " + property + " field"); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { Element labelElement = svgDocument.getElementById(property + "Label"); @@ -1032,7 +1040,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { @@ -1088,6 +1096,18 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } + protected void updateOnCanvas(Runnable runnable) { + try { + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(runnable); + } catch (IllegalStateException e) { + if (log.isErrorEnabled()) { + log.error("error while updating canvas, reload it"); + } + clearSVG(); + initResumeSvg(); + } + } + protected Float getModelPropertyValue(String property) { Float value; try { @@ -1138,49 +1158,48 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi final boolean computed, final String... idsInGroup) { - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + property + " field"); - } + updateOnCanvas(new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + property + " field"); + } - SVGOMTextElement valueElement = (SVGOMTextElement) svgDocument.getElementById(property + "Value"); - if (valueElement == null) { - return; - } + SVGOMTextElement valueElement = (SVGOMTextElement) svgDocument.getElementById(property + "Value"); + if (valueElement == null) { + return; + } - //TODO i18n ? - String textContent; - if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); - } else { - textContent = null; - } - valueElement.setTextContent(textContent); - - CSSStyleDeclaration style = valueElement.getStyle(); - - Color colorComputedWeights = getConfig().getColorComputedWeights(); - String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); - style.setProperty("fill", computed ? computedColor : "#000000", null); - style.setProperty("font-style", computed ? "italic" : "normal", null); - - SVGRect bbox = valueElement.getBBox(); - SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); - if (bbox != null && rectElement != null) { - float width = bbox.getWidth() + 15; - float actualWidth = rectElement.getBBox().getWidth(); - if (actualWidth < width) { - rectElement.setAttribute("width", Float.toString(width)); - for (String id : idsInGroup) { - Element el = svgDocument.getElementById(id + "Rect"); - el.setAttribute("width", Float.toString(width)); - } - } + //TODO i18n ? + String textContent; + if (value != null) { + textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); + } else { + textContent = null; + } + valueElement.setTextContent(textContent); + + CSSStyleDeclaration style = valueElement.getStyle(); + + Color colorComputedWeights = getConfig().getColorComputedWeights(); + String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); + style.setProperty("fill", computed ? computedColor : "#000000", null); + style.setProperty("font-style", computed ? "italic" : "normal", null); + + SVGRect bbox = valueElement.getBBox(); + SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); + if (bbox != null && rectElement != null) { + float width = bbox.getWidth() + 15; + float actualWidth = rectElement.getBBox().getWidth(); + if (actualWidth < width) { + rectElement.setAttribute("width", Float.toString(width)); + for (String id : idsInGroup) { + Element el = svgDocument.getElementById(id + "Rect"); + el.setAttribute("width", Float.toString(width)); } } - }); + } + } + }); } @@ -1278,22 +1297,21 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } protected void updateColor() { - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + elementId + " field"); - } + updateOnCanvas(new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + elementId + " field"); + } - Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); - SVGStylable field = (SVGStylable) rectElement; - CSSStyleDeclaration style = field.getStyle(); + Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); + SVGStylable field = (SVGStylable) rectElement; + CSSStyleDeclaration style = field.getStyle(); - final Color background = colorFunction.apply(getModel()); - String color = "#" + Integer.toHexString(background.getRGB()).substring(2); - style.setProperty("fill", color, null); - } - }); + final Color background = colorFunction.apply(getModel()); + String color = "#" + Integer.toHexString(background.getRGB()).substring(2); + style.setProperty("fill", color, null); + } + }); } } @@ -1351,8 +1369,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { + updateOnCanvas(new Runnable() { public void run() { if (log.isDebugEnabled()) { log.debug("update " + elementId + " field"); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.