KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > desktop > ColumbaDesktop


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.desktop;
17
18 import java.io.File JavaDoc;
19 import java.net.URL JavaDoc;
20
21 import org.columba.api.desktop.IDesktop;
22 import org.columba.core.base.OSInfo;
23 import org.columba.core.io.DefaultMimeTypeTable;
24 import org.columba.core.logging.Logging;
25
26 public class ColumbaDesktop implements IDesktop {
27
28     private static ColumbaDesktop instance = new ColumbaDesktop();
29
30     IDesktop activeDesktop;
31
32     protected ColumbaDesktop() {
33         activeDesktop = new DefaultDesktop();
34     }
35
36     public String JavaDoc getMimeType(File JavaDoc file) {
37         String JavaDoc mimeType = activeDesktop.getMimeType(file);
38         if (mimeType == null || mimeType.equals("application/octet-stream")) {
39             // Try the built-in mime table
40
return DefaultMimeTypeTable.lookup(file);
41         } else {
42             return mimeType;
43         }
44     }
45
46     public String JavaDoc getMimeType(String JavaDoc ext) {
47         String JavaDoc mimeType = activeDesktop.getMimeType(ext);
48         if (mimeType.equals("application/octet-stream")) {
49             // Try the built-in mime table
50
return DefaultMimeTypeTable.lookup(ext);
51         } else {
52             return mimeType;
53         }
54     }
55
56     public boolean supportsOpen() {
57         return activeDesktop.supportsOpen();
58     }
59
60     public boolean open(File JavaDoc file) {
61         return activeDesktop.open(file);
62     }
63
64     public boolean openAndWait(File JavaDoc file) {
65         return activeDesktop.openAndWait(file);
66     }
67
68     public boolean supportsBrowse() {
69         return activeDesktop.supportsBrowse();
70     }
71
72     public void browse(URL JavaDoc url) {
73         activeDesktop.browse(url);
74     }
75
76     /**
77      * @return Returns the activeDesktop.
78      */

79     public IDesktop getActiveDesktop() {
80         return activeDesktop;
81     }
82
83     /**
84      * @param activeDesktop
85      * The activeDesktop to set.
86      */

87     public void initActiveDesktop() {
88         try {
89             if (OSInfo.isLinux()) {
90                 activeDesktop = new JDICDesktop();
91             } else if (OSInfo.isWin32Platform()) {
92                 activeDesktop = new JDICDesktop();
93             } else if (OSInfo.isMac()) {
94                 activeDesktop = new MacDesktop();
95             }
96         } catch (Exception JavaDoc e) {
97             if (Logging.DEBUG)
98                 e.printStackTrace();
99             
100             activeDesktop = new ColumbaDesktop();
101         } catch (Error JavaDoc e) {
102             if (Logging.DEBUG)
103                 e.printStackTrace();
104             
105             activeDesktop = new ColumbaDesktop();
106         }
107     }
108
109     /**
110      * @return Returns the instance.
111      */

112     public static ColumbaDesktop getInstance() {
113         return instance;
114     }
115
116 }
117
Popular Tags