21 package net.squiz.matrix.inspector;
23 import net.squiz.matrix.core.*;
24 import net.squiz.matrix.matrixtree.*;
26 import javax.swing.JTable;
27 import javax.swing.JLabel;
28 import javax.swing.SwingConstants;
29 import javax.swing.table.TableCellRenderer;
30 import javax.swing.tree.*;
31 import javax.swing.border.LineBorder;
34 import java.awt.Component;
46 implements TableCellRenderer,
52 private boolean selected =
false;
54 private boolean allSelected =
false;
82 MatrixTreeNode node = (MatrixTreeNode) value;
85 this.selected = isSelected;
87 String name = node.getName();
89 if (name.length() > len) {
90 name = name.substring(0, len - 3) +
"...";
92 String numAssetsStr = null;
93 int numKids = node.
getAsset().getNumKids();
95 numAssetsStr =
"unknown";
96 }
else if (numKids == 1) {
97 numAssetsStr = numKids +
" asset";
99 numAssetsStr = numKids +
" assets";
102 setText(
"<html><center>" + name +
"<br><font color=\"#AAAAAA\">" + numAssetsStr +
"</font></center></html>");
103 String toolTip =
new String(
"<html>" +
104 node.getName() +
"<br>" +
105 asset.getType().getName() +
" [" + asset.getId() +
"]" +
107 setToolTipText(toolTip);
108 setFont(PLAIN_FONT_10);
109 setDisabledIcon(null);
111 if (asset.getType() != null) {
112 setIcon(asset.getType().getIcon());
114 setVerticalTextPosition(JLabel.BOTTOM);
115 setHorizontalTextPosition(JLabel.CENTER);
116 setHorizontalAlignment(JLabel.CENTER);
118 }
else if (value instanceof DefaultMutableTreeNode) {
119 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
120 if (node.getUserObject() instanceof String) {
121 setText((String) node.getUserObject());
136 int iconSquareOffset = (int) ( getSize().getWidth() - getIcon().getIconWidth() ) / 2;
137 int iconSquareWidth = getIcon().getIconWidth() + 10;
138 int iconSquareHeight = getIcon().getIconHeight() + 10;
140 if (selected || allSelected) {
141 FontMetrics fm = getFontMetrics(getFont());
143 int textWidth = fm.stringWidth(getText());
144 textWidth = textWidth > getWidth() ? getWidth() : textWidth;
145 textWidth = textWidth - 1 < iconSquareWidth ? iconSquareWidth + 1 : textWidth;
146 textWidth = textWidth % 2 != 0 ? textWidth++ : textWidth;
148 int offset = ((getWidth() - textWidth) / 2) + 1;
150 int textOffset = getIcon().getIconHeight() + getIconTextGap() + 3;
151 int height = fm.getHeight() - 2;
162 g.setColor(asset.getStatusColour());
163 g.fillRect(0, textOffset, getWidth() - 1, height);
164 g.setColor(asset.getStatusColour().darker());
165 g.drawRect(0, textOffset, getWidth() - 1, height);
203 allSelected = (allSelected) ?
false :
true;