diff --git a/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/ObjectMeshPanel.java b/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/ObjectMeshPanel.java index ad887cd23..3d5d8b4c8 100644 --- a/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/ObjectMeshPanel.java +++ b/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/ObjectMeshPanel.java @@ -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(); diff --git a/modules/ViewerController/src/main/java/org/janelia/workstation/controller/action/LoadMeshAction.java b/modules/ViewerController/src/main/java/org/janelia/workstation/controller/action/LoadMeshAction.java index 24a513e4f..ab466ce09 100644 --- a/modules/ViewerController/src/main/java/org/janelia/workstation/controller/action/LoadMeshAction.java +++ b/modules/ViewerController/src/main/java/org/janelia/workstation/controller/action/LoadMeshAction.java @@ -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; @@ -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 {