src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  35  *
  36  * @author Costantino Cerbo (c.cerbo@gmail.com)
  37  */
  38 final class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer {
  39 
  40     private final FileDialog fd;
  41 
  42     // A pointer to the native GTK FileChooser widget
  43     private volatile long widget = 0L;
  44 
  45     GtkFileDialogPeer(FileDialog fd) {
  46         super(fd);
  47         this.fd = fd;
  48     }
  49 
  50     private static native void initIDs();
  51     static {
  52         initIDs();
  53     }
  54 
  55     private native void run(String title, int mode, String dir, String file,
  56                             FilenameFilter filter, boolean isMultipleMode, int x, int y);
  57     private native void quit();
  58 
  59     @Override
  60     public native void toFront();
  61 
  62     @Override
  63     public native void setBounds(int x, int y, int width, int height, int op);
  64 
  65     /**
  66      * Called exclusively by the native C code.
  67      */
  68     private void setFileInternal(String directory, String[] filenames) {
  69         AWTAccessor.FileDialogAccessor accessor = AWTAccessor
  70                 .getFileDialogAccessor();
  71 
  72         if (filenames == null) {
  73             accessor.setDirectory(fd, null);
  74             accessor.setFile(fd, null);
  75             accessor.setFiles(fd, null);


 135 
 136     @Override
 137     public void setDirectory(String dir) {
 138         // We do not implement this method because we
 139         // have delegated to FileDialog#setDirectory
 140     }
 141 
 142     @Override
 143     public void setFile(String file) {
 144         // We do not implement this method because we
 145         // have delegated to FileDialog#setFile
 146     }
 147 
 148     @Override
 149     public void setFilenameFilter(FilenameFilter filter) {
 150         // We do not implement this method because we
 151         // have delegated to FileDialog#setFilenameFilter
 152     }
 153 
 154     private void showNativeDialog() {







 155         String dirname = fd.getDirectory();
 156         // File path has a priority against directory path.
 157         String filename = fd.getFile();
 158         if (filename != null) {
 159             final File file = new File(filename);
 160             if (fd.getMode() == FileDialog.LOAD
 161                 && dirname != null
 162                 && file.getParent() == null) {
 163                 // File path for gtk_file_chooser_set_filename.
 164                 filename = dirname + (dirname.endsWith(File.separator) ? "" :
 165                                               File.separator) + filename;
 166             }
 167             if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
 168                 // Filename for gtk_file_chooser_set_current_name.
 169                 filename = file.getName();
 170                 // Directory path for gtk_file_chooser_set_current_folder.
 171                 dirname = file.getParent();
 172             }
 173         }
 174         run(fd.getTitle(), fd.getMode(), dirname, filename,
 175             fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
 176     }
 177 }
   1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  35  *
  36  * @author Costantino Cerbo (c.cerbo@gmail.com)
  37  */
  38 final class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer {
  39 
  40     private final FileDialog fd;
  41 
  42     // A pointer to the native GTK FileChooser widget
  43     private volatile long widget = 0L;
  44 
  45     GtkFileDialogPeer(FileDialog fd) {
  46         super(fd);
  47         this.fd = fd;
  48     }
  49 
  50     private static native void initIDs();
  51     static {
  52         initIDs();
  53     }
  54 
  55     private native void run(long ownerWindow, String title, int mode, String dir, String file,
  56                             FilenameFilter filter, boolean isMultipleMode, int x, int y);
  57     private native void quit();
  58 
  59     @Override
  60     public native void toFront();
  61 
  62     @Override
  63     public native void setBounds(int x, int y, int width, int height, int op);
  64 
  65     /**
  66      * Called exclusively by the native C code.
  67      */
  68     private void setFileInternal(String directory, String[] filenames) {
  69         AWTAccessor.FileDialogAccessor accessor = AWTAccessor
  70                 .getFileDialogAccessor();
  71 
  72         if (filenames == null) {
  73             accessor.setDirectory(fd, null);
  74             accessor.setFile(fd, null);
  75             accessor.setFiles(fd, null);


 135 
 136     @Override
 137     public void setDirectory(String dir) {
 138         // We do not implement this method because we
 139         // have delegated to FileDialog#setDirectory
 140     }
 141 
 142     @Override
 143     public void setFile(String file) {
 144         // We do not implement this method because we
 145         // have delegated to FileDialog#setFile
 146     }
 147 
 148     @Override
 149     public void setFilenameFilter(FilenameFilter filter) {
 150         // We do not implement this method because we
 151         // have delegated to FileDialog#setFilenameFilter
 152     }
 153 
 154     private void showNativeDialog() {
 155         long ownerWindow = 0L;
 156 
 157         XWindowPeer ownerPeer = getOwnerPeer();
 158         if (ownerPeer != null) {
 159             ownerWindow = ownerPeer.getWindow();
 160         }
 161 
 162         String dirname = fd.getDirectory();
 163         // File path has a priority against directory path.
 164         String filename = fd.getFile();
 165         if (filename != null) {
 166             final File file = new File(filename);
 167             if (fd.getMode() == FileDialog.LOAD
 168                 && dirname != null
 169                 && file.getParent() == null) {
 170                 // File path for gtk_file_chooser_set_filename.
 171                 filename = dirname + (dirname.endsWith(File.separator) ? "" :
 172                                               File.separator) + filename;
 173             }
 174             if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
 175                 // Filename for gtk_file_chooser_set_current_name.
 176                 filename = file.getName();
 177                 // Directory path for gtk_file_chooser_set_current_folder.
 178                 dirname = file.getParent();
 179             }
 180         }
 181         run(ownerWindow, fd.getTitle(), fd.getMode(), dirname, filename,
 182             fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
 183     }
 184 }