com.googlecode.blaisemath.graphics.swing.JGraphics 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.
/**
* JGraphicUtils.java
* Created Aug 1, 2014
*/
package com.googlecode.blaisemath.graphics.swing;
/*
* #%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.graphics.core.DelegatingNodeLinkGraphic;
import com.googlecode.blaisemath.graphics.core.DelegatingPrimitiveGraphic;
import com.googlecode.blaisemath.graphics.core.PrimitiveGraphic;
import com.googlecode.blaisemath.style.AttributeSet;
import com.googlecode.blaisemath.style.ObjectStyler;
import com.googlecode.blaisemath.style.Styles;
import com.googlecode.blaisemath.util.AnchoredIcon;
import com.googlecode.blaisemath.util.AnchoredImage;
import com.googlecode.blaisemath.util.AnchoredText;
import com.googlecode.blaisemath.util.Edge;
import com.googlecode.blaisemath.util.OrientedPoint2D;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.Point2D;
import javax.swing.Icon;
/**
* Factory methods for creating basic java2d-based graphics.
*
* @author Elisha
*/
public class JGraphics {
/** Default stroke of 1 unit width. */
public static final BasicStroke DEFAULT_STROKE
= new BasicStroke(1.0f);
/** Default composite */
public static final Composite DEFAULT_COMPOSITE
= AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
// utilitiy class
private JGraphics() {
}
//
public static PrimitiveGraphic path(Shape primitive) {
return new PrimitiveGraphic(primitive, Styles.defaultPathStyle(), PathRenderer.getInstance());
}
public static PrimitiveGraphic path(Shape primitive, AttributeSet style) {
return new PrimitiveGraphic(primitive, style, PathRenderer.getInstance());
}
public static DelegatingPrimitiveGraphic path(S source, Shape primitive, ObjectStyler styler) {
return new DelegatingPrimitiveGraphic(source, primitive, styler, PathRenderer.getInstance());
}
public static PrimitiveGraphic shape(Shape primitive) {
return new PrimitiveGraphic(primitive, Styles.defaultShapeStyle(), ShapeRenderer.getInstance());
}
public static PrimitiveGraphic shape(Shape primitive, AttributeSet style) {
return new PrimitiveGraphic(primitive, style, ShapeRenderer.getInstance());
}
public static DelegatingPrimitiveGraphic shape(S source, Shape primitive, ObjectStyler styler) {
return new DelegatingPrimitiveGraphic(source, primitive, styler, ShapeRenderer.getInstance());
}
public static PrimitiveGraphic point(Point2D primitive) {
return new PrimitiveGraphic(primitive, Styles.defaultPointStyle(), MarkerRenderer.getInstance());
}
public static PrimitiveGraphic point(Point2D primitive, AttributeSet style) {
return new PrimitiveGraphic(primitive, style, MarkerRenderer.getInstance());
}
public static DelegatingPrimitiveGraphic point(S source, Point2D primitive, ObjectStyler styler) {
return new DelegatingPrimitiveGraphic(source, primitive, styler, MarkerRenderer.getInstance());
}
public static PrimitiveGraphic marker(OrientedPoint2D primitive) {
return new PrimitiveGraphic(primitive, Styles.defaultPointStyle(), MarkerRenderer.getInstance());
}
public static PrimitiveGraphic marker(OrientedPoint2D primitive, AttributeSet style) {
return new PrimitiveGraphic(primitive, style, MarkerRenderer.getInstance());
}
public static DelegatingPrimitiveGraphic marker(S source, OrientedPoint2D primitive, ObjectStyler styler) {
return new DelegatingPrimitiveGraphic(source, primitive, styler, MarkerRenderer.getInstance());
}
public static PrimitiveGraphic text(AnchoredText primitive) {
return new PrimitiveGraphic(primitive, Styles.defaultTextStyle(), TextRenderer.getInstance());
}
public static PrimitiveGraphic text(AnchoredText primitive, AttributeSet style) {
return new PrimitiveGraphic(primitive, style, TextRenderer.getInstance());
}
public static DelegatingPrimitiveGraphic text(S source, AnchoredText primitive, ObjectStyler styler) {
return new DelegatingPrimitiveGraphic(source, primitive, styler, TextRenderer.getInstance());
}
public static PrimitiveGraphic image(AnchoredImage primitive) {
return new PrimitiveGraphic(primitive, AttributeSet.EMPTY, ImageRenderer.getInstance());
}
public static PrimitiveGraphic image(double x, double y, double wid, double ht, Image image, String refc) {
return new PrimitiveGraphic(new AnchoredImage(x, y, wid, ht, image, refc), AttributeSet.EMPTY, ImageRenderer.getInstance());
}
public static PrimitiveGraphic icon(AnchoredIcon icon) {
return new PrimitiveGraphic(icon, AttributeSet.EMPTY, IconRenderer.getInstance());
}
public static PrimitiveGraphic icon(Icon icon, double x, double y) {
return new PrimitiveGraphic(new AnchoredIcon(x, y, icon), AttributeSet.EMPTY, IconRenderer.getInstance());
}
public static DelegatingNodeLinkGraphic, Graphics2D> nodeLink() {
return new DelegatingNodeLinkGraphic,Graphics2D>(
MarkerRenderer.getInstance(), TextRenderer.getInstance(), PathRenderer.getInstance());
}
//
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy