Nuiton-matrix-commits
Threads by month
- ----- 2026 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
April 2011
- 2 participants
- 13 discussions
r357 - in trunk/nuiton-matrix-gui/src/main: java/org/nuiton/math/matrix/gui resources/i18n
by echatellier@users.nuiton.org April 29, 2011
by echatellier@users.nuiton.org April 29, 2011
April 29, 2011
Author: echatellier
Date: 2011-04-29 17:07:38 +0200 (Fri, 29 Apr 2011)
New Revision: 357
Url: http://nuiton.org/repositories/revision/nuiton-matrix/357
Log:
#1491: Add new data function on pupop menu (fill identity, fill value)
Modified:
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.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
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java 2011-04-29 15:06:54 UTC (rev 356)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java 2011-04-29 15:07:38 UTC (rev 357)
@@ -54,6 +54,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixHelper;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.util.FileUtil;
@@ -129,10 +130,13 @@
withSemantics = new JCheckBoxMenuItem(
_("nuitonmatrix.menu.option.semantics"), false);
+ JMenu applyDataAction = getApplyDataAction();
+
add(sendToClipBoard);
add(sendToFile);
+ add(withSemantics);
add(new JSeparator());
- add(withSemantics);
+ add(applyDataAction);
}
/**
@@ -140,7 +144,7 @@
*
* @return retourne le menu d'action pour le bloc note
*/
- public JMenu getSendToClipBoard() {
+ protected JMenu getSendToClipBoard() {
if (sendToClipBoard == null) {
sendToClipBoard = new JMenu(_("nuitonmatrix.menu.action"));
JMenuItem sendToClipBoardAllCopy = new JMenuItem(
@@ -176,7 +180,7 @@
*
* @return retourne le menu d'action pour les fichiers CSV
*/
- public JMenu getSendToFile() {
+ protected JMenu getSendToFile() {
if (sendToFile == null) {
sendToFile = new JMenu(_("nuitonmatrix.menu.csv"));
JMenuItem sendToFileAllCopy = new JMenuItem(
@@ -204,7 +208,40 @@
return sendToFile;
}
+
+ /**
+ * Init export to file action.
+ *
+ * @return retourne le menu d'action pour les fichiers CSV
+ */
+ protected JMenu getApplyDataAction() {
+ JMenu getApplyDataAction = new JMenu(_("nuitonmatrix.menu.data"));
+ JMenuItem dataIdentityItem = new JMenuItem(
+ _("nuitonmatrix.menu.data.identity"));
+ JMenuItem dataFillValueItem = new JMenuItem(
+ _("nuitonmatrix.menu.data.fillvalue"));
+ getApplyDataAction.add(dataIdentityItem);
+ getApplyDataAction.add(dataFillValueItem);
+
+ dataIdentityItem.addActionListener(new AbstractAction() {
+ private static final long serialVersionUID = -2263800006423028369L;
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dataIdentityPerformed();
+ }
+ });
+ dataFillValueItem.addActionListener(new AbstractAction() {
+ private static final long serialVersionUID = -2263800006423028369L;
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dataFillValuePerformed();
+ }
+ });
+
+ return getApplyDataAction;
+ }
+
/**
* Init export to file writer.
*
@@ -706,4 +743,31 @@
}
}
}
+
+ /**
+ * Fill editor matrix with identity matrix.
+ */
+ protected void dataIdentityPerformed() {
+ MatrixHelper.convertToId(getMatrix());
+ matrixEditor.fireEvent();
+ matrixEditor.repaint();
+ }
+
+ /**
+ * Ask user for new value to fill into matrix.
+ */
+ protected void dataFillValuePerformed() {
+ String stringValue = JOptionPane.showInputDialog(matrixEditor, _("nuitonmatrix.menu.data.fillvalue.ask"));
+ if (stringValue != null) {
+ try {
+ double value = Double.parseDouble(stringValue);
+ MatrixHelper.fill(getMatrix(), value);
+ matrixEditor.fireEvent();
+ matrixEditor.repaint();
+ }
+ catch (NumberFormatException ex) {
+ // skip exception
+ }
+ }
+ }
}
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-29 15:06:54 UTC (rev 356)
+++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties 2011-04-29 15:07:38 UTC (rev 357)
@@ -21,6 +21,10 @@
nuitonmatrix.menu.csv.export.selection=Export selection
nuitonmatrix.menu.csv.import.file=Import from file
nuitonmatrix.menu.csv.import.position=Import at current position
+nuitonmatrix.menu.data=Data
+nuitonmatrix.menu.data.fillvalue=Fill value
+nuitonmatrix.menu.data.fillvalue.ask=Enter new value to fill into matrix \:
+nuitonmatrix.menu.data.identity=Convert to identity
nuitonmatrix.menu.option.semantics=Export/Copy with semantics
nuitonmatrix.viewer.dimnameindex=Dimension %d
nuitonmatrix.viewer.graphcomborender.bar=Verticals bar rendering
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-29 15:06:54 UTC (rev 356)
+++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties 2011-04-29 15:07:38 UTC (rev 357)
@@ -21,6 +21,10 @@
nuitonmatrix.menu.csv.export.selection=Exporter la s\u00E9lection
nuitonmatrix.menu.csv.import.file=Importer depuis un fichier
nuitonmatrix.menu.csv.import.position=Importer \u00E0 la position courante
+nuitonmatrix.menu.data=Donn\u00E9es
+nuitonmatrix.menu.data.fillvalue=Remplir avec une valeur
+nuitonmatrix.menu.data.fillvalue.ask=Entrez la valeur avec laquelle remplir la matrice \:
+nuitonmatrix.menu.data.identity=Convertir en matrice identit\u00E9
nuitonmatrix.menu.option.semantics=Exporter/Copier avec la s\u00E9mantique
nuitonmatrix.viewer.dimnameindex=Dimension %d
nuitonmatrix.viewer.graphcomborender.bar=Rendu en barres verticales
1
0
r356 - trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui
by echatellier@users.nuiton.org April 29, 2011
by echatellier@users.nuiton.org April 29, 2011
April 29, 2011
Author: echatellier
Date: 2011-04-29 17:06:54 +0200 (Fri, 29 Apr 2011)
New Revision: 356
Url: http://nuiton.org/repositories/revision/nuiton-matrix/356
Log:
Regression : en vrai property change cela ne fonctionne pas, doit faire certaines chose des que l'instance change
Modified:
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx
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-22 07:51:03 UTC (rev 355)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.jaxx 2011-04-29 15:06:54 UTC (rev 356)
@@ -30,9 +30,6 @@
<MatrixPanelEditorHandler id="handler" />
- <!-- Matrix to display -->
- <MatrixND id="matrix" javaBean='null' />
-
<!-- if true, use linear representation of matrix. -->
<Boolean id='linearModel' javaBean='false'/>
@@ -46,6 +43,8 @@
<Boolean id="displayOptions" javaBean='false' />
<script><![CDATA[
+protected MatrixND matrix;
+
public MatrixPanelEditor(boolean dimensionEdit, int width, int height) {
this.dimensionEdit = dimensionEdit;
setPreferredSize(new java.awt.Dimension(width, height));
@@ -60,18 +59,33 @@
matrix = m;
}
+@Override
+public void setMatrix(MatrixND matrix) {
+ this.matrix = matrix;
+ getHandler().initEditor(this);
+}
+
+@Override
+public MatrixND getMatrix() {
+ return matrix;
+}
+
protected void $afterCompleteSetup() {
getHandler().initEditor(this);
+ /* ne fonctionne, pas doit être fait des que l'instance change, même si les
+ deux matrices sont égales
addPropertyChangeListener(PROPERTY_MATRIX, new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
getHandler().initEditor(MatrixPanelEditor.this);
}
- });
+ });*/
}
+
@Override
protected void fireEvent() {
getHandler().fireEvent(this);
}
+
public void addMatrixPanelListener(MatrixPanelListener l) {
getHandler().addMatrixPanelListener(l);
}
1
0
r355 - trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui
by echatellier@users.nuiton.org April 22, 2011
by echatellier@users.nuiton.org April 22, 2011
April 22, 2011
Author: echatellier
Date: 2011-04-22 09:51:03 +0200 (Fri, 22 Apr 2011)
New Revision: 355
Url: http://nuiton.org/repositories/revision/nuiton-matrix/355
Log:
Remove timer
Modified:
trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java
Modified: 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 2011-04-14 09:30:03 UTC (rev 354)
+++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java 2011-04-22 07:51:03 UTC (rev 355)
@@ -111,6 +111,14 @@
}
@Test
+ public void testModelNDDim2() {
+ MatrixND matrix = getMatrixTest(2);
+ MatrixPanelEditor editor = new MatrixPanelEditor();
+ editor.setMatrix(matrix);
+ show(editor);
+ }
+
+ @Test
public void testModelNDDim3() {
MatrixND matrix = getMatrixTest(3);
MatrixPanelEditor editor = new MatrixPanelEditor();
@@ -125,8 +133,17 @@
editor.setMatrix(matrix);
show(editor);
}
-
+
@Test
+ public void testModelLinearNDDim2() {
+ MatrixND matrix = getMatrixTest(2);
+ MatrixPanelEditor editor = new MatrixPanelEditor();
+ editor.setLinearModel(true);
+ editor.setMatrix(matrix);
+ show(editor);
+ }
+
+ @Test
public void testModelLinearDim3() {
MatrixND matrix = getMatrixTest(3);
MatrixPanelEditor editor = new MatrixPanelEditor();
1
0
r354 - trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui
by echatellier@users.nuiton.org April 14, 2011
by echatellier@users.nuiton.org April 14, 2011
April 14, 2011
Author: echatellier
Date: 2011-04-14 11:30:03 +0200 (Thu, 14 Apr 2011)
New Revision: 354
Url: http://nuiton.org/repositories/revision/nuiton-matrix/354
Log:
Remove time wait
Modified:
trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java
Modified: 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 2011-04-13 15:59:26 UTC (rev 353)
+++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/gui/MatrixPanelEditorTest.java 2011-04-14 09:30:03 UTC (rev 354)
@@ -103,11 +103,11 @@
frame.setLocationRelativeTo(null);
frame.setVisible(true);
- try {
+ /*try {
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
- }
+ }*/
}
@Test
1
0
r353 - in trunk/nuiton-matrix-gui/src: main/java/org/nuiton/math/matrix/gui main/java/org/nuiton/math/matrix/viewer/renderer main/resources/i18n test/java/org/nuiton/math/matrix/gui test/java/org/nuiton/math/matrix/viewer
by echatellier@users.nuiton.org April 13, 2011
by echatellier@users.nuiton.org April 13, 2011
April 13, 2011
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
1
0
r352 - trunk/nuiton-matrix/src/main/java/org/nuiton/math/matrix
by echatellier@users.nuiton.org April 13, 2011
by echatellier@users.nuiton.org April 13, 2011
April 13, 2011
Author: echatellier
Date: 2011-04-13 17:50:50 +0200 (Wed, 13 Apr 2011)
New Revision: 352
Url: http://nuiton.org/repositories/revision/nuiton-matrix/352
Log:
Anomalie #1458: Can't use List<Integer> as semantics
Modified:
trunk/nuiton-matrix/src/main/java/org/nuiton/math/matrix/MatrixHelper.java
Modified: trunk/nuiton-matrix/src/main/java/org/nuiton/math/matrix/MatrixHelper.java
===================================================================
--- trunk/nuiton-matrix/src/main/java/org/nuiton/math/matrix/MatrixHelper.java 2011-04-13 08:39:28 UTC (rev 351)
+++ trunk/nuiton-matrix/src/main/java/org/nuiton/math/matrix/MatrixHelper.java 2011-04-13 15:50:50 UTC (rev 352)
@@ -32,8 +32,6 @@
import java.util.NoSuchElementException;
import java.util.Stack;
-import org.apache.commons.lang.ArrayUtils;
-
/**
* Contains usefull methods to get information on matrix.
*
@@ -191,7 +189,7 @@
for (int i = 0; i < result.length; i++) {
result[i] = semantics[i].get(coordinates[i]);
if (result[i] == null) {
- result[i] = Integer.valueOf(coordinates[i]);
+ result[i] = MatrixDimensionIndex.valueOf(coordinates[i]);
}
}
return result;
@@ -204,7 +202,7 @@
*
* @param semantics la semantique à utiliser pour la conversion
* @param coordinates les coordonnées sémantique
- * @return les coordonnées en entier. Si la sémantique est représentéé par un
+ * @return les coordonnées en entier. Si la sémantique est représentée par un
* Integer alors la valeur de l'integer est utilisé pour la
* conversion.
*/
@@ -233,8 +231,9 @@
*/
public static int indexOf(List<?>[] semantics, int dim, Object o)
throws NoSuchElementException {
- if (o instanceof Integer) {
- return ((Integer) o).intValue();
+ // see {#dimensionToSemantics()} to known why
+ if (o instanceof MatrixDimensionIndex) {
+ return ((MatrixDimensionIndex) o).intValue();
}
int result = -1;
if ((0 <= dim) && (dim < semantics.length)) {
@@ -373,3 +372,53 @@
}
} // MatrixHelper
+
+/**
+ * This class must stay private and can't be used outside nuiton matrix
+ * to prevent semantic type collision.
+ *
+ * This class is a copy of JDK's Integer with only necessary stuff.
+ */
+class MatrixDimensionIndex {
+ protected int value;
+
+ private MatrixDimensionIndex(int value) {
+ this.value = value;
+ }
+
+ /**
+ * See {@code Integer#IntegerCache} for details about that.
+ */
+ private static class MatrixDimensionIndexCache {
+ static final int high;
+ static final MatrixDimensionIndex cache[];
+
+ static {
+ final int low = 0;
+
+ // high value may be configured by property
+ high = 127;
+
+ cache = new MatrixDimensionIndex[(high - low) + 1];
+ int j = low;
+ for(int k = 0; k < cache.length; k++) {
+ cache[k] = new MatrixDimensionIndex(j++);
+ }
+ }
+
+ private MatrixDimensionIndexCache() {}
+ }
+
+ public static MatrixDimensionIndex valueOf(int i) {
+ if(i >= 0 && i <= MatrixDimensionIndexCache.high) {
+ return MatrixDimensionIndexCache.cache[i + 128];
+ }
+ else {
+ return new MatrixDimensionIndex(i);
+ }
+ }
+
+ public int intValue() {
+ return value;
+ }
+}
\ No newline at end of file
1
0
Author: echatellier
Date: 2011-04-13 10:39:28 +0200 (Wed, 13 Apr 2011)
New Revision: 351
Url: http://nuiton.org/repositories/revision/nuiton-matrix/351
Log:
Evolution #1455: Update to jaxx 2.4
Evolution #1456: Update to nuiton-util 2.1.1
Evolution #1457: Update nuiton-i18n 2.3.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-04-11 08:46:21 UTC (rev 350)
+++ trunk/pom.xml 2011-04-13 08:39:28 UTC (rev 351)
@@ -50,14 +50,10 @@
<artifactId>javahelp</artifactId>
</exclusion>
<exclusion>
- <groupId>com.opensymphony</groupId>
- <artifactId>xwork</artifactId>
+ <groupId>org.swinglabs</groupId>
+ <artifactId>swingx-core</artifactId>
</exclusion>
<exclusion>
- <groupId>opensymphony</groupId>
- <artifactId>ognl</artifactId>
- </exclusion>
- <exclusion>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</exclusion>
@@ -96,9 +92,9 @@
<projectId>nuiton-matrix</projectId>
- <jaxxVersion>2.2.5</jaxxVersion>
- <nuitonUtilsVersion>2.0</nuitonUtilsVersion>
- <nuitonI18nVersion>2.2</nuitonI18nVersion>
+ <jaxxVersion>2.4</jaxxVersion>
+ <nuitonUtilsVersion>2.1.1</nuitonUtilsVersion>
+ <nuitonI18nVersion>2.3.2</nuitonI18nVersion>
</properties>
1
0
Author: tchemit
Date: 2011-04-11 10:46:21 +0200 (Mon, 11 Apr 2011)
New Revision: 350
Url: http://nuiton.org/repositories/revision/nuiton-matrix/350
Log:
Update mavenpom4redmineAndCentral to 2.5.3.
Modified:
branches/nuiton-matrix-2.1.x/pom.xml
Modified: branches/nuiton-matrix-2.1.x/pom.xml
===================================================================
--- branches/nuiton-matrix-2.1.x/pom.xml 2011-04-11 08:46:18 UTC (rev 349)
+++ branches/nuiton-matrix-2.1.x/pom.xml 2011-04-11 08:46:21 UTC (rev 350)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.5.2</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-matrix</artifactId>
1
0
Author: tchemit
Date: 2011-04-11 10:46:18 +0200 (Mon, 11 Apr 2011)
New Revision: 349
Url: http://nuiton.org/repositories/revision/nuiton-matrix/349
Log:
Update mavenpom4redmineAndCentral to 2.5.3.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-04-08 14:03:40 UTC (rev 348)
+++ trunk/pom.xml 2011-04-11 08:46:18 UTC (rev 349)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.5.2</version>
+ <version>2.5.3</version>
</parent>
<artifactId>matrix</artifactId>
1
0
r348 - in trunk/nuiton-matrix-gui/src/main: java/org/nuiton/math/matrix/viewer java/org/nuiton/math/matrix/viewer/renderer resources/i18n
by echatellier@users.nuiton.org April 8, 2011
by echatellier@users.nuiton.org April 8, 2011
April 8, 2011
Author: echatellier
Date: 2011-04-08 16:03:40 +0200 (Fri, 08 Apr 2011)
New Revision: 348
Url: http://nuiton.org/repositories/revision/nuiton-matrix/348
Log:
#1448: Update MatrixFilter to support dimension filter
Modified:
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixFilter.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.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
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java 2011-04-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java 2011-04-08 14:03:40 UTC (rev 348)
@@ -27,6 +27,8 @@
import static org.nuiton.i18n.I18n._;
+import org.apache.commons.lang.StringUtils;
+
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
@@ -103,8 +105,8 @@
repaint();
}
- public MatrixND getModifiedMatrix() {
- MatrixND reducedMatrix = createAndReduce(matrix);
+ public MatrixND getModifiedMatrix(List<MatrixFilter> matrixFilters) {
+ MatrixND reducedMatrix = createAndReduce(matrix, matrixFilters);
return reducedMatrix;
}
@@ -141,6 +143,9 @@
* tous les boutons (methode setSelected surchargée).
*/
protected ButtonGroup buttonGroup = new ButtonGroup() {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 8214289174634749701L;
+
@Override
public void setSelected(ButtonModel m, boolean b) {
if (b) {
@@ -245,7 +250,14 @@
if (matrix != null) {
int index = 0;
for (List<?> semantic : matrix.getSemantics()) {
- SubDimensionPanel dimPanel = new SubDimensionPanel(index, _(matrix.getDimensionName(index)), semantic);
+
+ // compute dimension name
+ String dimensionName = _(matrix.getDimensionName(index));
+ if (StringUtils.isBlank(dimensionName)) {
+ dimensionName = _("nuitonmatrix.viewer.dimnameindex", index);
+ }
+
+ SubDimensionPanel dimPanel = new SubDimensionPanel(index, dimensionName, semantic);
add(dimPanel);
subPanelList.add(dimPanel);
index++;
@@ -275,10 +287,18 @@
}
}
- protected MatrixND createAndReduce(MatrixND matrix) {
+ /**
+ * Reduit, somme et filtre la matrice sur les dimensions selectionnés,
+ * les boutons d'action selections et les filtres enregistrés.
+ *
+ * @param matrix initial matrix to reduce
+ * @param matrixFilters matrix filter to apply
+ * @return filtred, reduced and sommed matrix
+ */
+ protected MatrixND createAndReduce(MatrixND matrix, List<MatrixFilter> matrixFilters) {
if (log.isDebugEnabled()) {
- log.debug("matrice avant submatrice : " + matrix);
+ log.debug("Matrice before submatrix : " + matrix);
}
// la matrice doit être reduite avant tout et en une seule
@@ -304,7 +324,7 @@
matrix = matrix.getSubMatrix(dimIndices);
if (log.isDebugEnabled()) {
- log.debug("matrice apres submatrice : " + matrix);
+ log.debug("Matrix after submatrix : " + matrix);
}
// Effectue la somme si l'utilisateur a selectionné l'option somme
@@ -322,49 +342,22 @@
// 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);
+ // apply main filter after reduction
+ for (MatrixFilter matrixFilter : matrixFilters) {
+ matrix = matrixFilter.filterDimension(matrix, i, subDimPanel.getSumStep());
}
- // end semantics modification */
}
if (log.isDebugEnabled()) {
- log.debug("matrice apres sum de la dim " + i + ": " + matrix);
+ log.debug("Matrix after sum on dim " + i + ": " + matrix);
}
}
if (log.isDebugEnabled()) {
- log.debug("Matrice avant le reduce: " + matrix);
+ log.debug("Matrix febore reduce: " + matrix);
}
// arrive ici on a une matrice qui a des tailles de dimension 1
@@ -374,6 +367,11 @@
// reduction de la matrice
MatrixND result = matrix.reduce(2);
+ // apply main filter after reduction
+ for (MatrixFilter matrixFilter : matrixFilters) {
+ result = matrixFilter.filter(result);
+ }
+
return result;
}
}
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixFilter.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixFilter.java 2011-04-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixFilter.java 2011-04-08 14:03:40 UTC (rev 348)
@@ -41,8 +41,22 @@
/**
* Filter input matrix.
*
+ * Called after submatrix creation on selected dimension and applied sum action.
+ *
+ * This method can be considerer as "main filter".
+ *
* @param matrix matrix to filter
* @return filtered matrix
*/
public MatrixND filter(MatrixND matrix);
+
+ /**
+ * Apply filter on matrix after dimension summing.
+ *
+ * @param matrix matrix to filter
+ * @param dim dimension concerned by summing
+ * @param sumStep sumStep summing
+ * @return filtered matrix
+ */
+ public MatrixND filterDimension(MatrixND matrix, int dim, int sumStep);
}
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java 2011-04-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java 2011-04-08 14:03:40 UTC (rev 348)
@@ -300,10 +300,8 @@
String actionCommand = e.getActionCommand();
if ("render".equals(actionCommand)) {
- // get matrix to display
- MatrixND matrix = dimensionPanel.getModifiedMatrix();
- // filter matrix
- matrix = getFilteredMatrix(matrix);
+ // get matrix to display filtered
+ MatrixND matrix = dimensionPanel.getModifiedMatrix(matrixFilters);
// matrice superieur a 2 dimensions non geree!!
if (matrix.getDimCount() > 2) {
Modified: 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-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/renderer/MatrixInfoTableRenderer.java 2011-04-08 14:03:40 UTC (rev 348)
@@ -27,14 +27,27 @@
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;
/**
@@ -46,17 +59,39 @@
* Last update : $Date$
* By : $Author$
*/
-public class MatrixInfoTableRenderer implements MatrixRenderer {
+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));
- return new JScrollPane(table);
+ 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;
}
/*
@@ -75,5 +110,33 @@
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/resources/i18n/nuiton-matrix-gui_en_GB.properties
===================================================================
--- trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties 2011-04-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_en_GB.properties 2011-04-08 14:03:40 UTC (rev 348)
@@ -17,6 +17,7 @@
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.dimnameindex=Dimension %d
nuitonmatrix.viewer.graphcomborender.bar=Verticals bar rendering
nuitonmatrix.viewer.graphcomborender.bar.3d=3D verticals bars rendering
nuitonmatrix.viewer.graphcomborender.bar.stacked=Stacked verticals bars rendering
@@ -28,5 +29,6 @@
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-08 13:10:03 UTC (rev 347)
+++ trunk/nuiton-matrix-gui/src/main/resources/i18n/nuiton-matrix-gui_fr_FR.properties 2011-04-08 14:03:40 UTC (rev 348)
@@ -17,6 +17,7 @@
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.dimnameindex=Dimension %d
nuitonmatrix.viewer.graphcomborender.bar=Rendu en barres verticales
nuitonmatrix.viewer.graphcomborender.bar.3d=Rendu en barres verticales 3D
nuitonmatrix.viewer.graphcomborender.bar.stacked=Rendu en barres verticales empil\u00E9es
@@ -28,5 +29,6 @@
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
1
0
April 8, 2011
Author: echatellier
Date: 2011-04-08 15:10:03 +0200 (Fri, 08 Apr 2011)
New Revision: 347
Url: http://nuiton.org/repositories/revision/nuiton-matrix/347
Log:
Modify version (api break)
Modified:
trunk/nuiton-matrix-gui/pom.xml
trunk/nuiton-matrix/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-matrix/pom.xml
===================================================================
--- trunk/nuiton-matrix/pom.xml 2011-04-07 12:26:45 UTC (rev 346)
+++ trunk/nuiton-matrix/pom.xml 2011-04-08 13:10:03 UTC (rev 347)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>matrix</artifactId>
- <version>2.1.1-SNAPSHOT</version>
+ <version>2.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.matrix</groupId>
Modified: trunk/nuiton-matrix-gui/pom.xml
===================================================================
--- trunk/nuiton-matrix-gui/pom.xml 2011-04-07 12:26:45 UTC (rev 346)
+++ trunk/nuiton-matrix-gui/pom.xml 2011-04-08 13:10:03 UTC (rev 347)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>matrix</artifactId>
- <version>2.1.1-SNAPSHOT</version>
+ <version>2.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.matrix</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-04-07 12:26:45 UTC (rev 346)
+++ trunk/pom.xml 2011-04-08 13:10:03 UTC (rev 347)
@@ -14,7 +14,7 @@
</parent>
<artifactId>matrix</artifactId>
- <version>2.1.1-SNAPSHOT</version>
+ <version>2.2-SNAPSHOT</version>
<modules>
<module>nuiton-matrix</module>
1
0
r346 - in trunk/nuiton-matrix-gui/src: main/java/org/nuiton/math/matrix/viewer test/java/org/nuiton/math/matrix/viewer
by echatellier@users.nuiton.org April 7, 2011
by echatellier@users.nuiton.org April 7, 2011
April 7, 2011
Author: echatellier
Date: 2011-04-07 14:26:45 +0200 (Thu, 07 Apr 2011)
New Revision: 346
Url: http://nuiton.org/repositories/revision/nuiton-matrix/346
Log:
Evolution #1437: Remove MatrixPanelViewer matrix list
Evolution #1441: Add dimension action support
Added:
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionAction.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/SumAllAction.java
Modified:
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java
trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/package-info.java
trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java
Added: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionAction.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionAction.java (rev 0)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionAction.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -0,0 +1,82 @@
+/*
+ * #%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.viewer;
+
+import javax.swing.Icon;
+
+/**
+ * Action de regroupement des valeurs d'une dimension, pour faire des sommes...
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public interface MatrixDimensionAction {
+
+ /**
+ * Action icon.
+ *
+ * @return action icon
+ */
+ public Icon getIcon();
+
+ /**
+ * Action selected icon.
+ *
+ * @return action selected icon
+ */
+ public Icon getSelectedIcon();
+
+ /**
+ * Return l'index de la dimension sur lequel porte l'action.
+ *
+ * Used only if {@link #getDimensionType} returns {@code null}.
+ *
+ * Return -1 to affect all dimensions.
+ *
+ * @return dimension index
+ */
+ public int getDimensionIndex();
+
+ /**
+ * Return le type de dimension concerné par les actions.
+ *
+ * @return dimension type
+ */
+ public Class<?> getDimensionType();
+
+ /**
+ * Method getSumStep indique le pas d'increment pour la somme sur
+ * la dimension.
+ *
+ * @return -1 indique de faire la somme sur tous les elements. 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();
+}
Property changes on: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java 2011-04-04 13:09:43 UTC (rev 345)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixDimensionPanel.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 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
@@ -31,21 +31,24 @@
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
+import javax.swing.ButtonGroup;
+import javax.swing.ButtonModel;
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 javax.swing.JToggleButton.ToggleButtonModel;
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.
@@ -56,31 +59,45 @@
* Last update : $Date$
* By : $Author$
*/
-public class MatrixDimensionPanel extends JPanel {
+public class MatrixDimensionPanel extends JPanel implements PropertyChangeListener {
/** serialVersionUID. */
private static final long serialVersionUID = -1919447532660452240L;
/** Class logger. */
- private static Log log = LogFactory.getLog(AbstractMatrixND.class);
+ private static Log log = LogFactory.getLog(MatrixDimensionPanel.class);
/** Matrix to display (original). */
protected MatrixND matrix;
protected List<SubDimensionPanel> subPanelList;
+ protected List<MatrixDimensionAction> matrixDimentionActions;
+
public MatrixDimensionPanel() {
setLayout(new GridLayout(0, 1));
subPanelList = new ArrayList<MatrixDimensionPanel.SubDimensionPanel>();
+ matrixDimentionActions = new ArrayList<MatrixDimensionAction>();
+
+ // default sum all action
+ matrixDimentionActions.add(new SumAllAction());
}
- public MatrixND getMatrix() {
- return matrix;
+ /**
+ * Add new action. Protected to force call on MatrixViewerPanel.
+ *
+ * @param matrixDimentionAction new action
+ */
+ protected void addMatrixDimentionAction(MatrixDimensionAction matrixDimentionAction) {
+ matrixDimentionActions.add(matrixDimentionAction);
}
- public void setMatrix(MatrixND matrix) {
- this.matrix = matrix;
-
+ /*
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ this.matrix = (MatrixND)evt.getNewValue();
buildDimensionPanel();
validate();
repaint();
@@ -91,43 +108,108 @@
return reducedMatrix;
}
- protected static class SubDimensionPanel extends JPanel {
+ /** Button model from button containing action instance */
+ protected static class MatrixActionButtonModel extends ToggleButtonModel {
/** serialVersionUID. */
+ private static final long serialVersionUID = -5737246124430280412L;
+
+ protected MatrixDimensionAction matrixAction;
+
+ public MatrixActionButtonModel(MatrixDimensionAction matrixAction) {
+ this.matrixAction = matrixAction;
+ }
+
+ public MatrixDimensionAction getMatrixAction() {
+ return matrixAction;
+ }
+ }
+
+ protected class SubDimensionPanel extends JPanel {
+
+ /** serialVersionUID. */
private static final long serialVersionUID = 9170588695850504050L;
+ protected int index;
+
protected String semanticName;
protected List<?> semantic;
- protected JToggleButton sumAll;
+ /**
+ * Declaration d'un button group avec possibilité de deselectionne
+ * tous les boutons (methode setSelected surchargée).
+ */
+ protected ButtonGroup buttonGroup = new ButtonGroup() {
+ @Override
+ public void setSelected(ButtonModel m, boolean b) {
+ if (b) {
+ super.setSelected(m, b);
+ }
+ else {
+ clearSelection();
+ }
+ }
+ };
+
+ /**
+ * Gere a la main le group de bouton, car sinon, lors que le premier
+ * bouton est sélectionné, on ne peut pas le deselection
+ *
+ protected List<JToggleButton> buttonList = new ArrayList<JToggleButton>();*/
protected JList semList;
- public SubDimensionPanel(String semanticName, List<?> semantic) {
+ public SubDimensionPanel(int index, String semanticName, List<?> semantic) {
super(new GridBagLayout());
+ this.index = index;
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));
-
+
+ int nbActionAdded = 0;
+ for (MatrixDimensionAction matrixDimensionAction : matrixDimentionActions) {
+
+ boolean addSumAll = false;
+ Class<?> semType = matrixDimensionAction.getDimensionType();
+ if (semType != null) {
+ for (Object semValue : semantic) {
+ if (semValue != null && semValue.getClass().isAssignableFrom(semType)) {
+ addSumAll = true;
+ }
+ }
+ }
+ else {
+ int semIndex = matrixDimensionAction.getDimensionIndex();
+ if (semIndex == -1 || semIndex == index) {
+ addSumAll = true;
+ }
+ }
+
+ if (addSumAll) {
+ // sum all button
+ JToggleButton sumAll = new JToggleButton(matrixDimensionAction.getIcon());
+ sumAll.setSelectedIcon(matrixDimensionAction.getSelectedIcon());
+ sumAll.setModel(new MatrixActionButtonModel(matrixDimensionAction));
+ add(sumAll, new GridBagConstraints(1 + nbActionAdded, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
+ GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
+ buttonGroup.add(sumAll);
+ nbActionAdded++;
+ }
+ }
+
// 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,
+ add(new JScrollPane(semList), new GridBagConstraints(0, 1, 1 + nbActionAdded, 1, 1, 1, GridBagConstraints.WEST,
GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
}
@@ -139,14 +221,15 @@
* 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
+ * @return -1 indique de faire la somme sur tous les elements. 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;
+ MatrixActionButtonModel buttonModel = (MatrixActionButtonModel)buttonGroup.getSelection();
+ if (buttonModel != null) {
+ result = buttonModel.getMatrixAction().getSumStep();
}
return result;
}
@@ -162,7 +245,7 @@
if (matrix != null) {
int index = 0;
for (List<?> semantic : matrix.getSemantics()) {
- SubDimensionPanel dimPanel = new SubDimensionPanel(_(matrix.getDimensionName(index)), semantic);
+ SubDimensionPanel dimPanel = new SubDimensionPanel(index, _(matrix.getDimensionName(index)), semantic);
add(dimPanel);
subPanelList.add(dimPanel);
index++;
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java 2011-04-04 13:09:43 UTC (rev 345)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixRenderer.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 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
@@ -45,8 +45,9 @@
/**
* Renderer component for matrix.
*
- * @param matrix matrix to display
+ * @param matrix matrix to display (can be null with default rendering support)
* @return component
+ * @see MatrixViewerPanel#addMatrixRenderer(MatrixRenderer, boolean)
*/
Component getComponent(MatrixND matrix);
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java 2011-04-04 13:09:43 UTC (rev 345)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/MatrixViewerPanel.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 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
@@ -34,21 +34,18 @@
import java.awt.Insets;
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.Collection;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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.JOptionPane;
import javax.swing.JPanel;
@@ -74,32 +71,24 @@
/** 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";
+ public static final String PROPERTY_MATRIX = "matrix";
- /** 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;
+ protected Map<MatrixRenderer, Boolean> matrixRenderers;
/** Matrix filters (used after matrix reduction). */
protected List<MatrixFilter> matrixFilters;
- /** Matrices to render (depend on {@link #matrixComboVisible} to {@code true}). */
- protected List<MatrixND> matrices;
+ /** La matrice courrement affichées. */
+ protected MatrixND matrix;
- /** Matrix list combo box. */
- protected MatrixComboBox matrixComboBox;
-
protected MatrixDimensionPanel dimensionPanel;
protected RadioButtonRenderingPanel radioPanel;
@@ -115,24 +104,14 @@
protected Map<MatrixRenderer, Component> componentForRenderers;
public MatrixViewerPanel() {
- matrixRenderers = new ArrayList<MatrixRenderer>();
+ // keep order
+ matrixRenderers = new LinkedHashMap<MatrixRenderer, Boolean>();
matrixFilters = new ArrayList<MatrixFilter>();
- matrices = new ArrayList<MatrixND>();
componentForRenderers = new HashMap<MatrixRenderer, Component>();
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;
}
@@ -143,16 +122,24 @@
firePropertyChange(PROPERTY_MATRIX_RENDERER_SOLUTION, oldValue, matrixRendererSolution);
}
- public boolean addMatrixRenderer(MatrixRenderer matrixRenderer) {
- boolean result = matrixRenderers.add(matrixRenderer);
+ public void addMatrixRenderer(MatrixRenderer matrixRenderer) {
+ addMatrixRenderer(matrixRenderer, false);
+ }
+
+ /**
+ * Add new matrix renderer.
+ *
+ * @param matrixRenderer matrix renderer
+ * @param defautRenderer renderer can be called with a null matrix to get default rendering
+ */
+ public void addMatrixRenderer(MatrixRenderer matrixRenderer, boolean defautRenderer) {
+ matrixRenderers.put(matrixRenderer, defautRenderer);
firePropertyChange(PROPERTY_MATRIX_RENDERERS, null, matrixRenderers);
- return result;
}
- public boolean removeMatrixRenderer(Object matrixRenderer) {
- boolean result = matrixRenderers.remove(matrixRenderer);
+ public void removeMatrixRenderer(Object matrixRenderer) {
+ matrixRenderers.remove(matrixRenderer);
firePropertyChange(PROPERTY_MATRIX_RENDERERS, null, matrixRenderers);
- return result;
}
/**
@@ -172,83 +159,35 @@
return result;
}
- public void addMatrix(MatrixND... matrices) {
- for (MatrixND matrix : matrices) {
- this.matrices.add(matrix);
- }
- firePropertyChange(PROPERTY_MATRICES, null, matrices);
+ /**
+ * Set currently displayed matrix.
+ *
+ * @param matrix new matrix to display
+ */
+ public void setMatrix(MatrixND matrix) {
+ MatrixND oldValue = this.matrix;
+ this.matrix = matrix;
+ firePropertyChange(PROPERTY_MATRIX, oldValue, matrix);
}
- public void removeMatrix(Object... matrices) {
- for (Object matrix : matrices) {
- this.matrices.remove(matrix);
- }
- firePropertyChange(PROPERTY_MATRICES, null, matrices);
+ /**
+ * Get currently displayed matrix.
+ *
+ * @return current matrix
+ */
+ public MatrixND getMatrix() {
+ return matrix;
}
- public void clearMatrix() {
- matrices.clear();
- firePropertyChange(PROPERTY_MATRICES, null, matrices);
+ /**
+ * Add new action.
+ *
+ * @param matrixDimentionAction new action
+ */
+ public void addMatrixDimentionAction(MatrixDimensionAction matrixDimentionAction) {
+ dimensionPanel.addMatrixDimentionAction(matrixDimentionAction);
}
- /** 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 {
@@ -259,10 +198,9 @@
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());
+ if (value != null) {
+ matrixName = _((String)value);
}
return super.getListCellRendererComponent(list, matrixName, index, isSelected, cellHasFocus);
}
@@ -295,11 +233,11 @@
private static final long serialVersionUID = 2591696695747738619L;
protected ButtonGroup buttonGroup;
-
+
public IconButtonRenderingPanel() {
super(new GridBagLayout());
}
-
+
/*
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
@@ -309,13 +247,13 @@
validate();
repaint();
}
-
+
/**
* Rebuild radio button lists.
*/
protected void rebuildPanel() {
removeAll();
-
+
JButton renderButton = new JButton(Resource.getIcon("/icons/1rightarrow.png"));
renderButton.setActionCommand("render");
renderButton.addActionListener(this);
@@ -326,11 +264,11 @@
int index = 1;
buttonGroup = new ButtonGroup();
- for (MatrixRenderer renderer : matrixRenderers) {
+ for (MatrixRenderer renderer : matrixRenderers.keySet()) {
JToggleButton radioButton = new JToggleButton(renderer.getIcon());
radioButton.addActionListener(this);
radioButton.setModel(new RendererButtonModel(renderer));
-
+
// auto select first matrix renderer
if (index == 1) {
radioButton.setSelected(true);
@@ -375,7 +313,7 @@
else {
// get all display component for each renderer
componentForRenderers.clear();
- for (MatrixRenderer matrixRenderer : matrixRenderers) {
+ for (MatrixRenderer matrixRenderer : matrixRenderers.keySet()) {
Component component = matrixRenderer.getComponent(matrix);
componentForRenderers.put(matrixRenderer, component);
}
@@ -436,7 +374,7 @@
int index = 0;
buttonGroup = new ButtonGroup();
- for (MatrixRenderer renderer : matrixRenderers) {
+ for (MatrixRenderer renderer : matrixRenderers.keySet()) {
JRadioButton radioButton = new JRadioButton(renderer.getName());
radioButton.addActionListener(this);
radioButton.setModel(new RendererButtonModel(renderer));
@@ -491,19 +429,10 @@
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());
- matrixComboBox.setVisible(matrixComboVisible);
- 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);
+ addPropertyChangeListener(PROPERTY_MATRIX, dimensionPanel);
// fleche de d'action de rendu
// render type : icon
@@ -528,7 +457,7 @@
/**
* Set rendering component in rendering container.
*/
- protected void updateSelectedRenderingComponent() {
+ public void updateSelectedRenderingComponent() {
renderingComponentContainer.removeAll();
MatrixRenderer matrixRenderer = null;
@@ -541,12 +470,23 @@
break;
}
- if (matrixRenderer != null) {
- Component component = componentForRenderers.get(matrixRenderer);
- if (component != null) {
- renderingComponentContainer.add(component, BorderLayout.CENTER);
+ if (!componentForRenderers.isEmpty()) {
+ if (matrixRenderer != null) {
+ Component component = componentForRenderers.get(matrixRenderer);
+ if (component != null) {
+ renderingComponentContainer.add(component, BorderLayout.CENTER);
+ }
}
}
+ else {
+ // if enables default rendering
+ if (matrixRenderers.get(matrixRenderer)) {
+ Component component = matrixRenderer.getComponent(null);
+ if (component != null) {
+ renderingComponentContainer.add(component, BorderLayout.CENTER);
+ }
+ }
+ }
renderingComponentContainer.validate();
renderingComponentContainer.repaint();
Added: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/SumAllAction.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/SumAllAction.java (rev 0)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/SumAllAction.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -0,0 +1,85 @@
+/*
+ * #%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.viewer;
+
+import javax.swing.Icon;
+
+import org.nuiton.util.Resource;
+
+/**
+ * Sum all raw action.
+ *
+ * Default matrix viewer panel action to sum all elements.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class SumAllAction implements MatrixDimensionAction {
+
+ /*
+ * @see org.nuiton.math.matrix.viewer.MatrixGroupAction#getIcon()
+ */
+ @Override
+ public Icon getIcon() {
+ return Resource.getIcon("/icons/sigma-barre.gif");
+ }
+
+ /*
+ * @see org.nuiton.math.matrix.viewer.MatrixGroupAction#getSelectedIcon()
+ */
+ @Override
+ public Icon getSelectedIcon() {
+ return Resource.getIcon("/icons/sigma.gif");
+ }
+
+ /*
+ * @see org.nuiton.math.matrix.viewer.MatrixGroupAction#getDimensionIndex()
+ */
+ @Override
+ public int getDimensionIndex() {
+ return -1;
+ }
+
+ /*
+ * @see org.nuiton.math.matrix.viewer.MatrixGroupAction#getDimensionType()
+ */
+ @Override
+ public Class<?> getDimensionType() {
+ return null;
+ }
+
+ /*
+ * @see org.nuiton.math.matrix.viewer.MatrixGroupAction#getSumStep()
+ */
+ @Override
+ public int getSumStep() {
+ // sum all => -1
+ return -1;
+ }
+}
Property changes on: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/SumAllAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/package-info.java
===================================================================
--- trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/package-info.java 2011-04-04 13:09:43 UTC (rev 345)
+++ trunk/nuiton-matrix-gui/src/main/java/org/nuiton/math/matrix/viewer/package-info.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -3,7 +3,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2004 - 2010 CodeLutin, Chatellier Eric
+ * 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
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-04 13:09:43 UTC (rev 345)
+++ trunk/nuiton-matrix-gui/src/test/java/org/nuiton/math/matrix/viewer/MatrixViewerPanelTest.java 2011-04-07 12:26:45 UTC (rev 346)
@@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;
+import javax.swing.Icon;
import javax.swing.JFrame;
import org.junit.Test;
@@ -38,6 +39,7 @@
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;
/**
* Test for matrix viewer panel.
@@ -51,14 +53,14 @@
public class MatrixViewerPanelTest {
protected MatrixND getTestMatrix(boolean proxy) {
- 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<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);
List<String> cities = new ArrayList<String>();
cities.add("Nantes");
@@ -73,15 +75,15 @@
matrix = MatrixFactory.getInstance().createProxy("test matrix", new List<?>[]{years, cities}, new String[]{"Years", "Cities"}, new MatrixProvider() {
@Override
public void fillValues(MatrixND matrix) {
- MatrixHelper.fill(matrix, 10000.0);
- matrix.setValue(0, 0, 1000);
+ MatrixHelper.fill(matrix, Math.random()*10000);
+ matrix.setValue(0, 0, Math.random()*10000);
}
});
}
else {
matrix = MatrixFactory.getInstance().create("test matrix", new List<?>[]{years, cities}, new String[]{"Years", "Cities"});
- MatrixHelper.fill(matrix, 10000.0);
- matrix.setValue(0, 0, 1000);
+ MatrixHelper.fill(matrix, Math.random()*10000);
+ matrix.setValue(0, 0, Math.random()*10000);
}
return matrix;
}
@@ -95,7 +97,7 @@
MatrixViewerPanel panel = new MatrixViewerPanel();
MatrixND testMatrix = getTestMatrix(false);
- panel.addMatrix(testMatrix, testMatrix);
+ panel.setMatrix(testMatrix);
panel.addMatrixRenderer(new MatrixInfoTableRenderer());
panel.addMatrixRenderer(new MatrixChartRenderer());
panel.addMatrixRenderer(new MatrixPanelRenderer());
@@ -121,9 +123,53 @@
MatrixViewerPanel panel = new MatrixViewerPanel();
MatrixND testMatrix = getTestMatrix(true);
- panel.addMatrix(testMatrix, testMatrix);
panel.addMatrixRenderer(new MatrixInfoTableRenderer());
panel.addMatrixRenderer(new MatrixChartRenderer());
+ panel.addMatrixDimentionAction(new MatrixDimensionAction() {
+ @Override
+ public int getSumStep() {
+ return 2;
+ }
+ @Override
+ public Icon getSelectedIcon() {
+ return null;
+ }
+ @Override
+ public Icon getIcon() {
+ return Resource.getIcon("/icons/table.png");
+ }
+ @Override
+ public Class<?> getDimensionType() {
+ return null;
+ }
+ @Override
+ public int getDimensionIndex() {
+ return 1;
+ }
+ });
+ panel.addMatrixDimentionAction(new MatrixDimensionAction() {
+ @Override
+ public int getSumStep() {
+ return 3;
+ }
+ @Override
+ public Icon getSelectedIcon() {
+ return null;
+ }
+ @Override
+ public Icon getIcon() {
+ return Resource.getIcon("/icons/chart_curve.png");
+ }
+ @Override
+ public Class<?> getDimensionType() {
+ return Integer.class;
+ }
+ @Override
+ public int getDimensionIndex() {
+ return -1;
+ }
+ });
+ panel.setMatrix(testMatrix);
frame.add(panel);
frame.pack();
1
0
r345 - in trunk/src/site: . resources resources/images rst
by echatellier@users.nuiton.org April 4, 2011
by echatellier@users.nuiton.org April 4, 2011
April 4, 2011
Author: echatellier
Date: 2011-04-04 15:09:43 +0200 (Mon, 04 Apr 2011)
New Revision: 345
Url: http://nuiton.org/repositories/revision/nuiton-matrix/345
Log:
Add doc about matrix panel viewer.
Added:
trunk/src/site/resources/
trunk/src/site/resources/images/
trunk/src/site/resources/images/matrixpanelviewer.png
trunk/src/site/rst/gui-matrixpanelviewer.rst
Modified:
trunk/src/site/site_fr.xml
Added: trunk/src/site/resources/images/matrixpanelviewer.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/images/matrixpanelviewer.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/src/site/rst/gui-matrixpanelviewer.rst
===================================================================
--- trunk/src/site/rst/gui-matrixpanelviewer.rst (rev 0)
+++ trunk/src/site/rst/gui-matrixpanelviewer.rst 2011-04-04 13:09:43 UTC (rev 345)
@@ -0,0 +1,89 @@
+MatrixPanelViewer component
+===========================
+
+This component goals are :
+ - display a list of matrix to manipulate
+ - display dimension of selected matrix with semantic
+ - render selected matrix with selected dimensions
+
+.. image:: images/matrixpanelviewer.png
+
+
+Simple matrix viewing
+---------------------
+
+This component can be used to display only one matrix.
+
+Use following code ::
+
+ MatrixViewerPanel matrixViewerPanel = new MatrixViewerPanel();
+ matrixViewerPanel.setMatrix(myMatrix);
+
+Then ``MatrixViewerPanel`` is a simple swing component, you can place it
+wherever you want.
+
+
+Display a list of matrix
+------------------------
+
+You can display multiples matrix in a ``MatrixViewerPanel``. User will have
+to select it in a ``ComboBox``.
+
+For performance reason, instantiating multiples huge matrix at init time can't
+be done. The matrix list can only contains matrix name, and matrix data
+will be loaded with a provider when user select it.
+
+Code example::
+
+ MatrixViewerPanel matrixViewerPanel = new MatrixViewerPanel();
+ matrixViewerPanel.setComboBoxVisible(true);
+ matrixViewerPanel.addMatrix("myMatrix1");
+ matrixViewerPanel.addMatrix("myMatrix2");
+ matrixViewerPanel.setMatrixLabelProvider(new MyMatrixLabelProvider());
+
+
+Use various renderer
+--------------------
+
+MatrixPanelViewer can render matrix in various way, including your own (just
+implements ``MatrixRenderer`` interface) ::
+
+ MatrixViewerPanel matrixViewerPanel = new MatrixViewerPanel();
+ matrixViewerPanel.addMatrixRenderer(new MatrixChartRenderer());
+ matrixViewerPanel.addMatrixRenderer(new MatrixInfoTableRenderer());
+ matrixViewerPanel.addMatrixRenderer(new MyCustomMatrixRenderer());
+
+
+Use matrix filter
+-----------------
+
+You can also add a matrix filter to modify matrix just after dimension
+selection and before applying all renderers.
+
+For example, you can use a filter to remove non significant values
+from a matrix (0 at each bounds).
+
+To do so::
+
+ MatrixViewerPanel matrixViewerPanel = new MatrixViewerPanel();
+ matrixViewerPanel.addMatrixFilter(new MyCustomFilter());
+
+
+Use matrix proxy and data provider
+----------------------------------
+
+When matrix contains huge set of data, render then is not possible. Do solve
+this, you can use a matrix "empty" just filled with semantics for each
+dimension. At rendering phase, ``MatrixViewerPanel`` will call getSubMatrix()
+with selected semantics on proxy witch is implemented by a call to
+``MatrixProvider`` to get filled data.
+
+Example::
+
+ MatrixND matrix = MatrixFactory.getInstance().createProxy("myMatrixName,
+ new List<?>[] { semantic1 , semantic2, semantic3, semantic4},
+ new String[] {"semantic1", "semantic2", "semantic3", "semantic4"},
+ new MyMatrixProvider());
+ MatrixViewerPanel matrixViewerPanel = new MatrixViewerPanel();
+ matrixViewerPanel.setMatrix(matrix);
+
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2011-03-21 14:45:21 UTC (rev 344)
+++ trunk/src/site/site_fr.xml 2011-04-04 13:09:43 UTC (rev 345)
@@ -45,6 +45,7 @@
<menu name="Utilisateur">
<item href="index.html" name="Accueil"/>
+ <item href="gui-matrixpanelviewer.png" name="Matrix panel viewer"/>
</menu>
<menu name="Développeur">
1
0