package com.traxel.lumbermill.event;
import com.traxel.color.model.ScreenWheel;
import com.traxel.color.model.Wheel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
private static final int SIZE = 16;
private static final Wheel WHEEL = new ScreenWheel();
ImageIcon classIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/class.png"));
ImageIcon inheritedIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/inherited.png"));
ImageIcon throwAwayIconMenu = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/delete.png"));
ImageIcon throwAwayIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/deleteSmall.png"));
ImageIcon inheritMenuIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/inheritMenu.png"));
ImageIcon rootIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/package_folder.png"));
ImageIcon packageIcon = new ImageIcon(getClass().getResource("/de/cismet/beanmill/res/package.png"));
private final Severity _actual;
private final Severity _effective;
private boolean root = false;
private boolean leaf = false;
private boolean menu = false;
public (final Severity actual,
final Severity effective,
final boolean root,
final boolean leaf,
final boolean menu) {
_actual = actual;
_effective = effective;
this.menu = menu;
this.root = root;
this.leaf = leaf;
}
public static Color
getColor(
final Severity severity) {
if (Severity.INHERIT.equals(severity)) {
return Color.GRAY;
}
if (Severity.ALL.equals(severity)) {
return Color.WHITE;
}
if (Severity.DISABLED.equals(severity)) {
return Color.BLACK;
}
final int angle;
final Color color;
final float ratio;
final float adjustedLevel;
adjustedLevel = (float)(severity.getLevel() - 1);
ratio = adjustedLevel / 8f;
angle = (int)(ratio * 270f) + 30;
color = WHEEL.getBaseColor(angle);
return color;
}
return _actual;
}
return _effective;
}
@Override
return SIZE + 10;
}
@Override
return SIZE + 2;
}
@Override
public void paintIcon(
final Component parent,
final Graphics g,
final int x,
final int y) {
if (!menu) {
if (root) {
g.drawImage(rootIcon.getImage(), 0, 0, null);
} else {
if (leaf) {
g.drawImage(classIcon.getImage(), 0, 0, null);
} else {
g.drawImage(packageIcon.getImage(), 0, 0, null);
}
}
if (Severity.DISABLED_THROW_AWAY.equals(getEffective())) {
g.drawImage(throwAwayIcon.getImage(), 12, 7, null);
} else {
g.drawImage(createNiceOval(9, getColor(getEffective())), 12, 7, null);
}
if (Severity.INHERIT.equals(getActual())) {
g.drawImage(inheritedIcon.getImage(), 14, 2, null);
}
} else {
final Color bg = parent.getBackground();
final Color color = getColor(getEffective());
if (Severity.INHERIT.equals(getActual())) {
g.drawImage(inheritMenuIcon.getImage(), 1, 1, null);
}
if (Severity.DISABLED_THROW_AWAY.equals(getActual())) {
g.drawImage(throwAwayIconMenu.getImage(), 1, 1, null);
} else {
g.drawImage(createNiceOval(SIZE, color), 1, 1, null);
}
}
}
public static BufferedImage
createNiceOval(
final int dimension,
final Color color) {
final int ICON_DIMENSION = dimension;
final Color backgroundColor = color;
final BufferedImage image = new BufferedImage(ICON_DIMENSION, ICON_DIMENSION,
BufferedImage.TYPE_INT_ARGB);
for (int col = 0; col < ICON_DIMENSION; col++) {
for (int row = 0; row < ICON_DIMENSION; row++) {
image.setRGB(col, row, 0x0);
}
}
final Graphics2D graphics = (Graphics2D)image.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setColor(backgroundColor);
graphics.fillOval(0, 0, ICON_DIMENSION - 1, ICON_DIMENSION - 1);
final double id4 = ICON_DIMENSION / 4.0;
final double spotX = id4;
final double spotY = id4;
for (int col = 0; col < ICON_DIMENSION; col++) {
for (int row = 0; row < ICON_DIMENSION; row++) {
final double dx = col - spotX;
final double dy = row - spotY;
double dist = Math.sqrt((dx * dx) + (dy * dy));
if (dist > ICON_DIMENSION) {
dist = ICON_DIMENSION;
}
final int currColor = image.getRGB(col, row);
final int transp = (currColor >>> 24) & 0xFF;
final int oldR = (currColor >>> 16) & 0xFF;
final int oldG = (currColor >>> 8) & 0xFF;
final int oldB = (currColor >>> 0) & 0xFF;
final double coef = 0.9 - (0.9 * dist / ICON_DIMENSION);
final int dr = 255 - oldR;
final int dg = 255 - oldG;
final int db = 255 - oldB;
final int newR = (int)(oldR + (coef * dr));
final int newG = (int)(oldG + (coef * dg));
final int newB = (int)(oldB + (coef * db));
final int newColor = (transp << 24) | (newR << 16) | (newG << 8) | newB;
image.setRGB(col, row, newColor);
}
}
graphics.setColor(Color.black);
graphics.drawOval(0, 0, ICON_DIMENSION - 1, ICON_DIMENSION - 1);
return image;
}
}