1 | package panels;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 | import javax.swing.*;
|
---|
6 |
|
---|
7 | import java.util.*;
|
---|
8 |
|
---|
9 | import messages.Messages;
|
---|
10 | import smed.SmedAction;
|
---|
11 | import seamarks.SeaMark.*;
|
---|
12 |
|
---|
13 | public class PanelSaw extends JPanel {
|
---|
14 |
|
---|
15 | private SmedAction dlg;
|
---|
16 | public ButtonGroup shapeButtons = new ButtonGroup();
|
---|
17 | public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
|
---|
18 | public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
|
---|
19 | public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
|
---|
20 | public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
|
---|
21 | public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
|
---|
22 | public EnumMap<Shp, JRadioButton> shapes = new EnumMap<Shp, JRadioButton>(Shp.class);
|
---|
23 | public EnumMap<Shp, Obj> objects = new EnumMap<Shp, Obj>(Shp.class);
|
---|
24 | public ActionListener alShape = new ActionListener() {
|
---|
25 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
26 | for (Shp shp : shapes.keySet()) {
|
---|
27 | JRadioButton button = shapes.get(shp);
|
---|
28 | if (button.isSelected()) {
|
---|
29 | dlg.panelMain.mark.setShape(shp);
|
---|
30 | dlg.panelMain.mark.setObject(objects.get(shp));
|
---|
31 | button.setBorderPainted(true);
|
---|
32 | } else
|
---|
33 | button.setBorderPainted(false);
|
---|
34 | }
|
---|
35 | if (dlg.panelMain.mark.testValid()) {
|
---|
36 | dlg.panelMain.panelChan.topmarkButton.setVisible(true);
|
---|
37 | dlg.panelMain.mark.setObjPattern(Pat.VSTRP);
|
---|
38 | dlg.panelMain.mark.setObjColour(Col.RED);
|
---|
39 | dlg.panelMain.mark.addObjColour(Col.WHITE);
|
---|
40 | } else {
|
---|
41 | dlg.panelMain.panelChan.topmarkButton.setVisible(false);
|
---|
42 | }
|
---|
43 | dlg.panelMain.panelMore.syncPanel();
|
---|
44 | }
|
---|
45 | };
|
---|
46 |
|
---|
47 | public PanelSaw(SmedAction dia) {
|
---|
48 | dlg = dia;
|
---|
49 | setLayout(null);
|
---|
50 | add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSAW));
|
---|
51 | add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYSAW));
|
---|
52 | add(getShapeButton(sphereButton, 0, 64, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSAW));
|
---|
53 | add(getShapeButton(floatButton, 0, 96, 34, 32, "Float", Shp.FLOAT, Obj.FLTSAW));
|
---|
54 | add(getShapeButton(beaconButton, 0, 128, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSAW));
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void syncPanel() {
|
---|
58 | for (Shp shp : shapes.keySet()) {
|
---|
59 | JRadioButton button = shapes.get(shp);
|
---|
60 | if (dlg.panelMain.mark.getShape() == shp) {
|
---|
61 | button.setBorderPainted(true);
|
---|
62 | } else
|
---|
63 | button.setBorderPainted(false);
|
---|
64 | }
|
---|
65 | dlg.panelMain.mark.testValid();
|
---|
66 | }
|
---|
67 |
|
---|
68 | private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
|
---|
69 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
70 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
71 | button.setToolTipText(Messages.getString(tip));
|
---|
72 | button.addActionListener(alShape);
|
---|
73 | shapeButtons.add(button);
|
---|
74 | shapes.put(shp, button);
|
---|
75 | objects.put(shp, obj);
|
---|
76 | return button;
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|