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

com.googlecode.blaisemath.graphics.core.DelegatingNodeLinkGraphic Maven / Gradle / Ivy

There is a newer version: 3.0.16
Show newest version
/**
 * DelegatingPointSetGraphic.java
 * Created Jan 22, 2011
 */
package com.googlecode.blaisemath.graphics.core;

/*
 * #%L
 * BlaiseGraphics
 * --
 * Copyright (C) 2009 - 2019 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import com.googlecode.blaisemath.style.ObjectStyler;
import com.googlecode.blaisemath.style.Renderer;
import com.googlecode.blaisemath.util.AnchoredText;
import com.googlecode.blaisemath.util.Edge;
import com.googlecode.blaisemath.util.coordinate.CoordinateManager;
import java.awt.Shape;
import java.awt.geom.Point2D;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

/**
 * A graph with fully-customizable points, edges, and tooltips. The styles and
 * point values are computed at runtime. Edges are maintained as a set of {@link Edge}s.
 *
 * @param  source object type
 * @param  edge type
 * @param  graphics canvas type
 * 
 * @author Elisha Peterson
 */
public class DelegatingNodeLinkGraphic,G> extends GraphicComposite {
    
    private static final int NODE_CACHE_SIZE = 20000;

    /** Point graphics */
    private final DelegatingPointSetGraphic pointGraphics;
    /** Edge graphics */
    private final DelegatingEdgeSetGraphic edgeGraphics;

    /**
     * Construct with no points
     */
    public DelegatingNodeLinkGraphic() {
        this(null, null, null);
    }
    
    /**
     * Construct with no points
     * @param nodeRenderer how nodes will be rendered
     * @param labelRenderer how node labels will be rendered
     * @param edgeRenderer how edges will be rendered
     */
    public DelegatingNodeLinkGraphic(@Nullable Renderer nodeRenderer,
            @Nullable Renderer labelRenderer,
            @Nullable Renderer edgeRenderer) {
        this(CoordinateManager.create(NODE_CACHE_SIZE), nodeRenderer, labelRenderer, edgeRenderer);
    }
    
    /**
     * Construct with specified coordinate manager
     * @param crdManager in charge of node locations
     * @param nodeRenderer draws the nodes
     * @param labelRenderer draws labels
     * @param edgeRenderer draws edges
     */
    public DelegatingNodeLinkGraphic(CoordinateManager crdManager,
            @Nullable Renderer nodeRenderer,
            @Nullable Renderer labelRenderer,
            @Nullable Renderer edgeRenderer) {
        pointGraphics = new DelegatingPointSetGraphic(crdManager, nodeRenderer, labelRenderer);
        edgeGraphics = new DelegatingEdgeSetGraphic(crdManager, edgeRenderer);
        addGraphic(edgeGraphics);
        addGraphic(pointGraphics);
    }
    
    
    //
    //
    // PROPERTY PATTERNS
    //

    public DelegatingPointSetGraphic getPointGraphic() {
        return pointGraphics;
    }

    public DelegatingEdgeSetGraphic getEdgeGraphic() {
        return edgeGraphics;
    }
    
    //
    
    //

    public CoordinateManager getCoordinateManager() {
        return pointGraphics.getCoordinateManager();
    }

    public void setCoordinateManager(CoordinateManager ptMgr) {
        pointGraphics.setCoordinateManager(ptMgr);
        edgeGraphics.setCoordinateManager(ptMgr);
    }

    public Set getNodeSet() {
        return pointGraphics.getObjects();
    }
    
    public Map getNodeLocations() {
        return pointGraphics.getCoordinateManager().getActiveLocationCopy();
    }
    

    public void setNodeLocations(Map pts) {
        pointGraphics.getCoordinateManager().putAll(pts);
    }

    public ObjectStyler getNodeStyler() {
        return pointGraphics.getStyler();
    }

    public void setNodeStyler(ObjectStyler styler) {
        pointGraphics.setStyler(styler);
    }

    public Renderer getNodeRenderer() {
        return pointGraphics.getRenderer();
    }

    public void setNodeRenderer(Renderer renderer) {
        pointGraphics.setRenderer(renderer);
    }

    public Renderer getLabelRenderer() {
        return pointGraphics.getLabelRenderer();
    }

    public void setLabelRenderer(Renderer renderer) {
        pointGraphics.setLabelRenderer(renderer);
    }

    public boolean isDragEnabled() {
        return pointGraphics.isDragEnabled();
    }

    public void setDragEnabled(boolean val) {
        pointGraphics.setDragEnabled(val);
    }

    public boolean isPointSelectionEnabled() {
        return pointGraphics.isPointSelectionEnabled();
    }

    public void setPointSelectionEnabled(boolean val) {
        pointGraphics.setPointSelectionEnabled(val);
    }
    
    //
    
    //

    public Set getEdgeSet() {
        return edgeGraphics.getEdges();
    }

    public void setEdgeSet(Set edges) {
        this.edgeGraphics.setEdges(edges);
    }

    public ObjectStyler getEdgeStyler() {
        return edgeGraphics.getEdgeStyler();
    }

    public void setEdgeStyler(ObjectStyler styler) {
        edgeGraphics.setEdgeStyler(styler);
    }

    public Renderer getEdgeRenderer() {
        return edgeGraphics.getEdgeRenderer();
    }

    public final void setEdgeRenderer(Renderer renderer) {
        edgeGraphics.setEdgeRenderer(renderer);
    }
    
    //

}