Search in sources :

Example 6 with PropertyInfo

use of maspack.properties.PropertyInfo 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 PropertyInfo

use of maspack.properties.PropertyInfo 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)

Example 8 with PropertyInfo

use of maspack.properties.PropertyInfo in project artisynth_core by artisynth.

the class SetHandler method finishWidget.

public static void finishWidget(LabeledComponentBase widget, Property prop) {
    Object value = prop.get();
    PropertyInfo info = prop.getInfo();
    if (widget instanceof LabeledControl) {
        LabeledControl control = (LabeledControl) widget;
        control.setVoidValueEnabled(true);
        control.maskValueChangeListeners(true);
        control.setValue(value);
        control.maskValueChangeListeners(false);
    }
    if (info.isReadOnly()) {
        if (widget instanceof LabeledControl) {
            ((LabeledControl) widget).setEnabledAll(false);
        } else if (widget instanceof Component) {
            ((Component) widget).setEnabled(false);
        }
    }
    if (info.hasRestrictedRange()) {
        if (widget instanceof LabeledControl) {
            ((LabeledControl) widget).addValueCheckListener(new PropCheckListener(prop));
        }
    }
}
Also used : PropertyInfo(maspack.properties.PropertyInfo) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 9 with PropertyInfo

use of maspack.properties.PropertyInfo in project artisynth_core by artisynth.

the class RenderPropsDialog method build.

// public RenderPropsDialog (Frame owner, String title,
// Iterable<? extends HasProperties> renderables) {
// super (owner, title);
// initialize ("Done Reset");
// build (renderables);
// inheritGlobalListeners (owner);
// setDefaultCloseOperation (DISPOSE_ON_CLOSE);
// }
// public RenderPropsDialog (Dialog owner, String title,
// Iterable<? extends HasProperties> renderables) {
// super (owner, title);
// initialize ("Done Reset");
// build (renderables);
// inheritGlobalListeners (owner);
// setDefaultCloseOperation (DISPOSE_ON_CLOSE);
// }
// public static RenderPropsDialog createDialog (
// Window win, String title, Iterable<? extends HasProperties> renderables) {
// RenderPropsDialog dialog;
// if (win instanceof Dialog) {
// dialog = new RenderPropsDialog ((Dialog)win, title, renderables);
// }
// else if (win instanceof Frame) {
// dialog = new RenderPropsDialog ((Frame)win, title, renderables);
// }
// else if (win == null) {
// dialog = new RenderPropsDialog (title, renderables);
// }
// else {
// throw new InternalErrorException ("Unsupported window type " + win);
// }
// return dialog;
// }
private void build(Iterable<? extends HasProperties> renderables) {
    myHostList = new HostList(renderables);
    Iterator<? extends HasProperties> it = renderables.iterator();
    if (!it.hasNext()) {
        throw new IllegalArgumentException("list of renderables is empty");
    }
    HasProperties renderable = it.next();
    PropertyInfo renderInfo = renderable.getAllPropertyInfo().get("renderProps");
    if (renderInfo == null) {
        throw new IllegalArgumentException("renderable '" + renderable.getClass() + "' does not contain property 'renderProps'");
    }
    PropTreeCell tree = new PropTreeCell();
    PropTreeCell renderCell = new PropTreeCell(renderInfo, null);
    tree.addChild(renderCell);
    // need to expand the host list down one level before we
    // can get to the render props
    myHostList.saveBackupValues(tree);
    // null render props will be stored as null here
    myHostList.getCommonValues(tree, /* live= */
    true);
    // values for null render props will be expanded
    // using props returned from createRenderProps
    renderCell.addChildren(myHostList.commonProperties(renderCell, false));
    // backup values will be saved, including the original
    // null values
    myHostList.saveBackupValues(renderCell);
    // null render props will be replaced with the render props
    // that were created during the the call to commonProperties
    myHostList.addSubHostsIfNecessary(renderCell);
    myHostList.getCommonValues(renderCell, /* live= */
    true);
    myNumProps = renderCell.numChildren();
    setPanel(new RenderPropsPanel(EditingProperty.createProperties(renderCell, myHostList, /* isLive= */
    true)));
    setScrollable(true);
    myTree = renderCell;
    // enableAutoRerendering (true);
    // ViewerManager driver = Main.getMain().getViewerManager();
    // driver.setSelectionHighlighting (GLViewer.SelectionHighlighting.None);
    // driver.render();
    // addWindowListener (
    // new PropertyWindowAdapter(this)
    // {
    // public void windowClosing (WindowEvent e)
    // {
    // getWindow().dispose();
    // }
    // public void windowClosed (WindowEvent e)
    // {
    // ViewerManager driver = Main.getMain().getViewerManager();
    // driver.setSelectionHighlighting (
    // GLViewer.SelectionHighlighting.Color);
    // driver.render();
    // }
    // });
    // addWindowListener (new WindowAdapter() {
    // // public void windowClosing (WindowEvent e)
    // // {
    // // e.getSource().dispose();
    // // }
    // 
    // public void windowClosed (WindowEvent e) {
    // ViewerManager driver = Main.getMain().getViewerManager();
    // driver.setSelectionHighlighting (
    // GLViewer.SelectionHighlighting.Color);
    // driver.render();
    // }
    // });
    // initFinish ("Done Reset");
    pack();
}
Also used : PropTreeCell(maspack.properties.PropTreeCell) HasProperties(maspack.properties.HasProperties) HostList(maspack.properties.HostList) PropertyInfo(maspack.properties.PropertyInfo)

Example 10 with PropertyInfo

use of maspack.properties.PropertyInfo in project artisynth_core by artisynth.

the class CompositePropertyPanel method isNullAllowed.

private boolean isNullAllowed(Property prop) {
    if (prop instanceof EditingProperty) {
        // then null values are allowed only if they are permitted
        // on all the hosts
        EditingProperty eprop = (EditingProperty) prop;
        HostList hostList = eprop.getHostList();
        PropTreeCell cell = eprop.getCell();
        PropertyInfo[] infos = hostList.getAllInfos(cell);
        boolean nullAllowed = true;
        for (PropertyInfo info : infos) {
            if (!info.getNullValueOK()) {
                nullAllowed = false;
            }
        }
        return nullAllowed;
    } else {
        return prop.getInfo().getNullValueOK();
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList) PropertyInfo(maspack.properties.PropertyInfo)

Aggregations

PropertyInfo (maspack.properties.PropertyInfo)12 HasProperties (maspack.properties.HasProperties)4 EnumRange (maspack.util.EnumRange)4 Range (maspack.util.Range)4 StringRange (maspack.util.StringRange)4 IntegerInterval (maspack.util.IntegerInterval)3 NumericInterval (maspack.util.NumericInterval)3 ModelComponent (artisynth.core.modelbase.ModelComponent)2 VectorNd (maspack.matrix.VectorNd)2 CompositeProperty (maspack.properties.CompositeProperty)2 HostList (maspack.properties.HostList)2 PropTreeCell (maspack.properties.PropTreeCell)2 InternalErrorException (maspack.util.InternalErrorException)2 RenderableComponent (artisynth.core.modelbase.RenderableComponent)1 Traceable (artisynth.core.modelbase.Traceable)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Font (java.awt.Font)1 Point (java.awt.Point)1 LinkedList (java.util.LinkedList)1