Update of /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/gui/swing
In directory sc8-pr-cvs1:/tmp/cvs-serv14848/src/java/xdoclet/gui/swing

Modified Files:
        PropertySheet.java PropertyText.java 
Added Files:
        PropertyFile.java 
Log Message:
Added File editor for output directory

--- NEW FILE: PropertyFile.java ---
package xdoclet.gui.swing;

import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;

import java.beans.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;

/**
 * Support for a PropertyEditor that uses text.
 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Helles&oslash;y</a>
 * @version $Revision: 1.1 $
 */
class PropertyFile extends JPanel implements DocumentListener, PropertyChangeListener {
    private final PropertyEditor _propertyEditor;
    private final PropertyDescriptor _propertyDescriptor;
    private final Object _bean;

    private JTextField _fileField = new JTextField();
    private JFileChooser _fileChooser = new JFileChooser();

    private class BrowseAction extends AbstractAction {
        public BrowseAction() {
            super("...");
        }

        public void actionPerformed(ActionEvent evt) {
            int returnVal = _fileChooser.showDialog(PropertyFile.this, "Output 
Directory");
            if( returnVal == JFileChooser.APPROVE_OPTION ) {
                File file = _fileChooser.getSelectedFile();
//                _propertyEditor.setValue( file );
                _fileField.setText( file.getAbsolutePath() );
            }
        }
    }

    PropertyFile(PropertyEditor propertyEditor, PropertyDescriptor propertyDescriptor, 
Object bean ) {
        super(new BorderLayout());
System.out.println("new PropertyFile");
        _propertyEditor = propertyEditor;
        _propertyDescriptor = propertyDescriptor;
        _bean = bean;

        _fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        add( _fileField, BorderLayout.CENTER);
        add( new JButton(new BrowseAction()), BorderLayout.EAST);

        _fileField.setText(_propertyEditor.getValue() != null ? 
_propertyEditor.getAsText() : "");

        _fileField.getDocument().addDocumentListener(this);
        _propertyEditor.addPropertyChangeListener(this);
        updateEditor();
    }

    protected void updateEditor() {
        try {
            _propertyEditor.setValue(new File( _fileField.getText() ));
        } catch (IllegalArgumentException e) {
            LogFactory.getLog(PropertyFile.class).error("Couldn't set new value", e);
        }
    }

    public void propertyChange(PropertyChangeEvent evt) {
        // Set the new value
        try {
            // Get the source. Should be "our" Property editor.
            // The event will always contain null as the newValue :-(
            PropertyEditor propertyEditor = (PropertyEditor) evt.getSource();
            Object newValue = propertyEditor.getValue();
System.out.println("New value:" + newValue);
            _propertyDescriptor.getWriteMethod().invoke( _bean, new Object[] 
{newValue} );
        } catch (Exception e) {
            LogFactory.getLog(PropertyFile.class).error("Couldn't set new value", e);
            throw new IllegalStateException(e.getMessage());
        }
    }

    public void insertUpdate(DocumentEvent e) {
        updateEditor();
    }

    public void removeUpdate(DocumentEvent e) {
        updateEditor();
    }

    public void changedUpdate(DocumentEvent e) {
        updateEditor();
    }
}

Index: PropertySheet.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/gui/swing/PropertySheet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** PropertySheet.java  20 Mar 2003 20:08:40 -0000      1.6
--- PropertySheet.java  23 Mar 2003 13:30:43 -0000      1.7
***************
*** 1,6 ****
  package xdoclet.gui.swing;
  
! import javax.swing.JLabel;
! import javax.swing.JPanel;
  
  import java.awt.Component;
--- 1,7 ----
  package xdoclet.gui.swing;
  
! import org.apache.commons.logging.LogFactory;
! 
! import javax.swing.*;
  
  import java.awt.Component;
***************
*** 15,20 ****
  import java.beans.PropertyEditorManager;
  
- import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  /**
--- 16,21 ----
  import java.beans.PropertyEditorManager;
  
  import java.lang.reflect.Method;
+ import java.io.File;
  
  /**
***************
*** 81,98 ****
  
                  propertyEditor.setValue(value);
!             } catch (IllegalAccessException e) {
!                 e.printStackTrace(); //To change body of catch statement use Options 
| File Templates.
! 
!                 // JOptionPane.showMessageDialog(null,"IllegalAccessException: " + 
e.getMessage());
!                 throw new IntrospectionException(e.getMessage());
!             } catch (IllegalArgumentException e) {
!                 e.printStackTrace(); //To change body of catch statement use Options 
| File Templates.
! 
!                 // JOptionPane.showMessageDialog(null,"IllegalArgumentException: " + 
e.getMessage());
!                 throw new IntrospectionException(e.getMessage());
!             } catch (InvocationTargetException e) {
!                 e.printStackTrace(); //To change body of catch statement use Options 
| File Templates.
! 
!                 // JOptionPane.showMessageDialog(null,"InvocationTargetException: " 
+ e.getMessage());
                  throw new IntrospectionException(e.getMessage());
              }
--- 82,88 ----
  
                  propertyEditor.setValue(value);
!             } catch (Exception e) {
!                 LogFactory.getLog(PropertySheet.class).error("Couldn't create 
editor", e);
!                 JOptionPane.showMessageDialog(this,"Couldn't create editor: " + 
e.getMessage());
                  throw new IntrospectionException(e.getMessage());
              }
***************
*** 104,112 ****
              } else if (propertyEditor.getTags() != null) {
                  // editorComponent = new PropertySelector(editor);
!             } else if (propertyEditor.getAsText() != null) {
                  return new PropertyText(propertyEditor, propertyDescriptor, bean);
              }
          }
- 
          throw new IntrospectionException("Property \"" + propertyDescriptor.getName()
              + "\" has non-displayabale editor.");
--- 94,103 ----
              } else if (propertyEditor.getTags() != null) {
                  // editorComponent = new PropertySelector(editor);
!             } else if (getter.getReturnType().equals(String.class)) {
                  return new PropertyText(propertyEditor, propertyDescriptor, bean);
+             } else if (getter.getReturnType().equals(File.class)) {
+                 return new PropertyFile(propertyEditor, propertyDescriptor, bean);
              }
          }
          throw new IntrospectionException("Property \"" + propertyDescriptor.getName()
              + "\" has non-displayabale editor.");

Index: PropertyText.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/gui/swing/PropertyText.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** PropertyText.java   20 Mar 2003 20:08:41 -0000      1.5
--- PropertyText.java   23 Mar 2003 13:30:43 -0000      1.6
***************
*** 25,31 ****
          _bean = bean;
  
          getDocument().addDocumentListener(this);
-         updateEditor();
          _propertyEditor.addPropertyChangeListener(this);
      }
  
--- 25,33 ----
          _bean = bean;
  
+         setText(_propertyEditor.getValue() != null ? _propertyEditor.getAsText() : 
"");
+ 
          getDocument().addDocumentListener(this);
          _propertyEditor.addPropertyChangeListener(this);
+         updateEditor();
      }
  



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to