KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > cbutil > CBAbout


1 package com.ca.commons.cbutil;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
8
9
10 /*
11  * This class displays the CA standard about dialog. This class is to be used across all the java
12  * projects. This is why all the Strings for components are passed in the constructor. Currently
13  * JXplorer handles its strings differently for internationalisation.
14  */

15
16 public class CBAbout extends JDialog
17 {
18
19     private JTextArea information; //This is where the message information about copyright etc. goes
20
private JLabel productLogoLabel, caLogoLabel; //Two JLabels to display the images at the top and bottom left of the screen
21
private JPanel buttonsPanel, bottomPanel;
22     private CBButton okButton;
23     private static final int width = 477; // the standard CA about window width
24
private static final int height = 288; // the standard CA about window hight
25
private JFrame owner;
26
27
28     /**
29      * The url for the CA website.
30      */

31     private static final String JavaDoc URL = "http://www.ca.com";
32
33     /**
34      * This is a constructor.
35      *
36      * @param frame the parent frame for the dialog box
37      * @param message the product details to be displayed in the center scrollpane
38      * @param caLogoImage the CA Logo ImageIcon to go down the bottom left of the dialog
39      * @param productLogoImage the product specific banner to go up the top of the dialog
40      * @param okButtonMessage the String to go on the label to the OK button
41      * @param okButtonTooltip the tooltip to be displayed on the mouseover for the OK button
42      * @param aboutDialogTitle the title of the AboutDlg
43      */

44
45
46     public CBAbout(JFrame frame, String JavaDoc message, ImageIcon caLogoImage, ImageIcon productLogoImage,
47                    String JavaDoc okButtonMessage, String JavaDoc okButtonTooltip, String JavaDoc aboutDialogTitle)
48     {
49         super(frame, aboutDialogTitle, true);
50
51         owner = frame;
52
53
54         setBackground(Color.white);
55
56         Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
57         setBounds((screen.width - width) / 2, (screen.height - height) / 2, width, height);
58
59         setSize(width, height);
60         setResizable(false);
61
62         /*
63          * puts the product banner image up the top of the dialog
64          */

65         productLogoLabel = new JLabel(productLogoImage);
66         productLogoLabel.setBackground(Color.white);
67         getContentPane().add(productLogoLabel, BorderLayout.NORTH);
68
69         /*
70          * creates a scrollable text area in the center of the dialog and
71          * inserts the String with your copyright information, versions etc.
72          */

73         JPanel infoPanel = new JPanel(new GridLayout(1, 0));
74         infoPanel.setBackground(Color.white);
75         information = new JTextArea(message);
76         information.setBackground(Color.white);
77         information.setOpaque(true);
78         information.setEditable(false);
79
80         JScrollPane textPane = new JScrollPane(information);
81         textPane.setBackground(Color.white);
82         textPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
83         infoPanel.add(textPane);
84         infoPanel.setBorder(BorderFactory.createLineBorder(Color.white, 15));
85         getContentPane().add(infoPanel, BorderLayout.CENTER);
86
87         /*
88          * Creates the bottom panel of the dialog which will hold the calogo image,
89          * a blank spacing label and the button panel
90          */

91         bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
92         bottomPanel.setBackground(Color.white);
93         caLogoLabel = new JLabel(caLogoImage);
94         caLogoLabel.setToolTipText("i am ca");
95
96         caLogoLabel.addMouseListener(new MouseAdapter()
97         {
98             /**
99              * Sets the cursor to the hand cursor when the mouse is over
100              * the CA logo.
101              */

102             public void mouseEntered(MouseEvent e)
103             {
104                 CBUtility.setHandCursor((Component) caLogoLabel);
105             }
106
107             /**
108              * Sets the cursor back to the normal cursor when the mouse is over
109              * the CA logo.
110              */

111             public void mouseExited(MouseEvent e)
112             {
113                 CBUtility.setNormalCursor((Component) caLogoLabel);
114             }
115
116             /**
117              * Kicks off the CA web site in the default browser when the CA logo is clicked.
118              */

119             public void mouseClicked(MouseEvent e)
120             {
121                 iAmCa();
122             }
123         });
124         bottomPanel.add(caLogoLabel);
125         bottomPanel.add(new JLabel(" "));
126
127         /*
128          * Creates a panel that places the ok button down the bottom right of the Dialog
129          * and will hide the dialog when pressed
130          */

131         buttonsPanel = new JPanel(new FlowLayout());
132         buttonsPanel.setBackground(Color.white);
133
134         //blank labels to move the ok button down to the bottom of the screen
135
buttonsPanel.add(new JLabel(""));
136         buttonsPanel.add(new JLabel(""));
137
138         okButton = new CBButton(okButtonMessage, okButtonTooltip);
139         okButton.addActionListener(new ActionListener()
140         {
141             public void actionPerformed(ActionEvent e)
142             {
143                 setVisible(false);
144             }
145         });
146         buttonsPanel.add(okButton);
147         bottomPanel.add(buttonsPanel);
148         getContentPane().add(bottomPanel, BorderLayout.SOUTH);
149     }
150
151
152     /**
153      * Attempts to launch the CA website in the users default browser.
154      * If the os is not windows it will ask the user to locate the default broswer.
155      */

156
157     public void iAmCa()
158     {
159         if (System.getProperty("os.name").indexOf("Windows") >= 0)
160             CBLauncher.launchProgram(".html", URL);
161         else
162         {
163
164             String JavaDoc browserName;
165
166             //Set up a FileDialog for the user to locate the browser to use.
167
FileDialog fileDialog = new FileDialog(owner);
168             fileDialog.setMode(FileDialog.LOAD);
169             fileDialog.setTitle("Choose the browser to use:");
170             fileDialog.setVisible(true);
171
172             //Retrieve the path information from the dialog and verify it.
173
String JavaDoc resultPath = fileDialog.getDirectory();
174             String JavaDoc resultFile = fileDialog.getFile();
175             if (resultPath != null && resultPath.length() != 0 && resultFile != null && resultFile.length() != 0)
176             {
177                 File JavaDoc file = new File JavaDoc(resultPath + resultFile);
178                 if (file != null)
179                 {
180                     browserName = file.getPath();
181
182                     try
183                     {
184                         //Launch the browser and pass it the desired URL
185
Runtime.getRuntime().exec(new String JavaDoc[]{browserName, URL});
186                     }
187                     catch (IOException JavaDoc exc)
188                     {
189                         exc.printStackTrace();
190                     }
191                 }
192             }
193         }
194     }
195 }
Popular Tags