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