1 4 package com.tc.welcome; 5 6 import org.dijon.ApplicationManager; 7 import org.dijon.DictionaryResource; 8 import org.dijon.Frame; 9 import org.dijon.Image; 10 import org.dijon.Label; 11 import org.dijon.Menu; 12 import org.dijon.MenuBar; 13 import org.dijon.Separator; 14 15 import com.tc.admin.common.ContactTerracottaAction; 16 import com.tc.admin.common.XAbstractAction; 17 import com.tc.object.tools.BootJarSignature; 18 import com.tc.object.tools.UnsupportedVMException; 19 import com.tc.util.ResourceBundleHelper; 20 import com.tc.util.ProductInfo; 21 import com.tc.util.runtime.Os; 22 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.WindowAdapter ; 25 import java.awt.event.WindowEvent ; 26 import java.io.File ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.lang.reflect.Method ; 30 import java.net.URL ; 31 32 import javax.swing.JOptionPane ; 33 import javax.swing.WindowConstants ; 34 import javax.swing.event.HyperlinkListener ; 35 36 public abstract class HyperlinkFrame extends Frame implements HyperlinkListener { 37 private static ResourceBundleHelper m_bundleHelper = new ResourceBundleHelper(HyperlinkFrame.class); 38 39 private File m_installRoot; 40 private File m_bootPath; 41 private File m_javaCmd; 42 private File m_tcLib; 43 private File m_samplesDir; 44 45 public HyperlinkFrame() { 46 super(); 47 48 MenuBar menubar = new MenuBar(); 49 Menu menu; 50 51 setJMenuBar(menubar); 52 menubar.add(menu = new Menu(getBundleString("file.menu.title"))); 53 menu.add(new QuitAction()); 54 menubar.add(menu = new Menu(getBundleString("help.menu.title"))); 55 menu.add(new ContactTerracottaAction(getBundleString("visit.forums.title"), 56 getBundleString("forums.url"))); 57 menu.add(new ContactTerracottaAction(getBundleString("contact.support.title"), 58 getBundleString("support.url"))); 59 menu.add(new Separator()); 60 menu.add(new AboutAction()); 61 62 URL url; 63 String iconPath = "/com/tc/admin/icons/logo_small.gif"; 64 65 if((url = getClass().getResource(iconPath)) != null) { 66 setIconImage(new Image(url)); 67 } 68 69 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 70 71 addWindowListener(new WindowAdapter () { 72 public void windowClosing(WindowEvent we) { 73 quit(); 74 } 75 }); 76 } 77 78 private String getBundleString(String key) { 79 return m_bundleHelper.getString(key); 80 } 81 82 protected void quit() { 83 System.exit(0); 84 } 85 86 protected File getInstallRoot() { 87 if(m_installRoot == null) { 88 m_installRoot = new File (System.getProperty("tc.install-root")); 89 } 90 return m_installRoot; 91 } 92 93 protected String getBootPath() throws UnsupportedVMException { 94 if(m_bootPath == null) { 95 File bootPath = new File (System.getProperty("tc.install-root")); 96 bootPath = new File (bootPath, "lib"); 97 bootPath = new File (bootPath, "dso-boot"); 98 bootPath = new File (bootPath, BootJarSignature.getBootJarNameForThisVM()); 99 m_bootPath = bootPath; 100 } 101 102 return m_bootPath.getAbsolutePath(); 103 } 104 105 protected static String getenv(String key) { 106 try { 107 Method m = System .class.getMethod("getenv", new Class [] {String .class}); 108 109 if(m != null) { 110 return (String )m.invoke(null, new Object []{key}); 111 } 112 } catch(Throwable t) {} 113 114 return null; 115 } 116 117 118 static File staticGetJavaCmd() { 119 File javaBin = new File (System.getProperty("java.home"), "bin"); 120 return new File (javaBin, "java" + (Os.isWindows() ? ".exe" : "")); 121 } 122 123 protected File getJavaCmd() { 124 if(m_javaCmd == null) { 125 m_javaCmd = staticGetJavaCmd(); 126 } 127 128 return m_javaCmd; 129 } 130 131 static File staticGetTCLib() { 132 File file = new File (System.getProperty("tc.install-root")); 133 file = new File (file, "lib"); 134 return new File (file, "tc.jar"); 135 } 136 137 protected File getTCLib() { 138 if(m_tcLib == null) { 139 m_tcLib = staticGetTCLib(); 140 } 141 return m_tcLib; 142 } 143 144 protected File getSamplesDir() { 145 if(m_samplesDir == null) { 146 m_samplesDir = new File (getInstallRoot(), "samples"); 147 } 148 return m_samplesDir; 149 } 150 151 protected Process exec(String [] cmdarray, String [] envp, File dir) { 152 try { 153 return Runtime.getRuntime().exec(cmdarray, envp, dir); 154 } catch(IOException ioe) { 155 ioe.printStackTrace(); 156 } 157 158 return null; 159 } 160 161 162 class QuitAction extends XAbstractAction { 163 QuitAction() { 164 super(getBundleString("quit.action.name")); 165 } 166 167 public void actionPerformed(ActionEvent ae) { 168 quit(); 169 } 170 } 171 172 class AboutAction extends XAbstractAction { 173 org.dijon.Container m_aboutPanel; 174 175 AboutAction() { 176 super(getBundleString("about.title.prefix")+HyperlinkFrame.this.getTitle()); 177 } 178 179 DictionaryResource loadTopRes() { 180 InputStream is = getClass().getResourceAsStream("Welcome.xml"); 181 DictionaryResource topRes = null; 182 183 try { 184 topRes = ApplicationManager.loadResource(is); 185 } catch(Exception e) { 186 e.printStackTrace(); 187 } 188 189 return topRes; 190 } 191 192 public void actionPerformed(ActionEvent ae) { 193 if(m_aboutPanel == null) { 194 DictionaryResource topRes = loadTopRes(); 195 196 if(topRes != null) { 197 m_aboutPanel = (org.dijon.Container)topRes.resolve("AboutPanel"); 198 199 ProductInfo prodInfo = ProductInfo.getThisProductInfo(); 200 Label label = (Label)m_aboutPanel.findComponent("TitleLabel"); 201 202 label.setText(prodInfo.toShortString()); 203 204 label = (Label)m_aboutPanel.findComponent("CopyrightLabel"); 205 label.setText(prodInfo.copyright()); 206 } 207 } 208 209 JOptionPane.showConfirmDialog(HyperlinkFrame.this, 210 m_aboutPanel, 211 getName(), 212 JOptionPane.DEFAULT_OPTION, 213 JOptionPane.PLAIN_MESSAGE); 214 } 215 } 216 } 217 | Popular Tags |