iconx.java

来自「一款即时通讯软件」· Java 代码 · 共 52 行

JAVA
52
字号
package edu.ou.kmi.buddyspace.utils;

import java.awt.*;
import javax.swing.*;

/**
 * An Icon that paint another icon plus extra things (e.g. emphasis)
 * @author Chris Denham
 * @version 1.0
 */

public class IconX implements Icon {

    private boolean emphasis = true;
    private int width;
    private int height;
    public boolean getEmphasis() { return emphasis;  }
    public void setEmphasis(boolean emphasis) { this.emphasis = emphasis; }

    private Icon icon = null;

    public IconX(Icon icon) {
        this.icon = icon;
        width = icon.getIconWidth() + 6;
        height = icon.getIconHeight() + 6;
        // This ensures size rounded to next lowest odd number
        // to prevent problems with concentric drawOval operations.
        width += width % 2 - 1;
        height += height % 2 - 1;
    }

    public Icon getIcon() { return icon; }
    public void setIcon(Icon icon) { this.icon = icon; }

    public int getIconWidth() { return width; }
    public int getIconHeight() { return height; }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        icon.paintIcon(c, g, x + 3, y + 3);
        if (emphasis) {
            Color oldColor = g.getColor();
            int w = width - 1, h = height - 1;
            g.setColor(java.awt.Color.blue);
            g.drawOval(x + 0, y + 0, w - 0, h - 0);
            g.drawOval(x + 1, y + 1, w - 2, h - 2);
            //g.drawOval(x + 2, y + 2, w - 4, h - 4);
            g.setColor(oldColor);
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?