class JColorBlackWhiteSwitcher extends JButton {

    private final static int ICON_WIDTH = 16;
    private final static int ICON_HEIGHT = 16;
    private final static Color DISABLED_BORDER = new Color(200, 200, 200);
    private final static Color DISABLED_FILL = new Color(220, 220, 220);
    public static String EVENT_COLOR = "color";
    private Color color;
    private boolean includeOpacity;

    public JColorBlackWhiteSwitcher(Color color) {
        this(color, false);
    }

    public JColorBlackWhiteSwitcher(Color originalColor, boolean includeOpacity) {
        this.includeOpacity = includeOpacity;
        this.color = originalColor;
        refreshIcon();
        /**
         * Right click action: choose color
         */
        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    Color newColor = ColorPicker.showDialog(WindowManager.getDefault().getMainWindow(), color,
                        JColorBlackWhiteSwitcher.this.includeOpacity);
                    if (newColor != null) {
                        setColor(newColor);
                    }
                }
            }
        });
        /**
         * Left click action: switch between white and black
         */
        addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!color.equals(Color.BLACK) && !color.equals(Color.WHITE)) {
                    //Color is not white or black. Set to white to be swithed un future clicks
                    setColor(Color.WHITE);
                } else {
                    setColor(new Color(0xffffff - color.getRGB()));//switch black-white
                }
            }
        });
    }

    private void refreshIcon() {<FILL_FUNCTION_BODY>}

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        if (color != this.color || (color != null && !color.equals(this.color))) {
            Color oldColor = this.color;
            this.color = color;
            firePropertyChange(EVENT_COLOR, oldColor, color);
            refreshIcon();
            repaint();
        }
    }

    public float[] getColorArray() {
        return new float[] {color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f,
            color.getAlpha() / 255f};
    }

    public void setIncludeOpacity(boolean includeOpacity) {
        this.includeOpacity = includeOpacity;
    }

    class ColorIcon implements Icon {

        @Override
        public int getIconWidth() {
            return ICON_WIDTH;
        }

        @Override
        public int getIconHeight() {
            return ICON_HEIGHT;
        }

        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            if (c.isEnabled()) {
                g.setColor(Color.BLACK);
                g.drawRect(x + 2, y + 2, ICON_WIDTH - 5, ICON_HEIGHT - 5);
                if (color != null) {
                    g.setColor(color);
                    g.fillRect(x + 3, y + 3, ICON_WIDTH - 6, ICON_HEIGHT - 6);
                }
            } else {
                g.setColor(DISABLED_BORDER);
                g.drawRect(x + 2, y + 2, ICON_WIDTH - 5, ICON_HEIGHT - 5);
                g.setColor(DISABLED_FILL);
                g.fillRect(x + 3, y + 3, ICON_WIDTH - 6, ICON_HEIGHT - 6);
            }
        }
    }
}

        if (color.equals(Color.WHITE)) {//White color, show a lightbulb on:
            setIcon(ImageUtilities.loadImageIcon("UIComponents/light-bulb.png", false));
        } else if (color.equals(Color.BLACK)) {//Black color, show a lightbulb off:
            setIcon(ImageUtilities.loadImageIcon("UIComponents/light-bulb-off.png", false));
        } else {
            setIcon(new ColorIcon());//Other color, show the color in a square as the icon
        }
    
<methods>public void <init>() ,public void <init>(javax.swing.Icon) ,public void <init>(java.lang.String) ,public void <init>(javax.swing.Action) ,public void <init>(java.lang.String, javax.swing.Icon) ,public javax.accessibility.AccessibleContext getAccessibleContext() ,public java.lang.String getUIClassID() ,public boolean isDefaultButton() ,public boolean isDefaultCapable() ,public void removeNotify() ,public void setDefaultCapable(boolean) ,public void updateUI() <variables>private static final java.lang.String uiClassID