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.core.actions; 005 006 import graphlab.graph.graph.FastRenderer; 007 import graphlab.graph.graph.GraphModel; 008 import graphlab.ui.components.gpropertyeditor.GBasicCellRenderer; 009 010 import javax.swing.*; 011 import java.awt.*; 012 013 /** 014 * author: Azin Azadi 015 * Email: 016 */ 017 public class GMergedColorRenderer implements GBasicCellRenderer { 018 public GMergedColorRenderer(boolean isvertex) { 019 this.isvertex = isvertex; 020 general = false; 021 } 022 023 public GMergedColorRenderer() { 024 general = true; 025 } 026 027 boolean isvertex; 028 boolean general = true; 029 030 public Component getRendererComponent(Object value) { 031 if (general) { 032 Integer i = (Integer) value; 033 JLabel l = new JLabel(i + ""); 034 l.setOpaque(true); 035 Color c = GraphModel.getColor(i); 036 l.setBackground(c); 037 l.setHorizontalAlignment(JLabel.CENTER); 038 return l; 039 } else 040 return getRendererComponent(value, isvertex); 041 } 042 043 public static Component getRendererComponent(Object value, boolean isVertex) { 044 Integer i = (Integer) value; 045 JLabel l = new JLabel(i + ""); 046 l.setOpaque(true); 047 Color c = GraphModel.getColor(i); 048 if (i == 0) { 049 if (isVertex) { 050 c = FastRenderer.defaultVertexColor; 051 } else 052 c = FastRenderer.defaultEdgeColor; 053 } 054 l.setBackground(c); 055 l.setHorizontalAlignment(JLabel.CENTER); 056 return l; 057 } 058 }