Fixed report file generation on disk. Changed seg dialog to be a frame so that it...
authormccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 22 Mar 2018 20:59:41 +0000 (20:59 +0000)
committermccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 22 Mar 2018 20:59:41 +0000 (20:59 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15429 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInDialogStrokeSegmentationListener.java
mipav/src/plugins/StrokeSegmentationDicomReceiver.java
mipav/src/plugins/stroke_seg_listener.properties

index 8ea8d75..25c9d21 100644 (file)
@@ -1,26 +1,30 @@
+import gov.nih.mipav.plugins.JDialogStandalonePlugin;\r
 import gov.nih.mipav.plugins.JDialogStandaloneScriptablePlugin;\r
 \r
 import gov.nih.mipav.model.scripting.ParserException;\r
 import gov.nih.mipav.model.scripting.parameters.ParameterFactory;\r
 \r
 import gov.nih.mipav.view.MipavUtil;\r
+import gov.nih.mipav.view.Preferences;\r
 import gov.nih.mipav.view.ViewUserInterface;\r
 import gov.nih.mipav.view.components.WidgetFactory;\r
 import gov.nih.mipav.view.dialogs.JDialogBase;\r
 \r
+import java.io.FileNotFoundException;\r
 import java.io.IOException;\r
+import java.io.InputStream;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
+import java.util.Properties;\r
 \r
 import java.awt.*;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.WindowEvent;\r
+import java.awt.event.*;\r
 import java.io.File;\r
 \r
 import javax.swing.*;\r
 \r
 \r
-public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScriptablePlugin {\r
+public class PlugInDialogStrokeSegmentationListener extends JFrame implements ActionListener, WindowListener {\r
     private JTextField aeField;\r
     private JTextField portField;\r
     private JTextField outputDirField;\r
@@ -30,10 +34,10 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
     \r
     private WidgetFactory.ScrollTextArea logOutputArea;\r
     \r
-    private String ae = "MIPAV-stroke";\r
-\r
     private String ipAddress;\r
     \r
+    private String ae = "MIPAV-stroke";\r
+    \r
     private int port = 11115;\r
 \r
     private String outputDir = new String(System.getProperty("user.home") + File.separator + "mipav" + File.separator + "dicom_catcher" + File.separator);\r
@@ -47,6 +51,8 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
     private static final String svnLastUpdate = "$Date$";\r
     \r
     private static final String pluginVersion = MipavUtil.getSVNChangedDate(svnLastUpdate);\r
+    \r
+    private static final String configFileName = "stroke_seg_listener.properties";\r
 \r
     public PlugInDialogStrokeSegmentationListener() {\r
         try {\r
@@ -56,6 +62,21 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
             e.printStackTrace();\r
         }\r
         \r
+        if (JDialogStandalonePlugin.isExitRequired()) {\r
+            setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);\r
+        } else {\r
+            setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);\r
+        }\r
+\r
+        try {\r
+            setIconImage(MipavUtil.getIconImage(Preferences.getIconName()));\r
+        } catch (final Exception e) {\r
+            // setIconImage() is not part of the Java 1.5 API - catch any\r
+            // runtime error on those systems\r
+        }\r
+        \r
+        readListenerConfig();\r
+        \r
         init();\r
     }\r
     \r
@@ -77,11 +98,11 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
 \r
         JPanel mainPanel = new JPanel(new GridBagLayout());\r
         mainPanel.setForeground(Color.black);\r
-        mainPanel.setBorder(buildTitledBorder("DICOM receiver parameters"));\r
+        mainPanel.setBorder(JDialogBase.buildTitledBorder("DICOM receiver parameters"));\r
         \r
         JLabel labelAE = new JLabel("AE title");\r
         labelAE.setForeground(Color.black);\r
-        labelAE.setFont(serif12);\r
+        labelAE.setFont(MipavUtil.font12);\r
         mainPanel.add(labelAE, gbc);\r
         \r
         aeField = new JTextField(20);\r
@@ -97,7 +118,7 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
         \r
         JLabel labelPort = new JLabel("Port");\r
         labelPort.setForeground(Color.black);\r
-        labelPort.setFont(serif12);\r
+        labelPort.setFont(MipavUtil.font12);\r
         mainPanel.add(labelPort, gbc);\r
         \r
         portField = new JTextField(20);\r
@@ -113,7 +134,7 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
         \r
         JLabel labelOutput = new JLabel("Output dir");\r
         labelOutput.setForeground(Color.black);\r
-        labelOutput.setFont(serif12);\r
+        labelOutput.setFont(MipavUtil.font12);\r
         mainPanel.add(labelOutput, gbc);\r
         \r
         outputDirField = new JTextField(40);\r
@@ -126,7 +147,7 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
         dirFileButton.setActionCommand("BrowseDir");\r
         dirFileButton.addActionListener(this);\r
         dirFileButton.setForeground(Color.black);\r
-        dirFileButton.setFont(serif12B);\r
+        dirFileButton.setFont(MipavUtil.font12B);\r
         gbc.gridx++;\r
         mainPanel.add(dirFileButton, gbc);\r
         \r
@@ -135,13 +156,13 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
         \r
         emailCheckbox = new JCheckBox("Email report to pre-defined address", doEmailReport);\r
         emailCheckbox.setForeground(Color.black);\r
-        emailCheckbox.setFont(serif12);\r
+        emailCheckbox.setFont(MipavUtil.font12);\r
         mainPanel.add(emailCheckbox, gbc);\r
         \r
 //        \r
 //        JLabel labelEmail = new JLabel("Send email report to");\r
 //        labelEmail.setForeground(Color.black);\r
-//        labelEmail.setFont(serif12);\r
+//        labelEmail.setFont(MipavUtil.font12);\r
 //        mainPanel.add(labelEmail, gbc);\r
         \r
 //        emailField = new JTextField(40);\r
@@ -165,29 +186,31 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
         startButton.setActionCommand("Start");\r
         startButton.addActionListener(this);\r
         startButton.setForeground(Color.black);\r
-        startButton.setFont(serif12B);\r
+        startButton.setFont(MipavUtil.font12B);\r
         buttonPanel.add(startButton);\r
         \r
         JButton stopButton = new JButton("Stop");\r
         stopButton.setActionCommand("Stop");\r
         stopButton.addActionListener(this);\r
         stopButton.setForeground(Color.black);\r
-        stopButton.setFont(serif12B);\r
+        stopButton.setFont(MipavUtil.font12B);\r
         buttonPanel.add(stopButton);\r
         \r
         JButton exitButton = new JButton("Exit");\r
         exitButton.setActionCommand("Exit");\r
         exitButton.addActionListener(this);\r
         exitButton.setForeground(Color.black);\r
-        exitButton.setFont(serif12B);\r
+        exitButton.setFont(MipavUtil.font12B);\r
         buttonPanel.add(exitButton);\r
 \r
         getContentPane().add(buttonPanel, BorderLayout.SOUTH);\r
 \r
         pack();\r
-        setVisible(true);\r
         setResizable(true);\r
         System.gc();\r
+        \r
+        MipavUtil.centerOnScreen(this);\r
+        setVisible(true);\r
     }\r
     \r
     public void actionPerformed(final ActionEvent event) {\r
@@ -203,28 +226,7 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
             browseDir();\r
         }\r
     }\r
-    \r
-    protected void setGUIFromParams() {\r
-        ae = scriptParameters.getParams().getString("AE_title");\r
-        port = scriptParameters.getParams().getInt("port");\r
-        outputDir = scriptParameters.getParams().getString("output_dir");\r
-        doEmailReport = scriptParameters.getParams().getBoolean("do_email_report");\r
-    }\r
 \r
-    protected void storeParamsFromGUI() throws ParserException {\r
-        scriptParameters.getParams().put(ParameterFactory.newParameter("AE_title", ae));\r
-        scriptParameters.getParams().put(ParameterFactory.newParameter("port", port));\r
-        scriptParameters.getParams().put(ParameterFactory.newParameter("output_dir", outputDir));\r
-        scriptParameters.getParams().put(ParameterFactory.newParameter("do_email_report", doEmailReport));\r
-    }\r
-    \r
-    /**\r
-     * Perform any actions required after the running of the algorithm is complete.\r
-     */\r
-    protected void doPostAlgorithmActions() {\r
-        // nothing to do\r
-    }\r
-    \r
     private boolean setVariables() {\r
         ae = aeField.getText();\r
         port = Integer.parseInt(portField.getText());\r
@@ -260,9 +262,29 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
     public void windowClosing(WindowEvent event) {\r
         stopAlgorithm();\r
         \r
-        super.windowClosing(event);\r
+        if (JDialogStandalonePlugin.isExitRequired()) {\r
+            ViewUserInterface.getReference().windowClosing(event);\r
+        }\r
     }\r
     \r
+    @Override\r
+    public void windowActivated(WindowEvent arg0) {}\r
+\r
+    @Override\r
+    public void windowClosed(WindowEvent arg0) {}\r
+\r
+    @Override\r
+    public void windowDeactivated(WindowEvent arg0) {}\r
+\r
+    @Override\r
+    public void windowDeiconified(WindowEvent arg0) {}\r
+\r
+    @Override\r
+    public void windowIconified(WindowEvent arg0) {}\r
+\r
+    @Override\r
+    public void windowOpened(WindowEvent arg0) {}\r
+    \r
     private boolean browseDir() {\r
         String initDir = outputDirField.getText();\r
         if (initDir.equals("") || !(new File(initDir).exists())) {\r
@@ -293,4 +315,31 @@ public class PlugInDialogStrokeSegmentationListener extends JDialogStandaloneScr
     public void log(final String line) {\r
         logOutputArea.getTextArea().append(line + "\n");\r
     }\r
+    \r
+    private boolean readListenerConfig() {\r
+        final InputStream in = getClass().getResourceAsStream(configFileName);\r
+        if (in != null) {\r
+            final Properties prop = new Properties();\r
+            try {\r
+                prop.load(in);\r
+            } catch (final IOException e) {\r
+                Preferences.debug("Unable to load stroke segementation listener plugin preferences file: " + configFileName + "\n", Preferences.DEBUG_MINOR);\r
+                e.printStackTrace();\r
+                return false;\r
+            }\r
+            \r
+            ae = prop.getProperty("listenerAETitle", ae);\r
+            \r
+            port = Integer.parseInt(prop.getProperty("listenerPort", "" + port));\r
+            \r
+            outputDir = prop.getProperty("listenerOutputDir", outputDir);\r
+            \r
+            doEmailReport = Boolean.parseBoolean(prop.getProperty("listenerDoEmail", "" + doEmailReport));\r
+            \r
+            return true;\r
+        } else {\r
+            // couldn't load file\r
+            return false;\r
+        }\r
+    }\r
 }
\ No newline at end of file
index 24c2baa..b730b6b 100644 (file)
@@ -393,12 +393,12 @@ public class StrokeSegmentationDicomReceiver {
         \r
         PrintWriter out;\r
         try {\r
-            reportTxt.replaceAll(reportDwiCid, dwiLightboxFile.getName());\r
-            reportTxt.replaceAll(reportAdcCid, adcLightboxFile.getName());\r
+            String fileTxt = reportTxt.replaceAll(reportDwiCid, dwiLightboxFile.getName());\r
+            fileTxt = fileTxt.replaceAll(reportAdcCid, adcLightboxFile.getName());\r
             \r
             out = new PrintWriter(htmlReportPath);\r
             out.println("<html>");\r
-            out.print(reportTxt);\r
+            out.print(fileTxt);\r
             out.println("</html>");\r
             out.close();\r
         } catch (FileNotFoundException e) {\r
@@ -475,11 +475,6 @@ public class StrokeSegmentationDicomReceiver {
         String patientName = (String) fileInfoDicom.getTagTable().getValue("0010,0010");\r
         String coreSegVol = format.format(coreVolCC);\r
         \r
-        String dwiPdfImage = dwiLightboxFile.getName();\r
-        String adcPdfImage = adcLightboxFile.getName();\r
-        \r
-        final int imgDisplay = 1027;\r
-        \r
         //String reportTxt = "<html>\n";\r
         String reportTxt = "";\r
         reportTxt += "<h1>" + "MIPAV Stroke Core Segmentation Report" + "</h1>\n";\r
index 330c03b..a3a7de4 100644 (file)
@@ -1,7 +1,11 @@
-emailFrom=\r
-emailTo=\r
-emailHost=\r
+listenerAETitle=MIPAV-stroke\r
+listenerPort=11115\r
+#listenerOutputDir=\r
+listenerDoEmail=true\r
+emailFrom=evan.mccreedy@gmail.com\r
+emailTo=mccreedy@mail.nih.gov\r
+emailHost=smtp.gmail.com\r
 emailPort=465\r
-emailUsername=\r
+emailUsername=evan.mccreedy@gmail.com\r
 emailPassword=\r
 \r