2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.GradientPaint;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics2D;
|
2008-02-28 00:39:49 +00:00
|
|
|
import java.awt.Insets;
|
2007-12-23 19:28:04 +00:00
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
|
|
|
|
|
import javax.swing.DefaultListCellRenderer;
|
|
|
|
import javax.swing.JList;
|
|
|
|
import javax.swing.border.Border;
|
|
|
|
import javax.swing.border.CompoundBorder;
|
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import javax.swing.border.LineBorder;
|
|
|
|
|
|
|
|
|
|
|
|
public class FancyListCellRenderer extends DefaultListCellRenderer {
|
|
|
|
|
|
|
|
private Color gradientBeginColor;
|
|
|
|
|
|
|
|
private Color gradientEndColor;
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
private boolean highlightingEnabled;
|
|
|
|
|
2007-12-23 19:28:04 +00:00
|
|
|
private Border defaultBorder;
|
|
|
|
|
|
|
|
private Border selectedBorder;
|
|
|
|
|
|
|
|
private GradientStyle gradientStyle;
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
private boolean paintGradientEnabled;
|
|
|
|
|
|
|
|
private Insets padding;
|
2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
public FancyListCellRenderer() {
|
2008-02-28 00:39:49 +00:00
|
|
|
this(GradientStyle.TOP_TO_BOTTOM, false, new Insets(7, 7, 7, 7), new Insets(1, 1, 0, 1), null);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
public FancyListCellRenderer(int padding, Color selectedBorderColor, GradientStyle gradientStyle) {
|
|
|
|
this(gradientStyle, false, new Insets(padding, padding, padding, padding), new Insets(0, 0, 0, 0), selectedBorderColor);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
public FancyListCellRenderer(GradientStyle gradientStyle, boolean highlighting, Insets margin, Insets padding, Color selectedBorderColor) {
|
2007-12-23 19:28:04 +00:00
|
|
|
this.gradientStyle = gradientStyle;
|
2008-02-28 00:39:49 +00:00
|
|
|
this.padding = padding;
|
|
|
|
this.highlightingEnabled = highlighting;
|
|
|
|
|
|
|
|
Border marginBorder = new EmptyBorder(margin);
|
|
|
|
Border paddingBorder = new EmptyBorder(padding);
|
2007-12-23 19:28:04 +00:00
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
defaultBorder = marginBorder;
|
|
|
|
selectedBorder = marginBorder;
|
2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
if (selectedBorderColor != null) {
|
2008-02-28 00:39:49 +00:00
|
|
|
defaultBorder = new CompoundBorder(new EmptyBorder(1, 1, 1, 1), defaultBorder);
|
|
|
|
selectedBorder = new CompoundBorder(new LineBorder(selectedBorderColor, 1), selectedBorder);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
defaultBorder = new CompoundBorder(paddingBorder, defaultBorder);
|
|
|
|
selectedBorder = new CompoundBorder(paddingBorder, selectedBorder);
|
|
|
|
|
|
|
|
setOpaque(false);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void paintComponent(Graphics g) {
|
2008-02-28 00:39:49 +00:00
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
|
Rectangle2D shape = new Rectangle2D.Double(padding.left, padding.top, getWidth() - (padding.left + padding.right), getHeight() - (padding.top + padding.bottom));
|
|
|
|
|
|
|
|
if (highlightingEnabled) {
|
|
|
|
g2d.setPaint(getBackground());
|
|
|
|
g2d.fill(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paintGradientEnabled) {
|
2007-12-23 19:28:04 +00:00
|
|
|
GradientPaint gradient = gradientStyle.getGradientPaint(shape, gradientBeginColor, gradientEndColor);
|
2008-02-28 00:39:49 +00:00
|
|
|
|
2007-12-23 19:28:04 +00:00
|
|
|
g2d.setPaint(gradient);
|
|
|
|
g2d.fill(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.paintComponent(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
|
|
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
Color sc = list.getSelectionBackground();
|
|
|
|
|
|
|
|
if (highlightingEnabled) {
|
|
|
|
Color normalBg = list.getBackground();
|
|
|
|
Color highlightBg = new Color(sc.getRed(), sc.getGreen(), sc.getBlue(), 28);
|
|
|
|
|
|
|
|
if ((index % 2) == 0)
|
|
|
|
setBackground(highlightBg);
|
|
|
|
else
|
|
|
|
setBackground(normalBg);
|
|
|
|
}
|
2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
if (isSelected) {
|
2008-02-28 00:39:49 +00:00
|
|
|
setPaintGradientEnabled(true);
|
2007-12-23 19:28:04 +00:00
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
setGradientBeginColor(sc.brighter());
|
|
|
|
setGradientEndColor(sc);
|
2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
setBorder(selectedBorder);
|
|
|
|
} else {
|
2008-02-28 00:39:49 +00:00
|
|
|
setPaintGradientEnabled(false);
|
2007-12-23 19:28:04 +00:00
|
|
|
setBorder(defaultBorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Color getGradientBeginColor() {
|
|
|
|
return gradientBeginColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGradientBeginColor(Color gradientBeginColor) {
|
|
|
|
this.gradientBeginColor = gradientBeginColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Color getGradientEndColor() {
|
|
|
|
return gradientEndColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGradientEndColor(Color gradientEndColor) {
|
|
|
|
this.gradientEndColor = gradientEndColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GradientStyle getGradientStyle() {
|
|
|
|
return gradientStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGradientStyle(GradientStyle gradientStyle) {
|
|
|
|
this.gradientStyle = gradientStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
public boolean isPaintGradientEnabled() {
|
|
|
|
return paintGradientEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setPaintGradientEnabled(boolean gradientEnabled) {
|
|
|
|
this.paintGradientEnabled = gradientEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isHighlightingEnabled() {
|
|
|
|
return highlightingEnabled;
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 00:39:49 +00:00
|
|
|
public void setHighlightingEnabled(boolean highlightingEnabled) {
|
|
|
|
this.highlightingEnabled = highlightingEnabled;
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|