KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > desktop > internal > impl > MacLaunchService


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.desktop.internal.impl;
22
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 import org.jdesktop.jdic.desktop.internal.LaunchFailedException;
27 import org.jdesktop.jdic.desktop.internal.LaunchService;
28
29 /**
30  * Concrete implementation of the LaunchService interface for Mac OS X.
31  *
32  * @author Elliott Hughes <enh@acm.org>
33  */

34 public class MacLaunchService implements LaunchService {
35     static {
36         System.loadLibrary("jdic");
37     }
38     
39     /**
40      * Converts the given filename path to a unique canonical form. Which
41      * removes redundent names, such as: `.' or `..' or symbolic links (on UNIX).
42      */

43     public File JavaDoc resolveLinkFile(File JavaDoc file) {
44         File JavaDoc resolvedFile = file;
45         try {
46             resolvedFile = file.getCanonicalFile();
47         } catch (IOException JavaDoc e) {
48         }
49          
50          return resolvedFile;
51     }
52
53     /**
54      * Launches the associated application to open the given file.
55      *
56      * @param file the given file to be opened.
57      * @throws LaunchFailedException if the given file has no associated
58      * application, or the associated application fails to be launched.
59      */

60     public void open(File JavaDoc file) throws LaunchFailedException {
61         boolean result = nativeOpenFile(file.toString());
62         if (result == false) {
63             throw new LaunchFailedException("Failed to launch the associated " +
64                 "application with the specified file.");
65         }
66     }
67     
68     /**
69      * Checks if the given file is editable.
70      */

71     public boolean isEditable(File JavaDoc file) {
72         return false;
73     }
74
75     /**
76      * Launches the associated editor to edit the given file.
77      *
78      * @param file the given file to be edited.
79      * @throws LaunchFailedException if the given file has no associated editor,
80      * or the associated editor fails to be launched.
81      */

82     public void edit(File JavaDoc file) throws LaunchFailedException {
83         throw new LaunchFailedException("No application associated with the " +
84             "specified file and verb.");
85     }
86
87     /**
88      * Checks if the given file is printable.
89      */

90     public boolean isPrintable(File JavaDoc file) {
91         return true;
92     }
93
94     /**
95      * Prints the given file.
96      *
97      * @param file the given file to be printed.
98      * @throws LaunchFailedException if the given file has no associated
99      * application, or the associated application fails to be launched.
100      */

101     public void print(File JavaDoc file) throws LaunchFailedException {
102         boolean result = nativePrintFile(file.toString());
103         if (result == false) {
104             throw new LaunchFailedException("Failed to launch the associated " +
105                 "application with the specified file.");
106         }
107     }
108     
109     private native boolean nativeOpenFile(String JavaDoc filePath);
110     private native boolean nativePrintFile(String JavaDoc filePath);
111 }
112
Popular Tags