use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class ComponentPropertyField method updatePropertySelector.
protected void updatePropertySelector() {
// mask value change listeners since othewise the
// property selector will fire one to announce the new
// value we already know about ...
myPropertySelector.maskValueChangeListeners(true);
HasProperties host = getHost();
if (myLastSelectorHost != host) {
if (host != null) {
PropertyInfoList list = host.getAllPropertyInfo();
LinkedList<String> nameList = new LinkedList<String>();
nameList.add(nullString);
for (PropertyInfo info : list) {
// need to prune
if (myNumericOnly && !isNumeric(info)) {
continue;
}
if (myWidgetableOnly && !PropertyWidget.canCreate(info)) {
continue;
}
nameList.add(info.getName());
}
myPropertySelector.setSelections(nameList.toArray(new String[0]), nullString);
} else {
myPropertySelector.setSelections(new String[] { nullString }, nullString);
}
myLastSelectorHost = host;
}
myPropertySelector.setValue(getLeafPropName());
myPropertySelector.maskValueChangeListeners(false);
}
use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class ComponentPropertyField method getPropertyForComposite.
private Property getPropertyForComposite(CompositeProperty cprop) {
PropertyInfo info = cprop.getPropertyInfo();
HasProperties host = cprop.getPropertyHost();
Property prop = host.getProperty(info.getName());
if (prop == null) {
throw new InternalErrorException("Property not found in composite property host");
}
return prop;
}
use of maspack.properties.HasProperties 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.HasProperties in project artisynth_core by artisynth.
the class SelectionPopup method addPropertyEditMenuItems.
public void addPropertyEditMenuItems(LinkedList<ModelComponent> selection) {
// parse the selection list.
boolean allSelectedHaveProperties = false;
boolean allSelectedAreTraceable = false;
int tracingCnt = 0;
boolean oneSelectedIsRenderable = false;
boolean oneSelectedHasRenderProps = false;
boolean oneSelectedHasFixedRenderProps = false;
boolean oneSelectedIsVisible = false;
boolean oneSelectedIsInvisible = false;
boolean oneSelectedHasRenderPropsProperty = false;
if (selection.size() > 0) {
allSelectedHaveProperties = true;
allSelectedAreTraceable = true;
for (ModelComponent c : selection) {
if (c instanceof RenderableComponent) {
oneSelectedIsRenderable = true;
RenderableComponent rcomp = (RenderableComponent) c;
if (isVisible(rcomp)) {
oneSelectedIsVisible = true;
} else {
oneSelectedIsInvisible = true;
}
// RenderableComponent > HasProperties, but may not have
// renderProps property
PropertyInfo rinfo = rcomp.getAllPropertyInfo().get("renderProps");
if (rinfo != null) {
oneSelectedHasRenderPropsProperty = true;
}
if (rcomp.getRenderProps() != null) {
oneSelectedHasRenderProps = true;
// be set to null ...
if (!oneSelectedHasFixedRenderProps) {
if (!rinfo.getNullValueOK()) {
oneSelectedHasFixedRenderProps = true;
}
}
}
}
if (!(c instanceof HasProperties)) {
allSelectedHaveProperties = false;
}
if (!(c instanceof Traceable)) {
allSelectedAreTraceable = false;
}
}
}
Collection<Traceable> traceSet = myMain.getRootModel().getTraceSet();
for (Traceable tr : traceSet) {
if (tr instanceof ModelComponent && ((ModelComponent) tr).isSelected()) {
tracingCnt++;
}
}
if (allSelectedHaveProperties) {
addMenuItem("Edit properties ...");
}
if (oneSelectedIsRenderable && oneSelectedHasRenderPropsProperty) {
if (oneSelectedHasRenderProps) {
addMenuItem("Edit render props ...");
if (!oneSelectedHasFixedRenderProps) {
addMenuItem("Clear render props");
}
} else {
addMenuItem("Set render props ...");
}
}
if (oneSelectedIsInvisible) {
addMenuItem("Set visible");
}
if (oneSelectedIsVisible) {
addMenuItem("Set invisible");
}
if (allSelectedAreTraceable) {
if (selection.size() - tracingCnt > 0) {
addMenuItem("Enable tracing");
}
if (tracingCnt > 0) {
addMenuItem("Disable tracing");
}
JMenuItem menuItem = new JMenuItem("Clear trace");
menuItem.addActionListener(this);
String[] commonTraceables = getCommonTraceables(selection);
if (commonTraceables.length > 0) {
menuItem = new JMenuItem("Add tracing probe");
myTraceItem = menuItem;
}
menuItem.addActionListener(this);
add(menuItem);
}
}
use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class IsRenderableHolder method init.
private void init(IsRenderable renderable) {
if (renderable == null) {
throw new IllegalArgumentException("Cannot hold a null object");
}
myRenderable = renderable;
myProps = new PropertyList(IsRenderableHolder.class, RenderableComponentBase.class);
myProps.add("renderProps * *", "render properties", null);
if (myRenderable instanceof HasProperties) {
myProps.addReadOnly("renderable", "the held renderable object");
}
if (myRenderable instanceof HasRenderProps) {
myHasRenderProps = (HasRenderProps) myRenderable;
getRenderPropsMethod = null;
setRenderPropsMethod = null;
createRenderPropsMethod = null;
} else {
myHasRenderProps = null;
// try to find methods
Class<?> clazz = myRenderable.getClass();
getRenderPropsMethod = getMethod(clazz, "getRenderProps");
setRenderPropsMethod = getMethod(clazz, "setRenderProps", RenderProps.class);
createRenderPropsMethod = getMethod(clazz, "createRenderProps");
}
if (myRenderable instanceof Scannable) {
myScannable = (Scannable) myRenderable;
writeMethod = null;
scanMethod = null;
} else {
myScannable = null;
Class<?> clazz = myRenderable.getClass();
writeMethod = getMethod(clazz, "write", PrintWriter.class, NumberFormat.class, Object.class);
scanMethod = getMethod(clazz, "scan", ReaderTokenizer.class, CompositeComponent.class);
}
}
Aggregations