1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package panels;
|
---|
3 |
|
---|
4 | import java.awt.Rectangle;
|
---|
5 | import java.awt.event.ActionEvent;
|
---|
6 | import java.awt.event.ActionListener;
|
---|
7 | import java.awt.event.FocusAdapter;
|
---|
8 | import java.awt.event.FocusEvent;
|
---|
9 | import java.awt.event.FocusListener;
|
---|
10 | import java.util.EnumMap;
|
---|
11 |
|
---|
12 | import javax.swing.BorderFactory;
|
---|
13 | import javax.swing.ButtonGroup;
|
---|
14 | import javax.swing.ImageIcon;
|
---|
15 | import javax.swing.JComboBox;
|
---|
16 | import javax.swing.JLabel;
|
---|
17 | import javax.swing.JPanel;
|
---|
18 | import javax.swing.JRadioButton;
|
---|
19 | import javax.swing.JTextField;
|
---|
20 | import javax.swing.SwingConstants;
|
---|
21 |
|
---|
22 | import messages.Messages;
|
---|
23 | import seamarks.SeaMark.Cns;
|
---|
24 | import seamarks.SeaMark.Col;
|
---|
25 | import seamarks.SeaMark.Con;
|
---|
26 | import seamarks.SeaMark.Ent;
|
---|
27 | import seamarks.SeaMark.Pat;
|
---|
28 | import seamarks.SeaMark.Reg;
|
---|
29 | import seamarks.SeaMark.Sts;
|
---|
30 | import smed.SmedAction;
|
---|
31 |
|
---|
32 | public class PanelMore extends JPanel {
|
---|
33 |
|
---|
34 | private SmedAction dlg;
|
---|
35 | public JLabel infoLabel;
|
---|
36 | public JTextField infoBox;
|
---|
37 | private FocusListener flInfo = new FocusAdapter() {
|
---|
38 | @Override
|
---|
39 | public void focusLost(FocusEvent e) {
|
---|
40 | SmedAction.panelMain.mark.setInfo(infoBox.getText());
|
---|
41 | }
|
---|
42 | };
|
---|
43 | public JLabel sourceLabel;
|
---|
44 | public JTextField sourceBox;
|
---|
45 | private FocusListener flSource = new FocusAdapter() {
|
---|
46 | @Override
|
---|
47 | public void focusLost(FocusEvent e) {
|
---|
48 | SmedAction.panelMain.mark.setSource(sourceBox.getText());
|
---|
49 | }
|
---|
50 | };
|
---|
51 | public JLabel elevLabel;
|
---|
52 | public JTextField elevBox;
|
---|
53 | private FocusListener flElev = new FocusAdapter() {
|
---|
54 | @Override
|
---|
55 | public void focusLost(FocusEvent e) {
|
---|
56 | SmedAction.panelMain.mark.setElevation(elevBox.getText());
|
---|
57 | }
|
---|
58 | };
|
---|
59 | public JLabel heightLabel;
|
---|
60 | public JTextField heightBox;
|
---|
61 | private FocusListener flHeight = new FocusAdapter() {
|
---|
62 | @Override
|
---|
63 | public void focusLost(FocusEvent e) {
|
---|
64 | SmedAction.panelMain.mark.setObjectHeight(heightBox.getText());
|
---|
65 | }
|
---|
66 | };
|
---|
67 | public JLabel statusLabel;
|
---|
68 | public JComboBox<String> statusBox;
|
---|
69 | public EnumMap<Sts, Integer> statuses = new EnumMap<>(Sts.class);
|
---|
70 | private ActionListener alStatus = new ActionListener() {
|
---|
71 | @Override
|
---|
72 | public void actionPerformed(ActionEvent e) {
|
---|
73 | for (Sts sts : statuses.keySet()) {
|
---|
74 | int idx = statuses.get(sts);
|
---|
75 | if (SmedAction.panelMain.mark != null && (idx == statusBox.getSelectedIndex())) {
|
---|
76 | SmedAction.panelMain.mark.setStatus(sts);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 | };
|
---|
81 | public JLabel constrLabel;
|
---|
82 | public JComboBox<String> constrBox;
|
---|
83 | public EnumMap<Cns, Integer> constructions = new EnumMap<>(Cns.class);
|
---|
84 | private ActionListener alConstr = new ActionListener() {
|
---|
85 | @Override
|
---|
86 | public void actionPerformed(ActionEvent e) {
|
---|
87 | for (Cns cns : constructions.keySet()) {
|
---|
88 | int idx = constructions.get(cns);
|
---|
89 | if (SmedAction.panelMain.mark != null && (idx == constrBox.getSelectedIndex())) {
|
---|
90 | SmedAction.panelMain.mark.setConstr(cns);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | };
|
---|
95 | public JLabel conLabel;
|
---|
96 | public JComboBox<String> conBox;
|
---|
97 | public EnumMap<Con, Integer> conspicuities = new EnumMap<>(Con.class);
|
---|
98 | private ActionListener alCon = new ActionListener() {
|
---|
99 | @Override
|
---|
100 | public void actionPerformed(ActionEvent e) {
|
---|
101 | for (Con con : conspicuities.keySet()) {
|
---|
102 | int idx = conspicuities.get(con);
|
---|
103 | if (SmedAction.panelMain.mark != null && (idx == conBox.getSelectedIndex())) {
|
---|
104 | SmedAction.panelMain.mark.setConsp(con);
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 | };
|
---|
109 | public JLabel reflLabel;
|
---|
110 | public JComboBox<String> reflBox;
|
---|
111 | public EnumMap<Con, Integer> reflectivities = new EnumMap<>(Con.class);
|
---|
112 | private ActionListener alRefl = new ActionListener() {
|
---|
113 | @Override
|
---|
114 | public void actionPerformed(ActionEvent e) {
|
---|
115 | for (Con con : reflectivities.keySet()) {
|
---|
116 | int idx = reflectivities.get(con);
|
---|
117 | if (SmedAction.panelMain.mark != null && (idx == reflBox.getSelectedIndex())) {
|
---|
118 | SmedAction.panelMain.mark.setRefl(con);
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | };
|
---|
123 | public PanelPat panelPat;
|
---|
124 | private ButtonGroup regionButtons = new ButtonGroup();
|
---|
125 | public JRadioButton regionAButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionAButton.png")));
|
---|
126 | public JRadioButton regionBButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionBButton.png")));
|
---|
127 | public JRadioButton regionCButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionCButton.png")));
|
---|
128 | private ActionListener alRegion = new ActionListener() {
|
---|
129 | @Override
|
---|
130 | public void actionPerformed(ActionEvent e) {
|
---|
131 | if (regionAButton.isSelected()) {
|
---|
132 | SmedAction.panelMain.mark.setRegion(Reg.A);
|
---|
133 | switch (dlg.panelMain.mark.getCategory()) {
|
---|
134 | case LAM_PORT:
|
---|
135 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
136 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
---|
137 | break;
|
---|
138 | case LAM_PPORT:
|
---|
139 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
140 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
141 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
142 | dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
143 | break;
|
---|
144 | case LAM_STBD:
|
---|
145 | dlg.panelMain.mark.setObjColour(Col.GREEN);
|
---|
146 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
---|
147 | break;
|
---|
148 | case LAM_PSTBD:
|
---|
149 | dlg.panelMain.mark.setObjColour(Col.GREEN);
|
---|
150 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
151 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
152 | dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | regionAButton.setBorderPainted(true);
|
---|
156 | } else {
|
---|
157 | regionAButton.setBorderPainted(false);
|
---|
158 | }
|
---|
159 | if (regionBButton.isSelected()) {
|
---|
160 | dlg.panelMain.mark.setRegion(Reg.B);
|
---|
161 | switch (dlg.panelMain.mark.getCategory()) {
|
---|
162 | case LAM_PORT:
|
---|
163 | dlg.panelMain.mark.setObjColour(Col.GREEN);
|
---|
164 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
---|
165 | break;
|
---|
166 | case LAM_PPORT:
|
---|
167 | dlg.panelMain.mark.setObjColour(Col.GREEN);
|
---|
168 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
169 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
170 | dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
171 | break;
|
---|
172 | case LAM_STBD:
|
---|
173 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
174 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
---|
175 | break;
|
---|
176 | case LAM_PSTBD:
|
---|
177 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
178 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
179 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
180 | dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | regionBButton.setBorderPainted(true);
|
---|
184 | } else {
|
---|
185 | regionBButton.setBorderPainted(false);
|
---|
186 | }
|
---|
187 | if (regionCButton.isSelected()) {
|
---|
188 | dlg.panelMain.mark.setRegion(Reg.C);
|
---|
189 | dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
190 | switch (dlg.panelMain.mark.getCategory()) {
|
---|
191 | case LAM_PORT:
|
---|
192 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
193 | dlg.panelMain.mark.addObjColour(Col.WHITE);
|
---|
194 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
195 | dlg.panelMain.mark.addObjColour(Col.WHITE);
|
---|
196 | break;
|
---|
197 | case LAM_PPORT:
|
---|
198 | case LAM_PSTBD:
|
---|
199 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
200 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
201 | dlg.panelMain.mark.addObjColour(Col.RED);
|
---|
202 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
203 | break;
|
---|
204 | case LAM_STBD:
|
---|
205 | dlg.panelMain.mark.setObjColour(Col.GREEN);
|
---|
206 | dlg.panelMain.mark.addObjColour(Col.WHITE);
|
---|
207 | dlg.panelMain.mark.addObjColour(Col.GREEN);
|
---|
208 | dlg.panelMain.mark.addObjColour(Col.WHITE);
|
---|
209 | break;
|
---|
210 | }
|
---|
211 | regionCButton.setBorderPainted(true);
|
---|
212 | } else {
|
---|
213 | regionCButton.setBorderPainted(false);
|
---|
214 | }
|
---|
215 | panelPat.syncPanel();
|
---|
216 | }
|
---|
217 | };
|
---|
218 |
|
---|
219 | public PanelMore(SmedAction dia) {
|
---|
220 | dlg = dia;
|
---|
221 | setLayout(null);
|
---|
222 | panelPat = new PanelPat(dlg, Ent.BODY);
|
---|
223 | panelPat.setBounds(new Rectangle(0, 0, 110, 160));
|
---|
224 | add(panelPat);
|
---|
225 | add(getRegionButton(regionAButton, 110, 0, 34, 30, "RegionA"));
|
---|
226 | add(getRegionButton(regionBButton, 110, 32, 34, 30, "RegionB"));
|
---|
227 | add(getRegionButton(regionCButton, 110, 64, 34, 30, "RegionC"));
|
---|
228 |
|
---|
229 | elevLabel = new JLabel(Messages.getString("Elevation"), SwingConstants.CENTER);
|
---|
230 | elevLabel.setBounds(new Rectangle(140, 0, 90, 20));
|
---|
231 | add(elevLabel);
|
---|
232 | elevBox = new JTextField();
|
---|
233 | elevBox.setBounds(new Rectangle(160, 20, 50, 20));
|
---|
234 | elevBox.setHorizontalAlignment(SwingConstants.CENTER);
|
---|
235 | add(elevBox);
|
---|
236 | elevBox.addFocusListener(flElev);
|
---|
237 |
|
---|
238 | heightLabel = new JLabel(Messages.getString("Height"), SwingConstants.CENTER);
|
---|
239 | heightLabel.setBounds(new Rectangle(140, 40, 90, 20));
|
---|
240 | add(heightLabel);
|
---|
241 | heightBox = new JTextField();
|
---|
242 | heightBox.setBounds(new Rectangle(160, 60, 50, 20));
|
---|
243 | heightBox.setHorizontalAlignment(SwingConstants.CENTER);
|
---|
244 | add(heightBox);
|
---|
245 | heightBox.addFocusListener(flHeight);
|
---|
246 |
|
---|
247 | sourceLabel = new JLabel(Messages.getString("Source"), SwingConstants.CENTER);
|
---|
248 | sourceLabel.setBounds(new Rectangle(110, 80, 130, 20));
|
---|
249 | add(sourceLabel);
|
---|
250 | sourceBox = new JTextField();
|
---|
251 | sourceBox.setBounds(new Rectangle(110, 100, 130, 20));
|
---|
252 | sourceBox.setHorizontalAlignment(SwingConstants.CENTER);
|
---|
253 | add(sourceBox);
|
---|
254 | sourceBox.addFocusListener(flSource);
|
---|
255 |
|
---|
256 | infoLabel = new JLabel(Messages.getString("Information"), SwingConstants.CENTER);
|
---|
257 | infoLabel.setBounds(new Rectangle(110, 120, 130, 20));
|
---|
258 | add(infoLabel);
|
---|
259 | infoBox = new JTextField();
|
---|
260 | infoBox.setBounds(new Rectangle(110, 140, 130, 20));
|
---|
261 | infoBox.setHorizontalAlignment(SwingConstants.CENTER);
|
---|
262 | add(infoBox);
|
---|
263 | infoBox.addFocusListener(flInfo);
|
---|
264 |
|
---|
265 | statusLabel = new JLabel(Messages.getString("Status"), SwingConstants.CENTER);
|
---|
266 | statusLabel.setBounds(new Rectangle(250, 0, 100, 20));
|
---|
267 | add(statusLabel);
|
---|
268 | statusBox = new JComboBox<>();
|
---|
269 | statusBox.setBounds(new Rectangle(250, 20, 100, 20));
|
---|
270 | addStsItem("", Sts.UNKSTS);
|
---|
271 | addStsItem(Messages.getString("Permanent"), Sts.PERM);
|
---|
272 | addStsItem(Messages.getString("Occasional"), Sts.OCC);
|
---|
273 | addStsItem(Messages.getString("Recommended"), Sts.REC);
|
---|
274 | addStsItem(Messages.getString("NotInUse"), Sts.NIU);
|
---|
275 | addStsItem(Messages.getString("Intermittent"), Sts.INT);
|
---|
276 | addStsItem(Messages.getString("Reserved"), Sts.RESV);
|
---|
277 | addStsItem(Messages.getString("Temporary"), Sts.TEMP);
|
---|
278 | addStsItem(Messages.getString("Private"), Sts.PRIV);
|
---|
279 | addStsItem(Messages.getString("Mandatory"), Sts.MAND);
|
---|
280 | addStsItem(Messages.getString("Destroyed"), Sts.DEST);
|
---|
281 | addStsItem(Messages.getString("Extinguished"), Sts.EXT);
|
---|
282 | addStsItem(Messages.getString("Illuminated"), Sts.ILLUM);
|
---|
283 | addStsItem(Messages.getString("Historic"), Sts.HIST);
|
---|
284 | addStsItem(Messages.getString("Public"), Sts.PUB);
|
---|
285 | addStsItem(Messages.getString("Synchronized"), Sts.SYNC);
|
---|
286 | addStsItem(Messages.getString("Watched"), Sts.WATCH);
|
---|
287 | addStsItem(Messages.getString("UnWatched"), Sts.UNWAT);
|
---|
288 | addStsItem(Messages.getString("Doubtful"), Sts.DOUBT);
|
---|
289 | add(statusBox);
|
---|
290 | statusBox.addActionListener(alStatus);
|
---|
291 |
|
---|
292 | constrLabel = new JLabel(Messages.getString("Construction"), SwingConstants.CENTER);
|
---|
293 | constrLabel.setBounds(new Rectangle(250, 40, 100, 20));
|
---|
294 | add(constrLabel);
|
---|
295 | constrBox = new JComboBox<>();
|
---|
296 | constrBox.setBounds(new Rectangle(250, 60, 100, 20));
|
---|
297 | addCnsItem("", Cns.UNKCNS);
|
---|
298 | addCnsItem(Messages.getString("Masonry"), Cns.BRICK);
|
---|
299 | addCnsItem(Messages.getString("Concreted"), Cns.CONC);
|
---|
300 | addCnsItem(Messages.getString("Boulders"), Cns.BOULD);
|
---|
301 | addCnsItem(Messages.getString("HardSurfaced"), Cns.HSURF);
|
---|
302 | addCnsItem(Messages.getString("Unsurfaced"), Cns.USURF);
|
---|
303 | addCnsItem(Messages.getString("Wooden"), Cns.WOOD);
|
---|
304 | addCnsItem(Messages.getString("Metal"), Cns.METAL);
|
---|
305 | addCnsItem(Messages.getString("GRP"), Cns.GLAS);
|
---|
306 | addCnsItem(Messages.getString("Painted"), Cns.PAINT);
|
---|
307 | add(constrBox);
|
---|
308 | constrBox.addActionListener(alConstr);
|
---|
309 |
|
---|
310 | conLabel = new JLabel(Messages.getString("Conspicuity"), SwingConstants.CENTER);
|
---|
311 | conLabel.setBounds(new Rectangle(250, 80, 100, 20));
|
---|
312 | add(conLabel);
|
---|
313 | conBox = new JComboBox<>();
|
---|
314 | conBox.setBounds(new Rectangle(250, 100, 100, 20));
|
---|
315 | addConItem("", Con.UNKCON);
|
---|
316 | addConItem(Messages.getString("Conspicuous"), Con.CONSP);
|
---|
317 | addConItem(Messages.getString("NotConspicuous"), Con.NCONS);
|
---|
318 | add(conBox);
|
---|
319 | conBox.addActionListener(alCon);
|
---|
320 |
|
---|
321 | reflLabel = new JLabel(Messages.getString("Reflectivity"), SwingConstants.CENTER);
|
---|
322 | reflLabel.setBounds(new Rectangle(250, 120, 100, 20));
|
---|
323 | add(reflLabel);
|
---|
324 | reflBox = new JComboBox<>();
|
---|
325 | reflBox.setBounds(new Rectangle(250, 140, 100, 20));
|
---|
326 | addReflItem("", Con.UNKCON);
|
---|
327 | addReflItem(Messages.getString("Conspicuous"), Con.CONSP);
|
---|
328 | addReflItem(Messages.getString("NotConspicuous"), Con.NCONS);
|
---|
329 | addReflItem(Messages.getString("Reflector"), Con.REFL);
|
---|
330 | add(reflBox);
|
---|
331 | reflBox.addActionListener(alRefl);
|
---|
332 |
|
---|
333 | }
|
---|
334 |
|
---|
335 | public void syncPanel() {
|
---|
336 | panelPat.syncPanel();
|
---|
337 | regionAButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.A);
|
---|
338 | regionBButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.B);
|
---|
339 | regionCButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.C);
|
---|
340 | elevBox.setText(dlg.panelMain.mark.getElevation());
|
---|
341 | heightBox.setText(dlg.panelMain.mark.getObjectHeight());
|
---|
342 | sourceBox.setText(dlg.panelMain.mark.getSource());
|
---|
343 | infoBox.setText(dlg.panelMain.mark.getInfo());
|
---|
344 | for (Sts sts : statuses.keySet()) {
|
---|
345 | int item = statuses.get(sts);
|
---|
346 | if (dlg.panelMain.mark.getStatus() == sts) {
|
---|
347 | statusBox.setSelectedIndex(item);
|
---|
348 | }
|
---|
349 | }
|
---|
350 | for (Cns cns : constructions.keySet()) {
|
---|
351 | int item = constructions.get(cns);
|
---|
352 | if (dlg.panelMain.mark.getConstr() == cns) {
|
---|
353 | constrBox.setSelectedIndex(item);
|
---|
354 | }
|
---|
355 | }
|
---|
356 | for (Con con : conspicuities.keySet()) {
|
---|
357 | int item = conspicuities.get(con);
|
---|
358 | if (dlg.panelMain.mark.getConsp() == con) {
|
---|
359 | conBox.setSelectedIndex(item);
|
---|
360 | }
|
---|
361 | }
|
---|
362 | for (Con con : reflectivities.keySet()) {
|
---|
363 | int item = reflectivities.get(con);
|
---|
364 | if (dlg.panelMain.mark.getRefl() == con) {
|
---|
365 | reflBox.setSelectedIndex(item);
|
---|
366 | }
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | private void addStsItem(String str, Sts sts) {
|
---|
371 | statuses.put(sts, statusBox.getItemCount());
|
---|
372 | statusBox.addItem(str);
|
---|
373 | }
|
---|
374 |
|
---|
375 | private void addCnsItem(String str, Cns cns) {
|
---|
376 | constructions.put(cns, constrBox.getItemCount());
|
---|
377 | constrBox.addItem(str);
|
---|
378 | }
|
---|
379 |
|
---|
380 | private void addConItem(String str, Con con) {
|
---|
381 | conspicuities.put(con, conBox.getItemCount());
|
---|
382 | conBox.addItem(str);
|
---|
383 | }
|
---|
384 |
|
---|
385 | private void addReflItem(String str, Con con) {
|
---|
386 | reflectivities.put(con, reflBox.getItemCount());
|
---|
387 | reflBox.addItem(str);
|
---|
388 | }
|
---|
389 |
|
---|
390 | private JRadioButton getRegionButton(JRadioButton button, int x, int y, int w, int h, String tip) {
|
---|
391 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
392 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
393 | button.setToolTipText(Messages.getString(tip));
|
---|
394 | button.addActionListener(alRegion);
|
---|
395 | regionButtons.add(button);
|
---|
396 | return button;
|
---|
397 | }
|
---|
398 | }
|
---|