diff --git a/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/HortaSceneEditorTopComponent.java b/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/HortaSceneEditorTopComponent.java index e6bf014a6..62a74fa87 100644 --- a/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/HortaSceneEditorTopComponent.java +++ b/modules/HortaTracer/src/main/java/org/janelia/horta/nodes/HortaSceneEditorTopComponent.java @@ -3,7 +3,9 @@ import com.google.common.eventbus.Subscribe; import org.janelia.model.domain.tiledMicroscope.TmObjectMesh; import org.janelia.model.domain.tiledMicroscope.TmWorkspace; +import org.janelia.workstation.common.gui.support.Icons; import org.janelia.workstation.controller.ViewerEventBus; +import org.janelia.workstation.controller.action.LoadMeshAction; import org.janelia.workstation.controller.eventbus.*; import org.janelia.workstation.controller.model.TmModelManager; import org.openide.awt.ActionID; @@ -14,6 +16,9 @@ import org.slf4j.LoggerFactory; import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * @@ -57,6 +62,24 @@ public HortaSceneEditorTopComponent() meshInfoPanel = new ObjectMeshPanel(); scrollPane = new JScrollPane(mainPanel); setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + LoadMeshAction loadMeshAction = new LoadMeshAction(); + final JPopupMenu meshToolMenu = new JPopupMenu(); + meshToolMenu.add(loadMeshAction); + + final JButton meshToolButton = new JButton(); + String gearIconFilename = "cog.png"; + ImageIcon gearIcon = Icons.getIcon(gearIconFilename); + meshToolButton.setIcon(gearIcon); + meshToolButton.setHideActionText(true); + meshToolButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + meshToolMenu.show(meshToolButton, + 0, + meshToolButton.getBounds().height); + } + }); + add(meshToolButton); + add(scrollPane); mainPanel.add(meshInfoPanel); 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 2bb42d198..ad887cd23 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 @@ -1,5 +1,7 @@ package org.janelia.horta.nodes; +import org.janelia.workstation.common.gui.support.Icons; +import org.janelia.workstation.controller.action.LoadMeshAction; import org.janelia.workstation.controller.widgets.SimpleIcons; import org.janelia.model.domain.tiledMicroscope.TmObjectMesh; import org.janelia.workstation.controller.eventbus.*; @@ -18,6 +20,7 @@ import javax.swing.table.JTableHeader; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collection; 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 new file mode 100644 index 000000000..24a513e4f --- /dev/null +++ b/modules/ViewerController/src/main/java/org/janelia/workstation/controller/action/LoadMeshAction.java @@ -0,0 +1,70 @@ +package org.janelia.workstation.controller.action; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import javax.swing.*; + +import org.janelia.model.domain.tiledMicroscope.TmObjectMesh; +import org.janelia.workstation.controller.ViewerEventBus; +import org.janelia.workstation.controller.eventbus.MeshCreateEvent; +import org.janelia.workstation.controller.model.TmModelManager; +import org.janelia.workstation.integration.util.FrameworkAccess; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbBundle.Messages; + +@ActionID( + category = "Horta", + id = "org.janelia.horta.actions.LoadMeshAction" +) +@ActionRegistration( + displayName = "#CTL_LoadMeshAction", + lazy = true +) +@Messages("CTL_LoadMeshAction=Load Object Mesh") +public final class LoadMeshAction + extends AbstractAction + implements ActionListener +{ + public LoadMeshAction() { + super("Load Object Mesh"); + } + + @Override + public void actionPerformed(ActionEvent e) { + + 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); + + int result = JOptionPane.showConfirmDialog(null, meshPanel, + "Enter Object Mesh Values", JOptionPane.OK_CANCEL_OPTION); + if (result == JOptionPane.OK_OPTION) { + saveObjectMesh(nameField.getText(), locationField.getText()); + } + } + + public void saveObjectMesh (String meshName, String filename) { + TmObjectMesh newObjMesh = new TmObjectMesh(meshName, filename); + try { + TmModelManager.getInstance().getCurrentWorkspace().addObjectMesh(newObjMesh); + TmModelManager.getInstance().saveCurrentWorkspace(); + + // fire off event for scene editor + MeshCreateEvent meshEvent = new MeshCreateEvent(this, + Arrays.asList(new TmObjectMesh[]{newObjMesh})); + ViewerEventBus.postEvent(meshEvent); + } catch (Exception error) { + FrameworkAccess.handleException(error); + } + } +}