/* Copyright 2004-2006 Stefan Ram. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package de.dclj.ram.system.filesystem; public class Directory /* de.dclj.ram.system.filesystem.Directory */ { javax.swing.filechooser.FileSystemView fileSystemView = null; boolean fileSystemViewIsUninitialized = true; /************ Portadir fundament ************/ /* Directory for user documents. for example: "C:\My Documents" or "/home/andrew". This is were the user would store an article he wrote. */ public java.io.File userDirectory() { if( this.fileSystemViewIsUninitialized )this.initializeFileSystemView(); return this.fileSystemView.getDefaultDirectory(); } /*Current directory on application startup. For example "C:\dvl" or "/home/kiwi/compiler_tests/environ". */ public java.io.File currentDirectory() { return new java.io.File( System.getProperty( "user.dir" )); } /*temporary directory (might leak user data?): C:\WINDOWS\TEMP/tmp */ public java.io.File temporaryDataDirectory() { return new java.io.File( System.getProperty( "java.io.tmpdir" )); } /************ Java specific ************/ /* This contains the Java installation. Usually it is considered read-only for applications with rare exceptions. */ public java.io.File javaDirectory() { return new java.io.File( System.getProperty( "java.home" )); } public java.io.File codeDirectory( final java.lang.Class class_ ) throws java.net.URISyntaxException { final java.security.ProtectionDomain protectionDomain = class_.getProtectionDomain(); final java.security.CodeSource codeSource = protectionDomain.getCodeSource(); final java.net.URL uRL = codeSource.getLocation(); final java.net.URI uRI = uRL.toURI(); /* throws java.net.URISyntaxException: */ final java.io.File file = new java.io.File( uRI ); return file; } public void initializeFileSystemView() { if( this.fileSystemViewIsUninitialized ) { this.fileSystemView = javax.swing.filechooser.FileSystemView.getFileSystemView(); this.fileSystemViewIsUninitialized = false; }} public static java.lang.String toString( final java.io.File file ) throws java.io.IOException { return file.getAbsolutePath(); } }