| 1 | |
package de.glossmaker.gui.bibtex; |
| 2 | |
|
| 3 | |
import java.awt.Color; |
| 4 | |
import java.awt.Component; |
| 5 | |
|
| 6 | |
import javax.swing.JLabel; |
| 7 | |
import javax.swing.JTable; |
| 8 | |
import javax.swing.table.TableCellRenderer; |
| 9 | |
|
| 10 | |
import de.glossmaker.gui.bibtex.model.AItemTableModel; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
public class EnabledCellRenderer extends JLabel implements TableCellRenderer { |
| 18 | |
private static final long serialVersionUID = -2780242639559461938L; |
| 19 | |
|
| 20 | 0 | public EnabledCellRenderer() { |
| 21 | 0 | setOpaque(true); |
| 22 | 0 | } |
| 23 | |
|
| 24 | |
@Override |
| 25 | |
public Component getTableCellRendererComponent(JTable table, Object value, |
| 26 | |
boolean isSelected, boolean hasFocus, int row, int column) { |
| 27 | |
|
| 28 | 0 | Color backgroundColor = new Color(227, 227, 227); |
| 29 | 0 | AItemTableModel model = (AItemTableModel) table.getModel(); |
| 30 | |
|
| 31 | 0 | if (row == model.getRequiredRow() || row == model.getOptionalRow()) { |
| 32 | 0 | backgroundColor = new Color(190, 190, 190); |
| 33 | |
} |
| 34 | 0 | Color textColor = new Color(0, 0, 0); |
| 35 | 0 | if (table.getModel().isCellEditable(row, column)) { |
| 36 | 0 | backgroundColor = new Color(255, 255, 255); |
| 37 | 0 | textColor = new Color(0, 0, 0); |
| 38 | |
} |
| 39 | |
|
| 40 | |
|
| 41 | 0 | Object obj = table.getValueAt(row, column); |
| 42 | 0 | if (obj != null) { |
| 43 | 0 | if (obj instanceof Integer) { |
| 44 | 0 | this.setText(((Integer)obj).toString()); |
| 45 | |
} |
| 46 | |
|
| 47 | 0 | if (obj instanceof String) { |
| 48 | 0 | String text = (String)obj; |
| 49 | 0 | if (row == model.getRequiredRow() || row == model.getOptionalRow()) { |
| 50 | 0 | text = "<html><i>" + text + "</i></html>"; |
| 51 | |
} |
| 52 | 0 | this.setText(text); |
| 53 | 0 | } |
| 54 | |
} else { |
| 55 | 0 | this.setText(""); |
| 56 | |
} |
| 57 | 0 | this.setBackground(backgroundColor); |
| 58 | 0 | this.setForeground(textColor); |
| 59 | |
|
| 60 | 0 | return this; |
| 61 | |
} |
| 62 | |
|
| 63 | |
} |