[Lutinmatrix-commits] r129 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix/gui
Author: sletellier Date: 2009-03-23 14:07:41 +0000 (Mon, 23 Mar 2009) New Revision: 129 Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java Modified: lutinmatrix/trunk/pom.xml lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java Log: JAXX implamentation of MatrixPanelEditor Modified: lutinmatrix/trunk/pom.xml =================================================================== --- lutinmatrix/trunk/pom.xml 2009-03-20 13:46:40 UTC (rev 128) +++ lutinmatrix/trunk/pom.xml 2009-03-23 14:07:41 UTC (rev 129) @@ -46,6 +46,14 @@ <scope>compile</scope> </dependency> + <!--Jaxx--> + <dependency> + <groupId>org.codelutin.jaxx</groupId> + <artifactId>jaxx-runtime-swing</artifactId> + <version>${jaxx.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -66,7 +74,8 @@ <!-- id du projet du labs --> <labs.id>63</labs.id> <labs.project>${project.artifactId}</labs.project> - + + <jaxx.version>1.3-SNAPSHOT</jaxx.version> <i18n.version>0.9</i18n.version> <lutinutil.version>1.0.3</lutinutil.version> </properties> @@ -74,6 +83,27 @@ <build> <plugins> + <plugin> + <groupId>org.codelutin.jaxx</groupId> + <artifactId>maven-jaxx-plugin</artifactId> + <version>${jaxx.version}</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + <configuration> + <extraImports> + <value>jaxx.runtime.SwingUtil</value> + <value>static jaxx.runtime.Util.getStringValue</value> + </extraImports> + <addSourcesToClassPath>true</addSourcesToClassPath> + <addProjectClassPath>true</addProjectClassPath> + </configuration> + </execution> + </executions> + </plugin> + <!-- plugin i18n --> <plugin> <groupId>org.codelutin</groupId> Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx (rev 0) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx 2009-03-23 14:07:41 UTC (rev 129) @@ -0,0 +1,172 @@ +<!-- +/* *##% + * Copyright (C) 2005 + * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * + * 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. + *##%*/ + +/* * + * IsisFish.java + * + * Created: 1 aout 2005 18:37:25 CEST + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision: 1312 $ + * + * Last update: $Date: 2008-08-28 10:21:07 +0200 (jeu, 28 aoû 2008) $ + * by : $Author: sletellier $ + */ + --> +<MatrixEditor id='jaxxMatrixManel' layout='{new BorderLayout()}'> + + <MatrixTableModel id='tableModel' javaBean='null'/> + + <!-- if true, use linear representation of matrix --> + <Boolean id='linearModel' javaBean='false'/> + + <!-- if false don't show default value in matrix (ex: 0) --> + <Boolean id='linearModelShowDefault' javaBean='false'/> + + <!-- Boolean to autorize matrice 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.Iterator; + +import org.codelutin.i18n.I18n; +import org.codelutin.math.matrix.MatrixFactory; +import org.codelutin.math.matrix.MatrixND; +import org.codelutin.util.ListenerSet; + +private final static int DEFAULT_WIDTH = 150; + +private final static int DEFAULT_HEIGHT = 150; + +protected ListenerSet listeners = new ListenerSet(); +protected MatrixPopupMenu popupMenu = null; +protected MatrixND matrix = null; +initObject(); +public JAXXMatrixEditor(MatrixND m, boolean dimensionEdit) { + this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT); +} + +public JAXXMatrixEditor(boolean dimensionEdit, int width, int height) { + this.dimensionEdit = dimensionEdit; + setPreferredSize(new Dimension(width, height)); +} + +public JAXXMatrixEditor(boolean dimensionEdit) { + this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT); +} + +public void setMatrix(MatrixND m){ + this.matrix = m; + initObject(); +} + +public MatrixND getMatrix() { + return matrix; +} + +protected MatrixFactory getFactory() { + return MatrixFactory.getInstance(); +} + +public void addMatrixListener(MatrixPanelListener l) { + listeners.add(l); +} + +public void removeMatrixPanelListener(MatrixPanelListener l) { + listeners.remove(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()); + editArea.setViewportView(table); + } + repaint(); +} + +protected void btnAction(){ + String dim; + dim = JOptionPane.showInputDialog(null, I18n._("lutinmatrix.create.matrix.message"), I18n._("lutinmatrix.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 (Iterator i = listeners.iterator(); i.hasNext();) { + MatrixPanelListener l = (MatrixPanelListener) i.next(); + l.matrixChanged(e); + } +} + ]]> + </script> + <JButton id='buttonEdit' text='lutinmatrix.create.matrix.button' enabled='{isDimensionEdit()}' + onActionPerformed='btnAction()' constraints='BorderLayout.SOUTH'/> + <JScrollPane id='editArea' constraints='BorderLayout.CENTER'> + <JTable id='table' autoResizeMode='{JTable.AUTO_RESIZE_OFF}' + cellSelectionEnabled='{true}' selectionMode='{ListSelectionModel.SINGLE_INTERVAL_SELECTION}'/> + </JScrollPane> +</MatrixEditor> \ No newline at end of file Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java (rev 0) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java 2009-03-23 14:07:41 UTC (rev 129) @@ -0,0 +1,77 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.codelutin.math.matrix.gui; + +import javax.swing.JButton; +import javax.swing.JPanel; +import org.codelutin.math.matrix.MatrixND; +import javax.swing.JTable; + +/** + * + * @author letellier + */ +public abstract class MatrixEditor extends JPanel { + + protected boolean enabled = false; + protected boolean visible = false; + + // Return JTable componant + public abstract JTable getTable(); + + // Return edit button componant + public abstract JButton getButtonEdit(); + + // Fire the matrix + protected abstract void fireEvent(); + + // Return matrixND + public abstract MatrixND getMatrix(); + + // Inisialize matrixND + public abstract void setMatrix(MatrixND matrix); + + /** + * @return Returns the linearModel. + */ + public abstract Boolean isLinearModel(); + + /** + * @param linearModel The linearModel to set. + */ + public abstract void setLinearModel(Boolean b); + + /** + * @return Returns the linearModelShowDefault. + */ + public abstract Boolean isLinearModelShowDefault(); + + /** + * @param linearModelShowDefault The linearModelShowDefault to set. + */ + public abstract void setLinearModelShowDefault(Boolean b); + + /** + * Enabled component + */ + public void setEnabled(Boolean enabled){ + this.enabled = enabled; + getTable().setEnabled(enabled); + getButtonEdit().setEnabled(enabled); + super.setEnabled(enabled); + } + + /** + * Enabled component + */ + public void setVisible(Boolean visible){ + this.visible = visible; + getTable().setVisible(visible); + getButtonEdit().setVisible(visible); + super.setVisible(visible); + } + +} Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-20 13:46:40 UTC (rev 128) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-23 14:07:41 UTC (rev 129) @@ -64,7 +64,7 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor +public class MatrixPanelEditor extends MatrixEditor implements TableModelListener { // MatrixPanelEditor /** serialVersionUID */ private static final long serialVersionUID = 2097859265435050946L; @@ -161,7 +161,7 @@ protected JButton bEdit = null; - protected JButton getButtonEdit() { + public JButton getButtonEdit() { if (bEdit == null) { bEdit = new JButton(I18n._("lutinmatrix.create.matrix.button")); bEdit.addActionListener(new ActionListener() { @@ -191,14 +191,14 @@ /** * @return Returns the linearModel. */ - public boolean isLinearModel() { + public Boolean isLinearModel() { return this.linearModel; } /** * @param linearModel The linearModel to set. */ - public void setLinearModel(boolean linearModel) { + public void setLinearModel(Boolean linearModel) { this.linearModel = linearModel; initObject(m); } @@ -206,14 +206,14 @@ /** * @return Returns the linearModelShowDefault. */ - public boolean isLinearModelShowDefault() { + public Boolean isLinearModelShowDefault() { return this.linearModelShowDefault; } /** * @param linearModelShowDefault The linearModelShowDefault to set. */ - public void setLinearModelShowDefault(boolean linearModelShowDefault) { + public void setLinearModelShowDefault(Boolean linearModelShowDefault) { this.linearModelShowDefault = linearModelShowDefault; initObject(m); } @@ -345,6 +345,10 @@ if (tableModel != null) { tableModel.setEnabled(enabled); } + if (table != null){ + table.setEnabled(enabled); + } + super.setEnabled(enabled); // if (text != null) { // text.setEditable(enabled); // } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-20 13:46:40 UTC (rev 128) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-23 14:07:41 UTC (rev 129) @@ -40,12 +40,12 @@ /** * @param source */ - public MatrixPanelEvent(MatrixPanelEditor source) { + public MatrixPanelEvent(MatrixEditor source) { super(source); } public MatrixND getMatrix() { - MatrixND result = ((MatrixPanelEditor) getSource()).getMatrix(); + MatrixND result = ((MatrixEditor) getSource()).getMatrix(); return result; } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-20 13:46:40 UTC (rev 128) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-23 14:07:41 UTC (rev 129) @@ -62,7 +62,7 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3349189688987885915L; - private MatrixPanelEditor matrixEditor; + private MatrixEditor matrixEditor; private JFileChooser fileChooser; private JMenu sendToClipBoard; @@ -80,7 +80,7 @@ private Action sendToFileSelectionCopyAction; private Action sendToFileCurrentPasteAction; - public MatrixPopupMenu(MatrixPanelEditor matrixEditor) { + public MatrixPopupMenu(MatrixEditor matrixEditor) { super(); this.matrixEditor = matrixEditor;
participants (1)
-
sletellier@users.labs.libre-entreprise.org