r292 - in trunk/src: main/java/org/nuiton/math/matrix main/java/org/nuiton/math/matrix/viewer main/java/org/nuiton/math/matrix/viewer/renderer main/resources main/resources/i18n main/resources/icons test/java/org/nuiton/math/matrix test/java/org/nuiton/math/matrix/viewer
Author: echatellier Date: 2010-12-08 12:13:06 +0100 (Wed, 08 Dec 2010) New Revision: 292 Url: http://nuiton.org/repositories/revision/nuiton-matrix/292 Log: Viewer component : first draft Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/ trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRendererSolution.java trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/ trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java trunk/src/main/resources/icons/ trunk/src/main/resources/icons/1rightarrow.png trunk/src/main/resources/icons/sigma-barre.gif trunk/src/main/resources/icons/sigma.gif trunk/src/main/resources/icons/table.png trunk/src/test/java/org/nuiton/math/matrix/viewer/ trunk/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java Modified: trunk/src/main/resources/i18n/nuiton-matrix_en_GB.properties trunk/src/main/resources/i18n/nuiton-matrix_fr_FR.properties Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,287 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer; + +import static org.nuiton.i18n.I18n._; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JToggleButton; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.AbstractMatrixND; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.util.Resource; + +/** + * Panel d'affichage des dimensions. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixDimensionPanel extends JPanel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -1919447532660452240L; + + /** Class logger. */ + private static Log log = LogFactory.getLog(AbstractMatrixND.class); + + /** Matrix to display (original). */ + protected MatrixND matrix; + + protected List<SubDimensionPanel> subPanelList; + + public MatrixDimensionPanel() { + setLayout(new GridLayout(0, 1)); + subPanelList = new ArrayList<MatrixDimensionPanel.SubDimensionPanel>(); + } + + public MatrixND getMatrix() { + return matrix; + } + + public void setMatrix(MatrixND matrix) { + this.matrix = matrix; + + buildDimensionPanel(); + validate(); + repaint(); + } + + public MatrixND getModifiedMatrix() { + MatrixND reducedMatrix = createAndReduce(matrix); + return reducedMatrix; + } + + protected static class SubDimensionPanel extends JPanel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 9170588695850504050L; + + protected String semanticName; + + protected List<?> semantic; + + protected JToggleButton sumAll; + + protected JList semList; + + public SubDimensionPanel(String semanticName, List<?> semantic) { + super(new GridBagLayout()); + this.semanticName = semanticName; + this.semantic = semantic; + renderSubPanel(); + } + + protected void renderSubPanel() { + // semantic name + JLabel semName = new JLabel(semanticName); + add(semName, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, + GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + + // sum all button + sumAll = new JToggleButton(Resource.getIcon("/icons/sigma-barre.gif")); + sumAll.setSelectedIcon(Resource.getIcon("/icons/sigma.gif")); + add(sumAll, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, + GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + + // semantic list + semList = new JList(); + SemanticListModel semModel = new SemanticListModel(semantic); + semList.setModel(semModel); + add(new JScrollPane(semList), new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.WEST, + GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0)); + } + + public JList getList() { + return semList; + } + + /** + * Method getSumStep indique le pas d'increment pour la somme sur + * la dimension. + * + * @return -1 indique de faire la somme sur tous les elmements. 1 + * indique de faire la somme 1 a 1 (donc de ne pas faire de + * somme), 2 indiques de faire la somme 2 a 2, ... + */ + public int getSumStep() { + int result = 1; + if (sumAll.isSelected()) { + result = -1; + } + return result; + } + } + + /** + * Build dimension panel. + */ + protected void buildDimensionPanel() { + subPanelList.clear(); + removeAll(); + + if (matrix != null) { + int index = 0; + for (List<?> semantic : matrix.getSemantics()) { + SubDimensionPanel dimPanel = new SubDimensionPanel(_(matrix.getDimensionName(index)), semantic); + add(dimPanel); + subPanelList.add(dimPanel); + index++; + } + } + } + + public static class SemanticListModel extends DefaultListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4384624824457446070L; + + protected List<?> semantic; + + public SemanticListModel(List<?> semantic) { + this.semantic = semantic; + } + + @Override + public int getSize() { + return semantic.size(); + } + + @Override + public Object getElementAt(int index) { + return semantic.get(index); + } + } + + protected MatrixND createAndReduce(MatrixND matrix) { + + // Reduit la matrice en fonction des choix de l utilisateur + // dans les autres InfoItem recuperation des autres elements + // selectionnees. + for (int i = 0; i < subPanelList.size(); i++) { + SubDimensionPanel subDimPanel = subPanelList.get(i); + JList list = subDimPanel.getList(); + int [] indList = list.getSelectedIndices(); + + if (indList.length == 0) { + // si rien n'est selectionné on selectionne tout + list.setSelectionInterval(0, list.getModel().getSize()-1); + indList = list.getSelectedIndices(); + } + + if (log.isDebugEnabled()) { + log.debug("matrice avant submatrice de la dim " + i + ": " + matrix); + } + + if (0 < indList.length && indList.length < matrix.getDim(i)) { + matrix = matrix.getSubMatrix(i, indList); + } + + if (log.isDebugEnabled()) { + log.debug("matrice apres submatrice de la dim " + i + ": " + matrix); + } + + if (subDimPanel.getSumStep() != 1) { + // on somme + matrix = matrix.sumOverDim(i, subDimPanel.getSumStep()); + if (matrix.getDim(i) == 1) { + // c une somme global sur tous les elements + matrix.setDimensionName(i, _("nuitonmatrix.viewer.sum")); + } else { + // c une somme partielle + String name = matrix.getDimensionName(i) + " " + _("nuitonmatrix.viewer.sum"); + + /* FIXME echatellier somme par autre interval que -1 + //si c une somme pour les annees, on change l'intitule + if (item instanceof InfoItemDate){ + name = _ ("isisfish.common.year"); + }*/ + + matrix.setDimensionName(i, name); + } + + /* FIXME echatellier somme par autre interval que -1 + // #1905 : modifie les semantiques de type Date pour que lorsque + // c'est par exemple une somme par année + // les semantique se nomment + // janvier 0, janvier 1... + // plutot que + // janvier 0, fevrier 0... + Object sem = matrix.getSemantics(i); + if (sem instanceof List) { + List<Object> semList = (List<Object>)sem; + List<Object> newList = new ArrayList<Object>(); + for (int index = 0 ; index < semList.size(); ++index) { + Object semObject = semList.get(index); + if (semObject instanceof Date) { + Date semDate = (Date)semObject; + Date newDate = new Date(semDate.getDate() * item.getSumStep()); + newList.add(newDate); + } + else { + newList.add(semObject); + } + } + matrix.setSemantics(i, newList); + } + // end semantics modification */ + } + + if (log.isDebugEnabled()) { + log.debug("matrice apres sum de la dim " + i + ": " + matrix); + } + } + + if (log.isDebugEnabled()) { + log.debug("Matrice avant le reduce: " + matrix); + } + + // arrive ici on a une matrice qui a des tailles de dimension 1 + // et un tableau des legende pour chaque dimension + + // il faut que la matrice est 2 dimensions + // reduction de la matrice + MatrixND result = matrix.reduce(2); + + return result; + } +} Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,66 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer; + +import java.awt.Component; + +import javax.swing.Icon; + +import org.nuiton.math.matrix.MatrixND; + +/** + * Matrix renderer plugin interface. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface MatrixRenderer { + + /** + * Renderer panel for matrix. + * + * @param matrix matrix to display + * @return component + */ + Component getPanel(MatrixND matrix); + + /** + * Renderer icon (used in {@link MatrixRendererSolution#ICON} rendering). + * + * @return plugin icon + */ + Icon getIcon(); + + /** + * Renderer name (used in {@link MatrixRendererSolution#RADIO_BUTTON} rendering). + * + * @return plugin name + */ + String getName(); +} Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRendererSolution.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRendererSolution.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRendererSolution.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,44 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer; + +/** + * Matrix renderer list solution. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public enum MatrixRendererSolution { + + /** Renderering with icons. */ + ICON, + + /** Renderering with radion button. */ + RADIO_BUTTON +} Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixRendererSolution.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,392 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer; + +import static org.nuiton.i18n.I18n._; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ButtonGroup; +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JSplitPane; +import javax.swing.JToggleButton.ToggleButtonModel; + +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.util.Resource; + +/** + * Panel that can display matrix list details (dimension) and rendering solutions. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixViewerPanel extends JPanel implements ActionListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = -5447856858278176837L; + + public static final String PROPERTY_MATRIX_COMBO_VISIBLE = "matrixComboVisible"; + + public static final String PROPERTY_MATRIX_RENDERER_SOLUTION = "matrixRendererSolution"; + + public static final String PROPERTY_MATRIX_RENDERERS = "matrixRenderers"; + + public static final String PROPERTY_MATRICES = "matrices"; + + /** Matrix list combo visibility (defaut to false). */ + protected boolean matrixComboVisible; + + /** Matrix renderer list solution. (default to {@link MatrixRendererSolution#RADIO_BUTTON} */ + protected MatrixRendererSolution matrixRendererSolution = MatrixRendererSolution.RADIO_BUTTON; + + /** Matrix renderer plugins. */ + protected List<MatrixRenderer> matrixRenderers; + + /** Matrices to render (depend on {@link #matrixComboVisible} to {@code true}). */ + protected List<MatrixND> matrices; + + /** Matrix list combo box. */ + protected MatrixComboBox matrixComboBox; + + protected MatrixDimensionPanel dimensionPanel; + + protected RadioButtonRenderingPanel radioPanel; + + protected JPanel renderingComponentContainer; + + public MatrixViewerPanel() { + matrixRenderers = new ArrayList<MatrixRenderer>(); + matrices = new ArrayList<MatrixND>(); + + buildPanel(); + } + + protected boolean isMatrixComboVisible() { + return matrixComboVisible; + } + + public void setMatrixComboVisible(boolean matrixComboVisible) { + boolean oldValue = this.matrixComboVisible; + this.matrixComboVisible = matrixComboVisible; + firePropertyChange(PROPERTY_MATRIX_COMBO_VISIBLE, oldValue, matrixComboVisible); + } + + public MatrixRendererSolution getMatrixRendererSolution() { + return matrixRendererSolution; + } + + public void setMatrixRendererSolution(MatrixRendererSolution matrixRendererSolution) { + MatrixRendererSolution oldValue = this.matrixRendererSolution; + this.matrixRendererSolution = matrixRendererSolution; + firePropertyChange(PROPERTY_MATRIX_RENDERER_SOLUTION, oldValue, matrixRendererSolution); + } + + public boolean addMatrixRenderer(MatrixRenderer matrixRenderer) { + boolean result = matrixRenderers.add(matrixRenderer); + firePropertyChange(PROPERTY_MATRIX_RENDERERS, null, matrixRenderers); + return result; + } + + public boolean removeMatrixRenderer(Object matrixRenderer) { + boolean result = matrixRenderers.remove(matrixRenderer); + firePropertyChange(PROPERTY_MATRIX_RENDERERS, null, matrixRenderers); + return result; + } + + public void addMatrix(MatrixND... matrices) { + for (MatrixND matrix : matrices) { + this.matrices.add(matrix); + } + firePropertyChange(PROPERTY_MATRICES, null, matrices); + } + + public void removeMatrix(Object... matrices) { + for (Object matrix : matrices) { + this.matrices.remove(matrix); + } + firePropertyChange(PROPERTY_MATRICES, null, matrices); + } + + public void clearMatrix() { + matrices.clear(); + firePropertyChange(PROPERTY_MATRICES, null, matrices); + } + + /** Matrix list combo box. */ + protected class MatrixComboBox extends JComboBox implements PropertyChangeListener, ItemListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = -3166642639854195273L; + + public MatrixComboBox() { + addItemListener(this); + } + + /* + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent evt) { + setVisible(matrixComboVisible); + } + + /* + * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) + */ + @Override + public void itemStateChanged(ItemEvent e) { + dimensionPanel.setMatrix((MatrixND)getSelectedItem()); + } + } + + /** Matrix list combo box model. */ + protected class MatrixComboBoxModel extends DefaultComboBoxModel implements PropertyChangeListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4294576545040155208L; + + @Override + public int getSize() { + int result = matrices.size(); + return result; + } + + @Override + public Object getElementAt(int index) { + Object matrix = matrices.get(index); + return matrix; + } + + /* + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent evt) { + fireContentsChanged(this, 0, matrices.size() - 1); + + if (getSelectedItem() == null && getSize() > 0) { + setSelectedItem(getElementAt(0)); + } + } + } + + /** Matrix list combo renderer. */ + protected static class MatrixComboRenderer extends DefaultListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = 6151127818315270895L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + MatrixND matrix = (MatrixND)value; + String matrixName = null; + if (matrix != null) { + matrixName = _(matrix.getName()); + } + return super.getListCellRendererComponent(list, matrixName, index, isSelected, cellHasFocus); + } + } + + /** Button model from button containing rendered instance. */ + protected static class RendererButtonModel extends ToggleButtonModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -5737246124430280412L; + + protected MatrixRenderer renderer; + + public RendererButtonModel(MatrixRenderer renderer) { + this.renderer = renderer; + } + + public MatrixRenderer getRenderer() { + return renderer; + } + } + + /** Radio button rendering panel. */ + protected class RadioButtonRenderingPanel extends JPanel implements PropertyChangeListener{ + + /** serialVersionUID. */ + private static final long serialVersionUID = -6312518069621077533L; + + protected ButtonGroup buttonGroup; + + public RadioButtonRenderingPanel() { + super(new GridLayout(1, 0)); + } + + /* + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent evt) { + rebuildPanel(); + validate(); + repaint(); + } + + /** + * Rebuild radio button lists. + */ + protected void rebuildPanel() { + removeAll(); + if (matrixRendererSolution == MatrixRendererSolution.RADIO_BUTTON) { + + buttonGroup = new ButtonGroup(); + for (MatrixRenderer renderer : matrixRenderers) { + JRadioButton radioButton = new JRadioButton(renderer.getName()); + radioButton.setModel(new RendererButtonModel(renderer)); + buttonGroup.add(radioButton); + add(radioButton); + } + + setVisible(true); + } + else { + setVisible(false); + } + } + + public MatrixRenderer getSelectedRender() { + MatrixRenderer renderer = ((RendererButtonModel)buttonGroup.getSelection()).getRenderer(); + return renderer; + } + } + + /** + * Build main panel. + */ + protected void buildPanel() { + + setLayout(new BorderLayout()); + + // split main ui left/rigth + JPanel editionSidePanel = new JPanel(new BorderLayout()); + JPanel renderSidePanel = new JPanel(new BorderLayout()); + JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, editionSidePanel, renderSidePanel); + mainSplitPane.setDividerLocation(0.3); + add(mainSplitPane, BorderLayout.CENTER); + + // matrix list combo + matrixComboBox = new MatrixComboBox(); + MatrixComboBoxModel matrixListComboBoxModel = new MatrixComboBoxModel(); + matrixComboBox.setModel(matrixListComboBoxModel); + matrixComboBox.setRenderer(new MatrixComboRenderer()); + addPropertyChangeListener(PROPERTY_MATRIX_COMBO_VISIBLE, matrixComboBox); + addPropertyChangeListener(PROPERTY_MATRICES, matrixListComboBoxModel); + editionSidePanel.add(matrixComboBox, BorderLayout.NORTH); + + // panel d'affichage des dimensions + dimensionPanel = new MatrixDimensionPanel(); + editionSidePanel.add(dimensionPanel, BorderLayout.CENTER); + + // fleche de d'action de rendu + JButton renderButton = new JButton(Resource.getIcon("/icons/1rightarrow.png")); + renderButton.setActionCommand("render"); + renderButton.addActionListener(this); + + editionSidePanel.add(renderButton, BorderLayout.EAST); + + // render type : icon + + // render type : combo box + + // current rendering pane + renderingComponentContainer = new JPanel(new BorderLayout()); + renderSidePanel.add(renderingComponentContainer, BorderLayout.CENTER); + + // render type : radio button + radioPanel = new RadioButtonRenderingPanel(); + renderSidePanel.add(radioPanel, BorderLayout.SOUTH); + addPropertyChangeListener(PROPERTY_MATRIX_RENDERER_SOLUTION, radioPanel); + addPropertyChangeListener(PROPERTY_MATRIX_RENDERERS, radioPanel); + } + + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @Override + public void actionPerformed(ActionEvent e) { + + String actionCommand = e.getActionCommand(); + + if ("render".equalsIgnoreCase(actionCommand)) { + + // get selected renderer + MatrixRenderer renderer = null; + switch (matrixRendererSolution) { + case RADIO_BUTTON: + renderer = radioPanel.getSelectedRender(); + break; + default : + + } + + // get matrix to display + MatrixND matrix = dimensionPanel.getModifiedMatrix(); + + // renderer matrix + Component component = renderer.getPanel(matrix); + setRenderingComponent(component); + } + + } + + /** + * Set rendering component in rendering container. + * + * @param component component to install + */ + protected void setRenderingComponent(Component component) { + renderingComponentContainer.removeAll(); + renderingComponentContainer.add(component, BorderLayout.CENTER); + renderingComponentContainer.validate(); + renderingComponentContainer.repaint(); + } +} Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,104 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2002 - 2010 Ifremer, CodeLutin + * %% + * 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 2 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-2.0.html>. + * #L% + */ +package org.nuiton.math.matrix.viewer.renderer; + +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.MatrixException; +import javax.swing.table.AbstractTableModel; + +/** + * Matrix info table model. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixInfoTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 2632133167225155487L; + + protected MatrixND matrix; + + public MatrixInfoTableModel(MatrixND mat) { + if (mat.getDimCount() > 2) { + throw new MatrixException( + "matrice with more than 2 dimension not supported."); + } + this.matrix = mat; + } + + /** + * @return Le nombre de lignes de la table. + */ + public int getRowCount() { + if (matrix == null || matrix.getDimCount() < 1) { + return 0; + } else { + return matrix.getDim(0); + } + } + + /** + * @return Le nombre de colonnes de la table. + */ + public int getColumnCount() { + if (matrix == null || matrix.getDimCount() < 1) { + return 0; + } else { + return matrix.getDim(1) + 1; + } + } + + /** + * @param row La ligne + * @param column La colonnes + * @return L'Object correspondant dans la matrice. + */ + public Object getValueAt(int row, int column) { + if (column == 0) { + Object obj = matrix.getSemantic(0).get(row); + return obj; + } else { + if (matrix.getDimCount() == 1) { + return String.valueOf(matrix.getValue(column - 1)); + } else { + return String.valueOf(matrix.getValue(row, column - 1)); + } + } + } + + public String getColumnName(int column) { + if (column == 0) { + return matrix.getDimensionName(0) + "\\" + + matrix.getDimensionName(1); + } else { + return "" + matrix.getSemantic(1).get(column - 1); + } + } + +}// MatrixInfoTableModel Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java (rev 0) +++ trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,79 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer.renderer; + +import static org.nuiton.i18n.I18n._; + +import java.awt.Component; + +import javax.swing.Icon; +import javax.swing.JScrollPane; +import javax.swing.JTable; + +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.viewer.MatrixRenderer; +import org.nuiton.util.Resource; + +/** + * Matrix info table renderer. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixInfoTableRenderer implements MatrixRenderer { + + /* + * @see org.nuiton.math.matrix.viewer.MatrixRenderer#getPanel(org.nuiton.math.matrix.MatrixND) + */ + @Override + public Component getPanel(MatrixND matrix) { + + JTable table = new JTable(); + table.setModel(new MatrixInfoTableModel(matrix)); + return new JScrollPane(table); + } + + /* + * @see org.nuiton.math.matrix.viewer.MatrixRenderer#getIcon() + */ + @Override + public Icon getIcon() { + return Resource.getIcon("/icons/table.png"); + } + + /* + * @see org.nuiton.math.matrix.viewer.MatrixRenderer#getName() + */ + @Override + public String getName() { + return _("nuitonmatrix.viewer.renderer.data"); + } + + +} Property changes on: trunk/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/src/main/resources/i18n/nuiton-matrix_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/nuiton-matrix_en_GB.properties 2010-12-07 09:17:30 UTC (rev 291) +++ trunk/src/main/resources/i18n/nuiton-matrix_en_GB.properties 2010-12-08 11:13:06 UTC (rev 292) @@ -19,3 +19,5 @@ nuitonmatrix.menu.csv.import.file=Import from file nuitonmatrix.menu.csv.import.position=Import at current position nuitonmatrix.menu.option.semantics=Export/Copy with semantics +nuitonmatrix.viewer.renderer.data=Data +nuitonmatrix.viewer.sum=Sum Modified: trunk/src/main/resources/i18n/nuiton-matrix_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/nuiton-matrix_fr_FR.properties 2010-12-07 09:17:30 UTC (rev 291) +++ trunk/src/main/resources/i18n/nuiton-matrix_fr_FR.properties 2010-12-08 11:13:06 UTC (rev 292) @@ -19,3 +19,5 @@ nuitonmatrix.menu.csv.import.file=Importer depuis un fichier nuitonmatrix.menu.csv.import.position=Importer \u00E0 la position courante nuitonmatrix.menu.option.semantics=Exporter/Copier avec la s\u00E9mantique +nuitonmatrix.viewer.renderer.data=Donn\u00E9es +nuitonmatrix.viewer.sum=Somme Added: trunk/src/main/resources/icons/1rightarrow.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/1rightarrow.png ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/src/main/resources/icons/sigma-barre.gif =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/sigma-barre.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/main/resources/icons/sigma.gif =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/sigma.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/main/resources/icons/table.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/table.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java =================================================================== --- trunk/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java 2010-12-08 11:13:06 UTC (rev 292) @@ -0,0 +1,93 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program 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 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.math.matrix.viewer; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; + +import org.junit.Test; +import org.nuiton.math.matrix.MatrixFactory; +import org.nuiton.math.matrix.MatrixHelper; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.viewer.renderer.MatrixInfoTableRenderer; + +/** + * Test for matrix viewer panel. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixViewerPanelTest { + + protected MatrixND getTestMatrix() { + List<String> years = new ArrayList<String>(); + years.add("1999"); + years.add("2000"); + years.add("2001"); + years.add("2002"); + years.add("2003"); + years.add("2004"); + years.add("2005"); + + List<String> cities = new ArrayList<String>(); + cities.add("Nantes"); + cities.add("Paris"); + cities.add("Lyon"); + cities.add("Lille"); + cities.add("Toulouse"); + cities.add("Marseille"); + + MatrixND matrix = MatrixFactory.getInstance().create("test matrix", new List<?>[] { years, cities }); + matrix.setDimensionNames(new String[] { "Years", "Cities"}); + MatrixHelper.fill(matrix, 10000.0); + matrix.setValue(0, 0, 1000); + return matrix; + } + + /** + * Test d'un affichage simple, par defaut. + * @throws InterruptedException + */ + @Test + public void testViewerPanel() throws InterruptedException { + JFrame frame = new JFrame(); + + MatrixViewerPanel panel = new MatrixViewerPanel(); + MatrixND testMatrix = getTestMatrix(); + panel.addMatrix(testMatrix, testMatrix); + panel.addMatrixRenderer(new MatrixInfoTableRenderer()); + frame.add(panel); + + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } +} Property changes on: trunk/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
echatellier@users.nuiton.org