Coverage Report - com.timjohnstondev.unitconverter.view.TopPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
TopPanel
0%
0/43
0%
0/4
1.286
TopPanel$1
0%
0/3
N/A
1.286
 
 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.Dimension;
 15  
 import java.awt.Insets;
 16  
 import java.util.ResourceBundle;
 17  
 import javax.swing.JTabbedPane;
 18  
 import javax.swing.UIManager;
 19  
 import javax.swing.event.ChangeEvent;
 20  
 import javax.swing.event.ChangeListener;
 21  
 import com.timjohnstondev.unitconverter.controller.ModelController;
 22  
 
 23  
 /**
 24  
  * This {@code JTabbedPane} provided a way to add the {@link ConfigurationPanel} and {@link AboutPanel} without adding
 25  
  * more to the window size. It holds all of the configuration options for the application.
 26  
  */
 27  0
 public class TopPanel extends JTabbedPane implements Configuration
 28  
 {
 29  
   private CalculationPanel calculationPanel;
 30  
   private ConfigurationPanel configurationPanel;
 31  
   private AboutPanel aboutPanel;
 32  
 
 33  
   /**
 34  
    * Constructs a {@code TopPanel} with a {@link UnitConverter} to allow contained panels access to other panels for
 35  
    * updating.
 36  
    * 
 37  
    * @param appPanel the {@code UnitConverter} to access to other panels
 38  
    * @param controller the {@code Controller} to access to the model layer
 39  
    */
 40  
   public TopPanel(final UnitConverter appPanel, final ModelController controller)
 41  0
   {
 42  0
     setPreferredSize(new Dimension(500, 100));
 43  0
     setMaximumSize(new Dimension(500, 100));
 44  
 
 45  0
     calculationPanel = new CalculationPanel();
 46  0
     configurationPanel = new ConfigurationPanel(appPanel, controller);
 47  0
     aboutPanel = new AboutPanel();
 48  
 
 49  0
     final ResourceBundle resources = ResourceBundle.getBundle("com.timjohnstondev.unitconverter.view.View");
 50  0
     add(resources.getString("TopPanel.calculationsTabTitle"), calculationPanel);
 51  0
     add(resources.getString("TopPanel.configurationTabTitle"), configurationPanel);
 52  0
     add(resources.getString("TopPanel.aboutTabTitle"), aboutPanel);
 53  
 
 54  0
     UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
 55  0
     updateUI();
 56  
 
 57  0
     addChangeListener(new ChangeListener()
 58  0
     {
 59  
       @Override
 60  
       public final void stateChanged(final ChangeEvent event)
 61  
       {
 62  0
         setTabColors();
 63  0
       }
 64  
     });
 65  0
   }
 66  
 
 67  
   private void setTabColors()
 68  
   {
 69  0
     final int selectedIndex = getSelectedIndex();
 70  0
     final int tabCount = getTabCount();
 71  0
     setForegroundAt(selectedIndex, aboutPanel.getForeground());
 72  0
     for (int i = 0; i < tabCount; i++)
 73  
     {
 74  0
       if (i != selectedIndex)
 75  
       {
 76  0
         setForegroundAt(i, aboutPanel.getBackground().darker());
 77  
       }
 78  
     }
 79  
 
 80  0
     UIManager.put("TabbedPane.selected", aboutPanel.getBackground());
 81  0
     UIManager.put("TabbedPane.focus", aboutPanel.getBackground());
 82  0
     updateUI();
 83  0
   }
 84  
 
 85  
   /**
 86  
    * Returns the contained {@code CalculationPanel} to other panels for updating.
 87  
    * 
 88  
    * @return the contained {@code CalculationPanel}
 89  
    */
 90  
   final CalculationPanel getCalculationPanel()
 91  
   {
 92  0
     return calculationPanel;
 93  
   }
 94  
 
 95  
   @Override
 96  
   public final void setBackgroundColor(final Color color)
 97  
   {
 98  0
     setBackground(color);
 99  0
     calculationPanel.setBackgroundColor(color);
 100  0
     configurationPanel.setBackgroundColor(color);
 101  0
     aboutPanel.setBackgroundColor(color);
 102  0
     setTabColors();
 103  0
   }
 104  
 
 105  
   @Override
 106  
   public final void setFontSize(final float fontSize)
 107  
   {
 108  0
     setFont(getFont().deriveFont(fontSize));
 109  0
     calculationPanel.setFontSize(fontSize);
 110  0
     configurationPanel.setFontSize(fontSize);
 111  0
     aboutPanel.setFontSize(fontSize);
 112  0
   }
 113  
 
 114  
   @Override
 115  
   public final void setForegroundColor(final Color color)
 116  
   {
 117  0
     setForeground(color);
 118  0
     calculationPanel.setForegroundColor(color);
 119  0
     configurationPanel.setForegroundColor(color);
 120  0
     aboutPanel.setForegroundColor(color);
 121  0
     setTabColors();
 122  0
   }
 123  
 }