| 1 | |
package de.glossmaker.gui.gloss.importGloss; |
| 2 | |
|
| 3 | |
import java.awt.Color; |
| 4 | |
import java.awt.Component; |
| 5 | |
|
| 6 | |
import javax.swing.BorderFactory; |
| 7 | |
import javax.swing.JLabel; |
| 8 | |
import javax.swing.JTable; |
| 9 | |
import javax.swing.border.Border; |
| 10 | |
import javax.swing.table.TableCellRenderer; |
| 11 | |
|
| 12 | |
import de.glossmaker.gloss.datastructure.EOperation; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
public class ImportGlossCellRenderer extends JLabel implements TableCellRenderer { |
| 20 | |
private static final long serialVersionUID = -6911049704043949016L; |
| 21 | |
|
| 22 | 0 | private Border mUnselectedBorder = null; |
| 23 | 0 | private Border mSelectedBorder = null; |
| 24 | 0 | private boolean mIsBordered = false; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | 0 | public ImportGlossCellRenderer(boolean isBordered) { |
| 29 | 0 | mIsBordered = isBordered; |
| 30 | 0 | setOpaque(true); |
| 31 | 0 | } |
| 32 | |
|
| 33 | |
@Override |
| 34 | |
public Component getTableCellRendererComponent(JTable table, Object color, |
| 35 | |
boolean isSelected, boolean hasFocus, int row, int column) { |
| 36 | 0 | Color backgroundColor = null; |
| 37 | 0 | Color textColor = null; |
| 38 | 0 | int modelRow = table.convertRowIndexToModel(row); |
| 39 | 0 | int modelCol = table.convertColumnIndexToModel(column); |
| 40 | 0 | ImportGlossTableModel model = (ImportGlossTableModel)table.getModel(); |
| 41 | |
|
| 42 | 0 | if (model.getOperation(modelRow) == EOperation.NOTHING) { |
| 43 | |
|
| 44 | 0 | backgroundColor = new Color(184, 184, 184); |
| 45 | |
|
| 46 | 0 | textColor = new Color(0, 0, 0); |
| 47 | |
} |
| 48 | |
|
| 49 | 0 | if (model.existsItem(modelRow)) { |
| 50 | 0 | if (model.getOperation(modelRow) == EOperation.IMPORT) { |
| 51 | |
|
| 52 | 0 | backgroundColor = new Color(255, 255, 255); |
| 53 | 0 | } else if (model.getOperation(modelRow) == EOperation.KEEP) { |
| 54 | |
|
| 55 | 0 | backgroundColor = new Color(191, 239, 255); |
| 56 | 0 | } else if (model.getOperation(modelRow) == EOperation.MERGE) { |
| 57 | |
|
| 58 | 0 | backgroundColor = new Color(255, 215, 0); |
| 59 | |
} else { |
| 60 | |
|
| 61 | 0 | backgroundColor = new Color(255, 0, 0); |
| 62 | |
} |
| 63 | |
|
| 64 | 0 | if (model.getOperation(modelRow) == EOperation.OVERRIDE) { |
| 65 | |
|
| 66 | 0 | textColor = new Color(255, 255, 255); |
| 67 | |
} else { |
| 68 | |
|
| 69 | 0 | textColor = new Color(0, 0, 0); |
| 70 | |
} |
| 71 | |
} |
| 72 | |
|
| 73 | 0 | this.setBackground(backgroundColor); |
| 74 | 0 | this.setForeground(textColor); |
| 75 | 0 | this.setText(model.getValueAt(modelRow, modelCol).toString()); |
| 76 | |
|
| 77 | 0 | if (mIsBordered) { |
| 78 | 0 | if (isSelected) { |
| 79 | 0 | if (mSelectedBorder == null) { |
| 80 | 0 | mSelectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getSelectionBackground()); |
| 81 | |
} |
| 82 | 0 | setBorder(mSelectedBorder); |
| 83 | |
} else { |
| 84 | 0 | if (mUnselectedBorder == null) { |
| 85 | 0 | mUnselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getBackground()); |
| 86 | |
} |
| 87 | 0 | setBorder(mUnselectedBorder); |
| 88 | |
} |
| 89 | |
} |
| 90 | |
|
| 91 | 0 | return this; |
| 92 | |
} |
| 93 | |
|
| 94 | |
} |