类sun.awt.shell.ShellFolder源码实例Demo

下面列出了怎么用sun.awt.shell.ShellFolder的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: darklaf   文件: DarkFilePaneUIBridge.java
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;
    }
}
 
源代码2 项目: jdk8u-dev-jdk   文件: WindowsLookAndFeel.java
@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;
}
 
源代码3 项目: openjdk-jdk9   文件: GTKFileChooserUI.java
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();
            }
        }
    }
}
 
源代码4 项目: jdk1.8-source-analysis   文件: GTKFileChooserUI.java
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();
            }
        }
    }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: BasicFileChooserUI.java
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();
            }
        }
    }
}
 
源代码6 项目: jdk8u_jdk   文件: bug6840086.java
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.");
}
 
源代码7 项目: Bytecoder   文件: FileSystemView.java
/**
 * 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());
    }
}
 
源代码8 项目: jdk8u-jdk   文件: bug6840086.java
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.");
}
 
源代码9 项目: TencentKona-8   文件: GTKFileChooserUI.java
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);
}
 
源代码10 项目: Bytecoder   文件: FileSystemView.java
/**
 * 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");
    }
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: bug6550546.java
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());
                }
            }
        }
    });
}
 
源代码12 项目: openjdk-jdk9   文件: BasicFileChooserUI.java
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();
            }
        }
    }
}
 
源代码13 项目: openjdk-jdk9   文件: bug6840086.java
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.");
}
 
源代码14 项目: jdk8u-jdk   文件: GTKFileChooserUI.java
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);
}
 
源代码15 项目: jdk8u60   文件: GTKFileChooserUI.java
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);
}
 
源代码16 项目: jdk8u60   文件: bug6840086.java
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.");
}
 
源代码17 项目: jdk8u60   文件: bug6550546.java
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());
                }
            }
        }
    });
}
 
源代码18 项目: Bytecoder   文件: GTKFileChooserUI.java
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();
            }
        }
    }
}
 
源代码19 项目: jdk8u-dev-jdk   文件: GTKFileChooserUI.java
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);
}
 
源代码20 项目: jdk8u-jdk   文件: bug6550546.java
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());
                }
            }
        }
    });
}
 
源代码21 项目: jdk8u-jdk   文件: GTKFileChooserUI.java
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);
}
 
源代码22 项目: openjdk-8-source   文件: bug6840086.java
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.");
}
 
源代码23 项目: darklaf   文件: DarkFilePaneUIBridge.java
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]);
}
 
源代码24 项目: jdk8u-jdk   文件: bug6798062.java
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;
}
 
源代码25 项目: hottub   文件: WindowsLookAndFeel.java
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);
}
 
源代码26 项目: jdk8u_jdk   文件: bug4847375.java
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;
    }
}
 
源代码27 项目: jdk8u-jdk   文件: GTKFileChooserUI.java
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);
}
 
源代码28 项目: dragonwell8_jdk   文件: WindowsLookAndFeel.java
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);
}
 
源代码29 项目: jdk8u_jdk   文件: GTKFileChooserUI.java
/**
 * 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);
}
 
源代码30 项目: openjdk-jdk9   文件: bug6945316.java
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();
    }
}
 
 类所在包
 类方法
 同包方法