package com.macfaq; import java.beans.*; import java.io.*; import java.awt.*; import java.awt.event.*; public class FileEditor extends PropertyEditorSupport { protected File f; public Object getValue() { return new File(f.toString()); } public void setValue(Object o) { File f = (File) o; this.f = new File(f.toString()); } public boolean supportsCustomEditor() { return true; } public boolean isPaintable() { return true; } public void paintValue(Graphics g, Rectangle r) { String filename = f.getName(); Font mono = new Font("Serif", Font.PLAIN, 12); FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(mono); g.setFont(mono); g.drawString(filename, 3, r.height - fm.getMaxDescent()); } public Component getCustomEditor() { Button b = new Button("Choose File..."); b.addActionListener(new FileChooser()); return b; } class FileChooser implements ActionListener { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(new Frame(), "Please select the file:", FileDialog.LOAD); fd.setVisible(true); String file = fd.getFile(); String dir = fd.getDirectory(); if (file != null) { setValue(new File(dir, file)); firePropertyChange(); } } } }