Java Code Examples for sun.swing.FilePane

The following examples show how to use sun.swing.FilePane. These examples are extracted from open source projects. 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 Project: darklaf   Source File: DarkFileChooserUI.java    License: MIT License 6 votes vote down vote up
protected DarkFilePaneUIBridge createFilePane(final JFileChooser fileChooser) {
    DarkFilePaneUIBridge filePane = new DarkFilePane(new MetalFileChooserUIAccessor());
    fileChooser.addPropertyChangeListener(filePane);

    // ComboBox Label
    filePane.addPropertyChangeListener(e -> {
        if (KEY_VIEW_TYPE.equals(e.getPropertyName())) {
            int viewType = filePane.getViewType();
            switch (viewType) {
                case FilePane.VIEWTYPE_LIST :
                    listViewButton.setSelected(true);
                    break;

                case FilePane.VIEWTYPE_DETAILS :
                    detailsViewButton.setSelected(true);
                    break;
            }
        }
    });
    filePane.setPreferredSize(LIST_PREF_SIZE);
    return filePane;
}
 
Example 2
public void updateUI(){
    LookAndFeel old = UIManager.getLookAndFeel();
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (Throwable ex) {
        old = null;
    }

    super.updateUI();

    if(old != null){
        FilePane filePane = findFilePane(this);
        filePane.setViewType(FilePane.VIEWTYPE_DETAILS);
        filePane.setViewType(FilePane.VIEWTYPE_LIST);

        Color background = UIManager.getColor("Label.background");
        setBackground(background);
        setOpaque(true);

        try {
            UIManager.setLookAndFeel(old);
        }
        catch (UnsupportedLookAndFeelException ignored) {} // shouldn't get here
    }
}
 
Example 3
private static FilePane findFilePane(Container parent){
    for(Component comp: parent.getComponents()){
        if(FilePane.class.isInstance(comp)){
            return (FilePane)comp;
        }
        if(comp instanceof Container){
            Container cont = (Container)comp;
            if(cont.getComponentCount() > 0){
                FilePane found = findFilePane(cont);
                if (found != null) {
                    return found;
                }
            }
        }
    }

    return null;
}
 
Example 4
Source Project: darklaf   Source File: DarkFileChooserUI.java    License: MIT License 5 votes vote down vote up
protected JToggleButton createDetailsViewButton() {
    JToggleButton button = new TooltipAwareToggleButton(detailsViewIcon);
    setupButton(button, detailsViewButtonAccessibleName, detailsViewButtonToolTipText);
    Icon selectedDetailsViewIcon = UIManager.getIcon("FileChooser.detailsViewSelectedIcon");
    button.setSelectedIcon(selectedDetailsViewIcon);
    button.putClientProperty(DarkButtonUI.KEY_CORNER, AlignmentExt.RIGHT);
    button.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
    return button;
}
 
Example 5
Source Project: darklaf   Source File: DarkFileChooserUI.java    License: MIT License 5 votes vote down vote up
protected JToggleButton createListViewButton() {
    JToggleButton button = new TooltipAwareToggleButton(listViewIcon);
    setupButton(button, listViewButtonAccessibleName, listViewButtonToolTipText);
    Icon selectedListViewIcon = UIManager.getIcon("FileChooser.listViewSelectedIcon");
    button.setSelectedIcon(selectedListViewIcon);
    button.putClientProperty(DarkButtonUI.KEY_CORNER, AlignmentExt.LEFT);
    button.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
    button.setSelected(true);
    return button;
}
 
Example 6
Source Project: darklaf   Source File: DarkFilePaneUIBridge.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("serial") // anonymous class inside
public Action getNewFolderAction() {
    if (!readOnly && newFolderAction == null) {
        newFolderAction = new AbstractAction(newFolderActionLabelText) {
            protected Action basicNewFolderAction;

            // Initializer
            {
                putValue(Action.ACTION_COMMAND_KEY, FilePane.ACTION_NEW_FOLDER);

                File currentDirectory = getFileChooser().getCurrentDirectory();
                if (currentDirectory != null) {
                    setEnabled(canWrite(currentDirectory, getFileChooser()));
                }
            }

            public void actionPerformed(final ActionEvent ev) {
                if (basicNewFolderAction == null) {
                    basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
                }
                JFileChooser fc = getFileChooser();
                File oldFile = fc.getSelectedFile();
                basicNewFolderAction.actionPerformed(ev);
                File newFile = fc.getSelectedFile();
                if (newFile != null && !newFile.equals(oldFile) && newFile.isDirectory()) {
                    newFolderFile = newFile;
                }
            }
        };
    }
    return newFolderAction;
}
 
Example 7
Source Project: snap-desktop   Source File: SnapFileChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void initViewType() {
    FilePane filePane = findFilePane(this);
    if (filePane != null) {
        int viewType = snapPreferences.getInt(PREFERENCES_VIEW_TYPE, FilePane.VIEWTYPE_LIST);
        filePane.setViewType(viewType);
    }
}
 
Example 8
Source Project: snap-desktop   Source File: SnapFileChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
private FilePane findFilePane(Container root) {
    Component[] components = root.getComponents();
    for (Component component : components) {
        if (component instanceof FilePane) {
            return (FilePane) component;
        }
        if (component instanceof Container) {
            FilePane filePane = findFilePane((Container) component);
            if (filePane != null) {
                return filePane;
            }
        }
    }
    return null;
}
 
Example 9
Source Project: snap-desktop   Source File: SnapFileChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void windowClosed(WindowEvent e) {
    FilePane filePane = findFilePane(SnapFileChooser.this);
    if (filePane != null) {
        snapPreferences.putInt(PREFERENCES_VIEW_TYPE, filePane.getViewType());
        flushPreferences();
    }
}
 
Example 10
Source Project: darklaf   Source File: DarkFileChooserUIBridge.java    License: MIT License 4 votes vote down vote up
/**
 * Constructs an instance of {@code ActionMap}.
 *
 * @return an instance of {@code ActionMap}
 */
protected ActionMap createActionMap() {
    ActionMap map = new ActionMapUIResource();
    FilePane.addActionsToMap(map, filePane.getActions());
    return map;
}
 
Example 11
Source Project: darklaf   Source File: DarkFileChooserUIBridge.java    License: MIT License 4 votes vote down vote up
/**
 * Adds the directory to the model and sets it to be selected, additionally clears out the previous selected
 * directory and the paths leading up to it, if any.
 *
 * @param directory the directory
 */
protected void addItem(final File directory) {

    if (directory == null) {
        return;
    }

    boolean useShellFolder = FilePane.usesShellFolder(chooser);

    directories.clear();

    File[] baseFolders = (useShellFolder)
            ? (File[]) ShellFolder.get("fileChooserComboBoxFolders")
            : fsv.getRoots();
    directories.addAll(Arrays.asList(baseFolders));

    // Get the canonical (full) path. This has the side
    // benefit of removing extraneous chars from the path,
    // for example /foo/bar/ becomes /foo/bar
    File canonical;
    try {
        canonical = ShellFolder.getNormalizedFile(directory);
    } catch (IOException e) {
        // Maybe drive is not ready. Can't abort here.
        canonical = directory;
    }

    // create File instances of each directory leading up to the top
    try {
        File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
                : canonical;
        File f = sf;
        Vector<File> path = new Vector<>(10);
        do {
            path.addElement(f);
        } while ((f = f.getParentFile()) != null);

        int pathCount = path.size();
        // Insert chain at appropriate place in vector
        for (int i = 0; i < pathCount; i++) {
            f = path.get(i);
            if (directories.contains(f)) {
                int topIndex = directories.indexOf(f);
                for (int j = i - 1; j >= 0; j--) {
                    directories.insertElementAt(path.get(j), topIndex + i - j);
                }
                break;
            }
        }
        calculateDepths();
        setSelectedItem(sf);
    } catch (FileNotFoundException ex) {
        calculateDepths();
    }
}
 
Example 12
Source Project: jdk1.8-source-analysis   Source File: GTKFileChooserUI.java    License: Apache License 2.0 4 votes vote down vote up
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 13
Source Project: jdk1.8-source-analysis   Source File: GTKFileChooserUI.java    License: Apache License 2.0 4 votes vote down vote up
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 14
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 15
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 16
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 17
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 18
Source Project: jdk8u60   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 19
Source Project: jdk8u60   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 20
Source Project: JDKSourceCode1.8   Source File: GTKFileChooserUI.java    License: MIT License 4 votes vote down vote up
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: GTKFileChooserUI.java    License: MIT License 4 votes vote down vote up
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 22
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 23
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 24
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 25
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 26
Source Project: Bytecoder   Source File: GTKFileChooserUI.java    License: Apache License 2.0 4 votes vote down vote up
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 27
Source Project: Bytecoder   Source File: GTKFileChooserUI.java    License: Apache License 2.0 4 votes vote down vote up
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 28
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}
 
Example 29
protected RenameFileAction() {
    super(FilePane.ACTION_EDIT_FILE_NAME);
}
 
Example 30
Source Project: jdk8u-jdk   Source File: GTKFileChooserUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected NewFolderAction() {
    super(FilePane.ACTION_NEW_FOLDER);
}