| 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.Rectangle;
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.awt.event.ActionListener;
|
|---|
| 9 | import java.awt.event.FocusEvent;
|
|---|
| 10 | import java.awt.event.FocusListener;
|
|---|
| 11 | import java.util.EnumMap;
|
|---|
| 12 | import java.util.EnumSet;
|
|---|
| 13 |
|
|---|
| 14 | import javax.swing.BorderFactory;
|
|---|
| 15 | import javax.swing.ImageIcon;
|
|---|
| 16 | import javax.swing.JLabel;
|
|---|
| 17 | import javax.swing.JPanel;
|
|---|
| 18 | import javax.swing.JTextField;
|
|---|
| 19 | import javax.swing.JToggleButton;
|
|---|
| 20 | import javax.swing.SwingConstants;
|
|---|
| 21 |
|
|---|
| 22 | import messages.Messages;
|
|---|
| 23 | import seamarks.SeaMark;
|
|---|
| 24 | import seamarks.SeaMark.Att;
|
|---|
| 25 | import seamarks.SeaMark.Chr;
|
|---|
| 26 | import seamarks.SeaMark.Col;
|
|---|
| 27 | import smed.SmedAction;
|
|---|
| 28 |
|
|---|
| 29 | public class PanelChr extends JPanel {
|
|---|
| 30 |
|
|---|
| 31 | private SmedAction dlg;
|
|---|
| 32 | public JLabel col1Label = new JLabel();
|
|---|
| 33 | public JLabel col2Label = new JLabel();
|
|---|
| 34 | public JLabel charLabel = new JLabel();
|
|---|
| 35 | public JTextField charBox = new JTextField();
|
|---|
| 36 | public JToggleButton noneButton = newJToggleButton("/images/NoCharButton.png");
|
|---|
| 37 | public JToggleButton fixedButton = newJToggleButton("/images/FixedButton.png");
|
|---|
| 38 | public JToggleButton flashButton = newJToggleButton("/images/FlashButton.png");
|
|---|
| 39 | public JToggleButton longFlashButton = newJToggleButton("/images/LongFlashButton.png");
|
|---|
| 40 | public JToggleButton quickButton = newJToggleButton("/images/QuickButton.png");
|
|---|
| 41 | public JToggleButton veryQuickButton = newJToggleButton("/images/VeryQuickButton.png");
|
|---|
| 42 | public JToggleButton ultraQuickButton = newJToggleButton("/images/UltraQuickButton.png");
|
|---|
| 43 | public JToggleButton interruptedQuickButton = newJToggleButton("/images/InterruptedQuickButton.png");
|
|---|
| 44 | public JToggleButton interruptedVeryQuickButton = newJToggleButton("/images/InterruptedVeryQuickButton.png");
|
|---|
| 45 | public JToggleButton interruptedUltraQuickButton = newJToggleButton("/images/InterruptedUltraQuickButton.png");
|
|---|
| 46 | public JToggleButton isophasedButton = newJToggleButton("/images/IsophasedButton.png");
|
|---|
| 47 | public JToggleButton occultingButton = newJToggleButton("/images/OccultingButton.png");
|
|---|
| 48 | public JToggleButton morseButton = newJToggleButton("/images/MorseButton.png");
|
|---|
| 49 | public JToggleButton alternatingButton = newJToggleButton("/images/AlternatingButton.png");
|
|---|
| 50 | private EnumMap<Chr, JToggleButton> buttons = new EnumMap<>(Chr.class);
|
|---|
| 51 | private ActionListener alCharButton = new ActionListener() {
|
|---|
| 52 | @Override
|
|---|
| 53 | public void actionPerformed(ActionEvent e) {
|
|---|
| 54 | JToggleButton source = (JToggleButton) e.getSource();
|
|---|
| 55 | EnumSet<Chr> combo = EnumSet.noneOf(Chr.class);
|
|---|
| 56 | for (Chr chr : buttons.keySet()) {
|
|---|
| 57 | JToggleButton button = buttons.get(chr);
|
|---|
| 58 | if (button.isSelected()) {
|
|---|
| 59 | combo.add(chr);
|
|---|
| 60 | button.setBorderPainted(true);
|
|---|
| 61 | } else {
|
|---|
| 62 | combo.remove(chr);
|
|---|
| 63 | button.setBorderPainted(false);
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | if (SeaMark.ChrMAP.containsKey(combo)) {
|
|---|
| 67 | charBox.setText(SeaMark.ChrMAP.get(combo));
|
|---|
| 68 | } else {
|
|---|
| 69 | for (Chr chr : buttons.keySet()) {
|
|---|
| 70 | JToggleButton button = buttons.get(chr);
|
|---|
| 71 | if (button == source) {
|
|---|
| 72 | charBox.setText(SeaMark.ChrMAP.get(EnumSet.of(chr)));
|
|---|
| 73 | button.setSelected(true);
|
|---|
| 74 | button.setBorderPainted(true);
|
|---|
| 75 | } else {
|
|---|
| 76 | button.setSelected(false);
|
|---|
| 77 | button.setBorderPainted(false);
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | String str = charBox.getText();
|
|---|
| 82 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, str);
|
|---|
| 83 | if (!str.contains("Al")) {
|
|---|
| 84 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
|
|---|
| 85 | SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, Col.UNKCOL);
|
|---|
| 86 | } else {
|
|---|
| 87 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | private FocusListener flCharBox = new FocusListener() {
|
|---|
| 93 | @Override
|
|---|
| 94 | public void focusGained(FocusEvent e) {}
|
|---|
| 95 |
|
|---|
| 96 | @Override
|
|---|
| 97 | public void focusLost(FocusEvent e) {
|
|---|
| 98 | String str = charBox.getText();
|
|---|
| 99 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, str);
|
|---|
| 100 | EnumSet<Chr> set = EnumSet.noneOf(Chr.class);
|
|---|
| 101 | for (EnumSet<Chr> map : SeaMark.ChrMAP.keySet()) {
|
|---|
| 102 | if (str.equals(SeaMark.ChrMAP.get(map))) {
|
|---|
| 103 | set = map;
|
|---|
| 104 | break;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 | for (Chr chr : buttons.keySet()) {
|
|---|
| 108 | JToggleButton button = buttons.get(chr);
|
|---|
| 109 | if (set.contains(chr)) {
|
|---|
| 110 | button.setSelected(true);
|
|---|
| 111 | button.setBorderPainted(true);
|
|---|
| 112 | } else {
|
|---|
| 113 | button.setSelected(false);
|
|---|
| 114 | button.setBorderPainted(false);
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 | if (!str.contains("Al")) {
|
|---|
| 118 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
|
|---|
| 119 | SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, Col.UNKCOL);
|
|---|
| 120 | } else {
|
|---|
| 121 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | public PanelChr(SmedAction dia) {
|
|---|
| 127 | dlg = dia;
|
|---|
| 128 | setLayout(null);
|
|---|
| 129 | add(getChrButton(noneButton, 0, 0, 44, 16, Messages.getString("NoChar"), Chr.UNKCHR));
|
|---|
| 130 | add(getChrButton(fixedButton, 0, 16, 44, 16, Messages.getString("FChar"), Chr.FIXED));
|
|---|
| 131 | add(getChrButton(flashButton, 0, 32, 44, 16, Messages.getString("FlChar"), Chr.FLASH));
|
|---|
| 132 | add(getChrButton(longFlashButton, 0, 48, 44, 16, Messages.getString("LFlChar"), Chr.LFLASH));
|
|---|
| 133 | add(getChrButton(quickButton, 0, 64, 44, 16, Messages.getString("QChar"), Chr.QUICK));
|
|---|
| 134 | add(getChrButton(veryQuickButton, 0, 80, 44, 16, Messages.getString("VQChar"), Chr.VQUICK));
|
|---|
| 135 | add(getChrButton(ultraQuickButton, 0, 96, 44, 16, Messages.getString("UQChar"), Chr.UQUICK));
|
|---|
| 136 | add(getChrButton(alternatingButton, 44, 0, 44, 16, Messages.getString("AlChar"), Chr.ALTERNATING));
|
|---|
| 137 | add(getChrButton(isophasedButton, 44, 16, 44, 16, Messages.getString("IsoChar"), Chr.ISOPHASED));
|
|---|
| 138 | add(getChrButton(occultingButton, 44, 32, 44, 16, Messages.getString("OcChar"), Chr.OCCULTING));
|
|---|
| 139 | add(getChrButton(morseButton, 44, 48, 44, 16, Messages.getString("MoChar"), Chr.MORSE));
|
|---|
| 140 | add(getChrButton(interruptedQuickButton, 44, 64, 44, 16, Messages.getString("IQChar"), Chr.IQUICK));
|
|---|
| 141 | add(getChrButton(interruptedVeryQuickButton, 44, 80, 44, 16, Messages.getString("IVQChar"), Chr.IVQUICK));
|
|---|
| 142 | add(getChrButton(interruptedUltraQuickButton, 44, 96, 44, 16, Messages.getString("IUQChar"), Chr.IUQUICK));
|
|---|
| 143 | charLabel.setBounds(new Rectangle(0, 113, 88, 20));
|
|---|
| 144 | charLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 145 | charLabel.setText(Messages.getString("Character"));
|
|---|
| 146 | add(charLabel);
|
|---|
| 147 | col1Label.setBounds(new Rectangle(10, 135, 10, 20));
|
|---|
| 148 | col1Label.setOpaque(true);
|
|---|
| 149 | add(col1Label);
|
|---|
| 150 | col2Label.setBounds(new Rectangle(70, 135, 10, 20));
|
|---|
| 151 | col2Label.setOpaque(true);
|
|---|
| 152 | add(col2Label);
|
|---|
| 153 | charBox.setBounds(new Rectangle(20, 135, 50, 20));
|
|---|
| 154 | charBox.setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 155 | add(charBox);
|
|---|
| 156 | charBox.addFocusListener(flCharBox);
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | private static JToggleButton newJToggleButton(String buttonIcon) {
|
|---|
| 160 | return new JToggleButton(new ImageIcon(PanelChr.class.getResource(buttonIcon)));
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | public void syncPanel() {
|
|---|
| 164 | String str = (String) SmedAction.panelMain.mark.getLightAtt(Att.CHR, 0);
|
|---|
| 165 | charBox.setText(str);
|
|---|
| 166 | EnumSet<Chr> set = EnumSet.noneOf(Chr.class);
|
|---|
| 167 | for (EnumSet<Chr> map : SeaMark.ChrMAP.keySet()) {
|
|---|
| 168 | if (dlg.node != null && str.equals(SeaMark.ChrMAP.get(map))) {
|
|---|
| 169 | set = map;
|
|---|
| 170 | break;
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|
| 173 | if (!str.contains("Al")) {
|
|---|
| 174 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
|
|---|
| 175 | } else {
|
|---|
| 176 | col2Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0)));
|
|---|
| 177 | }
|
|---|
| 178 | col1Label.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getLightAtt(Att.COL, 0)));
|
|---|
| 179 | for (Chr chr : buttons.keySet()) {
|
|---|
| 180 | JToggleButton button = buttons.get(chr);
|
|---|
| 181 | if (set.contains(chr)) {
|
|---|
| 182 | button.setSelected(true);
|
|---|
| 183 | button.setBorderPainted(true);
|
|---|
| 184 | } else {
|
|---|
| 185 | button.setSelected(false);
|
|---|
| 186 | button.setBorderPainted(false);
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | private JToggleButton getChrButton(JToggleButton button, int x, int y, int w, int h, String tip, Chr chr) {
|
|---|
| 192 | button.setBounds(new Rectangle(x, y, w, h));
|
|---|
| 193 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
|---|
| 194 | button.setBorderPainted(false);
|
|---|
| 195 | button.setToolTipText(tr(tip));
|
|---|
| 196 | button.addActionListener(alCharButton);
|
|---|
| 197 | buttons.put(chr, button);
|
|---|
| 198 | return button;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | }
|
|---|