1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.util;
25
26 import java.awt.BorderLayout;
27 import java.awt.Component;
28 import java.awt.Dimension;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31 import java.awt.Insets;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.io.IOException;
35 import java.text.MessageFormat;
36
37 import javax.swing.JButton;
38 import javax.swing.JDialog;
39 import javax.swing.JLabel;
40 import javax.swing.JOptionPane;
41 import javax.swing.JPanel;
42 import javax.swing.JScrollPane;
43 import javax.swing.JTextPane;
44 import javax.swing.event.HyperlinkEvent;
45 import javax.swing.event.HyperlinkListener;
46
47 import com.mindtree.techworks.insight.InsightConstants;
48 import com.mindtree.techworks.insight.ResourceManager;
49 import com.mindtree.techworks.insight.VersionUtil;
50 import com.mindtree.techworks.insight.gui.Insight;
51
52
53
54
55
56
57
58
59
60
61 public class AboutFrame extends JDialog {
62
63
64
65
66 private static final long serialVersionUID = 220882995949861144L;
67
68
69
70
71 private static final String ACTIVATED = "ACTIVATED";
72
73
74
75
76 private static final MessageFormat FORMATTER = new MessageFormat(
77 "<code>Version {0} (Build Id: {1})</code>" +
78 "<br><code>CopyRight © MindTree Consulting Pvt. Ltd.</code>" +
79 "<br><code>All Rights reserved.</code>" +
80 "<br><br><code>Support:</code>" +
81 "<br><code>Email - <a href = 'mailto:mindtreeinsight-users@lists.sourceforge.net'>mindtreeinsight-users@lists.sourceforge.net</a></code>" +
82 "<br><code>Intranet - <a href = 'http://mindtreeinsight.sourceforge.net/'>http://mindtreeinsight.sourceforge.net/</a></code>"
83 );
84
85
86
87
88 private static final int FRAME_WIDTH = 300;
89
90
91
92
93 private static final int FRAME_HEIGHT = 200;
94
95
96
97
98 private GridBagLayout gl;
99
100
101
102
103 private GridBagConstraints gc;
104
105
106
107
108 private JTextPane detailsPane;
109
110
111
112
113 protected JButton closeButton;
114
115
116
117
118 private Insight insight;
119
120
121
122
123
124 public AboutFrame(Insight insight) {
125 super(JOptionPane.getFrameForComponent(insight),InsightConstants.getLiteral("ABOUT_TITLE"),true);
126 this.setResizable(false);
127 this.insight = insight;
128 gl = new GridBagLayout();
129 gc = new GridBagConstraints();
130 getContentPane().setLayout(gl);
131
132 detailsPane = new JTextPane();
133 detailsPane.setEditable(false);
134 detailsPane.setContentType("text/html");
135
136 JPanel containerPanel = new JPanel();
137 containerPanel.setLayout(new BorderLayout());
138 containerPanel.add(new JLabel(ResourceManager.getInstance().loadImageIcon("INSIGHT_IMAGE")), BorderLayout.NORTH);
139 containerPanel.add(detailsPane, BorderLayout.SOUTH);
140
141 JScrollPane scrollPane = new JScrollPane(containerPanel);
142
143 detailsPane.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
144 addComponent(scrollPane,0,0,1,1,2,1);
145
146 closeButton = new JButton(InsightConstants.getLiteral("OK"));
147 addComponent(closeButton,0,1,0,0,1,1);
148
149 ButtionActionProcessor actionProcessor = new ButtionActionProcessor();
150 closeButton.addActionListener(actionProcessor);
151
152 detailsPane.addHyperlinkListener(actionProcessor);
153
154 final Object[] args = {
155 VersionUtil.getInsightVersion(),
156 VersionUtil.getInsightBuild(),
157 };
158 detailsPane.setText(FORMATTER.format(args));
159
160
161 this.pack();
162
163 int insightX = insight.getX();
164 int insightY = insight.getY();
165 int thisX = insightX + ((this.insight.getWidth() - this.getWidth())/ 2);
166 int thisY = insightY + ((this.insight.getHeight() - this.getHeight())/ 2);
167 this.setLocation(thisX, thisY);
168 this.show();
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 private final void addComponent(Component c, int gridx, int gridy, int weightx,
191 int weighty, int width, int height) {
192 gc.fill = GridBagConstraints.BOTH;
193 gc.anchor = GridBagConstraints.NORTHWEST;
194 gc.insets = new Insets(5,5,5,5);
195 gc.gridx = gridx;
196 gc.gridy = gridy;
197 gc.weightx = weightx;
198 gc.weighty = weighty;
199 gc.gridwidth = width;
200 gc.gridheight = height;
201 gl.setConstraints( c, gc);
202 getContentPane().add(c);
203 }
204
205
206
207
208 private final class ButtionActionProcessor implements ActionListener, HyperlinkListener {
209
210
211
212
213 public void actionPerformed(ActionEvent e) {
214 Object source = e.getSource();
215 if (source == closeButton) {
216 hide();
217 dispose();
218 }
219 }
220
221
222
223
224
225 public void hyperlinkUpdate(HyperlinkEvent event) {
226
227 if (event.getEventType().toString() == ACTIVATED) {
228 new BrowserControl().displayURL(event.getURL().toString());
229 }
230 }
231 }
232
233
234
235
236
237 private class BrowserControl {
238
239
240
241
242 private static final String WIN_ID = "Windows";
243
244
245
246
247 private static final String WIN_PATH = "rundll32";
248
249
250
251
252 private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
253
254
255
256
257 private static final String UNIX_PATH = "netscape";
258
259
260
261
262 private static final String UNIX_FLAG = "-remote openURL";
263
264
265
266
267
268
269 public void displayURL(String url) {
270 boolean windows = isWindowsPlatform();
271 String cmd = null;
272 try {
273 if (windows) {
274 cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
275 Runtime.getRuntime().exec(cmd);
276 } else {
277
278
279
280
281
282 cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
283 Process p = Runtime.getRuntime().exec(cmd);
284 try {
285
286
287 int exitCode = p.waitFor();
288 if (exitCode != 0) {
289
290
291 cmd = UNIX_PATH + " " + url;
292 p = Runtime.getRuntime().exec(cmd);
293 }
294 } catch(InterruptedException e) {
295 e.printStackTrace();
296 }
297 }
298 } catch(IOException e) {
299 e.printStackTrace();
300 }
301 }
302
303
304
305
306
307
308 private boolean isWindowsPlatform() {
309 String os = System.getProperty("os.name");
310 if ( os != null && os.startsWith(WIN_ID)) {
311 return true;
312 }
313 return false;
314 }
315 }
316 }