use of maspack.widgets.LabeledComponentBase 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.widgets.LabeledComponentBase 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.widgets.LabeledComponentBase 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.widgets.LabeledComponentBase 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("]");
}
}
use of maspack.widgets.LabeledComponentBase in project artisynth_core by artisynth.
the class ControlPanel method scanWidget.
public void scanWidget(String classNameOrAlias, ReaderTokenizer rtok, Deque<ScanToken> tokens) throws IOException {
Component comp;
try {
comp = (Component) ClassAliases.newInstance(classNameOrAlias, Component.class);
} catch (Exception e) {
throw new IOException("Could not instantiate widget " + classNameOrAlias + ", line " + rtok.lineno() + ":\n" + e.getMessage());
}
if (!(comp instanceof LabeledComponentBase)) {
rtok.scanToken('[');
rtok.scanToken(']');
tokens.offer(new StringToken("widget", rtok.lineno()));
tokens.offer(new ObjectToken(comp));
return;
}
LabeledComponentBase widget = (LabeledComponentBase) comp;
rtok.scanToken('[');
String propPath = null;
while (rtok.nextToken() != ']') {
if (scanAttributeName(rtok, "property")) {
propPath = rtok.scanQuotedString('"');
} else if (rtok.tokenIsWord()) {
String fieldName = rtok.sval;
if (!ScanWriteUtils.scanProperty(rtok, widget)) {
System.out.println("Warning: internal widget property '" + fieldName + "' not found for " + widget + "; ignoring");
widget = null;
break;
}
} else {
throw new IOException("Unexpected token: " + rtok);
}
}
if (widget != null) {
tokens.offer(new StringToken("widget", rtok.lineno()));
if (propPath != null) {
tokens.offer(new StringToken(propPath, rtok.lineno()));
}
tokens.offer(new ObjectToken(widget, rtok.lineno()));
}
}
Aggregations