2009-05-31 16:30:48 +00:00
|
|
|
|
2011-11-04 03:04:49 +00:00
|
|
|
package net.sourceforge.tuned.ui;
|
2009-05-31 16:30:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
import static java.awt.BasicStroke.*;
|
|
|
|
import static java.awt.RenderingHints.*;
|
|
|
|
|
|
|
|
import java.awt.BasicStroke;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.Insets;
|
|
|
|
|
|
|
|
import javax.swing.border.Border;
|
|
|
|
|
|
|
|
|
2011-11-04 03:04:49 +00:00
|
|
|
public class DashedSeparator implements Border {
|
2009-05-31 16:30:48 +00:00
|
|
|
|
|
|
|
private final int height;
|
|
|
|
private final int dash;
|
|
|
|
|
|
|
|
private final Color foreground;
|
|
|
|
private final Color background;
|
|
|
|
|
2011-11-04 03:04:49 +00:00
|
|
|
|
2009-05-31 16:30:48 +00:00
|
|
|
public DashedSeparator(int height, int dash, Color foreground, Color background) {
|
|
|
|
this.height = height;
|
|
|
|
this.dash = dash;
|
|
|
|
this.foreground = foreground;
|
|
|
|
this.background = background;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Insets getBorderInsets(Component c) {
|
|
|
|
return new Insets(0, 0, height, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBorderOpaque() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
|
|
|
Graphics2D g2d = (Graphics2D) g.create(x, h - this.height, w, h);
|
|
|
|
|
|
|
|
// fill background
|
|
|
|
g2d.setPaint(background);
|
|
|
|
g2d.fillRect(0, 0, w, h);
|
|
|
|
|
|
|
|
// draw dashed line
|
|
|
|
g2d.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
|
|
|
|
g2d.setColor(foreground);
|
|
|
|
g2d.setStroke(new BasicStroke(1, CAP_ROUND, JOIN_ROUND, 1, new float[] { dash }, 0));
|
|
|
|
|
|
|
|
g2d.drawLine(dash, this.height / 2, w - dash, this.height / 2);
|
|
|
|
|
|
|
|
g2d.dispose();
|
|
|
|
}
|
|
|
|
}
|