001 /*
002 * $Id: ColumnControlIcon.java 2737 2008-02-20 17:52:44Z 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
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 import 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 */
040 public 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 public int getIconWidth() {
049 return width;
050 }
051
052 public int getIconHeight() {
053 return height;
054 }
055
056 public void paintIcon(Component c, Graphics g, int x, int y) {
057 Color color = c.getForeground();
058 g.setColor(color);
059
060 // draw horizontal lines
061 g.drawLine(x, y, x+8, y);
062 g.drawLine(x, y+2, x+8, y+2);
063 g.drawLine(x, y+8, x+2, y+8);
064
065 // draw vertical lines
066 g.drawLine(x, y+1, x, y+7);
067 g.drawLine(x+4, y+1, x+4, y+4);
068 g.drawLine(x+8, y+1, x+8, y+4);
069
070 // draw arrow
071 g.drawLine(x+3, y+6, x+9, y+6);
072 g.drawLine(x+4, y+7, x+8, y+7);
073 g.drawLine(x+5, y+8, x+7, y+8);
074 g.drawLine(x+6, y+9, x+6, y+9);
075
076 }
077
078 public static void main(String args[]) {
079 JFrame frame = new JFrame();
080 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
081 JLabel label = new JLabel(new ColumnControlIcon());
082 frame.getContentPane().add(BorderLayout.CENTER, label);
083 frame.pack();
084 frame.setVisible(true);
085 }
086
087 }