Search in sources :

Example 6 with HasProperties

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);
}
Also used : PropertyInfoList(maspack.properties.PropertyInfoList) HasProperties(maspack.properties.HasProperties) PropertyInfo(maspack.properties.PropertyInfo) LinkedList(java.util.LinkedList)

Example 7 with HasProperties

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;
}
Also used : HasProperties(maspack.properties.HasProperties) InternalErrorException(maspack.util.InternalErrorException) PropertyInfo(maspack.properties.PropertyInfo) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property)

Example 8 with HasProperties

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

Example 9 with HasProperties

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);
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) RenderableComponent(artisynth.core.modelbase.RenderableComponent) HasProperties(maspack.properties.HasProperties) PropertyInfo(maspack.properties.PropertyInfo) Traceable(artisynth.core.modelbase.Traceable) JMenuItem(javax.swing.JMenuItem) Point(java.awt.Point)

Example 10 with HasProperties

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);
    }
}
Also used : HasRenderProps(maspack.render.HasRenderProps) HasProperties(maspack.properties.HasProperties) HasRenderProps(maspack.render.HasRenderProps) RenderProps(maspack.render.RenderProps) PropertyList(maspack.properties.PropertyList) ReaderTokenizer(maspack.util.ReaderTokenizer) Scannable(maspack.util.Scannable) PrintWriter(java.io.PrintWriter) NumberFormat(maspack.util.NumberFormat)

Aggregations

HasProperties (maspack.properties.HasProperties)13 LinkedList (java.util.LinkedList)4 HostList (maspack.properties.HostList)4 Property (maspack.properties.Property)4 PropertyInfo (maspack.properties.PropertyInfo)4 InternalErrorException (maspack.util.InternalErrorException)3 ModelComponent (artisynth.core.modelbase.ModelComponent)2 ArrayList (java.util.ArrayList)2 CompositeProperty (maspack.properties.CompositeProperty)2 PropertyDialog (maspack.widgets.PropertyDialog)2 RenderableComponent (artisynth.core.modelbase.RenderableComponent)1 Traceable (artisynth.core.modelbase.Traceable)1 IsRenderableHolder (artisynth.core.renderables.IsRenderableHolder)1 PullController (artisynth.core.workspace.PullController)1 Point (java.awt.Point)1 Window (java.awt.Window)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 File (java.io.File)1 IOException (java.io.IOException)1