001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.desktop;
017:
018: import java.io.File;
019: import java.net.URL;
020:
021: import org.columba.api.desktop.IDesktop;
022: import org.columba.core.base.OSInfo;
023: import org.columba.core.io.DefaultMimeTypeTable;
024: import org.columba.core.logging.Logging;
025:
026: public class ColumbaDesktop implements IDesktop {
027:
028: private static ColumbaDesktop instance = new ColumbaDesktop();
029:
030: IDesktop activeDesktop;
031:
032: protected ColumbaDesktop() {
033: activeDesktop = new DefaultDesktop();
034: }
035:
036: public String getMimeType(File file) {
037: String mimeType = activeDesktop.getMimeType(file);
038: if (mimeType == null
039: || mimeType.equals("application/octet-stream")) {
040: // Try the built-in mime table
041: return DefaultMimeTypeTable.lookup(file);
042: } else {
043: return mimeType;
044: }
045: }
046:
047: public String getMimeType(String ext) {
048: String mimeType = activeDesktop.getMimeType(ext);
049: if (mimeType.equals("application/octet-stream")) {
050: // Try the built-in mime table
051: return DefaultMimeTypeTable.lookup(ext);
052: } else {
053: return mimeType;
054: }
055: }
056:
057: public boolean supportsOpen() {
058: return activeDesktop.supportsOpen();
059: }
060:
061: public boolean open(File file) {
062: return activeDesktop.open(file);
063: }
064:
065: public boolean openAndWait(File file) {
066: return activeDesktop.openAndWait(file);
067: }
068:
069: public boolean supportsBrowse() {
070: return activeDesktop.supportsBrowse();
071: }
072:
073: public void browse(URL url) {
074: activeDesktop.browse(url);
075: }
076:
077: /**
078: * @return Returns the activeDesktop.
079: */
080: public IDesktop getActiveDesktop() {
081: return activeDesktop;
082: }
083:
084: /**
085: * @param activeDesktop
086: * The activeDesktop to set.
087: */
088: public void initActiveDesktop() {
089: try {
090: if (OSInfo.isLinux()) {
091: activeDesktop = new JDICDesktop();
092: } else if (OSInfo.isWin32Platform()) {
093: activeDesktop = new JDICDesktop();
094: } else if (OSInfo.isMac()) {
095: activeDesktop = new MacDesktop();
096: }
097: } catch (Exception e) {
098: if (Logging.DEBUG)
099: e.printStackTrace();
100:
101: activeDesktop = new ColumbaDesktop();
102: } catch (Error e) {
103: if (Logging.DEBUG)
104: e.printStackTrace();
105:
106: activeDesktop = new ColumbaDesktop();
107: }
108: }
109:
110: /**
111: * @return Returns the instance.
112: */
113: public static ColumbaDesktop getInstance() {
114: return instance;
115: }
116:
117: }
|