com.googlecode.blaisemath.graphics.impl.DelegatingNodeLinkGraphic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blaise-graphics Show documentation
Show all versions of blaise-graphics Show documentation
Scene graph and style library using Java2D graphics.
package com.googlecode.blaisemath.graphics.impl;
/*
* #%L
* BlaiseGraphics
* --
* Copyright (C) 2009 - 2020 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.google.common.graph.EndpointPair;
import com.googlecode.blaisemath.graphics.GraphicComposite;
import com.googlecode.blaisemath.graphics.Renderer;
import com.googlecode.blaisemath.style.ObjectStyler;
import com.googlecode.blaisemath.coordinate.CoordinateManager;
import com.googlecode.blaisemath.primitive.AnchoredText;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.awt.Shape;
import java.awt.geom.Point2D;
import java.util.Map;
import java.util.Set;
/**
* A graph with fully-customizable nodes, edges, and tooltips. The styles and
* point values are computed at runtime. Edges are maintained as a set of {@link EndpointPair}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 DEFAULT_NODE_CACHE_SIZE = 20000;
/** Point graphics */
private final DelegatingPointSetGraphic pointGraphics;
/** Edge graphics */
private final DelegatingEdgeSetGraphic edgeGraphics;
//region CONSTRUCTORS
/**
* Construct with no points and default renderers.
*/
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(DEFAULT_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);
}
//endregion
//region DELEGATES - POINTS
public DelegatingPointSetGraphic getPointGraphic() {
return pointGraphics;
}
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);
}
//endregion
//region DELEGATES - EDGES
public DelegatingEdgeSetGraphic getEdgeGraphic() {
return edgeGraphics;
}
public Set getEdgeSet() {
return edgeGraphics.getEdges();
}
public void setEdgeSet(Set extends E> 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);
}
//endregion
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy