org.pushingpixels.substance.internal.utils.SubstanceColorUtilities Java Examples

The following examples show how to use org.pushingpixels.substance.internal.utils.SubstanceColorUtilities. 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: MatteDecorationPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Fills the relevant part with the gradient fill.
 *
 * @param graphics Graphics.
 * @param scheme   Color scheme to use.
 * @param offsetY  Vertical offset.
 * @param x        X coordinate of the fill area.
 * @param y        Y coordinate of the fill area.
 * @param width    Fill area width.
 * @param height   Fill area height.
 */
protected void fill(Graphics2D graphics, SubstanceColorScheme scheme,
        int offsetY, int x, int y, int width, int height) {
    // 0 - flex : light -> medium
    // flex - : medium fill

    Color startColor = scheme.getLightColor();
    Color endColor = SubstanceColorUtilities.getInterpolatedColor(startColor,
            scheme.getMidColor(), 0.4f);

    int gradientHeight = Math.max(FLEX_POINT, height + offsetY);
    Paint paint = (gradientHeight == FLEX_POINT) ?
            new GradientPaint(0, y - offsetY, startColor, 0, y + gradientHeight - offsetY,
                    endColor) :
            new LinearGradientPaint(
                    0, y - offsetY, 0, y + height - offsetY,
                    new float[] { 0.0f, (float) FLEX_POINT / (float) gradientHeight, 1.0f },
                    new Color[] { startColor, endColor, endColor },
                    MultipleGradientPaint.CycleMethod.NO_CYCLE);

    graphics.setPaint(paint);
    graphics.fillRect(x, y, width, height);
}
 
Example #2
Source File: FractionBasedBorderPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Color getRepresentativeColor(SubstanceColorScheme borderScheme) {
	for (int i = 0; i < this.fractions.length - 1; i++) {
		float fractionLow = this.fractions[i];
		float fractionHigh = this.fractions[i + 1];
		if (fractionLow == 0.5f) {
			return this.colorQueries[i].query(borderScheme);
		}
		if (fractionHigh == 0.5f) {
			return this.colorQueries[i + 1].query(borderScheme);
		}
		if ((fractionLow < 0.5f) || (fractionHigh > 0.5f)) {
			continue;
		}
		// current range contains 0.5f
		Color colorLow = this.colorQueries[i].query(borderScheme);
		Color colorHigh = this.colorQueries[i + 1].query(borderScheme);
		float colorLowLikeness = (0.5f - fractionLow) / (fractionHigh - fractionLow);
		return SubstanceColorUtilities.getInterpolatedColor(colorLow, colorHigh,
				colorLowLikeness);
	}
	throw new IllegalStateException("Could not find representative color");
}
 
Example #3
Source File: GraphiteGlassSkin.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new <code>Graphite</code> skin.
 */
public GraphiteGlassSkin() {
	super();

	SubstanceSkin.ColorSchemes schemes = SubstanceSkin.getColorSchemes(
			this.getClass().getClassLoader().getResourceAsStream(
					"org/pushingpixels/substance/api/skin/graphite.colorschemes"));

	SubstanceColorScheme backgroundScheme = schemes.get("Graphite Background");
	this.registerAsDecorationArea(backgroundScheme, DecorationAreaType.PRIMARY_TITLE_PANE,
			DecorationAreaType.SECONDARY_TITLE_PANE, DecorationAreaType.HEADER);

	// add two overlay painters to create a bezel line between
	// menu bar and toolbars
	BottomLineOverlayPainter menuOverlayPainter = new BottomLineOverlayPainter(
			ColorSchemeSingleColorQuery.MID);
	TopLineOverlayPainter toolbarOverlayPainter = new TopLineOverlayPainter(
			(SubstanceColorScheme scheme) -> SubstanceColorUtilities.getAlphaColor(
					scheme.getForegroundColor(), 32));
	this.addOverlayPainter(menuOverlayPainter, DecorationAreaType.HEADER);
	this.addOverlayPainter(toolbarOverlayPainter, DecorationAreaType.TOOLBAR);

	this.fillPainter = new GlassFillPainter();
	this.decorationPainter = new ArcDecorationPainter();
	this.highlightPainter = new GlassHighlightPainter();
}
 
Example #4
Source File: TopShadowOverlayPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintOverlay(Graphics2D graphics, Component comp,
        DecorationAreaType decorationAreaType, int width, int height,
        SubstanceSkin skin) {
    Color shadowColor = SubstanceColorUtilities.deriveByBrightness(
            SubstanceColorUtilities.getBackgroundFillColor(comp), -0.4f);

    // need to handle components "embedded" in other components
    Component topMostWithSameDecorationAreaType = SubstanceCoreUtilities
            .getTopMostParentWithDecorationAreaType(comp, decorationAreaType);
    Point inTopMost = SwingUtilities.convertPoint(comp, new Point(0, 0),
            topMostWithSameDecorationAreaType);
    int dy = inTopMost.y;

    Graphics2D g2d = (Graphics2D) graphics.create();
    g2d.translate(0, -dy);
    g2d.setPaint(new GradientPaint(
            0, 0, SubstanceColorUtilities.getAlphaColor(shadowColor, this.startAlpha),
            0, 4, SubstanceColorUtilities.getAlphaColor(shadowColor, 16)));
    g2d.fillRect(0, 0, comp.getWidth(), 4);
    g2d.dispose();
}
 
Example #5
Source File: MatteDecorationPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintDecorationArea(Graphics2D graphics, Component comp, DecorationAreaType
        decorationAreaType, Shape contour, SubstanceColorScheme colorScheme) {
    Point offset = SubstanceCoreUtilities.getOffsetInRootPaneCoords(comp);

    Color startColor = colorScheme.getLightColor();
    Color endColor = SubstanceColorUtilities.getInterpolatedColor(startColor,
            colorScheme.getMidColor(), 0.4f);

    int gradientHeight = Math.max(FLEX_POINT, comp.getHeight() + offset.y);
    Paint paint = (gradientHeight == FLEX_POINT) ?
            new GradientPaint(0, -offset.y, startColor, 0, gradientHeight - offset.y,
                    endColor) :
            new LinearGradientPaint(
                    0, -offset.y, 0, comp.getHeight() - offset.y,
                    new float[] { 0.0f, (float) FLEX_POINT / (float) gradientHeight, 1.0f },
                    new Color[] { startColor, endColor, endColor },
                    MultipleGradientPaint.CycleMethod.NO_CYCLE);

    graphics.setPaint(paint);
    graphics.fill(contour);
}
 
Example #6
Source File: SaturatedColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new saturated color scheme.
 * 
 * @param origScheme
 *            The original color scheme.
 * @param saturationFactor
 *            Saturation factor. Should be in -1.0..1.0 range.
 */
public SaturatedColorScheme(SubstanceColorScheme origScheme,
		double saturationFactor) {
	super("Saturated (" + (int) (100 * saturationFactor) + "%) "
			+ origScheme.getDisplayName(), origScheme.isDark());
	this.saturationFactor = saturationFactor;
	this.origScheme = origScheme;
	this.foregroundColor = origScheme.getForegroundColor();
	this.mainUltraDarkColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getUltraDarkColor(), saturationFactor);
	this.mainDarkColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getDarkColor(), saturationFactor);
	this.mainMidColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getMidColor(), saturationFactor);
	this.mainLightColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getLightColor(), saturationFactor);
	this.mainExtraLightColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getExtraLightColor(), saturationFactor);
	this.mainUltraLightColor = SubstanceColorUtilities.getSaturatedColor(
			origScheme.getUltraLightColor(), saturationFactor);
}
 
Example #7
Source File: NegatedColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new inverted scheme.
 * 
 * @param origScheme
 *            The original color scheme.
 */
public NegatedColorScheme(SubstanceColorScheme origScheme) {
	super("Negated " + origScheme.getDisplayName(), !origScheme.isDark());
	this.origScheme = origScheme;

	this.foregroundColor = SubstanceColorUtilities.invertColor(origScheme.getForegroundColor());

	this.mainUltraDarkColor = SubstanceColorUtilities
			.invertColor(origScheme.getUltraDarkColor());
	this.mainDarkColor = SubstanceColorUtilities.invertColor(origScheme.getDarkColor());
	this.mainMidColor = SubstanceColorUtilities.invertColor(origScheme.getMidColor());
	this.mainLightColor = SubstanceColorUtilities.invertColor(origScheme.getLightColor());
	this.mainExtraLightColor = SubstanceColorUtilities
			.invertColor(origScheme.getExtraLightColor());
	this.mainUltraLightColor = SubstanceColorUtilities
			.invertColor(origScheme.getUltraLightColor());
	this.isDark = !origScheme.isDark();
}
 
Example #8
Source File: HueShiftColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new hue-shifted color scheme.
 * 
 * @param origScheme
 *            The original color scheme.
 * @param hueShiftFactor
 *            Shift factor. Should be in -1.0-1.0 range.
 */
public HueShiftColorScheme(SubstanceColorScheme origScheme,
		double hueShiftFactor) {
	super("Hue-shift " + origScheme.getDisplayName() + " "
			+ (int) (100 * hueShiftFactor) + "%", origScheme.isDark());
	this.hueShiftFactor = hueShiftFactor;
	this.origScheme = origScheme;
	this.foregroundColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getForegroundColor(), this.hueShiftFactor / 2.0);
	this.mainUltraDarkColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getUltraDarkColor(), this.hueShiftFactor);
	this.mainDarkColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getDarkColor(), this.hueShiftFactor);
	this.mainMidColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getMidColor(), this.hueShiftFactor);
	this.mainLightColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getLightColor(), this.hueShiftFactor);
	this.mainExtraLightColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getExtraLightColor(), this.hueShiftFactor);
	this.mainUltraLightColor = SubstanceColorUtilities.getHueShiftedColor(
			origScheme.getUltraLightColor(), this.hueShiftFactor);
}
 
Example #9
Source File: BaseColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toString() {
	return this.getDisplayName() + " {\n    kind="
			+ (this.isDark() ? "Dark" : "Light") + "\n    colorUltraLight="
			+ SubstanceColorUtilities.encode(this.getUltraLightColor())
			+ "\n    colorExtraLight="
			+ SubstanceColorUtilities.encode(this.getExtraLightColor())
			+ "\n    colorLight="
			+ SubstanceColorUtilities.encode(this.getLightColor())
			+ "\n    colorMid="
			+ SubstanceColorUtilities.encode(this.getMidColor())
			+ "\n    colorDark="
			+ SubstanceColorUtilities.encode(this.getDarkColor())
			+ "\n    colorUltraDark="
			+ SubstanceColorUtilities.encode(this.getUltraDarkColor())
			+ "\n    colorForeground="
			+ SubstanceColorUtilities.encode(this.getForegroundColor())
			+ "\n}";
}
 
Example #10
Source File: SubstanceTextPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void installDefaults() {
    super.installDefaults();

    // support for per-window skins
    SwingUtilities.invokeLater(() -> {
        if (textPane == null)
            return;
        Color foregr = textPane.getForeground();
        if ((foregr == null) || (foregr instanceof UIResource)) {
            textPane.setForeground(SubstanceColorUtilities
                    .getForegroundColor(SubstanceCortex.ComponentScope.getCurrentSkin(textPane)
                            .getEnabledColorScheme(ComponentOrParentChainScope
                                    .getDecorationType(textPane))));
        }
    });
    for (SubstanceWidget lafWidget : this.lafWidgets) {
        lafWidget.installDefaults();
    }
}
 
Example #11
Source File: SubstanceEditorPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void installDefaults() {
    super.installDefaults();

    editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    // support for per-window skins
    SwingUtilities.invokeLater(() -> {
        if (editorPane == null) {
            return;
        }
        Color foregr = editorPane.getForeground();
        if ((foregr == null) || (foregr instanceof UIResource)) {
            editorPane.setForeground(SubstanceColorUtilities.getForegroundColor(
                    SubstanceCortex.ComponentScope.getCurrentSkin(editorPane)
                            .getEnabledColorScheme(ComponentOrParentChainScope
                                    .getDecorationType(editorPane))));
        }
    });
    for (SubstanceWidget lafWidget : this.lafWidgets) {
        lafWidget.installDefaults();
    }
}
 
Example #12
Source File: SubstanceTextAreaUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void installDefaults() {
    super.installDefaults();

    // support for per-window skins
    SwingUtilities.invokeLater(() -> {
        if (!SubstanceCoreUtilities.isCurrentLookAndFeel())
            return;
        if (textArea == null)
            return;
        Color foregr = textArea.getForeground();
        if ((foregr == null) || (foregr instanceof UIResource)) {
            textArea.setForeground(SubstanceColorUtilities
                    .getForegroundColor(SubstanceCortex.ComponentScope.getCurrentSkin(textArea)
                            .getEnabledColorScheme(ComponentOrParentChainScope
                                    .getDecorationType(textArea))));
        }
    });
    for (SubstanceWidget lafWidget : this.lafWidgets) {
        lafWidget.installDefaults();
    }
}
 
Example #13
Source File: GrayscaleFilter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void grayScaleColor(int[] pixels) {
	for (int i = 0; i < pixels.length; i++) {
		int argb = pixels[i];
		int brightness = SubstanceColorUtilities.getColorBrightness(argb);
		pixels[i] = (argb & 0xFF000000) | brightness << 16 | brightness << 8 | brightness;
	}
}
 
Example #14
Source File: ColorWheelPanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Invoked when the mouse exits a component.
 */
public void mouseMoved(MouseEvent e) {
	GeneralPath oldPath = rolloverPath;
	rolloverPath = null;
	if (e.getSource() == imagePicker) {
		Point pt = e.getPoint();
		if (paths != null) {
			int numPaths = paths.length;
			for (int i = 0; i < numPaths; i++) {
				if (paths[i].contains(pt.x, pt.y)) {
					rolloverPath = paths[i];
					ModelColor[][] baseColors = ModelColor.getBaseColors();
					int ring = i / ModelColor.NUM_SEGMENTS;
					ModelColor modelColor = baseColors[i
							% ModelColor.NUM_SEGMENTS][ring];
					if (adjustRollover) {
						modelColor = new ModelColor(modelColor.H,
								saturationMultipler * modelColor.S,
								brightnessMultipler * modelColor.V);
					}

					rolloverColor = new Color(modelColor.getRed(),
							modelColor.getGreen(), modelColor.getBlue());
					if (ring < 4) {
						rolloverColor = SubstanceColorUtilities.deriveByBrightness(
								rolloverColor, -0.5f);
					} else {
						rolloverColor = SubstanceColorUtilities.deriveByBrightness(
								rolloverColor, 0.8f);
					}
					break;
				}
			}
		}
	}

	if (rolloverPath != oldPath)
		repaint();
}
 
Example #15
Source File: InvertedColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new inverted scheme.
 * 
 * @param origScheme
 *            The original color scheme.
 */
public InvertedColorScheme(SubstanceColorScheme origScheme) {
	super("Inverted " + origScheme.getDisplayName(), !origScheme.isDark());
	this.origScheme = origScheme;
	this.foregroundColor = SubstanceColorUtilities.invertColor(origScheme.getForegroundColor());
	this.mainUltraDarkColor = SubstanceColorUtilities
			.invertColor(origScheme.getUltraLightColor());
	this.mainDarkColor = SubstanceColorUtilities.invertColor(origScheme.getExtraLightColor());
	this.mainMidColor = SubstanceColorUtilities.invertColor(origScheme.getLightColor());
	this.mainLightColor = SubstanceColorUtilities.invertColor(origScheme.getMidColor());
	this.mainExtraLightColor = SubstanceColorUtilities.invertColor(origScheme.getDarkColor());
	this.mainUltraLightColor = SubstanceColorUtilities
			.invertColor(origScheme.getUltraDarkColor());
	this.isDark = !origScheme.isDark();
}
 
Example #16
Source File: BlendBiColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new blended color scheme.
 * 
 * @param firstScheme
 *            The first original color scheme.
 * @param secondScheme
 *            The second original color scheme.
 * @param firstSchemeLikeness
 *            Likeness to the first scheme. Values close to 0.0 will create
 *            scheme that closely matches the second original scheme. Values
 *            close to 1.0 will create scheme that closely matches the
 *            second original scheme.
 */
public BlendBiColorScheme(SubstanceColorScheme firstScheme,
		SubstanceColorScheme secondScheme, double firstSchemeLikeness) {
	super("Blended " + firstScheme.getDisplayName() + " & "
			+ secondScheme.getDisplayName() + " " + firstSchemeLikeness,
			firstScheme.isDark());
	this.firstScheme = firstScheme;
	this.secondScheme = secondScheme;
	this.firstSchemeLikeness = firstSchemeLikeness;
	this.foregroundColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getForegroundColor(),
					secondScheme.getForegroundColor(), firstSchemeLikeness));
	this.mainUltraDarkColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getUltraDarkColor(),
					secondScheme.getUltraDarkColor(), firstSchemeLikeness));
	this.mainDarkColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getDarkColor(), secondScheme
					.getDarkColor(), firstSchemeLikeness));
	this.mainMidColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getMidColor(), secondScheme
					.getMidColor(), firstSchemeLikeness));
	this.mainLightColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getLightColor(), secondScheme
					.getLightColor(), firstSchemeLikeness));
	this.mainExtraLightColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getExtraLightColor(),
					secondScheme.getExtraLightColor(), firstSchemeLikeness));
	this.mainUltraLightColor = new Color(SubstanceColorUtilities
			.getInterpolatedRGB(firstScheme.getUltraLightColor(),
					secondScheme.getUltraLightColor(), firstSchemeLikeness));
}
 
Example #17
Source File: SwatchPanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void paintComponent(Graphics g) {
    Dimension preferredSize = getSwatchesSize();
    int xoffset = (getWidth() - preferredSize.width) / 2;
    int yoffset = 0;// (getHeight() - preferredSize.height) / 2;

    Graphics2D g2d = (Graphics2D) g.create();

    for (int row = 0; row < numSwatches.height; row++) {
        for (int column = 0; column < numSwatches.width; column++) {
            Color cellColor = getColorForCell(column, row);
            g2d.setColor(cellColor);
            //int x = (numSwatches.width - column - 1) * (swatchSize.width + gap.width);
            int x = xoffset + column * (swatchSize.width + gap.width) + 1;
            int y = yoffset + row * (swatchSize.height + gap.height) + 1;
            g2d.fillRect(x, y, swatchSize.width + 1, swatchSize.height + 1);

            float borderStrokeWidth = SubstanceSizeUtils.getBorderStrokeWidth();
            g2d.setStroke(new BasicStroke(borderStrokeWidth));

            g2d.setColor(SubstanceColorUtilities.deriveByBrightness(cellColor, -0.5f));
            g2d.draw(new Line2D.Float(x - borderStrokeWidth, y - borderStrokeWidth,
                    x + swatchSize.width, y - borderStrokeWidth));
            //x - 1, y - 1, swatchSize.width+1, 1);
            g2d.draw(new Line2D.Float(x - borderStrokeWidth, y,
                    x - borderStrokeWidth, y + swatchSize.height));
            //g2d.fillRect(x - 1, y, 1, swatchSize.height);
        }
    }

    g2d.dispose();
}
 
Example #18
Source File: SubstanceCommandButtonPanelUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void paintGroupBackground(Graphics g, int groupIndex, int x,
        int y, int width, int height) {
    Color background = SubstanceColorUtilities.getBackgroundFillColor(this.buttonPanel);
    if (groupIndex % 2 == 1) {
        background = SubstanceColorUtilities.getDarkerColor(background, 0.06);
    }

    BackgroundPaintingUtils.fillAndWatermark(g, this.buttonPanel,
            background, new Rectangle(x, y, width, height));
}
 
Example #19
Source File: SubstancePanelUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void installDefaults(JPanel p) {
	super.installDefaults(p);
	// support for per-window skins
	Color backgr = p.getBackground();
	if ((backgr == null) || (backgr instanceof UIResource)) {
		Color backgroundFillColor = SubstanceColorUtilities.getBackgroundFillColor(p);
		// fix for issue 436 - logic in getBackground() of
		// custom panels can result in null value
		if (backgroundFillColor != null) {
			p.setBackground(new ColorUIResource(backgroundFillColor));
		}
	}
}
 
Example #20
Source File: SubstanceViewportUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void installDefaults(JComponent c) {
	super.installDefaults(c);
	// support for per-window skins
	Color backgr = c.getBackground();
	if ((backgr == null) || (backgr instanceof UIResource)) {
		Color backgroundFillColor = SubstanceColorUtilities.getBackgroundFillColor(c);
		if (backgroundFillColor != null) {
			c.setBackground(new ColorUIResource(backgroundFillColor));
		}
	}
}
 
Example #21
Source File: ColorSchemeFilter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void mixColor(int[] pixels) {
    for (int i = 0; i < pixels.length; i++) {
        int argb = pixels[i];

        int brightness = SubstanceColorUtilities.getColorBrightness(argb);

        int r = (argb >>> 16) & 0xFF;
        int g = (argb >>> 8) & 0xFF;
        int b = (argb >>> 0) & 0xFF;

        float[] hsb = Color.RGBtoHSB(r, g, b, null);
        int pixelColor = interpolated[brightness * MAPSTEPS / 256];

        int ri = (pixelColor >>> 16) & 0xFF;
        int gi = (pixelColor >>> 8) & 0xFF;
        int bi = (pixelColor >>> 0) & 0xFF;
        float[] hsbi = Color.RGBtoHSB(ri, gi, bi, null);

        hsb[0] = hsbi[0];
        hsb[1] = hsbi[1];
        if (this.originalBrightnessFactor >= 0.0f) {
            hsb[2] = this.originalBrightnessFactor * hsb[2]
                    + (1.0f - this.originalBrightnessFactor) * hsbi[2];
        } else {
            hsb[2] = hsb[2] * hsbi[2] * (1.0f + this.originalBrightnessFactor);
        }

        int result = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);

        pixels[i] = (argb & 0xFF000000) | ((result >> 16) & 0xFF) << 16
                | ((result >> 8) & 0xFF) << 8 | (result & 0xFF);
    }
}
 
Example #22
Source File: SubstanceEtchedBorder.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the shadow color for the specified component.
 * 
 * @param c
 *            Component.
 * @return Matching shadow color.
 */
public Color getShadowColor(Component c) {
	SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities
			.getColorScheme(c, ColorSchemeAssociationKind.SEPARATOR,
					ComponentState.ENABLED);
	Color back = colorScheme.isDark() ? colorScheme.getDarkColor()
			: colorScheme.getUltraLightColor();
	return SubstanceColorUtilities.getAlphaColor(back, 196);
}
 
Example #23
Source File: SubstanceEtchedBorder.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the highlight color for the specified component.
 * 
 * @param c
 *            Component.
 * @return Matching highlight color.
 */
public Color getHighlightColor(Component c) {
	SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities
			.getColorScheme(c, ColorSchemeAssociationKind.SEPARATOR,
					ComponentState.ENABLED);
	boolean isDark = colorScheme.isDark();
	Color foreDark = isDark ? colorScheme.getExtraLightColor()
			: SubstanceColorUtilities.getInterpolatedColor(colorScheme
					.getMidColor(), colorScheme.getDarkColor(), 0.4);

	return SubstanceColorUtilities.getAlphaColor(foreDark, 196);
}
 
Example #24
Source File: BottomShadowOverlayPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paintOverlay(Graphics2D graphics, Component comp,
		DecorationAreaType decorationAreaType, int width, int height,
		SubstanceSkin skin) {
	Color shadowColor = SubstanceColorUtilities.deriveByBrightness(
			SubstanceColorUtilities.getBackgroundFillColor(comp), -0.4f);

	Component topMostWithSameDecorationAreaType = SubstanceCoreUtilities
			.getTopMostParentWithDecorationAreaType(comp,
					decorationAreaType);
	int topHeight = topMostWithSameDecorationAreaType.getHeight();

	Point inTopMost = SwingUtilities.convertPoint(comp, new Point(0, 0),
			topMostWithSameDecorationAreaType);
	int dy = inTopMost.y;

	Graphics2D fillGraphics = (Graphics2D) graphics.create();
	fillGraphics.translate(0, -dy);

	int shadowHeight = 4;
	GradientPaint fillPaint = new GradientPaint(0, topHeight - shadowHeight, 
			SubstanceColorUtilities.getAlphaColor(shadowColor, 0), 0, topHeight,
			SubstanceColorUtilities.getAlphaColor(shadowColor, this.endAlpha));
	fillGraphics.setPaint(fillPaint);
	fillGraphics.fillRect(0, topHeight - shadowHeight, width, shadowHeight);
	fillGraphics.dispose();
}
 
Example #25
Source File: GlowingIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	if (this.delegate == null)
		return;
	float fadePos = this.iconGlowTracker.getIconGlowPosition();
	// System.out.println(fadePos);
	Icon toPaint = this.iconMap.get(fadePos);
	if (toPaint == null) {
		int width = this.getIconWidth();
		int height = this.getIconHeight();
		BufferedImage image = SubstanceCoreUtilities.getBlankImage(width,
				height);
		Graphics2D graphics = (Graphics2D) image.getGraphics();
		//graphics.scale(1.0f / scale, 1.0f / scale);
		this.delegate.paintIcon(c, graphics, 0, 0);
		int pixelWidth = image.getWidth();
		int pixelHeight = image.getHeight();
		for (int i = 0; i < pixelWidth; i++) {
			for (int j = 0; j < pixelHeight; j++) {
				int rgba = image.getRGB(i, j);
				int transp = (rgba >>> 24) & 0xFF;
				double coef = Math.sin(2.0 * Math.PI * fadePos / 2.0) / glowDampeningFactor;
				Color newColor = (coef >= 0.0) ? SubstanceColorUtilities
						.getLighterColor(new Color(rgba), coef)
						: SubstanceColorUtilities.getDarkerColor(new Color(
								rgba), -coef);
				image.setRGB(i, j, (transp << 24)
						| (newColor.getRed() << 16)
						| (newColor.getGreen() << 8) | newColor.getBlue());
			}
		}
		toPaint = new ImageWrapperIcon(image);
		this.iconMap.put(fadePos, toPaint);
	}
	Graphics2D g2d = (Graphics2D) g.create();
	g2d.translate(x, y);
	toPaint.paintIcon(c, g, 0, 0);
	g2d.dispose();
}
 
Example #26
Source File: NoiseFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns a noise image.
 *
 * @param skin         The skin to use for rendering the image.
 * @param width        Image width.
 * @param height       Image height.
 * @param xFactor      X stretch factor.
 * @param yFactor      Y stretch factor.
 * @param hasConstantZ Indication whether the Z is constant.
 * @param noiseFilter  Noise filter to apply.
 * @param toBlur       Indication whether the resulting image should be blurred.
 * @param isPreview    Indication whether the image is in preview mode.
 * @return Noise image.
 */
public static BufferedImage getNoiseImage(SubstanceSkin skin, int width,
        int height, double xFactor, double yFactor, boolean hasConstantZ,
        NoiseFilter noiseFilter, boolean toBlur, boolean isPreview) {
    SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
    Color c1 = scheme.getWatermarkDarkColor();
    // c1 = new Color(255, 0, 0, 0);
    // System.out.println(c1.getAlpha());
    // Color c2 = scheme.getWatermarkStampColor();
    Color c3 = scheme.getWatermarkLightColor();

    BufferedImage dst = NeonCortex.getBlankImage(width, height);
    //
    // new BufferedImage(width, height,
    // BufferedImage.TYPE_INT_ARGB);

    // Borrow from Sebastien Petrucci fast blur code - direct access
    // to the raster data
    int[] dstBuffer = ((DataBufferInt) dst.getRaster().getDataBuffer())
            .getData();
    // System.out.println((dstBuffer[0] >>> 24) & 0xFF);

    int imageWidth = dst.getWidth();
    int imageHeight = dst.getHeight();
    double m2 = xFactor * imageWidth * xFactor * imageWidth + yFactor * imageHeight
            * yFactor * imageHeight;
    int pos = 0;
    for (int j = 0; j < imageHeight; j++) {
        double jj = yFactor * j;
        for (int i = 0; i < imageWidth; i++) {
            double ii = xFactor * i;
            double z = hasConstantZ ? 1.0 : Math.sqrt(m2 - ii * ii - jj
                    * jj);
            double noise = 0.5 + 0.5 * PerlinNoiseGenerator
                    .noise(ii, jj, z);
            if (noiseFilter != null)
                noise = noiseFilter.apply(i, j, z, noise);

            double likeness = Math.max(0.0, Math.min(1.0, 2.0 * noise));
            // likeness = 0.0;
            dstBuffer[pos++] = SubstanceColorUtilities.getInterpolatedRGB(
                    c3, c1, likeness);
        }
    }
    // System.out.println((dstBuffer[0] >>> 24) & 0xFF);
    if (toBlur) {
        float edgeBlur = 0.08f / (float) NeonCortex.getScaleFactor();
        ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] {
                edgeBlur, edgeBlur, edgeBlur, edgeBlur, 1.06f - 8 * edgeBlur, edgeBlur,
                edgeBlur, edgeBlur, edgeBlur }),
                ConvolveOp.EDGE_NO_OP, null);
        dst = convolve.filter(dst, NeonCortex.getBlankImage(width, height));
    }
    return dst;
}
 
Example #27
Source File: ShiftColorScheme.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a new shifted color scheme.
 * 
 * @param origScheme
 *            The original color scheme.
 * @param backgroundShiftColor
 *            Shift color for the background colors.
 * @param backgroundShiftFactor
 *            Shift factor for the background colors. Should be in 0.0-1.0
 *            range.
 * @param foregroundShiftColor
 *            Shift color for the foreground colors.
 * @param foregroundShiftFactor
 *            Shift factor for the foreground colors. Should be in 0.0-1.0
 *            range.
 * @param shiftByBrightness
 *            If <code>true</code>, the shift will account for the
 *            brightness of the original color scheme colors.
 */
public ShiftColorScheme(SubstanceColorScheme origScheme, Color backgroundShiftColor,
		double backgroundShiftFactor, Color foregroundShiftColor, double foregroundShiftFactor,
		boolean shiftByBrightness) {
	super("Shift " + origScheme.getDisplayName() + " to backgr [" + backgroundShiftColor + "] "
			+ (int) (100 * backgroundShiftFactor) + "%, foregr [" + foregroundShiftColor + "]"
			+ (int) (100 * foregroundShiftFactor) + "%", origScheme.isDark());
	this.backgroundShiftColor = backgroundShiftColor;
	this.backgroundShiftFactor = backgroundShiftFactor;
	this.foregroundShiftColor = foregroundShiftColor;
	this.foregroundShiftFactor = foregroundShiftFactor;
	this.origScheme = origScheme;
	this.foregroundColor = (this.foregroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(this.foregroundShiftColor,
					origScheme.getForegroundColor(), this.foregroundShiftFactor)
			: origScheme.getForegroundColor();
	shiftByBrightness = shiftByBrightness && (this.backgroundShiftColor != null);
	Color ultraDarkToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getUltraDarkColor())
			: this.backgroundShiftColor;
	this.mainUltraDarkColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(ultraDarkToShiftTo,
					origScheme.getUltraDarkColor(), this.backgroundShiftFactor)
			: origScheme.getUltraDarkColor();
	Color darkToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getDarkColor())
			: this.backgroundShiftColor;
	this.mainDarkColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(darkToShiftTo,
					origScheme.getDarkColor(), this.backgroundShiftFactor)
			: origScheme.getDarkColor();
	Color midToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getMidColor())
			: this.backgroundShiftColor;
	this.mainMidColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(midToShiftTo,
					origScheme.getMidColor(), this.backgroundShiftFactor)
			: origScheme.getMidColor();
	Color lightToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getLightColor())
			: this.backgroundShiftColor;
	this.mainLightColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(lightToShiftTo,
					origScheme.getLightColor(), this.backgroundShiftFactor)
			: origScheme.getLightColor();
	Color extraLightToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getExtraLightColor())
			: this.backgroundShiftColor;
	this.mainExtraLightColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(extraLightToShiftTo,
					origScheme.getExtraLightColor(), this.backgroundShiftFactor)
			: origScheme.getExtraLightColor();
	Color ultraLightToShiftTo = shiftByBrightness
			? SubstanceColorUtilities.deriveByBrightness(this.backgroundShiftColor,
					origScheme.getUltraLightColor())
			: this.backgroundShiftColor;
	this.mainUltraLightColor = (this.backgroundShiftColor != null)
			? SubstanceColorUtilities.getInterpolatedColor(ultraLightToShiftTo,
					origScheme.getUltraLightColor(), this.backgroundShiftFactor)
			: origScheme.getUltraLightColor();
}
 
Example #28
Source File: TimelineBodyPanel.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static Color getEmptyFrameColor() {
    return SubstanceColorUtilities.getLighterColor(getControlColor(), 0.7);
}
 
Example #29
Source File: SubstanceLatchWatermark.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Draws the specified portion of the watermark image.
 *
 * @param skin      Skin to use for painting the watermark.
 * @param graphics  Graphic context.
 * @param x         the <i>x</i> coordinate of the watermark to be drawn.
 * @param y         The <i>y</i> coordinate of the watermark to be drawn.
 * @param width     The width of the watermark to be drawn.
 * @param height    The height of the watermark to be drawn.
 * @param isPreview Indication whether the result is a preview image.
 * @return Indication whether the draw succeeded.
 */
private boolean drawWatermarkImage(SubstanceSkin skin, Graphics2D graphics,
        int x, int y, int width, int height, boolean isPreview) {
    Color stampColorDark = null;
    Color stampColorAll = null;
    SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
    if (isPreview) {
        stampColorDark = scheme.isDark() ? Color.white : Color.black;
        stampColorAll = Color.lightGray;
    } else {
        stampColorDark = scheme.getWatermarkDarkColor();
        stampColorAll = scheme.getWatermarkStampColor();
    }

    Color c1 = stampColorDark;
    Color c2 = SubstanceColorUtilities.getInterpolatedColor(stampColorDark,
            stampColorAll, 0.5);
    graphics.setColor(stampColorAll);
    graphics.fillRect(0, 0, width, height);

    int dimension = 12;
    BufferedImage tile = NeonCortex.getBlankUnscaledImage(dimension, dimension);
    GeneralPath latch1 = new GeneralPath();
    latch1.moveTo(0.45f * dimension, 0);
    latch1.quadTo(0.45f * dimension, 0.45f * dimension, 0.05f * dimension, 0.45f * dimension);
    latch1.quadTo(0.15f * dimension, 0.15f * dimension, 0.45f * dimension, 0);
    this.drawLatch(tile, latch1, c1, c2);

    GeneralPath latch2 = new GeneralPath();
    latch2.moveTo(0.55f * dimension, 0.55f * dimension);
    latch2.quadTo(0.75f * dimension, 0.4f * dimension, dimension, dimension);
    latch2.quadTo(0.4f * dimension, 0.75f * dimension, 0.5f * dimension, 0.5f * dimension);
    this.drawLatch(tile, latch2, c1, c2);

    for (int row = 0; row < height; row += dimension) {
        for (int col = 0; col < width; col += dimension) {
            graphics.drawImage(tile, x + col, y + row, null);
        }
    }
    return true;
}
 
Example #30
Source File: SubstanceMosaicWatermark.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Draws the specified portion of the watermark image.
 *
 * @param skin      Skin to use for painting the watermark.
 * @param graphics  Graphic context.
 * @param x         the <i>x</i> coordinate of the watermark to be drawn.
 * @param y         The <i>y</i> coordinate of the watermark to be drawn.
 * @param width     The width of the watermark to be drawn.
 * @param height    The height of the watermark to be drawn.
 * @param isPreview Indication whether the result is a preview image.
 * @return Indication whether the draw succeeded.
 */
private boolean drawWatermarkImage(SubstanceSkin skin, Graphics2D graphics,
        int x, int y, int width, int height, boolean isPreview) {
    int sqDim = 7;
    int sqGap = 2;
    int cellDim = sqDim + sqGap;

    SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
    int rows = height / cellDim;
    int columns = width / cellDim;
    for (int col = 0; col <= columns; col++) {
        for (int row = 0; row <= rows; row++) {
            double val = isPreview ? Math.abs(Math.sin((1 + col + columns
                    * row))) : Math.random();
            int delta = isPreview ? (int) (150.0 * val)
                                  : (int) (50.0 * val);
            int alpha = 0;
            if (isPreview) {
                alpha = 50 + delta;
            } else {
                if (scheme.isDark())
                    alpha = 50 + delta * 3 / 2;
                else
                    alpha = 25 + delta;
            }
            alpha = Math.min(alpha, 255);
            Color stampColor = null;
            if (isPreview) {
                stampColor = scheme.isDark() ? Color.lightGray
                                             : Color.darkGray;
                stampColor = SubstanceColorUtilities.getAlphaColor(
                        stampColor, alpha);
            } else {
                stampColor = SubstanceColorUtilities.getAlphaColor(scheme
                        .getWatermarkStampColor(), alpha);
            }
            graphics.setColor(stampColor);
            graphics.fillRect(x + col * cellDim, y + row * cellDim, sqDim,
                    sqDim);
        }
    }
    return true;
}