View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is eXchaNGeR browser code. (org.xngr.browser.*)
14   *
15   * The Initial Developer of the Original Code is Cladonia Ltd.. Portions created 
16   * by the Initial Developer are Copyright (C) 2002 the Initial Developer. 
17   * All Rights Reserved. 
18   *
19   * Contributor(s): Edwin Dankert <edankert@cladonia.com>
20   */
21  package org.xmlhammer.gui;
22  
23  import java.awt.BorderLayout;
24  import java.awt.Color;
25  import java.awt.Dimension;
26  import java.awt.Font;
27  import java.awt.event.ActionEvent;
28  import java.awt.event.ActionListener;
29  import java.io.File;
30  
31  import javax.swing.Box;
32  import javax.swing.ImageIcon;
33  import javax.swing.JButton;
34  import javax.swing.JFrame;
35  import javax.swing.JLabel;
36  import javax.swing.JPanel;
37  import javax.swing.SwingConstants;
38  import javax.swing.border.CompoundBorder;
39  import javax.swing.border.EmptyBorder;
40  import javax.swing.border.LineBorder;
41  
42  import org.apache.log4j.Logger;
43  import org.bounce.FormLayout;
44  import org.bounce.LinkButton;
45  import org.bounce.QDialog;
46  import org.bounce.QPanel;
47  import org.bounce.image.ImageLoader;
48  import org.bounce.util.URIUtils;
49  import org.xmlhammer.Identity;
50  import org.xmlhammer.gui.util.ExternalApplicationLauncher;
51  
52  /***
53   * The dialog that shows the XML Hammer's identity.
54   *
55   * @version $Revision$, $Date$
56   * @author Edwin Dankert <edankert@cladonia.com>
57   */
58  public class AboutDialog extends QDialog {
59  	private static final long serialVersionUID = 6635348408738189991L;
60  
61      private static final ImageIcon LOG_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/view16/error_log.gif");
62  
63      private static final Dimension SIZE = new Dimension( 450, 220);
64  	LinkButton referenceField  = null;
65  
66  	/***
67  	 * The constructor for the about dialog.
68  	 *
69  	 * @param frame the parent frame.
70  	 */
71  	public AboutDialog( JFrame frame) {
72  		super( frame, false);
73  		
74  		setResizable( false);
75  		
76  		setSize( SIZE);
77  		
78  		setTitle( "About XML Hammer");
79  		
80  		QPanel formpanel = new QPanel( new FormLayout( 5, 3));
81  		formpanel.setBorder( 
82  					new CompoundBorder( 
83  						new LineBorder( Color.darkGray),
84  						new EmptyBorder( 5, 5, 5, 5)));
85  
86  		formpanel.setGradientBackground( true);
87  		
88  		ImageIcon icon = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/hammer.gif");
89  		Identity identity = Identity.getInstance();
90  		
91  		JPanel contentPane = new JPanel( new BorderLayout());
92  		
93  		JLabel titleField = new JLabel( identity.getTitle());
94  		Font prevFont = titleField.getFont();
95  		titleField.setFont( new Font( prevFont.getFontName(), Font.BOLD, prevFont.getSize() + 8));
96  
97  		JLabel descriptionField = new JLabel( identity.getDescription());
98  		JLabel versionField = new JLabel( "Version: "+identity.getVersion());
99  
100 		referenceField = new LinkButton( identity.getReference());
101 		referenceField.setHorizontalAlignment( SwingConstants.CENTER);
102 		referenceField.setForeground( Color.blue);
103 		referenceField.addActionListener( new ActionListener() {
104 			public void actionPerformed( ActionEvent e) {
105 				try {
106 					ExternalApplicationLauncher.getInstance().browse(URIUtils.createURI(referenceField.getText()));
107 				} catch(Exception ex) {
108 					Logger.getLogger("org.xmlhammer.gui.AboutDialog").debug(ex);
109 				}
110 			}
111 		});
112 
113 		JLabel copyrightField = new JLabel( identity.getCopyright());
114 		copyrightField.setHorizontalAlignment( SwingConstants.CENTER);
115 
116 		JLabel iconField = new JLabel( icon);
117 		iconField.setBorder( new EmptyBorder( 0, 10, 0, 10));
118 		
119 		Box descriptionPanel = Box.createVerticalBox();
120 //		descriptionPanel.setOpaque( false);
121 		descriptionPanel.add( titleField);
122 		descriptionPanel.add( descriptionField);
123 		descriptionPanel.add( versionField);
124 		
125 		JPanel productPanel = new JPanel( new BorderLayout());
126 	
127 		productPanel.setOpaque( false);
128 		productPanel.add( descriptionPanel, BorderLayout.CENTER);
129 		productPanel.add( iconField, BorderLayout.EAST);
130 		productPanel.setBorder( new EmptyBorder( 5, 5, 10, 5));
131 
132         JButton logButton = new JButton("Error Log");
133         logButton.setIcon(LOG_ICON);
134         logButton.addActionListener( new ActionListener() {
135             public void actionPerformed( ActionEvent e) {
136                 ExternalApplicationLauncher.getInstance().browse((new File(XMLHammer.HTML_LOG)).toURI());
137             }
138         });
139 
140         JButton closeButton = new JButton("Close");
141 		
142 		closeButton.addActionListener(new ActionListener() {
143 			public void actionPerformed( ActionEvent e) {
144 				close();
145 			}
146 		});
147 		
148 		contentPane.setBorder(new EmptyBorder( 2, 2, 2, 2));
149 		
150 		copyrightField.setBorder(new EmptyBorder( 10, 0, 0, 0));
151 		
152 		JPanel buttonPanel = new JPanel(new BorderLayout());
153 		buttonPanel.setBorder(new EmptyBorder(5, 5, 3, 5));
154 		buttonPanel.add(closeButton, BorderLayout.EAST);
155         buttonPanel.add(logButton, BorderLayout.WEST);
156 
157 		formpanel.add(productPanel, FormLayout.FULL_FILL);
158 		formpanel.add(referenceField, FormLayout.FULL_FILL);
159 		formpanel.add(copyrightField, FormLayout.FULL_FILL);
160 
161 		contentPane.add(formpanel, BorderLayout.CENTER);
162 		contentPane.add(buttonPanel, BorderLayout.SOUTH);
163 		
164 		setContentPane(contentPane);
165 		
166 		getRootPane().setDefaultButton(closeButton);
167 		setDefaultCloseOperation(HIDE_ON_CLOSE);
168 	}
169 }