[Lutinutil-commits] r875 - in trunk/commandline/commandline-ui: . src/main/java src/main/java/org src/main/java/org/codelutin src/main/java/org/codelutin/option src/main/java/org/codelutin/option/ui src/main/uimodel/org/codelutin/option/ui
Author: tchemit Date: 2008-07-22 20:06:39 +0000 (Tue, 22 Jul 2008) New Revision: 875 Added: trunk/commandline/commandline-ui/src/main/java/org/ trunk/commandline/commandline-ui/src/main/java/org/codelutin/ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ClassCellEditor.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableEditor.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableModel.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableRenderer.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUI.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUIHandler.java trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/LoginUIHandler.java Removed: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ClassCellEditor.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableEditor.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableModel.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableRenderer.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUI.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUIHandler.java trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/LoginUIHandler.java Modified: trunk/commandline/commandline-ui/pom.xml trunk/commandline/commandline-ui/src/main/java/ Log: utilisation d'un r?\195?\169pertoire de compilation dans le projet Modified: trunk/commandline/commandline-ui/pom.xml =================================================================== --- trunk/commandline/commandline-ui/pom.xml 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/pom.xml 2008-07-22 20:06:39 UTC (rev 875) @@ -48,7 +48,15 @@ <packaging>jar</packaging> <build> - + <!-- where to generate jaxx java files --> + <resources> + <resource> + <directory>${basedir}/target/gen/java</directory> + </resource> + <resource> + <directory>${maven.src.dir}/main/resources</directory> + </resource> + </resources> <plugins> <!-- jaxx --> <plugin> @@ -57,7 +65,8 @@ <version>0.2-SNAPSHOT</version> <configuration> <src>${maven.src.dir}/main/uimodel</src> - <out>${maven.src.dir}/main/java</out> + <out>${basedir}/target/gen/java</out> + <!--out>${maven.src.dir}/main/java</out--> </configuration> <executions> <execution> @@ -71,8 +80,9 @@ <groupId>org.codelutin.jaxx</groupId> <artifactId>jaxx-swing</artifactId> <scope>compile</scope> + <!--version>${jaxx.version}</version--> <version>0.2-SNAPSHOT</version> - </dependency> + </dependency> </dependencies> </plugin> @@ -83,6 +93,15 @@ <executions> <execution> <phase>compile</phase> + <configuration> + <entries> + <entry> + <basedir> + ${basedir}/target/gen/java + </basedir> + </entry> + </entries> + </configuration> <goals> <goal>parserJava</goal> <goal>gen</goal> @@ -94,7 +113,7 @@ <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> - <execution> + <!--execution> <id>clean</id> <phase>clean</phase> <configuration> @@ -107,8 +126,8 @@ <goals> <goal>run</goal> </goals> - </execution> - <execution> + </execution--> + <!--execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> @@ -123,7 +142,7 @@ <goals> <goal>run</goal> </goals> - </execution> + </execution--> </executions> </plugin> Property changes on: trunk/commandline/commandline-ui/src/main/java ___________________________________________________________________ Name: svn:ignore - org Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ClassCellEditor.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ClassCellEditor.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ClassCellEditor.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ClassCellEditor.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,112 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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 org.codelutin.option.ui; + +import org.apache.commons.beanutils.Converter; +import org.codelutin.util.ConverterUtil; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.event.CellEditorListener; +import javax.swing.table.TableCellEditor; +import java.awt.Component; +import java.util.EventObject; + +/** + * L'�diteur des valeurs des propri�t�s d'une configuration + * + * @author chemit + */ +public class ClassCellEditor implements TableCellEditor { + + protected TableCellEditor delegate; + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + + String valStr = (value + "").trim(); + if (valStr.equals("null")) { + valStr = ""; + } else if (valStr.startsWith("class ")) { + valStr = valStr.substring(6); + } + Component comp; + comp = getDelegate().getTableCellEditorComponent(table, valStr, isSelected, row, column); + return comp; + } + + public Object getCellEditorValue() { + Object o = !hasDelegate() ? null : delegate.getCellEditorValue(); + if (o == null) { + return null; + } + Converter converter = ConverterUtil.getConverter(Class.class); + + try { + if (converter != null) { + return converter.convert(Class.class, o); + } + o =Class.forName(o+""); + } catch (Exception e) { + o=null; + } + return o; + } + + public boolean isCellEditable(EventObject anEvent) { + return !hasDelegate() || delegate.isCellEditable(anEvent); + } + + public boolean shouldSelectCell(EventObject anEvent) { + return hasDelegate() && delegate.shouldSelectCell(anEvent); + } + + public boolean stopCellEditing() { + return !hasDelegate() || delegate.stopCellEditing(); + } + + public void cancelCellEditing() { + if (hasDelegate()) { + delegate.cancelCellEditing(); + } + } + + public void addCellEditorListener(CellEditorListener l) { + if (hasDelegate()) { + delegate.addCellEditorListener(l); + } + } + + public void removeCellEditorListener(CellEditorListener l) { + if (hasDelegate()) { + delegate.removeCellEditorListener(l); + } + } + + protected TableCellEditor getDelegate() { + if (delegate == null) { + delegate = new DefaultCellEditor(new JTextField()); + } + return delegate; + } + + protected boolean hasDelegate() { + return delegate != null; + } +} \ No newline at end of file Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ClassCellEditor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableEditor.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableEditor.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableEditor.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableEditor.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,114 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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 org.codelutin.option.ui; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.event.CellEditorListener; +import javax.swing.table.TableCellEditor; +import java.awt.Component; +import java.util.EventObject; +import java.util.Locale; + +/** + * L'�diteur des valeurs des propri�t�s d'une configuration + * + * @author chemit + */ +public class ConfigTableEditor implements TableCellEditor { + + protected TableCellEditor delegate; + protected ConfigTableModel model; + + public ConfigTableEditor(ConfigTableModel model) { + this.model = model; + } + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + delegate = findDelegate(table, model.getKey(row).getType()); + return delegate.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + public Object getCellEditorValue() { + return !hasDelegate() ? null : delegate.getCellEditorValue(); + } + + public boolean isCellEditable(EventObject anEvent) { + return !hasDelegate() || delegate.isCellEditable(anEvent); + } + + public boolean shouldSelectCell(EventObject anEvent) { + return hasDelegate() && delegate.shouldSelectCell(anEvent); + } + + public boolean stopCellEditing() { + return !hasDelegate() || delegate.stopCellEditing(); + } + + public void cancelCellEditing() { + if (hasDelegate()) { + delegate.cancelCellEditing(); + } + } + + public void addCellEditorListener(CellEditorListener l) { + if (hasDelegate()) { + delegate.addCellEditorListener(l); + } + } + + public void removeCellEditorListener(CellEditorListener l) { + if (hasDelegate()) { + delegate.removeCellEditorListener(l); + } + } + + protected TableCellEditor findDelegate(JTable table, Class<?> type) { + TableCellEditor delegate = table.getDefaultEditor(type); + TableCellEditor defaultEditor = table.getDefaultEditor(Object.class); + if (delegate == defaultEditor) { + // find not a specialized editor for the type + if (type.isEnum()) { + // add a EnumEditor to table + delegate = new DefaultCellEditor(org.codelutin.util.EnumEditor.newEditor(type)); + table.setDefaultEditor(type, delegate); + } else if (type == Class.class) { + delegate = new ClassCellEditor(); + table.setDefaultEditor(type, delegate); + } //else if (type == File.class){ + // TODO a FileEditor + // table.setDefaultEditor(type, delegate); + //} + else if (type.equals(Locale.class)) { + delegate = new DefaultCellEditor(org.codelutin.i18n.LocaleEditor.newEditor()); + table.setDefaultEditor(Locale.class, delegate); + } else { + delegate = table.getDefaultEditor(String.class); + } + } + if (delegate == null) { + throw new IllegalStateException("could not find a editor for type +" + type); + } + return delegate; + } + + protected boolean hasDelegate() { + return delegate != null; + } +} Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableEditor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableModel.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableModel.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableModel.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableModel.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,235 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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 org.codelutin.option.ui; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.option.Config; +import org.codelutin.option.ConfigPropertyKey; +import org.codelutin.util.ArrayUtil; + +import javax.swing.table.AbstractTableModel; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Un mod�le g�n�rique pour une configuration g�n�rique + * + * @author chemit + */ +public class ConfigTableModel extends AbstractTableModel { + + private static final long serialVersionUID = -1457510439292016551L; + + /** + * Une enum pour d�finir les types de donn�es � ajouter au model + * + * @author chemit + */ + public enum TypeModel { + all { + protected boolean accept(ConfigPropertyKey<?> key) { + return true; + }}, + nontech { + protected boolean accept(ConfigPropertyKey<?> key) { + return !(tech.accept(key) || key.isTransient()); + }}, + tech { + protected boolean accept(ConfigPropertyKey<?> key) { + return key.isFinal(); + //return key.isFinal() && key.isTransient() && key.isStatic(); + }}; + + abstract boolean accept(ConfigPropertyKey<?> key); + } + + // par d�faut on affiche uniquement les propri�t�s non techniques + private static final TypeModel DEFAULT_TYPE = TypeModel.nontech; + + private final String[] columnNames = {_("lutinutil.common.key"), _("lutinutil.common.value")}; + + private final Class[] columnClass = {String.class, Object.class}; + + protected ConfigPropertyKey<?>[] keys; + protected Map<ConfigPropertyKey<?>, Object> props; + protected TypeModel type; + + protected Config config; + + public ConfigTableModel(Config config) { + this(config, null); + } + + public ConfigTableModel(Config config, TypeModel type) { + this.config = config; + setType(type); + } + + public TypeModel getType() { + return type; + } + + public void setType(TypeModel type) { + this.type = type; + // rebuild model + if (props == null) { + props = new LinkedHashMap<ConfigPropertyKey<?>, Object>(); + } else { + props.clear(); + } + if (type == null) { + type = DEFAULT_TYPE; + } + if (type == TypeModel.all) { + for (ConfigPropertyKey<?> key : config.getUniverse()) { + if (TypeModel.nontech.accept(key)) { + props.put(key, key.getCurrentValue()); + } + } + for (ConfigPropertyKey<?> key : config.getUniverse()) { + if (TypeModel.tech.accept(key)) { + props.put(key, key.getCurrentValue()); + } + } + } else { + for (ConfigPropertyKey<?> key : config.getUniverse()) { + if (type.accept(key)) { + props.put(key, key.getCurrentValue()); + } + } + } + keys = ArrayUtil.toArray(props.keySet(), ConfigPropertyKey.class); + fireTableDataChanged(); + } + + public ConfigPropertyKey<?> getKey(int rowIndex) { + return keys[rowIndex]; + } + + public boolean isModified(int rowIndex) { + ConfigPropertyKey key = getKey(rowIndex); + return !key.equals(key.getCurrentValue(), props.get(key)); + } + + public boolean isValid(int rowIndex) { + ConfigPropertyKey<?> key = getKey(rowIndex); + Object value = props.get(key); + return !key.isMandatory() || value != null && !"".equals(value); + } + + public boolean isModified() { + for (int i = 0; i < keys.length; i++) { + if (isModified(i)) { + return true; + } + } + return false; + } + + public boolean isValid() { + for (int i = 0; i < keys.length; i++) { + if (!isValid(i)) { + return false; + } + } + return true; + } + + @SuppressWarnings({"unchecked"}) + public void transfertModified(Config config) { + for (int i = 0; i < getRowCount(); i++) { + if (isModified(i)) { + ConfigPropertyKey<Object> key = (ConfigPropertyKey<Object>) getKey(i); + Object value = props.get(key); + //System.out.println("transfert property {0} value {1}", key.getKey(), value); + config.addProperty(key, value); + } + } + } + + public void reset() { + for (int i = 0; i < getRowCount(); i++) { + if (isModified(i)) { + ConfigPropertyKey key = getKey(i); + props.put(key, key.getCurrentValue()); + } + } + fireTableDataChanged(); + } + + public int getRowCount() { + return keys.length; + } + + public int getColumnCount() { + return 2; + } + + public Object getValueAt(int row, int column) { + ConfigPropertyKey key = getKey(row); + if (column == 0) { + return key.getKey(); + } + return props.get(key); + } + + @Override + public String getColumnName(int columnIndex) { + return columnNames[columnIndex]; + } + + @Override + public Class<?> getColumnClass(int columnIndex) { + return columnClass[columnIndex]; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnIndex == 1 && !keys[rowIndex].isFinal(); + } + + @Override + public void setValueAt(Object aValue, int row, int column) { + if (column == 0) { + return; + } + ConfigPropertyKey<?> key = getKey(row); + Object val; + + if (aValue==null || key.getType() ==aValue.getClass()) { + // we have directly the value, no conversion need + val = aValue; + } else { + String valStr = String.valueOf(aValue).trim(); + try { + val = key.convert(key.getType(), valStr); + if (val != null && val instanceof Integer) { + if (new Integer(0).equals(val) && !valStr.equals("0")) { + val = null; + } + } + } catch (Exception e) { + val = null; + } + } + props.put(key, val); + fireTableRowsUpdated(row, row); + } + +} Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableModel.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableRenderer.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableRenderer.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableRenderer.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableRenderer.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,108 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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 org.codelutin.option.ui; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.option.ConfigPropertyKey; + +import javax.swing.JComponent; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; + +/** + * le renderer pour l'ui de config + * + * @author chemit + */ +public class ConfigTableRenderer extends DefaultTableCellRenderer { + + protected static Color col; + protected static Font font; + protected static Font font2; + + protected ConfigTableModel model; + + public ConfigTableRenderer(ConfigTableModel config) { + this.model = config; + col = getForeground(); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + //System.out.println(">>> ConfigColumnRenderer.getTableCellRendererComponent " + row + "/" + column); + ConfigPropertyKey key = model.getKey(row); + boolean isModified = model.isModified(row); + boolean isValid = model.isValid(row); + + boolean isFinal = key.isFinal(); + if (font == null) { + font = table.getFont(); + font2 = getFont().deriveFont(Font.ITALIC | Font.BOLD); + } + Component cellRenderer = null; + // modified lines are selected + if (column == 0) { + cellRenderer = getKeyCellRenderer(table, value, isModified, hasFocus, row, column, key, isValid); + } else if (column == 1) { + cellRenderer = getValueCellRenderer(table, value, isModified, hasFocus, row, column, key, isValid); + } + if (cellRenderer == null) { + throw new IllegalStateException("no renderer find for column " + column); + } + cellRenderer.setEnabled(!isFinal); + cellRenderer.setFont(isModified ? font2 : font); + return cellRenderer; + } + + protected Component getKeyCellRenderer(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, ConfigPropertyKey key, boolean valid) { + String tooltip = key.getDescription(); + String s = _("lutinutil.config.modified", key.getCurrentValue()); + + if (isSelected) { + value = value + " *"; + tooltip += " [" + s + ']'; + } + if (!valid) { + String s2 = _("lutinutil.config.unvalid", key.getCurrentValue(), key.getType()); + tooltip += " (" + s2 + ")"; + } + JComponent result = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + result.setToolTipText(tooltip); + result.setForeground(valid ? col : Color.RED); + return result; + } + + protected Component getValueCellRenderer(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, ConfigPropertyKey key, boolean valid) { + TableCellRenderer defaultRenderer = table.getDefaultRenderer(key.getType()); + + JComponent result; + result = (JComponent) defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (!valid) { + result.setBorder(new LineBorder(Color.red)); + } else { + result.setBorder(null); + } + return result; + } +} Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigTableRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUI.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUI.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUI.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUI.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,103 @@ +/* +* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit +* +* 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 org.codelutin.option.ui; + +import org.codelutin.option.AbstractContext; +import org.codelutin.option.Config; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + * TODO javadoc + * + * @author chemit + */ +public class ConfigUI extends JConfigUI { + + protected List<Config> configs; + + public List<Config> getConfigs() { + if (configs == null) { + configs = new ArrayList<Config>(); + } + return configs; + } + + public ListCellRenderer getListener() { + return new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + if (value instanceof Config) { + Config config = (Config) value; + JComponent listCellRendererComponent = (JComponent) super.getListCellRendererComponent(list, config.getCategory(), index, isSelected, cellHasFocus); + listCellRendererComponent.setToolTipText(config.getCategory()); + return listCellRendererComponent; + } + return this; + } + }; + } + + public void onValueChanged() { + Object value = list.getSelectedValue(); + if (value instanceof Config) { + Config config = (Config) value; + cardLayout.show(preview, config.getCategory()); + } + } + + public ConfigUI init(AbstractContext context, Config... configs) { + for (Config config : configs) { + add(context, config); + } + if (list.getModel().getSize() > 0) { + list.setSelectedIndex(0); + } + return this; + } + + public boolean add(AbstractContext context, Config config) { + int index = getConfigs().indexOf(config); + if (index > -1) { + return false; + } + configs.add(config); + ConfigTab ui = new ConfigTab(); + ui.getHandler().init(context, config); + listModel.addElement(config); + preview.add(ui, config.getCategory()); + return true; + } + + public boolean remove(Config o) { + if (configs == null) { + return false; + } + int index = configs.indexOf(o); + if (index == -1) { + return false; + } + listModel.remove(index); + preview.remove(index); + configs.remove(index); + return true; + } +} Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUI.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUIHandler.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUIHandler.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUIHandler.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUIHandler.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,115 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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 org.codelutin.option.ui; + +import org.codelutin.option.AbstractContext; +import org.codelutin.option.Config; + +import javax.swing.*; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +/** + * Le controleur de l'ui de modification de configuration. + * + * @author chemit + */ +public class ConfigUIHandler { + + protected ConfigTab ui; + protected Config config; + protected ConfigTableModel tableModel; + protected TableModelListener tableModelListener; + + protected AbstractContext context; + + public ConfigUIHandler(ConfigTab ui) { + this.ui = ui; + } + + public void init(AbstractContext context, Config config) { + this.config = config; + this.context = context; + tableModel = new ConfigTableModel(config); + + tableModel.addTableModelListener(getTableModelListener()); + JTable table = ui.getMain(); + table.setModel(tableModel); + + ConfigTableRenderer renderer = new ConfigTableRenderer(tableModel); + table.getColumnModel().getColumn(0).setCellRenderer(renderer); + table.getColumnModel().getColumn(1).setCellRenderer(renderer); + table.getColumnModel().getColumn(1).setCellEditor(new ConfigTableEditor(getTableModel())); + + tableModel.fireTableDataChanged(); + } + + public void doSave() { + if (!isEmpty() && getTableModel().isModified()) { + getTableModel().transfertModified(getConfig()); + context.saveSafely(); + } + doReset(); + } + + public void doReset() { + getTableModel().reset(); + } + + public void doSelectTechnical(boolean showTechnical) { + tableModel.setType(showTechnical ? ConfigTableModel.TypeModel.all : ConfigTableModel.TypeModel.nontech); + } + + protected boolean isSaveEnabled() { + return isResetEnabled() && tableModel.isValid(); + } + + protected boolean isResetEnabled() { + return !isEmpty() && tableModel.isModified(); + } + + protected boolean isEmpty() { + return tableModel == null || config == null || config.getUniverse().isEmpty(); + } + + protected Config getConfig() { + return config; + } + + protected ConfigTableModel getTableModel() { + return tableModel; + } + + protected TableModelListener getTableModelListener() { + if (tableModelListener == null) { + tableModelListener = new TableModelListener() { + public void tableChanged(TableModelEvent e) { + ui.getSave().setEnabled(isSaveEnabled()); + ui.getReset().setEnabled(isResetEnabled()); + } + }; + } + return tableModelListener; + } + + protected void dispose() { + getTableModel().reset(); + } + +} \ No newline at end of file Property changes on: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/ConfigUIHandler.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/LoginUIHandler.java (from rev 872, trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/LoginUIHandler.java) =================================================================== --- trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/LoginUIHandler.java (rev 0) +++ trunk/commandline/commandline-ui/src/main/java/org/codelutin/option/ui/LoginUIHandler.java 2008-07-22 20:06:39 UTC (rev 875) @@ -0,0 +1,28 @@ +package org.codelutin.option.ui; + +public abstract class LoginUIHandler { + + boolean cancel; + + JLoginUI ui; + + protected abstract boolean connect(String login, char[] password); + + protected abstract boolean failedToConnect(); + + public abstract void doConnect(); + + public abstract void doCancel(); + + protected void setUi(JLoginUI ui) { + this.ui = ui; + } + + public void setCancel(boolean cancel) { + this.cancel = cancel; + } + + public boolean isCancel() { + return cancel; + } +} \ No newline at end of file Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ClassCellEditor.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ClassCellEditor.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ClassCellEditor.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,112 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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 org.codelutin.option.ui; - -import org.apache.commons.beanutils.Converter; -import org.codelutin.util.ConverterUtil; - -import javax.swing.DefaultCellEditor; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.event.CellEditorListener; -import javax.swing.table.TableCellEditor; -import java.awt.Component; -import java.util.EventObject; - -/** - * L'�diteur des valeurs des propri�t�s d'une configuration - * - * @author chemit - */ -public class ClassCellEditor implements TableCellEditor { - - protected TableCellEditor delegate; - - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - - String valStr = (value + "").trim(); - if (valStr.equals("null")) { - valStr = ""; - } else if (valStr.startsWith("class ")) { - valStr = valStr.substring(6); - } - Component comp; - comp = getDelegate().getTableCellEditorComponent(table, valStr, isSelected, row, column); - return comp; - } - - public Object getCellEditorValue() { - Object o = !hasDelegate() ? null : delegate.getCellEditorValue(); - if (o == null) { - return null; - } - Converter converter = ConverterUtil.getConverter(Class.class); - - try { - if (converter != null) { - return converter.convert(Class.class, o); - } - o =Class.forName(o+""); - } catch (Exception e) { - o=null; - } - return o; - } - - public boolean isCellEditable(EventObject anEvent) { - return !hasDelegate() || delegate.isCellEditable(anEvent); - } - - public boolean shouldSelectCell(EventObject anEvent) { - return hasDelegate() && delegate.shouldSelectCell(anEvent); - } - - public boolean stopCellEditing() { - return !hasDelegate() || delegate.stopCellEditing(); - } - - public void cancelCellEditing() { - if (hasDelegate()) { - delegate.cancelCellEditing(); - } - } - - public void addCellEditorListener(CellEditorListener l) { - if (hasDelegate()) { - delegate.addCellEditorListener(l); - } - } - - public void removeCellEditorListener(CellEditorListener l) { - if (hasDelegate()) { - delegate.removeCellEditorListener(l); - } - } - - protected TableCellEditor getDelegate() { - if (delegate == null) { - delegate = new DefaultCellEditor(new JTextField()); - } - return delegate; - } - - protected boolean hasDelegate() { - return delegate != null; - } -} \ No newline at end of file Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableEditor.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableEditor.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableEditor.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,114 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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 org.codelutin.option.ui; - -import javax.swing.DefaultCellEditor; -import javax.swing.JTable; -import javax.swing.event.CellEditorListener; -import javax.swing.table.TableCellEditor; -import java.awt.Component; -import java.util.EventObject; -import java.util.Locale; - -/** - * L'�diteur des valeurs des propri�t�s d'une configuration - * - * @author chemit - */ -public class ConfigTableEditor implements TableCellEditor { - - protected TableCellEditor delegate; - protected ConfigTableModel model; - - public ConfigTableEditor(ConfigTableModel model) { - this.model = model; - } - - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - delegate = findDelegate(table, model.getKey(row).getType()); - return delegate.getTableCellEditorComponent(table, value, isSelected, row, column); - } - - public Object getCellEditorValue() { - return !hasDelegate() ? null : delegate.getCellEditorValue(); - } - - public boolean isCellEditable(EventObject anEvent) { - return !hasDelegate() || delegate.isCellEditable(anEvent); - } - - public boolean shouldSelectCell(EventObject anEvent) { - return hasDelegate() && delegate.shouldSelectCell(anEvent); - } - - public boolean stopCellEditing() { - return !hasDelegate() || delegate.stopCellEditing(); - } - - public void cancelCellEditing() { - if (hasDelegate()) { - delegate.cancelCellEditing(); - } - } - - public void addCellEditorListener(CellEditorListener l) { - if (hasDelegate()) { - delegate.addCellEditorListener(l); - } - } - - public void removeCellEditorListener(CellEditorListener l) { - if (hasDelegate()) { - delegate.removeCellEditorListener(l); - } - } - - protected TableCellEditor findDelegate(JTable table, Class<?> type) { - TableCellEditor delegate = table.getDefaultEditor(type); - TableCellEditor defaultEditor = table.getDefaultEditor(Object.class); - if (delegate == defaultEditor) { - // find not a specialized editor for the type - if (type.isEnum()) { - // add a EnumEditor to table - delegate = new DefaultCellEditor(org.codelutin.util.EnumEditor.newEditor(type)); - table.setDefaultEditor(type, delegate); - } else if (type == Class.class) { - delegate = new ClassCellEditor(); - table.setDefaultEditor(type, delegate); - } //else if (type == File.class){ - // TODO a FileEditor - // table.setDefaultEditor(type, delegate); - //} - else if (type.equals(Locale.class)) { - delegate = new DefaultCellEditor(org.codelutin.i18n.LocaleEditor.newEditor()); - table.setDefaultEditor(Locale.class, delegate); - } else { - delegate = table.getDefaultEditor(String.class); - } - } - if (delegate == null) { - throw new IllegalStateException("could not find a editor for type +" + type); - } - return delegate; - } - - protected boolean hasDelegate() { - return delegate != null; - } -} Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableModel.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableModel.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableModel.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,235 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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 org.codelutin.option.ui; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.option.Config; -import org.codelutin.option.ConfigPropertyKey; -import org.codelutin.util.ArrayUtil; - -import javax.swing.table.AbstractTableModel; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Un mod�le g�n�rique pour une configuration g�n�rique - * - * @author chemit - */ -public class ConfigTableModel extends AbstractTableModel { - - private static final long serialVersionUID = -1457510439292016551L; - - /** - * Une enum pour d�finir les types de donn�es � ajouter au model - * - * @author chemit - */ - public enum TypeModel { - all { - protected boolean accept(ConfigPropertyKey<?> key) { - return true; - }}, - nontech { - protected boolean accept(ConfigPropertyKey<?> key) { - return !(tech.accept(key) || key.isTransient()); - }}, - tech { - protected boolean accept(ConfigPropertyKey<?> key) { - return key.isFinal(); - //return key.isFinal() && key.isTransient() && key.isStatic(); - }}; - - abstract boolean accept(ConfigPropertyKey<?> key); - } - - // par d�faut on affiche uniquement les propri�t�s non techniques - private static final TypeModel DEFAULT_TYPE = TypeModel.nontech; - - private final String[] columnNames = {_("lutinutil.common.key"), _("lutinutil.common.value")}; - - private final Class[] columnClass = {String.class, Object.class}; - - protected ConfigPropertyKey<?>[] keys; - protected Map<ConfigPropertyKey<?>, Object> props; - protected TypeModel type; - - protected Config config; - - public ConfigTableModel(Config config) { - this(config, null); - } - - public ConfigTableModel(Config config, TypeModel type) { - this.config = config; - setType(type); - } - - public TypeModel getType() { - return type; - } - - public void setType(TypeModel type) { - this.type = type; - // rebuild model - if (props == null) { - props = new LinkedHashMap<ConfigPropertyKey<?>, Object>(); - } else { - props.clear(); - } - if (type == null) { - type = DEFAULT_TYPE; - } - if (type == TypeModel.all) { - for (ConfigPropertyKey<?> key : config.getUniverse()) { - if (TypeModel.nontech.accept(key)) { - props.put(key, key.getCurrentValue()); - } - } - for (ConfigPropertyKey<?> key : config.getUniverse()) { - if (TypeModel.tech.accept(key)) { - props.put(key, key.getCurrentValue()); - } - } - } else { - for (ConfigPropertyKey<?> key : config.getUniverse()) { - if (type.accept(key)) { - props.put(key, key.getCurrentValue()); - } - } - } - keys = ArrayUtil.toArray(props.keySet(), ConfigPropertyKey.class); - fireTableDataChanged(); - } - - public ConfigPropertyKey<?> getKey(int rowIndex) { - return keys[rowIndex]; - } - - public boolean isModified(int rowIndex) { - ConfigPropertyKey key = getKey(rowIndex); - return !key.equals(key.getCurrentValue(), props.get(key)); - } - - public boolean isValid(int rowIndex) { - ConfigPropertyKey<?> key = getKey(rowIndex); - Object value = props.get(key); - return !key.isMandatory() || value != null && !"".equals(value); - } - - public boolean isModified() { - for (int i = 0; i < keys.length; i++) { - if (isModified(i)) { - return true; - } - } - return false; - } - - public boolean isValid() { - for (int i = 0; i < keys.length; i++) { - if (!isValid(i)) { - return false; - } - } - return true; - } - - @SuppressWarnings({"unchecked"}) - public void transfertModified(Config config) { - for (int i = 0; i < getRowCount(); i++) { - if (isModified(i)) { - ConfigPropertyKey<Object> key = (ConfigPropertyKey<Object>) getKey(i); - Object value = props.get(key); - //System.out.println("transfert property {0} value {1}", key.getKey(), value); - config.addProperty(key, value); - } - } - } - - public void reset() { - for (int i = 0; i < getRowCount(); i++) { - if (isModified(i)) { - ConfigPropertyKey key = getKey(i); - props.put(key, key.getCurrentValue()); - } - } - fireTableDataChanged(); - } - - public int getRowCount() { - return keys.length; - } - - public int getColumnCount() { - return 2; - } - - public Object getValueAt(int row, int column) { - ConfigPropertyKey key = getKey(row); - if (column == 0) { - return key.getKey(); - } - return props.get(key); - } - - @Override - public String getColumnName(int columnIndex) { - return columnNames[columnIndex]; - } - - @Override - public Class<?> getColumnClass(int columnIndex) { - return columnClass[columnIndex]; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return columnIndex == 1 && !keys[rowIndex].isFinal(); - } - - @Override - public void setValueAt(Object aValue, int row, int column) { - if (column == 0) { - return; - } - ConfigPropertyKey<?> key = getKey(row); - Object val; - - if (aValue==null || key.getType() ==aValue.getClass()) { - // we have directly the value, no conversion need - val = aValue; - } else { - String valStr = String.valueOf(aValue).trim(); - try { - val = key.convert(key.getType(), valStr); - if (val != null && val instanceof Integer) { - if (new Integer(0).equals(val) && !valStr.equals("0")) { - val = null; - } - } - } catch (Exception e) { - val = null; - } - } - props.put(key, val); - fireTableRowsUpdated(row, row); - } - -} Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableRenderer.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableRenderer.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigTableRenderer.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,108 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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 org.codelutin.option.ui; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.option.ConfigPropertyKey; - -import javax.swing.JComponent; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; -import java.awt.Color; -import java.awt.Component; -import java.awt.Font; - -/** - * le renderer pour l'ui de config - * - * @author chemit - */ -public class ConfigTableRenderer extends DefaultTableCellRenderer { - - protected static Color col; - protected static Font font; - protected static Font font2; - - protected ConfigTableModel model; - - public ConfigTableRenderer(ConfigTableModel config) { - this.model = config; - col = getForeground(); - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - //System.out.println(">>> ConfigColumnRenderer.getTableCellRendererComponent " + row + "/" + column); - ConfigPropertyKey key = model.getKey(row); - boolean isModified = model.isModified(row); - boolean isValid = model.isValid(row); - - boolean isFinal = key.isFinal(); - if (font == null) { - font = table.getFont(); - font2 = getFont().deriveFont(Font.ITALIC | Font.BOLD); - } - Component cellRenderer = null; - // modified lines are selected - if (column == 0) { - cellRenderer = getKeyCellRenderer(table, value, isModified, hasFocus, row, column, key, isValid); - } else if (column == 1) { - cellRenderer = getValueCellRenderer(table, value, isModified, hasFocus, row, column, key, isValid); - } - if (cellRenderer == null) { - throw new IllegalStateException("no renderer find for column " + column); - } - cellRenderer.setEnabled(!isFinal); - cellRenderer.setFont(isModified ? font2 : font); - return cellRenderer; - } - - protected Component getKeyCellRenderer(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, ConfigPropertyKey key, boolean valid) { - String tooltip = key.getDescription(); - String s = _("lutinutil.config.modified", key.getCurrentValue()); - - if (isSelected) { - value = value + " *"; - tooltip += " [" + s + ']'; - } - if (!valid) { - String s2 = _("lutinutil.config.unvalid", key.getCurrentValue(), key.getType()); - tooltip += " (" + s2 + ")"; - } - JComponent result = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - result.setToolTipText(tooltip); - result.setForeground(valid ? col : Color.RED); - return result; - } - - protected Component getValueCellRenderer(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, ConfigPropertyKey key, boolean valid) { - TableCellRenderer defaultRenderer = table.getDefaultRenderer(key.getType()); - - JComponent result; - result = (JComponent) defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (!valid) { - result.setBorder(new LineBorder(Color.red)); - } else { - result.setBorder(null); - } - return result; - } -} Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUI.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUI.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUI.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,103 +0,0 @@ -/* -* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit -* -* 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 org.codelutin.option.ui; - -import org.codelutin.option.AbstractContext; -import org.codelutin.option.Config; - -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -/** - * TODO javadoc - * - * @author chemit - */ -public class ConfigUI extends JConfigUI { - - protected List<Config> configs; - - public List<Config> getConfigs() { - if (configs == null) { - configs = new ArrayList<Config>(); - } - return configs; - } - - public ListCellRenderer getListener() { - return new DefaultListCellRenderer() { - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value instanceof Config) { - Config config = (Config) value; - JComponent listCellRendererComponent = (JComponent) super.getListCellRendererComponent(list, config.getCategory(), index, isSelected, cellHasFocus); - listCellRendererComponent.setToolTipText(config.getCategory()); - return listCellRendererComponent; - } - return this; - } - }; - } - - public void onValueChanged() { - Object value = list.getSelectedValue(); - if (value instanceof Config) { - Config config = (Config) value; - cardLayout.show(preview, config.getCategory()); - } - } - - public ConfigUI init(AbstractContext context, Config... configs) { - for (Config config : configs) { - add(context, config); - } - if (list.getModel().getSize() > 0) { - list.setSelectedIndex(0); - } - return this; - } - - public boolean add(AbstractContext context, Config config) { - int index = getConfigs().indexOf(config); - if (index > -1) { - return false; - } - configs.add(config); - ConfigTab ui = new ConfigTab(); - ui.getHandler().init(context, config); - listModel.addElement(config); - preview.add(ui, config.getCategory()); - return true; - } - - public boolean remove(Config o) { - if (configs == null) { - return false; - } - int index = configs.indexOf(o); - if (index == -1) { - return false; - } - listModel.remove(index); - preview.remove(index); - configs.remove(index); - return true; - } -} Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUIHandler.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUIHandler.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/ConfigUIHandler.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,115 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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 org.codelutin.option.ui; - -import org.codelutin.option.AbstractContext; -import org.codelutin.option.Config; - -import javax.swing.*; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; - -/** - * Le controleur de l'ui de modification de configuration. - * - * @author chemit - */ -public class ConfigUIHandler { - - protected ConfigTab ui; - protected Config config; - protected ConfigTableModel tableModel; - protected TableModelListener tableModelListener; - - protected AbstractContext context; - - public ConfigUIHandler(ConfigTab ui) { - this.ui = ui; - } - - public void init(AbstractContext context, Config config) { - this.config = config; - this.context = context; - tableModel = new ConfigTableModel(config); - - tableModel.addTableModelListener(getTableModelListener()); - JTable table = ui.getMain(); - table.setModel(tableModel); - - ConfigTableRenderer renderer = new ConfigTableRenderer(tableModel); - table.getColumnModel().getColumn(0).setCellRenderer(renderer); - table.getColumnModel().getColumn(1).setCellRenderer(renderer); - table.getColumnModel().getColumn(1).setCellEditor(new ConfigTableEditor(getTableModel())); - - tableModel.fireTableDataChanged(); - } - - public void doSave() { - if (!isEmpty() && getTableModel().isModified()) { - getTableModel().transfertModified(getConfig()); - context.saveSafely(); - } - doReset(); - } - - public void doReset() { - getTableModel().reset(); - } - - public void doSelectTechnical(boolean showTechnical) { - tableModel.setType(showTechnical ? ConfigTableModel.TypeModel.all : ConfigTableModel.TypeModel.nontech); - } - - protected boolean isSaveEnabled() { - return isResetEnabled() && tableModel.isValid(); - } - - protected boolean isResetEnabled() { - return !isEmpty() && tableModel.isModified(); - } - - protected boolean isEmpty() { - return tableModel == null || config == null || config.getUniverse().isEmpty(); - } - - protected Config getConfig() { - return config; - } - - protected ConfigTableModel getTableModel() { - return tableModel; - } - - protected TableModelListener getTableModelListener() { - if (tableModelListener == null) { - tableModelListener = new TableModelListener() { - public void tableChanged(TableModelEvent e) { - ui.getSave().setEnabled(isSaveEnabled()); - ui.getReset().setEnabled(isResetEnabled()); - } - }; - } - return tableModelListener; - } - - protected void dispose() { - getTableModel().reset(); - } - -} \ No newline at end of file Deleted: trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/LoginUIHandler.java =================================================================== --- trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/LoginUIHandler.java 2008-07-21 00:34:57 UTC (rev 874) +++ trunk/commandline/commandline-ui/src/main/uimodel/org/codelutin/option/ui/LoginUIHandler.java 2008-07-22 20:06:39 UTC (rev 875) @@ -1,28 +0,0 @@ -package org.codelutin.option.ui; - -public abstract class LoginUIHandler { - - boolean cancel; - - JLoginUI ui; - - protected abstract boolean connect(String login, char[] password); - - protected abstract boolean failedToConnect(); - - public abstract void doConnect(); - - public abstract void doCancel(); - - protected void setUi(JLoginUI ui) { - this.ui = ui; - } - - public void setCancel(boolean cancel) { - this.cancel = cancel; - } - - public boolean isCancel() { - return cancel; - } -} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org