source: osm/applications/editors/josm/plugins/smed/src/panels/PanelFog.java@ 33054

Last change on this file since 33054 was 33054, checked in by donvip, 8 years ago

checkstyle

File size: 6.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package panels;
3
4import java.awt.Rectangle;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
7import java.awt.event.FocusAdapter;
8import java.awt.event.FocusEvent;
9import java.awt.event.FocusListener;
10import java.util.EnumMap;
11
12import javax.swing.BorderFactory;
13import javax.swing.ButtonGroup;
14import javax.swing.ImageIcon;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17import javax.swing.JRadioButton;
18import javax.swing.JTextField;
19import javax.swing.SwingConstants;
20
21import messages.Messages;
22import seamarks.SeaMark.Fog;
23import smed.SmedAction;
24
25public class PanelFog extends JPanel {
26
27 private SmedAction dlg;
28 private ButtonGroup fogButtons = new ButtonGroup();
29 public JRadioButton noFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OffButton.png")));
30 public JRadioButton yesFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogYesButton.png")));
31 public JRadioButton hornButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogHornButton.png")));
32 public JRadioButton sirenButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogSirenButton.png")));
33 public JRadioButton diaButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogDiaButton.png")));
34 public JRadioButton bellButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogBellButton.png")));
35 public JRadioButton whisButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogWhisButton.png")));
36 public JRadioButton gongButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogGongButton.png")));
37 public JRadioButton explosButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogExplosButton.png")));
38 private EnumMap<Fog, JRadioButton> fogs = new EnumMap<>(Fog.class);
39 private ActionListener alFog = new ActionListener() {
40 @Override
41 public void actionPerformed(ActionEvent e) {
42 for (Fog fog : fogs.keySet()) {
43 JRadioButton button = fogs.get(fog);
44 if (button.isSelected()) {
45 SmedAction.panelMain.mark.setFogSound(fog);
46 button.setBorderPainted(true);
47 } else {
48 button.setBorderPainted(false);
49 }
50 }
51 }
52 };
53 public JLabel groupLabel;
54 public JTextField groupBox;
55 private FocusListener flGroup = new FocusAdapter() {
56 @Override
57 public void focusLost(FocusEvent e) {
58 SmedAction.panelMain.mark.setFogGroup(groupBox.getText());
59 }
60 };
61 public JLabel periodLabel;
62 public JTextField periodBox;
63 private FocusListener flPeriod = new FocusAdapter() {
64 @Override
65 public void focusLost(FocusEvent e) {
66 SmedAction.panelMain.mark.setFogPeriod(periodBox.getText());
67 }
68 };
69 public JLabel seqLabel;
70 public JTextField seqBox;
71 private FocusListener flSeq = new FocusAdapter() {
72 @Override
73 public void focusLost(FocusEvent e) {
74 SmedAction.panelMain.mark.setFogSequence(seqBox.getText());
75 }
76 };
77 public JLabel rangeLabel;
78 public JTextField rangeBox;
79 private FocusListener flRange = new FocusAdapter() {
80 @Override
81 public void focusLost(FocusEvent e) {
82 SmedAction.panelMain.mark.setFogRange(rangeBox.getText());
83 }
84 };
85
86 public PanelFog(SmedAction dia) {
87 dlg = dia;
88 setLayout(null);
89 add(getFogButton(noFogButton, 0, 2, 27, 27, "NoFog", Fog.NOFOG));
90 add(getFogButton(yesFogButton, 0, 32, 27, 27, "FogSignal", Fog.FOGSIG));
91 add(getFogButton(hornButton, 0, 62, 27, 27, "Horn", Fog.HORN));
92 add(getFogButton(sirenButton, 0, 92, 27, 27, "Siren", Fog.SIREN));
93 add(getFogButton(gongButton, 0, 122, 27, 27, "Gong", Fog.GONG));
94 add(getFogButton(diaButton, 30, 2, 27, 27, "Diaphone", Fog.DIA));
95 add(getFogButton(bellButton, 30, 32, 27, 27, "Bell", Fog.BELL));
96 add(getFogButton(whisButton, 30, 62, 27, 27, "Whistle", Fog.WHIS));
97 add(getFogButton(explosButton, 30, 92, 27, 27, "Explosion", Fog.EXPLOS));
98
99 groupLabel = new JLabel(Messages.getString("Group"), SwingConstants.CENTER);
100 groupLabel.setBounds(new Rectangle(75, 0, 100, 20));
101 add(groupLabel);
102 groupBox = new JTextField();
103 groupBox.setBounds(new Rectangle(100, 20, 50, 20));
104 groupBox.setHorizontalAlignment(SwingConstants.CENTER);
105 add(groupBox);
106 groupBox.addFocusListener(flGroup);
107
108 periodLabel = new JLabel(Messages.getString("Period"), SwingConstants.CENTER);
109 periodLabel.setBounds(new Rectangle(75, 40, 100, 20));
110 add(periodLabel);
111 periodBox = new JTextField();
112 periodBox.setBounds(new Rectangle(100, 60, 50, 20));
113 periodBox.setHorizontalAlignment(SwingConstants.CENTER);
114 add(periodBox);
115 periodBox.addFocusListener(flPeriod);
116
117 seqLabel = new JLabel(Messages.getString("Sequence"), SwingConstants.CENTER);
118 seqLabel.setBounds(new Rectangle(75, 80, 100, 20));
119 add(seqLabel);
120 seqBox = new JTextField();
121 seqBox.setBounds(new Rectangle(100, 100, 50, 20));
122 seqBox.setHorizontalAlignment(SwingConstants.CENTER);
123 add(seqBox);
124 seqBox.addFocusListener(flSeq);
125
126 rangeLabel = new JLabel(Messages.getString("Range"), SwingConstants.CENTER);
127 rangeLabel.setBounds(new Rectangle(75, 120, 100, 20));
128 add(rangeLabel);
129 rangeBox = new JTextField();
130 rangeBox.setBounds(new Rectangle(100, 140, 50, 20));
131 rangeBox.setHorizontalAlignment(SwingConstants.CENTER);
132 add(rangeBox);
133 rangeBox.addFocusListener(flRange);
134
135 }
136
137 public void syncPanel() {
138 for (Fog fog : fogs.keySet()) {
139 JRadioButton button = fogs.get(fog);
140 button.setBorderPainted(SmedAction.panelMain.mark.getFogSound() == fog);
141 }
142 groupBox.setText(SmedAction.panelMain.mark.getFogGroup());
143 seqBox.setText(SmedAction.panelMain.mark.getFogSequence());
144 periodBox.setText(SmedAction.panelMain.mark.getFogPeriod());
145 rangeBox.setText(SmedAction.panelMain.mark.getFogRange());
146 }
147
148 private JRadioButton getFogButton(JRadioButton button, int x, int y, int w, int h, String tip, Fog fog) {
149 button.setBounds(new Rectangle(x, y, w, h));
150 button.setBorder(BorderFactory.createLoweredBevelBorder());
151 button.setToolTipText(Messages.getString(tip));
152 button.addActionListener(alFog);
153 fogButtons.add(button);
154 fogs.put(fog, button);
155 return button;
156 }
157
158}
Note: See TracBrowser for help on using the repository browser.