001 /* 002 Copyright (C) 2003 Adam Olsen 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU General Public License as published by 006 the Free Software Foundation; either version 1, or (at your option) 007 any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 017 */ 018 019 package com.valhalla.jbother; 020 021 import java.awt.*; 022 import java.awt.event.*; 023 import java.util.*; 024 import java.text.*; 025 026 import javax.swing.*; 027 import java.io.*; 028 029 import com.valhalla.gui.*; 030 import com.valhalla.jbother.*; 031 032 033 /** 034 * This obiously displays an about dialog with the credits for JBother 035 * 036 * @author Adam Olsen 037 * @version 1.0 038 **/ 039 public class AboutDialog extends JDialog 040 { 041 private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle" ); 042 private JButton okButton = new JButton( resources.getString( "okButton" ) ); 043 private JButton creditsButton = new JButton( resources.getString( "creditsButton" ) ); 044 private JTextPane textPane = new JTextPane(); 045 private JScrollPane scrollPane = new JScrollPane( textPane ); 046 private JPanel middlePanel = new JPanel( new BorderLayout() ); 047 private JPanel version; 048 private JLabel imageLabel = new JLabel( Standard.getIcon( "images/splashimage.png" ) ); 049 private JPanel buttonPanel = new JPanel(); 050 private JPanel mainPanel; 051 private JPanel container = new JPanel( new BorderLayout() ); 052 private boolean credits = false; 053 private AboutDialog thisPointer = this; 054 055 /** 056 * Sets up the Visual components 057 */ 058 public AboutDialog() 059 { 060 super( (Frame)null, "About JBother", false ); 061 setTitle( resources.getString( "aboutDialogTitle" ) ); 062 063 mainPanel = (JPanel)getContentPane(); 064 container.setLayout( new BorderLayout() ); 065 container.setBorder( BorderFactory.createEmptyBorder( 0, 15, 15, 15 ) ); 066 mainPanel.setBorder( BorderFactory.createTitledBorder( "About JBother" ) ); 067 068 buttonPanel.setLayout( new BoxLayout( buttonPanel, BoxLayout.X_AXIS ) ); 069 buttonPanel.add( Box.createHorizontalGlue() ); 070 buttonPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); 071 buttonPanel.add( okButton ); 072 buttonPanel.add( creditsButton ); 073 buttonPanel.add( Box.createHorizontalGlue() ); 074 075 createVersionPanel(); 076 middlePanel.add( version, BorderLayout.NORTH ); 077 078 container.add( imageLabel, BorderLayout.NORTH ); 079 container.add( middlePanel, BorderLayout.CENTER ); 080 mainPanel.add( buttonPanel, BorderLayout.SOUTH ); 081 082 mainPanel.add( container, BorderLayout.CENTER ); 083 084 imageLabel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 10, 5 ) ); 085 textPane.setEditable( false ); 086 087 // load in the application credits 088 InputStream file = getClass().getClassLoader().getResourceAsStream( "credits.txt" ); 089 InputStreamReader in = new InputStreamReader( file ); 090 BufferedReader reader = new BufferedReader( in ); 091 StringBuffer buffer = new StringBuffer(); 092 String line; 093 094 try { 095 096 while( ( line = reader.readLine() ) != null ) 097 { 098 buffer.append( line + "\n" ); 099 } 100 101 in.close(); 102 } 103 catch( IOException e ) { com.valhalla.Logger.debug( "Couldn't fread credits file." ); } 104 105 textPane.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) ); 106 textPane.setText( buffer.toString() ); 107 textPane.setCaretPosition( 0 ); 108 109 final AboutDialog thisPointer = this; 110 111 okButton.addActionListener( new ActionListener() 112 { 113 public void actionPerformed( ActionEvent e ) 114 { 115 DialogTracker.removeDialog( thisPointer ); 116 } 117 } ); 118 119 creditsButton.addActionListener( new ActionListener() 120 { 121 public void actionPerformed( ActionEvent e ) 122 { 123 changeHandler(); 124 } 125 } ); 126 127 pack(); 128 setLocationRelativeTo( null ); 129 setResizable( false ); 130 131 DialogTracker.addDialog( this, true, true ); 132 } 133 134 /** 135 * Toggles back and forth between showing the logo and version information and 136 * showing the application credits 137 */ 138 private void changeHandler() 139 { 140 if( !credits ) 141 { 142 mainPanel.remove( container ); 143 mainPanel.add( scrollPane ); 144 145 creditsButton.setText( resources.getString( "info" ) ); 146 mainPanel.setBorder( BorderFactory.createTitledBorder( "JBother Credits" ) ); 147 148 credits = true; 149 } 150 else { 151 mainPanel.remove( scrollPane ); 152 mainPanel.add( container ); 153 154 creditsButton.setText( resources.getString( "creditsButton" ) ); 155 mainPanel.setBorder( BorderFactory.createTitledBorder( "About JBother" ) ); 156 157 credits = false; 158 } 159 160 buttonPanel.repaint(); 161 mainPanel.repaint(); 162 validate(); 163 } 164 165 /** 166 * Creates a panel containing all of the Runtime version information 167 */ 168 private void createVersionPanel() 169 { 170 version = new JPanel(); 171 ResourceBundle bundle = ResourceBundle.getBundle( "buildid" ); 172 173 version.setLayout( new GridLayout( 0, 2 ) ); 174 addItem( "JBother Version", com.valhalla.jbother.JBother.JBOTHER_VERSION ); 175 addItem( "Build ID", bundle.getString( "build.number" ) ); 176 addItem( "Created By", "Adam Olsen" ); 177 addItem( "Smack Version", org.jivesoftware.smack.SmackConfiguration.getVersion() ); 178 addItem( "Host Operating System", System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" ) ); 179 addItem( "Host System Architecture", System.getProperty( "os.arch" ) ); 180 addItem( "Java Version", System.getProperty( "java.version" ) ); 181 addItem( "Java Vendor", System.getProperty( "java.vendor" ) ); 182 } 183 184 /** 185 * Adds a text label and a value 186 * @param name the label name 187 * @param the value 188 */ 189 private void addItem( String name, String value ) 190 { 191 UIDefaults ui = UIManager.getDefaults(); 192 193 Font newFont = (Font)ui.get( "Label.font" ); 194 195 JLabel nameLabel = new JLabel( name + ": ", SwingConstants.RIGHT ); 196 nameLabel.setFont( new Font( newFont.getName(), Font.BOLD, newFont.getSize() ) ); 197 198 JLabel valueLabel = new JLabel( value ); 199 version.add( nameLabel ); 200 version.add( valueLabel ); 201 } 202 }