Package javax.swing.filechooser

Examples of javax.swing.filechooser.FileSystemView$AbstractFileSystemView


    private static final Logger logger = Logger.getLogger(
            LauncherStub.class.getCanonicalName());

    private static File getFileChooseDefaultDir() {
        JFileChooser chooser = new JFileChooser();
        FileSystemView fsv = chooser.getFileSystemView();
        return fsv.getDefaultDirectory();
    }
View Full Code Here


      Console.writeOutput(e + Console.nl); Console.nl();
    }
  }
 
  public void system(String s){ //advanced system info
    FileSystemView v = FileSystemView.getFileSystemView();
    File f = new File(s + ":\\");
    String d;
    String d1 = v.getSystemDisplayName(f);
    String d2 = v.getSystemTypeDescription(f);
    Pattern p = Pattern.compile(" \\([A-Za-z]:\\)");
    Matcher m = p.matcher(d1);
        if (m.find()){
          d = d1.substring( 0, m.start() ).trim();
        }
View Full Code Here

   *            Points to a directory to be selected.
   */
  public void setPath(File dir) {
    // System.out.println(dir.getAbsolutePath());

    FileSystemView fsv = FileSystemView.getFileSystemView();

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

      ArrayList<BreadcrumbItem<File>> path = new ArrayList<BreadcrumbItem<File>>();
      File parent = dir;
      BreadcrumbItem<File> bci = new BreadcrumbItem<File>(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<File>(
            fsv.getSystemDisplayName(parent), parent);
        bci.setIcon(fsv.getSystemIcon(parent));
        path.add(bci);
      }
      Collections.reverse(path);
      this.setPath(path);
    }
View Full Code Here

   */
  public void setFileSystemView(FileSystemView fsv)
  {
    if (this.fsv != fsv)
      {
        FileSystemView old = this.fsv;
        this.fsv = fsv;
        firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, old, this.fsv);
      }
  }
View Full Code Here

    /**
     * Returns file system view that allows remote browsing.
     */
    private FileSystemView getFileSystemView(final Host host, final String directory) {
        final HardwareInfo thisClass = this;
        return new FileSystemView() {
            @Override
            public File[] getRoots() {
                return new LinuxFile[]{getLinuxDir("/", host)};
            }

View Full Code Here

     *
     * @return list of local drives and partitions
     */
    public static List<LocalDisk> getPartitions() {
        List<LocalDisk> drives = new ArrayList<>();
        FileSystemView fsv = FileSystemView.getFileSystemView();
        if (PlatformUtil.isWindowsOS()) {
            File[] f = File.listRoots();
            for (File f1 : f) {
                String name = fsv.getSystemDisplayName(f1);
                // Check if it is a drive, readable, and not mapped to the network
                if (f1.canRead() && !name.contains("\\\\") && (fsv.isDrive(f1) || fsv.isFloppyDrive(f1))) {
                    String path = f1.getPath();
                    String diskPath = "\\\\.\\" + path.substring(0, path.length() - 1);
                    if (canReadDrive(diskPath)) {
                        drives.add(new LocalDisk(fsv.getSystemDisplayName(f1), diskPath, f1.getTotalSpace()));
                    }
                }
            }
        } else {
            File dev = new File("/dev/");
View Full Code Here

    buttonPanel = null;
  }

  public void installComponents(JFileChooser fc)
  {
    FileSystemView fsv = fc.getFileSystemView();

    fc.setBorder(new EmptyBorder(12, 12, 11, 11));
    fc.setLayout(new BorderLayout(0, 11));

    // ********************************* //
    // **** Construct the top panel **** //
    // ********************************* //

    // Directory manipulation buttons
    JToolBar bar = new JToolBar();

    // Add the top panel to the fileChooser
    fc.add(bar, BorderLayout.NORTH);

    // ComboBox Label
    lookInLabel = new JLabel(lookInLabelText);
    lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
    bar.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);

    // CurrentDir ComboBox
    directoryComboBox = new JComboBox();
    directoryComboBox.putClientProperty("JComboBox.lightweightKeyboardNavigation", "Lightweight");
    lookInLabel.setLabelFor(directoryComboBox);
    directoryComboBoxModel = createDirectoryComboBoxModel(fc);
    directoryComboBox.setModel(directoryComboBoxModel);
    directoryComboBox.addActionListener(directoryComboBoxAction);
    directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
    directoryComboBox.setMaximumRowCount(8);

    bar.add(directoryComboBox, BorderLayout.CENTER);

    // Up Button
    JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
    upFolderButton.setText(null);
    upFolderButton.setIcon(upFolderIcon);
    upFolderButton.setToolTipText(upFolderToolTipText);
    upFolderButton.getAccessibleContext().setAccessibleName(upFolderAccessibleName);
    upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    upFolderButton.setMargin(shrinkwrap);

    bar.add(upFolderButton);
    bar.add(Box.createRigidArea(hstrut5));

    // Home Button
    File homeDir = fsv.getHomeDirectory();
    String toolTipText = homeFolderToolTipText;
    if (fsv.isRoot(homeDir))
    {
      toolTipText = getFileView(fc).getName(homeDir);

      // Probably "Desktop".
    }

    JButton b = new JButton(homeFolderIcon);
    b.setToolTipText(toolTipText);
    b.getAccessibleContext().setAccessibleName(homeFolderAccessibleName);
    b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    b.setMargin(shrinkwrap);

    b.addActionListener(getGoHomeAction());
    bar.add(b);
    bar.add(Box.createRigidArea(hstrut5));

    // New Directory Button
    b = new JButton(getNewFolderAction());
    b.setText(null);
    b.setIcon(newFolderIcon);
    b.setToolTipText(newFolderToolTipText);
    b.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
    b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    b.setMargin(shrinkwrap);

    bar.add(b);
    bar.add(Box.createRigidArea(hstrut5));

    // View button group
    ButtonGroup viewButtonGroup = new ButtonGroup();

    class ViewButtonListener
      implements ActionListener
    {
      JFileChooser chooser;

      ViewButtonListener(JFileChooser chooser)
      {
        this.chooser = chooser;
      }

      public void actionPerformed(ActionEvent e)
      {
        JToggleButton b = (JToggleButton) e.getSource();
        JPanel oldViewPanel = currentViewPanel;

        if (b == detailsViewButton)
        {
          if (detailsViewPanel == null)
          {
            detailsViewPanel = createDetailsView(chooser);
            detailsViewPanel.setPreferredSize(LIST_PREF_SIZE);
          }
          currentViewPanel = detailsViewPanel;
        }
        else
        {
          currentViewPanel = listViewPanel;
        }
        if (currentViewPanel != oldViewPanel)
        {
          centerPanel.remove(oldViewPanel);
          centerPanel.add(currentViewPanel, BorderLayout.CENTER);
          centerPanel.revalidate();
          centerPanel.repaint();
        }
      }
    }

    ViewButtonListener viewButtonListener = new ViewButtonListener(fc);

    // List Button
    listViewButton = new JToggleButton(listViewIcon);
    listViewButton.setToolTipText(listViewButtonToolTipText);
    listViewButton.getAccessibleContext().setAccessibleName(listViewButtonAccessibleName);
    listViewButton.setSelected(true);
    listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    listViewButton.setMargin(shrinkwrap);
    listViewButton.addActionListener(viewButtonListener);
    bar.add(listViewButton);
    viewButtonGroup.add(listViewButton);

    // Details Button
    detailsViewButton = new JToggleButton(detailsViewIcon);
    detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
    detailsViewButton.getAccessibleContext().setAccessibleName(detailsViewButtonAccessibleName);
    detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    detailsViewButton.setMargin(shrinkwrap);
    detailsViewButton.addActionListener(viewButtonListener);
    bar.add(detailsViewButton);
    viewButtonGroup.add(detailsViewButton);

    // Use ShellFolder class to populate combobox only if
    // FileSystemView.getRoots() returns one folder and that is
    // the same as the first item in the ShellFolder combobox list.
    {
      useShellFolder = false;
      File [] roots = fsv.getRoots();
      if (roots != null && roots.length == 1)
      {
        File [] cbFolders = (File []) ShellFolder.get("fileChooserComboBoxFolders");
        if (cbFolders != null && cbFolders.length > 0 && roots [0] == cbFolders [0])
        {
View Full Code Here

      public void valueChanged(ListSelectionEvent e)
      {
        if (!e.getValueIsAdjusting())
        {
          JFileChooser chooser = getFileChooser();
          FileSystemView fsv = chooser.getFileSystemView();
          JList list = (JList) e.getSource();

          if (chooser.isMultiSelectionEnabled())
          {
            File [] files = null;
            Object [] objects = list.getSelectedValues();
            if (objects != null)
            {
              if (objects.length == 1 && ((File) objects [0]).isDirectory() && chooser.isTraversable(((File) objects [0])) && (chooser.getFileSelectionMode() == JFileChooser.FILES_ONLY || !fsv.isFileSystem(((File) objects [0]))))
              {
                setDirectorySelected(true);
                setDirectory(((File) objects [0]));
              }
              else
              {
                files = new File [objects.length];
                int j = 0;
                for (int i = 0; i < objects.length; i++)
                {
                  File f = (File) objects [i];
                  if ((chooser.isFileSelectionEnabled() && f.isFile()) || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && f.isDirectory()))
                  {
                    files [j++] = f;
                  }
                }
                if (j == 0)
                {
                  files = null;
                }
                else if (j < objects.length)
                {
                  File [] tmpFiles = new File [j];
                  System.arraycopy(files, 0, tmpFiles, 0, j);
                  files = tmpFiles;
                }
                setDirectorySelected(false);
              }
            }
            chooser.setSelectedFiles(files);
          }
          else
          {
            File file = (File) list.getSelectedValue();
            if (file != null && file.isDirectory() && chooser.isTraversable(file) && (chooser.getFileSelectionMode() == JFileChooser.FILES_ONLY || !fsv.isFileSystem(file)))
            {
              setDirectorySelected(true);
              setDirectory(file);
              chooser.setSelectedFile(null);
            }
View Full Code Here

          {
            newFileName = newDisplayName + oldFileName.substring(i2);
          }

          // rename
          FileSystemView fsv = chooser.getFileSystemView();
          File f2 = fsv.createFileObject(f.getParentFile(), newFileName);
          if (getModel().renameFile(f, f2))
          {
            if (fsv.isParent(chooser.getCurrentDirectory(), f2))
            {
              if (chooser.isMultiSelectionEnabled())
              {
                chooser.setSelectedFiles(new File [] { f2 });
              }
View Full Code Here

  }

  private void doDirectoryChanged(PropertyChangeEvent e)
  {
    JFileChooser fc = getFileChooser();
    FileSystemView fsv = fc.getFileSystemView();

    applyEdit();
    resetEditIndex();
    clearIconCache();
    listSelectionModel.clearSelection();
    ensureIndexIsVisible(0);
    File currentDirectory = fc.getCurrentDirectory();
    if (currentDirectory != null)
    {
      directoryComboBoxModel.addItem(currentDirectory);

      // Currently can not create folder in the Desktop folder on Windows
      // (ShellFolder limitation)
      getNewFolderAction().setEnabled(fsv.isFileSystem(currentDirectory) && currentDirectory.canWrite());
      getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));

      if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled() && fsv.isFileSystem(currentDirectory))
      {
        setFileName(currentDirectory.getPath());
      }
      else
      {
View Full Code Here

TOP

Related Classes of javax.swing.filechooser.FileSystemView$AbstractFileSystemView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.