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
23 * questions.
24 */
25
26 package sun.awt.shell;
27
28 import java.awt.Image;
29 import java.awt.Toolkit;
30 import java.awt.image.BufferedImage;
31 import java.io.File;
32 import java.io.IOException;
33 import java.util.*;
34 import java.util.concurrent.*;
35 import javax.swing.SwingConstants;
36
37 // NOTE: This class supersedes Win32ShellFolder, which was removed from
38 // distribution after version 1.4.2.
39
40 /**
41 * Win32 Shell Folders
42 * <P>
43 * <BR>
44 * There are two fundamental types of shell folders : file system folders
45 * and non-file system folders. File system folders are relatively easy
46 * to deal with. Non-file system folders are items such as My Computer,
47 * Network Neighborhood, and the desktop. Some of these non-file system
48 * folders have special values and properties.
49 * <P>
50 * <BR>
51 * Win32 keeps two basic data structures for shell folders. The first
1112 *
1113 * @see sun.awt.shell.ShellFolder#compareTo(File)
1114 */
1115 public int compareTo(File file2) {
1116 if (!(file2 instanceof Win32ShellFolder2)) {
1117 if (isFileSystem() && !isSpecial()) {
1118 return super.compareTo(file2);
1119 } else {
1120 return -1; // Non-file shellfolders sort before files
1121 }
1122 }
1123 return Win32ShellFolderManager2.compareShellFolders(this, (Win32ShellFolder2) file2);
1124 }
1125
1126 // native constants from commctrl.h
1127 private static final int LVCFMT_LEFT = 0;
1128 private static final int LVCFMT_RIGHT = 1;
1129 private static final int LVCFMT_CENTER = 2;
1130
1131 public ShellFolderColumnInfo[] getFolderColumns() {
1132 return invoke(new Callable<ShellFolderColumnInfo[]>() {
1133 public ShellFolderColumnInfo[] call() {
1134 ShellFolderColumnInfo[] columns = doGetColumnInfo(getIShellFolder());
1135
1136 if (columns != null) {
1137 List<ShellFolderColumnInfo> notNullColumns =
1138 new ArrayList<ShellFolderColumnInfo>();
1139 for (int i = 0; i < columns.length; i++) {
1140 ShellFolderColumnInfo column = columns[i];
1141 if (column != null) {
1142 column.setAlignment(column.getAlignment() == LVCFMT_RIGHT
1143 ? SwingConstants.RIGHT
1144 : column.getAlignment() == LVCFMT_CENTER
1145 ? SwingConstants.CENTER
1146 : SwingConstants.LEADING);
1147
1148 column.setComparator(new ColumnComparator(Win32ShellFolder2.this, i));
1149
1150 notNullColumns.add(column);
1151 }
1152 }
1153 columns = new ShellFolderColumnInfo[notNullColumns.size()];
1154 notNullColumns.toArray(columns);
1155 }
1156 return columns;
1157 }
1158 });
1159 }
1160
1161 public Object getFolderColumnValue(final int column) {
1162 return invoke(new Callable<Object>() {
1163 public Object call() {
1164 return doGetColumnValue(getParentIShellFolder(), getRelativePIDL(), column);
1165 }
1166 });
1167 }
1168
1169 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1170 private native ShellFolderColumnInfo[] doGetColumnInfo(long iShellFolder2);
1171
1172 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1173 private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx);
1174
1175 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1176 private static native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx);
1177
1178
1179 public void sortChildren(final List<? extends File> files) {
1180 // To avoid loads of synchronizations with Invoker and improve performance we
1181 // synchronize the whole code of the sort method once
1182 invoke(new Callable<Void>() {
1183 public Void call() {
1184 Collections.sort(files, new ColumnComparator(Win32ShellFolder2.this, 0));
1185
1186 return null;
|
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
23 * questions.
24 */
25
26 package sun.awt.shell;
27
28 import java.awt.Image;
29 import java.awt.Toolkit;
30 import java.awt.image.BufferedImage;
31 import java.io.File;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34 import java.util.*;
35 import java.util.concurrent.*;
36 import javax.swing.SwingConstants;
37
38 // NOTE: This class supersedes Win32ShellFolder, which was removed from
39 // distribution after version 1.4.2.
40
41 /**
42 * Win32 Shell Folders
43 * <P>
44 * <BR>
45 * There are two fundamental types of shell folders : file system folders
46 * and non-file system folders. File system folders are relatively easy
47 * to deal with. Non-file system folders are items such as My Computer,
48 * Network Neighborhood, and the desktop. Some of these non-file system
49 * folders have special values and properties.
50 * <P>
51 * <BR>
52 * Win32 keeps two basic data structures for shell folders. The first
1113 *
1114 * @see sun.awt.shell.ShellFolder#compareTo(File)
1115 */
1116 public int compareTo(File file2) {
1117 if (!(file2 instanceof Win32ShellFolder2)) {
1118 if (isFileSystem() && !isSpecial()) {
1119 return super.compareTo(file2);
1120 } else {
1121 return -1; // Non-file shellfolders sort before files
1122 }
1123 }
1124 return Win32ShellFolderManager2.compareShellFolders(this, (Win32ShellFolder2) file2);
1125 }
1126
1127 // native constants from commctrl.h
1128 private static final int LVCFMT_LEFT = 0;
1129 private static final int LVCFMT_RIGHT = 1;
1130 private static final int LVCFMT_CENTER = 2;
1131
1132 public ShellFolderColumnInfo[] getFolderColumns() {
1133 ShellFolder library = resolveLibrary(this);
1134 if (library != null) return library.getFolderColumns();
1135 return invoke(new Callable<ShellFolderColumnInfo[]>() {
1136 public ShellFolderColumnInfo[] call() {
1137 ShellFolderColumnInfo[] columns = doGetColumnInfo(getIShellFolder());
1138
1139 if (columns != null) {
1140 List<ShellFolderColumnInfo> notNullColumns =
1141 new ArrayList<ShellFolderColumnInfo>();
1142 for (int i = 0; i < columns.length; i++) {
1143 ShellFolderColumnInfo column = columns[i];
1144 if (column != null) {
1145 column.setAlignment(column.getAlignment() == LVCFMT_RIGHT
1146 ? SwingConstants.RIGHT
1147 : column.getAlignment() == LVCFMT_CENTER
1148 ? SwingConstants.CENTER
1149 : SwingConstants.LEADING);
1150
1151 column.setComparator(new ColumnComparator(Win32ShellFolder2.this, i));
1152
1153 notNullColumns.add(column);
1154 }
1155 }
1156 columns = new ShellFolderColumnInfo[notNullColumns.size()];
1157 notNullColumns.toArray(columns);
1158 }
1159 return columns;
1160 }
1161 });
1162 }
1163
1164 public Object getFolderColumnValue(final int column) {
1165 if(isFileSystem()) {
1166 ShellFolder library = resolveLibrary(this);
1167 if (library != null) return library.getFolderColumnValue(column);
1168 }
1169 return invoke(new Callable<Object>() {
1170 public Object call() {
1171 return doGetColumnValue(getParentIShellFolder(), getRelativePIDL(), column);
1172 }
1173 });
1174 }
1175
1176 private static ShellFolder resolveLibrary(ShellFolder folder) {
1177 for (ShellFolder f = folder; f != null; f = f.parent) {
1178 if (!f.isFileSystem()) {
1179 if(f.getPath() != null && "Library".equals(f.getFolderType())) {
1180 try {
1181 return getShellFolder(new File(folder.getPath()));
1182 } catch (FileNotFoundException e) {
1183 }
1184 }
1185 break;
1186 }
1187 }
1188 return null;
1189 }
1190
1191 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1192 private native ShellFolderColumnInfo[] doGetColumnInfo(long iShellFolder2);
1193
1194 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1195 private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx);
1196
1197 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
1198 private static native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx);
1199
1200
1201 public void sortChildren(final List<? extends File> files) {
1202 // To avoid loads of synchronizations with Invoker and improve performance we
1203 // synchronize the whole code of the sort method once
1204 invoke(new Callable<Void>() {
1205 public Void call() {
1206 Collections.sort(files, new ColumnComparator(Win32ShellFolder2.this, 0));
1207
1208 return null;
|