Skip to content

Commit

Permalink
updated to use filechooser
Browse files Browse the repository at this point in the history
  • Loading branch information
porterbot committed Dec 14, 2022
1 parent 259494a commit 0e1b427
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ObjectMeshPanel extends JPanel {

private static final int NARROW_COLUNN_WIDTH = 50;
private JLabel meshLabel;
private JFileChooser meshLocChooser;

public ObjectMeshPanel() {
setupUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import org.janelia.model.domain.tiledMicroscope.TmObjectMesh;
import org.janelia.workstation.controller.ViewerEventBus;
Expand All @@ -28,31 +31,65 @@ public final class LoadMeshAction
extends AbstractAction
implements ActionListener
{

JTextField locationField;
public LoadMeshAction() {
super("Load Object Mesh");
}

@Override
public void actionPerformed(ActionEvent e) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 1.0;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;

String locationText = "";
String meshNameText = "";
JPanel meshPanel = new JPanel();
meshPanel.setLayout(new GridLayout(2, 2));
meshPanel.add(new JLabel("Mesh Location:"));
final JTextField locationField = new JTextField(locationText, 40);
meshPanel.add(locationField);
meshPanel.add(new JLabel("Mesh Name"));
final JTextField nameField = new JTextField(meshNameText, 30);
meshPanel.add(nameField);
meshPanel.setLayout(new GridBagLayout());

gbc.gridx = 0;
gbc.gridy = 0;
meshPanel.add(new JLabel("Mesh Location"), gbc);

gbc.gridx = 1;
locationField = new JTextField(locationText, 20);
meshPanel.add(locationField, gbc);

gbc.gridx = 2;
JButton meshChooser = new JButton("Choose Mesh");
meshChooser.addActionListener(ev -> chooseMesh());
meshPanel.add(meshChooser, gbc);

gbc.gridx = 0;
gbc.gridy = 1;
meshPanel.add(new JLabel("Mesh Name"), gbc);

gbc.gridx = 1;
final JTextField nameField = new JTextField(meshNameText, 20);
meshPanel.add(nameField, gbc);

int result = JOptionPane.showConfirmDialog(null, meshPanel,
"Enter Object Mesh Values", JOptionPane.OK_CANCEL_OPTION);
"Enter Object Mesh ", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
saveObjectMesh(nameField.getText(), locationField.getText());
}
}

public void chooseMesh() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileFilter(new FileNameExtensionFilter("Object Mesh Files", "obj"));
int returnVal = fileChooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
locationField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}
}

public void saveObjectMesh (String meshName, String filename) {
TmObjectMesh newObjMesh = new TmObjectMesh(meshName, filename);
try {
Expand Down

0 comments on commit 0e1b427

Please sign in to comment.