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

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

code style

File size: 3.7 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.Col;
16import seamarks.SeaMark.Obj;
17import seamarks.SeaMark.Pat;
18import seamarks.SeaMark.Shp;
19import smed.SmedAction;
20
21public class PanelSaw extends JPanel {
22
23 private SmedAction dlg;
24 public ButtonGroup shapeButtons = new ButtonGroup();
25 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
26 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
27 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
28 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
29 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
30 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
31 public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class);
32 public ActionListener alShape = new ActionListener() {
33 @Override
34 public void actionPerformed(ActionEvent e) {
35 for (Shp shp : shapes.keySet()) {
36 JRadioButton button = shapes.get(shp);
37 if (button.isSelected()) {
38 SmedAction.panelMain.mark.setShape(shp);
39 SmedAction.panelMain.mark.setObject(objects.get(shp));
40 button.setBorderPainted(true);
41 } else {
42 button.setBorderPainted(false);
43 }
44 }
45 if (SmedAction.panelMain.mark.testValid()) {
46 SmedAction.panelMain.panelChan.topmarkButton.setVisible(true);
47 SmedAction.panelMain.mark.setObjPattern(Pat.VSTRP);
48 SmedAction.panelMain.mark.setObjColour(Col.RED);
49 SmedAction.panelMain.mark.addObjColour(Col.WHITE);
50 } else {
51 SmedAction.panelMain.panelChan.topmarkButton.setVisible(false);
52 }
53 SmedAction.panelMain.panelMore.syncPanel();
54 }
55 };
56
57 public PanelSaw(SmedAction dia) {
58 dlg = dia;
59 setLayout(null);
60 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSAW));
61 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYSAW));
62 add(getShapeButton(sphereButton, 0, 64, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSAW));
63 add(getShapeButton(floatButton, 0, 96, 34, 32, "Float", Shp.FLOAT, Obj.FLTSAW));
64 add(getShapeButton(beaconButton, 0, 128, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSAW));
65 }
66
67 public void syncPanel() {
68 for (Shp shp : shapes.keySet()) {
69 JRadioButton button = shapes.get(shp);
70 if (SmedAction.panelMain.mark.getShape() == shp) {
71 button.setBorderPainted(true);
72 } else {
73 button.setBorderPainted(false);
74 }
75 }
76 SmedAction.panelMain.mark.testValid();
77 }
78
79 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
80 button.setBounds(new Rectangle(x, y, w, h));
81 button.setBorder(BorderFactory.createLoweredBevelBorder());
82 button.setToolTipText(Messages.getString(tip));
83 button.addActionListener(alShape);
84 shapeButtons.add(button);
85 shapes.put(shp, button);
86 objects.put(shp, obj);
87 return button;
88 }
89
90}
Note: See TracBrowser for help on using the repository browser.