org.jdesktop.swingx.editors.DimensionPropertyEditor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swingx Show documentation
Show all versions of swingx Show documentation
Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications.
/*
* 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