use of maspack.properties.Property 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();
}
}
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class ControlPanel method removeStalePropertyWidgets.
public boolean removeStalePropertyWidgets() {
LinkedList<LabeledComponentBase> removeList = new LinkedList<LabeledComponentBase>();
for (int i = 0; i < myPanel.numWidgets(); i++) {
if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
Property prop = myPanel.getWidgetProperty(widget);
if (prop != null && !(prop instanceof EditingProperty)) {
if (isStale(prop)) {
removeList.add(widget);
}
}
}
}
if (removeList.size() > 0) {
for (LabeledComponentBase widget : removeList) {
myPanel.removeWidget(widget);
// myWidgetPropMap.remove (widget);
}
if (myFrame != null) {
myFrame.pack();
}
return true;
} else {
return false;
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class ControlPanel method getSoftReferences.
@Override
public void getSoftReferences(List<ModelComponent> refs) {
HashSet<ModelComponent> myrefs = new HashSet<ModelComponent>();
for (int i = 0; i < myPanel.numWidgets(); i++) {
if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
Property prop = myPanel.getWidgetProperty(widget);
if (prop instanceof GenericPropertyHandle) {
ModelComponent comp = ComponentUtils.getPropertyComponent(prop);
if (comp != null && !ComponentUtils.isAncestorOf(comp, this)) {
myrefs.add(comp);
}
} else {
// TODO - handle other cases
}
}
}
refs.addAll(myrefs);
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class ControlPanel method postscanWidget.
public void postscanWidget(Deque<ScanToken> tokens, CompositeComponent ancestor) throws IOException {
String propPath = null;
if (tokens.peek() instanceof StringToken) {
propPath = (String) tokens.poll().value();
}
if (!(tokens.peek() instanceof ObjectToken)) {
throw new IOException("Expecting ObjectToken containing widget");
}
Component comp = (Component) tokens.poll().value();
if (comp instanceof LabeledComponentBase) {
Property property = null;
LabeledComponentBase widget = (LabeledComponentBase) comp;
// such as range could cause the property value itself to be reset
if (widget instanceof LabeledControl) {
((LabeledControl) widget).maskValueChangeListeners(true);
}
if (propPath != null) {
property = ancestor.getProperty(propPath);
if (property == null) {
System.out.println("Ignoring control panel widget for " + propPath);
widget = null;
} else {
boolean widgetSet = false;
try {
// initialize widget, but don't set properties because
// these will have already been set in the scan method
widgetSet = PropertyWidget.initializeWidget(widget, property);
} catch (Exception e) {
e.printStackTrace();
widgetSet = false;
}
if (widgetSet == false) {
System.out.println("Warning: widget " + widget + " inappropriate for property " + propPath + "; ignoring");
widget = null;
}
}
}
if (widget instanceof LabeledControl) {
((LabeledControl) widget).maskValueChangeListeners(false);
}
// properties (such as the range) are initialized
if (widget != null && property != null) {
PropertyWidget.finishWidget(widget, property);
myPanel.processPropertyWidget(property, widget);
}
if (widget != null) {
addWidget(widget);
}
} else {
addWidget(comp);
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class ControlPanel method writeWidget.
public void writeWidget(PrintWriter pw, Component comp, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
String aliasOrName = ClassAliases.getAliasOrName(comp.getClass());
if (!(comp instanceof LabeledComponentBase)) {
pw.println(aliasOrName + " [ ]");
} else {
LabeledComponentBase widget = (LabeledComponentBase) comp;
pw.println(aliasOrName);
pw.print("[ ");
IndentingPrintWriter.addIndentation(pw, 2);
Property prop = PropertyWidget.getProperty(widget);
if (prop != null) {
String propPath = ComponentUtils.getWritePropertyPathName(prop, ancestor);
if (propPath != null) {
pw.println("property=" + propPath);
}
}
widget.getAllPropertyInfo().writeNonDefaultProps(widget, pw, fmt);
IndentingPrintWriter.addIndentation(pw, -2);
pw.println("]");
}
}
Aggregations