git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268206 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,3 +1,12 @@ | |||||
| 2000-11-18 Simeon H.K. Fitch <simeon@fitch.net> | |||||
| * org/apache/tools/ant/gui/customizer/PropertiesPropertyEditor.java: | |||||
| Added proper editing capability. Rows are added and removed | |||||
| automatically. | |||||
| * org/apache/tools/ant/gui/customizer/XXXPropertyEditor.java: | |||||
| Removed stray event firing upon setting value of property to edit. | |||||
| 2000-11-16 Simeon H.K. Fitch <simeon@fitch.net> | 2000-11-16 Simeon H.K. Fitch <simeon@fitch.net> | ||||
| * org/apache/tools/ant/gui/customizer/StringPropertyEditor.java: | * org/apache/tools/ant/gui/customizer/StringPropertyEditor.java: | ||||
| @@ -63,6 +63,7 @@ import java.io.StringReader; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.awt.BorderLayout; | import java.awt.BorderLayout; | ||||
| import java.awt.Component; | import java.awt.Component; | ||||
| import java.awt.Point; | |||||
| /** | /** | ||||
| * Stub for a property editor. | * Stub for a property editor. | ||||
| @@ -76,6 +77,8 @@ class PropertyEditor extends AntEditor { | |||||
| private Customizer _customizer = null; | private Customizer _customizer = null; | ||||
| /** Container for the customizer. */ | /** Container for the customizer. */ | ||||
| private JPanel _container = null; | private JPanel _container = null; | ||||
| /** Scroll area containing contents. */ | |||||
| private JScrollPane _scroller = null; | |||||
| /** | /** | ||||
| * Standard ctor. | * Standard ctor. | ||||
| @@ -87,7 +90,7 @@ class PropertyEditor extends AntEditor { | |||||
| context.getEventBus().addMember(EventBus.MONITORING, new Handler()); | context.getEventBus().addMember(EventBus.MONITORING, new Handler()); | ||||
| setLayout(new BorderLayout()); | setLayout(new BorderLayout()); | ||||
| _container = new JPanel(new BorderLayout()); | _container = new JPanel(new BorderLayout()); | ||||
| add(new JScrollPane(_container)); | |||||
| add(_scroller = new JScrollPane(_container)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -115,7 +118,7 @@ class PropertyEditor extends AntEditor { | |||||
| } | } | ||||
| } | } | ||||
| validate(); | |||||
| _container.revalidate(); | |||||
| } | } | ||||
| @@ -103,7 +103,7 @@ public abstract class ACSElement extends ElementNode { | |||||
| * @param value Value of the attribute. | * @param value Value of the attribute. | ||||
| */ | */ | ||||
| public void setAttribute(String name, String value) { | public void setAttribute(String name, String value) { | ||||
| if(value == null || value.length() == 0) { | |||||
| if(value == null && getAttribute(name).length() != 0) { | |||||
| removeAttribute(name); | removeAttribute(name); | ||||
| } | } | ||||
| else { | else { | ||||
| @@ -57,6 +57,7 @@ import java.beans.*; | |||||
| import java.awt.Graphics; | import java.awt.Graphics; | ||||
| import java.awt.Component; | import java.awt.Component; | ||||
| import java.awt.Rectangle; | import java.awt.Rectangle; | ||||
| import java.awt.Dimension; | |||||
| import javax.swing.JComponent; | import javax.swing.JComponent; | ||||
| import java.awt.event.FocusEvent; | import java.awt.event.FocusEvent; | ||||
| import java.awt.event.FocusAdapter; | import java.awt.event.FocusAdapter; | ||||
| @@ -71,8 +72,9 @@ public abstract class AbstractPropertyEditor implements PropertyEditor { | |||||
| /** Bean property change property name. */ | /** Bean property change property name. */ | ||||
| public static final String BEAN_PROP = "BeanEditorProperty"; | public static final String BEAN_PROP = "BeanEditorProperty"; | ||||
| /** Event listener support. */ | |||||
| private PropertyChangeSupport _listeners = new PropertyChangeSupport(this); | private PropertyChangeSupport _listeners = new PropertyChangeSupport(this); | ||||
| /** | /** | ||||
| * Default constructor. | * Default constructor. | ||||
| * | * | ||||
| @@ -117,8 +117,6 @@ public class DoublePropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| _widget.setText(value.toString()); | _widget.setText(value.toString()); | ||||
| firePropertyChange(old, value); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -155,7 +153,6 @@ public class DoublePropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| text = val.toString(); | text = val.toString(); | ||||
| _widget.setText(text); | _widget.setText(text); | ||||
| firePropertyChange(old, text); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -117,8 +117,6 @@ public class IntegerPropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| _widget.setText(value.toString()); | _widget.setText(value.toString()); | ||||
| firePropertyChange(old, value); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -155,7 +153,6 @@ public class IntegerPropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| text = val.toString(); | text = val.toString(); | ||||
| _widget.setText(text); | _widget.setText(text); | ||||
| firePropertyChange(old, text); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -67,8 +67,15 @@ import java.util.*; | |||||
| * @author Simeon Fitch | * @author Simeon Fitch | ||||
| */ | */ | ||||
| public class PropertiesPropertyEditor extends AbstractPropertyEditor { | 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 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; | private JTable _table = null; | ||||
| /** | /** | ||||
| @@ -80,7 +87,7 @@ public class PropertiesPropertyEditor extends AbstractPropertyEditor { | |||||
| _widget.addFocusListener(new FocusHandler(this)); | _widget.addFocusListener(new FocusHandler(this)); | ||||
| _table = new JTable(); | _table = new JTable(); | ||||
| _table.setPreferredScrollableViewportSize(new Dimension(300, 100)); | |||||
| _table.setPreferredScrollableViewportSize(VIEWPORT_SIZE); | |||||
| JScrollPane scroller = new JScrollPane(_table); | JScrollPane scroller = new JScrollPane(_table); | ||||
| _widget.add(BorderLayout.CENTER, scroller); | _widget.add(BorderLayout.CENTER, scroller); | ||||
| } | } | ||||
| @@ -126,20 +133,21 @@ public class PropertiesPropertyEditor extends AbstractPropertyEditor { | |||||
| value.getClass().getName() + " is not of type Properties."); | 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() { | public Object getValue() { | ||||
| return _value; | |||||
| return _properties; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -165,46 +173,132 @@ public class PropertiesPropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| /** Table model view of the Properties object. */ | /** 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 NAME = 0; | ||||
| private static final int VALUE = 1; | private static final int VALUE = 1; | ||||
| private Properties _properties = null; | |||||
| private String[] _keys = null; | |||||
| public PropertiesTableModel(Properties props) { | |||||
| _properties = props; | |||||
| private List _keys = null; | |||||
| 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() { | public int getRowCount() { | ||||
| return _keys.length; | |||||
| return _properties.size() + 1; | |||||
| } | } | ||||
| /** | |||||
| * Get the number of columns. | |||||
| * | |||||
| * @return 2 | |||||
| */ | |||||
| public int getColumnCount() { | public int getColumnCount() { | ||||
| return 2; | 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) { | public String getColumnName(int column) { | ||||
| // XXX fix me. | // XXX fix me. | ||||
| return column == NAME ? "Name" : "Value"; | 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) { | 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; | 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); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -65,14 +65,14 @@ import java.util.StringTokenizer; | |||||
| * @author Simeon Fitch | * @author Simeon Fitch | ||||
| */ | */ | ||||
| public class StringArrayPropertyEditor extends AbstractPropertyEditor { | public class StringArrayPropertyEditor extends AbstractPropertyEditor { | ||||
| private JTextPane _widget = null; | |||||
| private JTextField _widget = null; | |||||
| /** | /** | ||||
| * Default ctor. | * Default ctor. | ||||
| * | * | ||||
| */ | */ | ||||
| public StringArrayPropertyEditor() { | public StringArrayPropertyEditor() { | ||||
| _widget = new JTextPane(); | |||||
| _widget = new JTextField() ; | |||||
| _widget.setBorder( | _widget.setBorder( | ||||
| BorderFactory.createBevelBorder(BevelBorder.LOWERED)); | BorderFactory.createBevelBorder(BevelBorder.LOWERED)); | ||||
| _widget.addFocusListener(new FocusHandler(this)); | _widget.addFocusListener(new FocusHandler(this)); | ||||
| @@ -130,7 +130,6 @@ public class StringArrayPropertyEditor extends AbstractPropertyEditor { | |||||
| } | } | ||||
| } | } | ||||
| _widget.setText(buf.toString()); | _widget.setText(buf.toString()); | ||||
| firePropertyChange(old, buf.toString()); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -158,7 +157,6 @@ public class StringArrayPropertyEditor extends AbstractPropertyEditor { | |||||
| public void setAsText(String text) throws IllegalArgumentException { | public void setAsText(String text) throws IllegalArgumentException { | ||||
| Object old = _widget.getText(); | Object old = _widget.getText(); | ||||
| _widget.setText(text); | _widget.setText(text); | ||||
| firePropertyChange(old, text); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -64,14 +64,20 @@ import javax.swing.border.BevelBorder; | |||||
| * @author Simeon Fitch | * @author Simeon Fitch | ||||
| */ | */ | ||||
| public class StringPropertyEditor extends AbstractPropertyEditor { | public class StringPropertyEditor extends AbstractPropertyEditor { | ||||
| private JTextPane _widget = null; | |||||
| private JTextArea _widget = null; | |||||
| /** | /** | ||||
| * Default ctor. | * Default ctor. | ||||
| * | * | ||||
| */ | */ | ||||
| public StringPropertyEditor() { | public StringPropertyEditor() { | ||||
| _widget = new JTextPane(); | |||||
| _widget = new JTextArea() { | |||||
| public boolean isManagingFocus() { | |||||
| return false; | |||||
| } | |||||
| }; | |||||
| _widget.setLineWrap(true); | |||||
| _widget.addFocusListener(new FocusHandler(this)); | _widget.addFocusListener(new FocusHandler(this)); | ||||
| _widget.setBorder( | _widget.setBorder( | ||||
| BorderFactory.createBevelBorder(BevelBorder.LOWERED)); | BorderFactory.createBevelBorder(BevelBorder.LOWERED)); | ||||
| @@ -115,15 +121,18 @@ public class StringPropertyEditor extends AbstractPropertyEditor { | |||||
| public void setValue(Object value) { | public void setValue(Object value) { | ||||
| Object old = _widget.getText(); | Object old = _widget.getText(); | ||||
| _widget.setText(String.valueOf(value)); | _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() { | 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 class StringPropertyEditor extends AbstractPropertyEditor { | |||||
| public void setAsText(String text) throws IllegalArgumentException { | public void setAsText(String text) throws IllegalArgumentException { | ||||
| Object old = _widget.getText(); | Object old = _widget.getText(); | ||||
| _widget.setText(text); | _widget.setText(text); | ||||
| firePropertyChange(old, text); | |||||
| } | } | ||||
| /** | /** | ||||