use of maspack.widgets.ValueChangeEvent in project artisynth_core by artisynth.
the class MeshCollisionViewer method createRenderPropsPanel.
private void createRenderPropsPanel(PolygonalMesh mesh) {
PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(mesh.getRenderProps())), "OK Cancel");
dialog.locateRight(this);
dialog.addGlobalValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
viewer.rerender();
}
});
dialog.setVisible(true);
}
use of maspack.widgets.ValueChangeEvent in project artisynth_core by artisynth.
the class MeshViewer method actionPerformed.
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Edit render props")) {
PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(myRenderProps)), "OK Cancel");
dialog.locateRight(this);
dialog.addGlobalValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
for (MeshBase mesh : myMeshes) {
mesh.setRenderProps(myRenderProps);
}
viewer.rerender();
}
});
myPopupManager.registerDialog(dialog);
dialog.setVisible(true);
} else if (cmd.equals("Edit viewer props")) {
PropertyDialog dialog = myPopupManager.createPropertyDialog("OK Cancel");
dialog.setVisible(true);
} else if (cmd.equals("Quit")) {
exit(0);
} else if (cmd.equals("Load mesh ...")) {
int retVal = myMeshChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
loadMesh(file);
}
} else if (cmd.equals("Save mesh ...")) {
int retVal = myMeshChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
saveMesh(file);
}
} else if (cmd.equals("Show mesh selector")) {
if (myMeshSelector == null) {
createMeshSelector();
myMeshSelector.setSelected(myMeshCursor);
}
myMeshSelector.setLocationRelativeTo(this);
myMeshSelector.setVisible(true);
} else if (cmd.equals("Hide mesh selector")) {
myMeshSelector.setVisible(false);
} else if (cmd.equals("Show property dialog ...")) {
setPropertyDialogVisible(true);
} else if (cmd.equals("Hide property dialog")) {
setPropertyDialogVisible(false);
} else if (cmd.equals("Background color")) {
setBackgroundColor();
} else if (cmd.equals("Perspective view")) {
viewer.setOrthographicView(false);
} else if (cmd.equals("Orthographic view")) {
viewer.setOrthographicView(true);
}
}
use of maspack.widgets.ValueChangeEvent in project artisynth_core by artisynth.
the class MenuBarHandler method createStepDisplay.
private DoubleField createStepDisplay() {
DoubleField display = new DoubleField("step:", 0, "%7.5f");
display.setToolTipText("maximum step size");
display.getTextField().setToolTipText("maximum step size");
// display.setEnabledAll (false);
display.setColumns(5);
display.addValueChangeListener(this);
display.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
double dval = ((Double) e.getValue()).doubleValue();
if (dval <= 0) {
return PropertyUtils.illegalValue("value must be positive", errMsg);
} else {
return PropertyUtils.validValue(e.getValue(), errMsg);
}
}
});
return display;
}
use of maspack.widgets.ValueChangeEvent in project artisynth_core by artisynth.
the class ControlPanel method actionPerformed.
public void actionPerformed(ActionEvent e) {
String actionCmd = e.getActionCommand();
if (actionCmd.equals("add widget")) {
myPanel.actionPerformed(e);
} else if (actionCmd.equals("set name")) {
WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "set name", "Set");
StringField widget = new StringField("name:", getName(), 20);
widget.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
String name = (String) e.getValue();
if (name != null && name.length() == 0) {
return null;
}
errMsg.value = ModelComponentBase.checkName(name, null);
if (errMsg.value != null) {
return Property.IllegalValue;
} else {
return name;
}
}
});
dialog.addWidget(widget);
GuiUtils.locateVertically(dialog, myFrame, GuiUtils.BELOW);
GuiUtils.locateHorizontally(dialog, myFrame, GuiUtils.CENTER);
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
String name = (String) widget.getValue();
setName(name);
}
} else if (actionCmd.equals("save as ...")) {
Main main = Main.getMain();
RootModel root = main.getRootModel();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(myFrame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
ComponentUtils.saveComponent(file, this, new NumberFormat("%.6g"), root);
} catch (Exception ex) {
JOptionPane.showMessageDialog(myFrame, "Error saving file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
} else if (actionCmd.equals("merge panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(true, this);
} else if (actionCmd.equals("separate panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(false, this);
} else {
throw new InternalErrorException("Unknown action: " + actionCmd);
}
}
use of maspack.widgets.ValueChangeEvent in project artisynth_core by artisynth.
the class PropertyWidgetDialog method initialize.
private void initialize() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
LabeledComponentPanel propPanel = new LabeledComponentPanel();
propPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
// myChooser = new PropertyChooser ("component/property", 30, myMain);
// myChooser.setAlignmentX (Component.CENTER_ALIGNMENT);
// myChooser.addValueChangeListener (this);
// pane.add (Box.createRigidArea (new Dimension (0, 4)));
// propPanel.addWidget (myChooser);
myPropField = new PropertyField("component/property", 30, myMain);
myPropField.setAlignmentX(Component.CENTER_ALIGNMENT);
myPropField.addValueChangeListener(this);
propPanel.addWidget(myPropField);
propPanel.addWidget(new JSeparator());
mySliderSelector = new BooleanSelector("slider");
mySliderSelector.addValueChangeListener(this);
propPanel.addWidget(mySliderSelector);
myRangeField = new DoubleIntervalField("range", new DoubleInterval(0, 1), "%.6g");
// new VectorMultiField (
// "range", new String[] { "min:", "max:" }, new Vector2d (0, 1),
// "%.6f");
// myRangeField.setAlignmentX (Component.CENTER_ALIGNMENT);
propPanel.addWidget(myRangeField);
myLabelTextField = new StringField("labelText", 20);
myLabelTextField.setEnabledAll(false);
myLabelTextField.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
String newName = (String) e.getValue();
String err = ModelComponentBase.checkName(newName, null);
if (err != null) {
err = "Invalid name '" + newName + "': " + err;
newName = null;
}
if (errMsg != null) {
errMsg.value = err;
}
return newName;
}
});
propPanel.addWidget(myLabelTextField);
myLabelFontColorSelector = new ColorSelector("labelFontColor");
myLabelFontColorSelector.enableNullColors();
myLabelFontColorSelector.setValue(null);
propPanel.addWidget(myLabelFontColorSelector);
myBackgroundColorSelector = new ColorSelector("backgroundColor");
myBackgroundColorSelector.enableNullColors();
myBackgroundColorSelector.setValue(null);
propPanel.addWidget(myBackgroundColorSelector);
// sliderPanel.add (myRangeField);
// pane.add (Box.createRigidArea (new Dimension (0, 4)));
// pane.add (sliderPanel);
pane.add(propPanel);
pane.add(new JSeparator());
// set slider value here because valueChanged needs some
// other widgets instantiated.
mySliderSelector.setValue(false);
mySliderSelector.setEnabledAll(false);
OptionPanel options = new OptionPanel("OK Cancel", this);
myOKButton = options.getButton("OK");
myOKButton.setEnabled(false);
options.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.add(options);
pack();
}
Aggregations