1
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
64 public class AboutPane {
65
68 public AboutPane() {
69 init();
70 }
71
72
75 private void init() {
76 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 CWAction action = actions.addAction("AboutOK", BDMsg.gettext("OK"));
97 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 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 String appName = BDMsg.getApplicationTitle();
120 tabMain.add(pnlSplash, appName);
121
122 License license = new License(appName);
123 JTextPane warranty = new AntiAliasedTextPane();
125 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 tabMain.add(warrantyPnl, BDMsg.gettext("Warranty"));
137
138 JTextPane details = new AntiAliasedTextPane();
139 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 tabMain.add(detailsPnl, BDMsg.gettext("License"));
151
152 if (advanced) {
154 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 tabMain.add(pnlProps, BDMsg.gettext("System Properties"));
169 }
170 GuiUtil.applyDefaultOrientation(pnlMain);
171 }
172
173
176 public void doAboutOK() {
177 if (dlgMain != null) {
178 dlgMain.dispose();
179 dlgMain = null;
180 }
181 }
182
183
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
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
214 public static synchronized boolean isAdvanced() {
215 return advanced;
216 }
217
218
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