1 4 package com.tc.admin; 5 6 import org.apache.commons.io.IOUtils; 7 import org.dijon.ApplicationManager; 8 import org.dijon.DictionaryResource; 9 import org.dijon.Image; 10 11 import com.tc.admin.common.Splash; 12 import com.tc.util.ResourceBundleHelper; 13 import com.tc.util.runtime.Os; 14 15 import java.awt.event.ActionEvent ; 16 import java.awt.event.ActionListener ; 17 import java.io.File ; 18 import java.io.FileInputStream ; 19 import java.io.FileOutputStream ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.util.logging.Level ; 24 import java.util.logging.Logger ; 25 import java.util.prefs.Preferences ; 26 27 import javax.swing.Timer ; 28 import javax.swing.UIManager ; 29 30 public class AdminClient extends ApplicationManager { 31 private static AdminClient m_client; 32 private AdminClientContext m_cntx; 33 34 private static final String PREF_FILE = ".AdminClient.xml"; 35 36 static { 37 Logger.getLogger("javax.management.remote.generic").setLevel(Level.OFF); 38 Logger.getLogger("javax.management.remote.misc").setLevel(Level.OFF); 39 Logger.getLogger("com.sun.jmx.remote.opt.util").setLevel(Level.OFF); 40 Logger.getLogger("com.sun.jmx.remote.opt.util").setLevel(Level.OFF); 41 Logger.getLogger("javax.management.remote.rmi").setLevel(Level.OFF); 42 } 43 44 protected AdminClient() { 45 super("AdminClient"); 46 47 if(Os.isMac()) { 48 System.setProperty("com.apple.macos.useScreenMenuBar", "true"); 49 System.setProperty("apple.laf.useScreenMenuBar", "true"); 50 51 System.setProperty("apple.awt.showGrowBox", "true"); 52 System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); 53 } 54 55 m_cntx = new AdminClientContext(); 56 m_cntx.client = m_client = this; 57 m_cntx.prefs = loadPrefs(); 58 m_cntx.topRes = loadTopRes(); 59 m_cntx.bundleHelper = new ResourceBundleHelper(getClass()); 60 61 if(!Boolean.getBoolean("com.tc.ui.java-icon")) { 62 setIconImage(new Image(getBytes("/com/tc/admin/icons/logo_small.gif"))); 63 } 64 } 65 66 static byte[] getBytes(String path) { 67 byte[] result = null; 68 URL url = AdminClient.class.getResource(path); 69 70 if(url != null) { 71 InputStream is = null; 72 73 try { 74 result = IOUtils.toByteArray(is = url.openStream()); 75 } catch(IOException ioe) { 76 ioe.printStackTrace(); 77 } finally { 78 IOUtils.closeQuietly(is); 79 } 80 } 81 82 return result; 83 } 84 85 public static AdminClient getClient() { 86 if(m_client == null) { 87 new AdminClient().parseArgs(new String []{}); 88 } 89 90 return m_client; 91 } 92 93 protected AdminClientContext context() { 94 return m_cntx; 95 } 96 97 public static AdminClientContext getContext() { 98 return getClient().context(); 99 } 100 101 104 public DictionaryResource loadPreferences() { 105 return new DictionaryResource(); 106 } 107 public void storePreferences() {} 108 109 private Preferences loadPrefs() { 110 FileInputStream fis = null; 111 112 try { 113 File f = new File (System.getProperty("user.home"), PREF_FILE); 114 115 if(f.exists()) { 116 fis = new FileInputStream (f); 117 Preferences.importPreferences(fis); 118 } 119 } catch(Exception e) { 120 } finally { 122 IOUtils.closeQuietly(fis); 123 } 124 125 return Preferences.userNodeForPackage(getClass()); 126 } 127 128 public void storePrefs() { 129 FileOutputStream fos = null; 130 131 try { 132 File f = new File (System.getProperty("user.home"), PREF_FILE); 133 fos = new FileOutputStream (f); 134 m_cntx.prefs.exportSubtree(fos); 135 m_cntx.prefs.flush(); 136 } catch(Exception e) { 137 e.printStackTrace(); 138 } finally { 139 IOUtils.closeQuietly(fos); 140 } 141 } 142 143 private DictionaryResource loadTopRes() { 144 DictionaryResource topRes = null; 145 InputStream is = null; 146 147 try { 148 is = getClass().getResourceAsStream("AdminClient.xml"); 149 topRes = ApplicationManager.loadResource(is); 150 } catch(Throwable t) { 151 t.printStackTrace(); 152 System.exit(-1); 153 } finally { 154 IOUtils.closeQuietly(is); 155 } 156 157 return topRes; 158 } 159 160 public void start() { 161 m_cntx.controller = new AdminClientFrame(); 162 Timer t = new Timer (2000, new ActionListener () { 163 public void actionPerformed(ActionEvent ae) { 164 ((AdminClientFrame)m_cntx.controller).setVisible(true); 165 splashProc.destroy(); 166 } 167 }); 168 t.setRepeats(false); 169 t.start(); 170 } 171 172 public String [] parseArgs(String [] args) { 173 args = super.parseArgs(args); 174 175 if (args != null && args.length > 0) { 176 } 178 179 return args; 180 } 181 182 private static Process splashProc; 183 184 public static final void main(final String [] args) 185 throws Exception 186 { 187 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 188 189 splashProc = Splash.start("Starting Terracotta AdminConsole...", new Runnable () { 190 public void run() { 191 AdminClient client = new AdminClient(); 192 client.parseArgs(ApplicationManager.parseLAFArgs(args)); 193 client.start(); 194 } 195 }); 196 splashProc.waitFor(); 197 } 198 } 199 | Popular Tags |