| 1 | package panels;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.*;
|
|---|
| 4 | import java.awt.event.*;
|
|---|
| 5 |
|
|---|
| 6 | import javax.swing.*;
|
|---|
| 7 |
|
|---|
| 8 | import java.util.*;
|
|---|
| 9 |
|
|---|
| 10 | import messages.Messages;
|
|---|
| 11 | import smed.SmedAction;
|
|---|
| 12 | import seamarks.SeaMark;
|
|---|
| 13 | import seamarks.SeaMark.*;
|
|---|
| 14 |
|
|---|
| 15 | public class PanelSpec extends JPanel {
|
|---|
| 16 |
|
|---|
| 17 | private SmedAction dlg;
|
|---|
| 18 | public JLabel categoryLabel;
|
|---|
| 19 | public JComboBox categoryBox;
|
|---|
| 20 | public EnumMap<Cat, Integer> categories = new EnumMap<Cat, Integer>(Cat.class);
|
|---|
| 21 | private ActionListener alCategoryBox = new ActionListener() {
|
|---|
| 22 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 23 | for (Cat cat : categories.keySet()) {
|
|---|
| 24 | int idx = categories.get(cat);
|
|---|
| 25 | if (dlg.node != null && (idx == categoryBox.getSelectedIndex()))
|
|---|
| 26 | dlg.panelMain.mark.setCategory(cat);
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 | };
|
|---|
| 30 | public JComboBox mooringBox;
|
|---|
| 31 | public EnumMap<Cat, Integer> moorings = new EnumMap<Cat, Integer>(Cat.class);
|
|---|
| 32 | private ActionListener alMooringBox = new ActionListener() {
|
|---|
| 33 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 34 | for (Cat cat : moorings.keySet()) {
|
|---|
| 35 | int idx = moorings.get(cat);
|
|---|
| 36 | if (dlg.node != null && (idx == mooringBox.getSelectedIndex())) {
|
|---|
| 37 | dlg.panelMain.mark.setCategory(cat);
|
|---|
| 38 | if ((cat == Cat.INB_CALM) || (cat == Cat.INB_SBM)) {
|
|---|
| 39 | dlg.panelMain.mark.setObject(Obj.BOYINB);
|
|---|
| 40 | dlg.panelMain.mark.setShape(Shp.UNKSHP);
|
|---|
| 41 | } else {
|
|---|
| 42 | dlg.panelMain.mark.setObject(Obj.MORFAC);
|
|---|
| 43 | if (cat != Cat.MOR_BUOY)
|
|---|
| 44 | dlg.panelMain.mark.setShape(Shp.UNKSHP);
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | if (dlg.node != null) syncPanel();
|
|---|
| 49 | }
|
|---|
| 50 | };
|
|---|
| 51 | public ButtonGroup shapeButtons = new ButtonGroup();
|
|---|
| 52 | public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
|
|---|
| 53 | public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
|
|---|
| 54 | public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png")));
|
|---|
| 55 | public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
|
|---|
| 56 | public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
|
|---|
| 57 | public JRadioButton barrelButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BarrelButton.png")));
|
|---|
| 58 | public JRadioButton superButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SuperButton.png")));
|
|---|
| 59 | public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
|
|---|
| 60 | public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
|
|---|
| 61 | public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
|
|---|
| 62 | public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png")));
|
|---|
| 63 | public JRadioButton cairnButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CairnButton.png")));
|
|---|
| 64 | public EnumMap<Shp, JRadioButton> shapes = new EnumMap<Shp, JRadioButton>(Shp.class);
|
|---|
| 65 | public EnumMap<Shp, Obj> objects = new EnumMap<Shp, Obj>(Shp.class);
|
|---|
| 66 | public ActionListener alShape = new ActionListener() {
|
|---|
| 67 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 68 | if ((dlg.panelMain.mark.getObject() != Obj.MORFAC) || (dlg.panelMain.mark.getCategory() == Cat.MOR_BUOY)) {
|
|---|
| 69 | for (Shp shp : shapes.keySet()) {
|
|---|
| 70 | JRadioButton button = shapes.get(shp);
|
|---|
| 71 | if (button.isSelected()) {
|
|---|
| 72 | dlg.panelMain.mark.setShape(shp);
|
|---|
| 73 | if (SeaMark.EntMAP.get(dlg.panelMain.mark.getObject()) != Ent.MOORING) {
|
|---|
| 74 | dlg.panelMain.mark.setObject(objects.get(shp));
|
|---|
| 75 | if (dlg.panelMain.mark.getObjColour(0) == Col.UNKCOL) {
|
|---|
| 76 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
|---|
| 77 | dlg.panelMain.mark.setObjColour(Col.YELLOW);
|
|---|
| 78 | }
|
|---|
| 79 | if (button == cairnButton) {
|
|---|
| 80 | dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
|
|---|
| 81 | dlg.panelMain.mark.setObjColour(Col.UNKCOL);
|
|---|
| 82 | }
|
|---|
| 83 | topmarkButton.setVisible(dlg.panelMain.mark.testValid());
|
|---|
| 84 | }
|
|---|
| 85 | button.setBorderPainted(true);
|
|---|
| 86 | } else
|
|---|
| 87 | button.setBorderPainted(false);
|
|---|
| 88 | }
|
|---|
| 89 | dlg.panelMain.panelMore.syncPanel();
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | };
|
|---|
| 93 | public JToggleButton topmarkButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/SpecTopButton.png")));
|
|---|
| 94 | private ActionListener alTop = new ActionListener() {
|
|---|
| 95 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 96 | if (topmarkButton.isSelected()) {
|
|---|
| 97 | dlg.panelMain.mark.setTopmark(Top.X_SHAPE);
|
|---|
| 98 | dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
|
|---|
| 99 | dlg.panelMain.mark.setTopColour(Col.YELLOW);
|
|---|
| 100 | topmarkButton.setBorderPainted(true);
|
|---|
| 101 | } else {
|
|---|
| 102 | dlg.panelMain.mark.setTopmark(Top.NOTOP);
|
|---|
| 103 | dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
|
|---|
| 104 | dlg.panelMain.mark.setTopColour(Col.UNKCOL);
|
|---|
| 105 | topmarkButton.setBorderPainted(false);
|
|---|
| 106 | }
|
|---|
| 107 | dlg.panelMain.panelTop.syncPanel();
|
|---|
| 108 | }
|
|---|
| 109 | };
|
|---|
| 110 | public JToggleButton noticeButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/NoticeButton.png")));
|
|---|
| 111 | private ActionListener alNotice = new ActionListener() {
|
|---|
| 112 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 113 | dlg.panelMain.mark.clrMark();
|
|---|
| 114 | if (noticeButton.isSelected()) {
|
|---|
| 115 | dlg.panelMain.mark.setObject(Obj.NOTMRK);
|
|---|
| 116 | noticeButton.setBorderPainted(true);
|
|---|
| 117 | } else {
|
|---|
| 118 | dlg.panelMain.mark.setObject(Obj.UNKOBJ);
|
|---|
| 119 | noticeButton.setBorderPainted(false);
|
|---|
| 120 | }
|
|---|
| 121 | dlg.panelMain.syncPanel();
|
|---|
| 122 | }
|
|---|
| 123 | };
|
|---|
| 124 | public JToggleButton mooringButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/MooringButton.png")));
|
|---|
| 125 | private ActionListener alMooring = new ActionListener() {
|
|---|
| 126 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 127 | dlg.panelMain.mark.setObject(Obj.UNKOBJ);
|
|---|
| 128 | dlg.panelMain.mark.setCategory(Cat.NOCAT);
|
|---|
| 129 | dlg.panelMain.mark.setTopmark(Top.NOTOP);
|
|---|
| 130 | if (mooringButton.isSelected()) {
|
|---|
| 131 | dlg.panelMain.mark.setObject(Obj.MORFAC);
|
|---|
| 132 | categoryBox.setVisible(false);
|
|---|
| 133 | mooringBox.setVisible(true);
|
|---|
| 134 | pillarButton.setEnabled(false);
|
|---|
| 135 | sparButton.setEnabled(false);
|
|---|
| 136 | beaconButton.setEnabled(false);
|
|---|
| 137 | towerButton.setEnabled(false);
|
|---|
| 138 | stakeButton.setEnabled(false);
|
|---|
| 139 | cairnButton.setEnabled(false);
|
|---|
| 140 | mooringButton.setBorderPainted(true);
|
|---|
| 141 | } else {
|
|---|
| 142 | mooringBox.setVisible(false);
|
|---|
| 143 | categoryBox.setVisible(true);
|
|---|
| 144 | pillarButton.setEnabled(true);
|
|---|
| 145 | sparButton.setEnabled(true);
|
|---|
| 146 | beaconButton.setEnabled(true);
|
|---|
| 147 | towerButton.setEnabled(true);
|
|---|
| 148 | stakeButton.setEnabled(true);
|
|---|
| 149 | cairnButton.setEnabled(true);
|
|---|
| 150 | mooringButton.setBorderPainted(false);
|
|---|
| 151 | }
|
|---|
| 152 | syncPanel();
|
|---|
| 153 | }
|
|---|
| 154 | };
|
|---|
| 155 |
|
|---|
| 156 | public PanelSpec(SmedAction dia) {
|
|---|
| 157 | dlg = dia;
|
|---|
| 158 | setLayout(null);
|
|---|
| 159 | add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSPP));
|
|---|
| 160 | add(getShapeButton(sparButton, 34, 0, 34, 32, "Spar", Shp.SPAR, Obj.BOYSPP));
|
|---|
| 161 | add(getShapeButton(canButton, 68, 0, 34, 32, "Can", Shp.CAN, Obj.BOYSPP));
|
|---|
| 162 | add(getShapeButton(coneButton, 102, 0, 34, 32, "Cone", Shp.CONI, Obj.BOYSPP));
|
|---|
| 163 | add(getShapeButton(sphereButton, 0, 32, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSPP));
|
|---|
| 164 | add(getShapeButton(barrelButton, 34, 32, 34, 32, "Barrel", Shp.BARREL, Obj.BOYSPP));
|
|---|
| 165 | add(getShapeButton(superButton, 68, 32, 34, 32, "Super", Shp.SUPER, Obj.BOYSPP));
|
|---|
| 166 | add(getShapeButton(floatButton, 102, 32, 34, 32, "Float", Shp.FLOAT, Obj.LITFLT));
|
|---|
| 167 | add(getShapeButton(beaconButton, 0, 64, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSPP));
|
|---|
| 168 | add(getShapeButton(towerButton, 34, 64, 34, 32, "TowerB", Shp.TOWER, Obj.BCNSPP));
|
|---|
| 169 | add(getShapeButton(stakeButton, 68, 64, 34, 32, "Stake", Shp.STAKE, Obj.BCNSPP));
|
|---|
| 170 | add(getShapeButton(cairnButton, 102, 64, 34, 32, "CairnB", Shp.CAIRN, Obj.BCNSPP));
|
|---|
| 171 |
|
|---|
| 172 | categoryLabel = new JLabel(Messages.getString("Category"), SwingConstants.CENTER);
|
|---|
| 173 | categoryLabel.setBounds(new Rectangle(5, 125, 160, 18));
|
|---|
| 174 | add(categoryLabel);
|
|---|
| 175 | categoryBox = new JComboBox();
|
|---|
| 176 | categoryBox.setBounds(new Rectangle(5, 142, 160, 18));
|
|---|
| 177 | add(categoryBox);
|
|---|
| 178 | categoryBox.setVisible(true);
|
|---|
| 179 | categoryBox.addActionListener(alCategoryBox);
|
|---|
| 180 | addCatItem("", Cat.NOCAT);
|
|---|
| 181 | addCatItem(Messages.getString("UKPurpose"), Cat.SPM_UNKN);
|
|---|
| 182 | addCatItem(Messages.getString("Warning"), Cat.SPM_WARN);
|
|---|
| 183 | addCatItem(Messages.getString("ChanSeparation"), Cat.SPM_CHBF);
|
|---|
| 184 | addCatItem(Messages.getString("Yachting"), Cat.SPM_YCHT);
|
|---|
| 185 | addCatItem(Messages.getString("Cable"), Cat.SPM_CABL);
|
|---|
| 186 | addCatItem(Messages.getString("Outfall"), Cat.SPM_OFAL);
|
|---|
| 187 | addCatItem(Messages.getString("ODAS"), Cat.SPM_ODAS);
|
|---|
| 188 | addCatItem(Messages.getString("RecreationZone"), Cat.SPM_RECN);
|
|---|
| 189 | addCatItem(Messages.getString("Mooring"), Cat.SPM_MOOR);
|
|---|
| 190 | addCatItem(Messages.getString("LANBY"), Cat.SPM_LNBY);
|
|---|
| 191 | addCatItem(Messages.getString("Leading"), Cat.SPM_LDNG);
|
|---|
| 192 | addCatItem(Messages.getString("Notice"), Cat.SPM_NOTC);
|
|---|
| 193 | addCatItem(Messages.getString("TSS"), Cat.SPM_TSS);
|
|---|
| 194 | addCatItem(Messages.getString("FoulGround"), Cat.SPM_FOUL);
|
|---|
| 195 | addCatItem(Messages.getString("Diving"), Cat.SPM_DIVE);
|
|---|
| 196 | addCatItem(Messages.getString("FerryCross"), Cat.SPM_FRRY);
|
|---|
| 197 | addCatItem(Messages.getString("Anchorage"), Cat.SPM_ANCH);
|
|---|
| 198 | mooringBox = new JComboBox();
|
|---|
| 199 | mooringBox.setBounds(new Rectangle(5, 142, 160, 18));
|
|---|
| 200 | add(mooringBox);
|
|---|
| 201 | mooringBox.setVisible(false);
|
|---|
| 202 | mooringBox.addActionListener(alMooringBox);
|
|---|
| 203 | addMorItem("", Cat.NOCAT);
|
|---|
| 204 | addMorItem(Messages.getString("Dolphin"), Cat.MOR_DLPN);
|
|---|
| 205 | addMorItem(Messages.getString("DevDolphin"), Cat.MOR_DDPN);
|
|---|
| 206 | addMorItem(Messages.getString("Bollard"), Cat.MOR_BLRD);
|
|---|
| 207 | addMorItem(Messages.getString("Wall"), Cat.MOR_WALL);
|
|---|
| 208 | addMorItem(Messages.getString("Post"), Cat.MOR_POST);
|
|---|
| 209 | addMorItem(Messages.getString("Chain"), Cat.MOR_CHWR);
|
|---|
| 210 | addMorItem(Messages.getString("Rope"), Cat.MOR_ROPE);
|
|---|
| 211 | addMorItem(Messages.getString("Automatic"), Cat.MOR_AUTO);
|
|---|
| 212 | addMorItem(Messages.getString("MooringBuoy"), Cat.MOR_BUOY);
|
|---|
| 213 | addMorItem(Messages.getString("CALM"), Cat.INB_CALM);
|
|---|
| 214 | addMorItem(Messages.getString("SBM"), Cat.INB_SBM);
|
|---|
| 215 |
|
|---|
| 216 | topmarkButton.setBounds(new Rectangle(136, 0, 34, 32));
|
|---|
| 217 | topmarkButton.setToolTipText(Messages.getString("Topmark"));
|
|---|
| 218 | topmarkButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 219 | topmarkButton.addActionListener(alTop);
|
|---|
| 220 | add(topmarkButton);
|
|---|
| 221 |
|
|---|
| 222 | // noticeButton.setBounds(new Rectangle(136, 32, 34, 32));
|
|---|
| 223 | // noticeButton.setToolTipText(Messages.getString("Notice"));
|
|---|
| 224 | // noticeButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 225 | // noticeButton.addActionListener(alNotice);
|
|---|
| 226 | // add(noticeButton);
|
|---|
| 227 |
|
|---|
| 228 | mooringButton.setBounds(new Rectangle(136, 64, 34, 32));
|
|---|
| 229 | mooringButton.setToolTipText(Messages.getString("Mooring"));
|
|---|
| 230 | mooringButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 231 | mooringButton.addActionListener(alMooring);
|
|---|
| 232 | add(mooringButton);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | public void syncPanel() {
|
|---|
| 236 | if (SeaMark.EntMAP.get(dlg.panelMain.mark.getObject()) == Ent.MOORING) {
|
|---|
| 237 | mooringButton.setBorderPainted(true);
|
|---|
| 238 | categoryBox.setVisible(false);
|
|---|
| 239 | mooringBox.setVisible(true);
|
|---|
| 240 | pillarButton.setEnabled(false);
|
|---|
| 241 | sparButton.setEnabled(false);
|
|---|
| 242 | beaconButton.setEnabled(false);
|
|---|
| 243 | towerButton.setEnabled(false);
|
|---|
| 244 | stakeButton.setEnabled(false);
|
|---|
| 245 | cairnButton.setEnabled(false);
|
|---|
| 246 | noticeButton.setEnabled(false);
|
|---|
| 247 | topmarkButton.setVisible(false);
|
|---|
| 248 | for (Cat cat : moorings.keySet()) {
|
|---|
| 249 | int item = moorings.get(cat);
|
|---|
| 250 | if (dlg.panelMain.mark.getCategory() == cat)
|
|---|
| 251 | mooringBox.setSelectedIndex(item);
|
|---|
| 252 | }
|
|---|
| 253 | } else {
|
|---|
| 254 | mooringButton.setBorderPainted(false);
|
|---|
| 255 | mooringBox.setVisible(false);
|
|---|
| 256 | categoryBox.setVisible(true);
|
|---|
| 257 | pillarButton.setEnabled(true);
|
|---|
| 258 | sparButton.setEnabled(true);
|
|---|
| 259 | beaconButton.setEnabled(true);
|
|---|
| 260 | towerButton.setEnabled(true);
|
|---|
| 261 | stakeButton.setEnabled(true);
|
|---|
| 262 | cairnButton.setEnabled(true);
|
|---|
| 263 | noticeButton.setEnabled(true);
|
|---|
| 264 | topmarkButton.setBorderPainted(dlg.panelMain.mark.getTopmark() != Top.NOTOP);
|
|---|
| 265 | topmarkButton.setSelected(dlg.panelMain.mark.getTopmark() != Top.NOTOP);
|
|---|
| 266 | topmarkButton.setVisible(dlg.panelMain.mark.testValid());
|
|---|
| 267 | for (Cat cat : categories.keySet()) {
|
|---|
| 268 | int item = categories.get(cat);
|
|---|
| 269 | if (dlg.panelMain.mark.getCategory() == cat)
|
|---|
| 270 | categoryBox.setSelectedIndex(item);
|
|---|
| 271 | }
|
|---|
| 272 | }
|
|---|
| 273 | for (Shp shp : shapes.keySet()) {
|
|---|
| 274 | JRadioButton button = shapes.get(shp);
|
|---|
| 275 | if (dlg.panelMain.mark.getShape() == shp) {
|
|---|
| 276 | button.setBorderPainted(true);
|
|---|
| 277 | } else
|
|---|
| 278 | button.setBorderPainted(false);
|
|---|
| 279 | }
|
|---|
| 280 | noticeButton.setBorderPainted(false);
|
|---|
| 281 | dlg.panelMain.mark.testValid();
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | private void addCatItem(String str, Cat cat) {
|
|---|
| 285 | categories.put(cat, categoryBox.getItemCount());
|
|---|
| 286 | categoryBox.addItem(str);
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | private void addMorItem(String str, Cat cat) {
|
|---|
| 290 | moorings.put(cat, mooringBox.getItemCount());
|
|---|
| 291 | mooringBox.addItem(str);
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
|
|---|
| 295 | button.setBounds(new Rectangle(x, y, w, h));
|
|---|
| 296 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 297 | button.setToolTipText(Messages.getString(tip));
|
|---|
| 298 | button.addActionListener(alShape);
|
|---|
| 299 | shapeButtons.add(button);
|
|---|
| 300 | shapes.put(shp, button);
|
|---|
| 301 | objects.put(shp, obj);
|
|---|
| 302 | return button;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | }
|
|---|