Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/launch/AboutBox.java


1   /*
2   ================================================================================
3   
4     FILE:  AboutBox.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      About box.
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.launch;
43  
44  
45  import java.io.IOException;
46  import java.util.Iterator;
47  import java.util.Set;
48  import java.awt.Container;
49  import java.awt.Font;
50  import java.awt.Color;
51  import java.awt.Frame;
52  import java.awt.Dialog;
53  import java.awt.FlowLayout;
54  import java.awt.BorderLayout;
55  import java.awt.GridBagLayout;
56  import java.awt.GridBagConstraints;
57  import java.awt.Rectangle;
58  import java.awt.Insets;
59  import java.awt.event.ActionListener;
60  import java.awt.event.ActionEvent;
61  import java.awt.event.WindowAdapter;
62  import java.awt.event.WindowEvent;
63  import java.awt.event.ComponentAdapter;
64  import java.awt.event.ComponentEvent;
65  import javax.swing.JComponent;
66  import javax.swing.JDialog;
67  import javax.swing.JPanel;
68  import javax.swing.JLabel;
69  import javax.swing.JButton;
70  import javax.swing.JTabbedPane;
71  import javax.swing.JScrollPane;
72  import javax.swing.JScrollBar;
73  import javax.swing.JTextArea;
74  import javax.swing.JEditorPane;
75  import javax.swing.JSeparator;
76  import javax.swing.BorderFactory;
77  import javax.swing.SwingUtilities;
78  
79  import com.virtuosotechnologies.lib.util.FileUtils;
80  import com.virtuosotechnologies.lib.swing.ScrollablePanel;
81  import com.virtuosotechnologies.lib.plugin.Framework;
82  
83  
84  /**
85   * About box
86   */
87  /*package*/ class AboutBox
88  {
89    private static final String LICENSE_FILENAME = "license.html";
90    
91    private static final String STR_AboutBox_Title =
92      ResourceAccess.Strings.buildString("AboutBox_Title");
93    private static final String STR_AboutBox_OKButton =
94      ResourceAccess.Strings.buildString("AboutBox_OKButton");
95    private static final String STR_AboutBox_InfoTab =
96      ResourceAccess.Strings.buildString("AboutBox_InfoTab");
97    private static final String STR_AboutBox_PluginsTab =
98      ResourceAccess.Strings.buildString("AboutBox_PluginsTab");
99    private static final String STR_AboutBox_LicenseTab =
100     ResourceAccess.Strings.buildString("AboutBox_LicenseTab");
101   private static final String STR_VersionText =
102     ResourceAccess.Strings.buildString("VersionText");
103   private static final String STR_BuildText =
104     ResourceAccess.Strings.buildString("BuildText");
105   private static final String STR_CopyrightNotice =
106     ResourceAccess.Strings.buildString("CopyrightNotice");
107   private static final String STR_SourceCodeNotice =
108     ResourceAccess.Strings.buildString("SourceCodeNotice");
109   private static final String STR_AboutBox_BuiltinPluginsLabel =
110     ResourceAccess.Strings.buildString("AboutBox_BuiltinPluginsLabel");
111   private static final String STR_AboutBox_InstalledPluginsLabel =
112     ResourceAccess.Strings.buildString("AboutBox_InstalledPluginsLabel");
113   private static final String STR_AboutBox_InfoText =
114     ResourceAccess.Strings.buildString("AboutBox_InfoTemplate",
115       new Object[]{
116         System.getProperty("java.vm.name"),
117         System.getProperty("java.vm.version"),
118         System.getProperty("os.name"),
119         System.getProperty("os.version"),
120         System.getProperty("os.arch"),
121         System.getProperty("user.name")
122       });
123   
124   private static final Font STANDARD_FONT = new Font("Dialog", Font.PLAIN, 12);
125   private static final Font MONOSPACE_FONT = new Font("Monospaced", Font.PLAIN, 11);
126   private static final Color STANDARD_COLOR = Color.black;
127   
128   private static JDialog dialog_ = null;
129   private static String licenseString_ = null;
130   
131   
132   /**
133    * Constructor
134    */
135   /*package*/ static void show(
136     final JComponent dialogParent,
137     final Framework framework,
138     final Set builtinPluginNames)
139   {
140     if (!SwingUtilities.isEventDispatchThread())
141     {
142       SwingUtilities.invokeLater(
143         new Runnable()
144         {
145           public void run()
146           {
147             show(dialogParent, framework, builtinPluginNames);
148           }
149         });
150       return;
151     }
152     if (dialog_ != null)
153     {
154       return;
155     }
156     
157     Container top = dialogParent.getTopLevelAncestor();
158     if (top instanceof Frame)
159     {
160       dialog_ = new JDialog((Frame)top, STR_AboutBox_Title, true);
161     }
162     else if (top instanceof Dialog)
163     {
164       dialog_ = new JDialog((Dialog)top, STR_AboutBox_Title, true);
165     }
166     else
167     {
168       return;
169     }
170     dialog_.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
171     dialog_.addWindowListener(
172       new WindowAdapter()
173       {
174         public void windowClosing(
175           WindowEvent ev)
176         {
177           dialog_.dispose();
178           dialog_ = null;
179         }
180       });
181     
182     JPanel mainPanel = new JPanel(new BorderLayout());
183     dialog_.setContentPane(mainPanel);
184     
185     JPanel titlePanel = new JPanel(new BorderLayout());
186     TitlePane titlePane = new TitlePane(false);
187     titlePanel.add(titlePane, BorderLayout.CENTER);
188     JSeparator separator = new JSeparator();
189     titlePanel.add(separator, BorderLayout.SOUTH);
190     mainPanel.add(titlePanel, BorderLayout.NORTH);
191     
192     JPanel buttonPanel = new JPanel(new FlowLayout());
193     JButton okButton = new JButton(STR_AboutBox_OKButton);
194     okButton.addActionListener(
195       new ActionListener()
196       {
197         public void actionPerformed(
198           ActionEvent ev)
199         {
200           dialog_.dispose();
201           dialog_ = null;
202         }
203       });
204     buttonPanel.add(okButton);
205     mainPanel.add(buttonPanel, BorderLayout.SOUTH);
206     
207     JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
208     mainPanel.add(tabs, BorderLayout.CENTER);
209     
210     {
211       ScrollablePanel viewport = new ScrollablePanel(new BorderLayout());
212       viewport.setScrollableTracksViewportWidth(true);
213       JScrollPane scroller = new JScrollPane(viewport,
214         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
215         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
216       tabs.add(STR_AboutBox_InfoTab, scroller);
217       JPanel infoPanel = new JPanel(new GridBagLayout());
218       infoPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
219       viewport.add(infoPanel, BorderLayout.NORTH);
220       
221       GridBagConstraints gbc = new GridBagConstraints();
222       gbc.gridx = 0;
223       gbc.weighty = 1;
224       gbc.weightx = 1;
225       gbc.insets = new Insets(5, 0, 5, 0);
226       gbc.fill = GridBagConstraints.HORIZONTAL;
227       
228       JTextArea field = new JTextArea(STR_VersionText);
229       field.setEditable(false);
230       field.setLineWrap(true);
231       field.setWrapStyleWord(true);
232       field.setFont(STANDARD_FONT);
233       field.setForeground(STANDARD_COLOR);
234       field.setBackground(infoPanel.getBackground());
235       infoPanel.add(field, gbc);
236       
237       field = new JTextArea(STR_BuildText);
238       field.setEditable(false);
239       field.setLineWrap(true);
240       field.setWrapStyleWord(true);
241       field.setFont(STANDARD_FONT);
242       field.setForeground(STANDARD_COLOR);
243       field.setBackground(infoPanel.getBackground());
244       infoPanel.add(field, gbc);
245       
246       field = new JTextArea(STR_CopyrightNotice);
247       field.setEditable(false);
248       field.setLineWrap(true);
249       field.setWrapStyleWord(true);
250       field.setFont(STANDARD_FONT);
251       field.setForeground(STANDARD_COLOR);
252       field.setBackground(infoPanel.getBackground());
253       infoPanel.add(field, gbc);
254       
255       field = new JTextArea(STR_SourceCodeNotice);
256       field.setEditable(false);
257       field.setLineWrap(true);
258       field.setWrapStyleWord(true);
259       field.setFont(STANDARD_FONT);
260       field.setForeground(STANDARD_COLOR);
261       field.setBackground(infoPanel.getBackground());
262       infoPanel.add(field, gbc);
263       
264       field = new JTextArea(STR_AboutBox_InfoText);
265       field.setEditable(false);
266       field.setLineWrap(true);
267       field.setWrapStyleWord(true);
268       field.setFont(STANDARD_FONT);
269       field.setForeground(STANDARD_COLOR);
270       field.setBackground(infoPanel.getBackground());
271       infoPanel.add(field, gbc);
272     }
273     
274     {
275       ScrollablePanel viewport = new ScrollablePanel(new BorderLayout());
276       viewport.setScrollableTracksViewportWidth(true);
277       JScrollPane scroller = new JScrollPane(viewport,
278         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
279         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
280       tabs.add(STR_AboutBox_PluginsTab, scroller);
281       JPanel infoPanel = new JPanel(new GridBagLayout());
282       infoPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
283       viewport.add(infoPanel, BorderLayout.NORTH);
284       
285       GridBagConstraints gbc = new GridBagConstraints();
286       gbc.gridx = 0;
287       gbc.weighty = 1;
288       gbc.weightx = 1;
289       gbc.insets = new Insets(5, 0, 5, 0);
290       gbc.fill = GridBagConstraints.HORIZONTAL;
291       
292       JLabel label = new JLabel(STR_AboutBox_BuiltinPluginsLabel);
293       infoPanel.add(label, gbc);
294       
295       gbc.insets = new Insets(5, 5, 5, 0);
296       
297       for (Iterator iter = framework.getCurrentPluginNames().iterator(); iter.hasNext(); )
298       {
299         String pluginName = (String)iter.next();
300         if (builtinPluginNames.contains(pluginName))
301         {
302           String description = framework.getPluginDescription(pluginName);
303           JTextArea field = new JTextArea(description);
304           field.setEditable(false);
305           field.setLineWrap(true);
306           field.setWrapStyleWord(true);
307           field.setFont(STANDARD_FONT);
308           field.setForeground(STANDARD_COLOR);
309           field.setBackground(infoPanel.getBackground());
310           infoPanel.add(field, gbc);
311         }
312       }
313       
314       gbc.insets = new Insets(5, 0, 5, 0);
315       label = new JLabel(STR_AboutBox_InstalledPluginsLabel);
316       infoPanel.add(label, gbc);
317       gbc.insets = new Insets(5, 5, 5, 0);
318       
319       for (Iterator iter = framework.getCurrentPluginNames().iterator(); iter.hasNext(); )
320       {
321         String pluginName = (String)iter.next();
322         if (!builtinPluginNames.contains(pluginName))
323         {
324           String description = framework.getPluginDescription(pluginName);
325           JTextArea field = new JTextArea(description);
326           field.setEditable(false);
327           field.setLineWrap(true);
328           field.setWrapStyleWord(true);
329           field.setFont(STANDARD_FONT);
330           field.setForeground(STANDARD_COLOR);
331           field.setBackground(infoPanel.getBackground());
332           infoPanel.add(field, gbc);
333         }
334       }
335     }
336     
337     if (licenseString_ == null)
338     {
339       try
340       {
341         licenseString_ = FileUtils.readResourceCompletely(
342           AboutBox.class, LICENSE_FILENAME);
343       }
344       catch (IOException ex)
345       {
346         licenseString_ = "";
347       }
348     }
349     {
350       JEditorPane field = new JEditorPane("text/html", licenseString_);
351       field.setEditable(false);
352       JScrollPane scroller = new JScrollPane(field,
353         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
354         JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
355       tabs.add(STR_AboutBox_LicenseTab, scroller);
356       final JScrollBar vscroll = scroller.getVerticalScrollBar();
357       dialog_.addComponentListener(
358         new ComponentAdapter()
359         {
360           public void componentShown(
361             ComponentEvent ev)
362           {
363             vscroll.setValue(vscroll.getMinimum());
364           }
365         });
366     }
367     
368     dialog_.setSize(700, 600);
369     dialog_.setLocationRelativeTo(dialogParent);
370     dialog_.show();
371   }
372 }