Java Code Examples for sun.awt.shell.ShellFolder

The following examples show how to use sun.awt.shell.ShellFolder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: darklaf   Source File: DarkFilePaneUIBridge.java    License: MIT License 6 votes vote down vote up
public static boolean canWrite(final File f, final JFileChooser chooser) {
    // Return false for non FileSystem files or if file doesn't exist.
    if (!f.exists()) {
        return false;
    }

    try {
        if (f instanceof ShellFolder) {
            return f.canWrite();
        } else {
            if (usesShellFolder(chooser)) {
                try {
                    return ShellFolder.getShellFolder(f).canWrite();
                } catch (FileNotFoundException ex) {
                    // File doesn't exist
                    return false;
                }
            } else {
                // Ordinary file
                return f.canWrite();
            }
        }
    } catch (SecurityException e) {
        return false;
    }
}
 
Example 2
@Override
public Object createValue(UIDefaults table) {
    if (icon == null) {
        Image image = (Image)ShellFolder.get(nativeImageName);
        if (image != null) {
            icon = new ImageIconUIResource(image);
        }
    }
    if (icon == null && fallbackName != null) {
        UIDefaults.LazyValue fallback = (UIDefaults.LazyValue)
                SwingUtilities2.makeIcon(WindowsLookAndFeel.class,
                    BasicLookAndFeel.class, fallbackName);
        icon = (Icon) fallback.createValue(table);
    }
    return icon;
}
 
Example 3
public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        int index = list.locationToIndex(e.getPoint());
        if (index >= 0) {
            File f = (File) list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if (getFileChooser().isTraversable(f)) {
                list.clearSelection();
                if (getFileChooser().getCurrentDirectory().equals(f)){
                    rescanCurrentDirectory(getFileChooser());
                } else {
                    getFileChooser().setCurrentDirectory(f);
                }
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example 4
Source Project: jdk1.8-source-analysis   Source File: GTKFileChooserUI.java    License: Apache License 2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        int index = list.locationToIndex(e.getPoint());
        if (index >= 0) {
            File f = (File) list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if (getFileChooser().isTraversable(f)) {
                list.clearSelection();
                if (getFileChooser().getCurrentDirectory().equals(f)){
                    rescanCurrentDirectory(getFileChooser());
                } else {
                    getFileChooser().setCurrentDirectory(f);
                }
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example 5
public void mouseClicked(MouseEvent evt) {
    // Note: we can't depend on evt.getSource() because of backward
    // compatibility
    if (list != null &&
        SwingUtilities.isLeftMouseButton(evt) &&
        (evt.getClickCount()%2 == 0)) {

        int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
        if (index >= 0) {
            File f = (File)list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if(getFileChooser().isTraversable(f)) {
                list.clearSelection();
                changeDirectory(f);
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example 6
Source Project: jdk8u_jdk   Source File: bug6840086.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 7
Source Project: Bytecoder   Source File: FileSystemView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 <code>File</code> object representing a directory or special folder
 * @param file a <code>File</code> object
 * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 * @since 1.4
 */
public boolean isParent(File folder, File file) {
    if (folder == null || file == null) {
        return false;
    } else if (folder instanceof ShellFolder) {
            File parent = file.getParentFile();
            if (parent != null && parent.equals(folder)) {
                return true;
            }
        File[] children = getFiles(folder, false);
        for (File child : children) {
            if (file.equals(child)) {
                return true;
            }
        }
        return false;
    } else {
        return folder.equals(file.getParentFile());
    }
}
 
Example 8
Source Project: jdk8u-jdk   Source File: bug6840086.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 9
public void actionPerformed(ActionEvent e) {
    if (isDirectorySelected()) {
        File dir = getDirectory();
        try {
            // Strip trailing ".."
            if (dir != null) {
                dir = ShellFolder.getNormalizedFile(dir);
            }
        } catch (IOException ex) {
            // Ok, use f as is
        }
        if (getFileChooser().getCurrentDirectory().equals(dir)) {
            directoryList.clearSelection();
            fileList.clearSelection();
            ListSelectionModel sm = fileList.getSelectionModel();
            if (sm instanceof DefaultListSelectionModel) {
                ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
                sm.setAnchorSelectionIndex(0);
            }
            rescanCurrentDirectory(getFileChooser());
            return;
        }
    }
    super.actionPerformed(e);
}
 
Example 10
Source Project: Bytecoder   Source File: FileSystemView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Icon for a file, directory, or folder as it would be displayed in
 * a system file browser. Example from Windows: the "M:\" directory
 * displays a CD-ROM icon.
 *
 * The default implementation gets information from the ShellFolder class.
 *
 * @param f a <code>File</code> object
 * @return an icon as it would be displayed by a native file chooser
 * @see JFileChooser#getIcon
 * @since 1.4
 */
public Icon getSystemIcon(File f) {
    if (f == null) {
        return null;
    }

    ShellFolder sf;

    try {
        sf = getShellFolder(f);
    } catch (FileNotFoundException e) {
        return null;
    }

    Image img = sf.getIcon(false);

    if (img != null) {
        return new ImageIcon(img, sf.getFolderType());
    } else {
        return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
    }
}
 
Example 11
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows, skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            File[] files = (File[]) ShellFolder.get("fileChooserComboBoxFolders");

            for (File file : files) {
                if (file instanceof ShellFolder && ((ShellFolder) file).isLink()) {
                    throw new RuntimeException("Link shouldn't be in FileChooser combobox, " + file.getPath());
                }
            }
        }
    });
}
 
Example 12
public void mouseClicked(MouseEvent evt) {
    // Note: we can't depend on evt.getSource() because of backward
    // compatibility
    if (list != null &&
        SwingUtilities.isLeftMouseButton(evt) &&
        (evt.getClickCount()%2 == 0)) {

        int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
        if (index >= 0) {
            File f = (File)list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if(getFileChooser().isTraversable(f)) {
                list.clearSelection();
                changeDirectory(f);
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example 13
Source Project: openjdk-jdk9   Source File: bug6840086.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 14
Source Project: jdk8u-jdk   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (isDirectorySelected()) {
        File dir = getDirectory();
        try {
            // Strip trailing ".."
            if (dir != null) {
                dir = ShellFolder.getNormalizedFile(dir);
            }
        } catch (IOException ex) {
            // Ok, use f as is
        }
        if (getFileChooser().getCurrentDirectory().equals(dir)) {
            directoryList.clearSelection();
            fileList.clearSelection();
            ListSelectionModel sm = fileList.getSelectionModel();
            if (sm instanceof DefaultListSelectionModel) {
                ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
                sm.setAnchorSelectionIndex(0);
            }
            rescanCurrentDirectory(getFileChooser());
            return;
        }
    }
    super.actionPerformed(e);
}
 
Example 15
Source Project: jdk8u60   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (isDirectorySelected()) {
        File dir = getDirectory();
        try {
            // Strip trailing ".."
            if (dir != null) {
                dir = ShellFolder.getNormalizedFile(dir);
            }
        } catch (IOException ex) {
            // Ok, use f as is
        }
        if (getFileChooser().getCurrentDirectory().equals(dir)) {
            directoryList.clearSelection();
            fileList.clearSelection();
            ListSelectionModel sm = fileList.getSelectionModel();
            if (sm instanceof DefaultListSelectionModel) {
                ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
                sm.setAnchorSelectionIndex(0);
            }
            rescanCurrentDirectory(getFileChooser());
            return;
        }
    }
    super.actionPerformed(e);
}
 
Example 16
Source Project: jdk8u60   Source File: bug6840086.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 17
Source Project: jdk8u60   Source File: bug6550546.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows, skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            File[] files = (File[]) ShellFolder.get("fileChooserComboBoxFolders");

            for (File file : files) {
                if (file instanceof ShellFolder && ((ShellFolder) file).isLink()) {
                    throw new RuntimeException("Link shouldn't be in FileChooser combobox, " + file.getPath());
                }
            }
        }
    });
}
 
Example 18
Source Project: Bytecoder   Source File: GTKFileChooserUI.java    License: Apache License 2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        int index = list.locationToIndex(e.getPoint());
        if (index >= 0) {
            File f = (File) list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if (getFileChooser().isTraversable(f)) {
                list.clearSelection();
                if (getFileChooser().getCurrentDirectory().equals(f)){
                    rescanCurrentDirectory(getFileChooser());
                } else {
                    getFileChooser().setCurrentDirectory(f);
                }
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example 19
public void actionPerformed(ActionEvent e) {
    if (isDirectorySelected()) {
        File dir = getDirectory();
        try {
            // Strip trailing ".."
            if (dir != null) {
                dir = ShellFolder.getNormalizedFile(dir);
            }
        } catch (IOException ex) {
            // Ok, use f as is
        }
        if (getFileChooser().getCurrentDirectory().equals(dir)) {
            directoryList.clearSelection();
            fileList.clearSelection();
            ListSelectionModel sm = fileList.getSelectionModel();
            if (sm instanceof DefaultListSelectionModel) {
                ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
                sm.setAnchorSelectionIndex(0);
            }
            rescanCurrentDirectory(getFileChooser());
            return;
        }
    }
    super.actionPerformed(e);
}
 
Example 20
Source Project: jdk8u-jdk   Source File: bug6550546.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows, skipped.");

        return;
    }

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            File[] files = (File[]) ShellFolder.get("fileChooserComboBoxFolders");

            for (File file : files) {
                if (file instanceof ShellFolder && ((ShellFolder) file).isLink()) {
                    throw new RuntimeException("Link shouldn't be in FileChooser combobox, " + file.getPath());
                }
            }
        }
    });
}
 
Example 21
Source Project: jdk8u-jdk   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (isDirectorySelected()) {
        File dir = getDirectory();
        try {
            // Strip trailing ".."
            if (dir != null) {
                dir = ShellFolder.getNormalizedFile(dir);
            }
        } catch (IOException ex) {
            // Ok, use f as is
        }
        if (getFileChooser().getCurrentDirectory().equals(dir)) {
            directoryList.clearSelection();
            fileList.clearSelection();
            ListSelectionModel sm = fileList.getSelectionModel();
            if (sm instanceof DefaultListSelectionModel) {
                ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
                sm.setAnchorSelectionIndex(0);
            }
            rescanCurrentDirectory(getFileChooser());
            return;
        }
    }
    super.actionPerformed(e);
}
 
Example 22
Source Project: openjdk-8-source   Source File: bug6840086.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 23
Source Project: darklaf   Source File: DarkFilePaneUIBridge.java    License: MIT License 5 votes vote down vote up
protected Object getFileColumnValue(final File f, final int col) {
    if (col == COLUMN_SIZE) {
        return f.isDirectory() ? null : f.length();
    }
    return (col == COLUMN_FILENAME)
            ? f // always return the file itself for the 1st column
            : ShellFolder.getFolderColumnValue(f, columnMap[col]);
}
 
Example 24
Source Project: jdk8u-jdk   Source File: bug6798062.java    License: GNU General Public License v2.0 5 votes vote down vote up
private MyThread(int delay, String link) {
    this.delay = delay;

    ShellFolder linkFolder;

    try {
        linkFolder = ShellFolder.getShellFolder(new File(link));
    } catch (FileNotFoundException e) {
        e.printStackTrace();

        linkFolder = null;
    }

    this.link = linkFolder;
}
 
Example 25
Source Project: hottub   Source File: WindowsLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Object createValue(UIDefaults table) {
    if (nativeImage != null) {
        Image image = (Image)ShellFolder.get(nativeImage);
        if (image != null) {
            return new ImageIcon(image);
        }
    }
    return SwingUtilities2.makeIcon(getClass(),
                                    WindowsLookAndFeel.class,
                                    resource);
}
 
Example 26
Source Project: jdk8u_jdk   Source File: bug4847375.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ShellFolder getWin32Folder(String getterName) {
    try {
        Class win32ShellFolderManager2 = Class.forName("sun.awt.shell.Win32ShellFolderManager2");

        Method method = win32ShellFolderManager2.getDeclaredMethod(getterName);
        method.setAccessible(true);

        return (ShellFolder) method.invoke(null);
    } catch (Exception e) {
        fail("Cannot call '" + getterName + "' in the Win32ShellFolderManager2 class", e);

        return null;
    }
}
 
Example 27
Source Project: jdk8u-jdk   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void doDirectoryChanged(PropertyChangeEvent e) {
    directoryList.clearSelection();
    ListSelectionModel sm = directoryList.getSelectionModel();
    if (sm instanceof DefaultListSelectionModel) {
        ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
        sm.setAnchorSelectionIndex(0);
    }
    fileList.clearSelection();
    sm = fileList.getSelectionModel();
    if (sm instanceof DefaultListSelectionModel) {
        ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
        sm.setAnchorSelectionIndex(0);
    }

    File currentDirectory = getFileChooser().getCurrentDirectory();
    if (currentDirectory != null) {
        try {
            setDirectoryName(ShellFolder.getNormalizedFile((File)e.getNewValue()).getPath());
        } catch (IOException ioe) {
            setDirectoryName(((File)e.getNewValue()).getAbsolutePath());
        }
        if ((getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) && !getFileChooser().isMultiSelectionEnabled()) {
            setFileName(pathField.getText());
        }
        directoryComboBoxModel.addItem(currentDirectory);
        directoryListModel.directoryChanged();
    }
    super.doDirectoryChanged(e);
}
 
Example 28
public Object createValue(UIDefaults table) {
    if (nativeImage != null) {
        Image image = (Image)ShellFolder.get(nativeImage);
        if (image != null) {
            return new ImageIcon(image);
        }
    }
    return SwingUtilities2.makeIcon(getClass(),
                                    WindowsLookAndFeel.class,
                                    resource);
}
 
Example 29
Source Project: jdk8u_jdk   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds the directory to the model and sets it to be selected,
 * additionally clears out the previous selected directory and
 * the paths leading up to it, if any.
 */
private void addItem(File directory) {

    if (directory == null) {
        return;
    }

    int oldSize = directories.size();
    directories.clear();
    if (oldSize > 0) {
        fireIntervalRemoved(this, 0, oldSize);
    }

    // Get the canonical (full) path. This has the side
    // benefit of removing extraneous chars from the path,
    // for example /foo/bar/ becomes /foo/bar
    File canonical;
    try {
        canonical = fsv.createFileObject(ShellFolder.getNormalizedFile(directory).getPath());
    } catch (IOException e) {
        // Maybe drive is not ready. Can't abort here.
        canonical = directory;
    }

    // create File instances of each directory leading up to the top
    File f = canonical;
    do {
        directories.add(f);
    } while ((f = f.getParentFile()) != null);
    int newSize = directories.size();
    if (newSize > 0) {
        fireIntervalAdded(this, 0, newSize);
    }
    setSelectedItem(canonical);
}
 
Example 30
Source Project: openjdk-jdk9   Source File: bug6945316.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test is suitable only for Windows OS. Skipped.");

        return;
    }

    // Init toolkit because it shouldn't be interrupted while initialization
    Toolkit.getDefaultToolkit();

    // Init the sun.awt.shell.Win32ShellFolderManager2.drives field
    ShellFolder.get("fileChooserComboBoxFolders");

    // To get NPE the path must obey the following rules:
    // path.length() == 3 && path.charAt(1) == ':'
    final File tempFile = new File("c:\\");

    for (int i = 0; i < 10000; i++) {
        final CountDownLatch countDownLatch = new CountDownLatch(1);

        final Thread thread = new Thread() {
            public void run() {
                countDownLatch.countDown();

                ShellFolder.isFileSystemRoot(tempFile);
            }
        };

        thread.start();

        countDownLatch.await();

        thread.interrupt();
    }
}