use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.
the class ControlPanel method scanItem.
public boolean scanItem(ReaderTokenizer rtok, Deque<ScanToken> tokens) throws IOException {
if (super.scanItem(rtok, tokens)) {
return true;
}
rtok.nextToken();
if (scanAttributeName(rtok, "options")) {
String options = rtok.scanQuotedString('"');
if (options != null) {
if (myFrame != null) {
OptionPanel optpanel = myFrame.addOptionPanel(options);
optpanel.addMouseListener(new MouseHandler());
myFrame.pack();
} else {
myOptionsString = options;
}
}
return true;
} else if (rtok.tokenIsWord()) {
scanWidget(rtok.sval, rtok, tokens);
return true;
}
rtok.pushBack();
return false;
}
use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.
the class ControlPanel method write.
public void write(PrintWriter pw, NumberFormat fmt, Object ref) throws IOException {
CompositeComponent ancestor = ComponentUtils.castRefToAncestor(ref);
pw.print("[ ");
IndentingPrintWriter.addIndentation(pw, 2);
getAllPropertyInfo().writeNonDefaultProps(this, pw, fmt);
String optionsStr = null;
if (myFrame != null) {
OptionPanel optpanel = myFrame.getOptionPanel();
if (optpanel != null) {
optionsStr = optpanel.getButtonString();
}
} else {
optionsStr = myOptionsString;
}
if (optionsStr != null) {
pw.println("options=\"" + optionsStr + "\"");
} else {
pw.println("options=null");
}
for (Component comp : myPanel.getWidgets()) {
writeWidget(pw, comp, fmt, ancestor);
}
IndentingPrintWriter.addIndentation(pw, -2);
pw.println("]");
}
use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.
the class FrameBasedEditingAgent method createOptionPanel.
/**
* Called by subclasses inside {@link #createDisplay createDisplay} to create
* a button panel. The names of the buttons are placed inside the string
* <code>buttonNames</code>, separated by white-space. An array of all
* created buttons is returned. Buttons with certain known names (e.g.,
* "Done", "Add") are also assigned to predefined variables.
*/
protected JButton[] createOptionPanel(String buttonNames) {
myOptionPanel = new OptionPanel(buttonNames, this);
myAddButton = myOptionPanel.getButton("Add");
myDoneButton = myOptionPanel.getButton("Done");
myStopButton = myOptionPanel.getButton("Stop");
addToContentPane(myOptionPanel);
return myOptionPanel.getButtons();
}
use of maspack.widgets.OptionPanel 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();
}
use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.
the class EditorUtils method saveMeshAsAnsysFile.
public static void saveMeshAsAnsysFile(final FemModel3d model) {
final Main main = Main.getMain();
JFrame frame = main.getMainFrame();
final JDialog saveOptions = new JDialog(frame, "Save As Ansys File");
LabeledComponentPanel savePanel = new LabeledComponentPanel();
savePanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
final StringField dirField = new StringField("Output folder", main.getModelDirectory().getAbsolutePath(), 20);
dirField.setStretchable(true);
dirField.getTextField().setEditable(false);
final JButton browseButton = new JButton("Change");
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showSaveDialog(browseButton) == JFileChooser.APPROVE_OPTION) {
dirField.setValue(chooser.getSelectedFile().getAbsolutePath());
}
}
});
browseButton.setMargin(new Insets(3, 3, 3, 3));
GuiUtils.setFixedSize(browseButton, new Dimension(80, 25));
dirField.add(browseButton);
savePanel.addWidget(dirField);
final StringField nodeField = new StringField("Node file name", "mesh.node", 10);
nodeField.setStretchable(true);
savePanel.addWidget(nodeField);
final StringField elemField = new StringField("Element file name", "mesh.elem", 10);
elemField.setStretchable(true);
savePanel.addWidget(elemField);
final JCheckBox elemType = new JCheckBox("Use custom type values for different elements");
savePanel.addWidget(elemType);
LabeledComponentPanel elemTypePanel = new LabeledComponentPanel();
elemTypePanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
final IntegerField tetField = new IntegerField("Tets (4 node)", 1);
tetField.getTextField().setEditable(false);
elemTypePanel.addWidget(tetField);
final IntegerField quadtetField = new IntegerField("Quadtets (10 node)", 1);
quadtetField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadtetField);
final IntegerField wedgeField = new IntegerField("Wedges", 1);
wedgeField.getTextField().setEditable(false);
elemTypePanel.addWidget(wedgeField);
final IntegerField hexField = new IntegerField("Hexs (8 node)", 1);
hexField.getTextField().setEditable(false);
elemTypePanel.addWidget(hexField);
final IntegerField quadhexField = new IntegerField("Quadhexs (20 node)", 1);
quadhexField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadhexField);
savePanel.addWidget(elemTypePanel);
elemType.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (elemType.isSelected()) {
tetField.getTextField().setEditable(true);
quadtetField.getTextField().setEditable(true);
wedgeField.getTextField().setEditable(true);
hexField.getTextField().setEditable(true);
quadhexField.getTextField().setEditable(true);
} else {
tetField.getTextField().setEditable(false);
quadtetField.getTextField().setEditable(false);
wedgeField.getTextField().setEditable(false);
hexField.getTextField().setEditable(false);
quadhexField.getTextField().setEditable(false);
}
}
});
OptionPanel dialogOptions = new OptionPanel("Save Cancel", new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (a_evt.getActionCommand().equals("Save")) {
File directory = new File(dirField.getStringValue());
File nodeFile = new File(directory, nodeField.getStringValue());
File elemFile = new File(directory, elemField.getStringValue());
AnsysWriter.writeNodeFile(model, nodeFile.getAbsolutePath());
AnsysWriter.writeElemFile(model, elemFile.getAbsolutePath());
}
saveOptions.dispose();
}
});
GuiUtils.setFixedSize(dialogOptions.getButton("Save"), new Dimension(80, 25));
GuiUtils.setFixedSize(dialogOptions.getButton("Cancel"), new Dimension(80, 25));
dialogOptions.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
savePanel.addWidget(dialogOptions);
saveOptions.getContentPane().add(savePanel);
saveOptions.pack();
saveOptions.setMinimumSize(saveOptions.getPreferredSize());
saveOptions.setVisible(true);
}
Aggregations