Java Code Examples for org.pushingpixels.substance.api.ComponentState#isFacetActive()

The following examples show how to use org.pushingpixels.substance.api.ComponentState#isFacetActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubstanceDefaultComboBoxRenderer.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private SubstanceColorScheme getColorSchemeForState(JList list, int index,
        SubstanceListUI listUI, ComponentState state) {
    boolean toUseHighlightKindForCurrState = (index >= 0)
            && (state.isFacetActive(ComponentStateFacet.ROLLOVER) || state
            .isFacetActive(ComponentStateFacet.SELECTION));
    UpdateOptimizationInfo updateOptimizationInfo = listUI
            .getUpdateOptimizationInfo();
    if (toUseHighlightKindForCurrState) {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities.getColorScheme(list,
                    ColorSchemeAssociationKind.HIGHLIGHT, state);
        } else {
            return updateOptimizationInfo.getHighlightColorScheme(state);
        }
    } else {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities
                    .getColorScheme(list, state);
        } else {
            return updateOptimizationInfo.getDefaultScheme();
        }
    }
}
 
Example 2
Source File: SubstanceCommandButtonUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Computes the alpha value for painting the separators.
 *
 * @return Alpha value for painting the separators.
 */
private float getSeparatorAlpha() {
    ComponentState actionAreaState = this.getActionTransitionTracker().getModelStateInfo()
            .getCurrModelState();

    if (!actionAreaState.isFacetActive(ComponentStateFacet.SELECTION)
            && !actionAreaState.isDisabled()) {
        float actionRolloverCycle = this.getActionTransitionTracker()
                .getFacetStrength(ComponentStateFacet.ROLLOVER);
        float popupRolloverCycle = this.getPopupTransitionTracker()
                .getFacetStrength(ComponentStateFacet.ROLLOVER);
        return Math.min(1.0f, actionRolloverCycle + popupRolloverCycle);
    }
    return 1.0f;
}
 
Example 3
Source File: SubstanceCommandButtonUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Color getMenuButtonForegroundColor(AbstractCommandButton menuButton,
        StateTransitionTracker.ModelStateInfo modelStateInfo) {
    ComponentState currState = modelStateInfo.getCurrModelStateNoSelection();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateNoSelectionContributionMap();

    SubstanceSlices.ColorSchemeAssociationKind currAssocKind = SubstanceSlices.ColorSchemeAssociationKind.FILL;
    // use HIGHLIGHT on active and non-rollover menu items
    if (!currState.isDisabled() && (currState != ComponentState.ENABLED)
            && !currState.isFacetActive(SubstanceSlices.ComponentStateFacet.ROLLOVER))
        currAssocKind = SubstanceSlices.ColorSchemeAssociationKind.HIGHLIGHT;
    SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.getColorScheme(menuButton,
            currAssocKind, currState);
    if (currState.isDisabled() || (activeStates == null) || (activeStates.size() == 1)) {
        return colorScheme.getForegroundColor();
    }

    float aggrRed = 0;
    float aggrGreen = 0;
    float aggrBlue = 0;
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        float alpha = activeEntry.getValue().getContribution();
        SubstanceSlices.ColorSchemeAssociationKind assocKind = SubstanceSlices.ColorSchemeAssociationKind.FILL;
        // use HIGHLIGHT on active and non-rollover menu items
        if (!activeState.isDisabled() && (activeState != ComponentState.ENABLED)
                && !activeState.isFacetActive(SubstanceSlices.ComponentStateFacet.ROLLOVER))
            assocKind = SubstanceSlices.ColorSchemeAssociationKind.HIGHLIGHT;
        SubstanceColorScheme activeColorScheme = SubstanceColorSchemeUtilities
                .getColorScheme(menuButton, assocKind, activeState);
        Color activeForeground = activeColorScheme.getForegroundColor();
        aggrRed += alpha * activeForeground.getRed();
        aggrGreen += alpha * activeForeground.getGreen();
        aggrBlue += alpha * activeForeground.getBlue();
    }
    return new Color((int) aggrRed, (int) aggrGreen, (int) aggrBlue);
}
 
Example 4
Source File: StateTransitionTracker.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public float getFacetStrength(ComponentStateFacet stateFacet) {
    float result = 0.0f;
    for (Map.Entry<ComponentState, StateContributionInfo> activeEntry :
            this.modelStateInfo.stateContributionMap
                    .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState.isFacetActive(stateFacet)) {
            result += activeEntry.getValue().getContribution();
        }
    }
    return result;
}
 
Example 5
Source File: HighlightableTransitionAwareIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private ResizableIcon getIconToPaint() {
    StateTransitionTracker stateTransitionTracker = this.transitionAwareUIDelegate
            .getTransitionAwareUI().getTransitionTracker();
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateNoSelectionContributionMap();
    ComponentState currState = modelStateInfo.getCurrModelStateNoSelection();

    // Use HIGHLIGHT when necessary and MARK for the rest
    ColorSchemeAssociationKind baseAssociationKind = currState
            .isFacetActive(this.facetForHighlights) ? ColorSchemeAssociationKind.HIGHLIGHT
                    : ColorSchemeAssociationKind.MARK;
    SubstanceColorScheme baseScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.component, baseAssociationKind, currState);
    float baseAlpha = SubstanceColorSchemeUtilities.getAlpha(this.component, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(this.component.getClass().getName(),
            this.uniqueIconTypeId, SubstanceSizeUtils.getComponentFontSize(this.component),
            baseScheme.getDisplayName(), baseAlpha);
    ResizableIcon layerBase = iconMap.get(keyBase);
    if (layerBase == null) {
        ResizableIcon baseFullOpacity = this.delegate.getColorSchemeIcon(baseScheme);
        if (baseAlpha == 1.0f) {
            layerBase = baseFullOpacity;
            iconMap.put(keyBase, layerBase);
        } else {
            BufferedImage baseImage = SubstanceCoreUtilities.getBlankImage(
                    baseFullOpacity.getIconWidth(), baseFullOpacity.getIconHeight());
            Graphics2D g2base = baseImage.createGraphics();
            g2base.setComposite(AlphaComposite.SrcOver.derive(baseAlpha));
            baseFullOpacity.paintIcon(this.component, g2base, 0, 0);
            g2base.dispose();
            layerBase = new ImageWrapperIcon(baseImage);
            iconMap.put(keyBase, layerBase);
        }
    }

    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return layerBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(layerBase.getIconWidth(),
            layerBase.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    layerBase.paintIcon(this.component, g2d, 0, 0);

    // draw the other active layers
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState == currState)
            continue;

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));

            // Use HIGHLIGHT when necessary and MARK for the rest
            ColorSchemeAssociationKind associationKind = activeState.isFacetActive(
                    this.facetForHighlights) ? ColorSchemeAssociationKind.HIGHLIGHT
                            : ColorSchemeAssociationKind.MARK;
            SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.component, associationKind, activeState);
            float alpha = SubstanceColorSchemeUtilities.getAlpha(this.component, activeState);

            HashMapKey key = SubstanceCoreUtilities.getHashKey(
                    this.component.getClass().getName(), this.uniqueIconTypeId,
                    SubstanceSizeUtils.getComponentFontSize(this.component),
                    scheme.getDisplayName(), alpha);
            ResizableIcon layer = iconMap.get(key);
            if (layer == null) {
                ResizableIcon fullOpacity = this.delegate.getColorSchemeIcon(scheme);
                if (alpha == 1.0f) {
                    layer = fullOpacity;
                    iconMap.put(key, layer);
                } else {
                    BufferedImage image = SubstanceCoreUtilities.getBlankImage(
                            fullOpacity.getIconWidth(), fullOpacity.getIconHeight());
                    Graphics2D g2layer = image.createGraphics();
                    g2layer.setComposite(AlphaComposite.SrcOver.derive(alpha));
                    fullOpacity.paintIcon(this.component, g2layer, 0, 0);
                    g2layer.dispose();
                    layer = new ImageWrapperIcon(image);
                    iconMap.put(key, layer);
                }
            }
            layer.paintIcon(this.component, g2d, 0, 0);
        }
    }
    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 6
Source File: CheckBoxMenuItemIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the current icon to paint.
 * 
 * @return Icon to paint.
 */
private ImageWrapperIcon getIconToPaint() {
    if (this.menuItem == null)
        return null;

    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) this.menuItem.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();

    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(this.menuItem);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
            .getBorderPainter(this.menuItem);
    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseFillColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK_BOX, currState);
    SubstanceColorScheme baseMarkColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK, currState);
    SubstanceColorScheme baseBorderColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER, currState);
    float visibility = stateTransitionTracker.getFacetStrength(ComponentStateFacet.SELECTION);
    boolean isCheckMarkFadingOut = !currState.isFacetActive(ComponentStateFacet.SELECTION);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(this.menuItem, currState);

    int fontSize = SubstanceSizeUtils.getComponentFontSize(this.menuItem);
    int checkMarkSize = this.size + 3;

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, isCheckMarkFadingOut,
            alpha);
    ImageWrapperIcon iconBase = iconMap.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(
                SubstanceImageCreator.getCheckBox(this.menuItem, fillPainter, borderPainter,
                        checkMarkSize, currState, baseFillColorScheme, baseMarkColorScheme,
                        baseBorderColorScheme, visibility, isCheckMarkFadingOut, alpha));
        iconMap.put(keyBase, iconBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return iconBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iconBase.getIconWidth(),
            iconBase.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    iconBase.paintIcon(this.menuItem, g2d, 0, 0);

    // draw 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;

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));
            SubstanceColorScheme fillColorScheme = SubstanceColorSchemeUtilities.getColorScheme(
                    this.menuItem, ColorSchemeAssociationKind.MARK_BOX, activeState);
            SubstanceColorScheme markColorScheme = SubstanceColorSchemeUtilities.getColorScheme(
                    this.menuItem, ColorSchemeAssociationKind.MARK, activeState);
            SubstanceColorScheme borderColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER,
                            activeState);

            HashMapKey keyLayer = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
                    fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    fillColorScheme.getDisplayName(), markColorScheme.getDisplayName(),
                    borderColorScheme.getDisplayName(), visibility, alpha);
            ImageWrapperIcon iconLayer = iconMap.get(keyLayer);
            if (iconLayer == null) {
                iconLayer = new ImageWrapperIcon(SubstanceImageCreator.getCheckBox(
                        this.menuItem, fillPainter, borderPainter, checkMarkSize, currState,
                        fillColorScheme, markColorScheme, borderColorScheme, visibility,
                        isCheckMarkFadingOut, alpha));
                iconMap.put(keyLayer, iconLayer);
            }

            iconLayer.paintIcon(this.menuItem, g2d, 0, 0);
        }
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 7
Source File: SubstanceCheckBoxUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the icon that matches the current and previous states of the checkbox.
 *
 * @param button                 Button (should be {@link JCheckBox}).
 * @param stateTransitionTracker State transition tracker for the checkbox.
 * @return Matching icon.
 */
private static Icon getIcon(JToggleButton button,
        StateTransitionTracker stateTransitionTracker) {
    StateTransitionTracker.ModelStateInfo modelStateInfo =
            stateTransitionTracker.getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates =
            modelStateInfo.getStateContributionMap();

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(button);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(button);
    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseFillColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(button, ColorSchemeAssociationKind.MARK_BOX, currState);
    SubstanceColorScheme baseMarkColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(button, ColorSchemeAssociationKind.MARK, currState);
    SubstanceColorScheme baseBorderColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(button, ColorSchemeAssociationKind.BORDER, currState);
    float visibility = stateTransitionTracker.getFacetStrength(ComponentStateFacet.SELECTION);
    boolean isCheckMarkFadingOut = !currState.isFacetActive(ComponentStateFacet.SELECTION);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(button, currState);

    int fontSize = SubstanceSizeUtils.getComponentFontSize(button);
    int checkMarkSize = SubstanceSizeUtils.getCheckBoxMarkSize(fontSize);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, isCheckMarkFadingOut,
            alpha);
    ImageWrapperIcon iconBase = icons.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(
                SubstanceImageCreator.getCheckBox(button, fillPainter, borderPainter,
                        checkMarkSize, currState, baseFillColorScheme, baseMarkColorScheme,
                        baseBorderColorScheme, visibility, isCheckMarkFadingOut,
                        alpha));
        icons.put(keyBase, iconBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return iconBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iconBase.getIconWidth(),
            iconBase.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    iconBase.paintIcon(button, g2d, 0, 0);

    // draw 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;
        }

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));
            SubstanceColorScheme fillColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(button, ColorSchemeAssociationKind.MARK_BOX, activeState);
            SubstanceColorScheme markColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(button, ColorSchemeAssociationKind.MARK, activeState);
            SubstanceColorScheme borderColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(button, ColorSchemeAssociationKind.BORDER, activeState);

            HashMapKey keyLayer = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
                    fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    fillColorScheme.getDisplayName(), markColorScheme.getDisplayName(),
                    borderColorScheme.getDisplayName(), visibility);
            ImageWrapperIcon iconLayer = icons.get(keyLayer);
            if (iconLayer == null) {
                iconLayer = new ImageWrapperIcon(
                        SubstanceImageCreator.getCheckBox(button, fillPainter, borderPainter,
                                checkMarkSize, currState, fillColorScheme, markColorScheme,
                                borderColorScheme, visibility, isCheckMarkFadingOut, alpha));
                icons.put(keyLayer, iconLayer);
            }

            iconLayer.paintIcon(button, g2d, 0, 0);
        }
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}