Source Code Cross Referenced for WinFile.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » x » swing » filechooser » windows » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.x.swing.filechooser.windows 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Anton Avtamonov
020:         * @version $Revision$
021:         */package org.apache.harmony.x.swing.filechooser.windows;
022:
023:        import java.io.File;
024:        import java.io.FileFilter;
025:        import java.io.FilenameFilter;
026:        import java.util.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.LinkedList;
029:        import java.util.List;
030:
031:        import javax.swing.Icon;
032:
033:        import org.apache.harmony.awt.nativebridge.windows.Win32;
034:        import org.apache.harmony.x.swing.filechooser.PlatformFile;
035:
036:        import org.apache.harmony.awt.nativebridge.windows.WindowsConsts;
037:        import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
038:
039:        public class WinFile extends PlatformFile {
040:            private final Win32.ITEMIDLIST absoluteItemId;
041:
042:            private int description = -1;
043:            private String displayName;
044:
045:            public String getDisplayName() {
046:                Object[] parentInfo = getParentInfo();
047:                Win32.IShellFolder parentFolder = (Win32.IShellFolder) parentInfo[0];
048:                String result = WinFileManager.getManager()
049:                        .getChildFolderDisplayName(parentFolder,
050:                                (Win32.ITEMIDLIST) parentInfo[1],
051:                                WindowsConsts.SHGDN_FORADDRESSBAR);
052:                WinFileManager.getManager().release(parentFolder);
053:
054:                if (result != null) {
055:                    displayName = result;
056:                } else {
057:                    result = displayName;
058:                }
059:
060:                return result;
061:            }
062:
063:            public Win32.ITEMIDLIST getAbsoluteItemID() {
064:                return absoluteItemId;
065:            }
066:
067:            public Object[] getParentInfo() {
068:                return WinFileManager.getManager().getParentShellInfo(
069:                        absoluteItemId);
070:            }
071:
072:            public File getParentFile() {
073:                Win32.ITEMIDLIST parentItemId = WinFileManager.getManager()
074:                        .getParentItemId(absoluteItemId);
075:                return parentItemId != null ? WinFileManager.getManager()
076:                        .getWinFile(parentItemId) : null;
077:            }
078:
079:            public boolean isDirectory() {
080:                return getAttribute(WindowsDefs.SFGAO_FOLDER)
081:                        && !getAttribute(WindowsDefs.SFGAO_STREAM);
082:            }
083:
084:            public boolean isHidden() {
085:                return getAttribute(WindowsDefs.SFGAO_HIDDEN);
086:            }
087:
088:            public boolean exists() {
089:                return isDirectory() ? true : super .exists();
090:            }
091:
092:            public File[] listFiles() {
093:                List files = getContent();
094:                return (File[]) files.toArray(new File[files.size()]);
095:            }
096:
097:            public File[] listFiles(final FileFilter filter) {
098:                List result = getContent();
099:                for (Iterator it = result.iterator(); it.hasNext();) {
100:                    if (!filter.accept((File) it.next())) {
101:                        it.remove();
102:                    }
103:                }
104:
105:                return (File[]) result.toArray(new File[result.size()]);
106:            }
107:
108:            public File[] listFiles(final FilenameFilter filter) {
109:                List result = getContent();
110:                for (Iterator it = result.iterator(); it.hasNext();) {
111:                    File file = (File) it.next();
112:                    if (!filter.accept(file.getParentFile(), file.getName())) {
113:                        it.remove();
114:                    }
115:                }
116:
117:                return (File[]) result.toArray(new File[result.size()]);
118:            }
119:
120:            public boolean isFileSystem() {
121:                return getAttribute(WindowsDefs.SFGAO_FILESYSTEM);
122:            }
123:
124:            public boolean isRoot() {
125:                Object[] parentInfo = getParentInfo();
126:                Win32.IShellFolder parentFolder = (Win32.IShellFolder) parentInfo[0];
127:                boolean result = parentFolder != null;
128:                WinFileManager.getManager().release(parentFolder);
129:
130:                return result;
131:            }
132:
133:            public boolean isLink() {
134:                return getAttribute(WindowsDefs.SFGAO_LINK);
135:            }
136:
137:            public boolean isDrive() {
138:                return isCDROM() || isFixedDrive() || isNetDrive() || isRAM()
139:                        || isRemovable() || isFloppyDrive();
140:            }
141:
142:            public boolean isCDROM() {
143:                return getDescription() == WindowsDefs.SHDID_COMPUTER_CDROM;
144:            }
145:
146:            public String toString() {
147:                return isFileSystem() ? super .toString() : getDisplayName();
148:            }
149:
150:            public boolean isFixedDrive() {
151:                return getDescription() == WindowsDefs.SHDID_COMPUTER_FIXED;
152:            }
153:
154:            public boolean isNetDrive() {
155:                return getDescription() == WindowsDefs.SHDID_COMPUTER_NETDRIVE;
156:            }
157:
158:            public boolean isRAM() {
159:                return getDescription() == WindowsDefs.SHDID_COMPUTER_RAMDISK;
160:            }
161:
162:            public boolean isFloppyDrive() {
163:                return getDescription() == WindowsDefs.SHDID_COMPUTER_DRIVE35
164:                        || getDescription() == WindowsDefs.SHDID_COMPUTER_DRIVE525;
165:            }
166:
167:            public boolean isRemovable() {
168:                return getDescription() == WindowsDefs.SHDID_COMPUTER_REMOVABLE;
169:            }
170:
171:            public boolean isComputerNode() {
172:                return getDescription() == WindowsDefs.SHDID_NET_SERVER;
173:            }
174:
175:            public String getTypeName() {
176:                if (isDrive()) {
177:                    return getDisplayName();
178:                } else {
179:                    Win32.SHFILEINFOW fileInfo = getFileInfo();
180:                    return fileInfo.get_szTypeName().getString();
181:                }
182:            }
183:
184:            public Icon getIcon() {
185:                return null;
186:            }
187:
188:            WinFile(final String path, final Win32.ITEMIDLIST absoluteItemId) {
189:                super (path);
190:                this .absoluteItemId = absoluteItemId;
191:            }
192:
193:            private boolean getAttribute(final int flags) {
194:                Object[] parentInfo = getParentInfo();
195:                Win32.IShellFolder parentFolder = (Win32.IShellFolder) parentInfo[0];
196:                boolean result = (WinFileManager.getManager().getAttribute(
197:                        parentFolder, (Win32.ITEMIDLIST) parentInfo[1], flags) & flags) != 0;
198:                WinFileManager.getManager().release(parentFolder);
199:
200:                return result;
201:            }
202:
203:            private int getDescription() {
204:                if (description == -1) {
205:                    Object[] parentInfo = getParentInfo();
206:                    Win32.IShellFolder parentFolder = (Win32.IShellFolder) parentInfo[0];
207:                    description = WinFileManager.getManager().getDescription(
208:                            parentFolder, (Win32.ITEMIDLIST) parentInfo[1]);
209:                    WinFileManager.getManager().release(parentFolder);
210:                }
211:                return description;
212:            }
213:
214:            List getContent() {
215:                return getContent(WindowsConsts.SHCONTF_STORAGE
216:                        | WindowsConsts.SHCONTF_FOLDERS
217:                        | WindowsConsts.SHCONTF_INCLUDEHIDDEN);
218:            }
219:
220:            List getContent(final int contentType) {
221:                if (!isDirectory()) {
222:                    return new ArrayList();
223:                }
224:
225:                List result = new LinkedList();
226:                Win32.ITEMIDLIST[] children = WinFileManager.getManager()
227:                        .getShellContent(absoluteItemId, contentType);
228:                for (int i = 0; i < children.length; i++) {
229:                    WinFile file = WinFileManager.getManager().getWinFile(
230:                            children[i]);
231:                    if (!result.contains(file)
232:                            && (file.isFileSystem() || file
233:                                    .isFileSystemAncestor())) {
234:                        result.add(file);
235:                    }
236:                }
237:
238:                return result;
239:            }
240:
241:            private Win32.SHFILEINFOW getFileInfo() {
242:                Object[] parentInfo = getParentInfo();
243:                WinFileManager.getManager().release(
244:                        (Win32.IShellFolder) parentInfo[0]);
245:                return WinFileManager.getManager().getFileInfo(
246:                        (Win32.ITEMIDLIST) parentInfo[1],
247:                        WindowsDefs.SHGFI_TYPENAME
248:                                | WindowsDefs.SHGFI_DISPLAYNAME
249:                                | WindowsDefs.SHGFI_ICON
250:                                | WindowsDefs.SHGFI_ICONLOCATION);
251:            }
252:
253:            private boolean isFileSystemAncestor() {
254:                return getAttribute(WindowsDefs.SFGAO_FILESYSANCESTOR);
255:            }
256:        }
ww__w.__ja_v_a2s___._c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.