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