source: osm/applications/editors/josm/plugins/smed/src/panels/PanelChr.java@ 32767

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

code style

File size: 9.6 KB
Line 
1package panels;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Rectangle;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.awt.event.FocusEvent;
9import java.awt.event.FocusListener;
10import java.util.EnumMap;
11import java.util.EnumSet;
12
13import javax.swing.BorderFactory;
14import javax.swing.ImageIcon;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17import javax.swing.JTextField;
18import javax.swing.JToggleButton;
19import javax.swing.SwingConstants;
20
21import messages.Messages;
22import seamarks.SeaMark;
23import seamarks.SeaMark.Att;
24import seamarks.SeaMark.Chr;
25import seamarks.SeaMark.Col;
26import smed.SmedAction;
27
28public class PanelChr extends JPanel {
29
30 private SmedAction dlg;
31 public JLabel col1Label = new JLabel();
32 public JLabel col2Label = new JLabel();
33 public JLabel charLabel = new JLabel();
34 public JTextField charBox = new JTextField();
35 public JToggleButton noneButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/NoCharButton.png")));
36 public JToggleButton fixedButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/FixedButton.png")));
37 public JToggleButton flashButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/FlashButton.png")));
38 public JToggleButton longFlashButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/LongFlashButton.png")));
39 public JToggleButton quickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/QuickButton.png")));
40 public JToggleButton veryQuickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/VeryQuickButton.png")));
41 public JToggleButton ultraQuickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/UltraQuickButton.png")));
42 public JToggleButton interruptedQuickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/InterruptedQuickButton.png")));
43 public JToggleButton interruptedVeryQuickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/InterruptedVeryQuickButton.png")));
44 public JToggleButton interruptedUltraQuickButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/InterruptedUltraQuickButton.png")));
45 public JToggleButton isophasedButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/IsophasedButton.png")));
46 public JToggleButton occultingButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/OccultingButton.png")));
47 public JToggleButton morseButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/MorseButton.png")));
48 public JToggleButton alternatingButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/AlternatingButton.png")));
49 private EnumMap<Chr, JToggleButton> buttons = new EnumMap<>(Chr.class);
50 private ActionListener alCharButton = new ActionListener() {
51 @Override
52 public void actionPerformed(ActionEvent e) {
53 JToggleButton source = (JToggleButton) e.getSource();
54 EnumSet<Chr> combo = EnumSet.noneOf(Chr.class);
55 for (Chr chr : buttons.keySet()) {
56 JToggleButton button = buttons.get(chr);
57 if (button.isSelected()) {
58 combo.add(chr);
59 button.setBorderPainted(true);
60 } else {
61 combo.remove(chr);
62 button.setBorderPainted(false);
63 }
64 }
65 if (SeaMark.ChrMAP.containsKey(combo)) {
66 charBox.setText(SeaMark.ChrMAP.get(combo));
67 } else {
68 for (Chr chr : buttons.keySet()) {
69 JToggleButton button = buttons.get(chr);
70 if (button == source) {
71 charBox.setText(SeaMark.ChrMAP.get(EnumSet.of(chr)));
72 button.setSelected(true);
73 button.setBorderPainted(true);
74 } else {
75 button.setSelected(false);
76 button.setBorderPainted(false);
77 }
78 }
79 }
80 String str = charBox.getText();
81 SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, str);
82 if (!str.contains("Al")) {
83 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
84 SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, Col.UNKCOL);
85 } else {
86 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
87 }
88 }
89 };
90 private FocusListener flCharBox = new FocusListener() {
91 @Override
92 public void focusGained(FocusEvent e) {}
93 @Override
94 public void focusLost(FocusEvent e) {
95 String str = charBox.getText();
96 SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, str);
97 EnumSet<Chr> set = EnumSet.noneOf(Chr.class);
98 for (EnumSet<Chr> map : SeaMark.ChrMAP.keySet()) {
99 if (str.equals(SeaMark.ChrMAP.get(map))) {
100 set = map;
101 break;
102 }
103 }
104 for (Chr chr : buttons.keySet()) {
105 JToggleButton button = buttons.get(chr);
106 if (set.contains(chr)) {
107 button.setSelected(true);
108 button.setBorderPainted(true);
109 } else {
110 button.setSelected(false);
111 button.setBorderPainted(false);
112 }
113 }
114 if (!str.contains("Al")) {
115 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
116 SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, Col.UNKCOL);
117 } else {
118 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
119 }
120 }
121 };
122
123 public PanelChr(SmedAction dia) {
124 dlg = dia;
125 setLayout(null);
126 add(getChrButton(noneButton, 0, 0, 44, 16, Messages.getString("NoChar"), Chr.UNKCHR));
127 add(getChrButton(fixedButton, 0, 16, 44, 16, Messages.getString("FChar"), Chr.FIXED));
128 add(getChrButton(flashButton, 0, 32, 44, 16, Messages.getString("FlChar"), Chr.FLASH));
129 add(getChrButton(longFlashButton, 0, 48, 44, 16, Messages.getString("LFlChar"), Chr.LFLASH));
130 add(getChrButton(quickButton, 0, 64, 44, 16, Messages.getString("QChar"), Chr.QUICK));
131 add(getChrButton(veryQuickButton, 0, 80, 44, 16, Messages.getString("VQChar"), Chr.VQUICK));
132 add(getChrButton(ultraQuickButton, 0, 96, 44, 16, Messages.getString("UQChar"), Chr.UQUICK));
133 add(getChrButton(alternatingButton, 44, 0, 44, 16, Messages.getString("AlChar"), Chr.ALTERNATING));
134 add(getChrButton(isophasedButton, 44, 16, 44, 16, Messages.getString("IsoChar"), Chr.ISOPHASED));
135 add(getChrButton(occultingButton, 44, 32, 44, 16, Messages.getString("OcChar"), Chr.OCCULTING));
136 add(getChrButton(morseButton, 44, 48, 44, 16, Messages.getString("MoChar"), Chr.MORSE));
137 add(getChrButton(interruptedQuickButton, 44, 64, 44, 16, Messages.getString("IQChar"), Chr.IQUICK));
138 add(getChrButton(interruptedVeryQuickButton, 44, 80, 44, 16, Messages.getString("IVQChar"), Chr.IVQUICK));
139 add(getChrButton(interruptedUltraQuickButton, 44, 96, 44, 16, Messages.getString("IUQChar"), Chr.IUQUICK));
140 charLabel.setBounds(new Rectangle(0, 113, 88, 20));
141 charLabel.setHorizontalAlignment(SwingConstants.CENTER);
142 charLabel.setText(Messages.getString("Character"));
143 add(charLabel);
144 col1Label.setBounds(new Rectangle(10, 135, 10, 20));
145 col1Label.setOpaque(true);
146 add(col1Label);
147 col2Label.setBounds(new Rectangle(70, 135, 10, 20));
148 col2Label.setOpaque(true);
149 add(col2Label);
150 charBox.setBounds(new Rectangle(20, 135, 50, 20));
151 charBox.setHorizontalAlignment(SwingConstants.CENTER);
152 add(charBox);
153 charBox.addFocusListener(flCharBox);
154 }
155
156 public void syncPanel() {
157 String str = (String)SmedAction.panelMain.mark.getLightAtt(Att.CHR, 0);
158 charBox.setText(str);
159 EnumSet<Chr> set = EnumSet.noneOf(Chr.class);
160 for (EnumSet<Chr> map : SeaMark.ChrMAP.keySet()) {
161 if (dlg.node != null && str.equals(SeaMark.ChrMAP.get(map))) {
162 set = map;
163 break;
164 }
165 }
166 if (!str.contains("Al")) {
167 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
168 } else {
169 col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
170 }
171 col1Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
172 for (Chr chr : buttons.keySet()) {
173 JToggleButton button = buttons.get(chr);
174 if (set.contains(chr)) {
175 button.setSelected(true);
176 button.setBorderPainted(true);
177 } else {
178 button.setSelected(false);
179 button.setBorderPainted(false);
180 }
181 }
182 }
183
184 private JToggleButton getChrButton(JToggleButton button, int x, int y, int w, int h, String tip, Chr chr) {
185 button.setBounds(new Rectangle(x, y, w, h));
186 button.setBorder(BorderFactory.createLoweredBevelBorder());
187 button.setBorderPainted(false);
188 button.setToolTipText(tr(tip));
189 button.addActionListener(alCharButton);
190 buttons.put(chr, button);
191 return button;
192 }
193
194}
Note: See TracBrowser for help on using the repository browser.