// start fading in
if (!enforceNoAnimations) {
// System.out
// .println("Getting selection/in tracker for "
// + cellId);
StateTransitionTracker tracker = getTracker(
cellId,
getCellState(cellId).isFacetActive(
ComponentStateFacet.ROLLOVER),
false);
tracker.getModel().setSelected(true);
// System.out
// .println("Selecting previously unselected "
// + i + ":" + j);
initiatedTrackers.add(tracker);
if (initiatedTrackers.size() > 20) {
stateTransitionMultiTracker.clear();
initiatedTrackers.clear();
enforceNoAnimations = true;
}
}
this.selectedIndices.put(cellId,
this.table.getValueAt(i, j));
}
} else {
// check if was selected before and still points
// to the same element
if (this.selectedIndices.containsKey(cellId)) {
// corner case when the model returns null
Object oldValue = this.selectedIndices.get(cellId);
if ((i >= this.table.getModel().getRowCount())
|| (j >= this.table.getModel().getColumnCount())) {
// not only the content changed, but the model
// dimensions as well
continue;
}
Object currValue = this.table.getValueAt(i, j);
boolean isSame = false;
if (oldValue == null) {
isSame = (currValue == null);
} else {
isSame = oldValue.equals(currValue);
}
if (isSame) {
// start fading out
if (!enforceNoAnimations) {
// System.out
// .println("Getting selection/out tracker for "
// + cellId);
StateTransitionTracker tracker = getTracker(
cellId,
getCellState(cellId).isFacetActive(
ComponentStateFacet.ROLLOVER),
true);
tracker.getModel().setSelected(false);
// System.out
// .println("Unselecting previously selected "
// + i + ":" + j);
initiatedTrackers.add(tracker);
if (initiatedTrackers.size() > 20) {
stateTransitionMultiTracker.clear();
initiatedTrackers.clear();
enforceNoAnimations = true;
}
}
}
this.selectedIndices.remove(cellId);
}
}
// handle focus animations
boolean cellHasFocus = isFocusOwner && (i == rowLeadIndex)
&& (j == colLeadIndex);
if (cellHasFocus) {
// check if it's a different cell
if ((this.focusedCellId == null)
|| !this.focusedCellId.equals(cellId)) {
if (!enforceNoAnimations) {
if (this.focusedCellId != null) {
// fade out the previous focus holder
ComponentState cellState = getCellState(this.focusedCellId);
// System.out.println("Getting focus/out tracker for "
// + cellId);
StateTransitionTracker tracker = getTracker(
this.focusedCellId,
cellState
.isFacetActive(ComponentStateFacet.ROLLOVER),
cellState
.isFacetActive(ComponentStateFacet.SELECTION));
tracker.setFocusState(false);
}
// fade in the current cell (new focus holder)
ComponentState cellState = getCellState(cellId);
// System.out.println("Getting focus/in tracker for "
// + currId);
StateTransitionTracker tracker = getTracker(
cellId,
cellState
.isFacetActive(ComponentStateFacet.ROLLOVER),
cellState
.isFacetActive(ComponentStateFacet.SELECTION));
tracker.setFocusState(true);
}
if (AnimationConfigurationManager.getInstance()
.isAnimationAllowed(AnimationFacet.FOCUS,
this.table)) {
// and store it for future checks
this.focusedCellId = new TableCellId(i, j);
}
}
} else {
// check if previously it held focus
if (cellId.equals(this.focusedCellId)) {
if (!enforceNoAnimations) {
// fade it out
ComponentState cellState = getCellState(cellId);
// System.out.println("Getting focus/out tracker for "
// + cellId);
StateTransitionTracker tracker = getTracker(
cellId,
cellState
.isFacetActive(ComponentStateFacet.ROLLOVER),
cellState
.isFacetActive(ComponentStateFacet.SELECTION));
tracker.setFocusState(false);
}
this.focusedCellId = null;
}
}