Author: echatellier Date: 2011-04-13 17:59:26 +0200 (Wed, 13 Apr 2011) New Revision: 353 Url: http://nuiton.org/repositories/revision/nuiton-matrix/353 Log: Evolution #1150: Add new toolbar on matrix panel to perform some operation on matrix Added: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditorHandler.java trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelOption.java trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java Removed: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModel.java trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixPanelRenderer.java trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelListenerTest.java trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx 2011-04-13 15:59:26 UTC (rev 353) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2004 - 2010 CodeLutin + Copyright (C) 2004 - 2011 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 @@ -24,8 +24,15 @@ --> <MatrixEditor layout='{new BorderLayout()}'> - <MatrixTableModel id='tableModel' javaBean='null'/> + <import> + org.nuiton.math.matrix.MatrixND + </import> + <MatrixPanelEditorHandler id="handler" /> + + <!-- Matrix to display --> + <MatrixND id="matrix" javaBean='null' /> + <!-- if true, use linear representation of matrix. --> <Boolean id='linearModel' javaBean='false'/> @@ -35,132 +42,68 @@ <!-- Boolean to autorize matrix dimension changes. --> <Boolean id='dimensionEdit' javaBean='false'/> - <script><![CDATA[ -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Event; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.util.Collection; -import java.util.HashSet; + <!-- Display option bar --> + <Boolean id="displayOptions" javaBean='false' /> -import org.nuiton.math.matrix.MatrixFactory; -import org.nuiton.math.matrix.MatrixND; - -private final static int DEFAULT_WIDTH = 150; - -private final static int DEFAULT_HEIGHT = 150; - -protected Collection<MatrixPanelListener> matrixPanelListeners = new HashSet<MatrixPanelListener>(); - -protected MatrixPopupMenu popupMenu = null; - -protected MatrixND matrix = null; - -initObject(); - -public MatrixPanelEditor(MatrixND m, boolean dimensionEdit) { - this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT); - matrix = m; -} - + <script><![CDATA[ public MatrixPanelEditor(boolean dimensionEdit, int width, int height) { this.dimensionEdit = dimensionEdit; - setPreferredSize(new Dimension(width, height)); + setPreferredSize(new java.awt.Dimension(width, height)); } public MatrixPanelEditor(boolean dimensionEdit) { - this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT); + this(dimensionEdit, 150, 150); } -public void setMatrix(MatrixND m){ - this.matrix = m; - initObject(); +public MatrixPanelEditor(MatrixND m, boolean dimensionEdit) { + this(dimensionEdit); + matrix = m; } -public MatrixND getMatrix() { - return matrix; +protected void $afterCompleteSetup() { + getHandler().initEditor(this); + addPropertyChangeListener(PROPERTY_MATRIX, new java.beans.PropertyChangeListener() { + public void propertyChange(java.beans.PropertyChangeEvent evt) { + getHandler().initEditor(MatrixPanelEditor.this); + } + }); } - -protected MatrixFactory getFactory() { - return MatrixFactory.getInstance(); +@Override +protected void fireEvent() { + getHandler().fireEvent(this); } - public void addMatrixPanelListener(MatrixPanelListener l) { - matrixPanelListeners.add(l); + getHandler().addMatrixPanelListener(l); } public void removeMatrixPanelListener(MatrixPanelListener l) { - matrixPanelListeners.remove(l); + getHandler().removeMatrixPanelListener(l); } - -protected void initObject() { - if (getMatrix() == null) { - editArea.setViewportView(null); - } - else { - popupMenu = new MatrixPopupMenu(this); - table = new JTable() { - public void processMouseEvent(MouseEvent event) { - if (event.isPopupTrigger()) { - popupMenu.show(event.getComponent(), event.getX(), event.getY()); - } - super.processMouseEvent(event); - } - }; - - table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK),"copy"); - table.getActionMap().put("copy",popupMenu.getSendToClipBoardSelectionCopyAction()); - table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK),"paste"); - table.getActionMap().put("paste",popupMenu.getSendToClipBoardCurrentPasteAction()); - if (isLinearModel()) { - setTableModel(new MatrixTableModelLinear(getMatrix(), isLinearModelShowDefault())); - } - else { - setTableModel(new MatrixTableModelND(getMatrix())); - } - - getTableModel().addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - fireEvent(); - } - }); - - table.setModel(getTableModel()); - table.setDefaultRenderer(String.class, tableModel.getMatrixCellRenderer()); - table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - editArea.setViewportView(table); - } - repaint(); -} - -protected void btnAction() { - String dim; - dim = JOptionPane.showInputDialog(null, _("nuitonmatrix.create.matrix.message"), _("nuitonmatrix.create.matrix.title"), JOptionPane.DEFAULT_OPTION); - - if (dim != null) { - String[] sdim = dim.split(";"); - int[] idim = new int[sdim.length]; - for (int i = 0; i < idim.length; i++) { - idim[i] = Integer.parseInt(sdim[i]); - } - setMatrix(getFactory().create(idim)); - } -} - -protected void fireEvent() { - MatrixPanelEvent e = new MatrixPanelEvent(this); - for (MatrixPanelListener matrixPanelListener : matrixPanelListeners) { - matrixPanelListener.matrixChanged(e); - } -} ]]> </script> + <Table visible="{isDisplayOptions()}" constraints='BorderLayout.NORTH'> + <row> + <cell anchor="center" weightx='1.0'> + <JLabel id="matrixNameLabel" /> + </cell> + <cell> + <JCheckBox id="sumOptionCheckBox" text="nuitonmatrix.gui.sumOption" + onActionPerformed="getHandler().initEditor(this);" /> + </cell> + <cell> + <JCheckBox id="meanOptionCheckBox" text="nuitonmatrix.gui.meanOption" + onActionPerformed="getHandler().initEditor(this);" /> + </cell> + <cell> + <JCheckBox id="transposeOptionCheckBox" text="nuitonmatrix.gui.transposeOption" + onActionPerformed="getHandler().initEditor(this);" /> + </cell> + </row> + </Table> <JScrollPane id='editArea' constraints='BorderLayout.CENTER'> - <JTable id='table' autoResizeMode='{JTable.AUTO_RESIZE_OFF}' cellSelectionEnabled='{true}' selectionMode='{ListSelectionModel.SINGLE_INTERVAL_SELECTION}'/> + <JTable id='table' /><!-- only to compile, not used after init :( autoResizeMode='{JTable.AUTO_RESIZE_OFF}' + cellSelectionEnabled='{true}' selectionMode='{ListSelectionModel.SINGLE_INTERVAL_SELECTION}'/> --> </JScrollPane> - <JButton id='buttonEdit' text='nuitonmatrix.create.matrix.button' visible='{isDimensionEdit()}' - onActionPerformed='btnAction()' constraints='BorderLayout.SOUTH'/> + <JButton id="buttonEdit" text='nuitonmatrix.create.matrix.button' visible='{isDimensionEdit()}' + onActionPerformed='getHandler().modifyMatrixDimension(this)' constraints='BorderLayout.SOUTH'/> </MatrixEditor> Added: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditorHandler.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditorHandler.java (rev 0) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditorHandler.java 2011-04-13 15:59:26 UTC (rev 353) @@ -0,0 +1,156 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.gui; + +import static org.nuiton.i18n.I18n._; + +import java.awt.Event; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.util.Collection; +import java.util.HashSet; + +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +import org.nuiton.math.matrix.MatrixFactory; +import org.nuiton.math.matrix.MatrixND; + +/** + * Handler for matrix panel editor. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixPanelEditorHandler { + + protected Collection<MatrixPanelListener> matrixPanelListeners = new HashSet<MatrixPanelListener>(); + + protected MatrixPopupMenu popupMenu = null; + + public void addMatrixPanelListener(MatrixPanelListener l) { + matrixPanelListeners.add(l); + } + + public void removeMatrixPanelListener(MatrixPanelListener l) { + matrixPanelListeners.remove(l); + } + + protected void fireEvent(MatrixPanelEditor matrixPanelEditor) { + MatrixPanelEvent event = new MatrixPanelEvent(matrixPanelEditor); + for (MatrixPanelListener matrixPanelListener : matrixPanelListeners) { + matrixPanelListener.matrixChanged(event); + } + } + + /** + * Init panel with current panel matrix. + * + * @param matrixPanelEditor panel to init + */ + protected void initEditor(final MatrixPanelEditor matrixPanelEditor) { + + MatrixND matrix = matrixPanelEditor.getMatrix(); + + JTable matrixTable = null; + if (matrix != null) { + popupMenu = new MatrixPopupMenu(matrixPanelEditor); + matrixTable = new JTable() { + public void processMouseEvent(MouseEvent event) { + if (event.isPopupTrigger()) { + popupMenu.show(event.getComponent(), event.getX(), event.getY()); + } + super.processMouseEvent(event); + } + }; + + matrixTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK), "copy"); + matrixTable.getActionMap().put("copy", popupMenu.getSendToClipBoardSelectionCopyAction()); + matrixTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK), "paste"); + matrixTable.getActionMap().put("paste", popupMenu.getSendToClipBoardCurrentPasteAction()); + + MatrixTableModel matrixTableModel = null; + if (matrixPanelEditor.isLinearModel()) { + matrixTableModel = new MatrixTableModelLinear(matrix, matrixPanelEditor.isLinearModelShowDefault()); + } + else { + matrixTableModel = new MatrixTableModelND(matrix); + } + + // unique gestion des options par modele interposé + if (matrixPanelEditor.isDisplayOptions()) { + matrixTableModel = new MatrixTableModelOption(matrixTableModel, + matrixPanelEditor.getSumOptionCheckBox().isSelected(), + matrixPanelEditor.getMeanOptionCheckBox().isSelected(), + matrixPanelEditor.getTransposeOptionCheckBox().isSelected()); + + } + + matrixTableModel.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + matrixPanelEditor.fireEvent(); + } + }); + + matrixTable.setModel(matrixTableModel); + matrixTable.setDefaultRenderer(String.class, matrixTableModel.getMatrixCellRenderer()); + matrixTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + matrixTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + matrixPanelEditor.table = matrixTable; + } + matrixPanelEditor.getEditArea().setViewportView(matrixTable); + matrixPanelEditor.repaint(); + } + + /** + * Modify matrix dimensions + * + * @param matrixPanelEditor matrix panel editor + */ + public void modifyMatrixDimension(MatrixPanelEditor matrixPanelEditor) { + String dim = JOptionPane.showInputDialog(matrixPanelEditor, + _("nuitonmatrix.create.matrix.message"), + _("nuitonmatrix.create.matrix.title")); + + if (dim != null && dim.indexOf(';') != -1) { + String[] sdim = dim.split(";"); + int[] idim = new int[sdim.length]; + for (int i = 0; i < idim.length; i++) { + idim[i] = Integer.parseInt(sdim[i]); + } + MatrixND newMatrix = MatrixFactory.getInstance().create(idim); + matrixPanelEditor.setMatrix(newMatrix); + } + } +} Property changes on: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModel.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModel.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModel.java 2011-04-13 15:59:26 UTC (rev 353) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2004 - 2010 CodeLutin + * Copyright (C) 2004 - 2011 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 @@ -25,13 +25,14 @@ package org.nuiton.math.matrix.gui; +import javax.swing.JTable; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableModel; import org.nuiton.math.matrix.MatrixND; /** - * MatrixTableModel. + * {@link TableModel} that can display matrix in a {@link JTable}. * * Created: 22 mars 2006 12:53:22 * @@ -40,15 +41,26 @@ * * Last update: $Date$ * by : $Author$ - * - * TODO Javadoc ? */ public interface MatrixTableModel extends TableModel { void setMatrix(MatrixND m); + + MatrixND getMatrix(); - void setEnabled(boolean enabled); - TableCellRenderer getMatrixCellRenderer(); + /** + * Get how many additional rows table model need to renderer matrix. + * + * @return additional rows + */ + int getAdditionalRows(); + + /** + * Get how many additional columns table model need to renderer matrix. + * + * @return additional columns + */ + int getAdditionalColumns(); } Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java 2011-04-13 15:59:26 UTC (rev 353) @@ -66,7 +66,6 @@ /** Logger for this class. */ private static Log log = LogFactory.getLog(MatrixTableModelLinear.class); - protected boolean enabled = true; protected MatrixND m = null; protected boolean showDefault = false; protected double defaultValue = 0; @@ -78,7 +77,15 @@ setMatrix(m); } + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getMatrix() + */ @Override + public MatrixND getMatrix() { + return m; + } + + @Override public void setMatrix(MatrixND m) { this.m = m; computeMapping(); @@ -97,21 +104,6 @@ } /** - * @return Returns the enabled. - */ - public boolean isEnabled() { - return this.enabled; - } - - /** - * @param enabled The enabled to set. - */ - @Override - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - /** * @return Returns the showDefault. */ public boolean isShowDefault() { @@ -178,7 +170,7 @@ */ @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - return isEnabled() && columnIndex == m.getDimCount(); + return columnIndex == m.getDimCount(); } /* @@ -282,4 +274,19 @@ } } + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalRows() + */ + @Override + public int getAdditionalRows() { + return 0; + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalColumns() + */ + @Override + public int getAdditionalColumns() { + return m.getDimCount(); + } } Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java 2011-04-13 15:59:26 UTC (rev 353) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2004 - 2010 CodeLutin + * Copyright (C) 2004 - 2011 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 @@ -72,9 +72,6 @@ protected int[] multRowCol = null; - /** par defaut, la matrice est editable. */ - protected boolean enabled = true; - protected TableCellRenderer renderer = null; /** @@ -106,7 +103,15 @@ setMatrix(m); } + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getMatrix() + */ @Override + public MatrixND getMatrix() { + return m; + } + + @Override public void setMatrix(MatrixND m) { this.m = m; addRow = m.getDimCount() / 2; @@ -303,15 +308,10 @@ } else if (m.getDimCount() == 1 && row < 1) { return false; } - return enabled; + return true; } @Override - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - @Override public Class<?> getColumnClass(int column) { return String.class; } @@ -376,4 +376,20 @@ } } + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalRows() + */ + @Override + public int getAdditionalRows() { + return addRow; + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalColumns() + */ + @Override + public int getAdditionalColumns() { + return addCol; + } + } Added: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelOption.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelOption.java (rev 0) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelOption.java 2011-04-13 15:59:26 UTC (rev 353) @@ -0,0 +1,414 @@ +/* + * #%L + * NuitonMatrix + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.gui; + +import static org.nuiton.i18n.I18n._; + +import javax.swing.event.TableModelListener; +import javax.swing.table.TableCellRenderer; + +import org.nuiton.math.matrix.MatrixND; + +/** + * Model that take a delegate model to add additional lines during + * rendering (such as row sum, column sum, row mean, column mean...) + * + * Created: 21 mars 2006 19:01:27 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class MatrixTableModelOption implements MatrixTableModel { + + protected MatrixTableModel delegate; + + protected boolean sumOption; + + protected boolean meanOption; + + protected boolean transposeOption; + + public MatrixTableModelOption(MatrixTableModel delegate) { + this(delegate, false, false, false); + } + + public MatrixTableModelOption(MatrixTableModel delegate, boolean sumOption, + boolean meanOption, boolean transposeOption) { + this.delegate = delegate; + this.sumOption = sumOption; + this.meanOption = meanOption; + this.transposeOption = transposeOption; + } + + public boolean isSumOption() { + return sumOption; + } + + public void setSumOption(boolean sumOption) { + this.sumOption = sumOption; + } + + public boolean isMeanOption() { + return meanOption; + } + + public void setMeanOption(boolean meanOption) { + this.meanOption = meanOption; + } + + public boolean isTransposeOption() { + return transposeOption; + } + + public void setTransposeOption(boolean transposeOption) { + this.transposeOption = transposeOption; + } + + /* + * @see javax.swing.table.TableModel#getRowCount() + */ + @Override + public int getRowCount() { + int result = -1; + if (transposeOption) { + result = delegate.getColumnCount(); + } + else { + result = delegate.getRowCount(); + } + if (sumOption) { + result++; + } + if (meanOption) { + result++; + } + return result; + } + + /* + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + int result = -1; + if (transposeOption) { + result = delegate.getRowCount(); + } + else { + result = delegate.getColumnCount(); + } + if (sumOption) { + result++; + } + if (meanOption) { + result++; + } + return result; + } + + /* + * @see javax.swing.table.TableModel#getColumnName(int) + */ + @Override + public String getColumnName(int columnIndex) { + String result = null; + if (sumOption && columnIndex == delegate.getColumnCount() + 0) { + result = null; //_("matrix.gui.model.sum"); + } + else if (meanOption && columnIndex == delegate.getColumnCount() + 1) { + result = null; //_("matrix.gui.model.mean"); + } + else { + result = delegate.getColumnName(columnIndex); + } + return result; + } + + /* + * @see javax.swing.table.TableModel#getColumnClass(int) + */ + @Override + public Class<?> getColumnClass(int columnIndex) { + return delegate.getColumnClass(columnIndex); + } + + /* + * @see javax.swing.table.TableModel#isCellEditable(int, int) + */ + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return delegate.isCellEditable(rowIndex, columnIndex); + } + + /* + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + int rowCount = delegate.getRowCount(); + int columnCount = delegate.getColumnCount(); + + Object result = null; + if (transposeOption) { + result = getValueAtTranposable(columnIndex, rowIndex, rowCount, columnCount); + } + else { + result = getValueAtTranposable(rowIndex, columnIndex, rowCount, columnCount); + } + return result; + } + + /** + * Get value qui fonctionne aussi en transposée. + * + * Le principe est que des que les bornes sur modele delegé sont dépassées + * on réalise des opération (mean/sum). + * + * Actuellement le code n'est vraiment pas evident. + * + * @param rowIndex rowIndex + * @param columnIndex columnIndex + * @param rowCount rowCount + * @param columnCount columnCount + * @return object at rowIndex/columnCount + */ + protected Object getValueAtTranposable(int rowIndex, int columnIndex, int rowCount, int columnCount) { + Object result = null; + // operation sur la derniere ligne + if (rowIndex >= rowCount) { + // une seule operation + if (columnIndex == 0) { + if (rowIndex == rowCount + 1) { + result = _("matrix.gui.model.mean"); + } + else { + if (sumOption) { + result = _("matrix.gui.model.sum"); + } + else { + result = _("matrix.gui.model.mean"); + } + } + } + // deux operation (forcement mean) (cas somme des sommes) + else if (columnIndex == columnCount + 1) { + if (rowIndex == rowCount + 1) { // pas de sens + result = delegate.getMatrix().meanAll(); + } + } + // une seule operation (cas somme des sommes) + else if (columnIndex == columnCount) { + if (rowIndex == rowCount) { // pas de sens + if (sumOption) { + result = delegate.getMatrix().sumAll(); + } + else { + result = delegate.getMatrix().sumAll(); + } + } + } + // deux operation (forcement mean) + else if (rowIndex == rowCount + 1) { + result = getComputedValueForColumn(columnIndex, true); // mean + } + // une seule operation + else { + if (sumOption) { + result = getComputedValueForColumn(columnIndex, false); // sum + } + else { + // sum + result = getComputedValueForColumn(columnIndex, true); // mean + } + } + } + + // operation sur la derniere colonne + else if (columnIndex >= columnCount) { + // une seule operation + if (rowIndex == 0) { + if (columnIndex == columnCount + 1) { + result = _("matrix.gui.model.mean"); + } + else { + if (sumOption) { + result = _("matrix.gui.model.sum"); + } + else { + result = _("matrix.gui.model.mean"); + } + } + } + // cas sommes de somme deja gérée + // par le premier if mais il faut quand meme les conditions + // pour qu'il ne passe pas dans le else final + else if (rowIndex == rowCount + 1) {} + else if (rowIndex == rowCount) {} + // deux operation (forcement mean) + else if (columnIndex == columnCount + 1) { + result = getComputedValueForRow(rowIndex, true); // mean + } + // une seule operation + else { + if (sumOption) { + result = getComputedValueForRow(rowIndex, false); // sum + } + else { + // sum + result = getComputedValueForRow(rowIndex, true); // mean + } + } + } + + else { + // reste du tableau + result = delegate.getValueAt(rowIndex, columnIndex); + } + return result; + } + + /** + * Compute sum for delegate model row index. + * + * @param delegateRowIndex delegate model row index + * @return sum for row + */ + protected Double getComputedValueForRow(int delegateRowIndex, boolean mean) { + double sum = 0.0; + double count = 0; + for (int col = delegate.getAdditionalColumns() ; col < delegate.getColumnCount() ; col++) { + sum += (Double)delegate.getValueAt(delegateRowIndex, col); + count++; + } + double result = sum; + if (mean) { + result = sum / count; + } + return result; + } + + /** + * Compute sum for delegate model column index. + * + * @param delegateColumnIndex delegate model column index + * @return sum for column + */ + protected Double getComputedValueForColumn(int delegateColumnIndex, boolean mean) { + double sum = 0.0; + double count = 0; + for (int row = delegate.getAdditionalRows() ; row < delegate.getRowCount() ; row++) { + sum += (Double)delegate.getValueAt(row, delegateColumnIndex); + count++; + } + double result = sum; + if (mean) { + result = sum / count; + } + return result; + } + + /* + * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) + */ + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + if (transposeOption) { + delegate.setValueAt(aValue, rowIndex, columnIndex); + } else { + delegate.setValueAt(aValue, columnIndex, rowIndex); + } + } + + /* + * @see javax.swing.table.TableModel#addTableModelListener(javax.swing.event.TableModelListener) + */ + @Override + public void addTableModelListener(TableModelListener l) { + delegate.addTableModelListener(l); + } + + /* + * @see javax.swing.table.TableModel#removeTableModelListener(javax.swing.event.TableModelListener) + */ + @Override + public void removeTableModelListener(TableModelListener l) { + delegate.removeTableModelListener(l); + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#setMatrix(org.nuiton.math.matrix.MatrixND) + */ + @Override + public void setMatrix(MatrixND m) { + delegate.setMatrix(m); + } + + @Override + public MatrixND getMatrix() { + return delegate.getMatrix(); + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getMatrixCellRenderer() + */ + @Override + public TableCellRenderer getMatrixCellRenderer() { + return delegate.getMatrixCellRenderer(); + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalRows() + */ + @Override + public int getAdditionalRows() { + int result = 0; + if (sumOption) { + result++; + } + if (meanOption) { + result++; + } + return result; + } + + /* + * @see org.nuiton.math.matrix.gui.MatrixTableModel#getAdditionalColumns() + */ + @Override + public int getAdditionalColumns() { + int result = 0; + if (sumOption) { + result++; + } + if (meanOption) { + result++; + } + return result; + } +} Property changes on: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelOption.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableModel.java 2011-04-13 15:59:26 UTC (rev 353) @@ -1,104 +0,0 @@ -/* - * #%L - * - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2002 - 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 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 Deleted: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java 2011-04-13 15:59:26 UTC (rev 353) @@ -1,142 +0,0 @@ -/* - * #%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.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.viewer.MatrixRenderer; -import org.nuiton.util.FileUtil; -import org.nuiton.util.Resource; - -/** - * Matrix info table renderer. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class MatrixInfoTableRenderer implements MatrixRenderer, ActionListener { - - /** Class logger. */ - private static Log log = LogFactory.getLog(MatrixInfoTableRenderer.class); - - protected MatrixND matrix; - - /* - * @see org.nuiton.math.matrix.viewer.MatrixRenderer#getPanel(org.nuiton.math.matrix.MatrixND) - */ - @Override - public Component getComponent(MatrixND matrix) { - this.matrix = matrix; - - JPanel panel = new JPanel(new BorderLayout()); - - // label matrix name - JLabel nameLabel = new JLabel(_(matrix.getName())); - nameLabel.setHorizontalAlignment(JLabel.CENTER); - panel.add(nameLabel, BorderLayout.NORTH); - - // data table - JTable table = new JTable(); - table.setModel(new MatrixInfoTableModel(matrix)); - panel.add(new JScrollPane(table), BorderLayout.CENTER); - - // export button - JButton exportButton = new JButton(_("nuitonmatrix.viewer.renderer.exportascsv")); - exportButton.addActionListener(this); - exportButton.setActionCommand("exportascsv"); - exportButton.setEnabled(this.matrix != null); - panel.add(exportButton, BorderLayout.SOUTH); - return panel; - } - - /* - * @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"); - } - - /* - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - @Override - public void actionPerformed(ActionEvent e) { - - if ("exportascsv".equals(e.getActionCommand())) { - FileWriter writer = null; - try { - File file = FileUtil.getFile(".+\\.csv", "CSV file"); - if (file != null) { - - // add csv extension - if (!file.getName().endsWith(".csv")) { - file = new File(file.getAbsolutePath() + ".csv"); - } - - writer = new FileWriter(file); - matrix.exportCSV(writer, true); - } - } catch (IOException eee) { - log.error(":104:Error during export" + eee); - } - finally { - IOUtils.closeQuietly(writer); - } - } - } - -} Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixPanelRenderer.java =================================================================== --- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixPanelRenderer.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixPanelRenderer.java 2011-04-13 15:59:26 UTC (rev 353) @@ -27,13 +27,25 @@ import static org.nuiton.i18n.I18n._; +import java.awt.BorderLayout; import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JPanel; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixND; import org.nuiton.math.matrix.gui.MatrixPanelEditor; import org.nuiton.math.matrix.viewer.MatrixRenderer; +import org.nuiton.util.FileUtil; import org.nuiton.util.Resource; /** @@ -45,16 +57,57 @@ * Last update : $Date$ * By : $Author$ */ -public class MatrixPanelRenderer implements MatrixRenderer { +public class MatrixPanelRenderer implements ActionListener, MatrixRenderer { + /** Class logger. */ + private static Log log = LogFactory.getLog(MatrixPanelRenderer.class); + + /** Renderer main component. */ + protected JPanel panel; + + /** Matrix editor. */ + protected MatrixPanelEditor editor; + + /** Export button. */ + protected JButton exportButton; + + /** Current matrix. */ + protected MatrixND matrix; + + public MatrixPanelRenderer() { + + panel = new JPanel(new BorderLayout()); + + // main component + editor = new MatrixPanelEditor(); + panel.add(editor, BorderLayout.CENTER); + + // export button + exportButton = new JButton(_("nuitonmatrix.viewer.renderer.exportascsv")); + exportButton.addActionListener(this); + exportButton.setActionCommand("exportascsv"); + exportButton.setEnabled(false); + panel.add(exportButton, BorderLayout.SOUTH); + } + + /** + * Get editor instance to allow configuration. + * + * @return internal editor reference + */ + public MatrixPanelEditor getEditor() { + return editor; + } + /* * @see org.nuiton.math.matrix.viewer.MatrixRenderer#getPanel(org.nuiton.math.matrix.MatrixND) */ @Override public Component getComponent(MatrixND matrix) { + this.matrix = matrix; + editor.setMatrix(matrix); + exportButton.setEnabled(matrix != null); - MatrixPanelEditor panel = new MatrixPanelEditor(); - panel.setMatrix(matrix); return panel; } @@ -73,6 +126,36 @@ public String getName() { return _("nuitonmatrix.viewer.renderer.panel"); } + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @Override + public void actionPerformed(ActionEvent e) { - + if ("exportascsv".equals(e.getActionCommand())) { + FileWriter writer = null; + try { + File file = FileUtil.getFile(".+\\.csv", "CSV file"); + if (file != null) { + + // add csv extension + if (!file.getName().endsWith(".csv")) { + file = new File(file.getAbsolutePath() + ".csv"); + } + + writer = new FileWriter(file); + matrix.exportCSV(writer, true); + } + } catch (IOException eee) { + if (log.isErrorEnabled()) { + log.error("Error during export", eee); + } + } + finally { + IOUtils.closeQuietly(writer); + } + } + } + } Modified: trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties =================================================================== --- trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties 2011-04-13 15:59:26 UTC (rev 353) @@ -1,3 +1,5 @@ +matrix.gui.model.mean=Mean +matrix.gui.model.sum=Sum nuitonmatrix.create.matrix.button=New matrix nuitonmatrix.create.matrix.message=Matrix size (separate by ';') nuitonmatrix.create.matrix.title=New matrix @@ -6,6 +8,9 @@ nuitonmatrix.error.clipboard.write=Cannot write clipboard nuitonmatrix.error.file.read=Cannot read file nuitonmatrix.error.file.write=Cannot write file +nuitonmatrix.gui.meanOption=Mean +nuitonmatrix.gui.sumOption=Sum +nuitonmatrix.gui.transposeOption=Transpose nuitonmatrix.menu.action=Copy/Paste nuitonmatrix.menu.action.copy=Copy nuitonmatrix.menu.action.copy.selection=Copy selection @@ -28,7 +33,6 @@ nuitonmatrix.viewer.graphcomborender.surface.stacked=Stacked area rendering nuitonmatrix.viewer.matrix.more.2d=Matrix dimensions count over 2 \!\nChoose less elements or apply sum operator. nuitonmatrix.viewer.renderer.chart=Chart -nuitonmatrix.viewer.renderer.data=Data nuitonmatrix.viewer.renderer.exportascsv=Export as CSV nuitonmatrix.viewer.renderer.panel=Matrix nuitonmatrix.viewer.sum=Sum Modified: trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties =================================================================== --- trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties 2011-04-13 15:59:26 UTC (rev 353) @@ -1,3 +1,5 @@ +matrix.gui.model.mean=Moyenne +matrix.gui.model.sum=Somme nuitonmatrix.create.matrix.button=Cr\u00E9er une matrice nuitonmatrix.create.matrix.message=Dimensions de la matrice (s\u00E9par\u00E9es par ';') nuitonmatrix.create.matrix.title=Cr\u00E9er une matrice @@ -6,6 +8,9 @@ nuitonmatrix.error.clipboard.write=Impossible d'\u00E9crire dans le bloc note nuitonmatrix.error.file.read=Impossible de lire le fichier nuitonmatrix.error.file.write=Impossible d'\u00E9crire dans le fichier +nuitonmatrix.gui.meanOption=Moyenne +nuitonmatrix.gui.sumOption=Somme +nuitonmatrix.gui.transposeOption=Transpos\u00E9e nuitonmatrix.menu.action=Copier/Coller nuitonmatrix.menu.action.copy=Copier nuitonmatrix.menu.action.copy.selection=Copier la s\u00E9lection @@ -28,7 +33,6 @@ nuitonmatrix.viewer.graphcomborender.surface.stacked=Rendu en aires empil\u00E9es nuitonmatrix.viewer.matrix.more.2d=Matrice de plus de 2 dimensions \!\nS\u00E9lectionnez moins d'\u00E9l\u00E9ments ou utilisez l'op\u00E9rateur somme. nuitonmatrix.viewer.renderer.chart=Graphique -nuitonmatrix.viewer.renderer.data=Donn\u00E9es nuitonmatrix.viewer.renderer.exportascsv=Exporter en CSV nuitonmatrix.viewer.renderer.panel=Matrice nuitonmatrix.viewer.sum=Somme Added: trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java =================================================================== --- trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java (rev 0) +++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java 2011-04-13 15:59:26 UTC (rev 353) @@ -0,0 +1,147 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.gui; + +import java.awt.Component; +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; + +/** + * Test to diplay matrix in MatrixPanelEditor using differents model. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MatrixPanelEditorTest { + + protected MatrixND getMatrixTest(int dimCount) { + List<?>[] dims = new List<?>[dimCount]; + + List<Integer> years = new ArrayList<Integer>(); + years.add(1999); + years.add(2000); + years.add(2001); + years.add(2002); + years.add(2003); + years.add(2004); + years.add(2005); + dims[0] = years; + + if (dimCount >= 2) { + List<String> cities = new ArrayList<String>(); + cities.add("Nantes"); + cities.add("Paris"); + cities.add("Lyon"); + cities.add("Lille"); + cities.add("Toulouse"); + cities.add("Marseille"); + dims[1] = cities; + } + + if (dimCount >= 3) { + List<String> sectors = new ArrayList<String>(); + sectors.add("Informatique"); + sectors.add("Administration"); + sectors.add("Livraison"); + sectors.add("Achat"); + dims[2] = sectors; + } + + if (dimCount >= 4) { + List<String> persons = new ArrayList<String>(); + persons.add("Bob"); + persons.add("Joe"); + persons.add("Louis"); + persons.add("Jean"); + dims[3] = persons; + } + + MatrixND matrix = MatrixFactory.getInstance().create(dims); + matrix.setName("test matrix"); + MatrixHelper.fill(matrix, Math.random()*10000); + + return matrix; + } + + protected void show(Component comp) { + JFrame frame = new JFrame(); + frame.add(comp); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + + try { + Thread.sleep(60000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void testModelNDDim3() { + MatrixND matrix = getMatrixTest(3); + MatrixPanelEditor editor = new MatrixPanelEditor(); + editor.setMatrix(matrix); + show(editor); + } + + @Test + public void testModelNDDim4() { + MatrixND matrix = getMatrixTest(4); + MatrixPanelEditor editor = new MatrixPanelEditor(); + editor.setMatrix(matrix); + show(editor); + } + + @Test + public void testModelLinearDim3() { + MatrixND matrix = getMatrixTest(3); + MatrixPanelEditor editor = new MatrixPanelEditor(); + editor.setLinearModel(true); + editor.setLinearModelShowDefault(true); + editor.setMatrix(matrix); + show(editor); + } + + @Test + public void testModelLinearDim4() { + MatrixND matrix = getMatrixTest(4); + MatrixPanelEditor editor = new MatrixPanelEditor(); + editor.setLinearModel(true); + editor.setMatrix(matrix); + show(editor); + } +} Property changes on: trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelListenerTest.java =================================================================== --- trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelListenerTest.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelListenerTest.java 2011-04-13 15:59:26 UTC (rev 353) @@ -33,7 +33,7 @@ import org.junit.Test; /** - * A test to verify that {@link MatrixPanelListener} is trully a JavaBeans + * A test to verify that {@link MatrixPanelListener} is truly a JavaBeans * listener implementation in editors. * * @author chemit @@ -44,7 +44,7 @@ public static final String MATRIX_PANEL_LISTENER_NAME = "matrixPanel"; /** - * Test if editors are trully JavaBeans listeners implementations + * Test if editors are truly JavaBeans listeners implementations * @throws Exception */ @Test Modified: trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java =================================================================== --- trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java 2011-04-13 15:50:50 UTC (rev 352) +++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java 2011-04-13 15:59:26 UTC (rev 353) @@ -37,7 +37,6 @@ import org.nuiton.math.matrix.MatrixND; import org.nuiton.math.matrix.MatrixProvider; import org.nuiton.math.matrix.viewer.renderer.MatrixChartRenderer; -import org.nuiton.math.matrix.viewer.renderer.MatrixInfoTableRenderer; import org.nuiton.math.matrix.viewer.renderer.MatrixPanelRenderer; import org.nuiton.util.Resource; @@ -83,7 +82,8 @@ else { matrix = MatrixFactory.getInstance().create("test matrix", new List<?>[]{years, cities}, new String[]{"Years", "Cities"}); MatrixHelper.fill(matrix, Math.random()*10000); - matrix.setValue(0, 0, Math.random()*10000); + matrix.setValue(1, 0, Math.random()*10000); + matrix.setValue(0, 4, Math.random()*10000); } return matrix; } @@ -98,9 +98,10 @@ MatrixViewerPanel panel = new MatrixViewerPanel(); MatrixND testMatrix = getTestMatrix(false); panel.setMatrix(testMatrix); - panel.addMatrixRenderer(new MatrixInfoTableRenderer()); panel.addMatrixRenderer(new MatrixChartRenderer()); - panel.addMatrixRenderer(new MatrixPanelRenderer()); + MatrixPanelRenderer panelRenderer = new MatrixPanelRenderer(); + panelRenderer.getEditor().setDisplayOptions(true); + panel.addMatrixRenderer(panelRenderer); frame.add(panel); frame.pack(); @@ -123,7 +124,7 @@ MatrixViewerPanel panel = new MatrixViewerPanel(); MatrixND testMatrix = getTestMatrix(true); - panel.addMatrixRenderer(new MatrixInfoTableRenderer()); + panel.addMatrixRenderer(new MatrixPanelRenderer()); panel.addMatrixRenderer(new MatrixChartRenderer()); panel.addMatrixDimentionAction(new MatrixDimensionAction() { @Override