Java Code Examples for sun.awt.AWTAccessor#getFileDialogAccessor()

The following examples show how to use sun.awt.AWTAccessor#getFileDialogAccessor() . 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: XFileDialogPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * handle the cancel event
 */
void handleCancel() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
        .removeKeyEventDispatcher(this);

    setSelectionField(null);
    setFilterField(null);
    directoryList.clear();
    fileList.clear();

    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(target, null);
    fileDialogAccessor.setFile(target, null);
    fileDialogAccessor.setFiles(target, null);

    handleQuitButton();
}
 
Example 2
Source File: XFileDialogPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * handle the selection event
 */
void handleSelection(String file) {

    int index = file.lastIndexOf(java.io.File.separatorChar);

    if (index == -1) {
        savedDir = this.dir;
        savedFile = file;
    } else {
        savedDir = file.substring(0, index+1);
        savedFile = file.substring(index+1);
    }

    String[] fileNames = fileList.getSelectedItems();
    int filesNumber = (fileNames != null) ? fileNames.length : 0;
    File[] files = new File[filesNumber];
    for (int i = 0; i < filesNumber; i++) {
        files[i] = new File(savedDir, fileNames[i]);
    }

    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(target, savedDir);
    fileDialogAccessor.setFile(target, savedFile);
    fileDialogAccessor.setFiles(target, files);
}
 
Example 3
Source File: XFileDialogPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * handle the selection event
 */
void handleSelection(String file) {

    int index = file.lastIndexOf(java.io.File.separatorChar);

    if (index == -1) {
        savedDir = this.dir;
        savedFile = file;
    } else {
        savedDir = file.substring(0, index+1);
        savedFile = file.substring(index+1);
    }

    String[] fileNames = fileList.getSelectedItems();
    int filesNumber = (fileNames != null) ? fileNames.length : 0;
    File[] files = new File[filesNumber];
    for (int i = 0; i < filesNumber; i++) {
        files[i] = new File(savedDir, fileNames[i]);
    }

    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(target, savedDir);
    fileDialogAccessor.setFile(target, savedFile);
    fileDialogAccessor.setFiles(target, files);
}
 
Example 4
Source File: XFileDialogPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * handle the cancel event
 */
void handleCancel() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
        .removeKeyEventDispatcher(this);

    setSelectionField(null);
    setFilterField(null);
    directoryList.clear();
    fileList.clear();

    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(target, null);
    fileDialogAccessor.setFile(target, null);
    fileDialogAccessor.setFiles(target, null);

    handleQuitButton();
}
 
Example 5
Source File: GtkFileDialogPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called exclusively by the native C code.
 */
private void setFileInternal(String directory, String[] filenames) {
    AWTAccessor.FileDialogAccessor accessor = AWTAccessor
            .getFileDialogAccessor();

    if (filenames == null) {
        accessor.setDirectory(fd, null);
        accessor.setFile(fd, null);
        accessor.setFiles(fd, null);
    } else {
        // Fix 6987233: add the trailing slash if it's absent
        String with_separator = directory;
        if (directory != null) {
            with_separator = directory.endsWith(File.separator) ?
                    directory : (directory + File.separator);
        }
        accessor.setDirectory(fd, with_separator);
        accessor.setFile(fd, filenames[0]);

        int filesNumber = (filenames != null) ? filenames.length : 0;
        File[] files = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            files[i] = new File(directory, filenames[i]);
        }
        accessor.setFiles(fd, files);
    }
}
 
Example 6
Source File: GtkFileDialogPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called exclusively by the native C code.
 */
private void setFileInternal(String directory, String[] filenames) {
    AWTAccessor.FileDialogAccessor accessor = AWTAccessor
            .getFileDialogAccessor();

    if (filenames == null) {
        accessor.setDirectory(fd, null);
        accessor.setFile(fd, null);
        accessor.setFiles(fd, null);
    } else {
        // Fix 6987233: add the trailing slash if it's absent
        String with_separator = directory;
        if (directory != null) {
            with_separator = directory.endsWith(File.separator) ?
                    directory : (directory + File.separator);
        }
        accessor.setDirectory(fd, with_separator);
        accessor.setFile(fd, filenames[0]);

        int filesNumber = (filenames != null) ? filenames.length : 0;
        File[] files = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            files[i] = new File(directory, filenames[i]);
        }
        accessor.setFiles(fd, files);
    }
}
 
Example 7
Source File: GtkFileDialogPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called exclusively by the native C code.
 */
private void setFileInternal(String directory, String[] filenames) {
    AWTAccessor.FileDialogAccessor accessor = AWTAccessor
            .getFileDialogAccessor();

    if (filenames == null) {
        accessor.setDirectory(fd, null);
        accessor.setFile(fd, null);
        accessor.setFiles(fd, null);
    } else {
        // Fix 6987233: add the trailing slash if it's absent
        String with_separator = directory;
        if (directory != null) {
            with_separator = directory.endsWith(File.separator) ?
                    directory : (directory + File.separator);
        }
        accessor.setDirectory(fd, with_separator);
        accessor.setFile(fd, filenames[0]);

        int filesNumber = (filenames != null) ? filenames.length : 0;
        File[] files = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            files[i] = new File(directory, filenames[i]);
        }
        accessor.setFiles(fd, files);
    }
}
 
Example 8
Source File: GtkFileDialogPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called exclusively by the native C code.
 */
private void setFileInternal(String directory, String[] filenames) {
    AWTAccessor.FileDialogAccessor accessor = AWTAccessor
            .getFileDialogAccessor();

    if (filenames == null) {
        accessor.setDirectory(fd, null);
        accessor.setFile(fd, null);
        accessor.setFiles(fd, null);
    } else {
        // Fix 6987233: add the trailing slash if it's absent
        String with_separator = directory;
        if (directory != null) {
            with_separator = directory.endsWith(File.separator) ?
                    directory : (directory + File.separator);
        }
        accessor.setDirectory(fd, with_separator);
        accessor.setFile(fd, filenames[0]);

        int filesNumber = (filenames != null) ? filenames.length : 0;
        File[] files = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            files[i] = new File(directory, filenames[i]);
        }
        accessor.setFiles(fd, files);
    }
}
 
Example 9
Source File: GtkFileDialogPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called exclusively by the native C code.
 */
private void setFileInternal(String directory, String[] filenames) {
    AWTAccessor.FileDialogAccessor accessor = AWTAccessor
            .getFileDialogAccessor();

    if (filenames == null) {
        accessor.setDirectory(fd, null);
        accessor.setFile(fd, null);
        accessor.setFiles(fd, null);
    } else {
        // Fix 6987233: add the trailing slash if it's absent
        String with_separator = directory;
        if (directory != null) {
            with_separator = directory.endsWith(File.separator) ?
                    directory : (directory + File.separator);
        }
        accessor.setDirectory(fd, with_separator);
        accessor.setFile(fd, filenames[0]);

        int filesNumber = (filenames != null) ? filenames.length : 0;
        File[] files = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            files[i] = new File(directory, filenames[i]);
        }
        accessor.setFiles(fd, files);
    }
}
 
Example 10
Source File: CFileDialog.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        boolean navigateApps = !AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.use-file-dialog-packages"));
        boolean chooseDirectories = AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.fileDialogForDirectories"));

        int dialogMode = target.getMode();
        String title = target.getTitle();
        if (title == null) {
            title = " ";
        }

        String[] userFileNames = nativeRunFileDialog(title,
                dialogMode,
                target.isMultipleMode(),
                navigateApps,
                chooseDirectories,
                target.getFilenameFilter() != null,
                target.getDirectory(),
                target.getFile());

        String directory = null;
        String file = null;
        File[] files = null;

        if (userFileNames != null) {
            // the dialog wasn't cancelled
            int filesNumber = userFileNames.length;
            files = new File[filesNumber];
            for (int i = 0; i < filesNumber; i++) {
                files[i] = new File(userFileNames[i]);
            }

            directory = files[0].getParent();
            // make sure directory always ends in '/'
            if (!directory.endsWith(File.separator)) {
                directory = directory + File.separator;
            }

            file = files[0].getName(); // pick any file
        }

        // store results back in component
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor.getFileDialogAccessor();
        accessor.setDirectory(target, directory);
        accessor.setFile(target, file);
        accessor.setFiles(target, files);
    } finally {
        // Java2 Dialog waits for hide to let show() return
        target.dispose();
    }
}
 
Example 11
Source File: WFileDialogPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         @Override
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}
 
Example 12
Source File: WFileDialogPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         @Override
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}
 
Example 13
Source File: CFileDialog.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        boolean navigateApps = !AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.use-file-dialog-packages"));
        boolean chooseDirectories = AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.fileDialogForDirectories"));

        int dialogMode = target.getMode();
        String title = target.getTitle();
        if (title == null) {
            title = " ";
        }

        String[] userFileNames = nativeRunFileDialog(title,
                dialogMode,
                target.isMultipleMode(),
                navigateApps,
                chooseDirectories,
                target.getFilenameFilter() != null,
                target.getDirectory(),
                target.getFile());

        String directory = null;
        String file = null;
        File[] files = null;

        if (userFileNames != null) {
            // the dialog wasn't cancelled
            int filesNumber = userFileNames.length;
            files = new File[filesNumber];
            for (int i = 0; i < filesNumber; i++) {
                files[i] = new File(userFileNames[i]);
            }

            directory = files[0].getParent();
            // make sure directory always ends in '/'
            if (!directory.endsWith(File.separator)) {
                directory = directory + File.separator;
            }

            file = files[0].getName(); // pick any file
        }

        // store results back in component
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor.getFileDialogAccessor();
        accessor.setDirectory(target, directory);
        accessor.setFile(target, file);
        accessor.setFiles(target, files);
    } finally {
        // Java2 Dialog waits for hide to let show() return
        target.dispose();
    }
}
 
Example 14
Source File: WFileDialogPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         @Override
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}
 
Example 15
Source File: CFileDialog.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        boolean navigateApps = !AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.use-file-dialog-packages"));
        boolean chooseDirectories = AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.fileDialogForDirectories"));

        int dialogMode = target.getMode();
        String title = target.getTitle();
        if (title == null) {
            title = " ";
        }

        String[] userFileNames = nativeRunFileDialog(title,
                dialogMode,
                target.isMultipleMode(),
                navigateApps,
                chooseDirectories,
                target.getFilenameFilter() != null,
                target.getDirectory(),
                target.getFile());

        String directory = null;
        String file = null;
        File[] files = null;

        if (userFileNames != null) {
            // the dialog wasn't cancelled
            int filesNumber = userFileNames.length;
            files = new File[filesNumber];
            for (int i = 0; i < filesNumber; i++) {
                files[i] = new File(userFileNames[i]);
            }

            directory = files[0].getParent();
            // make sure directory always ends in '/'
            if (!directory.endsWith(File.separator)) {
                directory = directory + File.separator;
            }

            file = files[0].getName(); // pick any file
        }

        // store results back in component
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor.getFileDialogAccessor();
        accessor.setDirectory(target, directory);
        accessor.setFile(target, file);
        accessor.setFiles(target, files);
    } finally {
        // Java2 Dialog waits for hide to let show() return
        target.dispose();
    }
}
 
Example 16
Source File: WFileDialogPeer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}
 
Example 17
Source File: WFileDialogPeer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         @Override
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}
 
Example 18
Source File: CFileDialog.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        boolean navigateApps = !AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.use-file-dialog-packages"));
        boolean chooseDirectories = AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.fileDialogForDirectories"));

        int dialogMode = target.getMode();
        String title = target.getTitle();
        if (title == null) {
            title = " ";
        }

        String[] userFileNames = nativeRunFileDialog(title,
                dialogMode,
                target.isMultipleMode(),
                navigateApps,
                chooseDirectories,
                target.getFilenameFilter() != null,
                target.getDirectory(),
                target.getFile());

        String directory = null;
        String file = null;
        File[] files = null;

        if (userFileNames != null) {
            // the dialog wasn't cancelled
            int filesNumber = userFileNames.length;
            files = new File[filesNumber];
            for (int i = 0; i < filesNumber; i++) {
                files[i] = new File(userFileNames[i]);
            }

            directory = files[0].getParent();
            // make sure directory always ends in '/'
            if (!directory.endsWith(File.separator)) {
                directory = directory + File.separator;
            }

            file = files[0].getName(); // pick any file
        }

        // store results back in component
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor.getFileDialogAccessor();
        accessor.setDirectory(target, directory);
        accessor.setFile(target, file);
        accessor.setFiles(target, files);
    } finally {
        // Java2 Dialog waits for hide to let show() return
        target.dispose();
    }
}
 
Example 19
Source File: CFileDialog.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        boolean navigateApps = !AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.use-file-dialog-packages"));
        boolean chooseDirectories = AccessController.doPrivileged(
                new GetBooleanAction("apple.awt.fileDialogForDirectories"));

        int dialogMode = target.getMode();
        String title = target.getTitle();
        if (title == null) {
            title = " ";
        }

        String[] userFileNames = nativeRunFileDialog(title,
                dialogMode,
                target.isMultipleMode(),
                navigateApps,
                chooseDirectories,
                target.getFilenameFilter() != null,
                target.getDirectory(),
                target.getFile());

        String directory = null;
        String file = null;
        File[] files = null;

        if (userFileNames != null) {
            // the dialog wasn't cancelled
            int filesNumber = userFileNames.length;
            files = new File[filesNumber];
            for (int i = 0; i < filesNumber; i++) {
                files[i] = new File(userFileNames[i]);
            }

            directory = files[0].getParent();
            // make sure directory always ends in '/'
            if (!directory.endsWith(File.separator)) {
                directory = directory + File.separator;
            }

            file = files[0].getName(); // pick any file
        }

        // store results back in component
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor.getFileDialogAccessor();
        accessor.setDirectory(target, directory);
        accessor.setFile(target, file);
        accessor.setFiles(target, files);
    } finally {
        // Java2 Dialog waits for hide to let show() return
        target.dispose();
    }
}
 
Example 20
Source File: WFileDialogPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
void handleSelected(final char[] buffer)
{
    String[] wFiles = (new String(buffer)).split("\0"); // NULL is the delimiter
    boolean multiple = (wFiles.length > 1);

    String jDirectory = null;
    String jFile = null;
    File[] jFiles = null;

    if (multiple) {
        jDirectory = wFiles[0];
        int filesNumber = wFiles.length - 1;
        jFiles = new File[filesNumber];
        for (int i = 0; i < filesNumber; i++) {
            jFiles[i] = new File(jDirectory, wFiles[i + 1]);
    }
        jFile = wFiles[1]; // choose any file
    } else {
        int index = wFiles[0].lastIndexOf(java.io.File.separatorChar);
        if (index == -1) {
            jDirectory = "."+java.io.File.separator;
            jFile = wFiles[0];
        } else {
            jDirectory = wFiles[0].substring(0, index + 1);
            jFile = wFiles[0].substring(index + 1);
        }
        jFiles = new File[] { new File(jDirectory, jFile) };
    }

    final FileDialog fileDialog = (FileDialog)target;
    AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();

    fileDialogAccessor.setDirectory(fileDialog, jDirectory);
    fileDialogAccessor.setFile(fileDialog, jFile);
    fileDialogAccessor.setFiles(fileDialog, jFiles);

    WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() {
         @Override
         public void run() {
             fileDialog.setVisible(false);
         }
    });
}