mirror of https://github.com/dnomd343/mobi-meta
Browse Source
Store directory of the last opened file using the Java Preferences API to make JFileChooser act the same way as FileDialog in that regard, that is, the last directory is remembered between different executions.master
Bruno Barbieri
12 years ago
3 changed files with 127 additions and 85 deletions
@ -0,0 +1,37 @@ |
|||
package gui; |
|||
|
|||
import java.io.File; |
|||
import java.io.FilenameFilter; |
|||
|
|||
import javax.swing.filechooser.FileFilter; |
|||
|
|||
class GenericFileFilter extends FileFilter implements FilenameFilter |
|||
{ |
|||
public String extension; |
|||
|
|||
public String getExtension() { |
|||
return extension; |
|||
} |
|||
|
|||
public GenericFileFilter(String extension) { |
|||
this.extension = extension.toLowerCase(); |
|||
} |
|||
|
|||
public String getDescription() |
|||
{ |
|||
return extension; |
|||
} |
|||
|
|||
public boolean accept(File f, String name) |
|||
{ |
|||
return (accept(f)); |
|||
} |
|||
|
|||
public boolean accept(File f) |
|||
{ |
|||
if (f.isDirectory()) return true; |
|||
|
|||
return (f.getName().toLowerCase().endsWith(extension)); |
|||
} |
|||
|
|||
} |
@ -1,32 +0,0 @@ |
|||
package gui; |
|||
|
|||
import java.io.File; |
|||
import java.io.FilenameFilter; |
|||
|
|||
import javax.swing.filechooser.FileFilter; |
|||
|
|||
class MobiFileFilter extends FileFilter implements FilenameFilter |
|||
{ |
|||
|
|||
// to make it work with JFileChooser
|
|||
//
|
|||
public boolean accept(File f) |
|||
{ |
|||
if (f.isDirectory()) return true; |
|||
|
|||
return (f.getName().toLowerCase().endsWith(".azw") || f.getName().toLowerCase().endsWith(".mobi")); |
|||
} |
|||
|
|||
public String getDescription() |
|||
{ |
|||
return "*.azw,*.mobi"; |
|||
} |
|||
|
|||
// to make it work with java.awt.FileDialog
|
|||
//
|
|||
public boolean accept(File f, String name) |
|||
{ |
|||
return (name.toLowerCase().endsWith(".azw") || name.toLowerCase().endsWith(".mobi")); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue