1
2
3
4
5
6
7
8
9
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
25
26
27 public class TopPanel extends JTabbedPane implements Configuration
28 {
29 private CalculationPanel calculationPanel;
30 private ConfigurationPanel configurationPanel;
31 private AboutPanel aboutPanel;
32
33
34
35
36
37
38
39
40 public TopPanel(final UnitConverter appPanel, final ModelController controller)
41 {
42 setPreferredSize(new Dimension(500, 100));
43 setMaximumSize(new Dimension(500, 100));
44
45 calculationPanel = new CalculationPanel();
46 configurationPanel = new ConfigurationPanel(appPanel, controller);
47 aboutPanel = new AboutPanel();
48
49 final ResourceBundle resources = ResourceBundle.getBundle("com.timjohnstondev.unitconverter.view.View");
50 add(resources.getString("TopPanel.calculationsTabTitle"), calculationPanel);
51 add(resources.getString("TopPanel.configurationTabTitle"), configurationPanel);
52 add(resources.getString("TopPanel.aboutTabTitle"), aboutPanel);
53
54 UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
55 updateUI();
56
57 addChangeListener(new ChangeListener()
58 {
59 @Override
60 public final void stateChanged(final ChangeEvent event)
61 {
62 setTabColors();
63 }
64 });
65 }
66
67 private void setTabColors()
68 {
69 final int selectedIndex = getSelectedIndex();
70 final int tabCount = getTabCount();
71 setForegroundAt(selectedIndex, aboutPanel.getForeground());
72 for (int i = 0; i < tabCount; i++)
73 {
74 if (i != selectedIndex)
75 {
76 setForegroundAt(i, aboutPanel.getBackground().darker());
77 }
78 }
79
80 UIManager.put("TabbedPane.selected", aboutPanel.getBackground());
81 UIManager.put("TabbedPane.focus", aboutPanel.getBackground());
82 updateUI();
83 }
84
85
86
87
88
89
90 final CalculationPanel getCalculationPanel()
91 {
92 return calculationPanel;
93 }
94
95 @Override
96 public final void setBackgroundColor(final Color color)
97 {
98 setBackground(color);
99 calculationPanel.setBackgroundColor(color);
100 configurationPanel.setBackgroundColor(color);
101 aboutPanel.setBackgroundColor(color);
102 setTabColors();
103 }
104
105 @Override
106 public final void setFontSize(final float fontSize)
107 {
108 setFont(getFont().deriveFont(fontSize));
109 calculationPanel.setFontSize(fontSize);
110 configurationPanel.setFontSize(fontSize);
111 aboutPanel.setFontSize(fontSize);
112 }
113
114 @Override
115 public final void setForegroundColor(final Color color)
116 {
117 setForeground(color);
118 calculationPanel.setForegroundColor(color);
119 configurationPanel.setForegroundColor(color);
120 aboutPanel.setForegroundColor(color);
121 setTabColors();
122 }
123 }