Java Code Examples for org.pushingpixels.substance.internal.animation.StateTransitionTracker#StateContributionInfo

The following examples show how to use org.pushingpixels.substance.internal.animation.StateTransitionTracker#StateContributionInfo . 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: RibbonTaskToggleButtonBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Updates background of the specified button.
 *
 * @param g      Graphic context.
 * @param button Button to update.
 */
public void updateTaskToggleButtonBackground(Graphics g, JRibbonTaskToggleButton button) {
    Graphics2D g2d = (Graphics2D) g.create();

    int width = button.getWidth();
    int height = button.getHeight();

    BufferedImage ribbonBackground = getTaskToggleButtonBackground(button, width, height);

    TransitionAwareUI ui = (TransitionAwareUI) button.getUI();
    StateTransitionTracker stateTransitionTracker = ui.getTransitionTracker();

    float extraActionAlpha = 0.0f;
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry
            : stateTransitionTracker.getModelStateInfo().getStateContributionMap().entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState.isDisabled()) {
            continue;
        }
        if (activeState == ComponentState.ENABLED) {
            continue;
        }
        extraActionAlpha += activeEntry.getValue().getContribution();
    }

    g2d.setComposite(WidgetUtilities.getAlphaComposite(button, extraActionAlpha, g));
    NeonCortex.drawImage(g2d, ribbonBackground, 0, 0);

    g2d.dispose();
}
 
Example 2
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 3
Source File: SubstanceColorUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the foreground text color of the specified menu component.
 *
 * @param menuComponent  Menu component.
 * @param modelStateInfo Model state info for the component.
 * @return The foreground text color of the specified menu component.
 */
public static Color getMenuComponentForegroundColor(JMenuItem menuComponent,
        StateTransitionTracker.ModelStateInfo modelStateInfo) {
    ComponentState currState = modelStateInfo.getCurrModelStateNoSelection();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates =
            modelStateInfo.getStateNoSelectionContributionMap();

    ColorSchemeAssociationKind currAssocKind = ColorSchemeAssociationKind.FILL;
    // use HIGHLIGHT on active menu items
    if (!currState.isDisabled() && (currState != ComponentState.ENABLED))
        currAssocKind = ColorSchemeAssociationKind.HIGHLIGHT;
    SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(menuComponent, 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();
        ColorSchemeAssociationKind assocKind = ColorSchemeAssociationKind.FILL;
        // use HIGHLIGHT on active menu items
        if (!activeState.isDisabled()
                && (activeState != ComponentState.ENABLED))
            assocKind = ColorSchemeAssociationKind.HIGHLIGHT;
        SubstanceColorScheme activeColorScheme = SubstanceColorSchemeUtilities
                .getColorScheme(menuComponent, 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: SubstanceScrollBarUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Retrieves image for vertical thumb.
 * 
 * @param thumbBounds
 *            Thumb bounding rectangle.
 * @return Image for vertical thumb.
 */
private BufferedImage getThumbVertical(Rectangle thumbBounds) {
    int width = Math.max(1, thumbBounds.width);
    int delta = Math.max(0, (int) (0.4 * width));
    if (delta % 2 == 1) {
        delta--;
    }
    width -= delta;

    int height = Math.max(1, thumbBounds.height);

    StateTransitionTracker.ModelStateInfo modelStateInfo = this.compositeStateTransitionTracker
            .getModelStateInfo();
    ComponentState currState = modelStateInfo.getCurrModelState();

    // enabled scroll bar is always painted as active
    SubstanceColorScheme baseFillScheme = (currState != ComponentState.ENABLED)
            ? SubstanceColorSchemeUtilities.getColorScheme(this.scrollbar, currState)
            : SubstanceColorSchemeUtilities.getActiveColorScheme(this.scrollbar, currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, currState);
    BufferedImage baseLayer = getThumbVertical(this.scrollbar, width, height, baseFillScheme,
            baseBorderScheme);

    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return baseLayer;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(baseLayer);
    Graphics2D g2d = result.createGraphics();
    g2d.drawImage(baseLayer, 0, 0, baseLayer.getWidth(), baseLayer.getHeight(), null);

    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState == modelStateInfo.getCurrModelState())
            continue;

        float contribution = activeEntry.getValue().getContribution();
        if (contribution == 0.0f)
            continue;

        g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));

        SubstanceColorScheme fillScheme = (activeState != ComponentState.ENABLED)
                ? SubstanceColorSchemeUtilities.getColorScheme(this.scrollbar, activeState)
                : SubstanceColorSchemeUtilities.getActiveColorScheme(this.scrollbar,
                        activeState);
        SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                .getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, activeState);
        BufferedImage layer = getThumbVertical(this.scrollbar, width, height, fillScheme,
                borderScheme);
        g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
    }

    g2d.dispose();
    return result;
}
 
Example 5
Source File: SubstanceRibbonTaskToggleButtonUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static Color getForegroundColor(AbstractCommandButton button,
            StateTransitionTracker.ModelStateInfo modelStateInfo) {
        ComponentState currStateIgnoreSelection =
                ComponentState.getState(button.getActionModel(), button, true);
        ComponentState currState = ComponentState.getState(button.getActionModel(), button, false);
        Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates =
                modelStateInfo.getStateNoSelectionContributionMap();

        SubstanceColorScheme buttonFillScheme = SubstanceColorSchemeUtilities.getColorScheme(
                button, ColorSchemeAssociationKind.FILL, currStateIgnoreSelection);
        SubstanceSkin skin = SubstanceCoreUtilities.getSkin(button);
        SubstanceSlices.DecorationAreaType parentDecorationAreaType =
                SubstanceCortex.ComponentOrParentChainScope.getDecorationType(button.getParent());
        SubstanceColorScheme parentFillScheme = skin.getBackgroundColorScheme(parentDecorationAreaType);

        if (currState.isDisabled() || (activeStates == null) || (activeStates.size() == 1)) {
            SubstanceColorScheme schemeForCurrState = (currState == ComponentState.ENABLED)
                    ? parentFillScheme : buttonFillScheme;
//            System.out.println("For " + button.getText() + " state is " + currState +
//                    " and scheme is " + schemeForCurrState.getDisplayName() +
//                    " -> " + schemeForCurrState.getForegroundColor());
            return schemeForCurrState.getForegroundColor();
        }

        float aggrRed = 0;
        float aggrGreen = 0;
        float aggrBlue = 0;
//        System.out.println(
//                "For " + button.getText() + " in " + currState + ":" + currStateIgnoreSelection);
        for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry :
                activeStates.entrySet()) {
            ComponentState activeState = activeEntry.getKey();
            float alpha = activeEntry.getValue().getContribution();

            boolean correspondsToParentFill = (activeState == ComponentState.ENABLED) &&
                    !button.getActionModel().isSelected();
            SubstanceColorScheme activeColorScheme =
                    SubstanceColorSchemeUtilities.getColorScheme(button,
                            ColorSchemeAssociationKind.FILL, activeState);
            //System.out.println("\t" + activeState + " : " + currState);
            Color activeForeground = correspondsToParentFill
                    ? parentFillScheme.getForegroundColor()
                    : activeColorScheme.getForegroundColor();

//            System.out.println("\t" + activeState + " at alpha " + alpha + " from " +
//                    (correspondsToParentFill ? parentFillScheme :
//                            activeColorScheme).getDisplayName()
//                    + "[" + correspondsToParentFill + "] contributes color " +
//                    activeForeground);
            aggrRed += alpha * activeForeground.getRed();
            aggrGreen += alpha * activeForeground.getGreen();
            aggrBlue += alpha * activeForeground.getBlue();
        }
        return new Color((int) aggrRed, (int) aggrGreen, (int) aggrBlue);
    }
 
Example 6
Source File: SubstanceSliderUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paintTrack(Graphics g) {
    Graphics2D graphics = (Graphics2D) g.create();

    boolean drawInverted = this.drawInverted();

    Rectangle paintRect = this.getPaintTrackRect();

    // Width and height of the painting rectangle.
    int width = paintRect.width;
    int height = paintRect.height;

    if (this.slider.getOrientation() == JSlider.VERTICAL) {
        // apply rotation / translate transformation on vertical
        // slider tracks
        int temp = width;
        width = height;
        height = temp;
        AffineTransform at = graphics.getTransform();
        at.translate(paintRect.x, width + paintRect.y);
        at.rotate(-Math.PI / 2);
        graphics.setTransform(at);
    } else {
        graphics.translate(paintRect.x, paintRect.y);
    }

    StateTransitionTracker.ModelStateInfo modelStateInfo = this.stateTransitionTracker
            .getModelStateInfo();

    SubstanceColorScheme trackSchemeUnselected = SubstanceColorSchemeUtilities
            .getColorScheme(this.slider, this.slider.isEnabled() ? ComponentState.ENABLED
                    : ComponentState.DISABLED_UNSELECTED);
    SubstanceColorScheme trackBorderSchemeUnselected = SubstanceColorSchemeUtilities
            .getColorScheme(this.slider, ColorSchemeAssociationKind.BORDER,
                    this.slider.isEnabled() ? ComponentState.ENABLED
                            : ComponentState.DISABLED_UNSELECTED);
    this.paintSliderTrack(graphics, drawInverted, trackSchemeUnselected,
            trackBorderSchemeUnselected, width, height);

    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (!activeState.isActive())
            continue;

        float contribution = activeEntry.getValue().getContribution();
        if (contribution == 0.0f)
            continue;

        graphics.setComposite(
                WidgetUtilities.getAlphaComposite(this.slider, contribution, g));

        SubstanceColorScheme activeFillScheme = SubstanceColorSchemeUtilities
                .getColorScheme(this.slider, activeState);
        SubstanceColorScheme activeBorderScheme = SubstanceColorSchemeUtilities
                .getColorScheme(this.slider, ColorSchemeAssociationKind.BORDER, activeState);
        this.paintSliderTrackSelected(graphics, drawInverted, paintRect, activeFillScheme,
                activeBorderScheme, width, height);
    }

    graphics.dispose();
}
 
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);
}
 
Example 8
Source File: SubstanceRadioButtonUI.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 radio button.
 * 
 * @param button
 *            Button (should be {@link JRadioButton}).
 * @param stateTransitionTracker
 *            State transition tracker for the radio button.
 * @return Matching icon.
 */
private static ImageWrapperIcon getIcon(JToggleButton button,
        StateTransitionTracker stateTransitionTracker) {
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

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

    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);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(button, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, alpha);
    ImageWrapperIcon iconBase = icons.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(SubstanceImageCreator.getRadioButton(button, fillPainter,
                borderPainter, checkMarkSize, currState, 0, baseFillColorScheme,
                baseMarkColorScheme, baseBorderColorScheme, visibility, 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, alpha);
            ImageWrapperIcon iconLayer = icons.get(keyLayer);
            if (iconLayer == null) {
                iconLayer = new ImageWrapperIcon(
                        SubstanceImageCreator.getRadioButton(button, fillPainter, borderPainter,
                                checkMarkSize, currState, 0, fillColorScheme, markColorScheme,
                                borderColorScheme, visibility, alpha));
                icons.put(keyLayer, iconLayer);
            }

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

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 9
Source File: SubstanceColorUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the foreground text color of the specified component.
 *
 * @param component      Component.
 * @param modelStateInfo Component model state info.
 * @return The foreground text color of the specified component.
 */
public static Color getForegroundColor(Component component,
        StateTransitionTracker.ModelStateInfo modelStateInfo) {
    ComponentState currState = modelStateInfo.getCurrModelState();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates =
            modelStateInfo.getStateContributionMap();

    // special case for enabled buttons with no background -
    // always use the color scheme for the default state.
    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        if (SubstanceCoreUtilities.isButtonNeverPainted(button)
                || !button.isContentAreaFilled()
                || (button instanceof JRadioButton)
                || (button instanceof JCheckBox)) {
            if (!currState.isDisabled()) {
                currState = ComponentState.ENABLED;
                activeStates = null;
            } else {
                currState = ComponentState.DISABLED_UNSELECTED;
                activeStates = null;
            }
        }
    }

    SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(component, 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();
        SubstanceColorScheme activeColorScheme = SubstanceColorSchemeUtilities
                .getColorScheme(component, 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 10
Source File: ComboBoxBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void updateBackground(Graphics g, JComboBox combo, ButtonModel comboModel) {
    // failsafe for LAF change
    if (!SubstanceCoreUtilities.isCurrentLookAndFeel())
        return;

    int width = combo.getWidth();
    int height = combo.getHeight();
    int y = 0;

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(combo);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(combo);

    BufferedImage bgImage = getFullAlphaBackground(combo, comboModel, fillPainter,
            borderPainter, width, height);

    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) combo.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    // Two special cases here:
    // 1. Combobox has flat appearance.
    // 2. Combobox is disabled.
    // For both cases, we need to set custom translucency.
    boolean isFlat = SubstanceCoreUtilities.hasFlatAppearance(combo, false);
    boolean isSpecial = isFlat || !combo.isEnabled();
    float extraAlpha = 1.0f;
    if (isSpecial) {
        if (isFlat) {
            // Special handling of flat combos
            extraAlpha = 0.0f;
            for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
                    .entrySet()) {
                ComponentState activeState = activeEntry.getKey();
                if (activeState.isDisabled())
                    continue;
                if (activeState == ComponentState.ENABLED)
                    continue;
                extraAlpha += activeEntry.getValue().getContribution();
            }
        } else {
            if (!combo.isEnabled()) {
                extraAlpha = SubstanceColorSchemeUtilities.getAlpha(combo,
                        modelStateInfo.getCurrModelState());
            }
        }
    }
    if (extraAlpha > 0.0f) {
        Graphics2D graphics = (Graphics2D) g.create();
        graphics.setComposite(WidgetUtilities.getAlphaComposite(combo, extraAlpha, g));
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        NeonCortex.drawImage(graphics, bgImage, 0, y);
        graphics.dispose();
    }
}
 
Example 11
Source File: ComboBoxBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static BufferedImage getFullAlphaBackground(JComboBox combo, ButtonModel model,
        SubstanceFillPainter fillPainter, SubstanceBorderPainter borderPainter, int width,
        int height) {
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) combo.getUI();
    StateTransitionTracker.ModelStateInfo modelStateInfo = transitionAwareUI
            .getTransitionTracker().getModelStateInfo();
    ComponentState currState = modelStateInfo.getCurrModelState();

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

    ClassicButtonShaper shaper = ClassicButtonShaper.INSTANCE;
    int comboFontSize = SubstanceSizeUtils.getComponentFontSize(combo);
    float radius = SubstanceSizeUtils.getClassicButtonCornerRadius(comboFontSize);

    SubstanceColorScheme baseFillScheme = SubstanceColorSchemeUtilities.getColorScheme(combo,
            currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities.getColorScheme(combo,
            ColorSchemeAssociationKind.BORDER, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(width, height,
            baseFillScheme.getDisplayName(), baseBorderScheme.getDisplayName(),
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            combo.getClass().getName(), radius, comboFontSize);
    BufferedImage layerBase = regularBackgrounds.get(keyBase);
    if (layerBase == null) {
        layerBase = createBackgroundImage(combo, shaper, fillPainter, borderPainter, width,
                height, baseFillScheme, baseBorderScheme, radius);
        regularBackgrounds.put(keyBase, layerBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return layerBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(layerBase);
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    g2d.drawImage(layerBase, 0, 0, layerBase.getWidth(), layerBase.getHeight(), 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;

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

            SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(combo, activeState);
            SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(combo, ColorSchemeAssociationKind.BORDER, activeState);
            HashMapKey key = SubstanceCoreUtilities.getHashKey(width, height,
                    fillScheme.getDisplayName(), borderScheme.getDisplayName(),
                    fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    combo.getClass().getName(), radius, comboFontSize);
            BufferedImage layer = regularBackgrounds.get(key);
            if (layer == null) {
                layer = createBackgroundImage(combo, shaper, fillPainter, borderPainter, width,
                        height, fillScheme, borderScheme, radius);
                regularBackgrounds.put(key, layer);
            }
            g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
        }
    }
    g2d.dispose();
    return result;
}
 
Example 12
Source File: SubstanceMenuBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Paints menu highlights.
 * 
 * @param g
 *            Graphics context.
 * @param menuItem
 *            Menu item.
 * @param borderAlpha
 *            Alpha channel for painting the border.
 */
public static void paintHighlights(Graphics g, JMenuItem menuItem,
		float borderAlpha) {
	Graphics2D graphics = (Graphics2D) g.create();

	TransitionAwareUI transitionAwareUI = (TransitionAwareUI) menuItem
			.getUI();
	StateTransitionTracker stateTransitionTracker = transitionAwareUI
			.getTransitionTracker();
	ModelStateInfo modelStateInfo = stateTransitionTracker
			.getModelStateInfo();

	ComponentState currState = modelStateInfo
			.getCurrModelStateNoSelection();

	if (currState.isDisabled()) {
		// no highlights on disabled menus
		return;
	}
	Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
			.getStateNoSelectionContributionMap();
	// if ("Check enabled unselected".equals(menuItem.getText())) {
	// System.out.println("New contribution map");
	// for (Map.Entry<ComponentState,
	// StateTransitionTracker.StateContributionInfo> existing : activeStates
	// .entrySet()) {
	// System.out.println("\t" + existing.getKey() + " in ["
	// + existing.getValue().start + ":"
	// + existing.getValue().end + "] -> "
	// + existing.getValue().curr);
	// }
	// }

	if ((currState == ComponentState.ENABLED) && (activeStates.size() == 1)) {
		// default state - no highlights
		return;
	}

	for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> stateEntry : activeStates
			.entrySet()) {
		ComponentState activeState = stateEntry.getKey();
		float alpha = SubstanceColorSchemeUtilities.getHighlightAlpha(
				menuItem, activeState)
				* stateEntry.getValue().getContribution();
		if (alpha == 0.0f)
			continue;

		SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
				.getColorScheme(menuItem,
						ColorSchemeAssociationKind.HIGHLIGHT, activeState);
		SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
				.getColorScheme(menuItem,
						ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
						activeState);
		graphics.setComposite(WidgetUtilities.getAlphaComposite(
				menuItem, alpha, g));
           HighlightPainterUtils.paintHighlight(graphics, null, menuItem,
                   new Rectangle(0, 0, menuItem.getWidth(), menuItem.getHeight()), borderAlpha,
                   null, fillScheme, borderScheme);
		graphics.setComposite(WidgetUtilities.getAlphaComposite(
				menuItem, g));
	}

	graphics.dispose();
}
 
Example 13
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 14
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 15
Source File: SubstanceScrollBarUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Retrieves image for horizontal thumb.
 * 
 * @param thumbBounds
 *            Thumb bounding rectangle.
 * @return Image for horizontal thumb.
 */
private BufferedImage getThumbHorizontal(Rectangle thumbBounds) {
    int width = Math.max(1, thumbBounds.width);
    int height = Math.max(1, thumbBounds.height);
    int delta = Math.max(0, (int) (0.4 * height));
    if (delta % 2 == 1) {
        delta--;
    }
    height -= delta;

    StateTransitionTracker.ModelStateInfo modelStateInfo = this.compositeStateTransitionTracker
            .getModelStateInfo();
    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseFillScheme = (currState != ComponentState.ENABLED)
            ? SubstanceColorSchemeUtilities.getColorScheme(this.scrollbar, currState)
            : SubstanceColorSchemeUtilities.getActiveColorScheme(this.scrollbar, currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, currState);
    BufferedImage baseLayer = getThumbHorizontal(this.scrollbar, width, height, baseFillScheme,
            baseBorderScheme);

    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return baseLayer;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(baseLayer);
    Graphics2D g2d = result.createGraphics();
    g2d.drawImage(baseLayer, 0, 0, baseLayer.getWidth(), baseLayer.getHeight(), null);

    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState == modelStateInfo.getCurrModelState())
            continue;
        // if (activeState == ComponentState.ENABLED)
        // activeState = ComponentState.SELECTED;

        float contribution = activeEntry.getValue().getContribution();
        if (contribution == 0.0f)
            continue;

        g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));

        SubstanceColorScheme fillScheme = (activeState != ComponentState.ENABLED)
                ? SubstanceColorSchemeUtilities.getColorScheme(this.scrollbar, activeState)
                : SubstanceColorSchemeUtilities.getActiveColorScheme(this.scrollbar,
                        activeState);
        SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                .getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, activeState);
        BufferedImage layer = getThumbHorizontal(this.scrollbar, width, height, fillScheme,
                borderScheme);
        g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
    }

    g2d.dispose();
    return result;
}
 
Example 16
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Retrieves icon that matches the specified state of the slider thumb.
 * 
 * @param slider
 *            The slider itself.
 * @return Icon that matches the specified state of the slider thumb.
 */
private ImageWrapperIcon getIcon(JSlider slider,
        StateTransitionTracker stateTransitionTracker) {
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();
    ComponentState currState = stateTransitionTracker.getModelStateInfo()
            .getCurrModelState();

    float activeStrength = stateTransitionTracker.getActiveStrength();
    float width = this.size * (2.0f + activeStrength) / 3.0f;

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(slider);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(slider);

    SubstanceColorScheme baseFillScheme = SubstanceColorSchemeUtilities
            .getColorScheme(slider, currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities
            .getColorScheme(slider, ColorSchemeAssociationKind.BORDER, currState);

    HashMapKey baseKey = SubstanceCoreUtilities.getHashKey(this.size, width,
            baseFillScheme.getDisplayName(), baseBorderScheme.getDisplayName(),
            fillPainter.getDisplayName(), borderPainter.getDisplayName());

    ImageWrapperIcon baseLayer = SliderRoundIcon.icons.get(baseKey);
    if (baseLayer == null) {
        baseLayer = getSingleLayer(slider, width, fillPainter, borderPainter,
                baseFillScheme, baseBorderScheme);
        SliderRoundIcon.icons.put(baseKey, baseLayer);
    }

    if (currState.isDisabled() || (activeStates.size() == 1))
        return baseLayer;

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(baseLayer.getIconWidth(),
            baseLayer.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    baseLayer.paintIcon(slider, g2d, 0, 0);

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

        float contribution = activeEntry.getValue().getContribution();
        if (contribution == 0.0f)
            continue;

        SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
                .getColorScheme(slider, activeState);
        SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                .getColorScheme(slider, ColorSchemeAssociationKind.BORDER, activeState);

        HashMapKey key = SubstanceCoreUtilities.getHashKey(this.size, width,
                fillScheme.getDisplayName(), borderScheme.getDisplayName(),
                fillPainter.getDisplayName(), borderPainter.getDisplayName());

        ImageWrapperIcon layer = SliderRoundIcon.icons.get(key);
        if (layer == null) {
            layer = getSingleLayer(slider, width, fillPainter, borderPainter, fillScheme,
                    borderScheme);
            SliderRoundIcon.icons.put(key, layer);
        }

        g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));
        layer.paintIcon(slider, g2d, 0, 0);
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 17
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private ImageWrapperIcon getIcon(JSlider slider,
        StateTransitionTracker stateTransitionTracker) {
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();
    ComponentState currState = stateTransitionTracker.getModelStateInfo()
            .getCurrModelState();

    float activeStrength = stateTransitionTracker.getActiveStrength();
    float width = this.size * (2.0f + activeStrength) / 3.0f;

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(slider);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(slider);

    SubstanceColorScheme baseFillScheme = SubstanceColorSchemeUtilities
            .getColorScheme(slider, currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities
            .getColorScheme(slider, ColorSchemeAssociationKind.BORDER, currState);

    HashMapKey baseKey = SubstanceCoreUtilities.getHashKey(this.size, width,
            baseFillScheme.getDisplayName(), baseBorderScheme.getDisplayName(),
            fillPainter.getDisplayName(), borderPainter.getDisplayName(), this.isMirrorred);

    ImageWrapperIcon baseLayer = SliderHorizontalIcon.icons.get(baseKey);
    if (baseLayer == null) {
        baseLayer = getSingleLayer(slider, width, fillPainter, borderPainter,
                baseFillScheme, baseBorderScheme);
        SliderHorizontalIcon.icons.put(baseKey, baseLayer);
    }

    if (currState.isDisabled() || (activeStates.size() == 1))
        return baseLayer;

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(baseLayer.getIconWidth(),
            baseLayer.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    baseLayer.paintIcon(slider, g2d, 0, 0);
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState == currState)
            continue;

        float contribution = activeEntry.getValue().getContribution();
        if (contribution == 0.0f)
            continue;

        SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
                .getColorScheme(slider, activeState);
        SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                .getColorScheme(slider, ColorSchemeAssociationKind.BORDER, activeState);

        HashMapKey key = SubstanceCoreUtilities.getHashKey(this.size, width,
                fillScheme.getDisplayName(), borderScheme.getDisplayName(),
                fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                this.isMirrorred);

        ImageWrapperIcon layer = SliderHorizontalIcon.icons.get(key);
        if (layer == null) {
            layer = getSingleLayer(slider, width, fillPainter, borderPainter, fillScheme,
                    borderScheme);
            SliderHorizontalIcon.icons.put(key, layer);
        }

        g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));
        layer.paintIcon(slider, g2d, 0, 0);
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 18
Source File: RadioButtonMenuItemIcon.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();

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

    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);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(this.menuItem, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize,
            checkMarkSize, fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, alpha);
    ImageWrapperIcon iconBase = iconMap.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(SubstanceImageCreator.getRadioButton(
                this.menuItem, fillPainter, borderPainter, checkMarkSize,
                currState, 0, baseFillColorScheme, baseMarkColorScheme,
                baseBorderColorScheme, visibility, 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
                        .getRadioButton(this.menuItem, fillPainter,
                                borderPainter, checkMarkSize, currState, 0,
                                fillColorScheme, markColorScheme,
                                borderColorScheme, visibility, alpha));
                iconMap.put(keyLayer, iconLayer);
            }

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

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example 19
Source File: ButtonBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Updates background of the specified button.
 *
 * @param g      Graphic context.
 * @param button Button to update.
 */
public void updateBackground(Graphics g, AbstractButton button) {
    // failsafe for LAF change
    if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
        return;
    }

    if (SubstanceCoreUtilities.isButtonNeverPainted(button)) {
        return;
    }

    int width = button.getWidth();
    int height = button.getHeight();
    int y = 0;
    if (SubstanceCoreUtilities.isScrollButton(button)
            || SubstanceCoreUtilities.isSpinnerButton(button)) {
        PairwiseButtonBackgroundDelegate.updatePairwiseBackground(g, button, width, height,
                false);
        return;
    }

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(button);
    SubstanceButtonShaper shaper = SubstanceCoreUtilities.getButtonShaper(button);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(button);

    BufferedImage bgImage = getFullAlphaBackground(button, shaper,
            fillPainter, borderPainter, width, height);

    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) button.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    // Two special cases here:
    // 1. Button has flat appearance.
    // 2. Button is disabled.
    // For both cases, we need to set custom translucency.
    boolean isFlat = SubstanceCoreUtilities.hasFlatAppearance(button);
    boolean isSpecial = isFlat || !button.isEnabled();
    float extraAlpha = 1.0f;
    if (isSpecial) {
        if (isFlat) {
            // Special handling of flat buttons
            extraAlpha = 0.0f;
            for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
                    .entrySet()) {
                ComponentState activeState = activeEntry.getKey();
                if (activeState.isDisabled())
                    continue;
                if (activeState == ComponentState.ENABLED)
                    continue;
                extraAlpha += activeEntry.getValue().getContribution();
            }
        } else {
            if (!button.isEnabled()) {
                extraAlpha = SubstanceColorSchemeUtilities.getAlpha(button,
                        modelStateInfo.getCurrModelState());
            }
        }
    }
    if (extraAlpha > 0.0f) {
        Graphics2D graphics = (Graphics2D) g.create();
        graphics.setComposite(WidgetUtilities.getAlphaComposite(button, extraAlpha, g));
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        NeonCortex.drawImage(graphics, bgImage, 0, y);
        graphics.dispose();
    }
}
 
Example 20
Source File: TransitionAwareResizableIcon.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 ResizableIcon getIconToPaint() {
    StateTransitionTracker stateTransitionTracker = this.stateTransitionTrackerDelegate
            .getStateTransitionTracker();

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

    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseScheme = SubstanceColorSchemeUtilities.getColorScheme(
            this.comp, ColorSchemeAssociationKind.MARK, currState);
    float baseAlpha = SubstanceColorSchemeUtilities.getAlpha(this.comp, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(baseScheme.getDisplayName(),
            baseAlpha, this.width, this.height);
    // System.out.println(key);
    ResizableIcon layerBase = this.iconMap.get(keyBase);
    if (layerBase == null) {
        ResizableIcon baseFullOpacity = this.delegate.getColorSchemeIcon(baseScheme, width, height);
        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.comp, 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();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    // draw the base layer
    layerBase.paintIcon(this.comp, g2d, 0, 0);

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

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

            SubstanceColorScheme scheme = SubstanceColorSchemeUtilities.getColorScheme(this.comp,
                    ColorSchemeAssociationKind.MARK, activeState);
            float alpha = SubstanceColorSchemeUtilities.getAlpha(this.comp, activeState);

            HashMapKey key = SubstanceCoreUtilities.getHashKey(scheme.getDisplayName(), alpha,
                    this.width, this.height);
            ResizableIcon layer = iconMap.get(key);
            if (layer == null) {
                ResizableIcon fullOpacity = this.delegate.getColorSchemeIcon(scheme, width, height);
                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.comp, g2layer, 0, 0);
                    g2layer.dispose();
                    layer = new ImageWrapperIcon(image);
                    iconMap.put(key, layer);
                }
            }
            layer.paintIcon(this.comp, g2d, 0, 0);
        }
    }
    g2d.dispose();
    return new ImageWrapperIcon(result);
}