You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by me...@locus.apache.org on 2000/11/19 05:21:37 UTC

cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer AbstractPropertyEditor.java DoublePropertyEditor.java IntegerPropertyEditor.java PropertiesPropertyEditor.java StringArrayPropertyEditor.java StringPropertyEditor.java

metasim     00/11/18 20:21:37

  Modified:    src/antidote/org/apache/tools/ant/gui PropertyEditor.java
               src/antidote/org/apache/tools/ant/gui/acs ACSElement.java
               src/antidote/org/apache/tools/ant/gui/customizer
                        AbstractPropertyEditor.java
                        DoublePropertyEditor.java
                        IntegerPropertyEditor.java
                        PropertiesPropertyEditor.java
                        StringArrayPropertyEditor.java
                        StringPropertyEditor.java
  Log:
  Added generic attribute editing capability for tasks.
  
  Revision  Changes    Path
  1.9       +6 -3      jakarta-ant/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java
  
  Index: PropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PropertyEditor.java	2000/11/16 22:38:38	1.8
  +++ PropertyEditor.java	2000/11/19 04:21:35	1.9
  @@ -63,11 +63,12 @@
   import java.io.IOException;
   import java.awt.BorderLayout;
   import java.awt.Component;
  +import java.awt.Point;
   
   /**
    * Stub for a property editor.
    *
  - * @version $Revision: 1.8 $ 
  + * @version $Revision: 1.9 $ 
    * @author Simeon H.K. Fitch 
    */
   class PropertyEditor extends AntEditor {
  @@ -76,6 +77,8 @@
       private Customizer _customizer = null;
       /** Container for the customizer. */
       private JPanel _container = null;
  +    /** Scroll area containing contents. */
  +    private JScrollPane _scroller = null;
   
   	/** 
   	 * Standard ctor.
  @@ -87,7 +90,7 @@
           context.getEventBus().addMember(EventBus.MONITORING, new Handler());
           setLayout(new BorderLayout());
           _container = new JPanel(new BorderLayout());
  -        add(new JScrollPane(_container));
  +        add(_scroller = new JScrollPane(_container));
   	}
   
   	/** 
  @@ -115,7 +118,7 @@
               }
           }
   
  -        validate();
  +        _container.revalidate();
       }
   
   
  
  
  
  1.5       +2 -2      jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java
  
  Index: ACSElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ACSElement.java	2000/11/14 19:48:06	1.4
  +++ ACSElement.java	2000/11/19 04:21:35	1.5
  @@ -62,7 +62,7 @@
    * Abstract base class for all Ant Construction Set
    * elements. Depends on the JAXP XML library from Sun.
    * 
  - * @version $Revision: 1.4 $ 
  + * @version $Revision: 1.5 $ 
    * @author Simeon Fitch */
   public abstract class ACSElement extends ElementNode {
       /** Name of the 'xmlString' property. */
  @@ -103,7 +103,7 @@
   	 * @param value Value of the attribute.
   	 */
       public void setAttribute(String name, String value) {
  -        if(value == null || value.length() == 0) {
  +        if(value == null && getAttribute(name).length() != 0) {
               removeAttribute(name);
           }
           else {
  
  
  
  1.2       +4 -2      jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java
  
  Index: AbstractPropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractPropertyEditor.java	2000/11/10 20:41:17	1.1
  +++ AbstractPropertyEditor.java	2000/11/19 04:21:36	1.2
  @@ -57,6 +57,7 @@
   import java.awt.Graphics;
   import java.awt.Component;
   import java.awt.Rectangle;
  +import java.awt.Dimension;
   import javax.swing.JComponent;
   import java.awt.event.FocusEvent;
   import java.awt.event.FocusAdapter;
  @@ -64,15 +65,16 @@
   /**
    * Abstract base class for the custom type property editors.
    * 
  - * @version $Revision: 1.1 $ 
  + * @version $Revision: 1.2 $ 
    * @author Simeon Fitch 
    */
   public abstract class AbstractPropertyEditor implements PropertyEditor {
   
       /** Bean property change property name. */
       public static final String BEAN_PROP = "BeanEditorProperty";
  -
  +    /** Event listener support. */
       private PropertyChangeSupport _listeners = new PropertyChangeSupport(this);
  +
       /** 
        * Default constructor.
        * 
  
  
  
  1.2       +1 -4      jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java
  
  Index: DoublePropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DoublePropertyEditor.java	2000/11/10 20:41:17	1.1
  +++ DoublePropertyEditor.java	2000/11/19 04:21:36	1.2
  @@ -59,7 +59,7 @@
   /**
    * Custom property editor for editing double values.
    * 
  - * @version $Revision: 1.1 $ 
  + * @version $Revision: 1.2 $ 
    * @author Simeon Fitch 
    */
   public class DoublePropertyEditor extends AbstractPropertyEditor {
  @@ -117,8 +117,6 @@
           }
   
           _widget.setText(value.toString());
  -        
  -        firePropertyChange(old, value);
       }
   
       /**
  @@ -155,7 +153,6 @@
           }
           text = val.toString();
           _widget.setText(text);
  -        firePropertyChange(old, text);
       }
   
       /**
  
  
  
  1.2       +1 -4      jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java
  
  Index: IntegerPropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntegerPropertyEditor.java	2000/11/10 20:41:17	1.1
  +++ IntegerPropertyEditor.java	2000/11/19 04:21:36	1.2
  @@ -59,7 +59,7 @@
   /**
    * Custom property editor for integer types.
    * 
  - * @version $Revision: 1.1 $ 
  + * @version $Revision: 1.2 $ 
    * @author Simeon Fitch 
    */
   public class IntegerPropertyEditor extends AbstractPropertyEditor {
  @@ -117,8 +117,6 @@
           }
   
           _widget.setText(value.toString());
  -        
  -        firePropertyChange(old, value);
       }
   
       /**
  @@ -155,7 +153,6 @@
           }
           text = val.toString();
           _widget.setText(text);
  -        firePropertyChange(old, text);
       }
   
       /**
  
  
  
  1.2       +122 -28   jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/PropertiesPropertyEditor.java
  
  Index: PropertiesPropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/PropertiesPropertyEditor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertiesPropertyEditor.java	2000/11/17 22:39:03	1.1
  +++ PropertiesPropertyEditor.java	2000/11/19 04:21:36	1.2
  @@ -63,12 +63,19 @@
   /**
    * Custom property editor for the Properties class.
    * 
  - * @version $Revision: 1.1 $ 
  + * @version $Revision: 1.2 $ 
    * @author Simeon Fitch 
    */
   public class PropertiesPropertyEditor extends AbstractPropertyEditor {
  +    /** Recommended size for widgets inside a JScrollPane, as communicated
  +     *  through the setPreferredScrollableViewportSize() method. */
  +    protected static final Dimension VIEWPORT_SIZE = new Dimension(200, 50);
  +
  +    /** Container. */
       private JPanel _widget = null;
  -    private Properties _value = null;
  +    /* The current properties being edited. */
  +    private Properties _properties = null;
  +    /** The table editor for the properties. */
       private JTable _table = null;
   
       /** 
  @@ -80,7 +87,7 @@
           _widget.addFocusListener(new FocusHandler(this));
   
           _table = new JTable();
  -        _table.setPreferredScrollableViewportSize(new Dimension(300, 100));
  +        _table.setPreferredScrollableViewportSize(VIEWPORT_SIZE);
           JScrollPane scroller = new JScrollPane(_table);
           _widget.add(BorderLayout.CENTER, scroller);
       }
  @@ -125,21 +132,22 @@
               throw new IllegalArgumentException(
                   value.getClass().getName() + " is not of type Properties.");
           }
  -
  -        Object old = _value;
  -        _value = (Properties) value;
   
  -        _table.setModel(new PropertiesTableModel(_value));
  +        Object old = _properties;
  +        _properties = (Properties) ((Properties) value).clone();
   
  -        firePropertyChange(old, value);
  +        PropertiesTableModel model = new PropertiesTableModel();
  +        _table.setModel(model);
  +        _table.clearSelection();
       }
   
       /**
  -     * @return The value of the property.  Builtin types such as "int" will
  -     * be wrapped as the corresponding object type such as "java.lang.Integer".
  +     * @return The value of the property.  Builtin types
  +     * such as "int" will be wrapped as the corresponding
  +     * object type such as "java.lang.Integer".  
        */
       public Object getValue() {
  -        return _value;
  +        return _properties;
       }
   
       /**
  @@ -165,46 +173,132 @@
       } 
   
       /** Table model view of the Properties object. */
  -    private static class PropertiesTableModel extends AbstractTableModel {
  +    private class PropertiesTableModel extends AbstractTableModel {
           private static final int NAME = 0;
           private static final int VALUE = 1;
   
  -        private Properties _properties = null;
  -        private String[] _keys = null;
  +        private List _keys = null;
   
  -        public PropertiesTableModel(Properties props) {
  -            _properties = props;
  -
  -            Enumeration enum = _properties.keys();
  -            _keys = new String[_properties.size()];
  -            for(int i = 0; enum.hasMoreElements(); i++) {
  -                String key = (String) enum.nextElement();
  -                _keys[i] = key;
  -            }
  +        public PropertiesTableModel() {
  +            // We need to store the property keys in an array
  +            // so that the ordering is preserved.
  +            _keys = new ArrayList(_properties.keySet());
  +            Collections.sort(_keys);
           }
   
  +        /** 
  +         * Get the number of rows. 
  +         * 
  +         * @return Number of rows.
  +         */
           public int getRowCount() {
  -            return _keys.length;
  +            return _properties.size() + 1;
           }
   
  +        /** 
  +         * Get the number of columns.
  +         * 
  +         * @return 2
  +         */
           public int getColumnCount() {
               return 2;
           }
   
  +        /** 
  +         * Get the editing and display class of the given column.
  +         * 
  +         * @return String.class
  +         */
  +        public Class getColumnClass(int column) {
  +            return String.class;
  +        }
  +
  +        /** 
  +         * Get the header name of the column.
  +         * 
  +         * @param column Column index.
  +         * @return Name of the column.
  +         */
           public String getColumnName(int column) {
               // XXX fix me.
               return column == NAME ? "Name" : "Value";
           }
  +
  +        /** 
  +         * Determine if the given cell is editable.
  +         * 
  +         * @param row Cell row.
  +         * @param column Cell column.
  +         * @return true
  +         */
  +        public boolean isCellEditable(int row, int column) {
  +            return true;
  +        }
  +
  +        /** 
  +         * Get the object at the given table coordinates.
  +         * 
  +         * @param row Table row.
  +         * @param column Table column.
  +         * @return Object at location, or null if none.
  +         */
           public Object getValueAt(int row, int column) {
  -            switch(column) {
  -              case NAME: return _keys[row];
  -              case VALUE: return _properties.getProperty(_keys[row]);
  +            if(row < _properties.size()) {
  +                switch(column) {
  +                  case NAME: 
  +                      return _keys.get(row);
  +                  case VALUE: 
  +                      return _properties.getProperty((String)_keys.get(row));
  +                }
               }
               return null;
           }
  -    }
  +        /** 
  +         * Set the table value at the given location.
  +         * 
  +         * @param value Value to set.
  +         * @param row Row.
  +         * @param column Column.
  +         */
  +        public void setValueAt(Object value, int row, int column) {
  +            String k = null;
  +            String v = null;
   
  +            String currKey = (String) getValueAt(row, NAME);
  +            switch(column) {
  +              case NAME: 
  +                  k = String.valueOf(value);
  +                  if(row < _keys.size()) {
  +                      _keys.set(row, k);
  +                  }
  +                  else {
  +                      _keys.add(k);
  +                  }
  +                  String currValue = null;
  +                  if(currKey != null) {
  +                      currValue = _properties.getProperty(currKey);
  +                      _properties.remove(currKey);
  +                  }
  +                  v = currValue == null ? "" : currValue;
  +                  break;
  +              case VALUE:
  +                  v = String.valueOf(value);
  +                  k = currKey;
  +                  if(k == null || k.length() == 0) {
  +                      k = "key-for-" + v;
  +                  }
  +                  break;
  +            }
   
  +            if(k.length() > 0) {
  +                _properties.setProperty(k, v);
  +            }
  +
  +            fireTableRowsUpdated(row, row);
  +            // Fire change in outer class.
  +            firePropertyChange(null, _properties);
  +        }
  +    }
   }
   
   
  
  
  
  1.3       +3 -5      jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/StringArrayPropertyEditor.java
  
  Index: StringArrayPropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/StringArrayPropertyEditor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringArrayPropertyEditor.java	2000/11/16 22:59:35	1.2
  +++ StringArrayPropertyEditor.java	2000/11/19 04:21:36	1.3
  @@ -61,18 +61,18 @@
   /**
    * Custom property editor for String arrays.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class StringArrayPropertyEditor extends AbstractPropertyEditor {
  -    private JTextPane _widget = null;
  +    private JTextField _widget = null;
   
       /** 
        * Default ctor.
        * 
        */
       public StringArrayPropertyEditor() {
  -        _widget = new JTextPane();
  +        _widget = new JTextField() ;
           _widget.setBorder(
               BorderFactory.createBevelBorder(BevelBorder.LOWERED));
           _widget.addFocusListener(new FocusHandler(this));
  @@ -130,7 +130,6 @@
               }
           }
           _widget.setText(buf.toString());
  -        firePropertyChange(old, buf.toString());
       }
   
       /**
  @@ -158,7 +157,6 @@
       public void setAsText(String text) throws IllegalArgumentException {
           Object old = _widget.getText();
           _widget.setText(text);
  -        firePropertyChange(old, text);
       }
   
       /**
  
  
  
  1.3       +17 -9     jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java
  
  Index: StringPropertyEditor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringPropertyEditor.java	2000/11/16 22:59:35	1.2
  +++ StringPropertyEditor.java	2000/11/19 04:21:36	1.3
  @@ -60,18 +60,24 @@
   /**
    * Custom property editor for string types.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class StringPropertyEditor extends AbstractPropertyEditor {
  -    private JTextPane _widget = null;
  +    private JTextArea _widget = null;
   
       /** 
        * Default ctor.
        * 
        */
       public StringPropertyEditor() {
  -        _widget = new JTextPane();
  +        _widget = new JTextArea() {
  +                public boolean isManagingFocus() {
  +                    return false;
  +                }
  +            };
  +
  +        _widget.setLineWrap(true);
           _widget.addFocusListener(new FocusHandler(this));
           _widget.setBorder(
               BorderFactory.createBevelBorder(BevelBorder.LOWERED));
  @@ -115,15 +121,18 @@
       public void setValue(Object value) {
           Object old = _widget.getText();
           _widget.setText(String.valueOf(value));
  -        firePropertyChange(old, value);
       }
   
       /**
  -     * @return The value of the property.  Builtin types such as "int" will
  -     * be wrapped as the corresponding object type such as "java.lang.Integer".
  -     */
  +     * @return The value of the property.  Builtin types
  +     * such as "int" will be wrapped as the corresponding
  +     * object type such as "java.lang.Integer".  */
       public Object getValue() {
  -        return _widget.getText();
  +        String retval = _widget.getText();
  +        if(retval != null && retval.length() == 0) {
  +            retval = null;
  +        }
  +        return retval;
       }
   
       /**
  @@ -136,7 +145,6 @@
       public void setAsText(String text) throws IllegalArgumentException {
           Object old = _widget.getText();
           _widget.setText(text);
  -        firePropertyChange(old, text);
       }
   
       /**