Revision: 6397
          http://sourceforge.net/p/jump-pilot/code/6397
Author:   edso
Date:     2020-08-30 14:18:39 +0000 (Sun, 30 Aug 2020)
Log Message:
-----------
fix #482: disable regedit call and always allow selection of 
ArcGIS_SLD_Converter.exe with the previous selected location preselected

Modified Paths:
--------------
    
core/trunk/src/org/openjump/core/ui/plugin/style/ImportArcMapStylePlugIn.java

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/style/ImportArcMapStylePlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/style/ImportArcMapStylePlugIn.java   
    2020-08-29 20:11:25 UTC (rev 6396)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/style/ImportArcMapStylePlugIn.java   
    2020-08-30 14:18:39 UTC (rev 6397)
@@ -41,7 +41,6 @@
 import static com.vividsolutions.jump.I18N.get;
 import static com.vividsolutions.jump.workbench.ui.MenuNames.LAYER;
 import static 
com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn.get;
-import static java.io.File.createTempFile;
 import static javax.swing.JFileChooser.APPROVE_OPTION;
 import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
 import static javax.swing.JOptionPane.showMessageDialog;
@@ -48,13 +47,11 @@
 import static javax.xml.parsers.DocumentBuilderFactory.newInstance;
 import static org.openjump.core.ui.plugin.style.ImportSLDPlugIn.importSLD;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
 
 import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Document;
@@ -92,49 +89,60 @@
 
     private static File findArcMap2SLD(WorkbenchFrame wbframe, Blackboard bb) 
throws IOException, InterruptedException {
         String arcmap2sld = (String) bb.get("ArcMapStylePlugin.toollocation");
-        if (arcmap2sld == null) {
-            File tmp = createTempFile("amtsldreg", null);
-            ProcessBuilder pb = new ProcessBuilder("regedit", "/e", 
tmp.toString(),
-                    
"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion");
-            pb.start().waitFor();
-            BufferedReader in = new BufferedReader(new InputStreamReader(new 
FileInputStream(tmp), "UTF-16"));
-            String s;
-            while ((s = in.readLine()) != null) {
-                if (s.startsWith("\"ProgramFilesDir\"=\"")) {
-                    s = s.split("=")[1];
-                    s = s.substring(1, s.length() - 1);
-                    arcmap2sld = s + 
"\\i3mainz\\ArcMap2SLD_Full_Setup\\ArcGIS_SLD_Converter.exe";
-                    break;
-                }
-            }
-            in.close();
-            tmp.delete();
-        }
+        
+        // disabled because it dies with
+        //Caused by: java.io.IOException: CreateProcess error=740, The 
requested operation requires elevation
+        //at java.lang.ProcessImpl.create(Native Method)
+//        if (arcmap2sld == null) {
+//            File tmp = createTempFile("amtsldreg", null);
+//            ProcessBuilder pb = new ProcessBuilder("regedit", "/e", 
tmp.toString(),
+//                    
"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion");
+//            pb.start().waitFor();
+//            BufferedReader in = new BufferedReader(new InputStreamReader(new 
FileInputStream(tmp), "UTF-16"));
+//            String s;
+//            while ((s = in.readLine()) != null) {
+//                if (s.startsWith("\"ProgramFilesDir\"=\"")) {
+//                    s = s.split("=")[1];
+//                    s = s.substring(1, s.length() - 1);
+//                    arcmap2sld = s + 
"\\i3mainz\\ArcMap2SLD_Full_Setup\\ArcGIS_SLD_Converter.exe";
+//                    break;
+//                }
+//            }
+//            in.close();
+//            tmp.delete();
+//        }
 
-        JFileChooser chooser = new JFileChooser();
+        final String executableName = "ArcGIS_SLD_Converter.exe";
+        JFileChooser chooser = new JFileChooser(arcmap2sld);
+        chooser.setFileFilter(new FileFilter() {
+          @Override
+          public String getDescription() {
+            return executableName;
+          }
+          @Override
+          public boolean accept(File f) {
+            return f.getName().equals(executableName);
+          }
+        });
 
-        File am2sld = arcmap2sld == null ? null : new File(arcmap2sld);
-        if (am2sld == null || !am2sld.exists()) {
-            showMessageDialog(wbframe,
-                    
get("org.openjump.core.ui.plugin.style.ImportArcMapStylePlugIn.Must-Select-Location-Of-Tool"),
-                    
get("org.openjump.core.ui.plugin.style.ImportSLDPlugIn.Question"), 
INFORMATION_MESSAGE);
-            if (arcmap2sld != null) {
-                chooser.setSelectedFile(new File(arcmap2sld));
-            }
+        showMessageDialog(wbframe,
+                
get("org.openjump.core.ui.plugin.style.ImportArcMapStylePlugIn.Must-Select-Location-Of-Tool"),
+                
get("org.openjump.core.ui.plugin.style.ImportSLDPlugIn.Question"), 
INFORMATION_MESSAGE);
+        if (arcmap2sld != null) {
+            chooser.setSelectedFile(new File(arcmap2sld));
+        }
 
-            int res = chooser.showOpenDialog(wbframe);
-            if (res == APPROVE_OPTION) {
-                am2sld = chooser.getSelectedFile();
-                if (!am2sld.exists()) {
-                    return null;
-                }
-                bb.put("ArcMapStylePlugin.toollocation", 
am2sld.getAbsoluteFile().toString());
-            } else {
+        int res = chooser.showOpenDialog(wbframe);
+        if (res == APPROVE_OPTION) {
+            File am2sld = chooser.getSelectedFile();
+            if (!am2sld.exists()) {
                 return null;
             }
+            bb.put("ArcMapStylePlugin.toollocation", 
am2sld.getAbsoluteFile().toString());
+            return am2sld;
         }
 
-        return am2sld;
+        return null;
     }
 
     @Override



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to