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