Skip to content

Commit

Permalink
added basic load object mesh option to Horta3D Scene Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
porterbot committed Dec 7, 2022
1 parent fd41e0d commit 259494a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,9 @@
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 259494a

Please sign in to comment.