1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: AboutPane.java 2105 2011-03-07 21:13:31Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.desktop;
23  
24  import gnu.gpl.License;
25  
26  import java.awt.BorderLayout;
27  import java.awt.Component;
28  import java.awt.Dimension;
29  import java.awt.Font;
30  import java.awt.Frame;
31  import java.awt.event.WindowAdapter;
32  import java.awt.event.WindowEvent;
33  
34  import javax.swing.BorderFactory;
35  import javax.swing.Icon;
36  import javax.swing.JButton;
37  import javax.swing.JDialog;
38  import javax.swing.JLabel;
39  import javax.swing.JOptionPane;
40  import javax.swing.JPanel;
41  import javax.swing.JScrollPane;
42  import javax.swing.JTabbedPane;
43  import javax.swing.JTable;
44  import javax.swing.JTextPane;
45  import javax.swing.SwingConstants;
46  import javax.swing.text.html.HTMLEditorKit;
47  
48  import org.crosswire.bibledesktop.BDMsg;
49  import org.crosswire.common.swing.ActionFactory;
50  import org.crosswire.common.swing.AntiAliasedTextPane;
51  import org.crosswire.common.swing.CWAction;
52  import org.crosswire.common.swing.CWScrollPane;
53  import org.crosswire.common.swing.GuiUtil;
54  import org.crosswire.common.swing.MapTableModel;
55  import org.crosswire.common.util.CollectionUtil;
56  
57  /**
58   * AboutPane is a window that contains various advanced user tools in one place.
59   * 
60   * @see gnu.gpl.License for license details.<br>
61   *      The copyright to this program is held by it's authors.
62   * @author Joe Walker [joe at eireneh dot com]
63   */
64  public class AboutPane {
65      /**
66       * Basic constructor
67       */
68      public AboutPane() {
69          init();
70      }
71  
72      /**
73       * Build the GUI components
74       */
75      private void init() {
76          // TRANSLATOR: This image is of an English Bible. It can be replaced with a localized one.
77          // It should be named splash_ll.png where ll is the 2 letter language code and put in the
78          // images directory. Then point this to it.
79          Icon icon = GuiUtil.getIcon(BDMsg.gettext("/images/splash.png"));
80  
81          JLabel lblPicture = new JLabel();
82          lblPicture.setIcon(icon);
83          lblPicture.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
84          lblPicture.setHorizontalAlignment(SwingConstants.CENTER);
85          lblPicture.setVerticalAlignment(SwingConstants.CENTER);
86  
87          JLabel lblInfo = new JLabel();
88          lblInfo.setFont(new Font(SPLASH_FONT, 1, 14));
89          lblInfo.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
90          lblInfo.setOpaque(true);
91          lblInfo.setHorizontalAlignment(SwingConstants.TRAILING);
92          lblInfo.setText(BDMsg.getVersionInfo());
93  
94          ActionFactory actions = new ActionFactory(this);
95          // TRANSLATOR: This is the text of an "OK" button that dismisses the dialog
96          CWAction action = actions.addAction("AboutOK", BDMsg.gettext("OK"));
97          // TRANSLATOR: This is the tooltip for an "OK" button that dismisses the dialog
98          action.setTooltip(BDMsg.gettext("Close this window"));
99          JButton btnOk = new JButton(action);
100 
101         JPanel pnlButtons = new JPanel();
102         pnlButtons.add(btnOk);
103 
104         pnlMain = new JPanel();
105         pnlMain.setLayout(new BorderLayout(5, 5));
106         pnlMain.add(pnlButtons, BorderLayout.SOUTH);
107         pnlMain.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
108         // Create and add the splash tab
109         JPanel pnlSplash = new JPanel();
110         pnlSplash.setLayout(new BorderLayout(5, 0));
111         pnlSplash.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
112         pnlSplash.add(lblPicture, BorderLayout.CENTER);
113         pnlSplash.add(lblInfo, BorderLayout.SOUTH);
114 
115         JTabbedPane tabMain = new JTabbedPane();
116         pnlMain.add(tabMain, BorderLayout.CENTER);
117 
118         // Add the splash
119         String appName = BDMsg.getApplicationTitle();
120         tabMain.add(pnlSplash, appName);
121 
122         License license = new License(appName);
123         //        Font fixedFont = new Font("Monospaced", 0, 18);
124         JTextPane warranty = new AntiAliasedTextPane();
125         // warranty.setFont(fixedFont);
126         warranty.setEditable(false);
127         warranty.setEditorKit(new HTMLEditorKit());
128         warranty.setText(license.getWarranty());
129         warranty.setCaretPosition(0);
130         JScrollPane warrantyScr = new CWScrollPane(warranty);
131         warrantyScr.setPreferredSize(new Dimension(500, 300));
132         JPanel warrantyPnl = new JPanel(new BorderLayout());
133         warrantyPnl.add(warrantyScr, BorderLayout.CENTER);
134         warrantyPnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
135         // TRANSLATOR: The label for the tab that shows BibleDesktop's GPL Non-Warranty
136         tabMain.add(warrantyPnl, BDMsg.gettext("Warranty"));
137 
138         JTextPane details = new AntiAliasedTextPane();
139         // details.setFont(fixedFont);
140         details.setEditable(false);
141         details.setEditorKit(new HTMLEditorKit());
142         details.setText(license.getDetails());
143         details.setCaretPosition(0);
144         JScrollPane detailScr = new CWScrollPane(details);
145         detailScr.setPreferredSize(new Dimension(500, 300));
146         JPanel detailsPnl = new JPanel(new BorderLayout());
147         detailsPnl.add(detailScr, BorderLayout.CENTER);
148         detailsPnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
149         // TRANSLATOR: The label for the tab that shows BibleDesktop's GPL License
150         tabMain.add(detailsPnl, BDMsg.gettext("License"));
151 
152         // Put in tabs if advanced
153         if (advanced) {
154             // create and add the System Properties tab
155             JTable tblProps = new JTable();
156             MapTableModel mdlProps = new MapTableModel(CollectionUtil.properties2Map(System.getProperties()));
157             tblProps.setModel(mdlProps);
158 
159             JScrollPane scrProps = new CWScrollPane(tblProps);
160             scrProps.setPreferredSize(new Dimension(500, 300));
161 
162             JPanel pnlProps = new JPanel();
163             pnlProps.setLayout(new BorderLayout());
164             pnlProps.add(scrProps, BorderLayout.CENTER);
165             pnlProps.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
166             // TRANSLATOR: The label for the tab that shows Java's System Properties.
167             // This is an advanced option not intended for end users.
168             tabMain.add(pnlProps, BDMsg.gettext("System Properties"));
169         }
170         GuiUtil.applyDefaultOrientation(pnlMain);
171     }
172 
173     /**
174      * Close this dialog
175      */
176     public void doAboutOK() {
177         if (dlgMain != null) {
178             dlgMain.dispose();
179             dlgMain = null;
180         }
181     }
182 
183     /**
184      * A method to be exposed by our children
185      * 
186      * @param parent
187      *            The component to which to attach the new dialog
188      */
189     public void showInDialog(Component parent) {
190         Frame root = JOptionPane.getFrameForComponent(parent);
191         dlgMain = new JDialog(root);
192 
193         dlgMain.getContentPane().add(pnlMain);
194         dlgMain.setTitle(BDMsg.getAboutInfo());
195         dlgMain.setModal(true);
196         dlgMain.addWindowListener(new WindowAdapter() {
197             /* (non-Javadoc)
198              * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
199              */
200             @Override
201             public void windowClosed(WindowEvent ev) {
202                 doAboutOK();
203             }
204         });
205         GuiUtil.applyDefaultOrientation(dlgMain);
206         dlgMain.pack();
207         dlgMain.setLocationRelativeTo(parent);
208         dlgMain.setVisible(true);
209     }
210 
211     /**
212      * @return Returns whether the window should show an advanced view.
213      */
214     public static synchronized boolean isAdvanced() {
215         return advanced;
216     }
217 
218     /**
219      * @param advanced
220      *            Turn on an advanced view of the window.
221      */
222     public static synchronized void setAdvanced(boolean advanced) {
223         AboutPane.advanced = advanced;
224     }
225 
226     private static final String SPLASH_FONT = "SanSerif";
227 
228     private static boolean advanced;
229     private JDialog dlgMain;
230     private JPanel pnlMain;
231 }
232