Java Code Examples for javax.swing.filechooser.FileSystemView#getFileSystemView()
The following examples show how to use
javax.swing.filechooser.FileSystemView#getFileSystemView() .
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: BaseFileObjectTestHid.java From netbeans with Apache License 2.0 | 6 votes |
public void testValidRoots () throws Exception { assertNotNull(testedFS.getRoot()); assertTrue(testedFS.getRoot().isValid()); FileSystemView fsv = FileSystemView.getFileSystemView(); File[] roots = File.listRoots(); boolean validRoot = false; for (int i = 0; i < roots.length; i++) { FileObject root1 = FileUtil.toFileObject(roots[i]); if (!roots[i].exists()) { assertNull(root1); continue; } assertNotNull(roots[i].getAbsolutePath (),root1); assertTrue(root1.isValid()); if (testedFS == root1.getFileSystem()) { validRoot = true; } } assertTrue(validRoot); }
Example 2
Source File: WindowsStorageDeviceDetector.java From usbdrivedetector with MIT License | 6 votes |
private String getDeviceName(final String rootPath) { final File f = new File(rootPath); final FileSystemView v = FileSystemView.getFileSystemView(); String name = v.getSystemDisplayName(f); if (name != null) { int idx = name.lastIndexOf('('); if (idx != -1) { name = name.substring(0, idx); } name = name.trim(); if (name.isEmpty()) { name = null; } } return name; }
Example 3
Source File: bug8003399.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) > 0 ) { FileSystemView fsv = FileSystemView.getFileSystemView(); for (File file : fsv.getFiles(fsv.getHomeDirectory(), false)) { if(file.isDirectory()) { for (File file1 : fsv.getFiles(file, false)) { if(file1.isDirectory()) { String path = file1.getPath(); if(path.startsWith("::{") && path.toLowerCase().endsWith(".library-ms")) { throw new RuntimeException("Unconverted library link found"); } } } } } } System.out.println("ok"); }
Example 4
Source File: ActuatorRedisController.java From jeecg-boot-with-activiti with MIT License | 5 votes |
/** * @功能:获取磁盘信息 * @param request * @param response * @return */ @GetMapping("/queryDiskInfo") public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){ Result<List<Map<String,Object>>> res = new Result<>(); try { // 当前文件系统类 FileSystemView fsv = FileSystemView.getFileSystemView(); // 列出所有windows 磁盘 File[] fs = File.listRoots(); log.info("查询磁盘信息:"+fs.length+"个"); List<Map<String,Object>> list = new ArrayList<>(); for (int i = 0; i < fs.length; i++) { if(fs[i].getTotalSpace()==0) { continue; } Map<String,Object> map = new HashMap<>(); map.put("name", fsv.getSystemDisplayName(fs[i])); map.put("max", fs[i].getTotalSpace()); map.put("rest", fs[i].getFreeSpace()); map.put("restPPT", (fs[i].getTotalSpace()-fs[i].getFreeSpace())*100/fs[i].getTotalSpace()); list.add(map); log.info(map.toString()); } res.setResult(list); res.success("查询成功"); } catch (Exception e) { res.error500("查询失败"+e.getMessage()); } return res; }
Example 5
Source File: ActuatorRedisController.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * @功能:获取磁盘信息 * @param request * @param response * @return */ @GetMapping("/queryDiskInfo") public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){ Result<List<Map<String,Object>>> res = new Result<>(); try { // 当前文件系统类 FileSystemView fsv = FileSystemView.getFileSystemView(); // 列出所有windows 磁盘 File[] fs = File.listRoots(); log.info("查询磁盘信息:"+fs.length+"个"); List<Map<String,Object>> list = new ArrayList<>(); for (int i = 0; i < fs.length; i++) { if(fs[i].getTotalSpace()==0) { continue; } Map<String,Object> map = new HashMap<>(); map.put("name", fsv.getSystemDisplayName(fs[i])); map.put("max", fs[i].getTotalSpace()); map.put("rest", fs[i].getFreeSpace()); map.put("restPPT", (fs[i].getTotalSpace()-fs[i].getFreeSpace())*100/fs[i].getTotalSpace()); list.add(map); log.info(map.toString()); } res.setResult(list); res.success("查询成功"); } catch (Exception e) { res.error500("查询失败"+e.getMessage()); } return res; }
Example 6
Source File: MockController.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 实时磁盘监控 * @param request * @param response * @return */ @GetMapping("/queryDiskInfo") public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){ Result<List<Map<String,Object>>> res = new Result<>(); try { // 当前文件系统类 FileSystemView fsv = FileSystemView.getFileSystemView(); // 列出所有windows 磁盘 File[] fs = File.listRoots(); log.info("查询磁盘信息:"+fs.length+"个"); List<Map<String,Object>> list = new ArrayList<>(); for (int i = 0; i < fs.length; i++) { if(fs[i].getTotalSpace()==0) { continue; } Map<String,Object> map = new HashMap<>(); map.put("name", fsv.getSystemDisplayName(fs[i])); map.put("max", fs[i].getTotalSpace()); map.put("rest", fs[i].getFreeSpace()); map.put("restPPT", fs[i].getFreeSpace()*100/fs[i].getTotalSpace()); list.add(map); log.info(map.toString()); } res.setResult(list); res.success("查询成功"); } catch (Exception e) { res.error500("查询失败"+e.getMessage()); } return res; }
Example 7
Source File: MockController.java From teaching with Apache License 2.0 | 5 votes |
/** * 实时磁盘监控 * @param request * @param response * @return */ @GetMapping("/queryDiskInfo") public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){ Result<List<Map<String,Object>>> res = new Result<>(); try { // 当前文件系统类 FileSystemView fsv = FileSystemView.getFileSystemView(); // 列出所有windows 磁盘 File[] fs = File.listRoots(); log.info("查询磁盘信息:"+fs.length+"个"); List<Map<String,Object>> list = new ArrayList<>(); for (int i = 0; i < fs.length; i++) { if(fs[i].getTotalSpace()==0) { continue; } Map<String,Object> map = new HashMap<>(); map.put("name", fsv.getSystemDisplayName(fs[i])); map.put("max", fs[i].getTotalSpace()); map.put("rest", fs[i].getFreeSpace()); map.put("restPPT", fs[i].getFreeSpace()*100/fs[i].getTotalSpace()); list.add(map); log.info(map.toString()); } res.setResult(list); res.success("查询成功"); } catch (Exception e) { res.error500("查询失败"+e.getMessage()); } return res; }
Example 8
Source File: CommonTest.java From efo with MIT License | 5 votes |
@Test public void testGetDriver() { FileSystemView fsv = FileSystemView.getFileSystemView(); File[] fs = File.listRoots(); for (File f : fs) { System.out.println(fsv.getSystemDisplayName(f)); System.out.print("总大小" + Formatter.formatSize(f.getTotalSpace())); System.out.println("剩余" + Formatter.formatSize(f.getFreeSpace())); System.out.println(f.isDirectory()); } }
Example 9
Source File: FileSystemViewFileIcon.java From pumpernickel with MIT License | 5 votes |
@Override public Icon getIcon(File file) { FileSystemView fsv = FileSystemView.getFileSystemView(); Icon icon = fsv.getSystemIcon(file); if (icon != null) return icon; return null; }
Example 10
Source File: bug6868611.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 11
Source File: DiskUtils.java From spring-boot with Apache License 2.0 | 4 votes |
public static final FileSystemView getFileSystemView(){ // 当前文件系统类 return FileSystemView.getFileSystemView(); }
Example 12
Source File: bug6868611.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 13
Source File: bug6868611.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 14
Source File: bug6868611.java From hottub with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 15
Source File: bug6868611.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 16
Source File: bug6868611.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 17
Source File: bug6868611.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public void run() { FileSystemView fileSystemView = FileSystemView.getFileSystemView(); fileSystemView.getFiles(new File(dir), false); }
Example 18
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
private MainPanel() { super(new BorderLayout()); FileSystemView fileSystemView = FileSystemView.getFileSystemView(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultTreeModel treeModel = new DefaultTreeModel(root); Stream.of(fileSystemView.getRoots()).forEach(fileSystemRoot -> { DefaultMutableTreeNode node = new DefaultMutableTreeNode(new CheckBoxNode(fileSystemRoot, Status.DESELECTED)); root.add(node); Stream.of(fileSystemView.getFiles(fileSystemRoot, true)) .filter(File::isDirectory) .map(file -> new CheckBoxNode(file, Status.DESELECTED)) .map(DefaultMutableTreeNode::new) .forEach(node::add); }); treeModel.addTreeModelListener(new CheckBoxStatusUpdateListener()); JTree tree = new JTree(treeModel) { @Override public void updateUI() { setCellRenderer(null); setCellEditor(null); super.updateUI(); // ???#1: JDK 1.6.0 bug??? Nimbus LnF setCellRenderer(new FileTreeCellRenderer(fileSystemView)); setCellEditor(new CheckBoxNodeEditor(fileSystemView)); } }; tree.setRootVisible(false); tree.addTreeSelectionListener(new FolderSelectionListener(fileSystemView)); tree.setEditable(true); tree.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); tree.expandRow(0); // tree.setToggleClickCount(1); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(new JScrollPane(tree)); // // TEST // add(new JButton(new AbstractAction("test") { // private void searchTreeForCheckedNode(TreePath path) { // Object o = path.getLastPathComponent(); // if (!(o instanceof DefaultMutableTreeNode)) { // return; // } // DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; // o = node.getUserObject(); // if (!(o instanceof CheckBoxNode)) { // return; // } // CheckBoxNode check = (CheckBoxNode) o; // if (check.getStatus() == Status.SELECTED) { // System.out.println(check.getFile().toString()); // } else if (check.getStatus() == Status.INDETERMINATE && !node.isLeaf()) { // // Java 9: Enumeration<TreeNode> e = node.children(); // Enumeration<?> e = node.children(); // while (e.hasMoreElements()) { // searchTreeForCheckedNode(path.pathByAddingChild(e.nextElement())); // } // } // } // // @Override public void actionPerformed(ActionEvent e) { // System.out.println("------------------"); // searchTreeForCheckedNode(tree.getPathForRow(0)); // // DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); // // // Java 9: Enumeration<TreeNode> e = root.breadthFirstEnumeration(); // // Enumeration<?> e = root.breadthFirstEnumeration(); // // while (e.hasMoreElements()) { // // DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); // // CheckBoxNode check = (CheckBoxNode) node.getUserObject(); // // if (Objects.nonNull(check) && check.getStatus() == Status.SELECTED) { // // System.out.println(check.getFile().toString()); // // } // // } // } // }), BorderLayout.SOUTH); setPreferredSize(new Dimension(320, 240)); }
Example 19
Source File: BreadcrumbFileSelector.java From radiance with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a new breadcrumb bar file selector that uses the default file * system view. * * @param useNativeIcons If <code>true</code>, the path selectors will use native * icons. */ public BreadcrumbFileSelector(boolean useNativeIcons) { this(FileSystemView.getFileSystemView(), useNativeIcons); }
Example 20
Source File: FileUtil.java From qingyang with Apache License 2.0 | 2 votes |
/** * 获取硬盘的盘符 * * @return */ public static String getDriver() { List<Disk> disks = new ArrayList<Disk>(); // 获得当前文件系统类 FileSystemView systemView = FileSystemView.getFileSystemView(); // 桌面 Disk homeDisk = new Disk(); File file = systemView.getHomeDirectory(); homeDisk.setFileName(systemView.getSystemDisplayName(file)); homeDisk.setTotalSpace(FormetFileSize(file.getTotalSpace())); homeDisk.setFreeSpace(FormetFileSize(file.getFreeSpace())); homeDisk.setPath(file.getAbsolutePath()); disks.add(homeDisk); // 我的文档 Disk myDisk = new Disk(); File myFile = systemView.getDefaultDirectory(); myDisk.setFileName(systemView.getSystemDisplayName(myFile)); myDisk.setTotalSpace(FormetFileSize(myFile.getTotalSpace())); myDisk.setFreeSpace(FormetFileSize(myFile.getFreeSpace())); myDisk.setPath(myFile.getAbsolutePath()); disks.add(myDisk); // 列出所有的windows 磁盘 File[] files = File.listRoots(); for (int i = 0; i < files.length; i++) { Disk disk = new Disk(); disk.setFileName(systemView.getSystemDisplayName(files[i])); disk.setTotalSpace(FormetFileSize(files[i].getTotalSpace())); disk.setFreeSpace(FormetFileSize(files[i].getFreeSpace())); disk.setPath(files[i].getAbsolutePath()); disks.add(disk); } Gson gson = new Gson(); String jsonStr = gson.toJson(disks); return jsonStr; }