Coverage Report - org.xmlhammer.gui.AboutDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
AboutDialog
87% 
N/A 
1.25
 
 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  22
     private static final ImageIcon LOG_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/view16/error_log.gif");
 62  
 
 63  22
     private static final Dimension SIZE = new Dimension( 450, 220);
 64  220
         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  220
                 super( frame, false);
 73  
                 
 74  220
                 setResizable( false);
 75  
                 
 76  220
                 setSize( SIZE);
 77  
                 
 78  220
                 setTitle( "About XML Hammer");
 79  
                 
 80  220
                 QPanel formpanel = new QPanel( new FormLayout( 5, 3));
 81  220
                 formpanel.setBorder( 
 82  
                                         new CompoundBorder( 
 83  
                                                 new LineBorder( Color.darkGray),
 84  
                                                 new EmptyBorder( 5, 5, 5, 5)));
 85  
 
 86  220
                 formpanel.setGradientBackground( true);
 87  
                 
 88  220
                 ImageIcon icon = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/hammer.gif");
 89  220
                 Identity identity = Identity.getInstance();
 90  
                 
 91  220
                 JPanel contentPane = new JPanel( new BorderLayout());
 92  
                 
 93  220
                 JLabel titleField = new JLabel( identity.getTitle());
 94  220
                 Font prevFont = titleField.getFont();
 95  220
                 titleField.setFont( new Font( prevFont.getFontName(), Font.BOLD, prevFont.getSize() + 8));
 96  
 
 97  220
                 JLabel descriptionField = new JLabel( identity.getDescription());
 98  220
                 JLabel versionField = new JLabel( "Version: "+identity.getVersion());
 99  
 
 100  220
                 referenceField = new LinkButton( identity.getReference());
 101  220
                 referenceField.setHorizontalAlignment( SwingConstants.CENTER);
 102  220
                 referenceField.setForeground( Color.blue);
 103  220
                 referenceField.addActionListener( new ActionListener() {
 104  220
                         public void actionPerformed( ActionEvent e) {
 105  
                                 try {
 106  0
                                         ExternalApplicationLauncher.getInstance().browse(URIUtils.createURI(referenceField.getText()));
 107  0
                                 } catch(Exception ex) {
 108  0
                                         Logger.getLogger("org.xmlhammer.gui.AboutDialog").debug(ex);
 109  0
                                 }
 110  0
                         }
 111  
                 });
 112  
 
 113  220
                 JLabel copyrightField = new JLabel( identity.getCopyright());
 114  220
                 copyrightField.setHorizontalAlignment( SwingConstants.CENTER);
 115  
 
 116  220
                 JLabel iconField = new JLabel( icon);
 117  220
                 iconField.setBorder( new EmptyBorder( 0, 10, 0, 10));
 118  
                 
 119  220
                 Box descriptionPanel = Box.createVerticalBox();
 120  
 //                descriptionPanel.setOpaque( false);
 121  220
                 descriptionPanel.add( titleField);
 122  220
                 descriptionPanel.add( descriptionField);
 123  220
                 descriptionPanel.add( versionField);
 124  
                 
 125  220
                 JPanel productPanel = new JPanel( new BorderLayout());
 126  
         
 127  220
                 productPanel.setOpaque( false);
 128  220
                 productPanel.add( descriptionPanel, BorderLayout.CENTER);
 129  220
                 productPanel.add( iconField, BorderLayout.EAST);
 130  220
                 productPanel.setBorder( new EmptyBorder( 5, 5, 10, 5));
 131  
 
 132  220
         JButton logButton = new JButton("Error Log");
 133  220
         logButton.setIcon(LOG_ICON);
 134  220
         logButton.addActionListener( new ActionListener() {
 135  220
             public void actionPerformed( ActionEvent e) {
 136  0
                 ExternalApplicationLauncher.getInstance().browse((new File(XMLHammer.HTML_LOG)).toURI());
 137  0
             }
 138  
         });
 139  
 
 140  220
         JButton closeButton = new JButton("Close");
 141  
                 
 142  220
                 closeButton.addActionListener(new ActionListener() {
 143  220
                         public void actionPerformed( ActionEvent e) {
 144  0
                                 close();
 145  0
                         }
 146  
                 });
 147  
                 
 148  220
                 contentPane.setBorder(new EmptyBorder( 2, 2, 2, 2));
 149  
                 
 150  220
                 copyrightField.setBorder(new EmptyBorder( 10, 0, 0, 0));
 151  
                 
 152  220
                 JPanel buttonPanel = new JPanel(new BorderLayout());
 153  220
                 buttonPanel.setBorder(new EmptyBorder(5, 5, 3, 5));
 154  220
                 buttonPanel.add(closeButton, BorderLayout.EAST);
 155  220
         buttonPanel.add(logButton, BorderLayout.WEST);
 156  
 
 157  220
                 formpanel.add(productPanel, FormLayout.FULL_FILL);
 158  220
                 formpanel.add(referenceField, FormLayout.FULL_FILL);
 159  220
                 formpanel.add(copyrightField, FormLayout.FULL_FILL);
 160  
 
 161  220
                 contentPane.add(formpanel, BorderLayout.CENTER);
 162  220
                 contentPane.add(buttonPanel, BorderLayout.SOUTH);
 163  
                 
 164  220
                 setContentPane(contentPane);
 165  
                 
 166  220
                 getRootPane().setDefaultButton(closeButton);
 167  220
                 setDefaultCloseOperation(HIDE_ON_CLOSE);
 168  220
         }
 169  
 }