Changeset 15114 in josm
- Timestamp:
- 2019-05-25T20:59:35+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r15049 r15114 23 23 import java.util.HashSet; 24 24 import java.util.List; 25 import java.util.Locale; 25 26 import java.util.Map; 26 27 import java.util.Objects; 27 28 import java.util.Optional; 28 29 import java.util.Set; 30 import java.util.function.BiConsumer; 31 import java.util.function.Function; 29 32 import java.util.stream.Collectors; 30 33 … … 289 292 290 293 /** 294 * class to render an information of Imagery source 295 * @param <T> type of information 296 */ 297 private static class ImageryTableCellRenderer<T> extends DefaultTableCellRenderer { 298 private final Function<T, Object> mapper; 299 private final Function<T, String> tooltip; 300 private final BiConsumer<T, JLabel> decorator; 301 302 ImageryTableCellRenderer(Function<T, Object> mapper, Function<T, String> tooltip, BiConsumer<T, JLabel> decorator) { 303 this.mapper = mapper; 304 this.tooltip = tooltip; 305 this.decorator = decorator; 306 } 307 308 @Override 309 @SuppressWarnings("unchecked") 310 public final Component getTableCellRendererComponent(JTable table, Object value, boolean 311 isSelected, boolean hasFocus, int row, int column) { 312 T obj = (T) value; 313 JLabel label = (JLabel) super.getTableCellRendererComponent( 314 table, mapper.apply(obj), isSelected, hasFocus, row, column); 315 GuiHelper.setBackgroundReadable(label, UIManager.getColor("Table.background")); 316 if (obj != null) { 317 label.setToolTipText(tooltip.apply(obj)); 318 if (decorator != null) { 319 decorator.accept(obj, label); 320 } 321 } 322 return label; 323 } 324 } 325 326 /** 327 * class to render the category information of Imagery source 328 */ 329 private static class ImageryCategoryTableCellRenderer extends ImageryTableCellRenderer<ImageryCategory> { 330 ImageryCategoryTableCellRenderer() { 331 super(cat -> null, cat -> tr("Imagery category: {0}", cat.getDescription()), 332 (cat, label) -> label.setIcon(cat.getIcon(ImageSizes.TABLE))); 333 } 334 } 335 336 /** 337 * class to render the country information of Imagery source 338 */ 339 private static class ImageryCountryTableCellRenderer extends ImageryTableCellRenderer<String> { 340 ImageryCountryTableCellRenderer() { 341 super(code -> code, code -> code.isEmpty() ? tr("Worldwide") : new Locale("en", code).getDisplayCountry(), null); 342 } 343 } 344 345 /** 291 346 * class to render the name information of Imagery source 292 * @since 8064293 347 */ 294 private static class ImageryNameTableCellRenderer extends DefaultTableCellRenderer { 295 @Override 296 public Component getTableCellRendererComponent(JTable table, Object value, boolean 297 isSelected, boolean hasFocus, int row, int column) { 298 ImageryInfo info = (ImageryInfo) value; 299 JLabel label = (JLabel) super.getTableCellRendererComponent( 300 table, info == null ? null : info.getName(), isSelected, hasFocus, row, column); 301 GuiHelper.setBackgroundReadable(label, UIManager.getColor("Table.background")); 302 if (info != null) { 303 label.setToolTipText(info.getToolTipText()); 304 } 305 return label; 348 private static class ImageryNameTableCellRenderer extends ImageryTableCellRenderer<ImageryInfo> { 349 ImageryNameTableCellRenderer() { 350 super(info -> info == null ? null : info.getName(), ImageryInfo::getToolTipText, null); 306 351 } 307 352 } … … 343 388 mod.getColumn(2).setPreferredWidth(475); 344 389 mod.getColumn(2).setCellRenderer(new ImageryNameTableCellRenderer()); 390 mod.getColumn(1).setCellRenderer(new ImageryCountryTableCellRenderer()); 345 391 mod.getColumn(0).setPreferredWidth(50); 392 mod.getColumn(0).setCellRenderer(new ImageryCategoryTableCellRenderer()); 346 393 mod.getColumn(0).setPreferredWidth(50); 347 394 … … 787 834 public Object getValueAt(int row, int column) { 788 835 ImageryInfo info = layerInfo.getAllDefaultLayers().get(row); 789 ImageryCategory cat = Optional.ofNullable(info.getImageryCategory()).orElse(ImageryCategory.OTHER);790 836 switch (column) { 791 837 case 0: 792 return cat.getIcon(ImageSizes.TABLE);838 return Optional.ofNullable(info.getImageryCategory()).orElse(ImageryCategory.OTHER); 793 839 case 1: 794 840 return info.getCountryCode();
Note:
See TracChangeset
for help on using the changeset viewer.