001 /*
002 * $Id: ColumnControlIcon.java,v 1.5 2006/05/14 08:19:44 dmouse Exp $
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
022 package org.jdesktop.swingx.icon;
023
024 import java.awt.BorderLayout;
025 import java.awt.Color;
026 import java.awt.Component;
027 import java.awt.Graphics;
028
029 import javax.swing.Icon;
030 import javax.swing.JFrame;
031 import javax.swing.JLabel;
032
033 /**
034 * Icon class for rendering icon which indicates user control of
035 * column visibility.
036 * @author Amy Fowler
037 * @version 1.0
038 */
039 public class ColumnControlIcon implements Icon {
040 private int width = 10;
041 private int height = 10;
042
043 /** TODO: need to support small, medium, large */
044 public ColumnControlIcon() {
045 }
046
047 public int getIconWidth() {
048 return width;
049 }
050
051 public int getIconHeight() {
052 return height;
053 }
054
055 public void paintIcon(Component c, Graphics g, int x, int y) {
056 Color color = c.getForeground();
057 g.setColor(color);
058
059 // draw horizontal lines
060 g.drawLine(x, y, x+8, y);
061 g.drawLine(x, y+2, x+8, y+2);
062 g.drawLine(x, y+8, x+2, y+8);
063
064 // draw vertical lines
065 g.drawLine(x, y+1, x, y+7);
066 g.drawLine(x+4, y+1, x+4, y+4);
067 g.drawLine(x+8, y+1, x+8, y+4);
068
069 // draw arrow
070 g.drawLine(x+3, y+6, x+9, y+6);
071 g.drawLine(x+4, y+7, x+8, y+7);
072 g.drawLine(x+5, y+8, x+7, y+8);
073 g.drawLine(x+6, y+9, x+6, y+9);
074
075 }
076
077 public static void main(String args[]) {
078 JFrame frame = new JFrame();
079 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
080 JLabel label = new JLabel(new ColumnControlIcon());
081 frame.getContentPane().add(BorderLayout.CENTER, label);
082 frame.pack();
083 frame.setVisible(true);
084 }
085
086 }