All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fife.ui.rtextfilechooser.RootManager Maven / Gradle / Ivy

/*
 * 06/24/2005
 *
 * RootManager.java - Maintains information on the "roots" of the local file
 * system.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */
package org.fife.ui.rtextfilechooser;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.swing.filechooser.FileSystemView;


/**
 * Keeps information on the roots of the local file system.  This class
 * is a singleton and is used by all RTextFileChoosers and
 * FileSystemTrees.
 *
 * @author Robert Futrell
 * @version 1.0
 */
class RootManager {

	private File[] roots;
	private int rootCount;

	private static final RootManager INSTANCE = new RootManager();


	/**
	 * Private constructor.
	 */
	private RootManager() {
		roots = RootManager.getAllRoots();
		rootCount = roots.length;
	}


	/**
	 * Gets the roots from the FileSystemView and File.
	 *
	 * @return An array of the roots of the local file system.
	 */
	private static final File[] getAllRoots() {
		FileSystemView fsv = FileSystemView.getFileSystemView();
		ArrayList list = new ArrayList(Arrays.asList(fsv.getRoots()));
		File[] moreRoots = File.listRoots();
		for (int i=0; iRootManager.
	 *
	 * @return The singleton instance.
	 */
	public static RootManager getInstance() {
		return INSTANCE;
	}


	/**
	 * Returns the root for a given file.
	 *
	 * @param file The file.
	 * @return The root for the file.
	 */
	public File getRootForFile(final File file) {
		File f2 = file.getAbsoluteFile(); // Needed for e.g. 'new File(".");'
		while (f2!=null) {
			for (int i=0; iFile standards or FileSystemView standards).
	 *
	 * @param file The file to check.
	 * @return Whether or not file is a root.
	 */
	public boolean isRoot(final File file) {
		for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy