- Timestamp:
- 2015-12-30T21:26:57+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableCellRenderer.java
r8510 r9223 11 11 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.gui.util.GuiHelper; 13 14 14 15 /** … … 43 44 } 44 45 45 protected void renderBackground (MemberTableModel model, OsmPrimitive primitive, boolean isSelected) {46 protected void renderBackgroundForeground(MemberTableModel model, OsmPrimitive primitive, boolean isSelected) { 46 47 Color bgc = UIManager.getColor("Table.background"); 47 48 if (isSelected) { … … 52 53 bgc = BGCOLOR_DOUBLE_ENTRY; 53 54 } 54 setBackground(bgc); 55 } 56 57 protected void renderForeground(boolean isSelected) { 58 Color fgc; 59 if (isSelected) { 60 fgc = UIManager.getColor("Table.selectionForeground"); 61 } else { 62 fgc = UIManager.getColor("Table.foreground"); 63 } 64 setForeground(fgc); 55 GuiHelper.setBackgroundReadable(this, bgc); 65 56 } 66 57 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java
r8870 r9223 33 33 34 34 this.value = (WayConnectionType) value; 35 renderForeground(isSelected);36 35 setToolTipText(((WayConnectionType) value).getToolTip()); 37 renderBackground (getModel(table), null, isSelected);36 renderBackgroundForeground(getModel(table), null, isSelected); 38 37 return this; 39 38 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableMemberCellRenderer.java
r8907 r9223 40 40 Rectangle cellSize = table.getCellRect(row, column, false); 41 41 42 renderForeground(isSelected);43 42 OsmPrimitive primitive = (OsmPrimitive) value; 44 renderBackground (getModel(table), primitive, isSelected);43 renderBackgroundForeground(getModel(table), primitive, isSelected); 45 44 renderPrimitive(primitive, cellSize); 46 45 return this; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableRoleCellRenderer.java
r4072 r9223 15 15 return this; 16 16 17 renderForeground(isSelected);18 17 String role = (String) value; 19 renderBackground (getModel(table), null, isSelected);18 renderBackgroundForeground(getModel(table), null, isSelected); 20 19 setText(role); 21 20 return this; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java
r8903 r9223 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.gui.DefaultNameFormatter; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 15 16 import org.openstreetmap.josm.tools.ImageProvider; 16 17 … … 56 57 bgc = BGCOLOR_DOUBLE_ENTRY; 57 58 } 58 setBackground(bgc);59 GuiHelper.setBackgroundReadable(this, bgc); 59 60 } 60 61 -
trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
r9078 r9223 19 19 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 20 20 import org.openstreetmap.josm.gui.NavigatableComponent; 21 import org.openstreetmap.josm.gui.util.GuiHelper; 21 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 23 … … 209 210 gc.weightx = 1.0; 210 211 add(lblLat = new JLabel(), gc); 211 lblLat.setBackground(Color.WHITE);212 GuiHelper.setBackgroundReadable(lblLat, Color.WHITE); 212 213 lblLat.setOpaque(true); 213 214 lblLat.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); … … 227 228 gc.weightx = 1.0; 228 229 add(lblLon = new JLabel(), gc); 229 lblLon.setBackground(Color.WHITE);230 GuiHelper.setBackgroundReadable(lblLon, Color.WHITE); 230 231 lblLon.setOpaque(true); 231 232 lblLon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); … … 275 276 if (coord == oppositeCoord || 276 277 (coord != null && oppositeCoord != null && coord.lat() == oppositeCoord.lat())) { 277 lblLat.setBackground(Color.WHITE);278 GuiHelper.setBackgroundReadable(lblLat, Color.WHITE); 278 279 } else { 279 lblLat.setBackground(BGCOLOR_DIFFERENCE);280 GuiHelper.setBackgroundReadable(lblLat, BGCOLOR_DIFFERENCE); 280 281 } 281 282 if (coord == oppositeCoord || 282 283 (coord != null && oppositeCoord != null && coord.lon() == oppositeCoord.lon())) { 283 lblLon.setBackground(Color.WHITE);284 GuiHelper.setBackgroundReadable(lblLon, Color.WHITE); 284 285 } else { 285 lblLon.setBackground(BGCOLOR_DIFFERENCE);286 GuiHelper.setBackgroundReadable(lblLon, BGCOLOR_DIFFERENCE); 286 287 } 287 288 } … … 322 323 gc.weightx = 1.0; 323 324 add(lblDistance = new JLabel(), gc); 324 lblDistance.setBackground(Color.WHITE);325 GuiHelper.setBackgroundReadable(lblDistance, Color.WHITE); 325 326 lblDistance.setOpaque(true); 326 327 lblDistance.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); … … 335 336 if (coord != null && oppositeCoord != null) { 336 337 double distance = coord.greatCircleDistance(oppositeCoord); 337 if (distance > 0) { 338 lblDistance.setBackground(BGCOLOR_DIFFERENCE); 339 } else { 340 lblDistance.setBackground(Color.WHITE); 341 } 338 GuiHelper.setBackgroundReadable(lblDistance, distance > 0 ? BGCOLOR_DIFFERENCE : Color.WHITE); 342 339 lblDistance.setText(NavigatableComponent.getDistText(distance)); 343 340 } else { 344 lblDistance.setBackground(coord != oppositeCoord ? BGCOLOR_DIFFERENCE : Color.WHITE);341 GuiHelper.setBackgroundReadable(lblDistance, coord != oppositeCoord ? BGCOLOR_DIFFERENCE : Color.WHITE); 345 342 lblDistance.setText(tr("(none)")); 346 343 } -
trunk/src/org/openstreetmap/josm/gui/history/NodeListTableCellRenderer.java
r9078 r9223 13 13 14 14 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 15 16 import org.openstreetmap.josm.tools.ImageProvider; 16 17 … … 46 47 } 47 48 setText(text); 48 setBackground(bgColor);49 GuiHelper.setBackgroundReadable(this, bgColor); 49 50 } 50 51 -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListTableCellRenderer.java
r9078 r9223 17 17 import org.openstreetmap.josm.data.osm.RelationMemberData; 18 18 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item; 19 import org.openstreetmap.josm.gui.util.GuiHelper; 19 20 import org.openstreetmap.josm.tools.ImageProvider; 20 21 … … 58 59 setText(text); 59 60 setToolTipText(text); 60 setBackground(bgColor);61 GuiHelper.setBackgroundReadable(this, bgColor); 61 62 } 62 63 … … 75 76 setText(text); 76 77 setToolTipText(text); 77 setBackground(bgColor);78 GuiHelper.setBackgroundReadable(this, bgColor); 78 79 } 79 80 -
trunk/src/org/openstreetmap/josm/gui/history/TagTableCellRenderer.java
r9194 r9223 9 9 import javax.swing.UIManager; 10 10 import javax.swing.table.TableCellRenderer; 11 12 import org.openstreetmap.josm.gui.util.GuiHelper; 11 13 12 14 /** … … 24 26 } 25 27 26 protected void setBackground (String key, HistoryBrowserModel.TagTableModel model, boolean isSelected) {28 protected void setBackgroundReadable(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected) { 27 29 Color bgColor = UIManager.getColor("Table.background"); 28 30 if (!model.hasTag(key) && model.isCurrentPointInTime() … … 39 41 } 40 42 41 setBackground(bgColor);43 GuiHelper.setBackgroundReadable(this, bgColor); 42 44 } 43 45 … … 57 59 setText(model.hasTag(key) ? key : ""); 58 60 setToolTipText(getText()); 59 setBackground (key, model, isSelected);61 setBackgroundReadable(key, model, isSelected); 60 62 break; 61 63 case 1: … … 63 65 setText(model.hasTag(key) ? model.getValue(key) : ""); 64 66 setToolTipText(getText()); 65 setBackground (key, model, isSelected);67 setBackgroundReadable(key, model, isSelected); 66 68 break; 67 69 } -
trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java
r9136 r9223 34 34 import org.openstreetmap.josm.data.osm.history.History; 35 35 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 36 import org.openstreetmap.josm.gui.util.GuiHelper; 36 37 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 37 38 import org.openstreetmap.josm.io.XmlWriter; … … 64 65 setShowGrid(false); 65 66 setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 66 setBackground(UIManager.getColor("Button.background"));67 GuiHelper.setBackgroundReadable(this, UIManager.getColor("Button.background")); 67 68 setIntercellSpacing(new Dimension(6, 0)); 68 69 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r9221 r9223 47 47 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 48 48 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 49 import org.openstreetmap.josm.gui.util.GuiHelper; 49 50 import org.openstreetmap.josm.tools.ColorHelper; 50 51 import org.openstreetmap.josm.tools.GBC; … … 230 231 Color c = (Color) o; 231 232 JLabel l = new JLabel(ColorHelper.color2html(c)); 232 l.setBackground(c); 233 // http://stackoverflow.com/a/3943023/2257172 234 l.setForeground((c.getRed()*0.299 + c.getGreen()*0.587 + c.getBlue()*0.114) > 186 ? 235 Color.BLACK : Color.WHITE); 233 GuiHelper.setBackgroundReadable(l, c); 236 234 l.setOpaque(true); 237 235 return l; -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r9070 r9223 5 5 6 6 import java.awt.BasicStroke; 7 import java.awt.Color; 7 8 import java.awt.Component; 8 9 import java.awt.Container; … … 43 44 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 44 45 import org.openstreetmap.josm.tools.CheckParameterUtil; 46 import org.openstreetmap.josm.tools.ColorHelper; 45 47 import org.openstreetmap.josm.tools.GBC; 46 48 import org.openstreetmap.josm.tools.ImageOverlay; … … 367 369 } 368 370 } 371 372 /** 373 * Sets the background color for this component, and adjust the foreground color so the text remains readable. 374 * @param c component 375 * @param background background color 376 * @since 9223 377 */ 378 public static void setBackgroundReadable(JComponent c, Color background) { 379 c.setBackground(background); 380 c.setForeground(ColorHelper.getForegroundColor(background)); 381 } 369 382 } -
trunk/src/org/openstreetmap/josm/tools/ColorHelper.java
r8846 r9223 72 72 return code; 73 73 } 74 75 /** 76 * Determines the correct foreground color (black or white) to use for the given background, 77 * so the text will be readable. 78 * @param bg background color 79 * @return {@code Color#BLACK} or {@code Color#WHITE} 80 * @since 9223 81 */ 82 public static Color getForegroundColor(Color bg) { 83 // http://stackoverflow.com/a/3943023/2257172 84 return (bg.getRed()*0.299 + bg.getGreen()*0.587 + bg.getBlue()*0.114) > 186 ? 85 Color.BLACK : Color.WHITE; 86 } 74 87 }
Note:
See TracChangeset
for help on using the changeset viewer.