001 /* 002 * ShapePropertyEditor.java 003 * 004 * Created on August 23, 2006, 10:17 PM 005 * 006 * To change this template, choose Tools | Template Manager 007 * and open the template in the editor. 008 */ 009 010 package org.jdesktop.swingx.editors; 011 012 import java.awt.Component; 013 import java.awt.Rectangle; 014 import java.awt.Shape; 015 import java.awt.event.ActionEvent; 016 import java.awt.event.ActionListener; 017 import java.awt.geom.Ellipse2D; 018 import java.awt.geom.Rectangle2D; 019 import java.beans.PropertyEditorSupport; 020 021 022 /** 023 * 024 * @author joshy 025 */ 026 public class ShapePropertyEditor extends PropertyEditorSupport { 027 ShapeChooser chooser; 028 /** Creates a new instance of ShapePropertyEditor */ 029 public ShapePropertyEditor() { 030 chooser = new ShapeChooser(); 031 chooser.shapeCombo.addActionListener(new ActionListener() { 032 public void actionPerformed(ActionEvent actionEvent) { 033 if(chooser.shapeCombo.getSelectedItem().equals("Square")) { 034 setValue(new Rectangle(0,0,100,100)); 035 } else { 036 setValue(new Ellipse2D.Double(0,0,100,100)); 037 } 038 } 039 }); 040 } 041 042 public Shape getValue() { 043 return (Shape)super.getValue(); 044 } 045 046 public void setValue(Object value) { 047 super.setValue(value); 048 } 049 050 public boolean isPaintable() { 051 return true; 052 } 053 054 public boolean supportsCustomEditor() { 055 return true; 056 } 057 058 public Component getCustomEditor() { 059 return chooser; 060 } 061 }