1 package org.columba.core.desktop; 17 18 import java.io.File ; 19 import java.net.URL ; 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 getMimeType(File file) { 37 String mimeType = activeDesktop.getMimeType(file); 38 if (mimeType == null || mimeType.equals("application/octet-stream")) { 39 return DefaultMimeTypeTable.lookup(file); 41 } else { 42 return mimeType; 43 } 44 } 45 46 public String getMimeType(String ext) { 47 String mimeType = activeDesktop.getMimeType(ext); 48 if (mimeType.equals("application/octet-stream")) { 49 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 file) { 61 return activeDesktop.open(file); 62 } 63 64 public boolean openAndWait(File file) { 65 return activeDesktop.openAndWait(file); 66 } 67 68 public boolean supportsBrowse() { 69 return activeDesktop.supportsBrowse(); 70 } 71 72 public void browse(URL url) { 73 activeDesktop.browse(url); 74 } 75 76 79 public IDesktop getActiveDesktop() { 80 return activeDesktop; 81 } 82 83 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 e) { 97 if (Logging.DEBUG) 98 e.printStackTrace(); 99 100 activeDesktop = new ColumbaDesktop(); 101 } catch (Error e) { 102 if (Logging.DEBUG) 103 e.printStackTrace(); 104 105 activeDesktop = new ColumbaDesktop(); 106 } 107 } 108 109 112 public static ColumbaDesktop getInstance() { 113 return instance; 114 } 115 116 } 117 | Popular Tags |