use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class SVGSVGElementImpl method draw.
/**
* {@inheritDoc}
*/
@Override
public void draw(final Graphics2D graphics) {
recalculateViewboxToViewportTransform();
boolean display = getDisplay();
float opacity = getOpacity();
if (display && opacity > 0) {
AffineTransform oldGraphicsTransform = graphics.getTransform();
Shape oldClip = graphics.getClip();
graphics.translate(viewport.getX(), viewport.getY());
if (opacity < 1) {
SVGSVGElement root = this;
float currentScale = root.getCurrentScale();
// create buffer to draw on
Shape shape = createShape(null);
AffineTransform screenCTM = getScreenCTM().getAffineTransform();
Shape transformedShape = screenCTM.createTransformedShape(shape);
Rectangle2D bounds = transformedShape.getBounds2D();
double xInc = bounds.getWidth() / 5;
double yInc = bounds.getHeight() / 5;
bounds.setRect(bounds.getX() - xInc, bounds.getY() - yInc, bounds.getWidth() + 2 * xInc, bounds.getHeight() + 2 * yInc);
int imageWidth = (int) (bounds.getWidth() * currentScale);
int imageHeight = (int) (bounds.getHeight() * currentScale);
if (imageWidth > 0 && imageHeight > 0) {
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D offGraphics = (Graphics2D) image.getGraphics();
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
offGraphics.setRenderingHints(hints);
if (currentScale != 1) {
offGraphics.scale(currentScale, currentScale);
}
offGraphics.translate(-bounds.getX(), -bounds.getY());
offGraphics.transform(screenCTM);
drawChildren(offGraphics);
Composite oldComposite = graphics.getComposite();
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
graphics.setComposite(ac);
AffineTransform imageTransform = AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY());
imageTransform.scale(1 / currentScale, 1 / currentScale);
try {
imageTransform.preConcatenate(screenCTM.createInverse());
} catch (NoninvertibleTransformException e) {
}
graphics.drawImage(image, imageTransform, null);
graphics.setComposite(oldComposite);
image.flush();
}
} else {
drawChildren(graphics);
}
graphics.setTransform(oldGraphicsTransform);
graphics.setClip(oldClip);
}
}
use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class GraphiteMenuUI method paintBackground.
/**
* {@inheritDoc}
*/
@Override
protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
JMenuItem b = (JMenuItem) c;
ButtonModel model = b.getModel();
if (c.getParent() instanceof JMenuBar) {
if (model.isRollover() || model.isArmed() || c instanceof JMenu && model.isSelected()) {
JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getMenuSelectionColors(), x, y, w, h);
}
if (model.isRollover() && !model.isSelected()) {
Color[] colArr = AbstractLookAndFeel.getTheme().getMenuSelectionColors();
Color frameColor = ColorHelper.darker(colArr[colArr.length - 1], 5);
g.setColor(frameColor);
g.drawRect(x, y, w - 1, h - 1);
}
} else {
if (model.isArmed() || c instanceof JMenu && model.isSelected()) {
JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getMenuSelectionColors(), x, y, w, h);
} else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
g2D.setComposite(alpha);
g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
g.fillRect(x, y, w, h);
g2D.setComposite(composite);
} else {
g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
g.fillRect(x, y, w, h);
}
}
if (menuItem.isSelected() && menuItem.isArmed()) {
g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
} else {
g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
}
}
use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class HiFiToggleButtonUI method paintText.
/**
* {@inheritDoc}
*/
@Override
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
ButtonModel model = b.getModel();
FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
int mnemIndex = b.getDisplayedMnemonicIndex();
int offs = 0;
if (model.isArmed() && model.isPressed()) {
offs = 1;
}
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
g2D.setComposite(alpha);
Color foreground = b.getForeground();
Color background = b.getBackground();
if (model.isPressed() && model.isArmed() || model.isSelected()) {
if (foreground instanceof ColorUIResource && background instanceof ColorUIResource) {
foreground = AbstractLookAndFeel.getTheme().getPressedForegroundColor();
}
}
if (!model.isEnabled()) {
foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
}
if (ColorHelper.getGrayValue(foreground) > 128) {
g2D.setColor(Color.black);
} else {
g2D.setColor(Color.white);
}
JTattooUtilities.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1);
g2D.setComposite(composite);
g2D.setColor(foreground);
JTattooUtilities.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent());
}
use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class HiFiTabbedPaneUI method paintText.
/**
* {@inheritDoc}
*/
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
Color backColor = tabPane.getBackgroundAt(tabIndex);
if (!(backColor instanceof UIResource)) {
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
return;
}
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
Graphics2D g2D = (Graphics2D) g;
Object savedRenderingHint = null;
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
}
v.paint(g, textRect);
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
}
} else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
g2D.setComposite(alpha);
Color fc = tabPane.getForegroundAt(tabIndex);
if (isSelected) {
fc = AbstractLookAndFeel.getTheme().getTabSelectionForegroundColor();
}
if (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex)) {
fc = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
}
if (ColorHelper.getGrayValue(fc) > 128) {
g2D.setColor(Color.black);
} else {
g2D.setColor(Color.white);
}
JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y + 1 + metrics.getAscent());
g2D.setComposite(composite);
g2D.setColor(fc);
JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
}
}
use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class CanvasRenderingImpl method setGlobalAlpha.
/**
* {@inheritDoc}
*/
@Override
public void setGlobalAlpha(Double globalAlpha) {
if (globalAlpha >= 0 && globalAlpha <= 1) {
Graphics2D graphics = createGraphics();
final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, globalAlpha.floatValue());
graphics.setComposite(composite);
}
}
Aggregations