View Javadoc

1   /*
2    * @(#)$Id: AboutDialog.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      :   About dialog.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Feb 01, 2007     ukurmann    Initial Release
15   * Mar 24, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.geco.dialog;
28  
29  import java.awt.Dimension;
30  import java.awt.event.MouseAdapter;
31  import java.awt.event.MouseEvent;
32  import java.io.IOException;
33  import java.net.URL;
34  import java.util.logging.Level;
35  import java.util.logging.Logger;
36  
37  import javax.swing.JButton;
38  import javax.swing.JEditorPane;
39  import javax.swing.JScrollPane;
40  import javax.swing.plaf.basic.BasicHTML;
41  
42  import org.sigtec.graphix.GuiBundle;
43  import org.sigtec.graphix.GuiTool;
44  import org.sigtec.graphix.widget.BasicDialog;
45  import org.ximtec.igesture.geco.util.Constant;
46  import org.ximtec.igesture.geco.util.GuiBundleTool;
47  import org.ximtec.igesture.graphics.SwingTool;
48  
49  
50  /**
51   * About dialog.
52   * 
53   * @version 1.0 Feb 2007
54   * @author Ueli Kurmann, igesture@uelikurmann.ch
55   * @author Beat Signer, signer@inf.ethz.ch
56   */
57  public class AboutDialog extends BasicDialog {
58  
59     private static final Logger LOGGER = Logger.getLogger(AboutDialog.class
60           .getName());
61  
62     /**
63      * The key used to retrieve dialog details from the resource bundle.
64      */
65     public static final String KEY = "AboutDialog";
66     public static final String RESOURCE = "Resource";
67  
68  
69     /**
70      * Constructs a new AboutDialog without getting any information from a GUI
71      * bundle.
72      */
73     public AboutDialog() {
74        super();
75     }
76  
77  
78     /**
79      * Constructs a new AboutDialog.
80      * @param key the key to be used for the lookup of information in
81      *            the GUI bundle.
82      * @param guiBundle the GUI bundle to be used to create the about dialog.
83      */
84     public AboutDialog(String key, GuiBundle guiBundle) {
85        super(key, guiBundle);
86     }
87  
88  
89     /**
90      * Initialises the dialogue.
91      * @param key the key to be used for the lookup of dialogue information in the
92      *            GUI bundle.
93      * @param guiBundle the GUI bundle to be used to create the dialogue.
94      */
95     protected void init(String key, GuiBundle guiBundle) {
96        super.init(key, guiBundle);
97        int width = guiBundle.getWidth(key);
98        int height = guiBundle.getHeight(key);
99        JEditorPane aboutField;
100 
101       try {
102          String resource = guiBundle.getProperty(key, RESOURCE);
103          URL path = AboutDialog.class.getClassLoader().getResource(resource);
104          aboutField = new JEditorPane(path);
105          aboutField.setEditable(false);
106          aboutField.setContentType("text/html");
107          aboutField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
108                Boolean.TRUE);
109          aboutField.putClientProperty(BasicHTML.documentBaseKey,
110                AboutDialog.class.getResource(Constant.SLASH));
111          aboutField.setPreferredSize(new Dimension(width - 10, height - 50));
112          JScrollPane scrollPane = new JScrollPane(aboutField);
113          scrollPane.setPreferredSize(new Dimension(width - 10, height - 50));
114          scrollPane.setAutoscrolls(true);
115          addComponent(scrollPane, SwingTool.createGridBagConstraint(0, 0));
116       }
117       catch (IOException e) {
118          LOGGER.log(Level.SEVERE, Constant.EMPTY_STRING, e);
119       }
120 
121       JButton okButton = GuiTool.createButton(Constant.CLOSE_ABOUT_BUTTON, GuiBundleTool.getBundle());
122       okButton.addMouseListener(new MouseAdapter() {
123 
124          @Override
125          public void mouseClicked(MouseEvent arg0) {
126             super.mouseClicked(arg0);
127             closeDialog();
128          }
129       });
130 
131       addComponent(okButton, SwingTool.createGridBagConstraint(0, 1));
132       pack();
133    } // init
134 
135 
136    private void closeDialog() {
137       setVisible(false);
138       dispose();
139    } // closeDialog
140 
141 }