| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package panels;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.Rectangle;
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.awt.event.ActionListener;
|
|---|
| 7 | import java.awt.event.FocusAdapter;
|
|---|
| 8 | import java.awt.event.FocusEvent;
|
|---|
| 9 | import java.awt.event.FocusListener;
|
|---|
| 10 | import java.util.EnumMap;
|
|---|
| 11 |
|
|---|
| 12 | import javax.swing.BorderFactory;
|
|---|
| 13 | import javax.swing.ButtonGroup;
|
|---|
| 14 | import javax.swing.ImageIcon;
|
|---|
| 15 | import javax.swing.JComboBox;
|
|---|
| 16 | import javax.swing.JLabel;
|
|---|
| 17 | import javax.swing.JPanel;
|
|---|
| 18 | import javax.swing.JRadioButton;
|
|---|
| 19 | import javax.swing.JTextField;
|
|---|
| 20 | import javax.swing.JToggleButton;
|
|---|
| 21 | import javax.swing.SwingConstants;
|
|---|
| 22 |
|
|---|
| 23 | import messages.Messages;
|
|---|
| 24 | import seamarks.SeaMark.Cat;
|
|---|
| 25 | import seamarks.SeaMark.Rtb;
|
|---|
| 26 | import smed.SmedAction;
|
|---|
| 27 |
|
|---|
| 28 | public class PanelRadar extends JPanel {
|
|---|
| 29 |
|
|---|
| 30 | private SmedAction dlg;
|
|---|
| 31 | private JToggleButton aisButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/AISButton.png")));
|
|---|
| 32 | private ActionListener alAis = new ActionListener() {
|
|---|
| 33 | @Override
|
|---|
| 34 | public void actionPerformed(ActionEvent e) {
|
|---|
| 35 | if (aisButton.isSelected()) {
|
|---|
| 36 | radioCatBox.setVisible(true);
|
|---|
| 37 | aisButton.setBorderPainted(true);
|
|---|
| 38 | } else {
|
|---|
| 39 | radioCatBox.setSelectedIndex(0);
|
|---|
| 40 | radioCatBox.setVisible(false);
|
|---|
| 41 | aisButton.setBorderPainted(false);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | };
|
|---|
| 45 | private JComboBox<String> radioCatBox;
|
|---|
| 46 | private EnumMap<Cat, Integer> radioCats = new EnumMap<>(Cat.class);
|
|---|
| 47 | private ActionListener alRadioCatBox = new ActionListener() {
|
|---|
| 48 | @Override
|
|---|
| 49 | public void actionPerformed(ActionEvent e) {
|
|---|
| 50 | for (Cat cat : radioCats.keySet()) {
|
|---|
| 51 | int idx = radioCats.get(cat);
|
|---|
| 52 | if (dlg.node != null && (idx == radioCatBox.getSelectedIndex())) {
|
|---|
| 53 | SmedAction.panelMain.mark.setRadio(cat);
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | };
|
|---|
| 58 | private ButtonGroup radarButtons = new ButtonGroup();
|
|---|
| 59 | public JRadioButton noRadButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OffButton.png")));
|
|---|
| 60 | public JRadioButton reflButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RadarReflectorButton.png")));
|
|---|
| 61 | public JRadioButton ramarkButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RamarkButton.png")));
|
|---|
| 62 | public JRadioButton raconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RaconButton.png")));
|
|---|
| 63 | public JRadioButton leadingButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/LeadingRaconButton.png")));
|
|---|
| 64 | private EnumMap<Rtb, JRadioButton> rads = new EnumMap<>(Rtb.class);
|
|---|
| 65 | private ActionListener alRad = new ActionListener() {
|
|---|
| 66 | @Override
|
|---|
| 67 | public void actionPerformed(ActionEvent e) {
|
|---|
| 68 | for (Rtb rtb : rads.keySet()) {
|
|---|
| 69 | JRadioButton button = rads.get(rtb);
|
|---|
| 70 | if (button.isSelected()) {
|
|---|
| 71 | SmedAction.panelMain.mark.setRadar(rtb);
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | syncPanel();
|
|---|
| 75 | }
|
|---|
| 76 | };
|
|---|
| 77 | public JLabel groupLabel;
|
|---|
| 78 | public JTextField groupBox;
|
|---|
| 79 | private FocusListener flGroup = new FocusAdapter() {
|
|---|
| 80 | @Override
|
|---|
| 81 | public void focusLost(FocusEvent e) {
|
|---|
| 82 | SmedAction.panelMain.mark.setRaconGroup(groupBox.getText());
|
|---|
| 83 | }
|
|---|
| 84 | };
|
|---|
| 85 | public JLabel periodLabel;
|
|---|
| 86 | public JTextField periodBox;
|
|---|
| 87 | private FocusListener flPeriod = new FocusAdapter() {
|
|---|
| 88 | @Override
|
|---|
| 89 | public void focusLost(FocusEvent e) {
|
|---|
| 90 | SmedAction.panelMain.mark.setRaconPeriod(periodBox.getText());
|
|---|
| 91 | }
|
|---|
| 92 | };
|
|---|
| 93 | public JLabel seqLabel;
|
|---|
| 94 | public JTextField seqBox;
|
|---|
| 95 | private FocusListener flSeq = new FocusAdapter() {
|
|---|
| 96 | @Override
|
|---|
| 97 | public void focusLost(FocusEvent e) {
|
|---|
| 98 | SmedAction.panelMain.mark.setRaconSequence(seqBox.getText());
|
|---|
| 99 | }
|
|---|
| 100 | };
|
|---|
| 101 | public JLabel rangeLabel;
|
|---|
| 102 | public JTextField rangeBox;
|
|---|
| 103 | private FocusListener flRange = new FocusAdapter() {
|
|---|
| 104 | @Override
|
|---|
| 105 | public void focusLost(FocusEvent e) {
|
|---|
| 106 | SmedAction.panelMain.mark.setRaconRange(rangeBox.getText());
|
|---|
| 107 | }
|
|---|
| 108 | };
|
|---|
| 109 | public JLabel sector1Label;
|
|---|
| 110 | public JTextField sector1Box;
|
|---|
| 111 | private FocusListener flSector1 = new FocusAdapter() {
|
|---|
| 112 | @Override
|
|---|
| 113 | public void focusLost(FocusEvent e) {
|
|---|
| 114 | SmedAction.panelMain.mark.setRaconSector1(sector1Box.getText());
|
|---|
| 115 | }
|
|---|
| 116 | };
|
|---|
| 117 | public JLabel sector2Label;
|
|---|
| 118 | public JTextField sector2Box;
|
|---|
| 119 | private FocusListener flSector2 = new FocusAdapter() {
|
|---|
| 120 | @Override
|
|---|
| 121 | public void focusLost(FocusEvent e) {
|
|---|
| 122 | SmedAction.panelMain.mark.setRaconSector2(sector2Box.getText());
|
|---|
| 123 | }
|
|---|
| 124 | };
|
|---|
| 125 | public JLabel sectorsLabel;
|
|---|
| 126 |
|
|---|
| 127 | public PanelRadar(SmedAction dia) {
|
|---|
| 128 | dlg = dia;
|
|---|
| 129 | setLayout(null);
|
|---|
| 130 | add(getRadButton(noRadButton, 0, 3, 27, 27, "NoRadar", Rtb.NORTB));
|
|---|
| 131 | add(getRadButton(reflButton, 0, 33, 27, 27, "RadarReflector", Rtb.REFLECTOR));
|
|---|
| 132 | add(getRadButton(ramarkButton, 0, 63, 27, 27, "Ramark", Rtb.RAMARK));
|
|---|
| 133 | add(getRadButton(raconButton, 0, 93, 27, 27, "Racon", Rtb.RACON));
|
|---|
| 134 | add(getRadButton(leadingButton, 0, 123, 27, 27, "LeadingRacon", Rtb.LEADING));
|
|---|
| 135 |
|
|---|
| 136 | groupLabel = new JLabel(Messages.getString("Group"), SwingConstants.CENTER);
|
|---|
| 137 | groupLabel.setBounds(new Rectangle(30, 0, 100, 20));
|
|---|
| 138 | add(groupLabel);
|
|---|
| 139 | groupBox = new JTextField();
|
|---|
| 140 | groupBox.setBounds(new Rectangle(55, 20, 50, 20));
|
|---|
| 141 | groupBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 142 | add(groupBox);
|
|---|
| 143 | groupBox.addFocusListener(flGroup);
|
|---|
| 144 |
|
|---|
| 145 | periodLabel = new JLabel(Messages.getString("Period"), SwingConstants.CENTER);
|
|---|
| 146 | periodLabel.setBounds(new Rectangle(130, 0, 100, 20));
|
|---|
| 147 | add(periodLabel);
|
|---|
| 148 | periodBox = new JTextField();
|
|---|
| 149 | periodBox.setBounds(new Rectangle(155, 20, 50, 20));
|
|---|
| 150 | periodBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 151 | add(periodBox);
|
|---|
| 152 | periodBox.addFocusListener(flPeriod);
|
|---|
| 153 |
|
|---|
| 154 | seqLabel = new JLabel(Messages.getString("Sequence"), SwingConstants.CENTER);
|
|---|
| 155 | seqLabel.setBounds(new Rectangle(30, 40, 100, 20));
|
|---|
| 156 | add(seqLabel);
|
|---|
| 157 | seqBox = new JTextField();
|
|---|
| 158 | seqBox.setBounds(new Rectangle(55, 60, 50, 20));
|
|---|
| 159 | seqBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 160 | add(seqBox);
|
|---|
| 161 | seqBox.addFocusListener(flSeq);
|
|---|
| 162 |
|
|---|
| 163 | rangeLabel = new JLabel(Messages.getString("Range"), SwingConstants.CENTER);
|
|---|
| 164 | rangeLabel.setBounds(new Rectangle(130, 40, 100, 20));
|
|---|
| 165 | add(rangeLabel);
|
|---|
| 166 | rangeBox = new JTextField();
|
|---|
| 167 | rangeBox.setBounds(new Rectangle(155, 60, 50, 20));
|
|---|
| 168 | rangeBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 169 | add(rangeBox);
|
|---|
| 170 | rangeBox.addFocusListener(flRange);
|
|---|
| 171 |
|
|---|
| 172 | sectorsLabel = new JLabel(Messages.getString("VisibleSector"), SwingConstants.CENTER);
|
|---|
| 173 | sectorsLabel.setBounds(new Rectangle(75, 85, 100, 20));
|
|---|
| 174 | add(sectorsLabel);
|
|---|
| 175 |
|
|---|
| 176 | sector1Label = new JLabel(Messages.getString("Start"), SwingConstants.CENTER);
|
|---|
| 177 | sector1Label.setBounds(new Rectangle(30, 100, 100, 20));
|
|---|
| 178 | add(sector1Label);
|
|---|
| 179 | sector1Box = new JTextField();
|
|---|
| 180 | sector1Box.setBounds(new Rectangle(55, 120, 50, 20));
|
|---|
| 181 | sector1Box.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 182 | add(sector1Box);
|
|---|
| 183 | sector1Box.addFocusListener(flSector1);
|
|---|
| 184 |
|
|---|
| 185 | sector2Label = new JLabel(Messages.getString("End"), SwingConstants.CENTER);
|
|---|
| 186 | sector2Label.setBounds(new Rectangle(130, 100, 100, 20));
|
|---|
| 187 | add(sector2Label);
|
|---|
| 188 | sector2Box = new JTextField();
|
|---|
| 189 | sector2Box.setBounds(new Rectangle(155, 120, 50, 20));
|
|---|
| 190 | sector2Box.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 191 | add(sector2Box);
|
|---|
| 192 | sector2Box.addFocusListener(flSector2);
|
|---|
| 193 |
|
|---|
| 194 | aisButton.setBounds(new Rectangle(270, 3, 27, 27));
|
|---|
| 195 | aisButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 196 | aisButton.setToolTipText("AIS");
|
|---|
| 197 | aisButton.addActionListener(alAis);
|
|---|
| 198 | add(aisButton);
|
|---|
| 199 |
|
|---|
| 200 | radioCatBox = new JComboBox<>();
|
|---|
| 201 | radioCatBox.setBounds(new Rectangle(210, 40, 150, 20));
|
|---|
| 202 | add(radioCatBox);
|
|---|
| 203 | radioCatBox.addActionListener(alRadioCatBox);
|
|---|
| 204 | addROItem("", Cat.NOROS);
|
|---|
| 205 | addROItem(Messages.getString("CircularBeacon"), Cat.ROS_OMNI);
|
|---|
| 206 | addROItem(Messages.getString("DirectionalBeacon"), Cat.ROS_DIRL);
|
|---|
| 207 | addROItem(Messages.getString("RotatingBeacon"), Cat.ROS_ROTP);
|
|---|
| 208 | addROItem(Messages.getString("ConsolBeacon"), Cat.ROS_CNSL);
|
|---|
| 209 | addROItem(Messages.getString("DirectionFinding"), Cat.ROS_RDF);
|
|---|
| 210 | addROItem(Messages.getString("QTGService"), Cat.ROS_QTG);
|
|---|
| 211 | addROItem(Messages.getString("AeronaticalBeacon"), Cat.ROS_AERO);
|
|---|
| 212 | addROItem(Messages.getString("Decca"), Cat.ROS_DECA);
|
|---|
| 213 | addROItem(Messages.getString("LoranC"), Cat.ROS_LORN);
|
|---|
| 214 | addROItem(Messages.getString("DGPS"), Cat.ROS_DGPS);
|
|---|
| 215 | addROItem(Messages.getString("Toran"), Cat.ROS_TORN);
|
|---|
| 216 | addROItem(Messages.getString("Omega"), Cat.ROS_OMGA);
|
|---|
| 217 | addROItem(Messages.getString("Syledis"), Cat.ROS_SYLD);
|
|---|
| 218 | addROItem(Messages.getString("Chiaka"), Cat.ROS_CHKA);
|
|---|
| 219 | addROItem(Messages.getString("PublicCommunication"), Cat.ROS_PCOM);
|
|---|
| 220 | addROItem(Messages.getString("CommercialBroadcast"), Cat.ROS_COMB);
|
|---|
| 221 | addROItem(Messages.getString("Facsimile"), Cat.ROS_FACS);
|
|---|
| 222 | addROItem(Messages.getString("TimeSignal"), Cat.ROS_TIME);
|
|---|
| 223 | addROItem(Messages.getString("AIS"), Cat.ROS_PAIS);
|
|---|
| 224 | addROItem(Messages.getString("S-AIS"), Cat.ROS_SAIS);
|
|---|
| 225 | radioCatBox.setVisible(false);
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | public void syncPanel() {
|
|---|
| 229 | boolean rad = ((SmedAction.panelMain.mark.getRadar() != Rtb.NORTB) && (SmedAction.panelMain.mark.getRadar() != Rtb.REFLECTOR));
|
|---|
| 230 | groupLabel.setVisible(rad);
|
|---|
| 231 | groupBox.setVisible(rad);
|
|---|
| 232 | periodLabel.setVisible(rad);
|
|---|
| 233 | periodBox.setVisible(rad);
|
|---|
| 234 | seqLabel.setVisible(rad);
|
|---|
| 235 | seqBox.setVisible(rad);
|
|---|
| 236 | rangeLabel.setVisible(rad);
|
|---|
| 237 | rangeBox.setVisible(rad);
|
|---|
| 238 | sector1Label.setVisible(rad);
|
|---|
| 239 | sector1Box.setVisible(rad);
|
|---|
| 240 | sector2Label.setVisible(rad);
|
|---|
| 241 | sector2Box.setVisible(rad);
|
|---|
| 242 | sectorsLabel.setVisible(rad);
|
|---|
| 243 | for (Rtb rtb : rads.keySet()) {
|
|---|
| 244 | rads.get(rtb).setBorderPainted(SmedAction.panelMain.mark.getRadar() == rtb);
|
|---|
| 245 | }
|
|---|
| 246 | groupBox.setText(SmedAction.panelMain.mark.getRaconGroup());
|
|---|
| 247 | seqBox.setText(SmedAction.panelMain.mark.getRaconSequence());
|
|---|
| 248 | periodBox.setText(SmedAction.panelMain.mark.getRaconPeriod());
|
|---|
| 249 | rangeBox.setText(SmedAction.panelMain.mark.getRaconRange());
|
|---|
| 250 | sector1Box.setText(SmedAction.panelMain.mark.getRaconSector1());
|
|---|
| 251 | sector2Box.setText(SmedAction.panelMain.mark.getRaconSector2());
|
|---|
| 252 | aisButton.setSelected(SmedAction.panelMain.mark.getRadio() != Cat.NOROS);
|
|---|
| 253 | aisButton.setBorderPainted(aisButton.isSelected());
|
|---|
| 254 | radioCatBox.setVisible(SmedAction.panelMain.mark.getRadio() != Cat.NOROS);
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | private JRadioButton getRadButton(JRadioButton button, int x, int y, int w, int h, String tip, Rtb rtb) {
|
|---|
| 258 | button.setBounds(new Rectangle(x, y, w, h));
|
|---|
| 259 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 260 | button.setToolTipText(Messages.getString(tip));
|
|---|
| 261 | button.addActionListener(alRad);
|
|---|
| 262 | radarButtons.add(button);
|
|---|
| 263 | rads.put(rtb, button);
|
|---|
| 264 | return button;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | private void addROItem(String str, Cat cat) {
|
|---|
| 268 | radioCats.put(cat, radioCatBox.getItemCount());
|
|---|
| 269 | radioCatBox.addItem(str);
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|