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

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

code style

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