sun.awt.shell.ShellFolder Java Examples
The following examples show how to use
sun.awt.shell.ShellFolder.
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 File: FileSystemView.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: GTKFileChooserUI.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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 #3
Source File: GTKFileChooserUI.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 File: GTKFileChooserUI.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: bug6840086.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: bug6550546.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: WindowsLookAndFeel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@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 #8
Source File: GTKFileChooserUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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 #9
Source File: GTKFileChooserUI.java From Bytecoder with Apache License 2.0 | 6 votes |
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 #10
Source File: BasicFileChooserUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: bug6550546.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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
Source File: FileSystemView.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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 #13
Source File: bug6840086.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 File: bug6840086.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #15
Source File: bug6840086.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #16
Source File: GTKFileChooserUI.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #17
Source File: GTKFileChooserUI.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #18
Source File: DarkFilePaneUIBridge.java From darklaf with MIT License | 6 votes |
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 #19
Source File: GTKFileChooserUI.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 File: bug6550546.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 File: bug6840086.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #22
Source File: BasicFileChooserUI.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #23
Source File: bug6945316.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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(); } }
Example #24
Source File: GTKFileChooserUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 #25
Source File: bug4847375.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 #26
Source File: BasicFileChooserUI.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void changeDirectory(File dir) { JFileChooser fc = getFileChooser(); // Traverse shortcuts on Windows if (dir != null && FilePane.usesShellFolder(fc)) { try { ShellFolder shellFolder = ShellFolder.getShellFolder(dir); if (shellFolder.isLink()) { File linkedTo = shellFolder.getLinkLocation(); // If linkedTo is null we try to use dir if (linkedTo != null) { if (fc.isTraversable(linkedTo)) { dir = linkedTo; } else { return; } } else { dir = shellFolder; } } } catch (FileNotFoundException ex) { return; } } fc.setCurrentDirectory(dir); if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES && fc.getFileSystemView().isFileSystem(dir)) { setFileName(dir.getAbsolutePath()); } }
Example #27
Source File: FileSystemView.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Throws {@code FileNotFoundException} if file not found or current thread was interrupted */ ShellFolder getShellFolder(File f) throws FileNotFoundException { if (!(f instanceof ShellFolder) && !(f instanceof FileSystemRoot) && isFileSystemRoot(f)) { f = createFileSystemRoot(f); } try { return ShellFolder.getShellFolder(f); } catch (InternalError e) { System.err.println("FileSystemView.getShellFolder: f="+f); e.printStackTrace(); return null; } }
Example #28
Source File: FileSystemView.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns all root partitions on this system. For example, on * Windows, this would be the "Desktop" folder, while on DOS this * would be the A: through Z: drives. * * @return an array of {@code File} objects representing all root partitions * on this system */ public File[] getRoots() { // Don't cache this array, because filesystem might change File[] roots = (File[])ShellFolder.get("roots"); for (int i = 0; i < roots.length; i++) { if (isFileSystemRoot(roots[i])) { roots[i] = createFileSystemRoot(roots[i]); } } return roots; }
Example #29
Source File: FileList.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private ShellFolder getShellFolder(File f) { try { return ShellFolder.getShellFolder(f); } catch (FileNotFoundException | InternalError e) { return null; } }
Example #30
Source File: bug6945316.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); } }