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.Dimension;
16  import java.util.ResourceBundle;
17  import javax.swing.BorderFactory;
18  import javax.swing.Box;
19  import javax.swing.BoxLayout;
20  import javax.swing.JLabel;
21  import javax.swing.JPanel;
22  
23  /**
24   * This panel holds the labels for the {@link UnitPanel}.
25   */
26  public class UnitLabelPanel extends JPanel implements Configuration
27  {
28    /**
29     * Constructs a {@code UnitLabelPanel} setting the label sizes to match the UnitPanel lists.
30     */
31    public UnitLabelPanel()
32    {
33      setPreferredSize(new Dimension(500, 20));
34      setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
35      setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
36  
37      final ResourceBundle resources = ResourceBundle.getBundle("com.timjohnstondev.unitconverter.view.View");
38      final JLabel properties = new JLabel(resources.getString("UnitLabelPanel.properties"));
39      final JLabel fromUnits = new JLabel(resources.getString("UnitLabelPanel.fromUnits"));
40      final JLabel toUnits = new JLabel(resources.getString("UnitLabelPanel.toUnits"));
41  
42      properties.setPreferredSize(new Dimension(170, 20));
43      properties.setMaximumSize(new Dimension(170, 20));
44      fromUnits.setPreferredSize(new Dimension(110, 20));
45      fromUnits.setMaximumSize(new Dimension(110, 20));
46      toUnits.setPreferredSize(new Dimension(110, 20));
47      toUnits.setMaximumSize(new Dimension(110, 20));
48  
49      add(properties);
50      add(fromUnits);
51      add(toUnits);
52      add(Box.createHorizontalGlue());
53    }
54  
55    @Override
56    public final void setBackgroundColor(final Color color)
57    {
58      setBackground(color);
59    }
60  
61    @Override
62    public final void setFontSize(final float fontSize)
63    {
64      setFont(getFont().deriveFont(fontSize));
65      final Component[] children = getComponents();
66      for (Component child : children)
67      {
68        child.setFont(child.getFont().deriveFont(fontSize));
69      }
70    }
71  
72    @Override
73    public final void setForegroundColor(final Color color)
74    {
75      setForeground(color);
76      final Component[] children = getComponents();
77      for (Component child : children)
78      {
79        child.setForeground(color);
80      }
81    }
82  }