< prev index next >

src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 import java.util.concurrent.Callable;
  40 import java.util.concurrent.ExecutionException;
  41 import java.util.concurrent.Future;
  42 import java.util.concurrent.LinkedBlockingQueue;
  43 import java.util.concurrent.RejectedExecutionException;
  44 import java.util.concurrent.ThreadFactory;
  45 import java.util.concurrent.ThreadPoolExecutor;
  46 import java.util.concurrent.TimeUnit;
  47 import java.util.stream.Stream;
  48 
  49 import sun.awt.OSInfo;
  50 import sun.awt.util.ThreadGroupUtils;
  51 import sun.util.logging.PlatformLogger;
  52 
  53 import static sun.awt.shell.Win32ShellFolder2.DESKTOP;
  54 import static sun.awt.shell.Win32ShellFolder2.DRIVES;
  55 import static sun.awt.shell.Win32ShellFolder2.Invoker;

  56 import static sun.awt.shell.Win32ShellFolder2.MultiResolutionIconImage;
  57 import static sun.awt.shell.Win32ShellFolder2.NETWORK;
  58 import static sun.awt.shell.Win32ShellFolder2.PERSONAL;
  59 import static sun.awt.shell.Win32ShellFolder2.RECENT;

  60 // NOTE: This class supersedes Win32ShellFolderManager, which was removed
  61 //       from distribution after version 1.4.2.
  62 
  63 /**
  64  * @author Michael Martak
  65  * @author Leif Samuelsson
  66  * @author Kenneth Russell
  67  * @since 1.4
  68  */
  69 
  70 final class Win32ShellFolderManager2 extends ShellFolderManager {
  71 
  72     private static final PlatformLogger
  73             log = PlatformLogger.getLogger("sun.awt.shell.Win32ShellFolderManager2");
  74 
  75     static {
  76         // Load library here
  77         sun.awt.windows.WToolkit.loadLibraries();
  78     }
  79 


 127     private static final int VIEW_NEWFOLDER = 11;
 128 
 129     private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
 130 
 131     private static Image getStandardViewButton(int iconIndex) {
 132         Image result = STANDARD_VIEW_BUTTONS[iconIndex];
 133 
 134         if (result != null) {
 135             return result;
 136         }
 137 
 138         final int[] iconBits = Win32ShellFolder2
 139                 .getStandardViewButton0(iconIndex, true);
 140         if (iconBits != null) {
 141             // icons are always square
 142             final int size = (int) Math.sqrt(iconBits.length);
 143             final BufferedImage img =
 144                     new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
 145             img.setRGB(0, 0, size, size, iconBits, 0, size);
 146 
 147             STANDARD_VIEW_BUTTONS[iconIndex] = (size == 16)
 148                     ? img
 149                     : new MultiResolutionIconImage(16, img);
 150         }
 151 
 152         return STANDARD_VIEW_BUTTONS[iconIndex];
 153     }
 154 
 155     // Special folders
 156     private static Win32ShellFolder2 desktop;
 157     private static Win32ShellFolder2 drives;
 158     private static Win32ShellFolder2 recent;
 159     private static Win32ShellFolder2 network;
 160     private static Win32ShellFolder2 personal;
 161 
 162     static Win32ShellFolder2 getDesktop() {
 163         if (desktop == null) {
 164             try {
 165                 desktop = new Win32ShellFolder2(DESKTOP);
 166             } catch (final SecurityException ignored) {
 167                 // Ignore, the message may have sensitive information, not
 168                 // accessible other ways
 169             } catch (IOException | InterruptedException e) {


 391             return getStandardViewButton(iconIndex);
 392         } else if (key.startsWith("optionPaneIcon ")) {
 393             Win32ShellFolder2.SystemIcon iconType;
 394             if (key == "optionPaneIcon Error") {
 395                 iconType = Win32ShellFolder2.SystemIcon.IDI_ERROR;
 396             } else if (key == "optionPaneIcon Information") {
 397                 iconType = Win32ShellFolder2.SystemIcon.IDI_INFORMATION;
 398             } else if (key == "optionPaneIcon Question") {
 399                 iconType = Win32ShellFolder2.SystemIcon.IDI_QUESTION;
 400             } else if (key == "optionPaneIcon Warning") {
 401                 iconType = Win32ShellFolder2.SystemIcon.IDI_EXCLAMATION;
 402             } else {
 403                 return null;
 404             }
 405             return Win32ShellFolder2.getSystemIcon(iconType);
 406         } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
 407             String name = key.substring(key.indexOf(" ") + 1);
 408             try {
 409                 int i = Integer.parseInt(name);
 410                 if (i >= 0) {
 411                     return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));

 412                 }
 413             } catch (NumberFormatException ex) {
 414             }
 415         }
 416         return null;
 417     }
 418 
 419     private static File checkFile(File file) {
 420         SecurityManager sm = System.getSecurityManager();
 421         return (sm == null || file == null) ? file : checkFile(file, sm);
 422     }
 423 
 424     private static File checkFile(File file, SecurityManager sm) {
 425         try {
 426             sm.checkRead(file.getPath());
 427 
 428             if (file instanceof Win32ShellFolder2) {
 429                 Win32ShellFolder2 f = (Win32ShellFolder2)file;
 430                 if (f.isLink()) {
 431                     Win32ShellFolder2 link = (Win32ShellFolder2)f.getLinkLocation();


   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 import java.util.concurrent.Callable;
  40 import java.util.concurrent.ExecutionException;
  41 import java.util.concurrent.Future;
  42 import java.util.concurrent.LinkedBlockingQueue;
  43 import java.util.concurrent.RejectedExecutionException;
  44 import java.util.concurrent.ThreadFactory;
  45 import java.util.concurrent.ThreadPoolExecutor;
  46 import java.util.concurrent.TimeUnit;
  47 import java.util.stream.Stream;
  48 
  49 import sun.awt.OSInfo;
  50 import sun.awt.util.ThreadGroupUtils;
  51 import sun.util.logging.PlatformLogger;
  52 
  53 import static sun.awt.shell.Win32ShellFolder2.DESKTOP;
  54 import static sun.awt.shell.Win32ShellFolder2.DRIVES;
  55 import static sun.awt.shell.Win32ShellFolder2.Invoker;
  56 import static sun.awt.shell.Win32ShellFolder2.LARGE_ICON_SIZE;
  57 import static sun.awt.shell.Win32ShellFolder2.MultiResolutionIconImage;
  58 import static sun.awt.shell.Win32ShellFolder2.NETWORK;
  59 import static sun.awt.shell.Win32ShellFolder2.PERSONAL;
  60 import static sun.awt.shell.Win32ShellFolder2.RECENT;
  61 import static sun.awt.shell.Win32ShellFolder2.SMALL_ICON_SIZE;
  62 // NOTE: This class supersedes Win32ShellFolderManager, which was removed
  63 //       from distribution after version 1.4.2.
  64 
  65 /**
  66  * @author Michael Martak
  67  * @author Leif Samuelsson
  68  * @author Kenneth Russell
  69  * @since 1.4
  70  */
  71 
  72 final class Win32ShellFolderManager2 extends ShellFolderManager {
  73 
  74     private static final PlatformLogger
  75             log = PlatformLogger.getLogger("sun.awt.shell.Win32ShellFolderManager2");
  76 
  77     static {
  78         // Load library here
  79         sun.awt.windows.WToolkit.loadLibraries();
  80     }
  81 


 129     private static final int VIEW_NEWFOLDER = 11;
 130 
 131     private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
 132 
 133     private static Image getStandardViewButton(int iconIndex) {
 134         Image result = STANDARD_VIEW_BUTTONS[iconIndex];
 135 
 136         if (result != null) {
 137             return result;
 138         }
 139 
 140         final int[] iconBits = Win32ShellFolder2
 141                 .getStandardViewButton0(iconIndex, true);
 142         if (iconBits != null) {
 143             // icons are always square
 144             final int size = (int) Math.sqrt(iconBits.length);
 145             final BufferedImage img =
 146                     new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
 147             img.setRGB(0, 0, size, size, iconBits, 0, size);
 148 
 149             STANDARD_VIEW_BUTTONS[iconIndex] = (size == SMALL_ICON_SIZE)
 150                     ? img
 151                     : new MultiResolutionIconImage(SMALL_ICON_SIZE, img);
 152         }
 153 
 154         return STANDARD_VIEW_BUTTONS[iconIndex];
 155     }
 156 
 157     // Special folders
 158     private static Win32ShellFolder2 desktop;
 159     private static Win32ShellFolder2 drives;
 160     private static Win32ShellFolder2 recent;
 161     private static Win32ShellFolder2 network;
 162     private static Win32ShellFolder2 personal;
 163 
 164     static Win32ShellFolder2 getDesktop() {
 165         if (desktop == null) {
 166             try {
 167                 desktop = new Win32ShellFolder2(DESKTOP);
 168             } catch (final SecurityException ignored) {
 169                 // Ignore, the message may have sensitive information, not
 170                 // accessible other ways
 171             } catch (IOException | InterruptedException e) {


 393             return getStandardViewButton(iconIndex);
 394         } else if (key.startsWith("optionPaneIcon ")) {
 395             Win32ShellFolder2.SystemIcon iconType;
 396             if (key == "optionPaneIcon Error") {
 397                 iconType = Win32ShellFolder2.SystemIcon.IDI_ERROR;
 398             } else if (key == "optionPaneIcon Information") {
 399                 iconType = Win32ShellFolder2.SystemIcon.IDI_INFORMATION;
 400             } else if (key == "optionPaneIcon Question") {
 401                 iconType = Win32ShellFolder2.SystemIcon.IDI_QUESTION;
 402             } else if (key == "optionPaneIcon Warning") {
 403                 iconType = Win32ShellFolder2.SystemIcon.IDI_EXCLAMATION;
 404             } else {
 405                 return null;
 406             }
 407             return Win32ShellFolder2.getSystemIcon(iconType);
 408         } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
 409             String name = key.substring(key.indexOf(" ") + 1);
 410             try {
 411                 int i = Integer.parseInt(name);
 412                 if (i >= 0) {
 413                     return Win32ShellFolder2.getShell32Icon(i,
 414                          key.startsWith("shell32LargeIcon ")?LARGE_ICON_SIZE : SMALL_ICON_SIZE);
 415                 }
 416             } catch (NumberFormatException ex) {
 417             }
 418         }
 419         return null;
 420     }
 421 
 422     private static File checkFile(File file) {
 423         SecurityManager sm = System.getSecurityManager();
 424         return (sm == null || file == null) ? file : checkFile(file, sm);
 425     }
 426 
 427     private static File checkFile(File file, SecurityManager sm) {
 428         try {
 429             sm.checkRead(file.getPath());
 430 
 431             if (file instanceof Win32ShellFolder2) {
 432                 Win32ShellFolder2 f = (Win32ShellFolder2)file;
 433                 if (f.isLink()) {
 434                     Win32ShellFolder2 link = (Win32ShellFolder2)f.getLinkLocation();


< prev index next >