r460 - trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common
Author: chatellier Date: 2011-01-04 17:25:09 +0000 (Tue, 04 Jan 2011) New Revision: 460 Log: Utilisation des filtres de nuiton matrix pour avoir de la coh?\195?\169rence entre le graphique et les donn?\195?\169es Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixFilter.java Removed: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java 2011-01-03 16:20:32 UTC (rev 459) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/DataHandler.java 2011-01-04 17:25:09 UTC (rev 460) @@ -32,6 +32,7 @@ import org.nuiton.math.matrix.MatrixND; import org.nuiton.math.matrix.viewer.MatrixViewerPanel; +import org.nuiton.math.matrix.viewer.renderer.MatrixChartRenderer; import org.nuiton.math.matrix.viewer.renderer.MatrixInfoTableRenderer; import org.nuiton.widget.SwingSession; @@ -73,8 +74,9 @@ JFrame matrixViewerFrame = new JFrame(_("coser.ui.graph.lengthStructure")); matrixViewerFrame.setName("lengthstructureframe"); MatrixViewerPanel panel = new MatrixViewerPanel(); - panel.addMatrixRenderer(new LengthStructureMatrixRenderer(project, container)); + panel.addMatrixRenderer(new MatrixChartRenderer()); panel.addMatrixRenderer(new MatrixInfoTableRenderer()); + panel.addMatrixFilter(new LengthStructureMatrixFilter(project, container)); panel.addMatrix(matrix); matrixViewerFrame.add(panel); matrixViewerFrame.pack(); Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixFilter.java (from rev 421, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixFilter.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixFilter.java 2011-01-04 17:25:09 UTC (rev 460) @@ -0,0 +1,127 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.common; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.util.Log; +import org.nuiton.math.matrix.MatrixFactory; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.viewer.MatrixFilter; + +import fr.ifremer.coser.bean.AbstractDataContainer; +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.Selection; + +/** + * Filtre qui ajoute les trou dans les données (valeur intermédiares absentes) + * et qui supprime les bornes sans valeures ensuite. + * + * Modifie egalement le titre de la matrice. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LengthStructureMatrixFilter implements MatrixFilter { + + protected Project project; + + protected AbstractDataContainer container; + + public LengthStructureMatrixFilter(Project project, AbstractDataContainer container) { + this.project = project; + this.container = container; + } + + @Override + public MatrixND filter(MatrixND matrix) { + + // modifie le titre de la matrice + String title = "Coser: " + project.getName(); + if (container instanceof Selection) { + title += ": " + ((Selection)container).getName(); + } + matrix.setName(title); + + MatrixND filteredMatrix = matrix; + + String semantic0Name = matrix.getDimensionName(0); + if ("coser.business.common.length".equals(semantic0Name)) { + + List<?> semantic0 = matrix.getSemantic(0); + double first = (Double)matrix.getSemantic(0).get(0); + double last = (Double)matrix.getSemantic(0).get(matrix.getSemantic(0).size() - 1); + + // on cherche les bornes qui ont des valeurs sup à 0.0 + // sinon, ya du vide autour des choses demandées + // mais le vide entre est requis (trou de données) + for (Object categorySem : matrix.getSemantic(0)) { + for (Object serieSem : matrix.getSemantic(1)) { + Double value = matrix.getValue(new Object[] { categorySem, serieSem }); + if (value > 0.0) { + double category = (Double)categorySem; + if (first > category) { + first = category; + } + if (last < category) { + last = category; + } + } + } + } + + // on verifie toutes les valeurs pour savoir si c'est un + // pas entier ou un demi pas + boolean haltStep = false; + for (Object number : semantic0) { + double dNumber = (Double)number; + if (dNumber - Math.floor(dNumber) > 0) { + haltStep = true; + break; + } + } + + List<Double> newLengthSemantic = new ArrayList<Double>(); + for (double index = first ; index <= last ; index += (haltStep) ? 0.5 : 1) { + newLengthSemantic.add(index); + } + + // nouvelle matrix remplit avec des zero + // avec la nouvelle semantique pour les tailles + List<?>[] semantics = new List<?>[matrix.getSemantics().length]; + semantics[0] = newLengthSemantic; + System.arraycopy(matrix.getSemantics(), 1, semantics, 1, matrix.getSemantics().length - 1); + filteredMatrix = MatrixFactory.getInstance().create(matrix.getName(), semantics); + + // copy des elements en fonction des semantiques + filteredMatrix.pasteSemantics(matrix); + } + + return filteredMatrix; + } +} Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java 2011-01-03 16:20:32 UTC (rev 459) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/common/LengthStructureMatrixRenderer.java 2011-01-04 17:25:09 UTC (rev 460) @@ -1,144 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.common; - -import static org.nuiton.i18n.I18n._; - -import java.util.List; - -import org.jfree.chart.JFreeChart; -import org.jfree.data.category.CategoryDataset; -import org.jfree.data.category.DefaultCategoryDataset; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.viewer.renderer.MatrixChartRenderer; -import org.nuiton.math.matrix.viewer.renderer.jfreechart.GraphMatrixNDDataset; - -import fr.ifremer.coser.bean.AbstractDataContainer; -import fr.ifremer.coser.bean.Project; -import fr.ifremer.coser.bean.Selection; - -/** - * JFreeChart matrix panel renderer. - * - * Only redefine {@link #getCategoryDataset(MatrixND)} because in coser, we need to - * generate graph with missing value. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class LengthStructureMatrixRenderer extends MatrixChartRenderer { - - protected Project project; - - protected AbstractDataContainer container; - - public LengthStructureMatrixRenderer(Project project, AbstractDataContainer container) { - this.project = project; - this.container = container; - } - - /** - * Pour modification du titre du graphique. - * - * Coser : projecttitle : selectiontitle - */ - protected JFreeChart getJFreeChart(MatrixND matrix) { - String title = "Coser: " + project.getName(); - if (container instanceof Selection) { - title += ": " + ((Selection)container).getName(); - } - JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, - getCategoryPlot(matrix), true); - return chart; - } - - @Override - protected CategoryDataset getCategoryDataset(MatrixND matrix) { - return getLengthStructureDataSet(matrix); - } - - protected CategoryDataset getLengthStructureDataSet(MatrixND matrix) { - CategoryDataset dataset = null; - - String semantic0Name = matrix.getDimensionName(0); - if ("coser.business.common.length".equals(semantic0Name)) { - DefaultCategoryDataset defaultDataset = new DefaultCategoryDataset(); - List<?> semantic0 = matrix.getSemantic(0); - double first = Double.MAX_VALUE; - double last = Double.MIN_VALUE; - - // on cherche les bornes qui ont des valeurs sup à 0.0 - // sinon, ya du vide autour des choses demandées - // mais le vide entre est requis (trou de données) - for (Object categorySem : matrix.getSemantic(0)) { - for (Object serieSem : matrix.getSemantic(1)) { - Double value = matrix.getValue(new Object[] { categorySem, serieSem }); - if (value > 0.0) { - double category = (Double)categorySem; - if (first > category) { - first = category; - } - if (last < category) { - last = category; - } - } - } - } - - // on verifie toutes les valeurs pour savoir si c'est un - // pas entier ou un demi pas - boolean haltStep = false; - for (Object number : semantic0) { - double dNumber = (Double)number; - if (dNumber - Math.floor(dNumber) > 0) { - haltStep = true; - break; - } - } - - for (double index = first ; index <= last ; index += (haltStep) ? 0.5 : 1) { - - for (Object serieSem : matrix.getSemantic(1)) { - Double value = null; - - // il n'y a pas de valeur dans la matrices - // pour les pas intermédiaires ajouté - if (semantic0.contains(index)) { - value = matrix.getValue(new Object[] { index, serieSem }); - } - - defaultDataset.setValue((Number)value, (Comparable)serieSem, (Comparable)index); - } - } - dataset = defaultDataset; - } - else { - dataset = new GraphMatrixNDDataset(matrix); - } - return dataset; - } -}
participants (1)
-
chatellier@users.labs.libre-entreprise.org