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;
}
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;
}
}
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));
}
}
}
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();
}
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();
}
}
Aggregations