| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package panels;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.Color;
|
|---|
| 7 | import java.awt.Insets;
|
|---|
| 8 | import java.awt.Rectangle;
|
|---|
| 9 | import java.awt.event.ActionEvent;
|
|---|
| 10 | import java.awt.event.ActionListener;
|
|---|
| 11 | import java.awt.event.FocusEvent;
|
|---|
| 12 | import java.awt.event.FocusListener;
|
|---|
| 13 |
|
|---|
| 14 | import javax.swing.BorderFactory;
|
|---|
| 15 | import javax.swing.ButtonGroup;
|
|---|
| 16 | import javax.swing.ImageIcon;
|
|---|
| 17 | import javax.swing.JButton;
|
|---|
| 18 | import javax.swing.JLabel;
|
|---|
| 19 | import javax.swing.JPanel;
|
|---|
| 20 | import javax.swing.JRadioButton;
|
|---|
| 21 | import javax.swing.JTextField;
|
|---|
| 22 | import javax.swing.SwingConstants;
|
|---|
| 23 |
|
|---|
| 24 | import messages.Messages;
|
|---|
| 25 | import seamarks.SeaMark;
|
|---|
| 26 | import smed.SmedAction;
|
|---|
| 27 |
|
|---|
| 28 | public class PanelMain extends JPanel {
|
|---|
| 29 |
|
|---|
| 30 | private SmedAction dlg;
|
|---|
| 31 | public SeaMark mark = null;
|
|---|
| 32 | public PanelChan panelChan = null;
|
|---|
| 33 | public PanelHaz panelHaz = null;
|
|---|
| 34 | public PanelSpec panelSpec = null;
|
|---|
| 35 | public PanelLights panelLights = null;
|
|---|
| 36 | public PanelMore panelMore = null;
|
|---|
| 37 | public PanelTop panelTop = null;
|
|---|
| 38 | public PanelFog panelFog = null;
|
|---|
| 39 | public PanelRadar panelRadar = null;
|
|---|
| 40 | public PanelLit panelLit = null;
|
|---|
| 41 | public JLabel nameLabel = null;
|
|---|
| 42 | public JTextField nameBox = null;
|
|---|
| 43 | public static JTextField messageBar = null;
|
|---|
| 44 | private FocusListener flName = new FocusListener() {
|
|---|
| 45 | @Override
|
|---|
| 46 | public void focusLost(FocusEvent e) {
|
|---|
| 47 | mark.setName(nameBox.getText());
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override
|
|---|
| 51 | public void focusGained(FocusEvent e) {
|
|---|
| 52 | }
|
|---|
| 53 | };
|
|---|
| 54 | public JButton saveButton = null;
|
|---|
| 55 | private ActionListener alSave = new ActionListener() {
|
|---|
| 56 | @Override
|
|---|
| 57 | public void actionPerformed(ActionEvent e) {
|
|---|
| 58 | mark.saveSign(dlg.node);
|
|---|
| 59 | }
|
|---|
| 60 | };
|
|---|
| 61 | public JButton moreButton = null;
|
|---|
| 62 | private ActionListener alMore = new ActionListener() {
|
|---|
| 63 | @Override
|
|---|
| 64 | public void actionPerformed(ActionEvent e) {
|
|---|
| 65 | if (panelMore.isVisible()) {
|
|---|
| 66 | moreButton.setText(">>");
|
|---|
| 67 | panelMore.setVisible(false);
|
|---|
| 68 | topButton.setEnabled(true);
|
|---|
| 69 | radButton.setEnabled(true);
|
|---|
| 70 | fogButton.setEnabled(true);
|
|---|
| 71 | litButton.setEnabled(true);
|
|---|
| 72 | } else {
|
|---|
| 73 | panelMore.setVisible(true);
|
|---|
| 74 | moreButton.setText("<<");
|
|---|
| 75 | miscButtons.clearSelection();
|
|---|
| 76 | panelTop.setVisible(false);
|
|---|
| 77 | topButton.setBorderPainted(false);
|
|---|
| 78 | topButton.setEnabled(false);
|
|---|
| 79 | panelRadar.setVisible(false);
|
|---|
| 80 | radButton.setBorderPainted(false);
|
|---|
| 81 | radButton.setEnabled(false);
|
|---|
| 82 | panelFog.setVisible(false);
|
|---|
| 83 | fogButton.setBorderPainted(false);
|
|---|
| 84 | fogButton.setEnabled(false);
|
|---|
| 85 | panelLit.setVisible(false);
|
|---|
| 86 | litButton.setBorderPainted(false);
|
|---|
| 87 | litButton.setEnabled(false);
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | };
|
|---|
| 91 | public ButtonGroup typeButtons = null;
|
|---|
| 92 | public JRadioButton chanButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ChanButton.png")));
|
|---|
| 93 | public JRadioButton hazButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/HazButton.png")));
|
|---|
| 94 | public JRadioButton specButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SpecButton.png")));
|
|---|
| 95 | public JRadioButton lightsButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/LightsButton.png")));
|
|---|
| 96 | private ActionListener alType = new ActionListener() {
|
|---|
| 97 | @Override
|
|---|
| 98 | public void actionPerformed(ActionEvent e) {
|
|---|
| 99 | if (chanButton.isSelected()) {
|
|---|
| 100 | chanButton.setBorderPainted(true);
|
|---|
| 101 | panelChan.syncPanel();
|
|---|
| 102 | panelChan.setVisible(true);
|
|---|
| 103 | } else {
|
|---|
| 104 | chanButton.setBorderPainted(false);
|
|---|
| 105 | panelChan.setVisible(false);
|
|---|
| 106 | }
|
|---|
| 107 | if (hazButton.isSelected()) {
|
|---|
| 108 | hazButton.setBorderPainted(true);
|
|---|
| 109 | panelHaz.syncPanel();
|
|---|
| 110 | panelHaz.setVisible(true);
|
|---|
| 111 | } else {
|
|---|
| 112 | hazButton.setBorderPainted(false);
|
|---|
| 113 | panelHaz.setVisible(false);
|
|---|
| 114 | }
|
|---|
| 115 | if (specButton.isSelected()) {
|
|---|
| 116 | specButton.setBorderPainted(true);
|
|---|
| 117 | panelSpec.syncPanel();
|
|---|
| 118 | panelSpec.setVisible(true);
|
|---|
| 119 | } else {
|
|---|
| 120 | specButton.setBorderPainted(false);
|
|---|
| 121 | panelSpec.setVisible(false);
|
|---|
| 122 | }
|
|---|
| 123 | if (lightsButton.isSelected()) {
|
|---|
| 124 | lightsButton.setBorderPainted(true);
|
|---|
| 125 | panelLights.syncPanel();
|
|---|
| 126 | panelLights.setVisible(true);
|
|---|
| 127 | } else {
|
|---|
| 128 | lightsButton.setBorderPainted(false);
|
|---|
| 129 | panelLights.setVisible(false);
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | };
|
|---|
| 133 | private ButtonGroup miscButtons = null;
|
|---|
| 134 | public JRadioButton topButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TopButton.png")));
|
|---|
| 135 | public JRadioButton fogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogButton.png")));
|
|---|
| 136 | public JRadioButton radButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RadarButton.png")));
|
|---|
| 137 | public JRadioButton litButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/LitButton.png")));
|
|---|
| 138 | private ActionListener alMisc = new ActionListener() {
|
|---|
| 139 | @Override
|
|---|
| 140 | public void actionPerformed(ActionEvent e) {
|
|---|
| 141 | if (topButton.isSelected()) {
|
|---|
| 142 | moreButton.setText(">>");
|
|---|
| 143 | panelMore.setVisible(false);
|
|---|
| 144 | topButton.setBorderPainted(true);
|
|---|
| 145 | panelTop.setVisible(true);
|
|---|
| 146 | panelTop.syncPanel();
|
|---|
| 147 | } else {
|
|---|
| 148 | topButton.setBorderPainted(false);
|
|---|
| 149 | panelTop.setVisible(false);
|
|---|
| 150 | }
|
|---|
| 151 | if (fogButton.isSelected()) {
|
|---|
| 152 | moreButton.setText(">>");
|
|---|
| 153 | panelMore.setVisible(false);
|
|---|
| 154 | fogButton.setBorderPainted(true);
|
|---|
| 155 | panelFog.setVisible(true);
|
|---|
| 156 | panelFog.syncPanel();
|
|---|
| 157 | } else {
|
|---|
| 158 | fogButton.setBorderPainted(false);
|
|---|
| 159 | panelFog.setVisible(false);
|
|---|
| 160 | }
|
|---|
| 161 | if (radButton.isSelected()) {
|
|---|
| 162 | moreButton.setText(">>");
|
|---|
| 163 | panelMore.setVisible(false);
|
|---|
| 164 | radButton.setBorderPainted(true);
|
|---|
| 165 | panelRadar.setVisible(true);
|
|---|
| 166 | panelRadar.syncPanel();
|
|---|
| 167 | } else {
|
|---|
| 168 | radButton.setBorderPainted(false);
|
|---|
| 169 | panelRadar.setVisible(false);
|
|---|
| 170 | }
|
|---|
| 171 | if (litButton.isSelected()) {
|
|---|
| 172 | moreButton.setText(">>");
|
|---|
| 173 | panelMore.setVisible(false);
|
|---|
| 174 | litButton.setBorderPainted(true);
|
|---|
| 175 | panelLit.setVisible(true);
|
|---|
| 176 | panelLit.syncPanel();
|
|---|
| 177 | } else {
|
|---|
| 178 | litButton.setBorderPainted(false);
|
|---|
| 179 | panelLit.setVisible(false);
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | };
|
|---|
| 183 |
|
|---|
| 184 | public PanelMain(SmedAction dia) {
|
|---|
| 185 |
|
|---|
| 186 | dlg = dia;
|
|---|
| 187 | setLayout(null);
|
|---|
| 188 | mark = new SeaMark(dlg);
|
|---|
| 189 | mark.setBounds(new Rectangle(235, 0, 165, 160));
|
|---|
| 190 | add(mark);
|
|---|
| 191 | panelChan = new PanelChan(dlg);
|
|---|
| 192 | panelChan.setBounds(new Rectangle(65, 0, 170, 160));
|
|---|
| 193 | panelChan.setVisible(false);
|
|---|
| 194 | add(panelChan);
|
|---|
| 195 | panelHaz = new PanelHaz(dlg);
|
|---|
| 196 | panelHaz.setBounds(new Rectangle(65, 0, 170, 160));
|
|---|
| 197 | panelHaz.setVisible(false);
|
|---|
| 198 | add(panelHaz);
|
|---|
| 199 | panelSpec = new PanelSpec(dlg);
|
|---|
| 200 | panelSpec.setBounds(new Rectangle(65, 0, 170, 160));
|
|---|
| 201 | panelSpec.setVisible(false);
|
|---|
| 202 | add(panelSpec);
|
|---|
| 203 | panelLights = new PanelLights(dlg);
|
|---|
| 204 | panelLights.setBounds(new Rectangle(65, 0, 170, 160));
|
|---|
| 205 | panelLights.setVisible(false);
|
|---|
| 206 | add(panelLights);
|
|---|
| 207 | panelMore = new PanelMore(dlg);
|
|---|
| 208 | panelMore.setBounds(new Rectangle(40, 165, 360, 160));
|
|---|
| 209 | panelMore.setVisible(false);
|
|---|
| 210 | add(panelMore);
|
|---|
| 211 | panelTop = new PanelTop(dlg);
|
|---|
| 212 | panelTop.setBounds(new Rectangle(40, 165, 360, 160));
|
|---|
| 213 | panelTop.setVisible(false);
|
|---|
| 214 | add(panelTop);
|
|---|
| 215 | panelFog = new PanelFog(dlg);
|
|---|
| 216 | panelFog.setBounds(new Rectangle(40, 165, 360, 160));
|
|---|
| 217 | panelFog.setVisible(false);
|
|---|
| 218 | add(panelFog);
|
|---|
| 219 | panelRadar = new PanelRadar(dlg);
|
|---|
| 220 | panelRadar.setBounds(new Rectangle(40, 165, 360, 160));
|
|---|
| 221 | panelRadar.setVisible(false);
|
|---|
| 222 | add(panelRadar);
|
|---|
| 223 | panelLit = new PanelLit(dlg);
|
|---|
| 224 | panelLit.setBounds(new Rectangle(40, 165, 360, 160));
|
|---|
| 225 | panelLit.setVisible(false);
|
|---|
| 226 | add(panelLit);
|
|---|
| 227 |
|
|---|
| 228 | add(getButton(chanButton, 0, 0, 62, 40, "Chan"), null);
|
|---|
| 229 | add(getButton(hazButton, 0, 40, 62, 40, "Haz"), null);
|
|---|
| 230 | add(getButton(specButton, 0, 80, 62, 40, "Spec"), null);
|
|---|
| 231 | add(getButton(lightsButton, 0, 120, 62, 40, "Lights"), null);
|
|---|
| 232 | typeButtons = new ButtonGroup();
|
|---|
| 233 | typeButtons.add(chanButton);
|
|---|
| 234 | typeButtons.add(hazButton);
|
|---|
| 235 | typeButtons.add(specButton);
|
|---|
| 236 | typeButtons.add(lightsButton);
|
|---|
| 237 | chanButton.addActionListener(alType);
|
|---|
| 238 | hazButton.addActionListener(alType);
|
|---|
| 239 | specButton.addActionListener(alType);
|
|---|
| 240 | lightsButton.addActionListener(alType);
|
|---|
| 241 |
|
|---|
| 242 | add(getButton(topButton, 0, 185, 34, 32, "Topmarks"));
|
|---|
| 243 | add(getButton(fogButton, 0, 220, 34, 32, "FogSignals"));
|
|---|
| 244 | add(getButton(radButton, 0, 255, 34, 32, "Radar"));
|
|---|
| 245 | add(getButton(litButton, 0, 290, 34, 32, "Lit"));
|
|---|
| 246 | miscButtons = new ButtonGroup();
|
|---|
| 247 | miscButtons.add(topButton);
|
|---|
| 248 | miscButtons.add(fogButton);
|
|---|
| 249 | miscButtons.add(radButton);
|
|---|
| 250 | miscButtons.add(litButton);
|
|---|
| 251 | topButton.addActionListener(alMisc);
|
|---|
| 252 | fogButton.addActionListener(alMisc);
|
|---|
| 253 | radButton.addActionListener(alMisc);
|
|---|
| 254 | litButton.addActionListener(alMisc);
|
|---|
| 255 |
|
|---|
| 256 | nameLabel = new JLabel();
|
|---|
| 257 | nameLabel.setBounds(new Rectangle(5, 329, 60, 20));
|
|---|
| 258 | nameLabel.setText(tr("Name:"));
|
|---|
| 259 | add(nameLabel);
|
|---|
| 260 | nameBox = new JTextField();
|
|---|
| 261 | nameBox.setBounds(new Rectangle(60, 330, 200, 20));
|
|---|
| 262 | nameBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 263 | add(nameBox);
|
|---|
| 264 | nameBox.addFocusListener(flName);
|
|---|
| 265 |
|
|---|
| 266 | saveButton = new JButton();
|
|---|
| 267 | saveButton.setBounds(new Rectangle(285, 330, 100, 20));
|
|---|
| 268 | saveButton.setText(tr("Save"));
|
|---|
| 269 | add(saveButton);
|
|---|
| 270 | saveButton.addActionListener(alSave);
|
|---|
| 271 |
|
|---|
| 272 | moreButton = new JButton();
|
|---|
| 273 | moreButton.setBounds(new Rectangle(0, 165, 34, 15));
|
|---|
| 274 | moreButton.setMargin(new Insets(0, 0, 0, 0));
|
|---|
| 275 | moreButton.setText(">>");
|
|---|
| 276 | add(moreButton);
|
|---|
| 277 | moreButton.addActionListener(alMore);
|
|---|
| 278 |
|
|---|
| 279 | messageBar = new JTextField();
|
|---|
| 280 | messageBar.setBounds(10, 355, 380, 20);
|
|---|
| 281 | messageBar.setEditable(false);
|
|---|
| 282 | messageBar.setBackground(Color.WHITE);
|
|---|
| 283 | add(messageBar);
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | public void syncPanel() {
|
|---|
| 287 | typeButtons.clearSelection();
|
|---|
| 288 | chanButton.setBorderPainted(false);
|
|---|
| 289 | chanButton.setEnabled(false);
|
|---|
| 290 | hazButton.setBorderPainted(false);
|
|---|
| 291 | hazButton.setEnabled(false);
|
|---|
| 292 | specButton.setBorderPainted(false);
|
|---|
| 293 | specButton.setEnabled(false);
|
|---|
| 294 | lightsButton.setBorderPainted(false);
|
|---|
| 295 | lightsButton.setEnabled(false);
|
|---|
| 296 | miscButtons.clearSelection();
|
|---|
| 297 | topButton.setEnabled(false);
|
|---|
| 298 | topButton.setBorderPainted(false);
|
|---|
| 299 | fogButton.setEnabled(false);
|
|---|
| 300 | fogButton.setBorderPainted(false);
|
|---|
| 301 | radButton.setEnabled(false);
|
|---|
| 302 | radButton.setBorderPainted(false);
|
|---|
| 303 | litButton.setEnabled(false);
|
|---|
| 304 | litButton.setBorderPainted(false);
|
|---|
| 305 | saveButton.setEnabled(false);
|
|---|
| 306 | moreButton.setVisible(false);
|
|---|
| 307 | moreButton.setText(">>");
|
|---|
| 308 | moreButton.setSelected(false);
|
|---|
| 309 | panelChan.setVisible(false);
|
|---|
| 310 | panelHaz.setVisible(false);
|
|---|
| 311 | panelSpec.setVisible(false);
|
|---|
| 312 | panelLights.setVisible(false);
|
|---|
| 313 | panelMore.setVisible(false);
|
|---|
| 314 | panelTop.setVisible(false);
|
|---|
| 315 | panelFog.setVisible(false);
|
|---|
| 316 | panelRadar.setVisible(false);
|
|---|
| 317 | panelLit.setVisible(false);
|
|---|
| 318 | nameBox.setEnabled(false);
|
|---|
| 319 | if (mark != null) {
|
|---|
| 320 | nameBox.setEnabled(true);
|
|---|
| 321 | chanButton.setEnabled(true);
|
|---|
| 322 | hazButton.setEnabled(true);
|
|---|
| 323 | specButton.setEnabled(true);
|
|---|
| 324 | lightsButton.setEnabled(true);
|
|---|
| 325 | nameBox.setText(mark.getName());
|
|---|
| 326 | switch (SeaMark.GrpMAP.get(mark.getObject())) {
|
|---|
| 327 | case LAT:
|
|---|
| 328 | case SAW:
|
|---|
| 329 | chanButton.setBorderPainted(true);
|
|---|
| 330 | panelChan.setVisible(true);
|
|---|
| 331 | panelChan.syncPanel();
|
|---|
| 332 | break;
|
|---|
| 333 | case CAR:
|
|---|
| 334 | case ISD:
|
|---|
| 335 | hazButton.setBorderPainted(true);
|
|---|
| 336 | panelHaz.setVisible(true);
|
|---|
| 337 | panelHaz.syncPanel();
|
|---|
| 338 | break;
|
|---|
| 339 | case SPP:
|
|---|
| 340 | specButton.setBorderPainted(true);
|
|---|
| 341 | panelSpec.setVisible(true);
|
|---|
| 342 | panelSpec.syncPanel();
|
|---|
| 343 | break;
|
|---|
| 344 | case LGT:
|
|---|
| 345 | case STN:
|
|---|
| 346 | case PLF:
|
|---|
| 347 | lightsButton.setBorderPainted(true);
|
|---|
| 348 | panelLights.setVisible(true);
|
|---|
| 349 | panelLights.syncPanel();
|
|---|
| 350 | break;
|
|---|
| 351 | default:
|
|---|
| 352 | break;
|
|---|
| 353 | }
|
|---|
| 354 | panelMore.syncPanel();
|
|---|
| 355 | panelTop.syncPanel();
|
|---|
| 356 | panelFog.syncPanel();
|
|---|
| 357 | panelRadar.syncPanel();
|
|---|
| 358 | panelLit.syncPanel();
|
|---|
| 359 | }
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | private JRadioButton getButton(JRadioButton button, int x, int y, int w, int h, String tip) {
|
|---|
| 363 | button.setBounds(new Rectangle(x, y, w, h));
|
|---|
| 364 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 365 | button.setToolTipText(Messages.getString(tip));
|
|---|
| 366 | return button;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | }
|
|---|