ch.randelshofer.quaqua.filechooser.LinuxFileSystemView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Quaqua Show documentation
Show all versions of Quaqua Show documentation
A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library)
Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer.
Mavenisation by Matt Gumbley, DevZendo.org - for problems with
Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page.
For full license details, see http://randelshofer.ch/quaqua/license.html
The newest version!
/*
* @(#)LinuxFileSystemView.java
*
* Copyright (c) 2009-2010 Werner Randelshofer, Immensee, Switzerland.
* All rights reserved.
*
* The copyright of this software is owned by Werner Randelshofer.
* You may not use, copy or modify this software, except in
* accordance with the license agreement you entered into with
* Werner Randelshofer. For details see accompanying license terms
*/
package ch.randelshofer.quaqua.filechooser;
import ch.randelshofer.quaqua.osx.OSXFile;
import java.io.File;
/**
* LinuxFileSystemView.
*
* @author Werner Randelshofer, stefanmd
* @version $Id: LinuxFileSystemView.java 363 2010-11-21 17:41:04Z wrandelshofer $
*/
public class LinuxFileSystemView extends QuaquaFileSystemView {
/** XXX - The computer mount does only exist in Gnome */
private File computer = new File("computer:///");
/** XXX - There is no volumes folder, only root. */
private File volumesFolder = new File("/");
/** XXX - This works on Gnome and KDE */
private File desktop = new File(System.getProperty("user.home")+"/Desktop");
/** The system volume is "/" for all Linux distributions. */
private File systemVolume = new File("/");
private final static boolean DEBUG = false;
/**
* Creates a new instance.
*/
public LinuxFileSystemView() {
}
public File getComputer() {
return computer;
}
public File getSystemVolume() {
return volumesFolder;
}
public File getDesktop() {
return desktop;
}
/**
* Returns all root partitions on this system.
* XXX - This needs more work.
*/
public File[] getRoots() {
return new File[] {volumesFolder};
}
/**
* Returns whether a file is hidden or not.
*/
public boolean isHiddenFile(File f) {
if (f.isHidden()) {
return true;
} else {
String name = f.getName();
if (name.length() == 0) {
return false;
} else if (name.charAt(0) == '.') {
// File names starting with '.' are considered as
// hidden
return true;
} else {
return false;
}
}
}
/**
* Determines if the given file is a root partition or drive.
*/
public boolean isRoot(File f) {
if (f == null || !f.isAbsolute()) {
return false;
}
if (f.equals(computer)) {
return true;
}
File[] roots = getRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].equals(f)) {
return true;
}
}
return false;
}
/**
* On Windows, a file can appear in multiple folders, other than its
* parent directory in the filesystem. Folder could for example be the
* "Desktop" folder which is not the same as file.getParentFile().
*
* @param folder a File
object repesenting a directory or special folder
* @param file a File
object
* @return true
if folder
is a directory or special folder and contains file
.
*/
public boolean isParent(File folder, File file) {
if (folder == null || file == null) {
return false;
} else {
return folder.equals(file.getParentFile());
}
}
/**
*
* @param parent a File
object repesenting a directory or special folder
* @param fileName a name of a file or folder which exists in parent
* @return a File object. This is normally constructed with new
* File(parent, fileName)
except when parent and child are both
* special folders, in which case the File
is a wrapper containing
* a ShellFolder
object.
*/
public File getChild(File parent, String fileName) {
return new File(parent, fileName);
}
/**
* Is dir the root of a tree in the file system, such as a drive
* or partition. Example: Returns true for "C:\" on Windows 98.
*
* @param dir a File
object representing a directory
* @return true
if f
is a root of a filesystem
* @see #isRoot
*/
public boolean isFileSystemRoot(File dir) {
File parentFile = dir.getParentFile();
return parentFile == null || parentFile.equals(volumesFolder);
}
// Providing default implementations for the remaining methods
// because most OS file systems will likely be able to use this
// code. If a given OS can't, override these methods in its
// implementation.
public File getHomeDirectory() {
return createFileObject(System.getProperty("user.home"));
}
/**
* Return the user's default starting directory for the file chooser.
*
* @return a File
object representing the default
* starting folder
*/
public File getDefaultDirectory() {
return getHomeDirectory();
}
public String getSystemDisplayName(File f) {
// FIXME - Determine display name
if (f.equals(systemVolume)) {
return "/";
} else {
if (OSXFile.canWorkWithAliases()) {
return OSXFile.getDisplayName(f);
} else {
return target.getSystemDisplayName(f);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy