edu.uci.ics.jung.visualization3d.PluggableRenderContext Maven / Gradle / Ivy
/*
* Copyright (c) 2003, the JUNG Project and the Regents of the University of
* California All rights reserved.
*
* This software is open-source under the BSD license; see either "license.txt"
* or http://jung.sourceforge.net/license.txt for a description.
*/
package edu.uci.ics.jung.visualization3d;
import javax.media.j3d.Appearance;
import javax.media.j3d.LineArray;
import javax.media.j3d.Material;
import javax.media.j3d.Node;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import org.apache.commons.collections15.Transformer;
import org.apache.commons.collections15.functors.ConstantTransformer;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.geometry.Sphere;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Context;
import edu.uci.ics.jung.visualization.picking.PickedState;
/**
*/
@SuppressWarnings("unchecked")
public class PluggableRenderContext implements RenderContext {
protected Transformer edgeAppearanceTransformer;
protected Transformer,E>,Node> edgeShapeTransformer;
protected PickedState pickedEdgeState;
protected PickedState pickedVertexState;
protected Transformer vertexAppearanceTransformer;
protected Transformer vertexStringer = new ConstantTransformer(null);
protected Transformer vertexShapeTransformer;
public PluggableRenderContext() {
super();
Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f);
Color3f black = new Color3f(0,0,0);
Color3f white = new Color3f(1,1,1);
Color3f gray = new Color3f(.2f, .2f, .2f);
Color3f red = new Color3f(1, 0, 0);
Color3f yellow = new Color3f(0,1,1);
Material lightGrayMaterial = new Material(lightGray, black,
lightGray, white, 100.0f);
Material blackMaterial = new Material(lightGray, black,
black, lightGray, 10.0f);
Material whiteMaterial = new Material(white, white,
white, white, 100.0f);
Material grayMaterial = new Material(gray, black,
gray, gray, 100.0f);
Material redMaterial = new Material(red, black,
red, red, 100.0f);
Material yellowMaterial = new Material(yellow, black,
yellow, yellow, 100.0f);
final Appearance lightGrayLook = new Appearance();
lightGrayLook.setMaterial(lightGrayMaterial);
Appearance blackLook = new Appearance();
blackLook.setMaterial(blackMaterial);
Appearance whiteLook = new Appearance();
whiteLook.setMaterial(whiteMaterial);
Appearance grayLook = new Appearance();
grayLook.setMaterial(grayMaterial);
// grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
// grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
final Appearance redLook = new Appearance();
redLook.setMaterial(redMaterial);
final Appearance yellowLook = new Appearance();
yellowLook.setMaterial(yellowMaterial);
final Cylinder cylinder = new Cylinder(1, 1,
Cylinder.GENERATE_NORMALS |
Cylinder.ENABLE_GEOMETRY_PICKING,
26, 26, lightGrayLook);
final Sphere sphere = new Sphere(10,
Sphere.GENERATE_NORMALS |
Sphere.ENABLE_GEOMETRY_PICKING, redLook);
final Box box = new Box(10,10,10,
Box.GENERATE_NORMALS |
Box.ENABLE_GEOMETRY_PICKING,
redLook);
this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook);
this.edgeShapeTransformer = new Transformer,E>,Node>() {
public Node transform(Context,E> ec) {
LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
lineArray.setCoordinates(0, new Point3f[]{new Point3f(0,-.5f,0),new Point3f(0,.5f,0)});
lineArray.setColor(0, new Color3f(1,1,1));
lineArray.setColor(1, new Color3f(1,1,1));
Shape3D shape = new Shape3D();
shape.setGeometry(lineArray);
return shape;
// return new Cylinder(1, 1,
// Cylinder.GENERATE_NORMALS |
// Cylinder.ENABLE_GEOMETRY_PICKING,
// 26, 26, lightGrayLook);
}};
this.vertexAppearanceTransformer = new ConstantTransformer(redLook);
this.vertexShapeTransformer = new Transformer() {
public Node transform(V arg0) {
return new Sphere(10,
Sphere.GENERATE_NORMALS |
Sphere.ENABLE_GEOMETRY_PICKING|
Sphere.ENABLE_APPEARANCE_MODIFY, redLook);
}};
}
public Transformer getEdgeAppearanceTransformer() {
return edgeAppearanceTransformer;
}
public Transformer,E>, Node> getEdgeShapeTransformer() {
return edgeShapeTransformer;
}
public PickedState getPickedEdgeState() {
return pickedEdgeState;
}
public PickedState getPickedVertexState() {
return pickedVertexState;
}
public Transformer getVertexAppearanceTransformer() {
return vertexAppearanceTransformer;
}
public Transformer getVertexShapeTransformer() {
return vertexShapeTransformer;
}
public Transformer getVertexStringer() {
return vertexStringer;
}
public void setEdgeAppearanceTransformer(Transformer edgeAppearanceTransformer) {
this.edgeAppearanceTransformer = edgeAppearanceTransformer;
}
public void setEdgeShapeTransformer(Transformer,E>, Node> edgeShapeTransformer) {
this.edgeShapeTransformer = edgeShapeTransformer;
}
public void setPickedEdgeState(PickedState pickedEdgeState) {
this.pickedEdgeState = pickedEdgeState;
}
public void setPickedVertexState(PickedState pickedVertexState) {
this.pickedVertexState = pickedVertexState;
}
public void setVertexAppearanceTransformer(Transformer vertexAppearanceTransformer) {
this.vertexAppearanceTransformer = vertexAppearanceTransformer;
}
public void setVertexShapeTransformer(Transformer vertexShapeTransformer) {
this.vertexShapeTransformer = vertexShapeTransformer;
}
public void setVertexStringer(Transformer vertexStringer) {
this.vertexStringer = vertexStringer;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy