All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.actelion.research.gui.dock.ShadowBorder Maven / Gradle / Ivy

There is a newer version: 2024.11.2
Show newest version
package com.actelion.research.gui.dock;

import com.actelion.research.gui.hidpi.HiDPIHelper;
import com.actelion.research.util.ColorHelper;

import javax.swing.border.AbstractBorder;
import java.awt.*;

public class ShadowBorder extends AbstractBorder {
    private static final long serialVersionUID = 0x20070807;

    private static int sBorderWidth,sThinSize;
    private Insets mInsets;
    private Color mColor;

    /**
     * Creates a border with a grey 1 pixel line on left and top
     * and a 3 pixel (scaled to Hi-dpi factor) wide shadow on right and bottom.
     * Insets are as large as needed for the drawn border.
     */
    public ShadowBorder() {
    	mInsets = new Insets(thinSize(), thinSize(), shadowSize(), shadowSize());
    	}

	public static int thinSize() {
		if (sThinSize == 0)
			sThinSize = HiDPIHelper.scale(1);

		return sThinSize;
		}

	public static int shadowSize() {
    	if (sBorderWidth == 0)
    		sBorderWidth = HiDPIHelper.scale(3);

    	return sBorderWidth;
		}

	public void setColor(Color c) {
    	mColor = c;
		}

    /**
     * Creates a border with a grey 1 pixel line on left and top
     * and a 3 pixel wide shadow on right and bottom.
     * Insets can be specified to be larger than the drawn border,
     * which allows to adjust the spacing outside the drawn border.
     */
    public ShadowBorder(int top, int left, int bottom, int right) {
    	mInsets = new Insets(HiDPIHelper.scale(top), HiDPIHelper.scale(left), HiDPIHelper.scale(bottom), HiDPIHelper.scale(right));
    	}

    public Insets getBorderInsets(Component c) {
        return mInsets;
        }

    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    	super.paintBorder(c, g, x, y, w, h);

    	Color[] shadow = new Color[shadowSize()];
        shadow[0] = mColor != null ? mColor : c.getBackground().darker();
        Color parentBG = c.getParent().getBackground();
        for (int i=1; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy