-
-
Save diamondobama/45ef7a37ca028f1a9234 to your computer and use it in GitHub Desktop.
A background painter that puts a circle in the background of a component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BackgroundPainter p = new BackgroundPainter(cmp) { | |
@Override | |
public void paint(Graphics g, Rectangle rect) { | |
boolean antiAliased = g.isAntiAliased(); | |
g.setAntiAliased(true); | |
int r = Math.min(rect.getWidth(), rect.getHeight())/2; | |
int x = rect.getX() + rect.getWidth()/2 - r; | |
int y = rect.getY() + rect.getHeight()/2 - r; | |
switch (style) { | |
case CircleButtonStrokedDark: | |
case CircleButtonStrokedLight: { | |
if (cmp.getStyle().getBgTransparency() != 0) { | |
int alpha = cmp.getStyle().getBgTransparency(); | |
if (alpha <0) { | |
alpha = 0xff; | |
} | |
g.setColor(cmp.getStyle().getBgColor()); | |
g.setAlpha(alpha); | |
g.fillArc(x, y, 2*r-1, 2*r-1, 0, 360); | |
g.setAlpha(0xff); | |
} | |
g.setColor(cmp.getStyle().getFgColor()); | |
g.drawArc(x, y, 2*r-1, 2*r-1, 0, 360); | |
break; | |
} | |
case CircleButtonFilledDark: | |
case CircleButtonFilledLight: | |
case CircleButtonTransparentDark: | |
case CircleButtonTransparentLight: { | |
int alpha = cmp.getStyle().getBgTransparency(); | |
if (alpha < 0) { | |
alpha = 0xff; | |
} | |
g.setAlpha(alpha); | |
g.setColor(cmp.getStyle().getBgColor()); | |
g.fillArc(x, y, 2*r, 2*r, 0, 360); | |
g.setAlpha(0xff); | |
break; | |
} | |
} | |
g.setAntiAliased(antiAliased); | |
} | |
}; | |
cmp.getAllStyles().setBgPainter(p); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment