branch develop updated (189b50d -> 28d0af6)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from 189b50d fix dependencies new 328fd81 add getDataorComputedData method new 28d0af6 clean code The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 28d0af68387634edf2ca8c99b8422f9526bc3777 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 20 11:51:52 2015 +0100 clean code commit 328fd819b48329e577f96210633635a5889c5ccb Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 20 11:37:16 2015 +0100 add getDataorComputedData method Summary of changes: .../operation/catches/EditCatchesUIHandler.java | 134 +++++++++++++-------- .../ui/swing/util/computable/ComputableData.java | 5 + 2 files changed, 88 insertions(+), 51 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 328fd819b48329e577f96210633635a5889c5ccb Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 20 11:37:16 2015 +0100 add getDataorComputedData method --- .../fr/ifremer/tutti/ui/swing/util/computable/ComputableData.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableData.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableData.java index d06a411..6f878b1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableData.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableData.java @@ -22,6 +22,7 @@ package fr.ifremer.tutti.ui.swing.util.computable; * #L% */ +import fr.ifremer.tutti.util.Numbers; import org.jdesktop.beans.AbstractSerializableBean; import org.nuiton.jaxx.application.listener.PropagatePropertyChangeListener; @@ -74,6 +75,10 @@ public class ComputableData<N extends Number> extends AbstractSerializableBean { firePropertyChange(PROPERTY_COMPUTED_DATA, oldValue, computedData); } + public N getDataOrComputedData() { + return Numbers.getValueOrComputedValue(data, computedData); + } + @Override public String toString() { String result = null; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 28d0af68387634edf2ca8c99b8422f9526bc3777 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 20 11:51:52 2015 +0100 clean code --- .../operation/catches/EditCatchesUIHandler.java | 134 +++++++++++++-------- 1 file changed, 83 insertions(+), 51 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 6e8ac0a..476c3b0 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 @@ -28,7 +28,6 @@ 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.ui.swing.util.computable.ComputableDataEditor; import fr.ifremer.tutti.util.Weights; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; @@ -44,19 +43,10 @@ import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.validator.swing.SwingValidator; -import org.apache.batik.bridge.BridgeContext; -import org.apache.batik.bridge.DocumentLoader; -import org.apache.batik.bridge.GVTBuilder; -import org.apache.batik.bridge.UpdateManagerAdapter; -import org.apache.batik.bridge.UserAgent; -import org.apache.batik.bridge.UserAgentAdapter; 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.gvt.GraphicsNode; import org.apache.batik.swing.JSVGCanvas; -import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter; -import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -68,7 +58,6 @@ 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.SVGRect; import org.w3c.dom.svg.SVGStylable; @@ -76,12 +65,11 @@ import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import java.net.URL; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.n; @@ -288,43 +276,21 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi Element labelElement = svgDocument.getElementById(property + "Label"); labelElement.setTextContent(t("tutti.editCatchBatch.field." + property)); - if (computableData != null) { + if (computableData == null) { + + // computed data value + + getModel().addPropertyChangeListener(property, new OnComputedDataValueChangedListener(property, weightUnit)); + } else { + + // data or computed data value + Element element = svgDocument.getElementById(property); EventTarget target = (EventTarget) element; - target.addEventListener("click", - new EventListener() { - public void handleEvent(org.w3c.dom.events.Event evt) { - log.info("element clicked"); - EnterWeightUI dialog = new EnterWeightUI(getContext()); - Float weight = dialog.openAndGetWeightValue(t("tutti.editCatchBatch.field." + property), - computableData.getData(), - weightUnit); - computableData.setData(weight); - } - }, false); - - computableData.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - ComputableData<Float> computableData = (ComputableData<Float>) evt.getSource(); - - if (computableData.getData() != null) { - updateValue(property, computableData.getData(), weightUnit, false); - - } else { - updateValue(property, computableData.getComputedData(), weightUnit, true); - } - } - }); + target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); + + computableData.addPropertyChangeListener(new OnDataOrComputedDataValueChangedListener(property, weightUnit)); - } else { - getModel().addPropertyChangeListener(property, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Float data = (Float) evt.getNewValue(); - updateValue(property, data, weightUnit, true); - } - }); } } @@ -344,7 +310,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi Element rectElement = svgDocument.getElementById(id + "Rect"); SVGOMRectElement rectElem = (SVGOMRectElement) rectElement; SVGRect bbox = rectElem.getBBox(); - Float x = Float.valueOf(bbox.getX()); + Float x = bbox.getX(); //TODO i18n ? String textContent; @@ -359,7 +325,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi CSSStyleDeclaration style = field.getStyle(); Color colorComputedWeights = getConfig().getColorComputedWeights(); - String computedColor = "#"+Integer.toHexString(colorComputedWeights.getRGB()).substring(2); + String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); style.setProperty("fill", computed ? computedColor : "#000000", null); style.setProperty("font-style", computed ? "italic" : "normal", null); @@ -367,7 +333,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi bbox = textElem.getBBox(); if (bbox != null) { float width = bbox.getWidth() + 20; - rectElement.setAttribute("width", new Float(width).toString()); + rectElement.setAttribute("width", Float.toString(width)); element.setAttribute("x", String.valueOf(x + width / 2)); } @@ -376,11 +342,12 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi SVGOMTextElement labelTextElem = (SVGOMTextElement) labelElement; bbox = labelTextElem.getBBox(); float width = bbox.getWidth() + 20; - labelRectElement.setAttribute("width", new Float(width).toString()); + labelRectElement.setAttribute("width", Float.toString(width)); labelRectElement.setAttribute("x", String.valueOf(x - width)); labelElement.setAttribute("x", String.valueOf(x - width / 2)); } }); + } public void closeAttachments() { @@ -897,4 +864,69 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } return result; } + + private class OnValueClickListener implements EventListener { + + private final ComputableData<Float> computableData; + + private final String property; + + private final WeightUnit weightUnit; + + public OnValueClickListener(ComputableData<Float> computableData, String property, WeightUnit weightUnit) { + this.computableData = computableData; + this.property = property; + this.weightUnit = weightUnit; + } + + public void handleEvent(org.w3c.dom.events.Event evt) { + log.info("element clicked"); + EnterWeightUI dialog = new EnterWeightUI(getContext()); + Float originalWeight = computableData.getData(); + Float weight = dialog.openAndGetWeightValue(t("tutti.editCatchBatch.field." + property), + originalWeight, + weightUnit); + + if (!Objects.equals(originalWeight, weight)) { + + computableData.setData(weight); + } + } + } + + private class OnDataOrComputedDataValueChangedListener implements PropertyChangeListener { + + private final String property; + + private final WeightUnit weightUnit; + + public OnDataOrComputedDataValueChangedListener(String property, WeightUnit weightUnit) { + this.property = property; + this.weightUnit = weightUnit; + } + + @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; + + private final WeightUnit weightUnit; + + 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); + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm