source: osm/applications/editors/josm/plugins/smed/plugs/oseam/src/oseam/panels/PanelPort.java@ 27230

Last change on this file since 27230 was 27230, checked in by malcolmh, 13 years ago

save

File size: 5.0 KB
Line 
1package oseam.panels;
2
3import java.awt.*;
4import java.awt.event.*;
5import javax.swing.*;
6
7import java.util.*;
8
9import oseam.Messages;
10import oseam.dialogs.OSeaMAction;
11import oseam.seamarks.SeaMark.*;
12
13public class PanelPort extends JPanel {
14
15 private OSeaMAction dlg;
16 public ButtonGroup shapeButtons = new ButtonGroup();
17 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
18 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
19 public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png")));
20 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
21 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
22 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
23 public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
24 public JRadioButton perchButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PerchPButton.png")));
25 public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png")));
26 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<Shp, JRadioButton>(Shp.class);
27 public EnumMap<Shp, Obj> objects = new EnumMap<Shp, Obj>(Shp.class);
28 public ActionListener alShape = new ActionListener() {
29 public void actionPerformed(java.awt.event.ActionEvent e) {
30 for (Shp shp : shapes.keySet()) {
31 JRadioButton button = shapes.get(shp);
32 if (button.isSelected()) {
33 dlg.panelMain.mark.setShape(shp);
34 dlg.panelMain.mark.setObject(objects.get(shp));
35 button.setBorderPainted(true);
36 } else
37 button.setBorderPainted(false);
38 }
39 if (dlg.panelMain.mark.testValid()) {
40 dlg.panelMain.panelChan.topmarkButton.setVisible(true);
41 dlg.panelMain.panelChan.lightButton.setVisible(true);
42 if (dlg.panelMain.mark.getCategory() == Cat.LAM_PORT) {
43 switch (dlg.panelMain.mark.getRegion()) {
44 case A:
45 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
46 dlg.panelMain.mark.setObjColour(Col.RED);
47 break;
48 case B:
49 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
50 dlg.panelMain.mark.setObjColour(Col.GREEN);
51 break;
52 case C:
53 dlg.panelMain.mark.setObjPattern(Pat.HORIZ);
54 dlg.panelMain.mark.setObjColour(Col.RED);
55 dlg.panelMain.mark.addObjColour(Col.WHITE);
56 dlg.panelMain.mark.addObjColour(Col.RED);
57 dlg.panelMain.mark.addObjColour(Col.WHITE);
58 break;
59 }
60 } else {
61 dlg.panelMain.mark.setObjPattern(Pat.HORIZ);
62 switch (dlg.panelMain.mark.getRegion()) {
63 case A:
64 dlg.panelMain.mark.setObjColour(Col.RED);
65 dlg.panelMain.mark.addObjColour(Col.GREEN);
66 dlg.panelMain.mark.addObjColour(Col.RED);
67 break;
68 case B:
69 dlg.panelMain.mark.setObjColour(Col.GREEN);
70 dlg.panelMain.mark.addObjColour(Col.RED);
71 dlg.panelMain.mark.addObjColour(Col.GREEN);
72 break;
73 case C:
74 dlg.panelMain.mark.setObjColour(Col.RED);
75 dlg.panelMain.mark.addObjColour(Col.GREEN);
76 dlg.panelMain.mark.addObjColour(Col.RED);
77 dlg.panelMain.mark.addObjColour(Col.GREEN);
78 break;
79 }
80 }
81 dlg.panelMain.panelMore.syncPanel();
82 } else {
83 dlg.panelMain.panelChan.topmarkButton.setVisible(false);
84 dlg.panelMain.panelChan.lightButton.setVisible(false);
85 }
86 }
87 };
88
89 public PanelPort(OSeaMAction dia) {
90 dlg = dia;
91 setLayout(null);
92 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYLAT));
93 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYLAT));
94 add(getShapeButton(canButton, 0, 64, 34, 32, "Can", Shp.CAN, Obj.BOYLAT));
95 add(getShapeButton(sphereButton, 0, 96, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYLAT));
96 add(getShapeButton(floatButton, 0, 128, 34, 32, "Float", Shp.FLOAT, Obj.FLTLAT));
97 add(getShapeButton(beaconButton, 35, 0, 34, 32, "Beacon", Shp.BEACON, Obj.BCNLAT));
98 add(getShapeButton(towerButton, 35, 32, 34, 32, "TowerB", Shp.TOWER, Obj.BCNLAT));
99 add(getShapeButton(perchButton, 35, 64, 34, 32, "Perch", Shp.PERCH, Obj.BCNLAT));
100 add(getShapeButton(stakeButton, 35, 96, 34, 32, "Stake", Shp.STAKE, Obj.BCNLAT));
101 }
102
103 public void syncPanel() {
104 for (Shp shp : shapes.keySet()) {
105 JRadioButton button = shapes.get(shp);
106 if (dlg.panelMain.mark.getShape() == shp) {
107 button.setBorderPainted(true);
108 } else
109 button.setBorderPainted(false);
110 }
111 }
112
113 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
114 button.setBounds(new Rectangle(x, y, w, h));
115 button.setBorder(BorderFactory.createLoweredBevelBorder());
116 button.setToolTipText(Messages.getString(tip));
117 button.addActionListener(alShape);
118 shapeButtons.add(button);
119 shapes.put(shp, button);
120 objects.put(shp, obj);
121 return button;
122 }
123
124}
Note: See TracBrowser for help on using the repository browser.