| 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 | 0 | 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 | 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 | |
|
| 87 | |
|
| 88 | |
|
| 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 | |
} |