use of com.github.weisj.darklaf.util.graphics.GraphicsContext in project darklaf by weisJ.
the class DarkToolTipUI method paint.
@Override
public void paint(final Graphics g, final JComponent c) {
if (getTipText().isEmpty()) {
return;
}
boolean isPlain = style == ToolTipStyle.PLAIN;
if (animationScheduled) {
startAnimation();
} else {
Window window = DarkUIUtil.getWindow(c);
if (window != null) {
if (window.getOpacity() != 1 && !transparencySupported(window)) {
window.setOpacity(1);
}
}
}
GraphicsContext context = GraphicsUtil.setupAntialiasing(g);
g.setColor(c.getBackground());
if (!isPlain && c.getBorder() instanceof DarkTooltipBorder) {
for (Shape shape : ((DarkTooltipBorder) c.getBorder()).getBackgroundShapes(c, c.getWidth(), c.getHeight())) {
((Graphics2D) g).fill(shape);
}
} else {
PaintUtil.fillRect(g, 0, 0, c.getWidth(), c.getHeight());
}
paintText(g, c);
context.restore();
}
use of com.github.weisj.darklaf.util.graphics.GraphicsContext in project darklaf by weisJ.
the class DarkRadioButtonUI method paint.
@Override
// We're not calling the super implementation
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
public void paint(final Graphics g2d, final JComponent c) {
Graphics2D g = (Graphics2D) g2d;
AbstractButton b = (AbstractButton) c;
g.setFont(c.getFont());
FontMetrics fm = SwingUtil.getFontMetrics(c, g);
paintBackground(c, g);
GraphicsContext config = GraphicsUtil.setupStrokePainting(g);
Icon icon = getIconBullet(b);
if (icon != null) {
icon.paintIcon(c, g, iconRect.x, iconRect.y);
} else {
Icon radioIcon = getStateIcon(b);
if (radioIcon != null) {
radioIcon.paintIcon(c, g, iconRect.x, iconRect.y);
}
}
config.restore();
if (displayString != null) {
paintText(g, b, textRect, displayString, fm, getDisabledTextColor());
}
}
use of com.github.weisj.darklaf.util.graphics.GraphicsContext in project darklaf by weisJ.
the class DarkHighlightPainter method paintLayer.
@Override
public Shape paintLayer(final Graphics g, final int offs0, final int offs1, final Shape bounds, final JTextComponent c, final View view) {
if (!enabled)
return bounds;
color = (Color) view.getAttributes().getAttribute(StyleConstantsEx.SelectedForeground);
if (color == null) {
color = StyleConstants.getForeground(view.getAttributes());
}
boolean customColor = color != null;
if (color == null) {
color = c.getSelectedTextColor();
}
boolean isForeground = Objects.equals(color, c.getForeground());
customColor = customColor || isForeground;
wrapper.setColor(color);
wrapper.setCustomForeground(!isForeground);
Graphics2D g2d = (Graphics2D) g;
GraphicsContext context = GraphicsUtil.setupStrokePainting(g2d);
if (getAlpha() < 1.0f) {
g2d.setComposite(getAlphaComposite());
}
setupColor((Graphics2D) g, c, bounds);
Shape dirtyShape;
boolean ltr = isLeftTorRight(c);
boolean rounded = ltr && isRounded();
boolean lineExtension = ltr && isLineExtendingEnabled();
if (lineExtension || rounded) {
dirtyShape = paintRoundedLayer(g2d, c, offs0, offs1, context, rounded, lineExtension, false);
// everything is visible.
if (lineExtension) {
if (lastSelEnd != c.getSelectionEnd() || lastSelStart != c.getSelectionStart()) {
lastSelEnd = c.getSelectionEnd();
lastSelStart = c.getSelectionStart();
repaintCount = 1;
}
if (repaintCount > 0) {
if (customColor) {
c.repaint();
} else {
Rectangle repaintBounds = dirtyShape.getBounds();
repaintBounds.grow(10, 10);
c.repaint(repaintBounds);
}
repaintCount--;
}
}
} else {
Color oldColor = wrapper.getColor();
wrapper.setColor(g.getColor());
dirtyShape = super.paintLayer(g, offs0, offs1, bounds, c, view);
wrapper.setColor(oldColor);
}
context.restore();
return dirtyShape;
}
use of com.github.weisj.darklaf.util.graphics.GraphicsContext in project darklaf by weisJ.
the class DarkTooltipBorder method paintBorder.
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
if (c instanceof JToolTip && ((JToolTip) c).getTipText() == null)
return;
GraphicsContext context = new GraphicsContext(g);
if (isPlain(c)) {
g.setColor(bubbleBorder.getColor());
PaintUtil.drawRect(g, x, y, width, height, 1);
return;
}
Insets ins = shadowBorder.getBorderInsets(c);
adjustInsets(ins);
Area innerArea = bubbleBorder.getBubbleArea(x + ins.left, y + ins.top, width - ins.left - ins.right, height - ins.top - ins.bottom, bubbleBorder.getThickness());
if (paintShadow) {
paintShadow(c, g, x, y, width, height, innerArea);
}
Area outerArea = bubbleBorder.getBubbleArea(x + ins.left, y + ins.top, width - ins.left - ins.right, height - ins.top - ins.bottom, 0);
outerArea.subtract(innerArea);
bubbleBorder.paintBorder(g, outerArea);
context.restore();
}
use of com.github.weisj.darklaf.util.graphics.GraphicsContext in project darklaf by weisJ.
the class DarkTableHeaderUI method paint.
@Override
public void paint(final Graphics g2, final JComponent c) {
final Graphics2D g = (Graphics2D) g2;
final GraphicsContext config = new GraphicsContext(g);
int x = 0;
int y = 0;
int h = c.getHeight();
int w = c.getWidth();
g.setColor(getHeaderBackground());
g.fillRect(x, y, w, h);
if (header.getColumnModel().getColumnCount() <= 0) {
return;
}
boolean ltr = header.getComponentOrientation().isLeftToRight();
Rectangle clip = g.getClipBounds();
Point leftClip = clip.getLocation();
Point rightCip = new Point(clip.x + clip.width - 1, clip.y);
TableColumnModel cm = header.getColumnModel();
int cMin = Math.max(header.columnAtPoint(ltr ? leftClip : rightCip), 0);
int cMax = header.columnAtPoint(ltr ? rightCip : leftClip);
// Replace this with the index of the last column.
if (cMax == -1) {
cMax = cm.getColumnCount() - 1;
}
Rectangle bounds = c.getVisibleRect();
Point left = bounds.getLocation();
Point right = new Point(bounds.x + bounds.width - 1, bounds.y);
int cMinVisible = Math.max(header.columnAtPoint(ltr ? left : right), 0);
int cMaxVisible = header.columnAtPoint(ltr ? right : left);
if (cMaxVisible == -1) {
cMaxVisible = cm.getColumnCount() - 1;
}
Color borderColor = c.getBorder() instanceof DarkTableScrollPaneBorder ? ((DarkTableScrollPaneBorder) c.getBorder()).getBorderColor() : getBorderColor();
g.setColor(borderColor);
TableColumn draggedColumn = header.getDraggedColumn();
Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
paintCells(g, h, ltr, cm, cMin, cMax, cMinVisible, cMaxVisible, borderColor, draggedColumn, cellRect);
// Paint the dragged column if we are dragging.
if (draggedColumn != null) {
paintDraggedArea(g, ltr, cMin, cMax, borderColor, draggedColumn);
}
// Remove all components in the rendererPane.
rendererPane.removeAll();
config.restore();
/*
* If the table is in a scroll pane which uses buffer backed viewports scrolling leads to the
* previously last cell missing part of its border. We manually repaint it to prevent the appearance
* of joint cells.
*/
if (lastMaxVisible != cMaxVisible) {
if (lastMaxVisible >= 0) {
Rectangle r = header.getHeaderRect(lastMaxVisible);
SwingUtilities.invokeLater(() -> header.repaint(r));
}
lastMaxVisible = cMaxVisible;
}
}
Aggregations