src/java.desktop/unix/classes/sun/awt/X11/GtkFileDialogPeer.java
author prr
Thu, 01 Nov 2018 13:56:14 -0700
changeset 52535 45a5c4d812d9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213213: Remove src/java.desktop/unix/classes/sun/awt/X11/keysym2ucs.h Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     1
/*
31653
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 29922
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     4
 *
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5444
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5444
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    10
 *
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    15
 * accompanied this code).
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    16
 *
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5444
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5444
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5444
diff changeset
    23
 * questions.
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    24
 */
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    25
package sun.awt.X11;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    26
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    27
import java.awt.FileDialog;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    28
import java.awt.peer.FileDialogPeer;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    29
import java.io.File;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    30
import java.io.FilenameFilter;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    31
import sun.awt.AWTAccessor;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    32
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    33
/**
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    34
 * FileDialogPeer for the GtkFileChooser.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    35
 *
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    36
 * @author Costantino Cerbo (c.cerbo@gmail.com)
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    37
 */
23254
cfd1819394cd 8030987: sun_awt_X11_GtkFileDialogPeer.h can be removed
serb
parents: 12653
diff changeset
    38
final class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer {
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    39
23254
cfd1819394cd 8030987: sun_awt_X11_GtkFileDialogPeer.h can be removed
serb
parents: 12653
diff changeset
    40
    private final FileDialog fd;
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    41
7150
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    42
    // A pointer to the native GTK FileChooser widget
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    43
    private volatile long widget = 0L;
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
    44
    private long standaloneWindow;
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
    45
    private volatile boolean quit;
7150
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    46
23254
cfd1819394cd 8030987: sun_awt_X11_GtkFileDialogPeer.h can be removed
serb
parents: 12653
diff changeset
    47
    GtkFileDialogPeer(FileDialog fd) {
cfd1819394cd 8030987: sun_awt_X11_GtkFileDialogPeer.h can be removed
serb
parents: 12653
diff changeset
    48
        super(fd);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    49
        this.fd = fd;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    50
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    51
7150
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    52
    private static native void initIDs();
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    53
    static {
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    54
        initIDs();
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    55
    }
6c95b4f80a72 6960655: GTKFileDialogPeer shouldn't be a singletone
anthony
parents: 6644
diff changeset
    56
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    57
    private native void run(String title, int mode, String dir, String file,
8513
101b3095ff5a 7009114: GTK FileDialog lies about it's Bounds
dcherepanov
parents: 7243
diff changeset
    58
                            FilenameFilter filter, boolean isMultipleMode, int x, int y);
7243
4678eab93673 6998592: FileDialog tests crashed on solaris
anthony
parents: 7150
diff changeset
    59
    private native void quit();
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    60
7243
4678eab93673 6998592: FileDialog tests crashed on solaris
anthony
parents: 7150
diff changeset
    61
    @Override
4678eab93673 6998592: FileDialog tests crashed on solaris
anthony
parents: 7150
diff changeset
    62
    public native void toFront();
4678eab93673 6998592: FileDialog tests crashed on solaris
anthony
parents: 7150
diff changeset
    63
8513
101b3095ff5a 7009114: GTK FileDialog lies about it's Bounds
dcherepanov
parents: 7243
diff changeset
    64
    @Override
101b3095ff5a 7009114: GTK FileDialog lies about it's Bounds
dcherepanov
parents: 7243
diff changeset
    65
    public native void setBounds(int x, int y, int width, int height, int op);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    66
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    67
    /**
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    68
     * Called exclusively by the native C code.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    69
     */
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    70
    private void setFileInternal(String directory, String[] filenames) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    71
        AWTAccessor.FileDialogAccessor accessor = AWTAccessor
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    72
                .getFileDialogAccessor();
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    73
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    74
        if (filenames == null) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    75
            accessor.setDirectory(fd, null);
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    76
            accessor.setFile(fd, null);
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    77
            accessor.setFiles(fd, null);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    78
        } else {
6644
ee35bd1e91f9 6987233: FileDialog.getDirectory() should add a trainling slash when GTK FileDialog is used
anthony
parents: 5506
diff changeset
    79
            // Fix 6987233: add the trailing slash if it's absent
11503
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    80
            String with_separator = directory;
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    81
            if (directory != null) {
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    82
                with_separator = directory.endsWith(File.separator) ?
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    83
                        directory : (directory + File.separator);
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    84
            }
c40240392a01 7130662: GTK file dialog crashes with a NPE
anthony
parents: 9766
diff changeset
    85
            accessor.setDirectory(fd, with_separator);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    86
            accessor.setFile(fd, filenames[0]);
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    87
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    88
            int filesNumber = (filenames != null) ? filenames.length : 0;
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    89
            File[] files = new File[filesNumber];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    90
            for (int i = 0; i < filesNumber; i++) {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    91
                files[i] = new File(directory, filenames[i]);
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    92
            }
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 11503
diff changeset
    93
            accessor.setFiles(fd, files);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    94
        }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    95
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    96
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    97
    /**
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    98
     * Called exclusively by the native C code.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
    99
     */
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   100
    private boolean filenameFilterCallback(String fullname) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   101
        if (fd.getFilenameFilter() == null) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   102
            // no filter, accept all.
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   103
            return true;
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   104
        }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   105
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   106
        File filen = new File(fullname);
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   107
        return fd.getFilenameFilter().accept(new File(filen.getParent()),
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   108
                filen.getName());
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   109
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   110
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   111
    @Override
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   112
    public void setVisible(boolean b) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   113
        XToolkit.awtLock();
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   114
        try {
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   115
            quit = !b;
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   116
            if (b) {
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 25859
diff changeset
   117
                Runnable task = () -> {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 25859
diff changeset
   118
                    showNativeDialog();
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   119
                    standaloneWindow = 0;
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 25859
diff changeset
   120
                    fd.setVisible(false);
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   121
                };
37550
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 32119
diff changeset
   122
                new Thread(null, task, "ShowDialog", 0, false).start();
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   123
            } else {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   124
                quit();
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   125
                fd.setVisible(false);
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   126
            }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   127
        } finally {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   128
            XToolkit.awtUnlock();
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   129
        }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   130
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   131
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   132
    @Override
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   133
    public void dispose() {
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   134
        XToolkit.awtLock();
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   135
        try {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   136
            quit = true;
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   137
            quit();
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   138
        }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   139
        finally {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   140
            XToolkit.awtUnlock();
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   141
        }
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   142
        super.dispose();
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   143
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   144
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   145
    @Override
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   146
    public void setDirectory(String dir) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   147
        // We do not implement this method because we
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   148
        // have delegated to FileDialog#setDirectory
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   149
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   150
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   151
    @Override
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   152
    public void setFile(String file) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   153
        // We do not implement this method because we
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   154
        // have delegated to FileDialog#setFile
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   155
    }
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   156
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   157
    protected void requestXFocus(long time, boolean timeProvided) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   158
        if(standaloneWindow == 0) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   159
            super.requestXFocus(time, timeProvided);
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   160
            return;
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   161
        }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   162
        XNETProtocol net_protocol = XWM.getWM().getNETProtocol();
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   163
        if (net_protocol != null) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   164
            net_protocol.setActiveWindow(standaloneWindow);
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   165
        }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   166
    }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   167
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   168
    @Override
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   169
    public void setFilenameFilter(FilenameFilter filter) {
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   170
        // We do not implement this method because we
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   171
        // have delegated to FileDialog#setFilenameFilter
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   172
    }
9766
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   173
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   174
    private void showNativeDialog() {
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   175
        String dirname = fd.getDirectory();
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   176
        // File path has a priority against directory path.
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   177
        String filename = fd.getFile();
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   178
        if (filename != null) {
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   179
            final File file = new File(filename);
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   180
            if (fd.getMode() == FileDialog.LOAD
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   181
                && dirname != null
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   182
                && file.getParent() == null) {
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   183
                // File path for gtk_file_chooser_set_filename.
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   184
                filename = dirname + (dirname.endsWith(File.separator) ? "" :
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   185
                                              File.separator) + filename;
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   186
            }
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   187
            if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   188
                // Filename for gtk_file_chooser_set_current_name.
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   189
                filename = file.getName();
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   190
                // Directory path for gtk_file_chooser_set_current_folder.
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   191
                dirname = file.getParent();
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   192
            }
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   193
        }
32119
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   194
        if (!quit) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   195
            run(fd.getTitle(), fd.getMode(), dirname, filename,
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   196
                    fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   197
        }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   198
    }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   199
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   200
    /**
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   201
     * Called by native code when GTK dialog is created.
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   202
     */
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   203
    boolean setWindow(long xid) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   204
        if (!quit && widget != 0) {
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   205
            standaloneWindow = xid;
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   206
            requestXFocus();
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   207
            return true;
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   208
        }
1778956d7bee 8025815: Child FileDialog of modal dialog does not get focus on Gnome
ssadetsky
parents: 31653
diff changeset
   209
        return false;
9766
bf57566e576d 7045193: interactive JCK tests java_awt/interactive/FileDialogTests fail
serb
parents: 9035
diff changeset
   210
    }
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
diff changeset
   211
}