Author: chatellier
Date: 2009-03-09 16:20:46 +0000 (Mon, 09 Mar 2009)
New Revision: 1920
Added:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeCellRenderer.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModel.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorAction.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityNavigationTreeSelectionAdapter.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabbedPaneListener.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java
Log:
Add factor tree model and his test.
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2009-03-09 14:40:20 UTC (rev 1919)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -1,7 +1,20 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
package fr.ifremer.isisfish.ui.sensitivity;
@@ -21,7 +34,6 @@
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import jaxx.runtime.JAXXInitialContext;
-import org.apache.commons.beanutils.BeanUtils;
import org.codelutin.math.matrix.MatrixND;
import org.codelutin.math.matrix.gui.MatrixPanelEditor;
import org.codelutin.topia.persistence.TopiaEntity;
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorAction.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorAction.java 2009-03-09 14:40:20 UTC (rev 1919)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorAction.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -1,12 +1,23 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
package fr.ifremer.isisfish.ui.sensitivity;
-import fr.ifremer.isisfish.datastore.SensitivityStorage;
-
/**
*
* @author letellier
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeCellRenderer.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeCellRenderer.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeCellRenderer.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -0,0 +1,72 @@
+/* *##%
+ * Copyright (C) 2009 Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.ui.sensitivity;
+
+import java.awt.Component;
+import java.util.List;
+
+import javax.swing.JLabel;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+
+/**
+ * Factor tree cell renderer.
+ *
+ * @author chatellier
+ * @version $Revision: 1.0 $
+ *
+ * Last update : $Date: 9 mars 2009 $
+ * By : $Author: chatellier $
+ */
+public class FactorTreeCellRenderer extends DefaultTreeCellRenderer {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 1686424876690392268L;
+
+ /*
+ * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
+ */
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean selected, boolean expanded, boolean leaf, int row,
+ boolean hasFocus) {
+
+ JLabel c = (JLabel)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
+
+ if (value instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ Object userObject = node.getUserObject();
+
+ if (userObject instanceof List) {
+ c.setText("Facteurs : ");
+ }
+ else if (userObject instanceof Factor) {
+ Factor<?> factor = (Factor)userObject;
+ //c = new JLabel(factor.getName());
+ c.setText(factor.getName());
+ }
+ }
+
+ return c;
+ }
+
+}
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModel.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModel.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModel.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -0,0 +1,128 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.ui.sensitivity;
+
+import java.util.List;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+
+/**
+ * Cette classe gere l'affichage d'une liste de facteurs dans l'arbre.
+ *
+ * @author chatellier
+ * @version $Revision: 2011 $
+ *
+ * Last update : $Date: 2008-06-13 11:05:57 +0200 (ven., 13 juin 2008)
+ * $ By : $Author: chatellier $
+ */
+public class FactorTreeModel extends DefaultTreeModel {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 593284613450915826L;
+
+ /**
+ * Constructor.
+ *
+ * @param root root node
+ */
+ public FactorTreeModel(TreeNode root) {
+ super(root);
+ }
+
+ /*
+ * @see javax.swing.tree.DefaultTreeModel#getChild(java.lang.Object, int)
+ */
+ @Override
+ public Object getChild(Object parent, int index) {
+
+ Object value = null;
+
+ if (parent instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent;
+ Object userObject = node.getUserObject();
+
+ if (userObject instanceof List) {
+ Object localUserObject = ((DefaultMutableTreeNode)root).getUserObject();
+ List<Factor<?>> factors = (List<Factor<?>>)localUserObject;
+ value = new DefaultMutableTreeNode(factors.get(index));
+ }
+ }
+
+ return value;
+ }
+
+ /*
+ * @see org.jdesktop.swingx.treetable.DefaultTreeTableModel#getChildCount(java.lang.Object)
+ */
+ @Override
+ public int getChildCount(Object parent) {
+
+ int childCount = 0;
+
+ if (parent instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent;
+ Object userObject = node.getUserObject();
+
+ if (userObject instanceof List) {
+ Object localUserObject = ((DefaultMutableTreeNode)root).getUserObject();
+ List<Factor<?>> factors = (List<Factor<?>>)localUserObject;
+ childCount = factors.size();
+ }
+ }
+
+ return childCount;
+ }
+
+ /*
+ * @see javax.swing.tree.DefaultTreeModel#getIndexOfChild(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int getIndexOfChild(Object parent, Object child) {
+
+ int childIndex = -1;
+
+ if (parent instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent;
+ Object userObject = node.getUserObject();
+ DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
+ Object childUserObject = childNode.getUserObject();
+
+ if (userObject instanceof List) {
+ Object localUserObject = ((DefaultMutableTreeNode)root).getUserObject();
+ List<Factor<?>> factors = (List<Factor<?>>)localUserObject;
+ childIndex = factors.indexOf(childUserObject);
+ }
+ }
+
+ return childIndex;
+ }
+
+ /*
+ * @see javax.swing.tree.DefaultTreeModel#isLeaf(java.lang.Object)
+ */
+ @Override
+ public boolean isLeaf(Object node) {
+ return getChildCount(node) == 0;
+ }
+
+}
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityNavigationTreeSelectionAdapter.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityNavigationTreeSelectionAdapter.java 2009-03-09 14:40:20 UTC (rev 1919)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityNavigationTreeSelectionAdapter.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -1,7 +1,20 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
package fr.ifremer.isisfish.ui.sensitivity;
@@ -28,15 +41,11 @@
import jaxx.runtime.swing.navigation.NavigationTreeSelectionAdapterWithCardLayout;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
import org.codelutin.topia.persistence.TopiaEntity;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
-import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import java.awt.Component;
-import org.hibernate.transaction.JOTMTransactionManagerLookup;
/** @author letellier */
public class SensitivityNavigationTreeSelectionAdapter extends NavigationTreeSelectionAdapterWithCardLayout {
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabbedPaneListener.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabbedPaneListener.java 2009-03-09 14:40:20 UTC (rev 1919)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabbedPaneListener.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -1,15 +1,26 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
package fr.ifremer.isisfish.ui.sensitivity;
import fr.ifremer.isisfish.ui.input.InputContentUI;
-import fr.ifremer.isisfish.ui.input.InputSaveVerifier;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-03-09 14:40:20 UTC (rev 1919)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -17,8 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*##%*/
-
-
package fr.ifremer.isisfish.entity;
import static org.codelutin.i18n.I18n._;
@@ -212,10 +210,6 @@
log.error("No X11 display available", he);
}
}
- System.out.println("end");
}
-
}
-
-
Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java (rev 0)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java 2009-03-09 16:20:46 UTC (rev 1920)
@@ -0,0 +1,157 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.ui.sensitivity;
+
+import static org.codelutin.i18n.I18n._;
+
+import java.awt.HeadlessException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeNode;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.junit.Test;
+
+import fr.ifremer.isisfish.simulator.sensitivity.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.DiscreteDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+
+/**
+ * Sensitivity tree model test.
+ *
+ * Created: 29 juin 2006 20:19:32
+ *
+ * @author poussin
+ * @version $Revision: 1781 $
+ *
+ * Last update: $Date: 2009-02-03 17:44:23 +0100 (mar 03 fév 2009) $
+ * by : $Author: chatellier $
+ */
+public class FactorTreeModelTest{
+
+ /** Logger for this class */
+ private static final Log log = LogFactory.getLog(FactorTreeModelTest.class);
+
+ /**
+ * Return une liste de facteur à afficher.
+ *
+ * @return la liste des facteur
+ */
+ protected List<Factor<? extends Serializable>> getFactors() {
+
+ Factor<Integer> factor1 = new Factor<Integer>("testint");
+ ContinuousDomain<Integer> domain1 = new ContinuousDomain<Integer>();
+ domain1.setMinBound(0);
+ domain1.setMaxBound(50);
+ factor1.setDomain(domain1);
+ factor1.setPath("org.codelutin.factor#1234567890#0.12242345354#name");
+ factor1.setValueForIdentifier(49);
+
+ // matrix 1
+ MatrixND matrix1 = MatrixFactory.getInstance().create("test1",
+ new int[] { 3, 2 }, new String[] { "col1", "col2" });
+ matrix1.setValue(new int[] { 0, 0 }, 13);
+ matrix1.setValue(new int[] { 0, 1 }, -14);
+ matrix1.setValue(new int[] { 1, 0 }, 21);
+ matrix1.setValue(new int[] { 1, 1 }, 2);
+ matrix1.setValue(new int[] { 2, 0 }, 12);
+ matrix1.setValue(new int[] { 2, 1 }, -1);
+
+ // matrix 2
+ MatrixND matrix2 = MatrixFactory.getInstance().create("test2",
+ new int[] { 2, 3 }, new String[] { "col1", "col2" });
+ matrix2.setValue(new int[] { 0, 0 }, 9999);
+ matrix2.setValue(new int[] { 0, 1 }, 15000);
+ matrix2.setValue(new int[] { 0, 2 }, -40000);
+ matrix2.setValue(new int[] { 1, 0 }, 21345);
+ matrix2.setValue(new int[] { 1, 1 }, 81000);
+ matrix2.setValue(new int[] { 1, 2 }, -13000);
+
+ // factor
+ Factor<MatrixND> factor2 = new Factor<MatrixND>("testmatrix");
+ DiscreteDomain<MatrixND> domain2 = new DiscreteDomain<MatrixND>();
+ domain2.getValues().put("m1", matrix1);
+ domain2.getValues().put("m2", matrix2);
+ factor2.setDomain(domain2);
+ factor2.setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim");
+ factor2.setValueForIdentifier("m2");
+
+ List<Factor<? extends Serializable>> factors1 = new ArrayList<Factor<? extends Serializable>>();
+ factors1.add(factor1);
+ factors1.add(factor2);
+
+ return factors1;
+ }
+
+ /*
+ * Test tree rendering.
+ */
+ @Test
+ public void testJTreeModel() throws InterruptedException {
+
+ TreeNode root = new DefaultMutableTreeNode(getFactors());
+ final JTree tree = new JTree(root);
+ tree.setRootVisible(true);
+ FactorTreeModel model = new FactorTreeModel(root);
+ tree.setModel(model);
+ tree.setCellRenderer(new FactorTreeCellRenderer());
+
+ try {
+ final JDialog dialog = new JDialog();
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ JOptionPane.showMessageDialog(dialog, tree,_("Tree factor model"), JOptionPane.INFORMATION_MESSAGE);
+ }
+ });
+
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ dialog.dispose();
+ }
+ });
+ t.start();
+
+ // it would really be nice to wait the thread, otherwise the test
+ // means nothing!!!
+ t.join();
+ } catch (HeadlessException he) {
+ if(log.isErrorEnabled()) {
+ log.error("No X11 display available", he);
+ }
+ }
+ }
+}
+
+