📄 oyoahadefaultfilesystemadaptor.java
字号:
{
o.toString();
}
return null;
}
public Color getColor(File file)
{
Hashtable table = getFileInformation();
String type = getType(file, false);
if(type==null)
{
return null;
}
Object o = table.get(type+"_color");
if(o==null)
{
return null;
}
if(o instanceof Color)
{
return (Color)o;
}
if(o instanceof String)
{
Color c = OyoahaThemeLoaderUtilities.readColor((String)o);
table.put(type+"_color", c);
return c;
}
return null;
}
public Boolean isTraversable(File file)
{
if (file.isDirectory() || file instanceof OyoahaVectorFolder)
{
return Boolean.TRUE;
}
else
{
return Boolean.FALSE;
}
}
public Boolean isHidden(File file)
{
String name = file.getName();
if(name != null && name.charAt(0) == '.')
{
return Boolean.TRUE;
}
else
{
return Boolean.FALSE;
}
}
public Icon getIcon(File file)
{
Hashtable table = getFileInformation();
if(file instanceof OyoahaVectorFolder)
{
return (Icon)table.get("folder_icon");
}
String type = getType(file, false);
if(type==null) //normaly impossible
{
if(file.isDirectory())
type = OyoahaFileView.FOLDER_TYPE;
else
type = OyoahaFileView.FILE_TYPE;
}
Object o = table.get(type+"_icon");
if(o==null)
{
if(file.isDirectory())
return (Icon)table.get("folder_icon");
else
return (Icon)table.get("file_icon");
}
if(o instanceof Icon)
{
return (Icon)o;
}
if(o instanceof String)
{
//TODO try to load from file?
try
{
ImageIcon icon = new OyoahaImageIcon(getClass().getResource("/com/oyoaha/swing/plaf/oyoaha/rc/"+o), (String)o);
table.put(type+"_icon", icon);
return icon;
}
catch(Exception e)
{
//remove from table
table.remove(type+"_icon");
}
}
return (Icon)table.get("file_icon");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// FILE ROUTINE
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
protected static Hashtable extraFile; //-> File : type (extraFile can be desktop or floppy drive)
protected static Hashtable fileType; //-> extention/file/string : type
protected static Hashtable fileInformation; //-> type + _foo : Object (String/Icon/Color)
/**
*
* //->windows
*
* //->"desktop = File"
* //->"doc = File"
* //->"web = File"
* //->"app = File"
*
*/
public static Hashtable getExtraFile()
{
//load only root by default
if(extraFile==null)
{
extraFile = new Hashtable();
File load = new File(System.getProperty("user.home"), ".filechooser" + File.separator + "extra.ini");
if(load.exists()) //erase old version
{
load.delete();
}
//try to whish...
String os = System.getProperty("os.name");
os = os.toLowerCase();
if(os.startsWith("windows"))
{
ResourceBundle bundle = ResourceBundle.getBundle("com.oyoaha.swing.plaf.oyoaha.filechooser.windowsFilename");
File desktopRoot = new File(System.getProperty("user.home"));
File desktop = new File(desktopRoot, bundle.getString(OyoahaFileView.DESKTOP_TYPE));
if(desktop.exists())
{
extraFile.put(desktop, OyoahaFileView.DESKTOP_TYPE);
}
//doc...
File doc = new File(desktopRoot, bundle.getString(OyoahaFileView.MY_DOCUMENT_TYPE));
if(doc.exists())
{
extraFile.put(doc, OyoahaFileView.MY_DOCUMENT_TYPE);
}
//app..
File app = new File("c:\\" + bundle.getString(OyoahaFileView.MY_APPLICATION_TYPE));
if(app.exists())
{
extraFile.put(app, OyoahaFileView.MY_APPLICATION_TYPE);
}
//floppy A...
extraFile.put(new File("a:\\"), OyoahaFileView.FLOPPY_TYPE);
}
/*else
if(os.startsWith("macos"))
{
}
else
if(os.equals("sunos") || os.equals("solaris"))
{
}*/
else //linux? freebsd? beos? as400? aix?
{
ResourceBundle bundle = ResourceBundle.getBundle("com.oyoaha.swing.plaf.oyoaha.filechooser.linuxFilename");
//KDE DESKTOP
File desktop = new File(System.getProperty("user.home"), bundle.getString(OyoahaFileView.DESKTOP_TYPE));
if(desktop.exists())
{
extraFile.put(desktop, OyoahaFileView.DESKTOP_TYPE);
}
//WEB
File web = new File(System.getProperty("user.home"), "httpd/html");
if(web.exists())
{
extraFile.put(web, OyoahaFileView.MY_HOMEPAGE_TYPE);
}
//MNT hard drive and floppy (c d e cdrom floppy)
File mnt = new File("/mnt");
if(mnt.exists() && mnt.isDirectory())
{
String[] list = mnt.list();
for(int i=0;i<list.length;i++)
{
File f = new File(mnt, list[i]);
if(f.isDirectory())
{
if(list[i].equalsIgnoreCase(bundle.getString(OyoahaFileView.FLOPPY_TYPE)))
extraFile.put(f, OyoahaFileView.FLOPPY_TYPE);
else
extraFile.put(f, OyoahaFileView.HARDDRIVE_TYPE);
}
}
}
}
File[] roots = javax.swing.filechooser.FileSystemView.getFileSystemView().getRoots();
for(int i=0;i<roots.length;i++)
{
extraFile.put(roots[i], OyoahaFileView.HARDDRIVE_TYPE);
}
//current
File current = new File(System.getProperty("user.dir"));
if(!extraFile.containsKey(current))
extraFile.put(current, OyoahaFileView.CURRENT_TYPE);
//home
File home = new File(System.getProperty("user.home"));
if(!extraFile.containsKey(home))
extraFile.put(home, OyoahaFileView.HOME_TYPE);
}
return extraFile;
}
/**
* //->".txt = name"
*/
public static Hashtable getFileType()
{
if(fileType==null)
{
fileType = new Hashtable();
//load the fileInformation from resource...
//file information can be locale sensitive
try
{
ResourceBundle bundle = ResourceBundle.getBundle("com.oyoaha.swing.plaf.oyoaha.filechooser.type");
Enumeration e = bundle.getKeys();
while(e.hasMoreElements())
{
String key = e.nextElement().toString();
fileType.put(key, bundle.getString(key));
}
}
catch(Exception e)
{
}
File load = new File(System.getProperty("user.home"), ".filechooser" + File.separator + "type.ini");
if(load.exists()) //erase old version
{
load.delete();
}
}
return fileType;
}
/**
* //->"name_icon = String/Icon"
* //->"name_big_icon = String/Icon"
* //->"name_info = String"
*/
public static Hashtable getFileInformation()
{
if(fileInformation==null)
{
fileInformation = new Hashtable();
//load the fileInformation from resource...
//file information can be locale sensitive
try
{
ResourceBundle bundle = ResourceBundle.getBundle("com.oyoaha.swing.plaf.oyoaha.filechooser.info");
Enumeration e = bundle.getKeys();
while(e.hasMoreElements())
{
String key = e.nextElement().toString();
fileInformation.put(key, bundle.getString(key));
}
}
catch(Exception e)
{
}
File load = new File(System.getProperty("user.home"), ".filechooser" + File.separator + "info.ini");
if(load.exists()) //erase old version
{
load.delete();
}
//mine info (special)
fileInformation.put("file_info", UIManager.getString("FileChooser.fileDescriptionText"));
fileInformation.put("folder_info", UIManager.getString("FileChooser.directoryDescriptionText"));
//mine icon (special)
fileInformation.put("folder_icon", UIManager.getIcon("FileView.directoryIcon"));
fileInformation.put("file_icon", UIManager.getIcon("FileView.fileIcon"));
fileInformation.put("hd_icon", UIManager.getIcon("FileView.hardDriveIcon"));
fileInformation.put("floppy_icon", UIManager.getIcon("FileView.floppyDriveIcon"));
}
return fileInformation;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -