Dynamic Custom Graphics Example 1: Gradient Bar

   1 public class GradientRectangleCustomGraphics extends AbstractCyCustomGraphics {
   2 
   3         private static final String NAME = "Gradient Round Rectangle";
   4         
   5         private static final String WIDTH = "Width";
   6         private static final String HEIGHT = "Height";
   7         private static final String COLOR1 = "Color 1";
   8         private static final String COLOR2 = "Color 2";
   9         
  10         private final CustomGraphicsProperty<Float> w;
  11         private final CustomGraphicsProperty<Float> h;
  12         private final CustomGraphicsProperty<Color> c1;
  13         private final CustomGraphicsProperty<Color> c2;
  14         
  15 
  16         public GradientRectangleCustomGraphics() {
  17                 super(NAME);
  18                 w = new CustomGraphicsPropertyImpl<Float>(WIDTH, 60f);
  19                 h = new CustomGraphicsPropertyImpl<Float>(HEIGHT, 150f);
  20                 c1 = new CustomGraphicsPropertyImpl<Color>(COLOR1, Color.white);
  21                 c2 = new CustomGraphicsPropertyImpl<Color>(COLOR2, Color.darkGray);
  22                 
  23                 this.props.add(w);
  24                 this.props.add(h);
  25                 this.props.add(c1);
  26                 this.props.add(c2);
  27                 this.tags.add("vector image");
  28                 
  29                 buildCustomGraphics();
  30         }
  31 
  32         private void buildCustomGraphics() {
  33                 cgList.clear();
  34                 final GradientPaint gradient = new GradientPaint(w.getValue()/2, 0, c2.getValue(),
  35                                 w.getValue()/2, h.getValue()/2, c1.getValue());
  36                 final RoundRectangle2D bound = new RoundRectangle2D.Double(-w.getValue() / 2, -h.getValue() / 2,
  37                                                                                                                                         w.getValue(), h.getValue(), 20, 20);
  38                 final CustomGraphic cg = new CustomGraphic(bound, gradient, NodeDetails.ANCHOR_CENTER);
  39                 cgList.add(cg);
  40         }
  41 }
  42 

RFC_Custom_Graphics_VizMapper/Dynamic1 (last edited 2010-04-13 22:16:56 by KeiichiroOno)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux