Search in sources :

Example 16 with HostList

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

the class SelectionPopup method createPropertyDialog.

public void createPropertyDialog(Collection<? extends ModelComponent> selectedItems) {
    HostList hostList = new HostList(selectedItems);
    PropTreeCell tree = hostList.commonProperties(null, /* allowReadonly= */
    true);
    tree.removeDescendant("renderProps");
    if (tree.numChildren() == 0) {
        JOptionPane.showMessageDialog(myParentGUIComponent, "No common properties for selected components", "no common properties", JOptionPane.INFORMATION_MESSAGE);
    } else {
        PropertyDialog propDialog = new PropertyDialog("Edit properties", tree, hostList, "OK Cancel LiveUpdate");
        propDialog.setScrollable(true);
        if (myLocatePropEditClose) {
            GuiUtils.locateRelative(propDialog, myLastBounds, 0.5, 0.5, 0, 0.5);
        } else {
            propDialog.locateRight(myMain.getFrame());
        }
        // propDialog.setSynchronizeObject (myMain.getRootModel());
        myMain.registerWindow(propDialog);
        propDialog.setTitle("Properties for " + getNameForSelection(selectedItems));
        propDialog.setVisible(true);
    }
}
Also used : PropertyDialog(maspack.widgets.PropertyDialog) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList)

Example 17 with HostList

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

the class PropertyWidgetDialog method createEditingProperty.

private EditingProperty createEditingProperty(Property prop) {
    if (prop.getHost() == null) {
        throw new InternalErrorException("Property " + prop.getName() + " does not have host");
    }
    HostList hostList = new HostList(1);
    hostList.addHost(prop.getHost());
    // get single property from host list
    String[] restricted = new String[] { prop.getName() };
    String[] excluded = null;
    PropTreeCell tree = hostList.commonProperties(null, /* allowReadonly= */
    false, restricted, excluded);
    if (tree.numChildren() == 0) {
        throw new InternalErrorException("Property " + prop.getName() + " not found in host");
    }
    // expand save data in hostList down one level ...
    hostList.saveBackupValues(tree);
    return new EditingProperty(tree.getFirstChild(), hostList, /* live= */
    true);
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList) InternalErrorException(maspack.util.InternalErrorException)

Example 18 with HostList

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

the class AddComponentAgent method setComponentType.

/**
 * Called whenever the specific class type of the components being added by
 * this agent is changed.
 */
public void setComponentType(Class type) {
    if (type == myComponentType) {
        return;
    }
    myComponentType = type;
    if (myPrototype != null) {
        setProperties(myPrototype, myPrototype);
    }
    myPrototype = getPrototypeComponent(type);
    if (myPrototype != null) {
        myHostList = new HostList(new HasProperties[] { myPrototype });
        myPropTree = myHostList.commonProperties(null, false);
        // remove properties which are to be excluded
        String[] excludedPropNames = getExcludedPropNames(type);
        for (int i = 0; i < excludedPropNames.length; i++) {
            myPropTree.removeDescendant(excludedPropNames[i]);
        }
        myHostList.saveBackupValues(myPropTree);
        myHostList.getCommonValues(myPropTree, /* live= */
        true);
        if (myPropertyPanelIdx != -1) {
            myDefaultProps = EditingProperty.createProperties(myPropTree, myHostList, /* isLive= */
            true);
            LinkedList<Property> basicProps = getBasicProps(type, myDefaultProps);
            if (basicProps.size() > 0) {
                LinkedList<Property> extraProps = new LinkedList<Property>();
                extraProps.addAll(myDefaultProps);
                extraProps.removeAll(basicProps);
                myPropertyPanel = new ExpandablePropertyPanel(basicProps, extraProps);
            } else {
                myPropertyPanel = new PropertyPanel(myDefaultProps);
            }
            if (myPropertyPanelBorderTitle != null) {
                String title = myPropertyPanelBorderTitle;
                if (title.indexOf("TYPE") != -1) {
                    title = title.replaceAll("TYPE", (String) myTypeSelector.getValue());
                }
                myPropertyPanel.setBorder(GuiUtils.createTitledPanelBorder(title));
            }
            resetDefaultProperties();
            myPropertyPanel.updateWidgetValues(/* updateFromSource= */
            false);
            myPropertyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            myContentPane.removeWidget(myPropertyPanelIdx);
            myContentPane.addWidget(myPropertyPanel, myPropertyPanelIdx);
            myContentPane.validate();
            // myContentPane.resetLabelAlignment();
            if (myDisplay.isVisible()) {
                myDisplay.pack();
            }
        }
    }
}
Also used : HasProperties(maspack.properties.HasProperties) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) HostList(maspack.properties.HostList) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property) LinkedList(java.util.LinkedList) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) PropertyPanel(maspack.widgets.PropertyPanel)

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