1 | package oseam.panels;
|
---|
2 |
|
---|
3 | import java.awt.event.ActionListener;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Rectangle;
|
---|
6 |
|
---|
7 | import javax.swing.ButtonGroup;
|
---|
8 | import javax.swing.ImageIcon;
|
---|
9 | import javax.swing.JRadioButton;
|
---|
10 | import javax.swing.BorderFactory;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import java.util.EnumMap;
|
---|
14 | import java.util.Iterator;
|
---|
15 |
|
---|
16 | import oseam.Messages;
|
---|
17 | import oseam.dialogs.OSeaMAction;
|
---|
18 | import oseam.seamarks.SeaMark.Shp;
|
---|
19 | import oseam.seamarks.SeaMark.Obj;
|
---|
20 |
|
---|
21 | public class PanelStbd extends JPanel {
|
---|
22 |
|
---|
23 | private OSeaMAction dlg;
|
---|
24 | private ButtonGroup regionButtons = new ButtonGroup();
|
---|
25 | public JRadioButton regionAButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionAButton.png")));
|
---|
26 | public JRadioButton regionBButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionBButton.png")));
|
---|
27 | private ActionListener alRegion = new ActionListener() {
|
---|
28 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
29 | regionAButton.setBorderPainted(regionAButton.isSelected());
|
---|
30 | regionBButton.setBorderPainted(regionBButton.isSelected());
|
---|
31 | dlg.mark.paintSign();
|
---|
32 | }
|
---|
33 | };
|
---|
34 | private ButtonGroup shapeButtons = new ButtonGroup();
|
---|
35 | public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
|
---|
36 | public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
|
---|
37 | public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
|
---|
38 | public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
|
---|
39 | public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
|
---|
40 | public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
|
---|
41 | public JRadioButton perchButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PerchSButton.png")));
|
---|
42 | private EnumMap<Shp, JRadioButton> shapes = new EnumMap<Shp, JRadioButton>(Shp.class);
|
---|
43 | private EnumMap<Shp, Obj> objects = new EnumMap<Shp, Obj>(Shp.class);
|
---|
44 | private ActionListener alShape = new ActionListener() {
|
---|
45 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
46 | Iterator<Shp> it = shapes.keySet().iterator();
|
---|
47 | while (it.hasNext()) {
|
---|
48 | Shp shp = it.next();
|
---|
49 | JRadioButton button = shapes.get(shp);
|
---|
50 | if (button.isSelected()) {
|
---|
51 | dlg.mark.setShape(shp);
|
---|
52 | dlg.mark.setObject(objects.get(shp));
|
---|
53 | button.setBorderPainted(true);
|
---|
54 | } else
|
---|
55 | button.setBorderPainted(false);
|
---|
56 | }
|
---|
57 | if (dlg.mark != null)
|
---|
58 | dlg.mark.paintSign();
|
---|
59 | }
|
---|
60 | };
|
---|
61 |
|
---|
62 | public PanelStbd(OSeaMAction dia) {
|
---|
63 | dlg = dia;
|
---|
64 | this.setLayout(null);
|
---|
65 | this.add(getRegionButton(regionAButton, 0, 2, 34, 30, "RegionATip"), null);
|
---|
66 | this.add(getRegionButton(regionBButton, 0, 32, 34, 30, "RegionBTip"), null);
|
---|
67 | this.add(getShapeButton(pillarButton, 0, 64, 34, 32, "PillarTip", Shp.PILLAR, Obj.BOYLAT), null);
|
---|
68 | this.add(getShapeButton(sparButton, 0, 96, 34, 32, "SparTip", Shp.SPAR, Obj.BOYLAT), null);
|
---|
69 | this.add(getShapeButton(coneButton, 0, 128, 34, 32, "ConeTip", Shp.CONE, Obj.BOYLAT), null);
|
---|
70 | this.add(getShapeButton(floatButton, 35, 0, 34, 32, "FloatTip", Shp.FLOAT, Obj.LITFLT), null);
|
---|
71 | this.add(getShapeButton(beaconButton, 35, 32, 34, 32, "BeaconTip", Shp.BEACON, Obj.BCNLAT), null);
|
---|
72 | this.add(getShapeButton(towerButton, 35, 64, 34, 32, "TowerTip", Shp.TOWER, Obj.BCNLAT), null);
|
---|
73 | this.add(getShapeButton(perchButton, 35, 96, 34, 32, "PerchTip", Shp.PERCH, Obj.BCNLAT), null);
|
---|
74 | }
|
---|
75 |
|
---|
76 | public void clearSelections() {
|
---|
77 | shapeButtons.clearSelection();
|
---|
78 | alShape.actionPerformed(null);
|
---|
79 | }
|
---|
80 |
|
---|
81 | private JRadioButton getRegionButton(JRadioButton button, int x, int y, int w, int h, String tip) {
|
---|
82 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
83 | button.setBorder(BorderFactory.createLineBorder(Color.magenta, 2));
|
---|
84 | button.setToolTipText(Messages.getString(tip));
|
---|
85 | button.addActionListener(alRegion);
|
---|
86 | regionButtons.add(button);
|
---|
87 | return button;
|
---|
88 | }
|
---|
89 |
|
---|
90 | private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
|
---|
91 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
92 | button.setBorder(BorderFactory.createLineBorder(Color.magenta, 2));
|
---|
93 | button.setToolTipText(Messages.getString(tip));
|
---|
94 | button.addActionListener(alShape);
|
---|
95 | shapeButtons.add(button);
|
---|
96 | shapes.put(shp, button);
|
---|
97 | objects.put(shp, obj);
|
---|
98 | return button;
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|