javax.swing.filechooser.FileSystemView Java Examples

The following examples show how to use javax.swing.filechooser.FileSystemView. 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: App.java    From Notebook with Apache License 2.0 6 votes vote down vote up
/** ������ݷ�ʽ */
private void createShortcut() {
	 // ��ȡϵͳ����·��
       String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
       // ����ִ���ļ�·��
       String appPath = System.getProperty("user.dir");
       File exePath = new File(appPath).getParentFile();

       JShellLink link = new JShellLink();
       link.setFolder(desktop);
       link.setName("Notebook.exe");
       link.setPath(exePath.getAbsolutePath() + File.separator + "Notebook.exe");
       // link.setArguments("form");
       link.save();
       System.out.println("======== create success ========");
}
 
Example #2
Source File: bug6484091.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #3
Source File: bug6484091.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #4
Source File: bug6484091.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #5
Source File: PlotImageServiceMock.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
static Image getImageSWT(File file) {
    ImageIcon systemIcon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon(file);
    if (systemIcon == null) // Happens when file does not exist
        return null;
    java.awt.Image image = systemIcon.getImage();
    if (image instanceof BufferedImage) {
        return new Image(Display.getDefault(), convertToSWT((BufferedImage)image));
    }
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bufferedImage.createGraphics();
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    return new Image(Display.getDefault(), convertToSWT(bufferedImage));
}
 
Example #6
Source File: BaseFileObjectTestHid.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testNormalizeDrivesOnWindows48681 () {
    if ((Utilities.isWindows () || (Utilities.getOperatingSystem () == Utilities.OS_OS2))) {
        File[] roots = File.listRoots();
        for (int i = 0; i < roots.length; i++) {
            File file = roots[i];
            if (FileSystemView.getFileSystemView().isFloppyDrive(file) || !file.exists()) {
                continue;
            }
            File normalizedFile = FileUtil.normalizeFile(file);
            File normalizedFile2 = FileUtil.normalizeFile(new File (file, "."));
            
            assertEquals (normalizedFile.getPath(), normalizedFile2.getPath());
        }
        
    }
}
 
Example #7
Source File: DesktopUtils.java    From WorldPainter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the default documents folder of the current user.
 *
 * @return The default documents folder of the current user, or the user's
 *     home directory if a documents folder could not be determined.
 */
public static File getDocumentsFolder() {
    if (XDG.XDG_DOCUMENTS_DIR_FILE != null) {
        // Should cover most Linuxes
        return XDG.XDG_DOCUMENTS_DIR_FILE;
    }
    if (SystemUtils.isWindows()) {
        // Should cover Windows
        return FileSystemView.getFileSystemView().getDefaultDirectory();
    }
    File homeDir = new File(System.getProperty("user.home"));
    File potentialDocsDir = new File(homeDir, "Documents");
    if (potentialDocsDir.isDirectory()) {
        // Should cover Mac OS X, and possibly others we missed
        return potentialDocsDir;
    }
    return homeDir;
}
 
Example #8
Source File: WindowsStorageDeviceDetector.java    From usbdrivedetector with MIT License 6 votes vote down vote up
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 #9
Source File: DarkFilePaneUIBridge.java    From darklaf with MIT License 6 votes vote down vote up
protected void doDirectoryChanged(final PropertyChangeEvent e) {
    getDetailsTableModel().updateColumnInfo();

    JFileChooser fc = getFileChooser();
    FileSystemView fsv = fc.getFileSystemView();

    applyEdit();
    resetEditIndex();
    ensureIndexIsVisible(0);
    File currentDirectory = fc.getCurrentDirectory();
    if (currentDirectory != null) {
        if (!readOnly) {
            getNewFolderAction().setEnabled(canWrite(currentDirectory, getFileChooser()));
        }
        fileChooserUIAccessor.getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
    }
    if (list != null) {
        list.clearSelection();
    }
}
 
Example #10
Source File: bug6484091.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #11
Source File: bug6484091.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #12
Source File: bug6484091.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
Example #13
Source File: DarkFileChooserUIBridge.java    From darklaf with MIT License 6 votes vote down vote up
protected void doDirectoryChanged(final PropertyChangeEvent e) {
    JFileChooser fc = getFileChooser();
    FileSystemView fsv = fc.getFileSystemView();

    clearIconCache();
    File currentDirectory = fc.getCurrentDirectory();
    if (currentDirectory != null) {
        directoryComboBoxModel.addItem(currentDirectory);

        if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
            if (fsv.isFileSystem(currentDirectory)) {
                setFileName(currentDirectory.getPath());
            } else {
                setFileName(null);
            }
        }
    }
}
 
Example #14
Source File: Layout.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
/**
 * Figure out where the Raccoon homedir is
 * 
 * @return the top level raccoon folder
 */
private static File whereami() {
	// Does the user want the Raccoon dir to be in a custom place?
	String tmp = System.getProperty(HOMEDIRSYSPROP, null);
	if (tmp == null) {
		// Nope!
		return new File(FileSystemView.getFileSystemView().getDefaultDirectory(),
				"Raccoon");
	}

	// User wants a custom directory, check if suitable.
	File f = new File(tmp);
	if (f.exists() && !f.isDirectory()) {
		return new File(FileSystemView.getFileSystemView().getDefaultDirectory(),
				"Raccoon");
	}
	else {
		return f;
	}
}
 
Example #15
Source File: BreadcrumbFileSelector.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the selected path based of the specified file. If this file is
 * either <code>null</code> or not a directory, the home directory is
 * selected.
 *
 * @param dir Points to a directory to be selected.
 */
public void setPath(File dir) {
    final FileSystemView fsv = FileSystemView.getFileSystemView();

    if ((dir == null) || !dir.isDirectory()) {
        dir = fsv.getHomeDirectory();
    }

    ArrayList<BreadcrumbItem<File>> path = new ArrayList<>();
    File parent = dir;
    BreadcrumbItem<File> bci = new BreadcrumbItem<>(fsv.getSystemDisplayName(dir), dir);
    bci.setIcon(fsv.getSystemIcon(dir));
    path.add(bci);
    while (true) {
        parent = fsv.getParentDirectory(parent);
        if (parent == null) {
            break;
        }
        bci = new BreadcrumbItem<>(fsv.getSystemDisplayName(parent), parent);
        bci.setIcon(fsv.getSystemIcon(parent));
        path.add(bci);
    }
    Collections.reverse(path);
    this.setPath(path);
}
 
Example #16
Source File: MockController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
   * 实时磁盘监控
 * @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 #17
Source File: bug6570445.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());

    // The next line of code forces FileSystemView to request data from Win32ShellFolder2,
    // what causes an exception if a security manager installed (see the bug 6570445 description)
    FileSystemView.getFileSystemView().getRoots();

    System.out.println("Passed.");
}
 
Example #18
Source File: MockController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
   * 实时磁盘监控
 * @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 #19
Source File: DirectoryManager.java    From JuiceboxLegacy with MIT License 5 votes vote down vote up
/**
 * The user directory.  On Mac and Linux this should be the user home directory.  On Windows platforms this
 * is the "My Documents" directory.
 */
public static synchronized File getUserDirectory() {
    if (USER_DIRECTORY == null) {
        System.out.print("Fetching user directory... ");
        USER_DIRECTORY = FileSystemView.getFileSystemView().getDefaultDirectory();
        //Mostly for testing, in some environments USER_DIRECTORY can be null
        if (USER_DIRECTORY == null) {
            USER_DIRECTORY = getUserHome();
        }
    }
    return USER_DIRECTORY;
}
 
Example #20
Source File: ActuatorRedisController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * @功能:获取磁盘信息
 * @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 #21
Source File: bug8062561.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkDefaultDirectory() {
    if (System.getSecurityManager() == null) {
        throw new RuntimeException("Security manager is not set!");
    }

    File defaultDirectory = FileSystemView.getFileSystemView().
            getDefaultDirectory();
    if (defaultDirectory != null) {
        throw new RuntimeException("File system default directory is null!");
    }
}
 
Example #22
Source File: GedEntry.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public GedEntry(File f,Class<T> classe) throws IOException {
	this.classe=classe;
	setName(Files.getNameWithoutExtension(f.getName()));
	setExt(Files.getFileExtension(f.getName()));
	setContent(Files.toByteArray(f));
	setIsImage(ImageTools.isImage(f));
	setIcon(FileSystemView.getFileSystemView().getSystemIcon(f));
	setId(FileTools.checksum(f));
}
 
Example #23
Source File: WindowsDirectoryChooserUI.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
protected void loadChildren() {
  FileSystemView fsv = (FileSystemView)getUserObject();
  File[] roots = fsv.getRoots();
  if (roots != null) {
    Arrays.sort(roots);
    for (int i = 0, c = roots.length; i < c; i++) {
      add(new FileTreeNode(roots[i]));
    }
  }
}
 
Example #24
Source File: bug8062561.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkDefaultDirectory() {
    if (System.getSecurityManager() == null) {
        throw new RuntimeException("Security manager is not set!");
    }

    File defaultDirectory = FileSystemView.getFileSystemView().
            getDefaultDirectory();
    if (defaultDirectory != null) {
        throw new RuntimeException("File system default directory is null!");
    }
}
 
Example #25
Source File: bug8062561.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void checkDefaultDirectory() {
    if (System.getSecurityManager() == null) {
        throw new RuntimeException("Security manager is not set!");
    }

    File defaultDirectory = FileSystemView.getFileSystemView().
            getDefaultDirectory();
    if (defaultDirectory != null) {
        throw new RuntimeException("File system default directory is null!");
    }
}
 
Example #26
Source File: CommonUtils.java    From Swing9patch with Apache License 2.0 5 votes vote down vote up
/**
 * Preview a NinePatcg pictrure with Draw9Patch4Coffee tool.
 * 
 * @param is must not null
 * @param fileName must not null, just used for file name, suffix must be ".9.png"
 */
public static void previewNinePatchWithDraw9PatchTool(InputStream is, String fileName)
{
	MainFrame frame = new MainFrame(is, 
			// this file path just used for Draw9Patch4Coffee, 
			// and dosn't really read data from it, see Draw9Patch4Coffee API doc
			FileSystemView.getFileSystemView().getDefaultDirectory()
					.getAbsolutePath()+File.separator+fileName);
	frame.setDefaultCloseOperation(MainFrame.DISPOSE_ON_CLOSE);
	frame.setSize(700,500);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
}
 
Example #27
Source File: SnapFileChooser.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public SnapFileChooser(File currentDirectory, FileSystemView fsv) {
    super(currentDirectory, fsv);

    snapPreferences = Config.instance("snap").preferences();
    resizeHandler = new ResizeHandler();
    windowCloseHandler = new CloseHandler();
    init();
}
 
Example #28
Source File: JTreeAdapterBreadCrumbTest.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,
        boolean isSelected, boolean cellHasFocus) {
    File file = (File) value;
    this.setIcon(FileSystemView.getFileSystemView().getSystemIcon(file));
    this.setText(FileSystemView.getFileSystemView().getSystemDisplayName(file));
    return this;
}
 
Example #29
Source File: TreeAdapterBreadCrumbTest.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index,
        boolean isSelected, boolean cellHasFocus) {
    File file = (File) value;
    this.setIcon(FileSystemView.getFileSystemView().getSystemIcon(file));
    this.setText(FileSystemView.getFileSystemView().getSystemDisplayName(file));
    return this;
}
 
Example #30
Source File: LocalRoot.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static File getWindowsHomeFile() {
    File desktop = getWindowsDesktopFile();
    if (desktop == null) {
        return null;
    }
    IPath homePath = new Path(HOME_DIR);
    String homeFilename = homePath.lastSegment();
    File[] files = FileSystemView.getFileSystemView().getFiles(desktop, false);
    for (File file : files) {
        if (file.getName().equals(homeFilename)) {
            return file;
        }
    }
    return null;
}