0N/A/*
3842N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/Aimport javax.swing.filechooser.FileSystemView;
0N/A
3842N/A
0N/A/**
0N/A * This is a simple example that uses the FileSystemView class.
0N/A * You can provide a superclass of the FileSystemView class with your own functionality.
0N/A *
0N/A * @author Pavel Porvatov
0N/A */
0N/Apublic class ExampleFileSystemView extends FileSystemView {
3842N/A
0N/A /**
0N/A * Creates a new folder with the default name "New folder". This method is invoked
0N/A * when the user presses the "New folder" button.
0N/A */
0N/A public File createNewFolder(File containingDir) throws IOException {
0N/A File result = new File(containingDir, "New folder");
0N/A
0N/A if (result.exists()) {
0N/A throw new IOException("Directory 'New folder' exists");
0N/A }
0N/A
0N/A if (!result.mkdir()) {
0N/A throw new IOException("Cannot create directory");
0N/A }
0N/A
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Returns a list which appears in a drop-down list of the FileChooser component.
0N/A * In this implementation only the home directory is returned.
0N/A */
3842N/A @Override
0N/A public File[] getRoots() {
3842N/A return new File[] { getHomeDirectory() };
0N/A }
0N/A
0N/A /**
0N/A * Returns a string that represents a directory or a file in the FileChooser component.
0N/A * A string with all upper case letters is returned for a directory.
0N/A * A string with all lower case letters is returned for a file.
0N/A */
3842N/A @Override
0N/A public String getSystemDisplayName(File f) {
0N/A String displayName = super.getSystemDisplayName(f);
0N/A
3842N/A return f.isDirectory() ? displayName.toUpperCase() : displayName.
3842N/A toLowerCase();
0N/A }
0N/A}