1 4 package com.tc; 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 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.ActionListener ; 16 import java.io.File ; 17 import java.io.FileInputStream ; 18 import java.io.FileOutputStream ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.net.URL ; 22 import java.util.prefs.Preferences ; 23 24 import javax.swing.Timer ; 25 import javax.swing.UIManager ; 26 27 public class SessionIntegrator extends ApplicationManager { 28 private static SessionIntegrator m_client; 29 private SessionIntegratorContext m_cntx; 30 31 private static final String APP_NAME = "SessionIntegrator"; 32 private static final String PREF_FILE = "."+APP_NAME+".xml"; 33 34 public SessionIntegrator() { 35 super(APP_NAME); 36 37 m_cntx = new SessionIntegratorContext(); 38 m_cntx.client = m_client = this; 39 m_cntx.prefs = loadPrefs(); 40 m_cntx.topRes = loadTopRes(); 41 m_cntx.bundleHelper = new ResourceBundleHelper(getClass()); 42 43 setIconImage(new Image(getBytes("/com/tc/admin/icons/logo_small.gif"))); 44 } 45 46 static byte[] getBytes(String path) { 47 byte[] result = null; 48 URL url = SessionIntegrator.class.getResource(path); 49 50 if(url != null) { 51 InputStream is = null; 52 53 try { 54 result = IOUtils.toByteArray(is = url.openStream()); 55 } catch(IOException ioe) { 56 ioe.printStackTrace(); 57 } finally { 58 IOUtils.closeQuietly(is); 59 } 60 } 61 62 return result; 63 } 64 65 public void toConsole(String msg) { 66 67 } 68 69 public static SessionIntegrator getClient() { 70 return m_client; 71 } 72 73 protected SessionIntegratorContext context() { 74 return m_cntx; 75 } 76 77 public static SessionIntegratorContext getContext() { 78 return getClient().context(); 79 } 80 81 public DictionaryResource loadPreferences() { 82 return new DictionaryResource(); 83 } 84 85 public void storePreferences() {} 86 87 private Preferences loadPrefs() { 88 FileInputStream fis = null; 89 90 try { 91 File f = new File (System.getProperty("user.home"), PREF_FILE); 92 93 if(f.exists()) { 94 fis = new FileInputStream (f); 95 Preferences.importPreferences(fis); 96 } 97 } catch(Exception e) { 98 } finally { 100 IOUtils.closeQuietly(fis); 101 } 102 103 return Preferences.userNodeForPackage(getClass()); 104 } 105 106 public void storePrefs() { 107 FileOutputStream fos = null; 108 109 try { 110 File f = new File (System.getProperty("user.home"), PREF_FILE); 111 fos = new FileOutputStream (f); 112 m_cntx.prefs.exportSubtree(fos); 113 m_cntx.prefs.flush(); 114 } catch(Exception e) { 115 e.printStackTrace(); 116 } finally { 117 IOUtils.closeQuietly(fos); 118 } 119 } 120 121 private DictionaryResource loadTopRes() { 122 DictionaryResource topRes = null; 123 InputStream is = null; 124 125 try { 126 is = getClass().getResourceAsStream(APP_NAME+".xml"); 127 topRes = ApplicationManager.loadResource(is); 128 } catch(Throwable t) { 129 t.printStackTrace(); 130 System.exit(-1); 131 } finally { 132 IOUtils.closeQuietly(is); 133 } 134 135 return topRes; 136 } 137 138 public void start() { 139 m_cntx.frame = new SessionIntegratorFrame(); 140 Timer t = new Timer (1000, new ActionListener () { 141 public void actionPerformed(ActionEvent ae) { 142 m_cntx.frame.setVisible(true); 143 splashProc.destroy(); 144 } 145 }); 146 t.setRepeats(false); 147 t.start(); 148 } 149 150 public String [] parseArgs(String [] args) { 151 args = super.parseArgs(args); 152 153 if (args != null && args.length > 0) { 154 } 156 157 return args; 158 } 159 160 private static Process splashProc; 161 162 public static final void main(final String [] args) 163 throws Exception 164 { 165 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 166 167 splashProc = Splash.start("Starting Terracotta Sessions Configurator...", new Runnable () { 168 public void run() { 169 SessionIntegrator client = new SessionIntegrator(); 170 client.parseArgs(ApplicationManager.parseLAFArgs(args)); 171 client.start(); 172 } 173 }); 174 splashProc.waitFor(); 175 } 176 } 177 | Popular Tags |