1 7 8 package org.jdesktop.swing.decorator; 9 10 import java.awt.Color ; 11 import java.awt.Component ; 12 13 85 public class Highlighter { 86 87 int order = -1; 90 91 97 public final static Highlighter ledgerBackground = 98 new Highlighter(new Color (0xF5, 0xFF, 0xF5), null); 99 100 106 public final static Highlighter notePadBackground = 107 new Highlighter(new Color (0xFF, 0xFF, 0xCC), null); 108 109 private Color background = null; 110 private Color foreground = null; 111 private Color selectedBackground = null; 112 private Color selectedForeground = null; 113 114 119 public Highlighter() { 120 } 122 123 132 public Highlighter(Color cellBackground, Color cellForeground) { 133 this.background = cellBackground; this.foreground = cellForeground; } 136 137 147 public Component highlight(Component renderer, ComponentAdapter adapter) { 148 return doHighlight(renderer, adapter); 149 } 150 151 162 protected Component doHighlight(Component renderer, ComponentAdapter adapter) { 163 applyBackground(renderer, adapter); 164 applyForeground(renderer, adapter); 165 applyFont(renderer, adapter); return renderer; 168 } 169 170 180 protected void applyBackground(Component renderer, ComponentAdapter adapter) { 181 Color color = computeBackground(renderer, adapter); 182 if (color != null) { 183 renderer.setBackground(color); 184 } 185 } 186 187 197 protected void applyForeground(Component renderer, ComponentAdapter adapter) { 198 Color color = computeForeground(renderer, adapter); 199 if (color != null) { 200 renderer.setForeground(color); 201 } 202 } 203 204 210 protected void applyFont(Component renderer, ComponentAdapter adapter) { 211 } 213 214 239 protected Color computeBackground(Component renderer, ComponentAdapter adapter) { 240 Color seed = background == null ? adapter.target.getBackground() : background; 244 return adapter.isSelected() ? computeSelectedBackground(seed) : seed; 245 } 246 247 272 protected Color computeForeground(Component renderer, ComponentAdapter adapter) { 273 Color seed = foreground == null ? adapter.target.getForeground() : foreground; 277 return adapter.isSelected() ? computeSelectedForeground(seed) : seed; 278 } 279 280 289 protected Color computeSelectedBackground(Color seed) { 290 return selectedBackground == null ? 291 seed == null ? Color.gray : seed.darker() : selectedBackground; 292 } 293 294 303 protected Color computeSelectedForeground(Color seed) { 304 return selectedForeground == null ? Color.white : selectedForeground; 305 } 306 307 313 public Color getBackground() { 314 return background; 315 } 316 317 323 public void setBackground(Color color) { 324 background = color; 325 } 326 327 333 public Color getForeground() { 334 return foreground; 335 } 336 337 343 public void setForeground(Color color) { 344 foreground = color; 345 } 346 347 353 public Color getSelectedBackground() { 354 return selectedBackground; 355 } 356 357 363 public void setSelectedBackground(Color color) { 364 selectedBackground = color; 365 } 366 367 373 public Color getSelectedForeground() { 374 return selectedForeground; 375 } 376 377 383 public void setSelectedForeground(Color color) { 384 selectedForeground = color; 385 } 386 387 } 388 | Popular Tags |