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 cc2d9e42549a60430bb77026bcf5921bdebd85fc Author: Kevin Morin <morin@codelutin.com> Date: Tue Nov 25 17:17:23 2014 +0100 fixes #6094 [CAPTURE] adapter le pas de l'axe des x "classe de taille" au pas de la classe de taille. Si 1 aller de 1 en 1, si 0.5 alller de 0.5 en 0.5 --- .../frequency/BenthosFrequencyUIHandler.java | 27 ++- .../frequency/SpeciesFrequencyUIHandler.java | 29 ++- .../ui/swing/util/TuttiNumberTickUnitSource.java | 205 +++++++++++++++++++++ 3 files changed, 251 insertions(+), 10 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java index f7b6eea..f309781 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java @@ -25,12 +25,15 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import fr.ifremer.tutti.ui.swing.util.TuttiNumberTickUnitSource; import fr.ifremer.tutti.util.Numbers; import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberTickUnitSource; +import org.jfree.chart.axis.ValueAxis; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.nuiton.jaxx.application.swing.util.Cancelable; @@ -89,6 +92,8 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth private XYSeriesCollection dataset; + private JFreeChart chart; + /** * Weight unit. * @@ -288,6 +293,8 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth // get step from the pmfm float step = getStep(newValue); getModel().setStep(step); + dataset.setIntervalWidth(step); + chart.getXYPlot().getDomainAxis().setStandardTickUnits(new TuttiNumberTickUnitSource(step == 1f)); if (CollectionUtils.isNotEmpty(getModel().getRows())) { for (BenthosFrequencyRowModel rowModel : getModel().getRows()) { rowModel.setLengthStepCaracteristic(newValue); @@ -928,12 +935,22 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth dataset.setIntervalPositionFactor(0); dataset.setIntervalWidth(step); - JFreeChart chart = ChartFactory.createXYBarChart(null, - t("tutti.editSpeciesFrequencies.table.header.lengthStep"), - false, - t("tutti.editSpeciesFrequencies.table.header.number"), - dataset); + chart = ChartFactory.createXYBarChart(null, + t("tutti.editSpeciesFrequencies.table.header.lengthStep"), + false, + t("tutti.editSpeciesFrequencies.table.header.number"), + dataset); chart.clearSubtitles(); + + ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); + rangeAxis.setAutoRange(true); + rangeAxis.setStandardTickUnits(new NumberTickUnitSource(true)); + + ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); + domainAxis.setAutoRange(true); + domainAxis.setStandardTickUnits(new TuttiNumberTickUnitSource(true)); + domainAxis.setMinorTickMarksVisible(true); + chart.getXYPlot().getRenderer().setSeriesPaint(0, getConfig().getColorComputedWeights()); final ChartPanel chartPanel = new ChartPanel(chart); 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 2c264ee..ab0d1d3 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 @@ -42,6 +42,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.Ben import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyCellComponent.FrequencyCellEditor; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.TuttiNumberTickUnitSource; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; @@ -58,6 +59,11 @@ import org.jdesktop.swingx.table.DefaultTableColumnModelExt; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberTickUnitSource; +import org.jfree.chart.axis.TickUnitSource; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.nuiton.jaxx.application.ApplicationBusinessException; @@ -96,6 +102,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci private XYSeriesCollection dataset; + private JFreeChart chart; + /** * Weight unit. * @@ -337,6 +345,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci float step = getStep(newValue); getModel().setStep(step); dataset.setIntervalWidth(step); + chart.getXYPlot().getDomainAxis().setStandardTickUnits(new TuttiNumberTickUnitSource(step == 1f)); if (CollectionUtils.isNotEmpty(getModel().getRows())) { for (SpeciesFrequencyRowModel rowModel : getModel().getRows()) { rowModel.setLengthStepCaracteristic(newValue); @@ -1044,12 +1053,22 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci dataset.setIntervalPositionFactor(0); dataset.setIntervalWidth(step); - JFreeChart chart = ChartFactory.createXYBarChart(null, - t("tutti.editSpeciesFrequencies.table.header.lengthStep"), - false, - t("tutti.editSpeciesFrequencies.table.header.number"), - dataset); + chart = ChartFactory.createXYBarChart(null, + t("tutti.editSpeciesFrequencies.table.header.lengthStep"), + false, + t("tutti.editSpeciesFrequencies.table.header.number"), + dataset); chart.clearSubtitles(); + + ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); + rangeAxis.setAutoRange(true); + rangeAxis.setStandardTickUnits(new NumberTickUnitSource(true)); + + ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); + domainAxis.setAutoRange(true); + domainAxis.setStandardTickUnits(new TuttiNumberTickUnitSource(true)); + domainAxis.setMinorTickMarksVisible(true); + chart.getXYPlot().getRenderer().setSeriesPaint(0, getConfig().getColorComputedWeights()); final ChartPanel chartPanel = new ChartPanel(chart); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiNumberTickUnitSource.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiNumberTickUnitSource.java new file mode 100644 index 0000000..b33dd09 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiNumberTickUnitSource.java @@ -0,0 +1,205 @@ +package fr.ifremer.tutti.ui.swing.util; + +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners.] + * + * ------------------------- + * NumberTickUnitSource.java + * ------------------------- + * (C) Copyright 2014, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 18-Mar-2014 : Version 1 (DG); + * + */ + +import org.jfree.chart.axis.NumberTickUnit; +import org.jfree.chart.axis.TickUnit; +import org.jfree.chart.axis.TickUnitSource; +import org.jfree.util.ObjectUtilities; + +import java.io.Serializable; +import java.text.DecimalFormat; +import java.text.NumberFormat; + +/** + * TickUnitSource for the frequency chart + * + * @author Kevin Morin (Code Lutin) + * @since 3.10 + */ +public class TuttiNumberTickUnitSource implements TickUnitSource, Serializable { + + private boolean integers; + + private int power = 0; + + private int factor = 1; + + /** + * Creates a new instance. + * + * @param integers show integers only. + */ + public TuttiNumberTickUnitSource(boolean integers) { + + this.integers = integers; + this.power = 0; + this.factor = 1; + } + + @Override + public TickUnit getLargerTickUnit(TickUnit unit) { + TickUnit t = getCeilingTickUnit(unit); + if (t.equals(unit)) { + next(); + t = new NumberTickUnit(getTickSize(), getTickLabelFormat(), + getMinorTickCount()); + } + return t; + } + + @Override + public TickUnit getCeilingTickUnit(TickUnit unit) { + return getCeilingTickUnit(unit.getSize()); + } + + @Override + public TickUnit getCeilingTickUnit(double size) { + if (Double.isInfinite(size)) { + throw new IllegalArgumentException("Must be finite."); + } + this.power = (int) Math.ceil(Math.log10(size)); + if (this.integers) { + power = Math.max(this.power, 0); + } + this.factor = 1; + boolean done = false; + // step down in size until the current size is too small or there are + // no more units + while (!done) { + done = !previous(); + if (getTickSize() < size) { + next(); + done = true; + } + } + return new NumberTickUnit(getTickSize(), getTickLabelFormat(), + getMinorTickCount()); + } + + private boolean next() { + if (factor == 1) { + factor = 5; + return true; + } + if (factor == 5) { + if (power == 300) { + return false; + } + power++; + factor = 1; + return true; + } + throw new IllegalStateException("We should never get here."); + } + + private boolean previous() { + if (factor == 1) { + if (this.integers && power == 0 || power == -1) { + return false; + } + factor = 5; + power--; + return true; + } + if (factor == 5) { + factor = 1; + return true; + } + throw new IllegalStateException("We should never get here."); + } + + private double getTickSize() { + return this.factor * Math.pow(10.0, this.power); + } + + private DecimalFormat dfNeg4 = new DecimalFormat("0.0000"); + private DecimalFormat dfNeg3 = new DecimalFormat("0.000"); + private DecimalFormat dfNeg2 = new DecimalFormat("0.00"); + private DecimalFormat dfNeg1 = new DecimalFormat("0.0"); + private DecimalFormat df0 = new DecimalFormat("#,##0"); + private DecimalFormat df = new DecimalFormat("#.######E0"); + + private NumberFormat getTickLabelFormat() { + if (power == -4) { + return dfNeg4; + } + if (power == -3) { + return dfNeg3; + } + if (power == -2) { + return dfNeg2; + } + if (power == -1) { + return dfNeg1; + } + if (power >= 0 && power <= 6) { + return df0; + } + return df; + } + + private int getMinorTickCount() { + return (int) (getTickSize() * (integers ? 1 : 2)); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof TuttiNumberTickUnitSource)) { + return false; + } + TuttiNumberTickUnitSource that = (TuttiNumberTickUnitSource) obj; + if (this.integers != that.integers) { + return false; + } + if (this.power != that.power) { + return false; + } + if (this.factor != that.factor) { + return false; + } + return true; + } +} + -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.