package de.memtext.icons; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JButton; public abstract class BasicIcon implements Icon { private int iconWidth = 16, iconHeight = 16; private Color color = Color.black; /** * @see javax.swing.Icon#getIconWidth() */ @Override public int getIconWidth() { return iconWidth; } /** * @see javax.swing.Icon#getIconHeight() */ @Override public int getIconHeight() { return iconHeight; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); if (c.isEnabled()) g.setColor(color); else g.setColor(Color.GRAY); myPaint(g); g.translate(-x, -y); } abstract void myPaint(Graphics g); void drawDoubleLine(Graphics g, int y) { if (y > getIconHeight() - 2) throw new IllegalArgumentException("can't draw that low"); g.drawLine(0, y, getIconWidth(), y); g.drawLine(0, y + 1, getIconWidth(), y + 1); } void drawArrowRight(Graphics g) { int midx = (int) Math.floor(getIconWidth() / 2); int midy = (int) Math.floor(getIconHeight() / 2); // mittellinie g.drawLine(0, midy - 1, getIconWidth(), midy - 1); g.drawLine(0, midy, getIconWidth(), midy); g.drawLine(0, midy + 1, getIconWidth(), midy + 1); g.drawLine(midx + 1, 1, getIconWidth(), midy - 1); g.drawLine(midx + 1, 2, getIconWidth(), midy); g.drawLine(midx + 1, getIconHeight() - 1, getIconWidth(), midy + 1); g.drawLine(midx + 1, getIconHeight() - 2, getIconWidth(), midy); } void drawArrowUp(Graphics g, int y) { int midx = (int) Math.floor(getIconWidth() / 2); int midy = (int) Math.floor(getIconHeight() / 2); g.drawLine(0, y + midy, midx, y); g.drawLine(midx, y, getIconWidth(), y + midy); g.drawLine(0, y + midy + 1, midx, y + 1); g.drawLine(midx, y + 1, getIconWidth(), y + midy + 1); } void drawArrowDown(Graphics g, int y) { int midx = (int) Math.floor(getIconWidth() / 2); int midy = (int) Math.floor(getIconHeight() / 2); g.drawLine(0, y, midx, midy + y); g.drawLine(midx, y + midy, getIconWidth(), y); g.drawLine(0, y + 1, midx, midy + y + 1); g.drawLine(midx, y + midy + 1, getIconWidth(), y + 1); } public static void main(String[] args) { de.memtext.widgets.MBFrame f = new de.memtext.widgets.MBFrame("test"); f.setCenter(new JButton("test", new ArrowRight())); f.pack(); f.show(); } public void setIconHeight(int i) { iconHeight = i; } public void setIconWidth(int i) { iconWidth = i; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } }