Changeset 32767 in osm for applications/editors/josm/plugins/smed/src/panels/PanelCol.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/PanelCol.java
r30738 r32767 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.*; 6 import java.awt.event.*; 7 import javax.swing.*; 8 9 import java.util.*; 5 import java.awt.Color; 6 import java.awt.Rectangle; 7 import java.awt.event.ActionEvent; 8 import java.awt.event.ActionListener; 9 import java.util.ArrayList; 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.JPanel; 16 import javax.swing.JRadioButton; 10 17 11 18 import messages.Messages; 19 import seamarks.SeaMark; 20 import seamarks.SeaMark.Att; 21 import seamarks.SeaMark.Col; 22 import seamarks.SeaMark.Ent; 12 23 import smed.SmedAction; 13 import seamarks.SeaMark;14 import seamarks.SeaMark.*;15 24 16 25 public class PanelCol extends JPanel { 17 26 18 private SmedAction dlg; 19 private Ent ent; 20 private ButtonGroup colourButtons = new ButtonGroup(); 21 public JRadioButton delButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/DelButton.png"))); 22 public JRadioButton addButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/AddButton.png"))); 23 public JRadioButton whiteButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/WhiteButton.png"))); 24 public JRadioButton redButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RedButton.png"))); 25 public JRadioButton greenButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/GreenButton.png"))); 26 public JRadioButton yellowButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/YellowButton.png"))); 27 public JRadioButton orangeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OrangeButton.png"))); 28 public JRadioButton amberButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/AmberButton.png"))); 29 public JRadioButton blueButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BlueButton.png"))); 30 public JRadioButton violetButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/VioletButton.png"))); 31 public JRadioButton blackButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BlackButton.png"))); 32 public JRadioButton greyButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/GreyButton.png"))); 33 public JRadioButton brownButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BrownButton.png"))); 34 public JRadioButton magentaButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/MagentaButton.png"))); 35 public JRadioButton pinkButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PinkButton.png"))); 36 public EnumMap<Col, JRadioButton> colours = new EnumMap<>(Col.class); 37 private ActionListener alColour = new ActionListener() { 38 public void actionPerformed(java.awt.event.ActionEvent e) { 39 for (Col col : colours.keySet()) { 40 JRadioButton button = colours.get(col); 41 if (button.isSelected()) { 42 if (ent == Ent.LIGHT) { 43 if (((String) SmedAction.panelMain.mark.getLightAtt(Att.CHR, 0)).contains("Al")) { 44 if (((button == delButton) && (SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0) == Col.UNKCOL)) 45 || (SmedAction.panelMain.mark.getLightAtt(Att.COL, 0) == Col.UNKCOL)) { 46 SmedAction.panelMain.mark.setLightAtt(Att.COL, 0, col); 47 SmedAction.panelMain.panelLit.panelChr.col1Label.setBackground(SeaMark.ColMAP.get(col)); 48 } else { 49 SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, col); 50 SmedAction.panelMain.panelLit.panelChr.col2Label.setBackground(SeaMark.ColMAP.get(col)); 51 } 52 } else { 53 SmedAction.panelMain.mark.setLightAtt(Att.COL, 0, col); 54 SmedAction.panelMain.panelLit.panelChr.col1Label.setBackground(SeaMark.ColMAP.get(col)); 55 SmedAction.panelMain.panelLit.panelChr.col2Label.setBackground(SeaMark.ColMAP.get(col)); 56 } 57 button.setBorderPainted(true); 58 } else { 59 if (button == delButton) { 60 SmedAction.panelMain.mark.subColour(ent, stackIdx); 61 } else if (button == addButton) { 62 if (stackCol.size() != 0) 63 stackIdx++; 64 if (stackCol.size() == 0) 65 SmedAction.panelMain.mark.setColour(ent, col); 66 else 67 switch (SmedAction.panelMain.mark.getPattern(ent)) { 68 case NOPAT: 69 break; 70 case BORDER: 71 case CROSS: 72 if (stackCol.size() < 2) 73 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 74 break; 75 case SQUARED: 76 if (stackCol.size() < 4) 77 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 78 break; 79 default: 80 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 81 break; 82 } 83 } else { 84 SmedAction.panelMain.mark.setColour(ent, stackIdx, col); 85 } 86 syncPanel(); 87 } 88 } else { 89 button.setBorderPainted(false); 90 } 91 } 92 } 93 }; 94 private JPanel stack; 95 private ButtonGroup stackColours = new ButtonGroup(); 96 private ArrayList<JRadioButton> stackCol = new ArrayList<>(); 97 private int stackIdx = 0; 98 private ActionListener alStack = new ActionListener() { 99 public void actionPerformed(java.awt.event.ActionEvent e) { 100 for (int i = 0; stackCol.size() > i; i++) { 101 JRadioButton button = stackCol.get(i); 102 if (button.isSelected()) { 103 stackIdx = i; 104 button.setBorderPainted(true); 105 } else { 106 button.setBorderPainted(false); 107 } 108 } 109 } 110 }; 111 112 public PanelCol(SmedAction dia, Ent entity) { 113 dlg = dia; 114 ent = entity; 115 setLayout(null); 116 add(getColButton(delButton, 0, 0, 34, 16, Messages.getString("RemColour"), Col.UNKCOL)); 117 add(getColButton(whiteButton, 0, 16, 34, 16, Messages.getString("White"), Col.WHITE)); 118 add(getColButton(redButton, 0, 32, 34, 16, Messages.getString("Red"), Col.RED)); 119 add(getColButton(orangeButton, 0, 48, 34, 16, Messages.getString("Orange"), Col.ORANGE)); 120 add(getColButton(amberButton, 0, 64, 34, 16, Messages.getString("Amber"), Col.AMBER)); 121 add(getColButton(yellowButton, 0, 80, 34, 16, Messages.getString("Yellow"), Col.YELLOW)); 122 add(getColButton(greenButton, 0, 96, 34, 16, Messages.getString("Green"), Col.GREEN)); 123 add(getColButton(blueButton, 0, 112, 34, 16, Messages.getString("Blue"), Col.BLUE)); 124 add(getColButton(violetButton, 0, 128, 34, 16, Messages.getString("Violet"), Col.VIOLET)); 125 if (ent != Ent.LIGHT) { 126 add(getColButton(addButton, 0, 144, 34, 16, Messages.getString("AddColour"), Col.BLANK)); 127 add(getColButton(blackButton, 37, 0, 34, 16, Messages.getString("Black"), Col.BLACK)); 128 add(getColButton(greyButton, 37, 16, 34, 16, Messages.getString("Grey"), Col.GREY)); 129 add(getColButton(brownButton, 37, 32, 34, 16, Messages.getString("Brown"), Col.BROWN)); 130 add(getColButton(magentaButton, 37, 48, 34, 16, Messages.getString("Magenta"), Col.MAGENTA)); 131 add(getColButton(pinkButton, 37, 64, 34, 16, Messages.getString("Pink"), Col.PINK)); 132 133 stack = new JPanel(); 134 stack.setBorder(BorderFactory.createLineBorder(Color.black, 2)); 135 stack.setBounds(38, 87, 34, 64); 136 stack.setLayout(null); 137 add(stack); 138 } 139 } 140 141 public void trimStack(int max) { 142 while (stackCol.size() > max) { 143 stackCol.get(stackCol.size() - 1).setSelected(true); 144 delButton.doClick(); 145 } 146 } 147 148 public void syncPanel() { 149 if (ent == Ent.LIGHT) { 150 for (Col col : colours.keySet()) { 151 JRadioButton button = colours.get(col); 152 if (SmedAction.panelMain.mark.getLightAtt(Att.COL, 0) == col) { 153 button.setBorderPainted(true); 154 } else 155 button.setBorderPainted(false); 156 } 157 } else { 158 int idx; 159 for (idx = 0; SmedAction.panelMain.mark.getColour(ent, idx) != Col.UNKCOL; idx++) { 160 if (stackCol.size() <= idx) { 161 stackCol.add(idx, new JRadioButton(new ImageIcon(getClass().getResource("/images/ColourButton.png")))); 162 JRadioButton btnI = stackCol.get(idx); 163 btnI.setBorder(BorderFactory.createLoweredBevelBorder()); 164 stack.add(btnI); 165 stackColours.add(btnI); 166 btnI.addActionListener(alStack); 167 } 168 } 169 while (idx < stackCol.size()) { 170 JRadioButton btnI = stackCol.get(idx); 171 btnI.removeActionListener(alStack); 172 stackColours.remove(btnI); 173 stack.remove(btnI); 174 stackCol.remove(idx); 175 } 176 if (stackIdx >= stackCol.size()) 177 stackIdx = stackCol.size() - 1; 178 if (stackIdx < 0) 179 stackIdx = 0; 180 if (stackCol.size() == 0) { 181 stack.repaint(); 182 } else { 183 int height = 60 / stackCol.size(); 184 for (idx = 0; stackCol.size() > idx; idx++) { 185 JRadioButton btnI = stackCol.get(idx); 186 btnI.setBounds(2, (2 + (idx * height)), 30, height); 187 btnI.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getColour(ent, idx))); 188 if (stackIdx == idx) { 189 btnI.setBorderPainted(true); 190 } else { 191 btnI.setBorderPainted(false); 192 } 193 } 194 } 195 } 196 } 197 198 private JRadioButton getColButton(JRadioButton button, int x, int y, int w, int h, String tip, Col col) { 199 button.setBounds(new Rectangle(x, y, w, h)); 200 button.setBorder(BorderFactory.createLoweredBevelBorder()); 201 button.setToolTipText(tr(tip)); 202 button.addActionListener(alColour); 203 colourButtons.add(button); 204 colours.put(col, button); 205 return button; 206 } 27 private SmedAction dlg; 28 private Ent ent; 29 private ButtonGroup colourButtons = new ButtonGroup(); 30 public JRadioButton delButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/DelButton.png"))); 31 public JRadioButton addButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/AddButton.png"))); 32 public JRadioButton whiteButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/WhiteButton.png"))); 33 public JRadioButton redButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RedButton.png"))); 34 public JRadioButton greenButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/GreenButton.png"))); 35 public JRadioButton yellowButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/YellowButton.png"))); 36 public JRadioButton orangeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OrangeButton.png"))); 37 public JRadioButton amberButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/AmberButton.png"))); 38 public JRadioButton blueButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BlueButton.png"))); 39 public JRadioButton violetButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/VioletButton.png"))); 40 public JRadioButton blackButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BlackButton.png"))); 41 public JRadioButton greyButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/GreyButton.png"))); 42 public JRadioButton brownButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BrownButton.png"))); 43 public JRadioButton magentaButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/MagentaButton.png"))); 44 public JRadioButton pinkButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PinkButton.png"))); 45 public EnumMap<Col, JRadioButton> colours = new EnumMap<>(Col.class); 46 private ActionListener alColour = new ActionListener() { 47 @Override 48 public void actionPerformed(ActionEvent e) { 49 for (Col col : colours.keySet()) { 50 JRadioButton button = colours.get(col); 51 if (button.isSelected()) { 52 if (ent == Ent.LIGHT) { 53 if (((String) SmedAction.panelMain.mark.getLightAtt(Att.CHR, 0)).contains("Al")) { 54 if (((button == delButton) && (SmedAction.panelMain.mark.getLightAtt(Att.ALT, 0) == Col.UNKCOL)) 55 || (SmedAction.panelMain.mark.getLightAtt(Att.COL, 0) == Col.UNKCOL)) { 56 SmedAction.panelMain.mark.setLightAtt(Att.COL, 0, col); 57 SmedAction.panelMain.panelLit.panelChr.col1Label.setBackground(SeaMark.ColMAP.get(col)); 58 } else { 59 SmedAction.panelMain.mark.setLightAtt(Att.ALT, 0, col); 60 SmedAction.panelMain.panelLit.panelChr.col2Label.setBackground(SeaMark.ColMAP.get(col)); 61 } 62 } else { 63 SmedAction.panelMain.mark.setLightAtt(Att.COL, 0, col); 64 SmedAction.panelMain.panelLit.panelChr.col1Label.setBackground(SeaMark.ColMAP.get(col)); 65 SmedAction.panelMain.panelLit.panelChr.col2Label.setBackground(SeaMark.ColMAP.get(col)); 66 } 67 button.setBorderPainted(true); 68 } else { 69 if (button == delButton) { 70 SmedAction.panelMain.mark.subColour(ent, stackIdx); 71 } else if (button == addButton) { 72 if (stackCol.size() != 0) { 73 stackIdx++; 74 } 75 if (stackCol.size() == 0) { 76 SmedAction.panelMain.mark.setColour(ent, col); 77 } else { 78 switch (SmedAction.panelMain.mark.getPattern(ent)) { 79 case NOPAT: 80 break; 81 case BORDER: 82 case CROSS: 83 if (stackCol.size() < 2) { 84 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 85 } 86 break; 87 case SQUARED: 88 if (stackCol.size() < 4) { 89 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 90 } 91 break; 92 default: 93 SmedAction.panelMain.mark.addColour(ent, stackIdx, col); 94 break; 95 } 96 } 97 } else { 98 SmedAction.panelMain.mark.setColour(ent, stackIdx, col); 99 } 100 syncPanel(); 101 } 102 } else { 103 button.setBorderPainted(false); 104 } 105 } 106 } 107 }; 108 private JPanel stack; 109 private ButtonGroup stackColours = new ButtonGroup(); 110 private ArrayList<JRadioButton> stackCol = new ArrayList<>(); 111 private int stackIdx = 0; 112 private ActionListener alStack = new ActionListener() { 113 @Override 114 public void actionPerformed(ActionEvent e) { 115 for (int i = 0; stackCol.size() > i; i++) { 116 JRadioButton button = stackCol.get(i); 117 if (button.isSelected()) { 118 stackIdx = i; 119 button.setBorderPainted(true); 120 } else { 121 button.setBorderPainted(false); 122 } 123 } 124 } 125 }; 126 127 public PanelCol(SmedAction dia, Ent entity) { 128 dlg = dia; 129 ent = entity; 130 setLayout(null); 131 add(getColButton(delButton, 0, 0, 34, 16, Messages.getString("RemColour"), Col.UNKCOL)); 132 add(getColButton(whiteButton, 0, 16, 34, 16, Messages.getString("White"), Col.WHITE)); 133 add(getColButton(redButton, 0, 32, 34, 16, Messages.getString("Red"), Col.RED)); 134 add(getColButton(orangeButton, 0, 48, 34, 16, Messages.getString("Orange"), Col.ORANGE)); 135 add(getColButton(amberButton, 0, 64, 34, 16, Messages.getString("Amber"), Col.AMBER)); 136 add(getColButton(yellowButton, 0, 80, 34, 16, Messages.getString("Yellow"), Col.YELLOW)); 137 add(getColButton(greenButton, 0, 96, 34, 16, Messages.getString("Green"), Col.GREEN)); 138 add(getColButton(blueButton, 0, 112, 34, 16, Messages.getString("Blue"), Col.BLUE)); 139 add(getColButton(violetButton, 0, 128, 34, 16, Messages.getString("Violet"), Col.VIOLET)); 140 if (ent != Ent.LIGHT) { 141 add(getColButton(addButton, 0, 144, 34, 16, Messages.getString("AddColour"), Col.BLANK)); 142 add(getColButton(blackButton, 37, 0, 34, 16, Messages.getString("Black"), Col.BLACK)); 143 add(getColButton(greyButton, 37, 16, 34, 16, Messages.getString("Grey"), Col.GREY)); 144 add(getColButton(brownButton, 37, 32, 34, 16, Messages.getString("Brown"), Col.BROWN)); 145 add(getColButton(magentaButton, 37, 48, 34, 16, Messages.getString("Magenta"), Col.MAGENTA)); 146 add(getColButton(pinkButton, 37, 64, 34, 16, Messages.getString("Pink"), Col.PINK)); 147 148 stack = new JPanel(); 149 stack.setBorder(BorderFactory.createLineBorder(Color.black, 2)); 150 stack.setBounds(38, 87, 34, 64); 151 stack.setLayout(null); 152 add(stack); 153 } 154 } 155 156 public void trimStack(int max) { 157 while (stackCol.size() > max) { 158 stackCol.get(stackCol.size() - 1).setSelected(true); 159 delButton.doClick(); 160 } 161 } 162 163 public void syncPanel() { 164 if (ent == Ent.LIGHT) { 165 for (Col col : colours.keySet()) { 166 JRadioButton button = colours.get(col); 167 if (SmedAction.panelMain.mark.getLightAtt(Att.COL, 0) == col) { 168 button.setBorderPainted(true); 169 } else { 170 button.setBorderPainted(false); 171 } 172 } 173 } else { 174 int idx; 175 for (idx = 0; SmedAction.panelMain.mark.getColour(ent, idx) != Col.UNKCOL; idx++) { 176 if (stackCol.size() <= idx) { 177 stackCol.add(idx, new JRadioButton(new ImageIcon(getClass().getResource("/images/ColourButton.png")))); 178 JRadioButton btnI = stackCol.get(idx); 179 btnI.setBorder(BorderFactory.createLoweredBevelBorder()); 180 stack.add(btnI); 181 stackColours.add(btnI); 182 btnI.addActionListener(alStack); 183 } 184 } 185 while (idx < stackCol.size()) { 186 JRadioButton btnI = stackCol.get(idx); 187 btnI.removeActionListener(alStack); 188 stackColours.remove(btnI); 189 stack.remove(btnI); 190 stackCol.remove(idx); 191 } 192 if (stackIdx >= stackCol.size()) { 193 stackIdx = stackCol.size() - 1; 194 } 195 if (stackIdx < 0) { 196 stackIdx = 0; 197 } 198 if (stackCol.size() == 0) { 199 stack.repaint(); 200 } else { 201 int height = 60 / stackCol.size(); 202 for (idx = 0; stackCol.size() > idx; idx++) { 203 JRadioButton btnI = stackCol.get(idx); 204 btnI.setBounds(2, (2 + (idx * height)), 30, height); 205 btnI.setBackground(SeaMark.ColMAP.get(SmedAction.panelMain.mark.getColour(ent, idx))); 206 if (stackIdx == idx) { 207 btnI.setBorderPainted(true); 208 } else { 209 btnI.setBorderPainted(false); 210 } 211 } 212 } 213 } 214 } 215 216 private JRadioButton getColButton(JRadioButton button, int x, int y, int w, int h, String tip, Col col) { 217 button.setBounds(new Rectangle(x, y, w, h)); 218 button.setBorder(BorderFactory.createLoweredBevelBorder()); 219 button.setToolTipText(tr(tip)); 220 button.addActionListener(alColour); 221 colourButtons.add(button); 222 colours.put(col, button); 223 return button; 224 } 207 225 208 226 }
Note:
See TracChangeset
for help on using the changeset viewer.
