branch feature/8146 created (now ebea8ee)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8146 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git at ebea8ee l'arrondi du poids rendait le poids négatif positif... d'où le poids total qui ne faisait qu'augmenter (fixes #8146) This branch includes the following new commits: new ebea8ee l'arrondi du poids rendait le poids négatif positif... d'où le poids total qui ne faisait qu'augmenter (fixes #8146) The 1 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 ebea8ee3d46616df08af526fc84df1fa16e2ba20 Author: Kevin Morin <morin@codelutin.com> Date: Fri Mar 25 16:38:58 2016 +0100 l'arrondi du poids rendait le poids négatif positif... d'où le poids total qui ne faisait qu'augmenter (fixes #8146) -- 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 feature/8146 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit ebea8ee3d46616df08af526fc84df1fa16e2ba20 Author: Kevin Morin <morin@codelutin.com> Date: Fri Mar 25 16:38:58 2016 +0100 l'arrondi du poids rendait le poids négatif positif... d'où le poids total qui ne faisait qu'augmenter (fixes #8146) --- .../main/java/fr/ifremer/tutti/util/Weights.java | 4 +++ .../frequency/SpeciesFrequencyRowModel.java | 23 +++++++++++++--- .../frequency/SpeciesFrequencyTableModel.java | 31 +++++++++++----------- .../frequency/SpeciesFrequencyUIHandler.java | 24 ++++++++++------- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java index 97d6fa1..a7ccee6 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java @@ -112,6 +112,10 @@ public class Weights { return compareWeights(v0, v1) > 0; } + public static boolean isPositive(float weight) { + return compareRawWeights(weight, 0.0f) >= 0; + } + public static boolean isEqualWeight(float v0, float v1) { return compareWeights(v0, v1) == 0; } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java index fed3d13..cf3d7d1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java @@ -235,15 +235,32 @@ public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBa } /** - * @param weightToAdd weight (can be negative) to add + * @param weightToAdd weight (cannot be negative) to add */ public void addToWeight(float weightToAdd) { + if (!Weights.isPositive(weightToAdd)) { + throw new IllegalArgumentException("you must add a positive weight"); + } + if (weight == null) { + weight = 0f; + } + setWeight(weightUnit.round(weight + weightToAdd)); + } + + /** + * @param weightToRemove weight (cannot be negative) to remove + */ + public void removeFromWeight(float weightToRemove) { + if (!Weights.isPositive(weightToRemove)) { + throw new IllegalArgumentException("you must remove a positive weight"); + } if (weight == null) { weight = 0f; } - if (weight + weightToAdd >= 0) { - setWeight(weight + weightToAdd); + if (Weights.isSmallerWeight(weight, weightToRemove)) { + throw new IllegalArgumentException("the weight to remove cannot be greater than the weight"); } + setWeight(weightUnit.round(weight - weightToRemove)); } public Float getRtpComputedWeight() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java index ae179fa..9ac8b4a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java @@ -265,12 +265,8 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (oldValue != null) { modelCache.removeLengthStep(oldValue); - if (frequenciesSeries.indexOf(oldValue) >= 0) { - frequenciesSeries.remove(oldValue); - } - if (averageWeightsSeries.indexOf(oldValue) >= 0) { - averageWeightsSeries.remove(oldValue); - } + removeLengthStepFromSeries(frequenciesSeries, oldValue); + removeLengthStepFromSeries(averageWeightsSeries, oldValue); } @@ -322,13 +318,8 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (!row.withNumber()) { // remove the value for the lengthStep - if (frequenciesSeries.indexOf(lengthStep) >= 0) { - frequenciesSeries.remove(lengthStep); - } - - if (averageWeightsSeries.indexOf(lengthStep) >= 0) { - averageWeightsSeries.remove(lengthStep); - } + removeLengthStepFromSeries(frequenciesSeries, lengthStep); + removeLengthStepFromSeries(averageWeightsSeries, lengthStep); } else { @@ -371,9 +362,7 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (!row.withWeight()) { // remove the value for the lengthStep - if (averageWeightsSeries.indexOf(lengthStep) >= 0) { - averageWeightsSeries.remove(lengthStep); - } + removeLengthStepFromSeries(averageWeightsSeries, lengthStep); } else { @@ -396,6 +385,16 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp return onWeightChangedListener; } + private void removeLengthStepFromSeries(XYSeries series, Float lengthStep) { + if (series.indexOf(lengthStep) >= 0) { + if (series.getItemCount() > 1) { + series.remove(lengthStep); + } else { + series.clear(); + } + } + } + private void dettachListeners(SpeciesFrequencyRowModel result) { result.removePropertyChangeListener(SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, getOnLengthStepChangedListener()); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index 7c5dde2..69b5dc2 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -47,12 +47,8 @@ import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchTableModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellRenderer; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellEditor; -import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; -import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; -import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchTableModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellRenderer; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchRowModel; @@ -1016,8 +1012,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } - if (log.isInfoEnabled()) { - log.info("CopyIndividualObservationMode: " + copyIndividualObservationMode); + if (log.isDebugEnabled()) { + log.debug("copy individual observation mode : " + copyIndividualObservationMode); } SpeciesBatchRowModel previousSiblingRow = frequencyEditor.getPreviousSiblingRow(); @@ -1113,6 +1109,9 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci model.computeRowWeightWithRtp(); + model.recomputeIndividualObservationRowsValidateState(); + model.recomputeRowsValidateState(); + if (getContext().isIchtyometerConnected()) { // let's listen the ichtyometer @@ -1202,9 +1201,16 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci lengthStep = getModel().getLengthStep(lengthStep); SpeciesFrequencyRowModel row = getRowForLengthstep(lengthStep); + + boolean addToWeight = Weights.isPositive(weight); // conversion de poids - weight = weightUnit.convertWeight(weight, getConfig().getIndividualObservationWeightUnit()); - row.addToWeight(weight); + // convertWeight retourne toujours un positif pour l'instant, mais mieux vaut se prémunir d'un changement futur + weight = Math.abs(weightUnit.convertWeight(weight, getConfig().getIndividualObservationWeightUnit())); + if (addToWeight) { + row.addToWeight(weight); + } else { + row.removeFromWeight(weight); + } if (Weights.isNullOrZero(row.getWeight())) { int rowIndex = tableModel.getRowIndex(row); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm