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 2a4947f9454fd3fe6e818bc88646f127fcca74f4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 20 13:03:45 2015 +0100 improve code --- .../operation/catches/EditCatchesUIHandler.java | 208 +++++++++++++-------- 1 file changed, 126 insertions(+), 82 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 476c3b0..5708064 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 @@ -25,11 +25,8 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; import com.google.common.collect.Sets; import fr.ifremer.tutti.TuttiConfiguration; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.type.WeightUnit; -import fr.ifremer.tutti.ui.swing.util.catches.EnterWeightUI; -import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; -import fr.ifremer.tutti.util.Weights; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyCellComponent; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyUI; @@ -41,12 +38,16 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSp import fr.ifremer.tutti.ui.swing.util.AbstractTuttiTabContainerUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; +import fr.ifremer.tutti.ui.swing.util.catches.EnterWeightUI; +import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; +import fr.ifremer.tutti.util.Weights; import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.validator.swing.SwingValidator; 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.util.RunnableQueue; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -61,10 +62,15 @@ import org.w3c.dom.events.EventTarget; import org.w3c.dom.svg.SVGRect; import org.w3c.dom.svg.SVGStylable; -import javax.swing.*; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; @@ -276,11 +282,12 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi Element labelElement = svgDocument.getElementById(property + "Label"); labelElement.setTextContent(t("tutti.editCatchBatch.field." + property)); + Color colorComputedWeights = getConfig().getColorComputedWeights(); if (computableData == null) { // computed data value - getModel().addPropertyChangeListener(property, new OnComputedDataValueChangedListener(property, weightUnit)); + getModel().addPropertyChangeListener(property, new OnDataOrComputedDataValueChangedListener(property, weightUnit, true, canvas, svgDocument, colorComputedWeights)); } else { // data or computed data value @@ -289,67 +296,11 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi EventTarget target = (EventTarget) element; target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); - computableData.addPropertyChangeListener(new OnDataOrComputedDataValueChangedListener(property, weightUnit)); + computableData.addPropertyChangeListener(new OnDataOrComputedDataValueChangedListener(property, weightUnit, false, canvas, svgDocument, colorComputedWeights)); } } - public void updateValue(final String id, final Float value, final WeightUnit unit, final boolean computed) { - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + id + " field"); - } - - Element element = svgDocument.getElementById(id + "Value"); - if (element == null) { - return; - } - - Element rectElement = svgDocument.getElementById(id + "Rect"); - SVGOMRectElement rectElem = (SVGOMRectElement) rectElement; - SVGRect bbox = rectElem.getBBox(); - Float x = bbox.getX(); - - //TODO i18n ? - String textContent; - if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + unit.getShortLabel(); - } else { - textContent = null; - } - element.setTextContent(textContent); - - SVGStylable field = (SVGStylable) element; - CSSStyleDeclaration style = field.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); - - SVGOMTextElement textElem = (SVGOMTextElement) element; - bbox = textElem.getBBox(); - if (bbox != null) { - float width = bbox.getWidth() + 20; - rectElement.setAttribute("width", Float.toString(width)); - element.setAttribute("x", String.valueOf(x + width / 2)); - } - - Element labelElement = svgDocument.getElementById(id + "Label"); - Element labelRectElement = svgDocument.getElementById(id + "LabelRect"); - SVGOMTextElement labelTextElem = (SVGOMTextElement) labelElement; - bbox = labelTextElem.getBBox(); - float width = bbox.getWidth() + 20; - labelRectElement.setAttribute("width", Float.toString(width)); - labelRectElement.setAttribute("x", String.valueOf(x - width)); - labelElement.setAttribute("x", String.valueOf(x - width / 2)); - } - }); - - } - public void closeAttachments() { ui.getCatchesCaracteristicsAttachmentsButton().onCloseUI(); ui.getSpeciesTabContent().getSpeciesBatchAttachmentsButton().onCloseUI(); @@ -388,7 +339,6 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi closeUI(ui.getAccidentalTabContent()); closeUI(ui.getIndividualObservationTabContent()); - canvas.dispose(); } @Override @@ -894,39 +844,133 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } } - private class OnDataOrComputedDataValueChangedListener implements PropertyChangeListener { + private static class OnDataOrComputedDataValueChangedListener implements PropertyChangeListener { private final String property; private final WeightUnit weightUnit; - public OnDataOrComputedDataValueChangedListener(String property, WeightUnit weightUnit) { + private final boolean onlyReactOnComputedData; + + private final JSVGCanvas canvas; + + private RunnableQueue updateRunnableQueue; + + private final Document svgDocument; + + private final Color colorComputedWeights; + + public OnDataOrComputedDataValueChangedListener(String property, + WeightUnit weightUnit, + boolean onlyReactOnComputedData, + JSVGCanvas canvas, + Document svgDocument, + Color colorComputedWeights) { this.property = property; this.weightUnit = weightUnit; + this.onlyReactOnComputedData = onlyReactOnComputedData; + this.canvas = canvas; + this.svgDocument = svgDocument; + this.colorComputedWeights = colorComputedWeights; + + } + + public RunnableQueue getUpdateRunnableQueue() { + if (updateRunnableQueue == null) { + updateRunnableQueue = canvas.getUpdateManager().getUpdateRunnableQueue(); + + } + return updateRunnableQueue; } @Override public void propertyChange(PropertyChangeEvent evt) { - ComputableData<Float> computableData = (ComputableData<Float>) evt.getSource(); - Float newValue = computableData.getDataOrComputedData(); - updateValue(property, newValue, weightUnit, false); - } - } - private class OnComputedDataValueChangedListener implements PropertyChangeListener { - private final String property; + boolean computedData; - private final WeightUnit weightUnit; + Float newValue; + + if (onlyReactOnComputedData) { + + computedData = true; + newValue = (Float) evt.getNewValue(); + + } else { + + ComputableData<Float> computableData = (ComputableData<Float>) evt.getSource(); + + if (computableData.getData() == null) { + + computedData = true; + newValue = computableData.getComputedData(); + + } else { + + computedData = false; + newValue = computableData.getData(); + + } + + } + updateValue(property, newValue, weightUnit, computedData); - public OnComputedDataValueChangedListener(String property, WeightUnit weightUnit) { - this.property = property; - this.weightUnit = weightUnit; } - @Override - public void propertyChange(PropertyChangeEvent evt) { - Float data = (Float) evt.getNewValue(); - updateValue(property, data, weightUnit, true); + protected void updateValue(final String id, final Float value, final WeightUnit unit, final boolean computed) { + + getUpdateRunnableQueue().invokeLater + (new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + id + " field"); + } + + Element element = svgDocument.getElementById(id + "Value"); + if (element == null) { + return; + } + + Element rectElement = svgDocument.getElementById(id + "Rect"); + SVGOMRectElement rectElem = (SVGOMRectElement) rectElement; + SVGRect bbox = rectElem.getBBox(); + Float x = bbox.getX(); + + //TODO i18n ? + String textContent; + if (value != null) { + textContent = Weights.getWeightStringValue(value) + " " + unit.getShortLabel(); + } else { + textContent = null; + } + element.setTextContent(textContent); + + SVGStylable field = (SVGStylable) element; + CSSStyleDeclaration style = field.getStyle(); + + String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); + style.setProperty("fill", computed ? computedColor : "#000000", null); + style.setProperty("font-style", computed ? "italic" : "normal", null); + + SVGOMTextElement textElem = (SVGOMTextElement) element; + bbox = textElem.getBBox(); + if (bbox != null) { + float width = bbox.getWidth() + 20; + rectElement.setAttribute("width", Float.toString(width)); + element.setAttribute("x", String.valueOf(x + width / 2)); + } + + Element labelElement = svgDocument.getElementById(id + "Label"); + Element labelRectElement = svgDocument.getElementById(id + "LabelRect"); + SVGOMTextElement labelTextElem = (SVGOMTextElement) labelElement; + bbox = labelTextElem.getBBox(); + float width = bbox.getWidth() + 20; + labelRectElement.setAttribute("width", Float.toString(width)); + labelRectElement.setAttribute("x", String.valueOf(x - width)); + labelElement.setAttribute("x", String.valueOf(x - width / 2)); + } + }); + } } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.