All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.swingx.editors.DimensionPropertyEditor Maven / Gradle / Ivy

Go to download

Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications.

There is a newer version: 1.6.1
Show newest version
/*
 * DimensionPropertyEditor.java
 *
 * Created on August 16, 2006, 12:18 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jdesktop.swingx.editors;

import java.awt.Dimension;
import java.beans.PropertyEditorSupport;

/**
 *
 * @author joshy
 */
public class DimensionPropertyEditor extends PropertyEditorSupport {
    
    public DimensionPropertyEditor() {
    }
    
    public Dimension getValue() {
        return (Dimension)super.getValue();
    }
    
    public String getJavaInitializationString() {
        Dimension point = getValue();
        return point == null ? "null" : "new java.awt.Dimension(" + point.width + ", " + point.height + ")";
    }
    
    public void setAsText(String text) throws IllegalArgumentException {
        String originalParam = text;
        try {
            Dimension val = (Dimension)PropertyEditorUtil.createValueFromString(
                    text, 2, Dimension.class, int.class);
            setValue(val);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            throw new IllegalArgumentException("The input value " + originalParam + " is not formatted correctly. Please " +
                    "try something of the form [w,h] or [w , h] or [w h]", ex);
        }
    }
    
    public String getAsText() {
        Dimension dim = getValue();
        return dim == null ? "[]" : "[" + dim.width + ", " + dim.height + "]";
    }
    
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy