Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java
32288 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.awt.X11;2526import java.awt.FileDialog;27import java.awt.peer.FileDialogPeer;28import java.io.File;29import java.io.FilenameFilter;30import sun.awt.AWTAccessor;3132/**33* FileDialogPeer for the GtkFileChooser.34*35* @author Costantino Cerbo ([email protected])36*/37final class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer {3839private final FileDialog fd;4041// A pointer to the native GTK FileChooser widget42private volatile long widget = 0L;4344GtkFileDialogPeer(FileDialog fd) {45super(fd);46this.fd = fd;47}4849private static native void initIDs();50static {51initIDs();52}5354private native void run(String title, int mode, String dir, String file,55FilenameFilter filter, boolean isMultipleMode, int x, int y);56private native void quit();5758@Override59public native void toFront();6061@Override62public native void setBounds(int x, int y, int width, int height, int op);6364/**65* Called exclusively by the native C code.66*/67private void setFileInternal(String directory, String[] filenames) {68AWTAccessor.FileDialogAccessor accessor = AWTAccessor69.getFileDialogAccessor();7071if (filenames == null) {72accessor.setDirectory(fd, null);73accessor.setFile(fd, null);74accessor.setFiles(fd, null);75} else {76// Fix 6987233: add the trailing slash if it's absent77String with_separator = directory;78if (directory != null) {79with_separator = directory.endsWith(File.separator) ?80directory : (directory + File.separator);81}82accessor.setDirectory(fd, with_separator);83accessor.setFile(fd, filenames[0]);8485int filesNumber = (filenames != null) ? filenames.length : 0;86File[] files = new File[filesNumber];87for (int i = 0; i < filesNumber; i++) {88files[i] = new File(directory, filenames[i]);89}90accessor.setFiles(fd, files);91}92}9394/**95* Called exclusively by the native C code.96*/97private boolean filenameFilterCallback(String fullname) {98if (fd.getFilenameFilter() == null) {99// no filter, accept all.100return true;101}102103File filen = new File(fullname);104return fd.getFilenameFilter().accept(new File(filen.getParent()),105filen.getName());106}107108@Override109public void setVisible(boolean b) {110XToolkit.awtLock();111try {112if (b) {113Thread t = new Thread() {114public void run() {115showNativeDialog();116fd.setVisible(false);117}118};119t.start();120} else {121quit();122fd.setVisible(false);123}124} finally {125XToolkit.awtUnlock();126}127}128129@Override130public void dispose() {131quit();132super.dispose();133}134135@Override136public void setDirectory(String dir) {137// We do not implement this method because we138// have delegated to FileDialog#setDirectory139}140141@Override142public void setFile(String file) {143// We do not implement this method because we144// have delegated to FileDialog#setFile145}146147@Override148public void setFilenameFilter(FilenameFilter filter) {149// We do not implement this method because we150// have delegated to FileDialog#setFilenameFilter151}152153private void showNativeDialog() {154String dirname = fd.getDirectory();155// File path has a priority against directory path.156String filename = fd.getFile();157if (filename != null) {158final File file = new File(filename);159if (fd.getMode() == FileDialog.LOAD160&& dirname != null161&& file.getParent() == null) {162// File path for gtk_file_chooser_set_filename.163filename = dirname + (dirname.endsWith(File.separator) ? "" :164File.separator) + filename;165}166if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {167// Filename for gtk_file_chooser_set_current_name.168filename = file.getName();169// Directory path for gtk_file_chooser_set_current_folder.170dirname = file.getParent();171}172}173run(fd.getTitle(), fd.getMode(), dirname, filename,174fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());175}176}177178179