KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > welcome > HyperlinkFrame


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
24 import java.awt.event.WindowAdapter JavaDoc;
25 import java.awt.event.WindowEvent JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30 import java.net.URL JavaDoc;
31
32 import javax.swing.JOptionPane JavaDoc;
33 import javax.swing.WindowConstants JavaDoc;
34 import javax.swing.event.HyperlinkListener JavaDoc;
35
36 public abstract class HyperlinkFrame extends Frame implements HyperlinkListener JavaDoc {
37   private static ResourceBundleHelper m_bundleHelper = new ResourceBundleHelper(HyperlinkFrame.class);
38   
39   private File JavaDoc m_installRoot;
40   private File JavaDoc m_bootPath;
41   private File JavaDoc m_javaCmd;
42   private File JavaDoc m_tcLib;
43   private File JavaDoc 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 JavaDoc url;
63     String JavaDoc 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 JavaDoc() {
72       public void windowClosing(WindowEvent JavaDoc we) {
73         quit();
74       }
75     });
76   }
77   
78   private String JavaDoc getBundleString(String JavaDoc key) {
79     return m_bundleHelper.getString(key);
80   }
81   
82   protected void quit() {
83     System.exit(0);
84   }
85   
86   protected File JavaDoc getInstallRoot() {
87     if(m_installRoot == null) {
88       m_installRoot = new File JavaDoc(System.getProperty("tc.install-root"));
89     }
90     return m_installRoot;
91   }
92   
93   protected String JavaDoc getBootPath() throws UnsupportedVMException {
94     if(m_bootPath == null) {
95       File JavaDoc bootPath = new File JavaDoc(System.getProperty("tc.install-root"));
96       bootPath = new File JavaDoc(bootPath, "lib");
97       bootPath = new File JavaDoc(bootPath, "dso-boot");
98       bootPath = new File JavaDoc(bootPath, BootJarSignature.getBootJarNameForThisVM());
99       m_bootPath = bootPath;
100     }
101
102     return m_bootPath.getAbsolutePath();
103   }
104
105   protected static String JavaDoc getenv(String JavaDoc key) {
106     try {
107       Method JavaDoc m = System JavaDoc.class.getMethod("getenv", new Class JavaDoc[] {String JavaDoc.class});
108     
109       if(m != null) {
110         return (String JavaDoc)m.invoke(null, new Object JavaDoc[]{key});
111       }
112     } catch(Throwable JavaDoc t) {/**/}
113
114     return null;
115   }
116   
117
118   static File JavaDoc staticGetJavaCmd() {
119     File JavaDoc javaBin = new File JavaDoc(System.getProperty("java.home"), "bin");
120     return new File JavaDoc(javaBin, "java" + (Os.isWindows() ? ".exe" : ""));
121   }
122   
123   protected File JavaDoc getJavaCmd() {
124     if(m_javaCmd == null) {
125       m_javaCmd = staticGetJavaCmd();
126     }
127
128     return m_javaCmd;
129   }
130
131   static File JavaDoc staticGetTCLib() {
132     File JavaDoc file = new File JavaDoc(System.getProperty("tc.install-root"));
133     file = new File JavaDoc(file, "lib");
134     return new File JavaDoc(file, "tc.jar");
135   }
136   
137   protected File JavaDoc getTCLib() {
138     if(m_tcLib == null) {
139       m_tcLib = staticGetTCLib();
140     }
141     return m_tcLib;
142   }
143   
144   protected File JavaDoc getSamplesDir() {
145     if(m_samplesDir == null) {
146       m_samplesDir = new File JavaDoc(getInstallRoot(), "samples");
147     }
148     return m_samplesDir;
149   }
150
151   protected Process JavaDoc exec(String JavaDoc[] cmdarray, String JavaDoc[] envp, File JavaDoc dir) {
152     try {
153       return Runtime.getRuntime().exec(cmdarray, envp, dir);
154     } catch(IOException JavaDoc 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 JavaDoc 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 JavaDoc is = getClass().getResourceAsStream("Welcome.xml");
181       DictionaryResource topRes = null;
182       
183       try {
184         topRes = ApplicationManager.loadResource(is);
185       } catch(Exception JavaDoc e) {
186         e.printStackTrace();
187       }
188       
189       return topRes;
190     }
191     
192     public void actionPerformed(ActionEvent JavaDoc 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