001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.welcome;
005:
006: import org.dijon.ApplicationManager;
007: import org.dijon.DictionaryResource;
008: import org.dijon.Frame;
009: import org.dijon.Image;
010: import org.dijon.Label;
011: import org.dijon.Menu;
012: import org.dijon.MenuBar;
013: import org.dijon.Separator;
014:
015: import com.tc.admin.common.ContactTerracottaAction;
016: import com.tc.admin.common.XAbstractAction;
017: import com.tc.object.tools.BootJarSignature;
018: import com.tc.object.tools.UnsupportedVMException;
019: import com.tc.util.ResourceBundleHelper;
020: import com.tc.util.ProductInfo;
021: import com.tc.util.runtime.Os;
022:
023: import java.awt.event.ActionEvent;
024: import java.awt.event.WindowAdapter;
025: import java.awt.event.WindowEvent;
026: import java.io.File;
027: import java.io.IOException;
028: import java.io.InputStream;
029: import java.lang.reflect.Method;
030: import java.net.URL;
031:
032: import javax.swing.JOptionPane;
033: import javax.swing.WindowConstants;
034: import javax.swing.event.HyperlinkListener;
035:
036: public abstract class HyperlinkFrame extends Frame implements
037: HyperlinkListener {
038: private static ResourceBundleHelper m_bundleHelper = new ResourceBundleHelper(
039: HyperlinkFrame.class);
040:
041: private File m_installRoot;
042: private File m_bootPath;
043: private File m_javaCmd;
044: private File m_tcLib;
045: private File m_samplesDir;
046:
047: public HyperlinkFrame() {
048: super ();
049:
050: MenuBar menubar = new MenuBar();
051: Menu menu;
052:
053: setJMenuBar(menubar);
054: menubar
055: .add(menu = new Menu(getBundleString("file.menu.title")));
056: initFileMenu(menu);
057: menubar
058: .add(menu = new Menu(getBundleString("help.menu.title")));
059: menu.add(new ContactTerracottaAction(
060: getBundleString("visit.forums.title"),
061: getBundleString("forums.url")));
062: menu.add(new ContactTerracottaAction(
063: getBundleString("contact.support.title"),
064: getBundleString("support.url")));
065: menu.add(new Separator());
066: menu.add(new AboutAction());
067:
068: URL url;
069: String iconPath = "/com/tc/admin/icons/logo_small.gif";
070:
071: if ((url = getClass().getResource(iconPath)) != null) {
072: setIconImage(new Image(url));
073: }
074:
075: setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
076:
077: addWindowListener(new WindowAdapter() {
078: public void windowClosing(WindowEvent we) {
079: quit();
080: }
081: });
082: }
083:
084: protected void initFileMenu(Menu fileMenu) {
085: fileMenu.add(new QuitAction());
086: }
087:
088: private String getBundleString(String key) {
089: return m_bundleHelper.getString(key);
090: }
091:
092: protected void quit() {
093: System.exit(0);
094: }
095:
096: protected File getInstallRoot() {
097: if (m_installRoot == null) {
098: m_installRoot = new File(System.getProperty(
099: "tc.install-root").trim());
100: }
101: return m_installRoot;
102: }
103:
104: protected String getBootPath() throws UnsupportedVMException {
105: if (m_bootPath == null) {
106: File bootPath = new File(getInstallRoot(), "lib");
107: bootPath = new File(bootPath, "dso-boot");
108: bootPath = new File(bootPath, BootJarSignature
109: .getBootJarNameForThisVM());
110: m_bootPath = bootPath;
111: }
112:
113: return m_bootPath.getAbsolutePath();
114: }
115:
116: protected static String getenv(String key) {
117: try {
118: Method m = System.class.getMethod("getenv",
119: new Class[] { String.class });
120:
121: if (m != null) {
122: return (String) m.invoke(null, new Object[] { key });
123: }
124: } catch (Throwable t) {/**/
125: }
126:
127: return null;
128: }
129:
130: static File staticGetJavaCmd() {
131: File javaBin = new File(System.getProperty("java.home"), "bin");
132: return new File(javaBin, "java"
133: + (Os.isWindows() ? ".exe" : ""));
134: }
135:
136: protected File getJavaCmd() {
137: if (m_javaCmd == null) {
138: m_javaCmd = staticGetJavaCmd();
139: }
140:
141: return m_javaCmd;
142: }
143:
144: static File staticGetTCLib() {
145: File file = new File(System.getProperty("tc.install-root")
146: .trim());
147: file = new File(file, "lib");
148: return new File(file, "tc.jar");
149: }
150:
151: protected File getTCLib() {
152: if (m_tcLib == null) {
153: m_tcLib = staticGetTCLib();
154: }
155: return m_tcLib;
156: }
157:
158: protected File getSamplesDir() {
159: if (m_samplesDir == null) {
160: m_samplesDir = new File(getInstallRoot(), "samples");
161: }
162: return m_samplesDir;
163: }
164:
165: protected Process exec(String[] cmdarray, String[] envp, File dir) {
166: try {
167: return Runtime.getRuntime().exec(cmdarray, envp, dir);
168: } catch (IOException ioe) {
169: ioe.printStackTrace();
170: }
171:
172: return null;
173: }
174:
175: class QuitAction extends XAbstractAction {
176: QuitAction() {
177: super (getBundleString("quit.action.name"));
178: }
179:
180: public void actionPerformed(ActionEvent ae) {
181: quit();
182: }
183: }
184:
185: class AboutAction extends XAbstractAction {
186: org.dijon.Container m_aboutPanel;
187:
188: AboutAction() {
189: super (getBundleString("about.title.prefix")
190: + HyperlinkFrame.this .getTitle());
191: }
192:
193: DictionaryResource loadTopRes() {
194: InputStream is = getClass().getResourceAsStream(
195: "Welcome.xml");
196: DictionaryResource topRes = null;
197:
198: try {
199: topRes = ApplicationManager.loadResource(is);
200: } catch (Exception e) {
201: e.printStackTrace();
202: }
203:
204: return topRes;
205: }
206:
207: public void actionPerformed(ActionEvent ae) {
208: if (m_aboutPanel == null) {
209: DictionaryResource topRes = loadTopRes();
210:
211: if (topRes != null) {
212: m_aboutPanel = (org.dijon.Container) topRes
213: .resolve("AboutPanel");
214:
215: ProductInfo prodInfo = ProductInfo.getInstance();
216: Label label = (Label) m_aboutPanel
217: .findComponent("TitleLabel");
218:
219: label.setText(prodInfo.toShortString());
220:
221: label = (Label) m_aboutPanel
222: .findComponent("CopyrightLabel");
223: label.setText(prodInfo.copyright());
224: }
225: }
226:
227: JOptionPane.showConfirmDialog(HyperlinkFrame.this,
228: m_aboutPanel, getName(),
229: JOptionPane.DEFAULT_OPTION,
230: JOptionPane.PLAIN_MESSAGE);
231: }
232: }
233: }
|