001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.plugins.main.ui;
005    
006    import graphlab.graph.old.GStroke;
007    import graphlab.ui.components.gpropertyeditor.GBasicCellRenderer;
008    
009    import javax.swing.*;
010    import java.awt.*;
011    
012    /**
013     * @author : Azin Azadi
014     */
015    public class GStrokeRenderer extends JPanel implements GBasicCellRenderer {
016        /**
017         *
018         */
019        private static final long serialVersionUID = 5000660721620223990L;
020    
021        @Override
022        public void paint(Graphics g) {
023            super.paint(g);
024            ((Graphics2D) g).setStroke(s.stroke);
025            int h = getHeight();
026            int w = getWidth();
027    //        g.setColor(lineColor);
028            g.drawLine(0, h / 2, w, h / 2);
029        }
030    
031    //    Color lineColor = Color.darkGray;
032    //    Color bgColor = Color.white;
033    
034        public GStrokeRenderer() {
035    //        setBackground(bgColor);
036        }
037    
038        public GStrokeRenderer(GStroke s) {
039            this.s = s;
040            setPreferredSize(new Dimension(50, 15));
041    //        setBackground(bgColor);
042        }
043    
044        GStroke s;
045    
046        public Component getRendererComponent(Object value) {
047            s = (GStroke) value;
048            if (s.equals(GStroke.empty)) {
049                return new JLabel("Empty");
050            }
051            return new GStrokeRenderer(s);
052        }
053    }