All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.uci.ics.jung.visualization.PluggableRenderContext Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2003, The JUNG Authors
 * All rights reserved.
 * 
 * This software is open-source under the BSD license; see either "license.txt"
 * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
 */
package edu.uci.ics.jung.visualization;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;

import javax.swing.CellRendererPane;
import javax.swing.Icon;
import javax.swing.JComponent;

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Context;
import edu.uci.ics.jung.graph.util.DefaultParallelEdgeIndexFunction;
import edu.uci.ics.jung.graph.util.EdgeIndexFunction;
import edu.uci.ics.jung.graph.util.IncidentEdgeIndexFunction;
import edu.uci.ics.jung.visualization.decorators.ConstantDirectionalEdgeValueTransformer;
import edu.uci.ics.jung.visualization.decorators.DirectionalEdgeArrowTransformer;
import edu.uci.ics.jung.visualization.decorators.EdgeShape;
import edu.uci.ics.jung.visualization.decorators.ParallelEdgeShapeTransformer;
import edu.uci.ics.jung.visualization.picking.PickedState;
import edu.uci.ics.jung.visualization.renderers.DefaultEdgeLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.EdgeLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.VertexLabelRenderer;
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator;


public class PluggableRenderContext implements RenderContext {
    
	protected float arrowPlacementTolerance = 1;
    protected Predicate,V>> vertexIncludePredicate = Predicates.alwaysTrue();
    protected Function vertexStrokeTransformer = 
    	Functions.constant(new BasicStroke(1.0f));
    
    protected Function vertexShapeTransformer = 
        		Functions.constant(
        		new Ellipse2D.Float(-10,-10,20,20));

    protected Function vertexLabelTransformer = Functions.constant(null);
    protected Function vertexIconTransformer;
    protected Function vertexFontTransformer = 
        Functions.constant(new Font("Helvetica", Font.PLAIN, 12));
    
    protected Function vertexDrawPaintTransformer = 
    	Functions.constant(Color.BLACK);
    protected Function vertexFillPaintTransformer = 
    	Functions.constant(Color.RED);
    
    protected Function edgeLabelTransformer = 
    	Functions.constant(null);
    protected Function edgeStrokeTransformer = 
    	Functions.constant(new BasicStroke(1.0f));
    protected Function edgeArrowStrokeTransformer = 
    	Functions.constant(new BasicStroke(1.0f));
    
    protected Function,E>,Shape> edgeArrowTransformer = 
        new DirectionalEdgeArrowTransformer(10, 8, 4);
    
    protected Predicate,E>> edgeArrowPredicate = new DirectedEdgeArrowPredicate();
    protected Predicate,E>> edgeIncludePredicate = Predicates.alwaysTrue();
    protected Function edgeFontTransformer =
        Functions.constant(new Font("Helvetica", Font.PLAIN, 12));
    protected Function,E>,Number> edgeLabelClosenessTransformer = 
        new ConstantDirectionalEdgeValueTransformer(0.5, 0.65);
    protected Function edgeShapeTransformer;
    protected Function edgeFillPaintTransformer =
        Functions.constant(null);
    protected Function edgeDrawPaintTransformer =
        Functions.constant(Color.black);
    protected Function arrowFillPaintTransformer =
        Functions.constant(Color.black);
    protected Function arrowDrawPaintTransformer =
        Functions.constant(Color.black);
    
    protected EdgeIndexFunction parallelEdgeIndexFunction = 
        DefaultParallelEdgeIndexFunction.getInstance();
    
    protected EdgeIndexFunction incidentEdgeIndexFunction = 
        IncidentEdgeIndexFunction.getInstance();
    
    protected MultiLayerTransformer multiLayerTransformer = new BasicTransformer();
    
	/**
	 * pluggable support for picking graph elements by
	 * finding them based on their coordinates.
	 */
	protected GraphElementAccessor pickSupport;

    
    protected int labelOffset = LABEL_OFFSET;
    
    /**
     * the JComponent that this Renderer will display the graph on
     */
    protected JComponent screenDevice;
    
    protected PickedState pickedVertexState;
    protected PickedState pickedEdgeState;
    
    /**
     * The CellRendererPane is used here just as it is in JTree
     * and JTable, to allow a pluggable JLabel-based renderer for
     * Vertex and Edge label strings and icons.
     */
    protected CellRendererPane rendererPane = new CellRendererPane();
    
    /**
     * A default GraphLabelRenderer - picked Vertex labels are
     * blue, picked edge labels are cyan
     */
    protected VertexLabelRenderer vertexLabelRenderer = 
        new DefaultVertexLabelRenderer(Color.blue);
    
    protected EdgeLabelRenderer edgeLabelRenderer = new DefaultEdgeLabelRenderer(Color.cyan);
    
    protected GraphicsDecorator graphicsContext;
    
    private EdgeShape edgeShape;
    
    PluggableRenderContext(Graph graph) {
        this.edgeShape = new EdgeShape(graph);
    	this.edgeShapeTransformer = edgeShape.new QuadCurve();    	
    }

	/**
	 * @return the vertexShapeTransformer
	 */
	public Function getVertexShapeTransformer() {
		return vertexShapeTransformer;
	}

	/**
	 * @param vertexShapeTransformer the vertexShapeTransformer to set
	 */
	public void setVertexShapeTransformer(
			Function vertexShapeTransformer) {
		this.vertexShapeTransformer = vertexShapeTransformer;
	}

	/**
	 * @return the vertexStrokeTransformer
	 */
	public Function getVertexStrokeTransformer() {
		return vertexStrokeTransformer;
	}

	/**
	 * @param vertexStrokeTransformer the vertexStrokeTransformer to set
	 */
	public void setVertexStrokeTransformer(
			Function vertexStrokeTransformer) {
		this.vertexStrokeTransformer = vertexStrokeTransformer;
	}

	public static float[] getDashing() {
        return dashing;
    }

    public static float[] getDotting() {
        return dotting;
    }

    public float getArrowPlacementTolerance() {
        return arrowPlacementTolerance;
    }

    public void setArrowPlacementTolerance(float arrow_placement_tolerance) {
        this.arrowPlacementTolerance = arrow_placement_tolerance;
    }

    public Function,E>,Shape> getEdgeArrowTransformer() {
        return edgeArrowTransformer;
    }

    public void setEdgeArrowTransformer(Function,E>,Shape> edgeArrowTransformer) {
        this.edgeArrowTransformer = edgeArrowTransformer;
    }

    public Predicate,E>> getEdgeArrowPredicate() {
        return edgeArrowPredicate;
    }

    public void setEdgeArrowPredicate(Predicate,E>> edgeArrowPredicate) {
        this.edgeArrowPredicate = edgeArrowPredicate;
    }

    public Function getEdgeFontTransformer() {
        return edgeFontTransformer;
    }

    public void setEdgeFontTransformer(Function edgeFontTransformer) {
        this.edgeFontTransformer = edgeFontTransformer;
    }

    public Predicate,E>> getEdgeIncludePredicate() {
        return edgeIncludePredicate;
    }

    public void setEdgeIncludePredicate(Predicate,E>> edgeIncludePredicate) {
        this.edgeIncludePredicate = edgeIncludePredicate;
    }

    public Function,E>,Number> getEdgeLabelClosenessTransformer() {
        return edgeLabelClosenessTransformer;
    }

    public void setEdgeLabelClosenessTransformer(
    		Function,E>,Number> edgeLabelClosenessTransformer) {
        this.edgeLabelClosenessTransformer = edgeLabelClosenessTransformer;
    }

    public EdgeLabelRenderer getEdgeLabelRenderer() {
        return edgeLabelRenderer;
    }

    public void setEdgeLabelRenderer(EdgeLabelRenderer edgeLabelRenderer) {
        this.edgeLabelRenderer = edgeLabelRenderer;
    }

    public Function getEdgeFillPaintTransformer() {
        return edgeFillPaintTransformer;
    }

    public void setEdgeDrawPaintTransformer(Function edgeDrawPaintTransformer) {
        this.edgeDrawPaintTransformer = edgeDrawPaintTransformer;
    }

    public Function getEdgeDrawPaintTransformer() {
        return edgeDrawPaintTransformer;
    }

    public void setEdgeFillPaintTransformer(Function edgeFillPaintTransformer) {
        this.edgeFillPaintTransformer = edgeFillPaintTransformer;
    }

    public Function getEdgeShapeTransformer() {
        return edgeShapeTransformer;
    }

    public void setEdgeShapeTransformer(Function edgeShapeTransformer) {
        this.edgeShapeTransformer = edgeShapeTransformer;
        if (edgeShapeTransformer instanceof ParallelEdgeShapeTransformer) {
        	@SuppressWarnings("unchecked")
			ParallelEdgeShapeTransformer transformer =
        			(ParallelEdgeShapeTransformer)edgeShapeTransformer;
        	if (transformer instanceof EdgeShape.Orthogonal) {
        		transformer.setEdgeIndexFunction(this.incidentEdgeIndexFunction);
        	} else {
        		transformer.setEdgeIndexFunction(this.parallelEdgeIndexFunction);
        	}
        }
    }

    public Function getEdgeLabelTransformer() {
        return edgeLabelTransformer;
    }

    public void setEdgeLabelTransformer(Function edgeLabelTransformer) {
        this.edgeLabelTransformer = edgeLabelTransformer;
    }

    public Function getEdgeStrokeTransformer() {
        return edgeStrokeTransformer;
    }

    public void setEdgeStrokeTransformer(Function edgeStrokeTransformer) {
        this.edgeStrokeTransformer = edgeStrokeTransformer;
    }

    public Function getEdgeArrowStrokeTransformer() {
        return edgeArrowStrokeTransformer;
    }

    public void setEdgeArrowStrokeTransformer(Function edgeArrowStrokeTransformer) {
        this.edgeArrowStrokeTransformer = edgeArrowStrokeTransformer;
    }

    public GraphicsDecorator getGraphicsContext() {
        return graphicsContext;
    }

    public void setGraphicsContext(GraphicsDecorator graphicsContext) {
        this.graphicsContext = graphicsContext;
    }

    public int getLabelOffset() {
        return labelOffset;
    }

    public void setLabelOffset(int labelOffset) {
        this.labelOffset = labelOffset;
    }

    public EdgeIndexFunction getParallelEdgeIndexFunction() {
        return parallelEdgeIndexFunction;
    }

    public void setParallelEdgeIndexFunction(
            EdgeIndexFunction parallelEdgeIndexFunction) {
        this.parallelEdgeIndexFunction = parallelEdgeIndexFunction;
        // reset the edge shape Function, as the parallel edge index function
        // is used by it
        this.setEdgeShapeTransformer(getEdgeShapeTransformer());
    }

    public PickedState getPickedEdgeState() {
        return pickedEdgeState;
    }

    public void setPickedEdgeState(PickedState pickedEdgeState) {
        this.pickedEdgeState = pickedEdgeState;
    }

    public PickedState getPickedVertexState() {
        return pickedVertexState;
    }

    public void setPickedVertexState(PickedState pickedVertexState) {
        this.pickedVertexState = pickedVertexState;
    }

    public CellRendererPane getRendererPane() {
        return rendererPane;
    }

    public void setRendererPane(CellRendererPane rendererPane) {
        this.rendererPane = rendererPane;
    }

    public JComponent getScreenDevice() {
        return screenDevice;
    }

    public void setScreenDevice(JComponent screenDevice) {
        this.screenDevice = screenDevice;
        screenDevice.add(rendererPane);
    }

    public Function getVertexFontTransformer() {
        return vertexFontTransformer;
    }

    public void setVertexFontTransformer(Function vertexFontTransformer) {
        this.vertexFontTransformer = vertexFontTransformer;
    }

    public Function getVertexIconTransformer() {
        return vertexIconTransformer;
    }

    public void setVertexIconTransformer(Function vertexIconTransformer) {
        this.vertexIconTransformer = vertexIconTransformer;
    }

    public Predicate,V>> getVertexIncludePredicate() {
        return vertexIncludePredicate;
    }

    public void setVertexIncludePredicate(Predicate,V>> vertexIncludePredicate) {
        this.vertexIncludePredicate = vertexIncludePredicate;
    }

    public VertexLabelRenderer getVertexLabelRenderer() {
        return vertexLabelRenderer;
    }

    public void setVertexLabelRenderer(VertexLabelRenderer vertexLabelRenderer) {
        this.vertexLabelRenderer = vertexLabelRenderer;
    }

    public Function getVertexFillPaintTransformer() {
        return vertexFillPaintTransformer;
    }

    public void setVertexFillPaintTransformer(Function vertexFillPaintTransformer) {
        this.vertexFillPaintTransformer = vertexFillPaintTransformer;
    }

    public Function getVertexDrawPaintTransformer() {
        return vertexDrawPaintTransformer;
    }

    public void setVertexDrawPaintTransformer(Function vertexDrawPaintTransformer) {
        this.vertexDrawPaintTransformer = vertexDrawPaintTransformer;
    }

    public Function getVertexLabelTransformer() {
        return vertexLabelTransformer;
    }

    public void setVertexLabelTransformer(Function vertexLabelTransformer) {
        this.vertexLabelTransformer = vertexLabelTransformer;
    }

	public GraphElementAccessor getPickSupport() {
		return pickSupport;
	}

	public void setPickSupport(GraphElementAccessor pickSupport) {
		this.pickSupport = pickSupport;
	}
	
	public MultiLayerTransformer getMultiLayerTransformer() {
		return multiLayerTransformer;
	}

	public void setMultiLayerTransformer(MultiLayerTransformer basicTransformer) {
		this.multiLayerTransformer = basicTransformer;
	}

	public Function getArrowDrawPaintTransformer() {
		return arrowDrawPaintTransformer;
	}

	public Function getArrowFillPaintTransformer() {
		return arrowFillPaintTransformer;
	}

	public void setArrowDrawPaintTransformer(Function arrowDrawPaintTransformer) {
		this.arrowDrawPaintTransformer = arrowDrawPaintTransformer;
		
	}

	public void setArrowFillPaintTransformer(Function arrowFillPaintTransformer) {
		this.arrowFillPaintTransformer = arrowFillPaintTransformer;
		
	}
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy