Search in sources :

Example 1 with HasProperties

use of maspack.properties.HasProperties 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 HasProperties

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

the class LabeledComponentPanel method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("delete")) {
        LinkedList<JComponent> list = new LinkedList<JComponent>();
        list.addAll(mySelectedWidgets);
        for (JComponent comp : list) {
            removeWidget(comp);
        }
        repackContainingWindow();
    } else if (command.equals("add separator")) {
        JComponent comp = mySelectedWidgets.iterator().next();
        addWidget(new JSeparator(), getComponentIndex(comp) + 1);
        repackContainingWindow();
    } else if (command.equals("set properties")) {
        Window win = SwingUtilities.getWindowAncestor(this);
        if (win != null) {
            LinkedList<HasProperties> hosts = new LinkedList<HasProperties>();
            JComponent lastComp = null;
            for (JComponent comp : mySelectedWidgets) {
                if (comp instanceof HasProperties) {
                    hosts.add((HasProperties) comp);
                }
                lastComp = comp;
            }
            HostList hostList = new HostList(hosts);
            PropertyDialog dialog = PropertyDialog.createDialog(win, "Edit properties", hostList, "OK Cancel");
            // PropertyDialog dialog = PropertyDialog.createDialog (
            // win, "Edit properties", new PropertyPanel (comp), "OK Cancel");
            GuiUtils.locateVertically(dialog, lastComp, GuiUtils.BELOW);
            GuiUtils.locateHorizontally(dialog, this, GuiUtils.CENTER);
            dialog.setModal(true);
            dialog.setVisible(true);
        }
    } else if (command.equals("reset sliderRange")) {
        for (JComponent comp : mySelectedWidgets) {
            if (comp instanceof NumericFieldSlider) {
                // fix this for regular sliders too?
                NumericFieldSlider nslider = (NumericFieldSlider) comp;
                nslider.setSliderRange(SliderRange.estimateBoundsIfNecessary(nslider.getRange(), nslider.getDoubleValue()));
            }
        }
    } else if (mySelectedWidgets.size() == 1) {
        JComponent comp = mySelectedWidgets.iterator().next();
        if (comp instanceof LabeledComponentBase) {
            ((LabeledComponentBase) comp).actionPerformed(e);
        }
    } else {
        throw new InternalErrorException("Unexpected action: " + e);
    }
}
Also used : Window(java.awt.Window) JComponent(javax.swing.JComponent) HasProperties(maspack.properties.HasProperties) HostList(maspack.properties.HostList) InternalErrorException(maspack.util.InternalErrorException) LinkedList(java.util.LinkedList) JSeparator(javax.swing.JSeparator)

Example 3 with HasProperties

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

the class MenuBarHandler method showPullControllerRenderPropsDialog.

private void showPullControllerRenderPropsDialog() {
    if (myPullControllerRenderPropsDialog == null) {
        PullController pc = myMain.getPullController();
        LinkedList<HasProperties> list = new LinkedList<HasProperties>();
        list.add(pc);
        RenderPropsDialog dialog = new RenderPropsDialog("Edit render properties", list);
        dialog.locateRight(myMain.getFrame());
        // dialog.setSynchronizeObject(myMain.getRootModel());
        dialog.setTitle("RenderProps for PullController");
        dialog.addWindowListener(new WindowAdapter() {

            public void windowClosed(WindowEvent e) {
                myPullControllerRenderPropsDialog = null;
            }
        });
        myMain.registerWindow(dialog);
        myPullControllerRenderPropsDialog = dialog;
        dialog.pack();
        dialog.setVisible(true);
    }
}
Also used : RenderPropsDialog(maspack.widgets.RenderPropsDialog) WindowEvent(java.awt.event.WindowEvent) HasProperties(maspack.properties.HasProperties) WindowAdapter(java.awt.event.WindowAdapter) LinkedList(java.util.LinkedList) PullController(artisynth.core.workspace.PullController)

Example 4 with HasProperties

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

the class AddPropertyPane method RecursePropString.

private Property RecursePropString(String propPath, Object parent) {
    // System.out.println("recurse path: " + propPath);
    if (// if there is a . in the path, then we
    propPath.indexOf(".") > 0) // need to go down further
    {
        String propName = propPath.substring(0, propPath.indexOf("."));
        String rest = propPath.substring(propPath.indexOf(".") + 1, propPath.length());
        Property prop = ((HasProperties) parent).getProperty(propName);
        if (prop != null) {
            Object obj = prop.get();
            return RecursePropString(rest, obj);
        } else {
            return (Property) parent;
        }
    } else {
        // if there are no more "."s in the name, then just
        // simply get all the properties contained within this property
        System.out.println("no more .'s... just list the properties at this level");
        Property prop = ((HasProperties) parent).getProperty(propPath);
        if (prop != null) {
            // System.out.println("bottom prop found");
            return prop;
        } else {
            // System.out.println("bottom prop NOT found");
            return null;
        }
    }
}
Also used : HasProperties(maspack.properties.HasProperties) Property(maspack.properties.Property)

Example 5 with HasProperties

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

the class IsRenderableEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    if (glEditCmd.equals(actionCommand)) {
        ArrayList<HasProperties> contained = new ArrayList<HasProperties>(selection.size());
        for (ModelComponent mc : selection) {
            if (mc instanceof IsRenderableHolder) {
                IsRenderableHolder holder = (IsRenderableHolder) mc;
                IsRenderable glr = holder.getRenderable();
                if (glr instanceof HasProperties) {
                    contained.add((HasProperties) glr);
                }
            }
        }
        if (contained.size() > 0) {
            createPropertyDialog(contained, true, popupBounds);
        } else {
            JOptionPane.showMessageDialog(null, "No properties for selected components", "No properties", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}
Also used : IsRenderable(maspack.render.IsRenderable) ModelComponent(artisynth.core.modelbase.ModelComponent) IsRenderableHolder(artisynth.core.renderables.IsRenderableHolder) HasProperties(maspack.properties.HasProperties) ArrayList(java.util.ArrayList)

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