Ignore:
Timestamp:
2016-08-04T02:27:43+02:00 (9 years ago)
Author:
donvip
Message:

code style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed/src/panels/PanelSpec.java

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