Java Code Examples for org.pushingpixels.substance.api.ComponentState#ENABLED

The following examples show how to use org.pushingpixels.substance.api.ComponentState#ENABLED . 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: SubstanceColorSchemeUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the color scheme of the component.
 *
 * @param component       Component.
 * @param associationKind Association kind.
 * @param componentState  Component state.
 * @return Component color scheme.
 */
public static SubstanceColorScheme getDirectColorScheme(Component component,
        ColorSchemeAssociationKind associationKind, ComponentState componentState) {
    // special case - if the component is marked as flat and
    // it is in the default state, get the color scheme of the parent.
    // However, flat toolbars should be ignored, since they are
    // the "top" level decoration area.
    if (!(component instanceof JToolBar)
            && SubstanceCoreUtilities.hasFlatAppearance(component, false)
            && (componentState == ComponentState.ENABLED)) {
        component = component.getParent();
    }

    SubstanceColorScheme nonColorized = SubstanceCoreUtilities.getSkin(component)
            .getDirectColorScheme(component, associationKind, componentState);
    return getColorizedScheme(component, nonColorized, !componentState.isDisabled());
}
 
Example 2
Source File: SubstanceColorSchemeUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the color scheme of the component.
 *
 * @param component       Component.
 * @param associationKind Association kind.
 * @param componentState  Component state.
 * @return Component color scheme.
 */
public static SubstanceColorScheme getColorScheme(Component component,
        ColorSchemeAssociationKind associationKind, ComponentState componentState) {
    // special case - if the component is marked as flat and
    // it is in the default state, get the color scheme of the parent.
    // However, flat toolbars should be ignored, since they are
    // the "top" level decoration area.
    if (!(component instanceof JToolBar)
            && SubstanceCoreUtilities.hasFlatAppearance(component, false)
            && (componentState == ComponentState.ENABLED)) {
        component = component.getParent();
    }

    SubstanceSkin skin = SubstanceCoreUtilities.getSkin(component);
    if (skin == null) {
        return null;
    }
    SubstanceColorScheme nonColorized = skin.getColorScheme(component, associationKind,
            componentState);
    return getColorizedScheme(component, nonColorized, !componentState.isDisabled());
}
 
Example 3
Source File: SubstanceScrollBarUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the scroll button state.
 * 
 * @param scrollButton
 *            Scroll button.
 * @return Scroll button state.
 */
protected ComponentState getState(JButton scrollButton) {
    if (scrollButton == null)
        return null;

    ComponentState result = ((TransitionAwareUI) scrollButton.getUI()).getTransitionTracker()
            .getModelStateInfo().getCurrModelState();
    if ((result == ComponentState.ENABLED)
            && SubstanceCoreUtilities.hasFlatAppearance(this.scrollbar, false)) {
        result = null;
    }
    if (SubstanceCoreUtilities.isButtonNeverPainted(scrollButton)) {
        result = null;
    }
    return result;
}
 
Example 4
Source File: SubstanceDefaultListCellRenderer.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private SubstanceColorScheme getColorSchemeForState(JList list, SubstanceListUI ui,
        ComponentState state) {
    UpdateOptimizationInfo updateOptimizationInfo = ui.getUpdateOptimizationInfo();
    if (state == ComponentState.ENABLED) {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities.getColorScheme(list, state);
        } else {
            return updateOptimizationInfo.getDefaultScheme();
        }
    } else {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities.getColorScheme(list,
                    ColorSchemeAssociationKind.HIGHLIGHT, state);
        } else {
            return updateOptimizationInfo.getHighlightColorScheme(state);
        }
    }
}
 
Example 5
Source File: SubstanceColorUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Color getBackgroundFillColorScrollBar(JScrollBar scrollbar) {
    ComponentState state = scrollbar.isEnabled() ? ComponentState.ENABLED
            : ComponentState.DISABLED_UNSELECTED;
    Color backgr = SubstanceColorUtilities.getDefaultBackgroundColor(
            scrollbar, state);

    if (state.isDisabled()) {
        float alpha = SubstanceColorSchemeUtilities.getAlpha(scrollbar, state);
        if (alpha < 1.0f) {
            Color defaultColor = SubstanceColorUtilities
                    .getDefaultBackgroundColor(scrollbar,
                            ComponentState.ENABLED);
            backgr = SubstanceColorUtilities.getInterpolatedColor(
                    backgr, defaultColor, 1.0f - (1.0f - alpha) / 2.0f);
        }
    }

    SubstanceColorScheme colorScheme =
            SubstanceColorSchemeUtilities.getColorScheme(scrollbar, state);
    float factor = colorScheme.isDark() ? 0.98f : 0.9f;
    backgr = SubstanceColorUtilities.getInterpolatedColor(backgr,
            SubstanceColorUtilities.getAlphaColor(colorScheme.getForegroundColor(),
                    backgr.getAlpha()),
            factor);
    return backgr;
}
 
Example 6
Source File: SubstanceDefaultTableCellRenderer.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private SubstanceColorScheme getColorSchemeForState(JTable table,
        SubstanceTableUI ui, ComponentState state) {
    UpdateOptimizationInfo updateOptimizationInfo = ui.getUpdateOptimizationInfo();
    if (state == ComponentState.ENABLED) {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities.getColorScheme(table, state);
        } else {
            return updateOptimizationInfo.getDefaultScheme();
        }
    } else {
        if (updateOptimizationInfo == null) {
            return SubstanceColorSchemeUtilities.getColorScheme(table,
                    ColorSchemeAssociationKind.HIGHLIGHT, state);
        } else {
            return updateOptimizationInfo.getHighlightColorScheme(state);
        }
    }
}
 
Example 7
Source File: SubstanceTableHeaderUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    // System.err.println("Painting " + this.hashCode() + " from "
    // + ((header == null) ? "null" : header.hashCode()));

    boolean ltr = header.getComponentOrientation().isLeftToRight();
    final ComponentState backgroundState = (header.isEnabled()
            && header.getTable().isEnabled()) ? ComponentState.ENABLED
                    : ComponentState.DISABLED_UNSELECTED;

    SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities.getColorScheme(
            this.header, ColorSchemeAssociationKind.HIGHLIGHT, backgroundState);
    SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities.getColorScheme(
            this.header, ColorSchemeAssociationKind.HIGHLIGHT_BORDER, backgroundState);

    HighlightPainterUtils.paintHighlight(g2d, null, this.header,
            new Rectangle(0, 0, this.getWidth(), this.getHeight()), 0.0f, null, fillScheme,
            borderScheme);

    g2d.setColor(getGridColor(this.header));
    float strokeWidth = SubstanceSizeUtils.getBorderStrokeWidth();
    g2d.setStroke(
            new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setComposite(WidgetUtilities.getAlphaComposite(this.header, 0.7f, g));

    int x = ltr ? (int) strokeWidth / 2 : getWidth() - 1 - (int) strokeWidth / 2;
    g2d.drawLine(x, 0, x, getHeight());

    g2d.dispose();
}
 
Example 8
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 9
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Retrieves icon that matches the specified state of the tree.
 */
private static ImageWrapperIcon getIcon(JTree tree, boolean isCollapsed) {
    ComponentState state = ((tree == null) || tree.isEnabled()) ? ComponentState.ENABLED
            : ComponentState.DISABLED_UNSELECTED;
    SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities.getColorScheme(tree,
            state);
    SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities.getColorScheme(tree,
            ColorSchemeAssociationKind.BORDER, state);
    SubstanceColorScheme markScheme = SubstanceColorSchemeUtilities.getColorScheme(tree,
            ColorSchemeAssociationKind.MARK, state);

    int fontSize = SubstanceSizeUtils.getComponentFontSize(tree);

    HashMapKey key = SubstanceCoreUtilities.getHashKey(fontSize,
            fillScheme.getDisplayName(), borderScheme.getDisplayName(),
            markScheme.getDisplayName(), isCollapsed);

    ImageWrapperIcon result = TreeIcon.icons.get(key);
    if (result != null)
        return result;

    result = new ImageWrapperIcon(SubstanceImageCreator.getTreeIcon(tree, fillScheme,
            borderScheme, markScheme, isCollapsed));
    TreeIcon.icons.put(key, result);

    return result;
}
 
Example 10
Source File: UpdateOptimizationInfo.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public SubstanceColorScheme getFillColorScheme(ComponentState state) {
    if (state == ComponentState.ENABLED) {
        return this.defaultScheme;
    }
    if (this.fillSchemeMap == null) {
        this.fillSchemeMap = new HashMap<>();
    }
    SubstanceColorScheme result = this.fillSchemeMap.get(state);
    if (result == null) {
        result = SubstanceColorSchemeUtilities.getColorScheme(
                this.component, state);
        this.fillSchemeMap.put(state, result);
    }
    return result;
}
 
Example 11
Source File: SubstanceDefaultTableHeaderCellRenderer.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SubstanceColorScheme getColorSchemeForState(
        JTableHeader tableHeader, ComponentState activeState) {
    SubstanceColorScheme scheme = (activeState == ComponentState.ENABLED)
            ? SubstanceColorSchemeUtilities.getColorScheme(tableHeader, activeState)
            : SubstanceColorSchemeUtilities.getColorScheme(tableHeader,
            ColorSchemeAssociationKind.HIGHLIGHT, activeState);
    return scheme;
}
 
Example 12
Source File: SubstanceDefaultTreeCellRenderer.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SubstanceColorScheme getColorSchemeForState(JTree tree, SubstanceTreeUI ui,
        ComponentState activeState) {
    SubstanceColorScheme scheme = (activeState == ComponentState.ENABLED)
            ? ui.getDefaultColorScheme()
            : SubstanceColorSchemeUtilities.getColorScheme(tree,
            ColorSchemeAssociationKind.HIGHLIGHT, activeState);
    if (scheme == null) {
        scheme = SubstanceColorSchemeUtilities.getColorScheme(tree,
                ColorSchemeAssociationKind.HIGHLIGHT, activeState);
    }
    return scheme;
}
 
Example 13
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 14
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 15
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 16
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 17
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 18
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 19
Source File: KeyTipRenderingUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void renderKeyTip(Graphics g, Container c, Rectangle rect, String keyTip,
        boolean toPaintEnabled) {
    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(c);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
            .getBorderPainter(c);

    ComponentState state =
            toPaintEnabled ? ComponentState.ENABLED : ComponentState.DISABLED_UNSELECTED;
    float alpha = SubstanceColorSchemeUtilities.getAlpha(c, state);
    SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
            .getColorScheme(c, state);
    SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
            .getColorScheme(c, SubstanceSlices.ColorSchemeAssociationKind.BORDER, state);
    float radius = SubstanceSizeUtils.getClassicButtonCornerRadius(
            SubstanceSizeUtils.getComponentFontSize(c));

    float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f;

    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setComposite(WidgetUtilities.getAlphaComposite(c, alpha, g));
    g2d.translate(rect.x, rect.y);
    Shape contour = SubstanceOutlineUtilities.getBaseOutline(rect.width, rect.height, radius,
            null, borderDelta);
    fillPainter.paintContourBackground(g2d, c, rect.width, rect.height,
            contour, false, fillScheme, true);

    float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth();
    Shape contourInner = SubstanceOutlineUtilities.getBaseOutline(rect.width, rect.height,
            radius, null, borderDelta + borderThickness);
    borderPainter.paintBorder(g2d, c, rect.width, rect.height, contour,
            contourInner, borderScheme);

    g2d.setColor(SubstanceColorSchemeUtilities.getColorScheme(c, state).getForegroundColor());
    Font font = SubstanceCortex.GlobalScope.getFontPolicy().getFontSet().
            getControlFont();
    font = font.deriveFont(font.getSize() + 1.0f);
    g2d.setFont(font);
    int strWidth = g2d.getFontMetrics().stringWidth(keyTip);

    LineMetrics lineMetrics = g2d.getFontMetrics().getLineMetrics(keyTip, g2d);
    int strHeight = (int) lineMetrics.getHeight();
    NeonCortex.installDesktopHints(g2d, font);
    g2d.drawString(keyTip, (rect.width - strWidth) / 2,
            (rect.height + strHeight) / 2 - g2d.getFontMetrics().getDescent());

    g2d.dispose();
}
 
Example 20
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;
}