1 | package oseam.panels;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 |
|
---|
6 | import javax.swing.*;
|
---|
7 |
|
---|
8 | import java.util.*;
|
---|
9 |
|
---|
10 | import oseam.Messages;
|
---|
11 | import oseam.dialogs.OSeaMAction;
|
---|
12 | import oseam.seamarks.SeaMark.*;
|
---|
13 |
|
---|
14 | public class PanelSpec extends JPanel {
|
---|
15 |
|
---|
16 | private OSeaMAction dlg;
|
---|
17 | public JLabel categoryLabel;
|
---|
18 | public JComboBox categoryBox;
|
---|
19 | public EnumMap<Cat, Integer> categories = new EnumMap<Cat, Integer>(Cat.class);
|
---|
20 | private ActionListener alCategoryBox = new ActionListener() {
|
---|
21 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
22 | for (Cat cat : categories.keySet()) {
|
---|
23 | int idx = categories.get(cat);
|
---|
24 | if (dlg.mark != null && (idx == categoryBox.getSelectedIndex()))
|
---|
25 | dlg.mark.setCategory(cat);
|
---|
26 | }
|
---|
27 | checkValidity();
|
---|
28 | }
|
---|
29 | };
|
---|
30 |
|
---|
31 | public ButtonGroup shapeButtons = new ButtonGroup();
|
---|
32 | public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
|
---|
33 | public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
|
---|
34 | public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png")));
|
---|
35 | public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
|
---|
36 | public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
|
---|
37 | public JRadioButton barrelButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BarrelButton.png")));
|
---|
38 | public JRadioButton superButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SuperButton.png")));
|
---|
39 | public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
|
---|
40 | public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
|
---|
41 | public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
|
---|
42 | public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png")));
|
---|
43 | public JRadioButton cairnButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CairnButton.png")));
|
---|
44 | public EnumMap<Shp, JRadioButton> shapes = new EnumMap<Shp, JRadioButton>(Shp.class);
|
---|
45 | public EnumMap<Shp, Obj> objects = new EnumMap<Shp, Obj>(Shp.class);
|
---|
46 | public ActionListener alShape = new ActionListener() {
|
---|
47 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
48 | for (Shp shp : shapes.keySet()) {
|
---|
49 | JRadioButton button = shapes.get(shp);
|
---|
50 | if (button.isSelected()) {
|
---|
51 | dlg.mark.setShape(shp);
|
---|
52 | dlg.mark.setObject(objects.get(shp));
|
---|
53 | if ((button == cairnButton) && !(dlg.panelMain.panelMore.panelPat.panelCol.offButton.isSelected()))
|
---|
54 | dlg.panelMain.panelMore.panelPat.panelCol.offButton.doClick();
|
---|
55 | button.setBorderPainted(true);
|
---|
56 | } else
|
---|
57 | button.setBorderPainted(false);
|
---|
58 | }
|
---|
59 | checkValidity();
|
---|
60 | }
|
---|
61 | };
|
---|
62 |
|
---|
63 | public PanelSpec(OSeaMAction dia) {
|
---|
64 | dlg = dia;
|
---|
65 |
|
---|
66 | this.setLayout(null);
|
---|
67 | this.add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSPP), null);
|
---|
68 | this.add(getShapeButton(sparButton, 35, 0, 34, 32, "Spar", Shp.SPAR, Obj.BOYSPP), null);
|
---|
69 | this.add(getShapeButton(canButton, 70, 0, 34, 32, "Can", Shp.CAN, Obj.BOYSPP), null);
|
---|
70 | this.add(getShapeButton(coneButton, 105, 0, 34, 32, "Cone", Shp.CONE, Obj.BOYSPP), null);
|
---|
71 | this.add(getShapeButton(sphereButton, 140, 0, 34, 32, "Sphere", Shp.SPHERE, Obj.BOYSPP), null);
|
---|
72 | this.add(getShapeButton(barrelButton, 35, 32, 34, 32, "Barrel", Shp.BARREL, Obj.BOYSPP), null);
|
---|
73 | this.add(getShapeButton(superButton, 70, 32, 34, 32, "Super", Shp.SUPER, Obj.BOYSPP), null);
|
---|
74 | this.add(getShapeButton(floatButton, 105, 32, 34, 32, "Float", Shp.FLOAT, Obj.LITFLT), null);
|
---|
75 | this.add(getShapeButton(beaconButton, 17, 64, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSPP), null);
|
---|
76 | this.add(getShapeButton(towerButton, 52, 64, 34, 32, "Tower", Shp.TOWER, Obj.BCNSPP), null);
|
---|
77 | this.add(getShapeButton(stakeButton, 87, 64, 34, 32, "Stake", Shp.STAKE, Obj.BCNSPP), null);
|
---|
78 | this.add(getShapeButton(cairnButton, 122, 64, 34, 32, "Cairn", Shp.CAIRN, Obj.BCNSPP), null);
|
---|
79 |
|
---|
80 | categoryLabel = new JLabel(Messages.getString("Category"), SwingConstants.CENTER);
|
---|
81 | categoryLabel.setBounds(new Rectangle(5, 100, 170, 20));
|
---|
82 | this.add(categoryLabel, null);
|
---|
83 | categoryBox = new JComboBox();
|
---|
84 | categoryBox.setBounds(new Rectangle(5, 120, 170, 20));
|
---|
85 | this.add(categoryBox, null);
|
---|
86 | categoryBox.addActionListener(alCategoryBox);
|
---|
87 | addCatItem(Messages.getString("UKPurpose"), Cat.SPM_UNKN);
|
---|
88 | addCatItem(Messages.getString("Warning"), Cat.SPM_WARN);
|
---|
89 | addCatItem(Messages.getString("ChanSeparation"), Cat.SPM_CHBF);
|
---|
90 | addCatItem(Messages.getString("Yachting"), Cat.SPM_YCHT);
|
---|
91 | addCatItem(Messages.getString("Cable"), Cat.SPM_CABL);
|
---|
92 | addCatItem(Messages.getString("Outfall"), Cat.SPM_OFAL);
|
---|
93 | addCatItem(Messages.getString("ODAS"), Cat.SPM_ODAS);
|
---|
94 | addCatItem(Messages.getString("RecreationZone"), Cat.SPM_RECN);
|
---|
95 | addCatItem(Messages.getString("Mooring"), Cat.SPM_MOOR);
|
---|
96 | addCatItem(Messages.getString("LANBY"), Cat.SPM_LNBY);
|
---|
97 | addCatItem(Messages.getString("Leading"), Cat.SPM_LDNG);
|
---|
98 | addCatItem(Messages.getString("Notice"), Cat.SPM_NOTC);
|
---|
99 | addCatItem(Messages.getString("TSS"), Cat.SPM_TSS);
|
---|
100 | addCatItem(Messages.getString("FoulGround"), Cat.SPM_FOUL);
|
---|
101 | addCatItem(Messages.getString("Diving"), Cat.SPM_DIVE);
|
---|
102 | addCatItem(Messages.getString("FerryCross"), Cat.SPM_FRRY);
|
---|
103 | addCatItem(Messages.getString("Anchorage"), Cat.SPM_ANCH);
|
---|
104 | }
|
---|
105 |
|
---|
106 | private void checkValidity() {
|
---|
107 | if (dlg.mark != null) {
|
---|
108 | if ((dlg.mark.getObject() != Obj.UNKNOWN) && (dlg.mark.getShape() != Shp.UNKNOWN)) {
|
---|
109 | dlg.panelMain.topButton.setEnabled(true);
|
---|
110 | dlg.panelMain.fogButton.setEnabled(true);
|
---|
111 | dlg.panelMain.radButton.setEnabled(true);
|
---|
112 | dlg.panelMain.litButton.setEnabled(true);
|
---|
113 | dlg.panelMain.moreButton.setVisible(true);
|
---|
114 | } else {
|
---|
115 | dlg.panelMain.topButton.setEnabled(false);
|
---|
116 | dlg.panelMain.fogButton.setEnabled(false);
|
---|
117 | dlg.panelMain.radButton.setEnabled(false);
|
---|
118 | dlg.panelMain.litButton.setEnabled(false);
|
---|
119 | dlg.panelMain.moreButton.setVisible(false);
|
---|
120 | }
|
---|
121 | dlg.mark.paintSign();
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | public void updateSelections() {
|
---|
126 | if (dlg.mark != null) {
|
---|
127 | if (dlg.mark.getObject() == Obj.UNKNOWN) {
|
---|
128 | clearSelections();
|
---|
129 | dlg.panelMain.panelMore.panelPat.panelCol.yellowButton.doClick();
|
---|
130 | } else {
|
---|
131 | dlg.panelMain.panelMore.panelPat.panelCol.colours.get(dlg.mark.getColour(Ent.BODY, 0)).doClick();
|
---|
132 | }
|
---|
133 | if (shapes.containsKey(dlg.mark.getShape())) {
|
---|
134 | shapes.get(dlg.mark.getShape()).doClick();
|
---|
135 | } else {
|
---|
136 | shapeButtons.clearSelection();
|
---|
137 | alShape.actionPerformed(null);
|
---|
138 | }
|
---|
139 | } else
|
---|
140 | clearSelections();
|
---|
141 | }
|
---|
142 |
|
---|
143 | private void addCatItem(String str, Cat cat) {
|
---|
144 | categories.put(cat, categoryBox.getItemCount());
|
---|
145 | categoryBox.addItem(str);
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void clearSelections() {
|
---|
149 | shapeButtons.clearSelection();
|
---|
150 | alShape.actionPerformed(null);
|
---|
151 | }
|
---|
152 |
|
---|
153 | private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
|
---|
154 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
155 | button.setBorder(BorderFactory.createLineBorder(Color.magenta, 2));
|
---|
156 | button.setToolTipText(Messages.getString(tip));
|
---|
157 | button.addActionListener(alShape);
|
---|
158 | shapeButtons.add(button);
|
---|
159 | shapes.put(shp, button);
|
---|
160 | objects.put(shp, obj);
|
---|
161 | return button;
|
---|
162 | }
|
---|
163 |
|
---|
164 | }
|
---|