KickJava   Java API By Example, From Geeks To Geeks.

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


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 Gnome.
31  */

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

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

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

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

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

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

97     public void print(File JavaDoc file) throws LaunchFailedException {
98         throw new LaunchFailedException("No application associated with the specified file and verb.");
99     }
100     
101     private native boolean nativeOpenFile(String JavaDoc filePath);
102 }
103
Popular Tags