|
Java example source code file (Win32ShellFolderManager2.java)
The Win32ShellFolderManager2.java Java example source code/* * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package sun.awt.shell; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; import java.util.List; import java.util.concurrent.*; import static sun.awt.shell.Win32ShellFolder2.*; import sun.awt.OSInfo; // NOTE: This class supersedes Win32ShellFolderManager, which was removed // from distribution after version 1.4.2. /** * @author Michael Martak * @author Leif Samuelsson * @author Kenneth Russell * @since 1.4 */ public class Win32ShellFolderManager2 extends ShellFolderManager { static { // Load library here AccessController.doPrivileged( new java.security.PrivilegedAction<Void>() { public Void run() { System.loadLibrary("awt"); return null; } }); } public ShellFolder createShellFolder(File file) throws FileNotFoundException { try { return createShellFolder(getDesktop(), file); } catch (InterruptedException e) { throw new FileNotFoundException("Execution was interrupted"); } } static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file) throws FileNotFoundException, InterruptedException { long pIDL; try { pIDL = parent.parseDisplayName(file.getCanonicalPath()); } catch (IOException ex) { pIDL = 0; } if (pIDL == 0) { // Shouldn't happen but watch for it anyway throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found"); } try { return createShellFolderFromRelativePIDL(parent, pIDL); } finally { Win32ShellFolder2.releasePIDL(pIDL); } } static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, long pIDL) throws InterruptedException { // Walk down this relative pIDL, creating new nodes for each of the entries while (pIDL != 0) { long curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL); if (curPIDL != 0) { parent = new Win32ShellFolder2(parent, curPIDL); pIDL = Win32ShellFolder2.getNextPIDLEntry(pIDL); } else { // The list is empty if the parent is Desktop and pIDL is a shortcut to Desktop break; } } return parent; } private static final int VIEW_LIST = 2; private static final int VIEW_DETAILS = 3; private static final int VIEW_PARENTFOLDER = 8; private static final int VIEW_NEWFOLDER = 11; private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12]; private static Image getStandardViewButton(int iconIndex) { Image result = STANDARD_VIEW_BUTTONS[iconIndex]; if (result != null) { return result; } BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); img.setRGB(0, 0, 16, 16, Win32ShellFolder2.getStandardViewButton0(iconIndex), 0, 16); STANDARD_VIEW_BUTTONS[iconIndex] = img; return img; } // Special folders private static Win32ShellFolder2 desktop; private static Win32ShellFolder2 drives; private static Win32ShellFolder2 recent; private static Win32ShellFolder2 network; private static Win32ShellFolder2 personal; static Win32ShellFolder2 getDesktop() { if (desktop == null) { try { desktop = new Win32ShellFolder2(DESKTOP); } catch (IOException e) { // Ignore error } catch (InterruptedException e) { // Ignore error } } return desktop; } static Win32ShellFolder2 getDrives() { if (drives == null) { try { drives = new Win32ShellFolder2(DRIVES); } catch (IOException e) { // Ignore error } catch (InterruptedException e) { // Ignore error } } return drives; } static Win32ShellFolder2 getRecent() { if (recent == null) { try { String path = Win32ShellFolder2.getFileSystemPath(RECENT); if (path != null) { recent = createShellFolder(getDesktop(), new File(path)); } } catch (InterruptedException e) { // Ignore error } catch (IOException e) { // Ignore error } } return recent; } static Win32ShellFolder2 getNetwork() { if (network == null) { try { network = new Win32ShellFolder2(NETWORK); } catch (IOException e) { // Ignore error } catch (InterruptedException e) { // Ignore error } } return network; } static Win32ShellFolder2 getPersonal() { if (personal == null) { try { String path = Win32ShellFolder2.getFileSystemPath(PERSONAL); if (path != null) { Win32ShellFolder2 desktop = getDesktop(); personal = desktop.getChildByPath(path); if (personal == null) { personal = createShellFolder(getDesktop(), new File(path)); } if (personal != null) { personal.setIsPersonal(); } } } catch (InterruptedException e) { // Ignore error } catch (IOException e) { // Ignore error } } return personal; } private static File[] roots; /** * @param key a <code>String * "fileChooserDefaultFolder": * Returns a <code>File - the default shellfolder for a new filechooser * "roots": * Returns a <code>File[] - containing the root(s) of the displayable hierarchy * "fileChooserComboBoxFolders": * Returns a <code>File[] - an array of shellfolders representing the list to * show by default in the file chooser's combobox * "fileChooserShortcutPanelFolders": * Returns a <code>File[] - an array of shellfolders representing well-known * folders, such as Desktop, Documents, History, Network, Home, etc. * This is used in the shortcut panel of the filechooser on Windows 2000 * and Windows Me. * "fileChooserIcon <icon>": * Returns an <code>Image - icon can be ListView, DetailsView, UpFolder, NewFolder or * ViewMenu (Windows only). * "optionPaneIcon iconName": * Returns an <code>Image - icon from the system icon list * * @return An Object matching the key string. */ public Object get(String key) { if (key.equals("fileChooserDefaultFolder")) { File file = getPersonal(); if (file == null) { file = getDesktop(); } return file; } else if (key.equals("roots")) { // Should be "History" and "Desktop" ? if (roots == null) { File desktop = getDesktop(); if (desktop != null) { roots = new File[] { desktop }; } else { roots = (File[])super.get(key); } } return roots; } else if (key.equals("fileChooserComboBoxFolders")) { Win32ShellFolder2 desktop = getDesktop(); if (desktop != null) { ArrayList<File> folders = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java Win32ShellFolderManager2.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.