Search in sources :

Example 6 with Range

use of maspack.util.Range in project artisynth_core by artisynth.

the class SetHandler method create.

public static LabeledComponentBase create(Property prop, double min, double max) {
    String name = prop.getName();
    PropertyInfo info = prop.getInfo();
    Class<?> type = info.getValueClass();
    LabeledComponentBase widget = null;
    if (type == double.class || type == float.class || type == Double.class || type == Float.class) {
        DoubleFieldSlider doubleSlider = new DoubleFieldSlider(name, min, max);
        if (info.getPrintFormat() != null) {
            doubleSlider.setFormat(info.getPrintFormat());
        }
        Range range = prop.getRange();
        if (range instanceof NumericInterval) {
            NumericInterval nrange = (NumericInterval) range;
            doubleSlider.setRange(nrange);
            if (nrange.isBounded()) {
                doubleSlider.setSliderRange(nrange);
            }
        }
        GuiUtils.setFixedWidth(doubleSlider.getTextField(), 100);
        doubleSlider.addValueChangeListener(new PropChangeListener(prop));
        widget = doubleSlider;
    } else if (type == int.class || type == Integer.class) {
        IntegerFieldSlider intSlider = new IntegerFieldSlider(name, (int) min, (int) max);
        Range range = prop.getRange();
        if (range instanceof IntegerInterval) {
            IntegerInterval irange = (IntegerInterval) range;
            intSlider.setRange(irange);
            if (irange.isBounded()) {
                intSlider.setSliderRange(irange);
            }
        // intSlider.setSliderRange ((IntRange)range);
        }
        GuiUtils.setFixedWidth(intSlider.getTextField(), 100);
        intSlider.addValueChangeListener(new PropChangeListener(prop));
        widget = intSlider;
    }
    if (widget != null) {
        widget.setToolTipText(info.getDescription());
        finishWidget(widget, prop);
    }
    return widget;
}
Also used : IntegerInterval(maspack.util.IntegerInterval) PropertyInfo(maspack.properties.PropertyInfo) EnumRange(maspack.util.EnumRange) StringRange(maspack.util.StringRange) Range(maspack.util.Range) NumericInterval(maspack.util.NumericInterval)

Example 7 with Range

use of maspack.util.Range in project artisynth_core by artisynth.

the class SetHandler method createWidget.

protected static LabeledComponentBase createWidget(Property prop) {
    PropertyInfo info = prop.getInfo();
    Class<?> type = info.getValueClass();
    if (String.class.isAssignableFrom(type)) {
        Range range = prop.getRange();
        if (info.isReadOnly() || range == null || !(range instanceof StringRange) || ((StringRange) range).isWildcard()) {
            return new StringField();
        } else {
            return new StringSelector();
        }
    } else if (type == double.class || type == float.class || type == Double.class || type == Float.class) {
        return new DoubleField();
    } else if (type == int.class || type == Integer.class) {
        return new IntegerField();
    } else if (type == boolean.class || type == Boolean.class) {
        if (info.isReadOnly()) {
            return new StringField();
        } else {
            return new BooleanSelector();
        }
    } else if (VectorBase.class.isAssignableFrom(type)) {
        if (VectorNd.class.isAssignableFrom(type) || info.getDimension() == -1) {
            return new VariableVectorField();
        } else {
            return new VectorField();
        }
    } else if (VectoriBase.class.isAssignableFrom(type) && info.getDimension() != -1) {
        return new VectoriField();
    } else if (SymmetricMatrix3d.class.isAssignableFrom(type)) {
        return new SymmetricMatrix3dField();
    } else if (RigidTransform3d.class.isAssignableFrom(type)) {
        return new RigidTransformWidget();
    } else if (AffineTransform3d.class.isAssignableFrom(type)) {
        return new AffineTransformWidget();
    } else // }
    if (Rectangle2d.class.isAssignableFrom(type)) {
        return new RectangleField();
    } else if (AxisAngle.class.isAssignableFrom(type)) {
        return new AxisAngleField();
    } else if (Enum.class.isAssignableFrom(type)) {
        if (info.isReadOnly()) {
            return new StringField();
        } else {
            return new EnumSelector();
        }
    } else if (Color.class.isAssignableFrom(type)) {
        return new ColorSelector();
    } else if (IntegerInterval.class.isAssignableFrom(type)) {
        return new IntegerIntervalField();
    } else if (NumericInterval.class.isAssignableFrom(type)) {
        return new DoubleIntervalField();
    } else if (GLGridResolution.class.isAssignableFrom(type)) {
        return new GridResolutionField();
    } else if (Font.class.isAssignableFrom(type)) {
        return new FontField();
    } else if (CompositeProperty.class.isAssignableFrom(type)) {
        Class<?>[] subclasses = PropertyUtils.findCompositePropertySubclasses(type);
        if (subclasses != null) {
            return new CompositePropertyPanel();
        } else {
            return new CompositePropertyWidget();
        }
    // if (info.getWidgetType() == PropertyInfo.WidgetType.Panel) {
    // return new CompositePropertyWidget();
    // }
    // else {
    // return new CompositePropertyWidget();
    // }
    } else {
        return null;
    }
}
Also used : Rectangle2d(maspack.geometry.Rectangle2d) GLGridResolution(maspack.render.GL.GLGridResolution) CompositeProperty(maspack.properties.CompositeProperty) RigidTransform3d(maspack.matrix.RigidTransform3d) IntegerInterval(maspack.util.IntegerInterval) EnumRange(maspack.util.EnumRange) StringRange(maspack.util.StringRange) Range(maspack.util.Range) StringRange(maspack.util.StringRange) VectorNd(maspack.matrix.VectorNd) PropertyInfo(maspack.properties.PropertyInfo)

Aggregations

Range (maspack.util.Range)7 EnumRange (maspack.util.EnumRange)5 StringRange (maspack.util.StringRange)5 PropertyInfo (maspack.properties.PropertyInfo)4 NumericInterval (maspack.util.NumericInterval)4 IntegerInterval (maspack.util.IntegerInterval)3 VectorNd (maspack.matrix.VectorNd)2 InternalErrorException (maspack.util.InternalErrorException)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Rectangle2d (maspack.geometry.Rectangle2d)1 AffineTransform3d (maspack.matrix.AffineTransform3d)1 AxisAngle (maspack.matrix.AxisAngle)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)1 VectorBase (maspack.matrix.VectorBase)1 VectorNi (maspack.matrix.VectorNi)1 VectoriBase (maspack.matrix.VectoriBase)1 CompositeProperty (maspack.properties.CompositeProperty)1 GLGridResolution (maspack.render.GL.GLGridResolution)1