-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for rare environments that caused an oobE in the list renderer of…
… JFileChooser.
- Loading branch information
Showing
4 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ctakes-gui/src/main/java/org/apache/ctakes/gui/util/FileChooserUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.ctakes.gui.util; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.swing.*; | ||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* @author SPF , chip-nlp | ||
* @since {8/21/2024} | ||
*/ | ||
final public class FileChooserUtil { | ||
static private final Logger LOGGER = LoggerFactory.getLogger( "FileChooserUtil" ); | ||
|
||
private FileChooserUtil() {} | ||
|
||
static public void selectWorkingDir( final JFileChooser chooser ) { | ||
String cwd = Paths.get( "" ).toAbsolutePath().toFile().getPath(); | ||
if ( cwd.isEmpty() ) { | ||
cwd = System.getProperty( "user.dir" ); | ||
} | ||
selectDir( chooser, cwd ); | ||
} | ||
|
||
static public void selectDir( final JFileChooser chooser, final String dir ) { | ||
if ( dir == null || dir.isEmpty() ) { | ||
LOGGER.debug( "Selected directory is null or empty." ); | ||
return; | ||
} | ||
SwingUtilities.invokeLater( () -> | ||
{ | ||
try { | ||
chooser.setCurrentDirectory( new File( dir ) ); | ||
} catch ( IndexOutOfBoundsException oobE ) { | ||
LOGGER.error( "FileChooser could not change directory to {}", dir ); | ||
LOGGER.error( oobE.getMessage() ); | ||
LOGGER.warn( "Keeping current directory {}", chooser.getCurrentDirectory() ); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |