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

The following examples show how to use org.pushingpixels.substance.api.ComponentState#isActive() . 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: StateTransitionTracker.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void sync() {
    this.activeStrength = 0.0f;
    for (Map.Entry<ComponentState, StateContributionInfo> activeEntry : this
            .stateContributionMap.entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState.isActive()) {
            this.activeStrength += activeEntry.getValue().getContribution();
        }
    }
}
 
Example 2
Source File: SubstanceImageCreator.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Retrieves radio button of the specified size that matches the specified parameters.
 * 
 * @param component
 *            Component.
 * @param dimension
 *            Radio button dimension.
 * @param componentState
 *            Component state.
 * @param offsetX
 *            Offset on X axis - should be positive in order to see the entire radio button.
 * @param fillColorScheme
 *            Color scheme for the inner fill.
 * @param markColorScheme
 *            Color scheme for the check mark.
 * @param borderColorScheme
 *            Color scheme for the border.
 * @param checkMarkVisibility
 *            Check mark visibility in 0.0-1.0 range.
 * @return Radio button of the specified size that matches the specified parameters.
 */
public static BufferedImage getRadioButton(JComponent component,
        SubstanceFillPainter fillPainter, SubstanceBorderPainter borderPainter, int dimension,
        ComponentState componentState, int offsetX, SubstanceColorScheme fillColorScheme,
        SubstanceColorScheme markColorScheme, SubstanceColorScheme borderColorScheme,
        float checkMarkVisibility, float alpha) {

    if (!componentState.isActive()) {
        fillPainter = SimplisticSoftBorderReverseFillPainter.INSTANCE;
    }

    float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth();

    // float fDelta = borderThickness / 2.0f;
    Shape contourBorder = new Ellipse2D.Float(borderDelta / 2.0f, borderDelta / 2.0f,
            dimension - borderDelta, dimension - borderDelta);

    BufferedImage offBackground = SubstanceCoreUtilities.getBlankImage(dimension + offsetX,
            dimension);
    Graphics2D graphics = (Graphics2D) offBackground.getGraphics().create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_PURE);

    graphics.setComposite(getAlphaComposite(alpha));

    graphics.translate(offsetX, 0);
    fillPainter.paintContourBackground(graphics, component, dimension, dimension, contourBorder,
            false, fillColorScheme, true);

    Shape contourInner = new Ellipse2D.Float(1.5f * borderDelta, 1.5f * borderDelta,
            dimension - 3 * borderDelta, dimension - 3 * borderDelta);

    borderPainter.paintBorder(graphics, component, dimension, dimension, contourBorder,
            contourInner, borderColorScheme);
    graphics.setComposite(AlphaComposite.SrcOver);

    float rc = dimension / 2.0f;
    float radius = dimension / 4.5f;

    Shape markOval = new Ellipse2D.Double(rc - radius, rc - radius, 2 * radius, 2 * radius);
    if (checkMarkVisibility > 0.0) {
        // mark
        graphics.setComposite(getAlphaComposite(alpha * checkMarkVisibility));
        graphics.setColor(SubstanceColorUtilities.getMarkColor(markColorScheme,
                !componentState.isDisabled()));
        graphics.fill(markOval);
    } else {
        // draw ghost mark holder
        graphics.setComposite(getAlphaComposite(alpha * 0.3f));
        graphics.setPaint(
                new GradientPaint(rc + radius, rc - radius, fillColorScheme.getDarkColor(),
                        rc - radius, rc + radius, fillColorScheme.getLightColor()));
        graphics.fill(markOval);
    }
    graphics.dispose();

    return offBackground;
}
 
Example 3
Source File: SubstanceImageCreator.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Retrieves check box of the specified size that matches the specified component state.
 * 
 * @param button
 *            Button for the check mark.
 * @param dimension
 *            Check box size.
 * @param componentState
 *            Component state.
 * @param fillColorScheme
 *            Color scheme for the inner fill.
 * @param markColorScheme
 *            Color scheme for the check mark.
 * @param borderColorScheme
 *            Color scheme for the border.
 * @param checkMarkVisibility
 *            Check mark visibility in 0.0-1.0 range.
 * @param isCheckMarkFadingOut
 *            if <code>true</code>, the value of <code>interpolationCyclePos10</code> is used as
 *            the alpha channel.
 * @return Check box of the specified size that matches the specified component state.
 */
public static BufferedImage getCheckBox(AbstractButton button, SubstanceFillPainter fillPainter,
        SubstanceBorderPainter borderPainter, int dimension, ComponentState componentState,
        SubstanceColorScheme fillColorScheme, SubstanceColorScheme markColorScheme,
        SubstanceColorScheme borderColorScheme, float checkMarkVisibility,
        boolean isCheckMarkFadingOut, float alpha) {
    int xOffset = SubstanceSizeUtils
            .getAdjustedSize(SubstanceSizeUtils.getComponentFontSize(button), 2, 9, 1, false);
    int yOffset = xOffset + 1;
    int delta = xOffset;
    float cornerRadius = SubstanceSizeUtils
            .getClassicButtonCornerRadius(SubstanceSizeUtils.getComponentFontSize(button));
    if (dimension <= 10) {
        xOffset = 1;
        yOffset = 2;
        cornerRadius = 2;
    }

    int contourDim = dimension - delta;
    float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f;
    Shape contour = SubstanceOutlineUtilities.getBaseOutline(contourDim, contourDim,
            cornerRadius, null, borderDelta);

    if (!componentState.isActive()) {
        fillPainter = SimplisticSoftBorderReverseFillPainter.INSTANCE;
    }

    BufferedImage offBackground = SubstanceCoreUtilities.getBlankImage(dimension, dimension);
    Graphics2D graphics = (Graphics2D) offBackground.getGraphics();
    graphics.setComposite(getAlphaComposite(alpha));

    graphics.translate(delta - 1, delta - 1);
    fillPainter.paintContourBackground(graphics, button, contourDim, contourDim, contour, false,
            fillColorScheme, true);

    float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth();
    Shape contourInner = SubstanceOutlineUtilities.getBaseOutline(contourDim, contourDim,
            cornerRadius - borderThickness, null, borderThickness + borderDelta);
    borderPainter.paintBorder(graphics, button, contourDim, contourDim, contour, contourInner,
            borderColorScheme);
    graphics.translate(-delta, 1 - delta);
    if (checkMarkVisibility > 0.0) {
        if (isCheckMarkFadingOut) {
            graphics.setComposite(getAlphaComposite(alpha * checkMarkVisibility));
            checkMarkVisibility = 1.0f;
        }

        BufferedImage checkMark = SubstanceImageCreator.getCheckMark(dimension - yOffset / 2,
                !componentState.isDisabled(), markColorScheme, checkMarkVisibility);

        NeonCortex.drawImage(graphics, checkMark, 1 + 2 * xOffset / 3,
                (dimension < 14) ? 0 : -1);
    }

    return offBackground;
}
 
Example 4
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();
}