Search in sources :

Example 1 with HostList

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();
    }
}
Also used : PropertyDialog(maspack.widgets.PropertyDialog) HasProperties(maspack.properties.HasProperties) TestNode(maspack.properties.TestNode) HostList(maspack.properties.HostList) TestHierarchy(maspack.properties.TestHierarchy)

Example 2 with HostList

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;
    }
}
Also used : PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList)

Example 3 with HostList

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());
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) HostList(maspack.properties.HostList)

Example 4 with HostList

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);
                }
            }
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) HostList(maspack.properties.HostList)

Example 5 with HostList

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;
}
Also used : EditingProperty(maspack.properties.EditingProperty) Clonable(maspack.util.Clonable) HostList(maspack.properties.HostList) CompositeProperty(maspack.properties.CompositeProperty) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

HostList (maspack.properties.HostList)18 EditingProperty (maspack.properties.EditingProperty)8 PropTreeCell (maspack.properties.PropTreeCell)8 HasProperties (maspack.properties.HasProperties)4 InternalErrorException (maspack.util.InternalErrorException)3 PropertyDialog (maspack.widgets.PropertyDialog)3 PropertyPanel (maspack.widgets.PropertyPanel)3 LinkedList (java.util.LinkedList)2 CompositeProperty (maspack.properties.CompositeProperty)2 Property (maspack.properties.Property)2 PropertyInfo (maspack.properties.PropertyInfo)2 Window (java.awt.Window)1 JComponent (javax.swing.JComponent)1 JSeparator (javax.swing.JSeparator)1 InheritableProperty (maspack.properties.InheritableProperty)1 TestHierarchy (maspack.properties.TestHierarchy)1 TestNode (maspack.properties.TestNode)1 Clonable (maspack.util.Clonable)1 ExpandablePropertyPanel (maspack.widgets.ExpandablePropertyPanel)1