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

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

checkstyle

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