use of maspack.widgets.FileNameField in project artisynth_core by artisynth.
the class FemModel3dAgent method createFileChooser.
private FileNameField createFileChooser(String label, String fileName, String extension) {
FileNameField fileWidget = new FileNameField(label, 20);
JFileChooser chooser = fileWidget.getFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(new FileExtensionFilter("OBJ file", "obj"));
if (!extension.equals("obj")) {
chooser.addChoosableFileFilter(new FileExtensionFilter(label, extension));
}
if (fileName == null) {
fileName = "";
}
fileWidget.setValue(fileName);
File directory = ArtisynthPath.getWorkingDir();
if (fileName != null) {
File parentFile = new File(fileName).getParentFile();
if (parentFile != null && parentFile.isDirectory()) {
directory = parentFile;
}
}
chooser.setCurrentDirectory(directory);
return fileWidget;
}
use of maspack.widgets.FileNameField in project artisynth_core by artisynth.
the class GeometryInertiaPanel method createGeometryWidgets.
// Called once at panel creation time to create all the widgets
// that may be needed for the Geometry.
protected void createGeometryWidgets() {
myBoxWidthsField = new VectorField("widths", new Vector3d(), "%.4g");
myBoxWidthsField.setResultHolder(new Vector3d());
initWidget(myBoxWidthsField);
myPointRadiusField = new DoubleField("radius", 0, "%.4g");
initWidget(myPointRadiusField);
myPointSlicesField = new IntegerField("slices", 12);
initWidget(myPointSlicesField);
myMeshFileField = new FileNameField("file name", "", 20);
initWidget(myMeshFileField);
myMeshXformWidget = new AffineTransformWidget("", "TRS", new RigidTransform3d());
initWidget(myMeshXformWidget);
myMeshXformWidget.unpackFields();
myMeshXformWidget.getTranslationField().setLabelText("offset");
myMeshXformWidget.getScaleField().setLabelText("scale");
myMeshXformWidget.getRotationField().setLabelText("rotation");
myCOMButton = new JButton("COM");
myCOMButton.addActionListener(this);
myCOMButton.setToolTipText("puts mesh origin at its center of mass");
GuiUtils.setFixedSize(myCOMButton, myMeshFileField.getBrowseButton().getPreferredSize());
myMeshXformWidget.getTranslationField().addMajorComponent(myCOMButton);
}
use of maspack.widgets.FileNameField in project artisynth_core by artisynth.
the class DicomLoader method createControlPanel.
void createControlPanel() {
panel = new ControlPanel("DICOM controls");
fnf = new FileNameField("File or folder:", 30);
fnf.getFileChooser().setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fnf.getFileChooser().setCurrentDirectory(ArtisynthPath.getSrcRelativeFile(this, "data/"));
fnf.setName("dicom_path");
panel.addWidget(fnf);
fnp = new StringField("File regex:", 30);
fnp.setValue(".*");
panel.addWidget(fnp);
fns = new BooleanSelector("Subdirectories", true);
panel.addWidget(fns);
// panel for full-width button
JPanel jpanel = new JPanel();
jpanel.setLayout(new GridLayout());
panel.addWidget(jpanel);
JButton button = new JButton("Load");
button.setActionCommand("load");
button.addActionListener(this);
jpanel.add(button);
button = new JButton("Add Plane");
button.setActionCommand("plane");
button.addActionListener(this);
jpanel.add(button);
addControlPanel(panel);
}
use of maspack.widgets.FileNameField in project artisynth_core by artisynth.
the class FemModel3dAgent method valueChange.
public void valueChange(ValueChangeEvent evt) {
Object source = evt.getSource();
if (source == meshSelector) {
updateMeshPanel();
updateElemSelector();
updateState();
resetPreviewModel();
if (meshPropPanel.getComponentIndex(scaleField) != -1 && fem != null) {
updateScale();
}
} else if (source == elemSelector || source == gridDimField || source == gridDivField || source == tubeDimField || source == tubeDivField || source == torusDimField || source == torusDivField || source == extrusDepthField || source == extrusLayersField) {
resetPreviewModel();
} else if (source == sphereNodesField) {
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else if (source == extrusFileField) {
File file = new File(extrusFileField.getStringValue());
if (file.exists() && file.isFile()) {
fileCheck = true;
updateState();
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "File does not exist:" + file.getAbsolutePath());
}
} else if (source == ansysNodeFileField || source == ansysElemFileField) {
File file = new File(((source == ansysNodeFileField) ? ansysNodeFileField : ansysElemFileField).getStringValue());
File otherFile = new File(((source != ansysNodeFileField) ? ansysNodeFileField : ansysElemFileField).getStringValue());
if (file.exists() && file.isFile()) {
if (otherFile.exists() && otherFile.isFile()) {
fileCheck = true;
updateState();
}
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "Invalid file: " + file.getAbsolutePath());
}
File currentDir = ((FileNameField) source).getFileChooser().getCurrentDirectory();
if (source == ansysNodeFileField) {
ansysElemFileField.getFileChooser().setCurrentDirectory(currentDir);
} else {
ansysNodeFileField.getFileChooser().setCurrentDirectory(currentDir);
}
} else if (source == tetgenNodeFileField || source == tetgenEleFileField) {
File file = new File(((source == tetgenNodeFileField) ? tetgenNodeFileField : tetgenEleFileField).getStringValue());
File otherFile = new File(((source != tetgenNodeFileField) ? tetgenNodeFileField : tetgenEleFileField).getStringValue());
if (file.exists() && file.isFile()) {
if (otherFile.exists() && otherFile.isFile()) {
fileCheck = true;
updateState();
}
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "Invalid file: " + file.getAbsolutePath());
}
File currentDir = ((FileNameField) source).getFileChooser().getCurrentDirectory();
if (source == tetgenNodeFileField) {
tetgenEleFileField.getFileChooser().setCurrentDirectory(currentDir);
} else {
tetgenNodeFileField.getFileChooser().setCurrentDirectory(currentDir);
}
} else if (source == ucdMeshFileField) {
File file = new File(ucdMeshFileField.getStringValue());
if (file.exists() && file.isFile()) {
fileCheck = true;
updateState();
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "File does not exist:" + file.getAbsolutePath());
}
} else if (source == surfaceMeshFileField) {
File file = new File(surfaceMeshFileField.getStringValue());
if (file.exists() && file.isFile()) {
fileCheck = true;
updateState();
resetPreviewModel();
if (fem != null) {
updateScale();
}
} else {
fileCheck = false;
EditorUtils.showError(myDisplay, "File does not exist:" + file.getAbsolutePath());
}
} else if (source == positionField) {
updateState();
if (meshPropPanel.getComponentIndex(scaleField) != -1 && fem != null) {
updateScale();
}
updateDisplayLocation();
} else if (source == orientationField) {
updateDisplayLocation();
} else if (source == scaleField) {
if (fem != null && scaleField.getValue() != lastScale) {
Object scale = scaleField.getValue();
resetScaling();
if (scale instanceof Double) {
fem.getSurfaceMesh().scale((Double) scale);
} else if (scale instanceof Vector3d) {
fem.getSurfaceMesh().scale(((Vector3d) scale).x, ((Vector3d) scale).y, ((Vector3d) scale).z);
}
scaleField.maskValueChangeListeners(true);
scaleField.setValue(scale);
scaleField.maskValueChangeListeners(false);
lastScale = scale;
myMain.rerender();
}
} else {
super.valueChange(evt);
}
}
Aggregations