Actions

CustomEdge.java.wp

From Santa Fe Institute Events Wiki

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

/*

* CustomEdge.java
*
* Created on January 22, 2005, 5:55 PM
* Modified on June 13 2006
* 
* This class is for the edges in a netwok
*/

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
   //***********************************************************
   // 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
   }
   
   //////////////////////////////////////////////////
   // setColor
   // Inputs: Color c
   // Outputs: none
   // Sets edge's color to c, a Java color
   public void setColor(Color c) {
       color = c;
   }
   


   ////////////////////////////////////////////////////////
   // 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);
   }


   //******************************************************
   // 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); }

   }

}