TransitionAwareUI transitionAwareUI = (TransitionAwareUI) button
.getUI();
StateTransitionTracker.ModelStateInfo modelStateInfo = transitionAwareUI
.getTransitionTracker().getModelStateInfo();
ComponentState currState = modelStateInfo.getCurrModelState();
// ComponentState prevState = stateTransitionModel.getPrevModelState();
// System.out.println(button.getText() + ": " + prevState.name() +
// " -> "
// + state.name() + " at "
// + stateTransitionModel.getTransitionPosition());
// compute cycle count (for animation)
float cyclePos = 0.0f;// currState.getCyclePosition();
// boolean isPulsating = false;
if (button instanceof JButton) {
JButton jb = (JButton) button;
if (RootPaneDefaultButtonTracker.isPulsating(jb)
&& (currState != ComponentState.PRESSED_SELECTED)
&& (currState != ComponentState.PRESSED_UNSELECTED)) {
// isPulsating = true;
cyclePos = RootPaneDefaultButtonTracker.getTimelinePosition(jb);
}
}
// compute the straight sides
Set<SubstanceConstants.Side> straightSides = SubstanceCoreUtilities
.getSides(button, SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY);
boolean isRoundButton = StandardButtonShaper.isRoundButton(button);
float radius = 0.0f;
if (shaper instanceof RectangularButtonShaper) {
radius = ((RectangularButtonShaper) shaper).getCornerRadius(button,
null);
}
Set<Side> openSides = SubstanceCoreUtilities.getSides(button,
SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY);
// String openKey = "";
// for (Side oSide : openSides) {
// openKey += oSide.name() + "-";
// }
// String extraModelKey = "";
// for (String modelKey : extraModelKeys) {
// extraModelKey += (modelKey + "-");
// }
boolean isContentAreaFilled = button.isContentAreaFilled();
boolean isBorderPainted = button.isBorderPainted();
// compute color scheme
SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities
.getColorScheme(button, ColorSchemeAssociationKind.BORDER,
currState);
// see if need to use attention-drawing animation
// boolean isWindowModified = false;
if (button.getUI() instanceof ModificationAwareUI) {
ModificationAwareUI modificationAwareUI = (ModificationAwareUI) button
.getUI();
Timeline modificationTimeline = modificationAwareUI
.getModificationTimeline();
if (modificationTimeline != null) {
if (modificationTimeline.getState() != TimelineState.IDLE) {
// isWindowModified = true;
SubstanceColorScheme colorScheme2 = SubstanceColorSchemeUtilities.YELLOW;
SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.ORANGE;
cyclePos = modificationTimeline.getTimelinePosition();
HashMapKey key1 = SubstanceCoreUtilities.getHashKey(width,
height, colorScheme.getDisplayName(),
baseBorderScheme.getDisplayName(), shaper
.getDisplayName(), fillPainter
.getDisplayName(), borderPainter
.getDisplayName(), straightSides,
openSides, button.getClass().getName(),
isRoundButton, radius, isContentAreaFilled,
isBorderPainted, SubstanceSizeUtils
.getComponentFontSize(button));
BufferedImage layer1 = regularBackgrounds.get(key1);
if (layer1 == null) {
layer1 = createBackgroundImage(button, shaper,
fillPainter, borderPainter, width, height,
colorScheme, baseBorderScheme, openSides,
isContentAreaFilled, isBorderPainted);
regularBackgrounds.put(key1, layer1);
}
HashMapKey key2 = SubstanceCoreUtilities.getHashKey(width,
height, colorScheme2.getDisplayName(),
baseBorderScheme.getDisplayName(), shaper
.getDisplayName(), fillPainter
.getDisplayName(), borderPainter
.getDisplayName(), straightSides,
openSides, button.getClass().getName(),
isRoundButton, radius, isContentAreaFilled,
isBorderPainted, SubstanceSizeUtils
.getComponentFontSize(button));
BufferedImage layer2 = regularBackgrounds.get(key2);
if (layer2 == null) {
layer2 = createBackgroundImage(button, shaper,
fillPainter, borderPainter, width, height,
colorScheme2, baseBorderScheme, openSides,
isContentAreaFilled, isBorderPainted);
regularBackgrounds.put(key2, layer2);
}
BufferedImage result = SubstanceCoreUtilities
.getBlankImage(width, height);
Graphics2D g2d = result.createGraphics();
if (cyclePos < 1.0f)
g2d.drawImage(layer1, 0, 0, null);
if (cyclePos > 0.0f) {
g2d.setComposite(AlphaComposite.SrcOver
.derive(cyclePos));
g2d.drawImage(layer2, 0, 0, null);
}
g2d.dispose();
return result;
}
}
}
// see if need to use transition animation. Important - don't do it
// on pulsating buttons (such as default or close buttons
// of modified frames).
Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
.getStateContributionMap();
SubstanceColorScheme baseFillScheme = SubstanceColorSchemeUtilities
.getColorScheme(button, currState);
HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(width, height,
baseFillScheme.getDisplayName(), baseBorderScheme
.getDisplayName(), shaper.getDisplayName(), fillPainter
.getDisplayName(), borderPainter.getDisplayName(),
straightSides, openSides, button.getClass().getName(),
isRoundButton, (int) (1000 * radius), isContentAreaFilled,
isBorderPainted, SubstanceSizeUtils
.getComponentFontSize(button));
BufferedImage layerBase = regularBackgrounds.get(keyBase);
if (layerBase == null) {
layerBase = createBackgroundImage(button, shaper, fillPainter,
borderPainter, width, height, baseFillScheme,
baseBorderScheme, openSides, isContentAreaFilled,
isBorderPainted);
regularBackgrounds.put(keyBase, layerBase);
}
if (currState.isDisabled() || (activeStates.size() == 1)) {
return layerBase;
}
BufferedImage result = SubstanceCoreUtilities.getBlankImage(width,
height);
Graphics2D g2d = result.createGraphics();
// draw the base layer
g2d.drawImage(layerBase, 0, 0, null);
// System.out.println("\nPainting base state " + currState);
// draw the other active layers
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
ComponentState activeState = activeEntry.getKey();
// System.out.println("Painting state " + activeState + "[curr is "
// + currState + "] with " + activeEntry.getValue());
if (activeState == currState)
continue;