r3331 - in isis-fish/branches/3.3.1/src/main: java/fr/ifremer/isisfish/ui/sensitivity java/fr/ifremer/isisfish/ui/sensitivity/equation resources/i18n
Author: chatellier Date: 2011-05-16 14:53:00 +0000 (Mon, 16 May 2011) New Revision: 3331 Log: Ajout du support des facteurs min/max et pourcentage pour les equations Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainListModel.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainRenderer.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EquationContinuousPanelUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EquationContinuousPanelUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EquationContinuousPanelUI.jaxx 2011-05-15 20:44:38 UTC (rev 3330) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EquationContinuousPanelUI.jaxx 2011-05-16 14:53:00 UTC (rev 3331) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2009 - 2010 Ifremer, CodeLutin + Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -53,107 +53,49 @@ <!-- bean property --> <fr.ifremer.isisfish.entities.Formule id='formule' javaBean='null'/> + <Boolean id="selectedDomain" javaBean="false" /> + <Boolean id="percentageTypeDomain" javaBean="false" /> + <script><![CDATA[ -protected String[] columnNames = { - _("isisfish.sensitivity.equation.variable.name"), - _("isisfish.sensitivity.equation.variable.value"), - _("isisfish.sensitivity.equation.variable.coefficient"), - _("isisfish.sensitivity.equation.variable.action")}; + protected List<EquationContinuousDomain> domains = new ArrayList<EquationContinuousDomain>(); -protected List<JButton> actions = new ArrayList<JButton>(); public List<EquationContinuousDomain> getDomains() { return domains; } -public void setDomains(List<EquationContinuousDomain> newDomains) { - domains.clear(); - for (EquationContinuousDomain d : newDomains) { - addDomain(d); - } -} - -public void addDomain(EquationContinuousDomain domain) { - newButton(); +protected void addDomain(EquationContinuousDomain domain) { domains.add(domain); + // fire data change + variablesListModel.setDomains(domains); } -protected AbstractTableModel getTableModel() { - AbstractTableModel model = new AbstractTableModel() { - @Override - public int getRowCount() { - return domains.size(); - } - - @Override - public int getColumnCount() { - return columnNames.length; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return true; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - if (columnIndex == 0) { - return domains.get(rowIndex).getVariableName(); - } else if (columnIndex == 1) { - return domains.get(rowIndex).getReferenceValue(); - } else if (columnIndex == 2) { - Double result = domains.get(rowIndex).getCoefficient() * 100; - return result; - } else if (columnIndex == 3) { - return _("isisfish.sensitivity.validDiscretNumber"); - } - return null; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if (String.class.isInstance(aValue)) { - if (!((String)aValue).equals("")) { - if (columnIndex == 0){ - domains.get(rowIndex).setVariableName((String)aValue); - } else if (columnIndex == 1) { - domains.get(rowIndex).setReferenceValue(Double.parseDouble((String)aValue)); - } else if (columnIndex == 2) { - domains.get(rowIndex).setCoefficient(Double.parseDouble((String)aValue) / 100); - } - } - } - } - - @Override - public String getColumnName(int col) { - return columnNames[col].toString(); - } - - }; - return model; -} - -protected void newButton() { - JButton result = new JButton(); - result.setText(_("isisfish.sensitivity.validDiscretNumber")); - actions.add(result); - result.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JButton source = (JButton)e.getSource(); - int i = actions.indexOf(source); - valid(i); - } - }); -} - -protected JButton getActionButton(int i) { - return actions.get(i); -} - -protected void valid(int i) { - String variableName = domains.get(i).getVariableName(); +/** + * Valid selected domain. + */ +protected void validSelectedDomain() { + // fill selected + EquationContinuousDomain selectedDomain = (EquationContinuousDomain)variablesList.getSelectedValue(); + selectedDomain.setVariableName(variableNameField.getText().trim()); + if (isPercentageTypeDomain()) { + selectedDomain.setMinBound(null); // important + selectedDomain.setMaxBound(null); // important + selectedDomain.setReferenceValue(Double.parseDouble(referenceValueField.getText())); + selectedDomain.setCoefficient(Double.parseDouble(coefficientField.getText()) / 100); + } else { + selectedDomain.setMinBound(Double.parseDouble(minBoundField.getText())); + selectedDomain.setMaxBound(Double.parseDouble(maxBoundField.getText())); + selectedDomain.setReferenceValue(null); // important + selectedDomain.setCoefficient(null); // important + } + + + // parse equation content to replace + // double xxx = 4.0; + // by + // double xxx = context.getValueAndCompute("myfactorname.xxx", 4.0) + // if xxx is the variable name to replace + String variableName = selectedDomain.getVariableName(); String[] lines = editor.getEditor().getText().split("\n"); String result = ""; for (String line : lines) { @@ -166,78 +108,77 @@ result += line + "\n"; } editor.getEditor().setText(result); + + // fire data change + variablesListModel.setDomains(domains); } -protected void setTable() { - params.setModel(getTableModel()); - params.getColumnModel().getColumn(3).setCellEditor(new TableCellEditor() { +protected void addNewVariable() { + EquationContinuousDomain domain = new EquationContinuousDomain(); + domain.setVariableName("X"); + addDomain(domain); + + // auto select + variablesList.setSelectedValue(domain, true); +} - @Override - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - return getActionButton(row); +protected void displaySelectedDomain() { + EquationContinuousDomain selectedDomain = (EquationContinuousDomain)variablesList.getSelectedValue(); + if (selectedDomain != null) { + setSelectedDomain(true); + variableNameField.setText(selectedDomain.getVariableName()); + setPercentageTypeDomain(selectedDomain.getCoefficient() != null); + if (selectedDomain.getCoefficient() != null) { + coefficientField.setText(String.valueOf(selectedDomain.getCoefficient() * 100)); + } else { + coefficientField.setText(""); } - - @Override - public Object getCellEditorValue() { - return null; + if (selectedDomain.getReferenceValue() != null) { + referenceValueField.setText(selectedDomain.getReferenceValue().toString()); + } else { + referenceValueField.setText(""); } - - @Override - public boolean isCellEditable(EventObject anEvent) { - return true; + if (selectedDomain.getOriginalMinBound() != null) { + minBoundField.setText(selectedDomain.getOriginalMinBound().toString()); + } else { + minBoundField.setText(""); } - - @Override - public boolean shouldSelectCell(EventObject anEvent) { - return true; + if (selectedDomain.getOriginalMaxBound() != null) { + maxBoundField.setText(selectedDomain.getOriginalMaxBound().toString()); + } else { + maxBoundField.setText(""); } - - @Override - public boolean stopCellEditing() { - return true; - } - - @Override - public void cancelCellEditing() { - } - - @Override - public void addCellEditorListener(CellEditorListener l) { - } - - @Override - public void removeCellEditorListener(CellEditorListener l) { - } - }); + } else { + setSelectedDomain(false); + } } -protected void addNewVariable() { - EquationContinuousDomain domain = new EquationContinuousDomain(); - // fixe NPE in table model renderer - domain.setCoefficient(1.0); - domains.add(domain); - newButton(); - setTable(); -} -protected void removeVariable() { - int selectedRow = params.getSelectedRow(); - domains.remove(selectedRow); - actions.remove(selectedRow); - setTable(); +protected void removeSelectedVariable() { + int selectedIndex = variablesList.getSelectedIndex(); + domains.remove(selectedIndex); + + // fire data change + variablesListModel.setDomains(domains); } @Override public boolean isFactorValid() { boolean valid = true; - for (EquationContinuousDomain domain : domains) { - if (domain.getReferenceValue() == null - || domain.getCoefficient() == null - || domain.getCoefficient() > 100 - || domain.getCoefficient() <= 0 - || domain.getVariableName() == null) { - valid = false; + try { + for (EquationContinuousDomain domain : domains) { + if (StringUtils.isBlank(domain.getVariableName())) { + valid = false; + } + else if (domain.getCoefficient() == null) { + valid = domain.getOriginalMinBound() != null && domain.getOriginalMaxBound() != null; + } + else { + valid = domain.getReferenceValue() != null; + } } + } catch (NumberFormatException ex) { + valid = false; } return valid; @@ -246,23 +187,112 @@ <JPanel id='content'> <Table constraints='BorderLayout.CENTER'> <row> - <cell fill='both' columns='2' weightx='1' weighty='1'> + <cell fill='both' weightx='1' weighty='1'> <JScrollPane preferredSize="{new Dimension(200, 150)}"> - <JTable id='params' visible='{isContinuePossible()}' model='{getTableModel()}' - enabled='{isContinueSelected()}' /> - <ListSelectionModel initializer="params.getSelectionModel()" - onValueChanged="remove.setEnabled(params.getSelectedRow() != -1)" /> + <fr.ifremer.isisfish.ui.sensitivity.equation.EquationDomainListModel + id="variablesListModel" constructorParams="domains" /> + <JList id="variablesList" model="{variablesListModel}" + cellRenderer="{new fr.ifremer.isisfish.ui.sensitivity.equation.EquationDomainRenderer()}"/> + <ListSelectionModel initializer="variablesList.getSelectionModel()" + onValueChanged="displaySelectedDomain();setSelectedDomain(variablesList.getSelectedIndex() != -1)" /> </JScrollPane> </cell> + <cell fill='both' weightx='1' weighty='1'> + <Table> + <row> + <cell> + <JLabel text="isisfish.sensitivity.equation.variablename" enabled='{isSelectedDomain()}' /> + </cell> + <cell fill="horizontal"> + <JTextField id="variableNameField" enabled='{isSelectedDomain()}'/> + </cell> + </row> + <row> + <cell fill="horizontal" columns="2"> + <JRadioButton id="percentageTypeButton" text="isisfish.sensitivity.continuouspercentagetype" + onActionPerformed="setPercentageTypeDomain(percentageTypeButton.isSelected())" + selected="{isPercentageTypeDomain()}" + enabled='{isSelectedDomain()}'/> + </cell> + </row> + <row> + <cell fill="both" weightx='1' weighty='1' columns="2"> + <Table border='{BorderFactory.createTitledBorder("")}'> + <row> + <cell fill='horizontal'> + <JLabel text='isisfish.sensitivity.referencevalue' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && isPercentageTypeDomain()}'/> + </cell> + <cell fill='horizontal' weightx='0.5'> + <JTextField id='referenceValueField' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && isPercentageTypeDomain()}'/> + </cell> + </row> + <row> + <cell fill='horizontal'> + <JLabel text='isisfish.sensitivity.coefficient' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && isPercentageTypeDomain()}'/> + </cell> + <cell fill='horizontal' weightx='0.5'> + <JTextField id='coefficientField' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && isPercentageTypeDomain()}'/> + </cell> + </row> + </Table> + </cell> + </row> + <row> + <cell fill="horizontal" columns="2"> + <JRadioButton id="minMaxButton" text="isisfish.sensitivity.continuousminmaxtype" + onActionPerformed="setPercentageTypeDomain(!minMaxButton.isSelected())" + selected="{!isPercentageTypeDomain()}" + enabled='{isSelectedDomain() && isContinueSelected()}'/> + </cell> + </row> + <row> + <cell fill="both" weightx='1' weighty='1' columns="2"> + <Table border='{BorderFactory.createTitledBorder("")}'> + <row> + <cell fill='horizontal'> + <JLabel text='isisfish.sensitivity.firstValue' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && !isPercentageTypeDomain()}'/> + </cell> + <cell fill='horizontal' weightx='0.5'> + <JTextField id='minBoundField' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && !isPercentageTypeDomain()}'/> + </cell> + </row> + <row> + <cell fill='horizontal'> + <JLabel text='isisfish.sensitivity.lastValue' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && !isPercentageTypeDomain()}'/> + </cell> + <cell fill='horizontal' weightx='0.5'> + <JTextField id='maxBoundField' visible='{isContinuePossible()}' + enabled='{isSelectedDomain() && !isPercentageTypeDomain()}'/> + </cell> + </row> + </Table> + </cell> + </row> + <row> + <cell fill="horizontal" columns="2"> + <JButton text="isisfish.sensitivity.equation.valid" + enabled='{isSelectedDomain()}' + onActionPerformed='validSelectedDomain()' /> + </cell> + </row> + </Table> + </cell> </row> <row> - <cell fill='horizontal' weightx='1'> + <cell fill='horizontal'> <JButton id='add' text='isisfish.common.add' visible='{isContinuePossible()}' enabled='{isContinueSelected()}' onActionPerformed='addNewVariable()'/> </cell> - <cell fill='horizontal' weightx='1'> + <cell fill='horizontal'> <JButton id='remove' text='isisfish.common.remove' visible='{isContinuePossible()}' - enabled='false' onActionPerformed='removeVariable()'/> + enabled='{isSelectedDomain()}' onActionPerformed='removeSelectedVariable()'/> </cell> </row> <row> Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2011-05-15 20:44:38 UTC (rev 3330) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2011-05-16 14:53:00 UTC (rev 3331) @@ -682,7 +682,6 @@ EquationContinuousDomain equationDomain = (EquationContinuousDomain) domain; ui.addDomain(equationDomain); - ui.setTable(); result = ui; } catch (Exception ex) { @@ -922,6 +921,11 @@ // Save equation bean.update(); topiaContext.commitTransaction(); + + List<EquationContinuousDomain> domains = equationPanel.getDomains(); + for (EquationContinuousDomain domain : domains) { + action.addContinuousEquationFactor(name, comment, path, domain, exist); + } } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("Can't call method : ", ex); Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainListModel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainListModel.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainListModel.java 2011-05-16 14:53:00 UTC (rev 3331) @@ -0,0 +1,92 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui.sensitivity.equation; + +import java.util.List; + +import javax.swing.DefaultListModel; + +import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; + +/** + * Model pour la liste des {@link EquationContinuousDomain}. + * + * Pas de selection par defaut. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class EquationDomainListModel extends DefaultListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 2281927104735245489L; + + /** EquationContinuousDomain list */ + protected List<EquationContinuousDomain> domains; + + /** + * Constructor with domains list. + * + * @param domains domains list + */ + public EquationDomainListModel(List<EquationContinuousDomain> domains) { + this.domains = domains; + } + + /** + * Change data list and fire data change event. + * + * @param domains new data list + */ + public void setDomains(List<EquationContinuousDomain> domains) { + this.domains = domains; + fireContentsChanged(this, 0, domains.size()); + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return domains.get(index); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int size = 0; + + if (domains != null) { + size = domains.size(); + } + return size; + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainRenderer.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainRenderer.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainRenderer.java 2011-05-16 14:53:00 UTC (rev 3331) @@ -0,0 +1,60 @@ +/* + * #%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 fr.ifremer.isisfish.ui.sensitivity.equation; + +import java.awt.Component; + +import javax.swing.JList; + +import org.jdesktop.swingx.renderer.DefaultListRenderer; + +import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; + +/** + * Renderer for equation factor variables list. + * Renderer as variable name string. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class EquationDomainRenderer extends DefaultListRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -8210763862382993163L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + EquationContinuousDomain domain = (EquationContinuousDomain)value; + String stringValue = domain.getVariableName(); + return super.getListCellRendererComponent(list, stringValue, index, isSelected, cellHasFocus); + } + +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/equation/EquationDomainRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-05-15 20:44:38 UTC (rev 3330) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-05-16 14:53:00 UTC (rev 3331) @@ -910,11 +910,13 @@ isisfish.sensitivity.discret=Discret factor isisfish.sensitivity.discretevaluelabel=Value %d isisfish.sensitivity.displaysecondpass=Display results +isisfish.sensitivity.equation.valid=Valid variable isisfish.sensitivity.equation.variable.action=Action isisfish.sensitivity.equation.variable.coefficient=Coef. (in %) isisfish.sensitivity.equation.variable.name=Name isisfish.sensitivity.equation.variable.operator=Operator isisfish.sensitivity.equation.variable.value=Value +isisfish.sensitivity.equation.variablename=Varaible name \: isisfish.sensitivity.export=Export isisfish.sensitivity.factor=Factor isisfish.sensitivity.factor.notvalid=Factor not valid \! Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-05-15 20:44:38 UTC (rev 3330) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-05-16 14:53:00 UTC (rev 3331) @@ -910,11 +910,13 @@ isisfish.sensitivity.discret=Facteur discret isisfish.sensitivity.discretevaluelabel=Valeur %d isisfish.sensitivity.displaysecondpass=Afficher les résultats +isisfish.sensitivity.equation.valid=Valider la variable isisfish.sensitivity.equation.variable.action=Action isisfish.sensitivity.equation.variable.coefficient=Coef (en %) isisfish.sensitivity.equation.variable.name=Nom isisfish.sensitivity.equation.variable.operator=Opérateur isisfish.sensitivity.equation.variable.value=Valeur +isisfish.sensitivity.equation.variablename=Variable name \: isisfish.sensitivity.export=Export isisfish.sensitivity.factor=Facteur isisfish.sensitivity.factor.notvalid=Facteur non valide \!
participants (1)
-
chatellier@users.labs.libre-entreprise.org