/*
 * Copyright © 2026 Luis Andrés Lange <http://javacomm.net>
 *
 * The MIT Licence
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package net.javacomm.babelfish.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import javax.swing.border.AbstractBorder;



@SuppressWarnings("serial")
public class NimbusRoundedBorder extends AbstractBorder {

  private final Color base;

  public NimbusRoundedBorder(Color base) {
    this.base = base;
  }



  @Override
  public Insets getBorderInsets(Component c) {
    return new Insets(8, 8, 8, 8);
  }



  @Override
  public Insets getBorderInsets(Component c, Insets insets) {
    insets.set(8, 8, 8, 8);
    return insets;
  }



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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int arc = 14;

    // Nimbus-typische weiche Farbverläufe
    Color highlight = base.brighter();
    Color shadow = base.darker();

    // äußere weiche Linie
    g2.setColor(highlight);
    g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc);

    // innere Schattenlinie (für "etched" Effekt)
    g2.setColor(shadow);
    g2.drawRoundRect(x + 1, y + 1, w - 3, h - 3, arc - 2, arc - 2);

    // optional: ganz feiner innerer Glow (Nimbus-like)
    g2.setColor(new Color(255, 255, 255, 40));
    g2.drawRoundRect(x + 2, y + 2, w - 5, h - 5, arc - 4, arc - 4);

    g2.dispose();
  }
}