Changeset 12953 in josm
- Timestamp:
- 2017-10-08T18:37:02+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r12952 r12953 7 7 import java.awt.Component; 8 8 import java.awt.Dimension; 9 import java.awt.Font; 9 10 import java.awt.GridBagLayout; 10 11 import java.awt.event.MouseAdapter; … … 16 17 import java.util.List; 17 18 import java.util.Map; 19 import java.util.Objects; 18 20 19 21 import javax.swing.BorderFactory; … … 47 49 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 48 50 import org.openstreetmap.josm.gui.util.GuiHelper; 51 import org.openstreetmap.josm.tools.CheckParameterUtil; 49 52 import org.openstreetmap.josm.tools.ColorHelper; 50 53 import org.openstreetmap.josm.tools.GBC; … … 78 81 79 82 public ColorEntry(String key, String colorHtml) { 83 CheckParameterUtil.ensureParameterNotNull(key, "key"); 80 84 this.key = key; 81 85 this.color = ColorHelper.html2color(colorHtml); … … 85 89 } 86 90 91 public String getDisplay() { 92 return Main.pref.getColorName(key); 93 } 94 87 95 @Override 88 96 public int compareTo(ColorEntry o) { 89 return Collator.getInstance().compare(getName(key), getName(o.key)); 97 if (o == null) return -1; 98 return Collator.getInstance().compare(getDisplay(), o.getDisplay()); 90 99 } 91 100 } … … 111 120 } 112 121 122 public ColorEntry getEntry(int row) { 123 return data.get(row); 124 } 125 113 126 public List<ColorEntry> getData() { 114 127 return data; … … 136 149 @Override 137 150 public Object getValueAt(int rowIndex, int columnIndex) { 138 return columnIndex == 0 ? getName(data.get(rowIndex).key) : data.get(rowIndex).color;151 return columnIndex == 0 ? data.get(rowIndex) : data.get(rowIndex).color; 139 152 } 140 153 … … 153 166 if (columnIndex == 1 && aValue instanceof Color) { 154 167 data.get(rowIndex).color = (Color) aValue; 155 fireTable CellUpdated(rowIndex,columnIndex);168 fireTableRowsUpdated(rowIndex, rowIndex); 156 169 } 157 170 } … … 211 224 } 212 225 213 private static String getName(String o) {214 return Main.pref.getColorName(o);215 }216 217 226 @Override 218 227 public void addGui(final PreferenceTabbedPane gui) { … … 223 232 colorEdit.addActionListener(e -> { 224 233 int sel = colors.getSelectedRow(); 225 JColorChooser chooser = new JColorChooser((Color) colors.getValueAt(sel, 1)); 234 ColorEntry ce = tableModel.getEntry(sel); 235 JColorChooser chooser = new JColorChooser(ce.color); 226 236 int answer = JOptionPane.showConfirmDialog( 227 237 gui, chooser, 228 tr("Choose a color for {0}", getName((String) colors.getValueAt(sel, 0))),238 tr("Choose a color for {0}", ce.getDisplay()), 229 239 JOptionPane.OK_CANCEL_OPTION, 230 240 JOptionPane.PLAIN_MESSAGE); … … 236 246 defaultSet.addActionListener(e -> { 237 247 int sel = colors.getSelectedRow(); 238 String name = (String) colors.getValueAt(sel, 0);239 Color c = Main.pref.getDefaultColor( name);248 ColorEntry ce = tableModel.getEntry(sel); 249 Color c = Main.pref.getDefaultColor(ce.key); 240 250 if (c != null) { 241 251 colors.setValueAt(c, sel, 1); … … 244 254 JButton defaultAll = new JButton(tr("Set all to default")); 245 255 defaultAll.addActionListener(e -> { 246 for (int i = 0; i < colors.getRowCount(); ++i) { 247 String name = (String) colors.getValueAt(i, 0); 248 Color c = Main.pref.getDefaultColor(name); 256 List<ColorEntry> data = tableModel.getData(); 257 for (int i = 0; i < data.size(); ++i) { 258 ColorEntry ce = data.get(i); 259 Color c = Main.pref.getDefaultColor(ce.key); 249 260 if (c != null) { 250 261 colors.setValueAt(c, i, 1); … … 279 290 }); 280 291 colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 292 colors.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { 293 @Override 294 public Component getTableCellRendererComponent( 295 JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 296 Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 297 if (value != null && comp instanceof JLabel) { 298 JLabel label = (JLabel) comp; 299 ColorEntry e = (ColorEntry) value; 300 label.setText(e.getDisplay()); 301 if (!Objects.equals(e.color, Main.pref.getDefaultColor(e.key))) { 302 label.setFont(label.getFont().deriveFont(Font.BOLD)); 303 } else { 304 label.setFont(label.getFont().deriveFont(Font.PLAIN)); 305 } 306 return label; 307 } 308 return comp; 309 } 310 }); 281 311 colors.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 282 312 @Override … … 315 345 316 346 Boolean isRemoveColor(int row) { 317 return tableModel.get Data().get(row).key.startsWith("layer.");347 return tableModel.getEntry(row).key.startsWith("layer."); 318 348 } 319 349
Note:
See TracChangeset
for help on using the changeset viewer.