Actions

CustomEdge.java.wp

From Santa Fe Institute Events Wiki

Revision as of 22:41, 22 June 2006 by Seoc (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

WikiPeerCode

/*
 * CustomEdge.java
 *
 * Created on January 22, 2005, 5:55 PM
 * Modified on June 19 2006, 08:50 by Jack
 * Modified June 22, 2006 00:16 by Andrew
 * Modified June 22, 2006 16:40 by Jack
 *
 * This class is for the edges in a netwok
 * It points from a voter to the subject
 */

package RepMod;
import java.awt.Color;
import uchicago.src.sim.gui.ColorMap;

import uchicago.src.sim.gui.DrawableEdge;
import uchicago.src.sim.gui.SimGraphics;
import uchicago.src.sim.network.DefaultEdge;
import uchicago.src.sim.network.Node;
/**
 *
 * @author Jack Waddell
 */

// DefaultEdge gives us the standard edge methods
// DrawableEdge lets us draw it in the GUI
public class CustomEdge extends DefaultEdge implements DrawableEdge {
    //*************************************************************
    // Static Parameters

    // These are for drawing the edge in GUI
    public static GUIModel          guiModel = null;
    public static ColorMap          redColorMap, blueColorMap;
    public static final int         colorMapSize = 64;
    public static final int         colorMapMax = colorMapSize - 1;

    //***********************************************************
    //Instance parameters
    
    private Color  color = Color.red;  // Edge color
    //public  int    vote = 0;
		public double vote = 0; // AS for [0-1] voting
    public  double opinion = 0.5;

    //***********************************************************
    // Methods

    //////////////////////////////////////////////////
    // Constructor
    public CustomEdge() {
    }
    
    //////////////////////////////////////////////////
    // Constructor (overloaded)
    // Inputs: Node from, the (generic class) Node from which the edge emerges
    //         Node to, the (generic) Node to which the edge points
    public CustomEdge(Node from, Node to) {
        super(from, to, "");   // Calls DefaultEdge constructor
    }
    

    
    ////////////////////////////////////////////////////////
    // draw
    // Inputs: SimGraphics g
    //         int fromX, toX, fromY, toY
    // Outputs: none
    // Required to implement DrawableEdge.
    public void draw(SimGraphics g, int fromX, int toX, int fromY, int toY) {
        g.drawDirectedLink(color, fromX, toX, fromY, toY);
    }


    //getters and setters
    public void setColor(Color c) {color = c;}
    public Color getColor() {return color;}

    //public void setVote(int i) {vote = i;}
    //public int  getVote() {return vote;}
		public void setVote(double i) {vote = i;}
    public double  getVote() {return vote;}


    public void setOpinion(double i) {opinion = i;}
    public double getOpinion() {return opinion;}


    //******************************************************
    // Static Methods

    
    ////////////////////////////////////////////////////
    // setUpEdgeDrawing
    // Inputs: GUIModel m, a pointer to the GUIModel instance
    // Outputs: none
    // Prepares the edge to be drawn in the GUI
    public static void setUpEdgeDrawing (GUIModel m) {
	//System.out.printf("Setting up Edge Color Map\n");
	guiModel = m;
	redColorMap = new ColorMap();
	double minRed = 0.5;
	
	for (int i = 0; i < colorMapSize; i++){
	    double fracR = minRed + ( (1.0-minRed)*i/colorMapMax );
	    fracR = 1.0 + minRed - fracR;
	    //System.out.printf("Edge Color Map: i = %d, fR = %f\n", i, fracR);
	    redColorMap.mapColor(i, fracR, 0, 0);		   
	}


	blueColorMap = new ColorMap();
	double minBlue = 0.5;
	for (int i = 0; i < colorMapSize; i++){
	    double fracB = minBlue + ( (1.0-minBlue)*i/colorMapMax );
	    fracB = 1.0 + minBlue - fracB;
	    //System.out.printf("Edge Color Map: i = %d, fR = %f\n", i, fracR);
	    blueColorMap.mapColor(i, 0, 0, fracB);		   
	}
    }
}