Search in sources :

Example 1 with StringSelector

use of maspack.widgets.StringSelector in project artisynth_core by artisynth.

the class AddComponentAgent method createTypeSelector.

/**
 * Called by subclasses inside {@link #createDisplay createDisplay} to add a
 * type selector in the display. The type selector changes the specific
 * component type that this agent adds. The available component types consist
 * of those already been specified using {@link #addComponentType
 * addComponentType}. Text strings to choose these types are provided by the
 * argument <code>names</code>; if this is <code>null</code>, then the text
 * strings are generated automatically. When the selection is changed,
 * {@link #setComponentType setComponentType} is called with the new class
 * type.
 */
protected void createTypeSelector(String label, String[] names) {
    if (myTypePropertyMap == null) {
        throw new IllegalStateException("no component types have been specified");
    }
    if (names == null) {
        names = new String[myTypePropertyMap.size()];
        int k = 0;
        for (Class type : myTypePropertyMap.keySet()) {
            String name = type.getName();
            int dotIdx;
            if ((dotIdx = name.lastIndexOf('.')) != -1) {
                name = name.substring(dotIdx + 1);
            }
            names[k++] = name;
        }
    } else {
        if (names.length < myTypePropertyMap.size()) {
            throw new IllegalArgumentException("Number of names is less than the number of component types");
        }
    }
    myNameTypeMap = new HashMap<String, Class>();
    int k = 0;
    for (Class type : myTypePropertyMap.keySet()) {
        myNameTypeMap.put(names[k++], type);
    }
    myTypeSelector = new StringSelector(label, names);
    myTypeSelector.addValueChangeListener(this);
    addToContentPane(myTypeSelector);
}
Also used : StringSelector(maspack.widgets.StringSelector)

Example 2 with StringSelector

use of maspack.widgets.StringSelector in project artisynth_core by artisynth.

the class ComponentPropertyField method addPropertySelector.

protected void addPropertySelector() {
    myPropertySelector = new StringSelector("", new String[] { nullString });
    myPropertySelector.setValue(nullString);
    myPropertySelector.addValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent e) {
            setValueFromPropertySelector();
        }
    });
    myPropertiesAllowed = true;
    addMajorComponent(myPropertySelector);
}
Also used : ValueChangeEvent(maspack.widgets.ValueChangeEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) StringSelector(maspack.widgets.StringSelector)

Aggregations

StringSelector (maspack.widgets.StringSelector)2 ValueChangeEvent (maspack.widgets.ValueChangeEvent)1 ValueChangeListener (maspack.widgets.ValueChangeListener)1