1 7 8 package org.jdesktop.swing.decorator; 9 10 import java.awt.Color ; 11 import java.awt.Component ; 12 13 19 public class AlternateRowHighlighter extends Highlighter { 20 private final static Color defaultOddRowColor = Color.white; 21 private final static Color defaultEvenRowColor = new Color (0xF0, 0xF0, 0xE0); 22 23 public final static Highlighter beige = 24 new AlternateRowHighlighter(Color.white, new Color (245, 245, 220), null); 25 26 public final static Highlighter linePrinter = 27 new AlternateRowHighlighter(Color.white, new Color (0xCC, 0xCC, 0xFF), null); 28 29 public final static Highlighter classicLinePrinter = 30 new AlternateRowHighlighter(Color.white, new Color (0xCC, 0xFF, 0xCC), null); 31 32 public final static Highlighter floralWhite = 33 new AlternateRowHighlighter(Color.white, new Color (255, 250, 240), null); 34 35 public final static Highlighter quickSilver = 36 new AlternateRowHighlighter(Color.white, defaultEvenRowColor, null); 37 38 private Color oddRowBackground = defaultOddRowColor; 39 private Color evenRowBackground = defaultEvenRowColor; 40 41 46 public AlternateRowHighlighter() { 47 } 48 49 61 public AlternateRowHighlighter(Color oddRowBackground, 62 Color evenRowBackground, Color foreground) { 63 super(oddRowBackground, foreground); this.oddRowBackground = oddRowBackground; 65 this.evenRowBackground = evenRowBackground; 66 } 67 68 75 public Color getOddRowBackground() { 76 return oddRowBackground; 77 } 78 79 88 public void setOddRowBackground(Color color) { 89 oddRowBackground = color; 90 } 91 92 99 public Color getEvenRowBackground() { 100 return evenRowBackground; 101 } 102 103 111 public void setEvenRowBackground(Color color) { 112 evenRowBackground = color; 113 } 114 115 128 protected Color computeBackground(Component renderer, 129 ComponentAdapter adapter) { 130 Color color = (adapter.row % 2) == 0 ? 132 oddRowBackground : evenRowBackground; 133 134 if ((color != null) && adapter.isSelected()) { 135 color = computeSelectedBackground(color); 136 } 137 138 return color; 139 } 140 } 141 | Popular Tags |