001    /*
002     * InsetsPropertyEditor.java
003     *
004     * Created on July 20, 2006, 12:16 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.Insets;
013    import java.beans.PropertyEditorSupport;
014    
015    /**
016     *
017     * @author joshy
018     */
019    public class InsetsPropertyEditor extends PropertyEditorSupport {
020        
021        /** Creates a new instance of InsetsPropertyEditor */
022        public InsetsPropertyEditor() {
023        }
024        
025        public Insets getValue() {
026            return (Insets)super.getValue();
027        }
028        
029        public void setAsText(String text) {
030            String originalParam = text;
031            
032            try {
033                Insets val = (Insets)PropertyEditorUtil.createValueFromString(
034                        text, 4, Insets.class, int.class);
035                setValue(val);
036            } catch (Exception e) {
037                throw new IllegalArgumentException("The input value " + originalParam + " is not formatted correctly. Please " +
038                        "try something of the form [top,left,bottom,right] or [top , left , bottom , right] or [top left bottom right]", e);
039            }
040        }
041        
042        public String getAsText() {
043            Insets val = getValue();
044            return val == null ? "[]" : "[" + val.top + ", " + val.left + ", " + 
045                    val.bottom + ", " + val.right + "]";
046        }
047        
048    }