/**
* Adds listeners to automatically update lengths when proportional check box is checked.
*/
private void addListeners() {
this.widthChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
if (isProportional()) {
removePropertyChangeListener(Property.DEPTH, depthChangeListener);
removePropertyChangeListener(Property.HEIGHT, heightChangeListener);
// If proportions should be kept, update depth and height
float ratio = (Float)ev.getNewValue() / (Float)ev.getOldValue();
setDepth(getDepth() * ratio);
setHeight(getHeight() * ratio);
addPropertyChangeListener(Property.DEPTH, depthChangeListener);
addPropertyChangeListener(Property.HEIGHT, heightChangeListener);
}
}
};
this.depthChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
if (isProportional()) {
removePropertyChangeListener(Property.WIDTH, widthChangeListener);
removePropertyChangeListener(Property.HEIGHT, heightChangeListener);
// If proportions should be kept, update width and height
float ratio = (Float)ev.getNewValue() / (Float)ev.getOldValue();
setWidth(getWidth() * ratio);
setHeight(getHeight() * ratio);
addPropertyChangeListener(Property.WIDTH, widthChangeListener);
addPropertyChangeListener(Property.HEIGHT, heightChangeListener);
}
}
};
this.heightChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
if (isProportional()) {
removePropertyChangeListener(Property.WIDTH, widthChangeListener);
removePropertyChangeListener(Property.DEPTH, depthChangeListener);