View Javadoc

1   /**
2    * Copyright 2009 Timothy Johnston Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
3    * file except in compliance with the License. You may obtain a copy of the License at
4    * 
5    * http://www.apache.org/licenses/LICENSE-2.0
6    * 
7    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9    * specific language governing permissions and limitations under the License.
10   */
11  package com.timjohnstondev.unitconverter.view;
12  
13  import java.awt.Color;
14  import java.awt.Component;
15  import java.awt.FlowLayout;
16  import java.awt.Font;
17  import java.util.ResourceBundle;
18  import javax.swing.BoxLayout;
19  import javax.swing.JLabel;
20  import javax.swing.JPanel;
21  import javax.swing.JTextField;
22  
23  /**
24   * This panel displays all of the information about this application including version, author and contact information.
25   */
26  public class AboutPanel extends JPanel implements Configuration
27  {
28    private final ResourceBundle resources = ResourceBundle.getBundle("com.timjohnstondev.unitconverter.view.View");
29  
30    /**
31     * Constructs an {@code AboutPanel}
32     */
33    AboutPanel()
34    {
35      setLayout(new FlowLayout(FlowLayout.LEFT, 12, 10));
36  
37      final JPanel labels = createLabels();
38      final JPanel fields = createFields();
39  
40      add(labels);
41      add(fields);
42    }
43  
44    private JPanel createLabels()
45    {
46      final JPanel labels = new JPanel();
47      final JLabel programNameLabel = new JLabel(resources.getString("AboutPanel.programNameLabel"));
48      final JLabel authorLabel = new JLabel(resources.getString("AboutPanel.authorLabel"));
49      final JLabel emailLabel = new JLabel(resources.getString("AboutPanel.emailLabel"));
50      labels.setLayout(new BoxLayout(labels, BoxLayout.PAGE_AXIS));
51      labels.add(programNameLabel);
52      labels.add(authorLabel);
53      labels.add(emailLabel);
54      return labels;
55    }
56  
57    private JPanel createFields()
58    {
59      final JPanel fields = new JPanel();
60      final JLabel releasedField = new JLabel(resources.getString("AboutPanel.releasedField"));
61      releasedField.setFont(releasedField.getFont().deriveFont(Font.PLAIN));
62      final JLabel authorField = new JLabel(resources.getString("AboutPanel.authorField"));
63      authorField.setFont(releasedField.getFont().deriveFont(Font.PLAIN));
64      final JTextField emailField = new JTextField(resources.getString("AboutPanel.emailField"));
65      emailField.setEditable(false);
66      emailField.setBorder(null);
67      fields.setLayout(new BoxLayout(fields, BoxLayout.PAGE_AXIS));
68      fields.add(releasedField);
69      fields.add(authorField);
70      fields.add(emailField);
71  
72      return fields;
73    }
74  
75    @Override
76    public final void setBackgroundColor(final Color color)
77    {
78      setBackground(color);
79      final Component[] panels = getComponents();
80  
81      for (Component panel : panels)
82      {
83        panel.setBackground(color);
84        final Component[] children = ((JPanel) panel).getComponents();
85        for (Component child : children)
86        {
87          child.setBackground(color);
88        }
89      }
90    }
91  
92    @Override
93    public final void setFontSize(final float fontSize)
94    {
95      final Component[] panels = getComponents();
96      for (Component panel : panels)
97      {
98        final Component[] children = ((JPanel) panel).getComponents();
99        for (Component child : children)
100       {
101         child.setFont(child.getFont().deriveFont(fontSize));
102       }
103     }
104   }
105 
106   @Override
107   public final void setForegroundColor(final Color color)
108   {
109     setForeground(color);
110     final Component[] panels = getComponents();
111 
112     for (Component panel : panels)
113     {
114       panel.setForeground(color);
115       final Component[] children = ((JPanel) panel).getComponents();
116       for (Component child : children)
117       {
118         child.setForeground(color);
119       }
120     }
121   }
122 }