| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.dishevelled.identify; |
| 25 | |
|
| 26 | |
import java.awt.Image; |
| 27 | |
import java.awt.Component; |
| 28 | |
|
| 29 | |
import javax.swing.JTable; |
| 30 | |
import javax.swing.JLabel; |
| 31 | |
import javax.swing.ImageIcon; |
| 32 | |
|
| 33 | |
import javax.swing.table.DefaultTableCellRenderer; |
| 34 | |
|
| 35 | |
import org.dishevelled.iconbundle.IconSize; |
| 36 | |
import org.dishevelled.iconbundle.IconState; |
| 37 | |
import org.dishevelled.iconbundle.IconBundle; |
| 38 | |
import org.dishevelled.iconbundle.IconTextDirection; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class IdTableCellRenderer |
| 47 | |
extends StripeTableCellRenderer |
| 48 | |
{ |
| 49 | |
|
| 50 | 2 | public static final IconSize DEFAULT_ICON_SIZE = IconSize.DEFAULT_16X16; |
| 51 | |
|
| 52 | |
|
| 53 | |
private IconSize iconSize; |
| 54 | |
|
| 55 | |
|
| 56 | |
private transient ImageIcon imageIcon; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public IdTableCellRenderer() |
| 66 | |
{ |
| 67 | 6 | this(DEFAULT_ICON_SIZE); |
| 68 | 6 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public IdTableCellRenderer(final IconSize iconSize) |
| 77 | |
{ |
| 78 | 12 | super(); |
| 79 | 12 | setIconSize(iconSize); |
| 80 | 10 | } |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public final IconSize getIconSize() |
| 89 | |
{ |
| 90 | 8 | return iconSize; |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public final void setIconSize(final IconSize iconSize) |
| 99 | |
{ |
| 100 | 16 | if (iconSize == null) |
| 101 | |
{ |
| 102 | 2 | throw new IllegalArgumentException("iconSize must not be null"); |
| 103 | |
} |
| 104 | 14 | this.iconSize = iconSize; |
| 105 | 14 | } |
| 106 | |
|
| 107 | |
@Override |
| 108 | |
public Component getTableCellRendererComponent(final JTable table, |
| 109 | |
final Object value, |
| 110 | |
final boolean isSelected, |
| 111 | |
final boolean hasFocus, |
| 112 | |
final int row, |
| 113 | |
final int column) |
| 114 | |
{ |
| 115 | 40 | JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
| 116 | |
|
| 117 | 40 | String name = IdentifyUtils.getNameFor(value); |
| 118 | 40 | label.setText(name); |
| 119 | |
|
| 120 | 40 | IconBundle iconBundle = IdentifyUtils.getIconBundleFor(value); |
| 121 | |
|
| 122 | 40 | if (iconBundle == null) |
| 123 | |
{ |
| 124 | 16 | label.setIcon(null); |
| 125 | |
} |
| 126 | |
else |
| 127 | |
{ |
| 128 | 24 | IconTextDirection textDirection = IdentifyUtils.determineTextDirection(label); |
| 129 | 24 | Image image = iconBundle.getImage(label, textDirection, IconState.NORMAL, iconSize); |
| 130 | |
|
| 131 | 24 | if (imageIcon == null) |
| 132 | |
{ |
| 133 | 2 | imageIcon = new ImageIcon(image); |
| 134 | |
} |
| 135 | |
else |
| 136 | |
{ |
| 137 | 22 | imageIcon.setImage(image); |
| 138 | |
} |
| 139 | |
|
| 140 | 24 | label.setIcon(imageIcon); |
| 141 | |
} |
| 142 | |
|
| 143 | 40 | return label; |
| 144 | |
} |
| 145 | |
} |