Example usage for javax.swing.filechooser FileSystemView getFileSystemView

List of usage examples for javax.swing.filechooser FileSystemView getFileSystemView

Introduction

In this page you can find the example usage for javax.swing.filechooser FileSystemView getFileSystemView.

Prototype

public static FileSystemView getFileSystemView() 

Source Link

Document

Returns the file system view.

Usage

From source file:org.docx4all.ui.menu.FileMenu.java

@Action
public void newFile() {
    Preferences prefs = Preferences.userNodeForPackage(getClass());
    WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class);

    FileObject fo = null;//from  ww  w . java  2  s.  c  o  m
    try {
        //Prepare the new file name
        StringBuffer newFile = new StringBuffer();
        newFile.append(editor.getUntitledFileName());
        newFile.append(++_untitledFileNumber);
        newFile.append(".docx");

        //put new file in same directory as last opened local file's.
        //if there isn't last opened local file, put it in the
        //swing file chooser's default directory.
        String lastFile = prefs.get(Constants.LAST_OPENED_LOCAL_FILE, Constants.EMPTY_STRING);
        if (lastFile.length() == 0) {
            fo = VFSUtils.getFileSystemManager()
                    .toFileObject(FileSystemView.getFileSystemView().getDefaultDirectory());
        } else {
            fo = VFSUtils.getFileSystemManager().resolveFile(lastFile).getParent();
        }
        fo = fo.resolveFile(newFile.toString());

    } catch (FileSystemException exc) {
        exc.printStackTrace();
        ResourceMap rm = editor.getContext().getResourceMap(getClass());
        String title = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.text");
        String message = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.errorMessage");
        editor.showMessageDialog(title, message, JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    editor.createInternalFrame(fo);
}

From source file:org.openmicroscopy.shoola.env.data.model.appdata.WindowsApplicationDataExtractor.java

/**
 * Gets the system icon for the application
 * //from ww w .  j  ava2 s  . c om
 * @param file
 *            the file location of the application to retrieve the icon for
 * @return the icon associated with this application
 */
private Icon getSystemIconFor(File file) {
    Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file);

    return icon;
}

From source file:phex.gui.tabs.library.FileSystemTableCellRenderer.java

public FileSystemTableCellRenderer() {
    fsv = FileSystemView.getFileSystemView();
    shareFileIconMap = new LRUMap(100);
    grayMap = new LRUMap(100);

    defaultIcon = GUIRegistry.getInstance().getPlafIconPack().getIcon("Library.File");
    defaultGrayIcon = ImageFilterUtils.createGrayIcon(defaultIcon);
}

From source file:plugin.notes.gui.JIcon.java

/**
 *  Gets the icon of the JIcon object//from   w w w.j a v a2 s. c  o  m
 *
 *@param  file  File name that this represents
 *@return           The icon
 */
private Icon getIconForType(File file) {
    // TODO: this blows, it's hardcoded.  This needs to be in a properties file.
    // XXX ideally this should be use mime type
    String ext = file.getName().replaceFirst(".*\\.", "");
    String labelText = ' ' + file.getName() + ' ';

    if (file.getName().length() > 18) {
        labelText = ' ' + file.getName().substring(0, 15) + "... ";
    }
    label.setText(labelText);

    Icon ico = FileSystemView.getFileSystemView().getSystemIcon(file);
    button.setIcon(ico);
    button.setToolTipText(file.getName());
    return ico;
}

From source file:savant.agp.HTTPBrowser.java

/**
 * Use the Swing FileSystemView to get a system icon corresponding to the given
 * file./* ww  w  . j a  v  a2  s. c om*/
 *
 * @param f the remote file-name whose icon we want to retrieve
 * @return a system icon representing f
 */
private static Icon getIcon(String f) {
    try {
        if (f.contains("..") || f.contains("/")) {
            return FileSystemView.getFileSystemView().getSystemIcon(new File("."));
        } else {
            Icon i;
            if (isLikelyFormattedTrack(f)) {
                i = SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK);
            } else {
                File tmp = File.createTempFile("temp_icon.", "." + "txt");
                i = FileSystemView.getFileSystemView().getSystemIcon(tmp);
                tmp.delete();
            }
            return i;
        }
    } catch (IOException ex) {
        return null;
    }
}

From source file:savant.thousandgenomes.FTPBrowser.java

/**
 * Use the Swing FileSystemView to get a system icon corresponding to the given
 * file.//w w  w .  j  ava2s . com
 *
 * @param f the FTP entry whose icon we want to retrieve
 * @return a system icon representing f
 */
private static Icon getIcon(FTPFile f) {
    if (f == null || f.isDirectory()) {
        return FileSystemView.getFileSystemView().getSystemIcon(new File("."));
    } else {
        String name = f.getName();
        int ind = name.lastIndexOf(".");
        if (ind > 0) {
            String ext = name.substring(ind + 1);
            try {
                File tempFile = File.createTempFile("temp_icon.", "." + ext);
                Icon i = FileSystemView.getFileSystemView().getSystemIcon(tempFile);
                tempFile.delete();
                return i;
            } catch (IOException ex) {
            }
        }
    }
    return null;
}