diff options
author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-06-03 23:18:43 +0000 |
---|---|---|
committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-06-03 23:18:43 +0000 |
commit | 5bf762459121cc397663d22498d62d71fa179ef6 (patch) | |
tree | a9c9e7d91c484d53fe154f9285fc57325572ce50 /libjava/classpath/java/awt/Desktop.java | |
parent | 6d7301dc346a198a89ac987c1008aac09f191ee6 (diff) | |
download | ppe42-gcc-5bf762459121cc397663d22498d62d71fa179ef6.tar.gz ppe42-gcc-5bf762459121cc397663d22498d62d71fa179ef6.zip |
libjava/classpath/ChangeLog.gcj:
2007-05-31 Matthias Klose <doko@ubuntu.com>
* javax/management/NotificationBroadcasterSupport.java
(getNotificationInfo): Add cast.
* native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
directories.
* native/jni/qt-peer/Makefile.in: Regenerate.
libjava/ChangeLog:
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/natFileWin32.cc (setFilePermissions): New (stub only).
_access: Handle EXEC query, stub only.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Merged from classpath:
* gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
* java/lang/System.java(inheritedChannel): New.
* java/lang/Character.java: Remove stray`;'.
* java/net/MulticastSocket.java: Merged.
* java/text/DateFormatSymbols.java(getInstance): New, comment updates.
* java/text/Collator.java(getInstance): Merged.
* java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
getDisplayName, getDisplayNames: New.
* java/util/logging/Logger.java: Merged.
* Regenerate .class and .h files.
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/File.java: Merge with classpath-0.95, new method
setFilePermissions, new attribute EXEC.
* java/io/natFilePosix.cc (setFilePermissions): New.
_access: Handle EXEC query.
* classpath/lib/java/io/File.class, java/io/File.h: Regenerate.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Imported GNU Classpath 0.95.
* classpath/Makefile.in,
classpath/native/jni/midi-dssi/Makefile.in,
classpath/native/jni/classpath/Makefile.in,
classpath/native/jni/Makefile.in,
classpath/native/jni/gconf-peer/Makefile.in,
classpath/native/jni/java-io/Makefile.in,
classpath/native/jni/native-lib/Makefile.in,
classpath/native/jni/java-util/Makefile.in,
classpath/native/jni/midi-alsa/Makefile.in,
classpath/native/jni/java-lang/Makefile.in,
classpath/native/jni/java-nio/Makefile.in,
classpath/native/jni/java-net/Makefile.in,
classpath/native/jni/xmlj/Makefile.in,
classpath/native/jni/qt-peer/Makefile.in,
classpath/native/jni/gtk-peer/Makefile.in,
classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
classpath/native/fdlibm/Makefile.in,
classpath/native/plugin/Makefile.in,
classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
classpath/tools/Makefile.in, classpath/doc/Makefile.in,
classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
classpath/external/sax/Makefile.in,
classpath/external/w3c_dom/Makefile.in,
classpath/external/relaxngDatatype/Makefile.in,
classpath/include/Makefile.in,
classpath/examples/Makefile.in: Regenerate.
* classpath/config.guess, classpath/config.sub,
classpath/ltmain.sh : Update.
* classpath/configure, classpath/depcomp, classpath/missing,
classpath/aclocal.m4, classpath/install-sh: Regenerate.
* gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
* sources.am: Regenerate.
* Makefile.in: Regenerate.
* Update the .class files and generated CNI header files, add new
.class and generated CNI header files.
* Remove generated files for removed java source files:
classpath/gnu/java/net/BASE64.java,
classpath/gnu/java/security/util/Base64.java,
classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
classpath/gnu/java/awt/font/autofit/Scaler.java,
classpath/gnu/classpath/jdwp/util/Value.java,
classpath/gnu/javax/net/ssl/Base64.java.
* Remove empty directories.
* Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
* java/lang/Class.java(setAccessible): Merge from classpath.
* java/util/Locale.java: Remove.
* gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
* gcj/javaprims.h: Update class declarations.
* scripts/classes.pl: Update usage.
* HACKING: Mention to build all peers.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125302 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/awt/Desktop.java')
-rw-r--r-- | libjava/classpath/java/awt/Desktop.java | 268 |
1 files changed, 268 insertions, 0 deletions
diff --git a/libjava/classpath/java/awt/Desktop.java b/libjava/classpath/java/awt/Desktop.java new file mode 100644 index 00000000000..8010464c00d --- /dev/null +++ b/libjava/classpath/java/awt/Desktop.java @@ -0,0 +1,268 @@ +/* Desktop.java -- enable desktop integration between java programs and system + programs. + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package java.awt; + +import java.awt.peer.DesktopPeer; +import java.io.File; +import java.io.IOException; +import java.net.URI; + +/** + * This class enables Java application to access system commands to perform + * desktop oriented operations, like writing and sending emails, or surfing + * webpages with the system browser or editing/printing files with a default + * editor. Methods are provided to handle these common operations, plus an + * <code>open</code> command selects a default registered application for the + * specified file type. For example, opening an odf file results in launching + * OpenOffice. If an operation is not supported, or the application fails to + * launch, an exception is generated. + * + * <strong>Implementation note: </strong>As this class is used to manage Desktop + * integration, we provide some extension to configure the behaviour of this + * class depending on the type of dektop that is detected.<br /> + * + * First of all, we support 5 system properties that can be used to define + * the application to launch in any given case. These properties are:<br /> + * <br /> + * <code>gnu.java.awt.peer.Desktop.html.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.mail.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.edit.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.print.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.open.command</code><br /> + * <br /> + * <br /> + * These can be specified from the command line and have priority on every + * other setting.<br /> + * <br /> + * The second method supported is defining a Java preference.<br /> + * The main preference node is a <strong>user node</strong> relative to the + * class <code>gnu.java.awt.peer.ClasspathDesktopPeer</code>. This node + * contains a child for each supported operation. The key for each type is + * always <code>command</code>: + * <br /><br /> + * <code>gnu.java.awt.peer.Desktop.html.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.mail.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.edit.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.print.command</code><br /> + * <code>gnu.java.awt.peer.Desktop.open.command</code><br /> + * <br /> + * <br /> + * The access to these keys is done with the Preference API or, if outside + * of the java scope, is done in a backend dependent way. For example, + * with the GConf backend, you can access these properties + * with (may not be accurate on your system): + * <br /><br /> + * <code> + * gconftool-2 -g /apps/classpath/gnu/java/awt/peer/Desktop/html/command + * </code> + * + * @author Mario Torre <neugens@limasoftware.net> + * @since 1.6 + */ +public class Desktop +{ + /** + * Represents an action type supported by a platform. + * + * To determine if a given action is supported by the platform, + * use the <code>Desktop.isSupported(java.awt.Desktop.Action)</code> + * method. + * + * @author Mario Torre <neugens@limasoftware.net> + */ + public enum Action + { + BROWSE, EDIT, MAIL, OPEN, PRINT + } + + private DesktopPeer peer; + + private Desktop() + { + /* nothing to be done */ + } + + /** + * Returns an istance of the Desktop Class. + * + * If this implementation does not support Desktop, an + * UnsupportedOperationException will be thrown. + * Also, an HeadlessException will be generated if + * GraphicsEnvironment.isHeadless() returns true. + * + * @throws UnsupportedOperationException + * @throws HeadlessException + */ + public static Desktop getDesktop() throws UnsupportedOperationException, + HeadlessException + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + + if (!Desktop.isDesktopSupported()) + throw new UnsupportedOperationException(); + + Desktop desktop = new Desktop(); + desktop.peer = Toolkit.getDefaultToolkit().createDesktopPeer(desktop); + + return desktop; + } + + /** + * Check if this implementation supports Desktop. + * If true, use getDesktop to get an instance of this class. + * + * This implementation will return false when GraphicsEnvironment.isHeadless + * returns true. + * + * @return true if this class is supported on the current platform; + * false otherwise + */ + private static boolean isDesktopSupported() + { + if (GraphicsEnvironment.isHeadless()) + return false; + + return true; + } + + /** + * Check if the given Action is supported by this implementation. + * + * @param action + * @return + */ + public boolean isSupported(Desktop.Action action) + { + return peer.isSupported(action); + } + + /** + * Launches the Desktop default browser to open the given <code>uri</code>. + * + * If a security manager exists and denies + * AWTPermission("showWindowWithoutWarningBanner"),a SecurityException will + * be generated. + * + * @param uri + * @throws IOException + */ + public void browse(URI uri) + throws IOException + { + peer.browse(uri); + } + + /** + * Launch the edit command to edit this file. + * File should already exist before the editing starts. + * + * If a security manager exists and + * SecurityManager.checkRead(java.lang.String) method denies read access to + * the file, or SecurityManager.checkPrintJobAccess() method denies the + * permission to print the file, a SecurityException will be generated. + * + * @param file + * @throws IOException + */ + public void edit(File file) + throws IOException + { + peer.edit(file); + } + + /** + * Launches the Desktop default mailer. + * + * If a security manager exists and denies + * AWTPermission("showWindowWithoutWarningBanner"), a SecurityException will + * be generated. + * + * @throws IOException + */ + public void mail() + throws IOException + { + peer.mail(); + } + + /** + * Launches the Desktop default mailer, with the given mailtoURI + * as agrument. The <code>mailtoURI</code> must conform to the + * {@link http://www.ietf.org/rfc/rfc2368.txt The mailto URL scheme (RFC 2368)} + * + * If a security manager exists and denies + * AWTPermission("showWindowWithoutWarningBanner"), a SecurityException will + * be generated. + * + * @param mailtoURI + * @throws IOException + */ + public void mail(URI mailtoURI) + throws IOException + { + peer.mail(mailtoURI); + } + + /** + * Launches the Desktop default application to open the given File. + * If <code>file</code> is a directory, a file manager is launched. + * + * @param file + * @throws IOException + */ + public void open(File file) + throws IOException + { + peer.open(file); + } + + /** + * Launch the print program to print this file. + * + * @param file + * @throws IOException + */ + public void print(File file) + throws IOException + { + peer.print(file); + } +} |