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.BorderLayout;
022    import java.awt.Font;
023    import java.awt.Frame;
024    import java.awt.GridLayout;
025    import java.awt.event.ActionEvent;
026    import java.awt.event.ActionListener;
027    import java.io.BufferedReader;
028    import java.io.IOException;
029    import java.io.InputStream;
030    import java.io.InputStreamReader;
031    import java.util.ResourceBundle;
032    
033    import javax.swing.BorderFactory;
034    import javax.swing.Box;
035    import javax.swing.BoxLayout;
036    import javax.swing.JButton;
037    import javax.swing.JDialog;
038    import javax.swing.JLabel;
039    import javax.swing.JPanel;
040    import javax.swing.JScrollPane;
041    import javax.swing.JTextPane;
042    import javax.swing.SwingConstants;
043    import javax.swing.UIDefaults;
044    import javax.swing.UIManager;
045    
046    import com.valhalla.gui.DialogTracker;
047    import com.valhalla.gui.Standard;
048    import com.valhalla.pluginmanager.PluginLoader;
049    
050    /**
051     * This obiously displays an about dialog with the credits for JBother
052     *
053     * @author Adam Olsen
054     * @version 1.0
055     */
056    public class AboutDialog extends JDialog {
057        private ResourceBundle resources = ResourceBundle
058                .getBundle("JBotherBundle");
059    
060        private JButton okButton = new JButton(resources.getString("okButton"));
061    
062        private JButton creditsButton = new JButton(resources
063                .getString("creditsButton"));
064    
065        private JTextPane textPane = new JTextPane();
066    
067        private JScrollPane scrollPane = new JScrollPane(textPane);
068    
069        private JPanel middlePanel = new JPanel(new BorderLayout());
070    
071        private JPanel version;
072    
073        private JLabel imageLabel = new JLabel(Standard
074                .getIcon("images/splashimage.png"));
075    
076        private JPanel buttonPanel = new JPanel();
077    
078        private JPanel mainPanel;
079    
080        private JPanel container = new JPanel(new BorderLayout());
081    
082        private boolean credits = false;
083    
084        /**
085         * Sets up the Visual components
086         */
087        public AboutDialog() {
088            super(BuddyList.getInstance().getContainerFrame(), "About JBother", false);
089            setTitle(resources.getString("aboutDialogTitle"));
090    
091            mainPanel = (JPanel) getContentPane();
092            container.setLayout(new BorderLayout());
093            container.setBorder(BorderFactory.createEmptyBorder(0, 15, 15, 15));
094            mainPanel.setBorder(BorderFactory.createTitledBorder(resources
095                    .getString("aboutDialogTitle")));
096    
097            buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
098            buttonPanel.add(Box.createHorizontalGlue());
099            buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
100            buttonPanel.add(okButton);
101            buttonPanel.add(creditsButton);
102            buttonPanel.add(Box.createHorizontalGlue());
103    
104            createVersionPanel();
105            middlePanel.add(version, BorderLayout.NORTH);
106    
107            container.add(imageLabel, BorderLayout.NORTH);
108            container.add(middlePanel, BorderLayout.CENTER);
109            mainPanel.add(buttonPanel, BorderLayout.SOUTH);
110    
111            mainPanel.add(container, BorderLayout.CENTER);
112    
113            imageLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
114            textPane.setEditable(false);
115    
116            // load in the application credits
117            InputStream file = getClass().getClassLoader().getResourceAsStream(
118                    "credits.txt");
119            InputStreamReader in = new InputStreamReader(file);
120            BufferedReader reader = new BufferedReader(in);
121            StringBuffer buffer = new StringBuffer();
122            String line;
123    
124            try {
125    
126                while ((line = reader.readLine()) != null) {
127                    buffer.append(line + "\n");
128                }
129    
130                file.close();
131            } catch (IOException e) {
132                com.valhalla.Logger.debug("Couldn't fread credits file.");
133            }
134    
135            textPane.setFont(new Font("Monospaced", Font.PLAIN, 12));
136            textPane.setText(buffer.toString());
137            textPane.setCaretPosition(0);
138    
139            okButton.addActionListener(new ActionListener() {
140                public void actionPerformed(ActionEvent e) {
141                    DialogTracker.removeDialog(AboutDialog.this);
142                }
143            });
144    
145            creditsButton.addActionListener(new ActionListener() {
146                public void actionPerformed(ActionEvent e) {
147                    changeHandler();
148                }
149            });
150    
151            pack();
152            setLocationRelativeTo(null);
153            setResizable(false);
154    
155            DialogTracker.addDialog(this, true, true);
156         }
157    
158        /**
159         * Toggles back and forth between showing the logo and version information
160         * and showing the application credits
161         */
162        private void changeHandler() {
163            if (!credits) {
164                mainPanel.remove(container);
165                mainPanel.add(scrollPane);
166    
167                creditsButton.setText(resources.getString("info"));
168                mainPanel.setBorder(BorderFactory.createTitledBorder(resources
169                        .getString("creditsButton")));
170    
171                credits = true;
172            } else {
173                mainPanel.remove(scrollPane);
174                mainPanel.add(container);
175    
176                creditsButton.setText(resources.getString("creditsButton"));
177                mainPanel.setBorder(BorderFactory.createTitledBorder(resources
178                        .getString("aboutDialogTitle")));
179    
180                credits = false;
181            }
182    
183            buttonPanel.repaint();
184            mainPanel.repaint();
185            validate();
186        }
187    
188        /**
189         * Creates a panel containing all of the Runtime version information
190         */
191        private void createVersionPanel() {
192            version = new JPanel();
193            ResourceBundle bundle = ResourceBundle.getBundle("buildid");
194    
195            version.setLayout(new GridLayout(0, 2));
196            addItem(resources.getString("aboutJbotherVersion"),
197                    com.valhalla.jbother.JBother.JBOTHER_VERSION);
198            addItem(resources.getString("aboutBildId"), bundle
199                    .getString("build.number"));
200            addItem(resources.getString("aboutCreatedBy"), "Adam Olsen");
201            addItem(resources.getString("aboutPluginApiVersion"), PluginLoader
202                    .getAPIVersion()
203                    + "");
204            addItem(resources.getString("aboutSmackVersion"),
205                    org.jivesoftware.smack.SmackConfiguration.getVersion());
206            addItem(resources.getString("aboutHostOperatingSystem"), System
207                    .getProperty("os.name")
208                    + " " + System.getProperty("os.version"));
209            addItem(resources.getString("aboutHostSystemArchitecture"), System
210                    .getProperty("os.arch"));
211            addItem(resources.getString("aboutJavaVersion"), System
212                    .getProperty("java.version"));
213            addItem(resources.getString("aboutJavaVendor"), System
214                    .getProperty("java.vendor"));
215        }
216    
217        /**
218         * Adds a text label and a value
219         *
220         * @param name
221         *            the label name
222         * @param the
223         *            value
224         */
225        private void addItem(String name, String value) {
226            UIDefaults ui = UIManager.getDefaults();
227    
228            Font newFont = (Font) ui.get("Label.font");
229    
230            JLabel nameLabel = new JLabel(name + ":  ", SwingConstants.RIGHT);
231            nameLabel.setFont(new Font(newFont.getName(), Font.BOLD, newFont
232                    .getSize()));
233    
234            JLabel valueLabel = new JLabel(value);
235            version.add(nameLabel);
236            version.add(valueLabel);
237        }
238    }