com.googlecode.blaisemath.graph.view.GraphComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blaise-graph-theory-ui Show documentation
Show all versions of blaise-graph-theory-ui Show documentation
Swing UI components for blaise-graph-theory.
package com.googlecode.blaisemath.graph.view;
/*
* #%L
* BlaiseGraphTheory
* --
* 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.google.common.graph.EndpointPair;
import com.google.common.graph.Graph;
import com.googlecode.blaisemath.coordinate.CoordinateManager;
import com.googlecode.blaisemath.graph.layout.GraphLayoutManager;
import com.googlecode.blaisemath.graphics.impl.DelegatingNodeLinkGraphic;
import com.googlecode.blaisemath.graphics.DelegatingPrimitiveGraphic;
import com.googlecode.blaisemath.graphics.swing.JGraphicComponent;
import com.googlecode.blaisemath.graphics.swing.JGraphics;
import com.googlecode.blaisemath.graphics.swing.PanAndZoomHandler;
import com.googlecode.blaisemath.style.ObjectStyler;
import com.googlecode.blaisemath.util.swing.ContextMenuInitializer;
import java.awt.*;
import java.awt.event.HierarchyEvent;
import java.util.Collection;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import static java.util.stream.Collectors.toSet;
/**
* Provides a view of a graph, using a {@link GraphLayoutManager} for positions/layout and a {@link VisualGraph} for appearance.
* The layout manager supports executing long-running layout algorithms in a background thread, and the visual graph
* shares a {@link CoordinateManager} that is used for updating locations from the layout manager. The coordinate manager is thread-safe.
*
* @author Elisha Peterson
*/
public class GraphComponent extends JGraphicComponent {
private static final Logger LOG = Logger.getLogger(GraphComponent.class.getName());
public static final String MENU_KEY_GRAPH = "graph";
public static final String MENU_KEY_EDGE = "edge";
public static final String MENU_KEY_NODE = "node";
/** This mechanism is used to create the initial view graph for swing components, by setting up appropriate renderers. */
private static final Supplier, Graphics2D>> SWING_GRAPH_SUPPLIER = () -> {
DelegatingNodeLinkGraphic