Java Code Examples for org.pushingpixels.substance.api.SubstanceSkin#isRegisteredAsDecorationArea()

The following examples show how to use org.pushingpixels.substance.api.SubstanceSkin#isRegisteredAsDecorationArea() . 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: UpdateOptimizationInfo.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public UpdateOptimizationInfo(JComponent component) {
    this.component = component;

    this.toDrawWatermark = SubstanceCoreUtilities.toDrawWatermark(this.component);
    this.defaultScheme = SubstanceColorSchemeUtilities.getColorScheme(
            this.component, ComponentState.ENABLED);
    this.decorationAreaType = ComponentOrParentChainScope.getDecorationType(this.component);

    SubstanceSkin skin = SubstanceCoreUtilities.getSkin(this.component);
    this.isInDecorationArea = (this.decorationAreaType != null)
            && skin.isRegisteredAsDecorationArea(this.decorationAreaType)
            && SubstanceCoreUtilities.isOpaque(this.component);
}
 
Example 2
Source File: RibbonTaskToggleButtonBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static BufferedImage getSingleLayer(JRibbonTaskToggleButton button, int width,
        int height, SubstanceColorScheme fillScheme,
        SubstanceColorScheme borderScheme,
        SubstanceBorderPainter borderPainter) {
    Set<Side> bottom = EnumSet.of(Side.BOTTOM);

    Color contextualGroupHueColor = button.getContextualGroupHueColor();
    if (contextualGroupHueColor != null) {
        fillScheme = SubstanceColorSchemeUtilities.getShiftedScheme(fillScheme,
                contextualGroupHueColor, RibbonContextualTaskGroup.HUE_ALPHA, null, 0.0f);
    }

    float radius = getTaskToggleButtonCornerRadius(button);
    float borderDelta = 2.0f * SubstanceSizeUtils.getBorderStrokeWidth();
    float borderInsets = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f;
    Shape contour = SubstanceOutlineUtilities.getBaseOutline(width,
            height + 2 + borderDelta, radius, bottom, borderInsets);

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height + 2);
    Graphics2D graphics = result.createGraphics();

    SubstanceSkin skin = SubstanceCoreUtilities.getSkin(button);
    SubstanceSlices.DecorationAreaType buttonDecorationAreaType =
            SubstanceCortex.ComponentOrParentChainScope.getDecorationType(button);
    if (skin.isRegisteredAsDecorationArea(buttonDecorationAreaType)) {
        DecorationPainterUtils.paintDecorationArea(graphics, button, contour,
                buttonDecorationAreaType, fillScheme, false);
    } else {
        graphics.setColor(fillScheme.getBackgroundFillColor());
        graphics.fill(contour);
    }

    float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth();
    Shape contourInner = SubstanceOutlineUtilities.getBaseOutline(width,
            height + 2 + borderDelta, radius, bottom, borderThickness + borderInsets);

    borderPainter.paintBorder(graphics, button, width, height + 2, contour, contourInner,
            borderScheme);
    graphics.dispose();

    return result;
}
 
Example 3
Source File: BackgroundPaintingUtils.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Updates the background of the specified component on the specified
 * graphic context. The background is not painted when the
 * <code>force</code> parameter is <code>false</code> and at least one of
 * the following conditions holds:
 * <ul>
 * <li>The component is in a cell renderer.</li>
 * <li>The component is not showing on the screen.</li>
 * <li>The component is in the preview mode.</li>
 * </ul>
 * 
 * @param g
 *            Graphic context.
 * @param c
 *            Component.
 * @param force
 *            If <code>true</code>, the painting of background is enforced.
 */
public static void update(Graphics g, JComponent c, boolean force) {
	// failsafe for LAF change
	if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
		return;
	}

	boolean isInCellRenderer = (SwingUtilities.getAncestorOfClass(
			CellRendererPane.class, c) != null);
	boolean isPreviewMode = Boolean.TRUE.equals(
			c.getClientProperty(WidgetUtilities.PREVIEW_MODE));

	Graphics2D graphics = (Graphics2D) g.create();
	// optimization - do not call fillRect on graphics with anti-alias turned on
	graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_OFF);
	graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g));

	DecorationAreaType decorationType = ComponentOrParentChainScope.getDecorationType(c);
	SubstanceSkin skin = SubstanceCoreUtilities.getSkin(c);
	boolean isShowing = c.isShowing();
	boolean showOverlays = true;
	if (c.getParent() instanceof JPopupMenu) {
		// Don't show any overlays on content in popup menus
		showOverlays = false;
	} else {
		if (c instanceof JMenuItem) {
			showOverlays = false;
			if (c instanceof JMenu) {
				// Show overlays on top-level menu content
				showOverlays = ((JMenu) c).isTopLevelMenu();
			}
		} else if (c instanceof JMenuBar) {
			// Show overlays on menu bar
			showOverlays = true;
		}
	}

	if (isShowing && (decorationType != DecorationAreaType.NONE)
			&& (skin.isRegisteredAsDecorationArea(decorationType))) {
		// use the decoration painter
		DecorationPainterUtils.paintDecorationBackground(graphics, c, force);
		if (showOverlays) {
			OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
		}
	} else {
		// fill the area with solid color
		Color backgr = SubstanceColorUtilities
				.getBackgroundFillColor(((c instanceof JTextComponent) || (c instanceof JSpinner)) 
						? c.getParent() : c);
		graphics.setColor(backgr);
		graphics.fillRect(0, 0, c.getWidth(), c.getHeight());

		if (isShowing) {
			if (showOverlays) {
				// add overlays
				OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
			}

			// and paint watermark
			SubstanceWatermark watermark = SubstanceCoreUtilities.getSkin(c).getWatermark();
			if ((watermark != null) && !isPreviewMode && !isInCellRenderer
					&& SubstanceCoreUtilities.toDrawWatermark(c)) {
				watermark.drawWatermarkImage(graphics, c, 0, 0, c.getWidth(), c.getHeight());
			}
		}
	}

	graphics.dispose();
}