| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.gui.table; |
| 27 |
|
| 28 |
import javax.swing.table.DefaultTableCellRenderer; |
| 29 |
import javax.swing.*; |
| 30 |
import java.awt.*; |
| 31 |
|
| 32 |
import jam.mac.Utils; |
| 33 |
|
| 34 |
public class MultiLineTableCellRenderer extends DefaultTableCellRenderer { |
| 35 |
|
| 36 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
| 37 |
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
| 38 |
if ((row % 2 == 0) && !isSelected) { |
| 39 |
Color newColour = alternateRowColor(table.getSelectionBackground()); |
| 40 |
label.setBackground(newColour); |
| 41 |
} else if (!isSelected) { |
| 42 |
label.setBackground(table.getBackground()); |
| 43 |
} |
| 44 |
return label; |
| 45 |
} |
| 46 |
|
| 47 |
public Color alternateRowColor(Color selectionColor) { |
| 48 |
Color useColor = selectionColor; |
| 49 |
if (Utils.isMacOSX()) { |
| 50 |
useColor = UIManager.getColor("Focus.color"); |
| 51 |
} |
| 52 |
return new Color(255 - (255 - useColor.getRed()) / 10, 255 - (255 - useColor.getGreen()) / 10, 255 - (255 - useColor.getBlue()) / 10); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
protected void setValue(Object value) { |
| 57 |
MultiLineTableCellContent content = (MultiLineTableCellContent) value; |
| 58 |
setIcon(content.getTableCellIcon()); |
| 59 |
setText(content.getTableCellContent()); |
| 60 |
setToolTipText(content.getToolTipContent()); |
| 61 |
} |
| 62 |
} |