KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > InfoPanel


1 /**
2  * A Swing-based AboutBox class.
3  * <P>
4  * @author Stefanovic Nenad, Bojanic Sasa
5  * @Date: July-November 2001.
6  */

7
8 import java.awt.*;
9 import java.util.*;
10 import javax.swing.*;
11 import javax.swing.border.*;
12
13
14    /** Used to get the <b>about</b> information for the <b>TextEditor</b> applet,
15     * and information of default parameters which are set by the <i>property file</i>.
16    */

17    public class InfoPanel extends JPanel {
18
19    JLabel jLabel1 = new JLabel();
20    JLabel jLabel2 = new JLabel();
21    JLabel jLabel3 = new JLabel();
22    JLabel jLabel4 = new JLabel();
23    JLabel jLabel5 = new JLabel();
24    JLabel jLabel6 = new JLabel();
25    JLabel jLabel8 = new JLabel();
26    JLabel jLabel9 = new JLabel();
27    JLabel jLabel7 = new JLabel();
28    JLabel jLabel10 = new JLabel();
29    Border bord = new EtchedBorder();
30    GridBagLayout gridBagLay = new GridBagLayout();
31
32    JLabel jL;
33
34    /**
35     * Constructs a new instance of 'About' panel.
36     */

37    public InfoPanel() {
38       try {
39             jbAbout();
40       }
41       catch (Exception JavaDoc e) {
42          e.printStackTrace();
43       }
44    }
45    /**
46     * Constructs a new instance of 'ParameterInfo' panel.
47      * @param rb ResorceBoundle representing "main" property file context
48     * @param lang String representing the abbreviation for language
49     * @param pf String representing the name of "main" property file
50     * @param defHyph String representing the 'hyphenation language'
51     */

52    public InfoPanel(ResourceBundle rb,String JavaDoc lang,String JavaDoc pf,String JavaDoc defHyph) {
53       try {
54          jbParam(rb,lang,pf,defHyph);
55       }
56       catch (Exception JavaDoc e) {
57          e.printStackTrace();
58       }
59    }
60    /**
61     * Initializes the state of this instance for "About".
62     */

63    private void jbAbout() throws Exception JavaDoc {
64       jLabel4.setText("chupo@iis.ns.ac.yu");
65       jLabel4.setFont(new Font("Dialog", 1, 12));
66       jLabel1.setText("Authors:");
67       jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
68       jLabel2.setText("Stefanovic Nenad");
69       jLabel2.setFont(new Font("Dialog", 1, 12));
70       jLabel7.setText("Bojanic Sasa");
71       jLabel7.setFont(new Font("Dialog", 1, 12));
72       jLabel10.setText("Puskas Vladimir");
73       jLabel10.setFont(new Font("Dialog", 1, 12));
74       jLabel9.setText("FOP applet");
75       jLabel9.setFont(new Font("Dialog", 3, 14));
76       jLabel3.setText("e-mail:");
77       jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
78       jLabel5.setText("version:");
79       jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
80       jLabel6.setText("1.0");
81       jLabel6.setFont(new Font("Dialog", 1, 12));
82       this.setLayout(gridBagLay);
83       this.add(jLabel9, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
84             GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(2, 0, 5, 0), 0, 0));
85       this.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
86             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 8, 0, 5), 0, 0));
87       this.add(jLabel2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
88             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
89       this.add(jLabel7, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
90             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
91       this.add(jLabel10, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
92             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
93       this.add(jLabel3, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
94             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 8, 0, 5), 0, 0));
95       this.add(jLabel4, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
96             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
97       this.add(jLabel5, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
98             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 8, 0, 5), 0, 0));
99       this.add(jLabel6, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0,
100             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
101       this.setBorder(bord);
102    }
103    /**
104     * Initializes the state of this instance for "Parameter Info".
105     * Reads the default values from <i>property file</i> and displays it along
106     * with some other properties.
107     * @param rb ResorceBoundle representing "main" property file context
108     * @param lang String representing the abbreviation for language
109     * @param pf String representing the name of "main" property file
110     * @param defHyph String representing the 'hyphenation language'
111     */

112    private void jbParam(ResourceBundle rb,String JavaDoc lang,String JavaDoc pf,String JavaDoc defHyph) throws Exception JavaDoc {
113             this.add(new JLabel(" 'Main' property file = "+pf+".properties "));
114             this.add(new JLabel(" 'Language' property file = Text_"+lang+".properties "));
115             this.add(new JLabel(" Height of lines = "+getResourceString("lineHeight",rb)));
116             this.add(new JLabel(" Hyphenation language = "+defHyph));
117          String JavaDoc[] defKeys = TextEditor.tokenize(getResourceString("defvalues",rb));
118             this.setLayout(new GridLayout(defKeys.length+4,1));
119             for (int i=0; i<defKeys.length; i++)
120                 this.add(new JLabel(" "+defKeys[i]+" = "+getResourceString(defKeys[i],rb)));
121             this.setBorder(bord);
122    }
123    /**
124      * Gets a resource string from the resource bundle.<p>
125     * Resource bundle represents the <i>property file</i>. For example, if
126     * property file contains something like this:<BR>
127     * <CENTER>defFontFamily=SansSerif</CENTER>
128     * method call getResourceString("defFontFamily",pf), where resource
129     * boundle <b>pf</b> represents given <i>property file</i>,
130     * will give the string <i>SansSerif</i> as a result.
131      * @param nm name of the resource to fetch.
132      * @param rb ResorceBoundle representing "main" property file context
133     * @return String value of named resource.
134      */

135    protected String JavaDoc getResourceString(String JavaDoc nm,ResourceBundle rb) {
136       String JavaDoc str;
137       try {
138          str = rb.getString(nm);
139       }
140       catch (MissingResourceException mre) {
141         str = null;
142       }
143       if (str != null) str=str.trim();
144       return str;
145    }
146 }
147
Popular Tags