Revision: 5167
          http://sourceforge.net/p/jump-pilot/code/5167
Author:   edso
Date:     2016-11-06 15:16:45 +0000 (Sun, 06 Nov 2016)
Log Message:
-----------
fix JFCWithEnterAction and reactivate it in SaveLayersWithoutDataSourcePlugIn
reformatting: removed some tabs

Modified Paths:
--------------
    
core/trunk/src/org/openjump/core/ui/plugin/file/SaveLayersWithoutDataSourcePlugIn.java
    core/trunk/src/org/openjump/core/ui/plugin/file/open/JFCWithEnterAction.java

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/file/SaveLayersWithoutDataSourcePlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/file/SaveLayersWithoutDataSourcePlugIn.java
      2016-11-06 14:23:06 UTC (rev 5166)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/file/SaveLayersWithoutDataSourcePlugIn.java
      2016-11-06 15:16:45 UTC (rev 5167)
@@ -90,8 +90,7 @@
     }
     
     public void initialize(PlugInContext context) throws Exception {
-      //fileChooser = new JFCWithEnterAction();
-      fileChooser = new JFileChooser();
+      fileChooser = new JFCWithEnterAction();
       fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
       fileChooser.setDialogTitle(FILECHOOSER);
     }
@@ -165,12 +164,12 @@
         if (dotPos > 0) name = name.substring(0, dotPos);
         File fileName = FileUtil.addExtensionIfNone(new File(name), ext);
         String path = new File(dir, fileName.getName()).getAbsolutePath();
-        
+
         DriverProperties dp = new DriverProperties();
         dp.set(DataSource.URI_KEY, new File(path).toURI().toString());
         dp.set(DataSource.FILE_KEY, path);
         dataSource.setProperties(dp);
-                
+
         DataSourceQuery dsq = new DataSourceQuery(dataSource, path, path);
         layer.setDataSourceQuery(dsq).setFeatureCollectionModified(false);
         dataSource.getConnection().executeUpdate("", 
layer.getFeatureCollectionWrapper(), new DummyTaskMonitor());
@@ -186,23 +185,26 @@
         }
         return layersWithoutDataSource;
     }
-    
+
     /**
      * @param workbenchContext
      * @return an enable check
      */
     public EnableCheck createEnableCheck(WorkbenchContext workbenchContext) {
-           final WorkbenchContext wc = workbenchContext;
-           EnableCheckFactory enableCheckFactory = new 
EnableCheckFactory(workbenchContext);
-           MultiEnableCheck enableCheck = new MultiEnableCheck();
-           
enableCheck.add(enableCheckFactory.createWindowWithLayerManagerMustBeActiveCheck());
-           enableCheck.add(new EnableCheck(){
-               public String check(javax.swing.JComponent component) {
-                   return layersWithoutDataSource(wc.getTask()).size() > 0 ? 
null :
-                       
I18N.get("org.openjump.core.ui.plugin.file.SaveLayersWithoutDataSourcePlugIn.a-layer-without-datasource-must-exist");
-               }
-           });
-           return enableCheck;
+      final WorkbenchContext wc = workbenchContext;
+      EnableCheckFactory enableCheckFactory = new EnableCheckFactory(
+          workbenchContext);
+      MultiEnableCheck enableCheck = new MultiEnableCheck();
+      enableCheck.add(enableCheckFactory
+          .createWindowWithLayerManagerMustBeActiveCheck());
+      enableCheck.add(new EnableCheck() {
+        public String check(javax.swing.JComponent component) {
+          return layersWithoutDataSource(wc.getTask()).size() > 0 ? null
+              : I18N
+                  
.get("org.openjump.core.ui.plugin.file.SaveLayersWithoutDataSourcePlugIn.a-layer-without-datasource-must-exist");
+        }
+      });
+      return enableCheck;
     }
 
 }

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/file/open/JFCWithEnterAction.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/file/open/JFCWithEnterAction.java    
    2016-11-06 14:23:06 UTC (rev 5166)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/file/open/JFCWithEnterAction.java    
    2016-11-06 15:16:45 UTC (rev 5167)
@@ -3,12 +3,14 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.io.File;
+import java.lang.reflect.Method;
 
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 import javax.swing.plaf.FileChooserUI;
 import javax.swing.plaf.basic.BasicFileChooserUI;
 
+import com.vividsolutions.jump.workbench.Logger;
 import com.vividsolutions.jump.workbench.ui.RecursiveKeyListener;
 
 /**
@@ -44,29 +46,47 @@
     });
   }
 
+  /**
+   * Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns
+   * nothing when a file is selected" [Jon Aquino]
+   */
   public File getSelectedFile() {
+    File file = super.getSelectedFile();
+    if (file != null)
+      return file;
+
     File[] files = super.getSelectedFiles();
     if (files.length > 0)
       return files[0];
 
-    // if none was selected but there is text in the filename field
-    FileChooserUI ui = getUI();
-    // fetch a filename if manually entered in file name text field of chooser
-    if (ui instanceof BasicFileChooserUI) {
-      BasicFileChooserUI bui = (BasicFileChooserUI) ui;
-      String filename = ((BasicFileChooserUI) ui).getFileName();
-      if (!filename.isEmpty()) {
-        return new File(getCurrentDirectory(), filename);
-      }
+//    // if none was selected but there is text in the filename field
+//    FileChooserUI ui = getUI();
+//    // fetch a filename if manually entered in file name text field of 
chooser
+//    if (ui instanceof BasicFileChooserUI) {
+//      BasicFileChooserUI bui = (BasicFileChooserUI) ui;
+//      String filename = ((BasicFileChooserUI) ui).getFileName();
+//      if (!filename.isEmpty()) {
+//        return new File(getCurrentDirectory(), filename);
+//      }
+//    }
+
+    // a little more generic than the above
+    try {
+      Method getFileName = getUI().getClass().getDeclaredMethod("getFileName");
+      String filename = (String) getFileName.invoke(getUI());
+      if (!filename.isEmpty())
+        file = new File(filename);
+        if (file.getParentFile() == null)
+          file = new File(getCurrentDirectory(), filename);
+        return file;
+    } catch (Exception e) {
+      Logger.error(e);
     }
-    
-    return super.getSelectedFile();
+
+    // ok, we give up! nothing was selected at all :)
+    return null;
   }
 
-  /**
-   * Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns
-   * nothing when a file is selected" [Jon Aquino]
-   */
   public File[] getSelectedFiles() {
     return ((super.getSelectedFiles().length == 0) && (super.getSelectedFile() 
!= null)) ? new File[] { getSelectedFile() } : super.getSelectedFiles();
   }


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to