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

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

checkstyle

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