F. Java Desktop Integration Components (JDIC)

F.1 Introduction

The Java Desktop Integration Components (JDIC) are part of an open-source project aimed at allowing better integration between Java applications and the platforms on which they execute. Some JDIC features include:

• interacting with the underlying platform to launch native applications (such as web browsers and email clients)

• displaying a splash screen when an application begins execution to indicate to the user that the application is loading

• creating icons in the system tray (also called the taskbar status area or notification area) to provide access to Java applications running in the background

• registering file-type associations, so that files of specified types will automatically open in corresponding Java applications

• creating installer packages, and more.

The JDIC homepage (jdic.dev.java.net/) includes an introduction to JDIC, downloads, documentation, FAQs, demos, articles, blogs, announcements, incubator projects, a developer’s page, forums, mailing lists, and more. Java SE 6 now includes some of the features mentioned above. We discuss several of these features here.

F.2 Splash Screens

Java application users often perceive a performance problem, because nothing appears on the screen when you first launch an application. One way to show a user that your program is loading is to display a splash screen—a borderless window that appears temporarily while an application loads. Java SE 6 provides the new command-line option -splash for the java command to accomplish this task. This option enables you to specify a PNG, GIF or JPG image that should display when your application begins loading. To demonstrate this new option, we created a program (Fig. F.1) that sleeps for 5 seconds (so you can view the splash screen) then displays a message at the command line. The directory for this example includes a PNG format image to use as the splash screen. To display the splash screen when this application loads, use the command

java -splash:DeitelBug.png SplashDemo

Fig. F.1. Spash screen displayed with the -splash option to the java command.

Image

Image

Once you’ve initiated the splash screen display, you can interact with it programmatically via the SplashScreen class of the java.awt package. You might do this to add some dynamic content to the splash screen. For more information on working with splash screens, see the following sites:

java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/
   splashscreen/
java.sun.com/javase/6/docs/api/java/awt/SplashScreen.html

F.3 Desktop Class

Java SE 6’s new Desktop class enables you to specify a file or URI that you’d like to open using the underlying platform’s appropriate application. For example, if Firefox is your computer’s default browser, you can use the Desktop class’s browse method to open a web site in Firefox. In addition, you can open an email composition window in your system’s default email client, open a file in its associated application and print a file using the associated application’s print command. Figure F.2 demonstrates the first three of these capabilities.

Fig. F.2. Use Desktop to launch the default browser, open a file in its associated application and compose an email in the default email client.

Image

Image

Image

Image

The event handler at lines 22–52 obtains the index number of the task the user selects in the tasksJComboBox (line 25) and the String that represents the file or URI to process (line 26). Line 28 uses Desktop static method isDesktopSupported to determine whether class Desktop’s features are supported on the platform on which this application runs. If they are, line 32 uses Desktop static method getDesktop, to obtain a Desktop object. If the user selected the option to open the default browser, line 37 creates a new URI object using the String input as the site to display in the browser, then passes the URI object to Desktop method browse which invokes the system’s default browser and passes the URI to the browser for display. If the user selects the option to open a file in its associated program, line 40 creates a new File object using the String input as the file to open, then passes the File object to Desktop method open which passes the file to the appropriate application to open the file. Finally, if the user selects the option to compose an email, line 43 creates a new URI object using the String input as the email address to which the email will be sent, then passes the URI object to Desktop method mail which invokes the system’s default email client and passes the URI to the email client as the email recipient. You can learn more about class Desktop at

java.sun.com/javase/6/docs/api/java/awt/Desktop.html

F.4 Tray Icons

Tray icons generally appear in your system’s system tray, taskbar status area or notification area. They typically provide quick access to applications that are executing in the background on your system. When you position the mouse over one of these icons, a tooltip appears indicating what application the icon represents. If you click the icon, a popup menu appears with options for that application.

Classes SystemTray and TrayIcon (both from package java.awt) enable you to create and manage your own tray icons in a platform independent manner. Class SystemTray provides access to the underlying platform’s system tray—the class consists of three methods:

static method getDefaultSystemTray returns the system tray

• method addTrayIcon adds a new TrayIcon to the system tray

• method removeTrayIcon removes an icon from the system tray

Class TrayIcon consists of several methods allowing users to specify an icon, a tooltip and a pop-up menu for the icon. In addition, tray icons support ActionListeners, MouseListeners and MouseMotionListeners. You can learn more about classes SystemTray and TrayIcon at

java.sun.com/javase/6/docs/api/java/awt/SystemTray.html

java.sun.com/javase/6/docs/api/java/awt/TrayIcon.html

F.5 JDIC Incubator Projects

The JDIC Incubator Projects are developed, maintained and owned by members of the Java community. These projects are associated with, but not distributed with, JDIC. The Incubator Projects may eventually become part of the JDIC project once they have been fully developed and meet certain criteria. For more information about the Incubator Projects and to learn how you can setup an Incubator Project, visit

jdic.dev.java.net/#incubator

Current Incubator Projects include:

• FileUtil—A file utility API that extends the java.io.File class.

• Floating Dock Top-level Window—A Java API for developing a floating dock toplevel window.

• Icon Service—Returns a Java icon object from a native icon specification.

• Misc API—Hosts simple (one method, one class type of) APIs.

• Music Player Control API—Java API that controls native music players.

• SaverBeans Screensaver SDK—Java screensaver development kit.

• SystemInfo—Checks the system information.

F.6 JDIC Demos

The JDIC site includes demos for FileExplorer, the browser package, the TrayIcon package, the Floating Dock class and the Wallpaper API (jdic.dev.java.net/#demos). The source code for these demos is included in the JDIC download (jdic.dev.java.net/servlets/ProjectDocumentList). For more demos, check out some of the incubator projects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset