001: package com.tagtraum.perf.gcviewer;
002:
003: import javax.swing.*;
004: import javax.swing.border.EtchedBorder;
005: import javax.swing.border.SoftBevelBorder;
006: import java.awt.*;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.util.ResourceBundle;
010: import java.net.URL;
011: import java.net.URLDecoder;
012: import java.net.MalformedURLException;
013: import java.io.IOException;
014:
015: /**
016: * About dialog.
017: *
018: * @author Hendrik Schreiber
019: * @version $Id: $
020: */
021: public class AboutDialog extends JDialog implements ActionListener {
022:
023: /**
024: * Source-Version
025: */
026: public static String vcid = "$Id: AboutDialog.java,v 1.1.1.1 2002/01/15 19:48:45 hendriks73 Exp $";
027: private static ResourceBundle localStrings = ResourceBundle
028: .getBundle("com.tagtraum.perf.gcviewer.localStrings");
029: private static final String GCVIEWER_HOMEPAGE = "http://www.tagtraum.com/";
030:
031: private Frame frame;
032:
033: public AboutDialog(Frame f) {
034: super (f, localStrings.getString("about_dialog_title"), true);
035: this .frame = f;
036: setLocation(20, 20);
037: Panel panel0 = new Panel();
038: ImageIcon logoIcon = new ImageIcon(getClass().getResource(
039: localStrings.getString("about_dialog_image")));
040: JLabel la_icon = new JLabel(logoIcon);
041: //la_icon.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
042: la_icon.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));
043: panel0.add(la_icon);
044: Panel panel2 = new Panel();
045: panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
046: if (ExternalViewer.isSupported()) {
047: try {
048: JButton homepageButton = new JButton("Homepage");
049: homepageButton.addActionListener(new ExternalViewer(
050: new URL(GCVIEWER_HOMEPAGE)));
051: panel2.add(homepageButton);
052: } catch (MalformedURLException e) {
053: // should never happen
054: e.printStackTrace();
055: }
056: }
057:
058: JButton okButton = new JButton(localStrings
059: .getString("button_ok"));
060: okButton.setActionCommand("ok");
061: okButton.addActionListener(this );
062: panel2.add(okButton);
063: getContentPane().add("North", panel0);
064: // getContentPane().add("Center",panel1);
065: getContentPane().add("South", panel2);
066: pack();
067: setResizable(false);
068: setVisible(false);
069: }
070:
071: public void actionPerformed(ActionEvent e) {
072: String cmd = e.getActionCommand();
073: if (cmd.equals("ok")) {
074: setVisible(false);
075: }
076: }
077:
078: public void setVisible(boolean visible) {
079: if (visible)
080: setLocation((int) frame.getLocation().getX()
081: + (frame.getWidth() / 2) - (getWidth() / 2),
082: (int) frame.getLocation().getY()
083: + (frame.getHeight() / 2)
084: - (getHeight() / 2));
085: super .setVisible(visible);
086: }
087:
088: private static class ExternalViewer implements ActionListener {
089:
090: private static final boolean WINDOWS = System.getProperty(
091: "os.name").toLowerCase().startsWith("win");
092: private static final boolean MAC = System
093: .getProperty("os.name").toLowerCase().indexOf("mac") != -1;
094:
095: // The default system browser under Mac OS X.
096: private static final String MAC_PATH = "open";
097: // The default system browser under WINDOWS.
098: private static final String WIN_PATH = "rundll32";
099: // The flag to display a url.
100: private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
101:
102: private URL url;
103:
104: public ExternalViewer(URL url) {
105: this .url = url;
106: }
107:
108: public void actionPerformed(ActionEvent e) {
109: try {
110: displayURL(url);
111: } catch (IOException e1) {
112: e1.printStackTrace();
113: }
114: }
115:
116: /**
117: * Display a file in the system browser. If you want to display a
118: * file, you must include the absolute path name.
119: *
120: * @param url the file's url (the url must start with either "http://" or
121: * "file://").
122: */
123: public static void displayURL(URL url) throws IOException {
124: String cmd = null;
125: String urlString = url.toString();
126: if (WINDOWS) {
127: // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
128: // make sure, file URLs start with file:// instead of just file:/
129: if (urlString.startsWith("file:/")) {
130: if (!urlString.startsWith("file://")) {
131: urlString = "file://"
132: + urlString
133: .substring("file:/".length());
134: }
135: }
136: // replace %20 with spaces
137: try {
138: urlString = URLDecoder.decode(urlString);
139: } catch (Exception e) {
140: e.printStackTrace();
141: }
142: cmd = WIN_PATH + " " + WIN_FLAG + " " + urlString;
143: /*
144: if (urlString.startsWith("file:")) {
145: }
146: else {
147: cmd = "rundll32.exe msconf.dll,CallToProtocolHandler " + urlString;
148: }
149: */
150: Runtime.getRuntime().exec(cmd);
151: } else if (MAC) {
152: // TODO: fix this!
153: // hack to display jsps in TextEdit
154: if (urlString.endsWith(".jsp")
155: || urlString.endsWith(".jspx")) {
156: cmd = MAC_PATH + " -e "
157: + urlString.substring("file:".length());
158: } else {
159: cmd = MAC_PATH + " " + url;
160: }
161: Runtime.getRuntime().exec(cmd);
162: }
163: }
164:
165: public static boolean isSupported() {
166: return WINDOWS || MAC;
167: }
168: }
169:
170: }
|