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.Arrow;
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 ArrowRenderer implements GBasicCellRenderer<Arrow> {
016    
017        public Component getRendererComponent(final Arrow arrow) {
018            JPanel p = new JPanel() {
019                /**
020                 *
021                 */
022                private static final long serialVersionUID = -5698778092356962429L;
023    
024                @Override
025                public void paint(Graphics g) {
026                    super.paint(g);
027                    Graphics2D gg = ((Graphics2D) g);
028                    int h = getHeight();
029                    gg.translate(h, h / 2);
030                    arrow.paintArrow(gg, h, h);
031                    gg.drawString(arrow.getName(), 3, 5);
032                }
033            };
034            p.setPreferredSize(new Dimension(100, Math.max(p.getHeight(), 20)));
035            p.setBackground(Color.white);
036            return p;
037    
038        }
039    }