001/*
002 * $Id: ColumnControlIcon.java 3927 2011-02-22 16:34:11Z kleopatra $
003 *
004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 * 
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 * 
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020 */
021
022package org.jdesktop.swingx.icon;
023
024import java.awt.BorderLayout;
025import java.awt.Color;
026import java.awt.Component;
027import java.awt.Graphics;
028
029import javax.swing.Icon;
030import javax.swing.JFrame;
031import javax.swing.JLabel;
032import javax.swing.plaf.UIResource;
033
034/**
035 * Icon class for rendering icon which indicates user control of
036 * column visibility.
037 * @author Amy Fowler
038 * @version 1.0
039 */
040public class ColumnControlIcon implements Icon, UIResource {
041    private int width = 10;
042    private int height = 10;
043
044    /** TODO: need to support small, medium, large */
045    public ColumnControlIcon() {
046    }
047
048    @Override
049    public int getIconWidth() {
050        return width;
051    }
052
053    @Override
054    public int getIconHeight() {
055        return height;
056    }
057
058    @Override
059    public void paintIcon(Component c, Graphics g, int x, int y) {
060        Color color = c.getForeground();
061        g.setColor(color);
062
063        // draw horizontal lines
064        g.drawLine(x, y, x+8, y);
065        g.drawLine(x, y+2, x+8, y+2);
066        g.drawLine(x, y+8, x+2, y+8);
067
068        // draw vertical lines
069        g.drawLine(x, y+1, x, y+7);
070        g.drawLine(x+4, y+1, x+4, y+4);
071        g.drawLine(x+8, y+1, x+8, y+4);
072
073        // draw arrow
074        g.drawLine(x+3, y+6, x+9, y+6);
075        g.drawLine(x+4, y+7, x+8, y+7);
076        g.drawLine(x+5, y+8, x+7, y+8);
077        g.drawLine(x+6, y+9, x+6, y+9);
078
079    }
080
081    public static void main(String args[]) {
082        JFrame frame = new JFrame();
083        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
084        JLabel label = new JLabel(new ColumnControlIcon());
085        frame.getContentPane().add(BorderLayout.CENTER, label);
086        frame.pack();
087        frame.setVisible(true);  
088    }
089
090}