this.hasFocus = hasFocus;
this.setText(stringValue);
TreeUI treeUI = tree.getUI();
if (treeUI instanceof SubstanceTreeUI) {
SubstanceTreeUI ui = (SubstanceTreeUI) treeUI;
TreePathId pathId = new TreePathId(tree.getPathForRow(row));
StateTransitionTracker.ModelStateInfo modelStateInfo = ui
.getModelStateInfo(pathId);
ComponentState currState = ui.getPathState(pathId);
// special case for drop location
JTree.DropLocation dropLocation = tree.getDropLocation();
boolean isDropLocation = (dropLocation != null
&& dropLocation.getChildIndex() == -1 && tree
.getRowForPath(dropLocation.getPath()) == row);
if (!isDropLocation && (modelStateInfo != null)) {
Map<ComponentState, StateContributionInfo> activeStates = modelStateInfo
.getStateContributionMap();
SubstanceColorScheme colorScheme = getColorSchemeForState(tree,
ui, currState);
if (currState.isDisabled() || (activeStates == null)
|| (activeStates.size() == 1)) {
super.setForeground(new ColorUIResource(colorScheme
.getForegroundColor()));
} else {
float aggrRed = 0;
float aggrGreen = 0;
float aggrBlue = 0;
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : modelStateInfo
.getStateContributionMap().entrySet()) {
ComponentState activeState = activeEntry.getKey();
SubstanceColorScheme scheme = getColorSchemeForState(
tree, ui, activeState);
Color schemeFg = scheme.getForegroundColor();
float contribution = activeEntry.getValue()
.getContribution();
aggrRed += schemeFg.getRed() * contribution;
aggrGreen += schemeFg.getGreen() * contribution;
aggrBlue += schemeFg.getBlue() * contribution;
}
super.setForeground(new ColorUIResource(new Color(
(int) aggrRed, (int) aggrGreen, (int) aggrBlue)));
}
} else {
SubstanceColorScheme scheme = getColorSchemeForState(tree, ui,
currState);
if (isDropLocation) {
scheme = SubstanceColorSchemeUtilities.getColorScheme(tree,
ColorSchemeAssociationKind.TEXT_HIGHLIGHT,
currState);
}
super.setForeground(new ColorUIResource(scheme
.getForegroundColor()));
}
} else {
if (sel)
this.setForeground(UIManager
.getColor("Tree.selectionForeground"));
else
this.setForeground(UIManager.getColor("Tree.textForeground"));
}
if (SubstanceLookAndFeel.isCurrentLookAndFeel())
SubstanceStripingUtils.applyStripedBackground(tree, row, this);
// There needs to be a way to specify disabled icons.
if (!tree.isEnabled()) {
this.setEnabled(false);
if (leaf) {
this.setDisabledIcon(SubstanceImageCreator
.toGreyscale(SubstanceImageCreator.makeTransparent(
tree, this.getDefaultLeafIcon(), 0.5)));
} else if (expanded) {
this.setDisabledIcon(SubstanceImageCreator
.toGreyscale(SubstanceImageCreator.makeTransparent(
tree, this.getDefaultOpenIcon(), 0.5)));
// setIcon(SubstanceImageCreator.toGreyscale(
// SubstanceImageCreator
// .makeTransparent(getDefaultOpenIcon(), 0.5)));
} else {
this.setDisabledIcon(SubstanceImageCreator
.toGreyscale(SubstanceImageCreator.makeTransparent(
tree, this.getDefaultClosedIcon(), 0.5)));
// setIcon(SubstanceImageCreator.toGreyscale(
// SubstanceImageCreator
// .makeTransparent(getDefaultClosedIcon(), 0.5)));
}
} else {
this.setEnabled(true);
if (leaf) {
this.setIcon(this.getDefaultLeafIcon());
} else if (expanded) {
this.setIcon(this.getDefaultOpenIcon());
} else {
this.setIcon(this.getDefaultClosedIcon());
}
}
this.setComponentOrientation(tree.getComponentOrientation());
this.setOpaque(false);
this.selected = sel;
if (treeUI instanceof SubstanceTreeUI) {
SubstanceTreeUI ui = (SubstanceTreeUI) treeUI;
Insets regInsets = ui.getCellRendererInsets();
this
.setBorder(new BorderUIResource.EmptyBorderUIResource(
regInsets));
}