use of maspack.properties.HostList in project artisynth_core by artisynth.
the class PropertyGuiTest method main.
public static void main(String[] args) {
TestHierarchy test = new TestHierarchy();
LinkedList<TestNode> nodeList = new LinkedList<TestNode>();
for (int i = 0; i < args.length; i++) {
TestNode node = test.getNode(args[i]);
if (node == null) {
System.err.println("Node '" + args[i] + "' not found");
System.exit(1);
}
nodeList.add(node);
}
// test.M1.getMaterial().setStiffness (123.0);
System.out.println("Properties:");
test.printAllProperties(System.out, test.recordAllProperties(test.getRoot()));
if (nodeList.size() == 0) {
System.err.println("Usage: java maspack.apps.PropertyGuiTest <NodeName1> <NodeName2> ... ");
System.exit(1);
} else if (nodeList.size() == 1) {
HasProperties host = nodeList.get(0);
PropertyDialog dialog = new PropertyDialog("prop panel test", host, "OK Cancel");
dialog.setVisible(true);
while (dialog.isVisible()) {
try {
Thread.sleep(100);
} catch (Exception e) {
//
}
}
dialog.dispose();
} else {
HostList hostList = new HostList((HasProperties[]) nodeList.toArray(new TestNode[0]));
PropertyDialog dialog = new PropertyDialog("prop panel test", hostList, "OK Cancel");
dialog.setVisible(true);
while (dialog.isVisible()) {
try {
Thread.sleep(100);
} catch (Exception e) {
//
}
}
dialog.dispose();
}
}
use of maspack.properties.HostList in project artisynth_core by artisynth.
the class PropertyDialog method createDialog.
public static PropertyDialog createDialog(String title, Iterable<? extends HasProperties> hosts, String optionStr, Component parentComp, ValueChangeListener globalChangeListener) {
HostList hostList = new HostList(hosts);
PropTreeCell tree = hostList.commonProperties(null, /* allowReadonly= */
true);
tree.removeDescendant("renderProps");
if (tree.numChildren() == 0) {
JOptionPane.showMessageDialog(parentComp, "No common properties for selected components", "no common properties", JOptionPane.INFORMATION_MESSAGE);
return null;
} else {
PropertyDialog dialog = new PropertyDialog("Edit properties", tree, hostList, optionStr);
dialog.setScrollable(true);
if (globalChangeListener != null) {
dialog.addGlobalValueChangeListener(globalChangeListener);
}
dialog.locateRight(parentComp);
dialog.setTitle(title);
return dialog;
}
}
use of maspack.properties.HostList in project artisynth_core by artisynth.
the class CompositePropertyPanel method getCpropTypeFromProperty.
/**
* Get the type of the current composite property from its property
* handle. If the property handle is an EditingProperty, then it may refer
* to several instances on several hosts, and if the type is not the same
* across those hosts, the type is considered to be Property.VoidValue.
*/
private Class<?> getCpropTypeFromProperty(Property cprop) {
if (cprop instanceof EditingProperty) {
EditingProperty eprop = (EditingProperty) cprop;
HostList hostList = eprop.getHostList();
Object[] values = hostList.getAllValues(eprop.getCell());
Class<?> cpropType = getCpropType(values[0]);
if (cpropType == Property.VoidValue) {
return Property.VoidValue;
}
for (int i = 1; i < values.length; i++) {
Class<?> nextType = getCpropType(values[i]);
if (nextType == Property.VoidValue || nextType != cpropType) {
return Property.VoidValue;
}
}
return cpropType;
} else {
return getCpropType(cprop.get());
}
}
use of maspack.properties.HostList in project artisynth_core by artisynth.
the class CompositePropertyPanel method updateWidgetValues.
/**
* Updates the current set of widgets in this panel so that their
* values reflect the underlying property values.
*
* @param updateFromSource if <code>false</code>, do not update the values
* of EditingProperties from their underlying source component(s).
*/
public void updateWidgetValues(boolean updateFromSource) {
Class<?> cpropType = getCpropTypeFromProperty(myCpropProperty);
if (myCpropType != cpropType) {
// composite property type has changed, and hence so have the widgets
myCpropType = cpropType;
rebuildPanel(/*setFromWidgets=*/
false);
GuiUtils.repackComponentWindow(this);
} else {
// widgets are the same but need to update their values
if (myWidgets != null && myWidgets.length > 0) {
if (myCpropProperty instanceof EditingProperty) {
if (updateFromSource) {
// reset source hosts in case those have been reset by
// another party
EditingProperty eprop = (EditingProperty) myCpropProperty;
HostList hostList = eprop.getHostList();
hostList.setSubHostsFromValue(eprop.getCell());
}
doUpdateWidgets(updateFromSource);
} else {
if (myCprop != getCurrentCprop()) {
myWidgetProps = createWidgetProps();
attachPropsToWidgets(myWidgets, myWidgetProps, /*setValuesFromWidgets=*/
false);
// widgets will be updated in the above code
} else {
doUpdateWidgets(updateFromSource);
}
}
}
}
}
use of maspack.properties.HostList in project artisynth_core by artisynth.
the class CompositePropertyPanel method tryCreatingCpropFromPrototype.
/**
* Try to create a prototype for a particular type of composite property by
* cloning an instance (if there is one) in a host list.
*/
private CompositeProperty tryCreatingCpropFromPrototype(Class<?> type) {
CompositeProperty protoCprop = null;
EditingProperty eprop = (EditingProperty) myCpropProperty;
HostList hostList = eprop.getHostList();
Object[] values = hostList.getAllValues(eprop.getCell());
for (int i = 0; i < values.length; i++) {
if (type.isInstance(values[i]) && values[i] instanceof Clonable) {
try {
protoCprop = (CompositeProperty) ((Clonable) values[i]).clone();
} catch (Exception e) {
System.out.println("Warning: clone failed for " + values[i].getClass());
}
if (protoCprop != null) {
break;
}
}
}
return protoCprop;
}
Aggregations