Rename Processing to G2D
Esse commit está contido em:
@@ -54,7 +54,7 @@ import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.gephi.preview.api.PreviewController;
|
||||
import org.gephi.preview.api.PreviewMouseEvent;
|
||||
import org.gephi.preview.api.ProcessingTarget;
|
||||
import org.gephi.preview.api.G2DTarget;
|
||||
import org.gephi.preview.api.Vector;
|
||||
import org.openide.util.Lookup;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class PreviewSketch extends JPanel implements MouseListener, MouseWheelLi
|
||||
private static final int WHEEL_TIMER = 500;
|
||||
//Data
|
||||
private final PreviewController previewController;
|
||||
private final ProcessingTarget target;
|
||||
private final G2DTarget target;
|
||||
//Geometry
|
||||
private final Vector ref = new Vector();
|
||||
private final Vector lastMove = new Vector();
|
||||
@@ -76,7 +76,7 @@ public class PreviewSketch extends JPanel implements MouseListener, MouseWheelLi
|
||||
private Timer wheelTimer;
|
||||
private boolean inited;
|
||||
|
||||
public PreviewSketch(ProcessingTarget target) {
|
||||
public PreviewSketch(G2DTarget target) {
|
||||
this.target = target;
|
||||
previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
}
|
||||
|
||||
+3
-3
@@ -56,7 +56,7 @@ import org.gephi.desktop.preview.api.PreviewUIController;
|
||||
import org.gephi.desktop.preview.api.PreviewUIModel;
|
||||
import org.gephi.preview.api.PreviewController;
|
||||
import org.gephi.preview.api.PreviewProperty;
|
||||
import org.gephi.preview.api.ProcessingTarget;
|
||||
import org.gephi.preview.api.G2DTarget;
|
||||
import org.gephi.preview.api.RenderTarget;
|
||||
import org.gephi.ui.components.JColorButton;
|
||||
import org.gephi.ui.utils.UIUtils;
|
||||
@@ -87,7 +87,7 @@ public final class PreviewTopComponent extends TopComponent implements PropertyC
|
||||
private final transient ProcessingListener processingListener = new ProcessingListener();
|
||||
//Data
|
||||
private transient PreviewUIModel model;
|
||||
private transient ProcessingTarget target;
|
||||
private transient G2DTarget target;
|
||||
private transient PreviewSketch sketch;
|
||||
|
||||
public PreviewTopComponent() {
|
||||
@@ -187,7 +187,7 @@ public final class PreviewTopComponent extends TopComponent implements PropertyC
|
||||
setBackgroundColor(background);
|
||||
}
|
||||
|
||||
target = (ProcessingTarget) previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET);
|
||||
target = (G2DTarget) previewController.getRenderTarget(RenderTarget.G2D_TARGET);
|
||||
if (target != null) {
|
||||
sketch = new PreviewSketch(target);
|
||||
sketchPanel.add(sketch, BorderLayout.CENTER);
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
Copyright 2008-2011 Gephi
|
||||
Authors : Mathieu Bastian
|
||||
Website : http://www.gephi.org
|
||||
|
||||
This file is part of Gephi.
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Copyright 2011 Gephi Consortium. All rights reserved.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 3 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://gephi.org/about/legal/license-notice/
|
||||
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License files at
|
||||
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 3, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 3] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 3 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 3 code and therefore, elected the GPL
|
||||
Version 3 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Portions Copyrighted 2011 Gephi Consortium.
|
||||
*/
|
||||
package org.gephi.preview;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import org.gephi.preview.api.G2DTarget;
|
||||
import org.gephi.preview.api.PreviewController;
|
||||
import org.gephi.preview.api.PreviewModel;
|
||||
import org.gephi.preview.api.PreviewProperty;
|
||||
import org.gephi.preview.api.RenderTarget;
|
||||
import org.gephi.preview.api.Vector;
|
||||
import org.gephi.preview.spi.RenderTargetBuilder;
|
||||
import org.openide.util.Lookup;
|
||||
import org.openide.util.lookup.ServiceProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mathieu Bastian
|
||||
*/
|
||||
@ServiceProvider(service = RenderTargetBuilder.class)
|
||||
public class G2DRenderTargetBuilder implements RenderTargetBuilder {
|
||||
|
||||
@Override
|
||||
public RenderTarget buildRenderTarget(PreviewModel previewModel) {
|
||||
Integer width = previewModel.getProperties().getValue("width");
|
||||
Integer height = previewModel.getProperties().getValue("height");
|
||||
if (width != null && height != null) {
|
||||
width = Math.max(1, width);
|
||||
height = Math.max(1, height);
|
||||
return new G2DTargetImpl(previewModel, width, height);
|
||||
} else {
|
||||
return new G2DTargetImpl(previewModel, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return RenderTarget.G2D_TARGET;
|
||||
}
|
||||
|
||||
public static class G2DTargetImpl extends AbstractRenderTarget implements G2DTarget {
|
||||
|
||||
private final PreviewController previewController;
|
||||
private final PreviewModel previewModel;
|
||||
private G2DGraphics graphics;
|
||||
|
||||
public G2DTargetImpl(PreviewModel model, int width, int height) {
|
||||
graphics = new G2DGraphics(width, height);
|
||||
previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
previewModel = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
width = Math.max(1, width);
|
||||
height = Math.max(1, height);
|
||||
graphics.getGraphics().dispose();
|
||||
graphics = new G2DGraphics(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Graphics2D getGraphics() {
|
||||
return graphics.getGraphics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage() {
|
||||
return graphics.getImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return graphics.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return graphics.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getTranslate() {
|
||||
return graphics.getTranslate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaling() {
|
||||
return graphics.getScaling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaling(float scaling) {
|
||||
graphics.setScaling(scaling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMoving(boolean moving) {
|
||||
previewModel.getProperties().putValue(PreviewProperty.MOVING, moving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
graphics.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if (graphics != null) {
|
||||
graphics.refresh(previewController.getModel(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class G2DGraphics {
|
||||
|
||||
private final PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
private PreviewModel model;
|
||||
private boolean inited;
|
||||
//Drawing
|
||||
private final Image image;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final Graphics2D g2;
|
||||
private final Vector trans = new Vector();
|
||||
private float scaling;
|
||||
private Color background = Color.WHITE;
|
||||
|
||||
public G2DGraphics(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
|
||||
image = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
g2 = (Graphics2D) image.getGraphics();
|
||||
|
||||
//Smooth
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
||||
}
|
||||
|
||||
public void refresh(PreviewModel previewModel, RenderTarget target) {
|
||||
this.model = previewModel;
|
||||
if (model != null) {
|
||||
background = model.getProperties().getColorValue(PreviewProperty.BACKGROUND_COLOR);
|
||||
initAppletLayout();
|
||||
|
||||
g2.clearRect(0, 0, width, height);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (background != null) {
|
||||
g2.setColor(background);
|
||||
g2.fillRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
// user zoom
|
||||
Vector center = new Vector(width / 2f, height / 2f);
|
||||
Vector scaledCenter = Vector.mult(center, scaling);
|
||||
Vector scaledTrans = Vector.sub(center, scaledCenter);
|
||||
g2.translate(scaledTrans.x, scaledTrans.y);
|
||||
g2.scale(scaling, scaling);
|
||||
|
||||
// user move
|
||||
g2.translate(trans.x, trans.y);
|
||||
|
||||
//Draw target
|
||||
previewController.render(target);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector getTranslate() {
|
||||
return trans;
|
||||
}
|
||||
|
||||
public float getScaling() {
|
||||
return scaling;
|
||||
}
|
||||
|
||||
public void setScaling(float scaling) {
|
||||
this.scaling = scaling;
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics() {
|
||||
return g2;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
inited = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the preview applet layout according to the graph's
|
||||
* dimension.
|
||||
*/
|
||||
private void initAppletLayout() {
|
||||
// graphSheet.setMargin(MARGIN);
|
||||
if (!inited && model != null && model.getDimensions() != null && model.getTopLeftPosition() != null) {
|
||||
|
||||
// initializes zoom
|
||||
Dimension dimensions = model.getDimensions();
|
||||
Point topLeftPostition = model.getTopLeftPosition();
|
||||
Vector box = new Vector((float) dimensions.getWidth(), (float) dimensions.getHeight());
|
||||
float ratioWidth = width / box.x;
|
||||
float ratioHeight = height / box.y;
|
||||
scaling = ratioWidth < ratioHeight ? ratioWidth : ratioHeight;
|
||||
|
||||
// initializes move
|
||||
Vector semiBox = Vector.div(box, 2);
|
||||
Vector topLeftVector = new Vector((float) topLeftPostition.x, (float) topLeftPostition.y);
|
||||
Vector center = new Vector(width / 2f, height / 2f);
|
||||
Vector scaledCenter = Vector.add(topLeftVector, semiBox);
|
||||
trans.set(center);
|
||||
trans.sub(scaledCenter);
|
||||
// lastMove.set(trans);
|
||||
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
Copyright 2008-2011 Gephi
|
||||
Authors : Jeremy Subtil <jeremy.subtil@gephi.org>, Mathieu Bastian
|
||||
Website : http://www.gephi.org
|
||||
|
||||
This file is part of Gephi.
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Copyright 2011 Gephi Consortium. All rights reserved.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 3 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://gephi.org/about/legal/license-notice/
|
||||
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License files at
|
||||
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 3, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 3] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 3 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 3 code and therefore, elected the GPL
|
||||
Version 3 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Portions Copyrighted 2011 Gephi Consortium.
|
||||
*/
|
||||
package org.gephi.preview;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import org.gephi.preview.api.PreviewController;
|
||||
import org.gephi.preview.api.PreviewModel;
|
||||
import org.gephi.preview.api.PreviewProperty;
|
||||
import org.gephi.preview.api.RenderTarget;
|
||||
import org.gephi.preview.api.Vector;
|
||||
import org.openide.util.Lookup;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mathieu Bastian
|
||||
*/
|
||||
public class ProcessingGraphics {
|
||||
|
||||
private final PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
private PreviewModel model;
|
||||
private RenderTarget target;
|
||||
private boolean inited;
|
||||
//Drawing
|
||||
private final Image image;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final Graphics2D g2;
|
||||
private final Vector trans = new Vector();
|
||||
private float scaling;
|
||||
private Color background = Color.WHITE;
|
||||
|
||||
public ProcessingGraphics(int width, int height) {
|
||||
System.out.println("Creating new graphcis " + width + " " + height);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
|
||||
image = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
g2 = (Graphics2D) image.getGraphics();
|
||||
|
||||
//Smooth
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
||||
}
|
||||
|
||||
public void refresh(PreviewModel previewModel, RenderTarget target) {
|
||||
this.model = previewModel;
|
||||
this.target = target;
|
||||
if (model != null) {
|
||||
background = model.getProperties().getColorValue(PreviewProperty.BACKGROUND_COLOR);
|
||||
initAppletLayout();
|
||||
|
||||
g2.clearRect(0, 0, width, height);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (background != null) {
|
||||
g2.setColor(background);
|
||||
g2.fillRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
// user zoom
|
||||
Vector center = new Vector(width / 2f, height / 2f);
|
||||
Vector scaledCenter = Vector.mult(center, scaling);
|
||||
Vector scaledTrans = Vector.sub(center, scaledCenter);
|
||||
g2.translate(scaledTrans.x, scaledTrans.y);
|
||||
g2.scale(scaling, scaling);
|
||||
|
||||
// user move
|
||||
g2.translate(trans.x, trans.y);
|
||||
|
||||
//Draw target
|
||||
previewController.render(target);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector getTranslate() {
|
||||
return trans;
|
||||
}
|
||||
|
||||
public float getScaling() {
|
||||
return scaling;
|
||||
}
|
||||
|
||||
public void setScaling(float scaling) {
|
||||
this.scaling = scaling;
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics() {
|
||||
return g2;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
inited = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the preview applet layout according to the graph's dimension.
|
||||
*/
|
||||
private void initAppletLayout() {
|
||||
// graphSheet.setMargin(MARGIN);
|
||||
if (!inited && model != null && model.getDimensions() != null && model.getTopLeftPosition() != null) {
|
||||
|
||||
// initializes zoom
|
||||
Dimension dimensions = model.getDimensions();
|
||||
Point topLeftPostition = model.getTopLeftPosition();
|
||||
Vector box = new Vector((float) dimensions.getWidth(), (float) dimensions.getHeight());
|
||||
float ratioWidth = width / box.x;
|
||||
float ratioHeight = height / box.y;
|
||||
scaling = ratioWidth < ratioHeight ? ratioWidth : ratioHeight;
|
||||
|
||||
// initializes move
|
||||
Vector semiBox = Vector.div(box, 2);
|
||||
Vector topLeftVector = new Vector((float) topLeftPostition.x, (float) topLeftPostition.y);
|
||||
Vector center = new Vector(width / 2f, height / 2f);
|
||||
Vector scaledCenter = Vector.add(topLeftVector, semiBox);
|
||||
trans.set(center);
|
||||
trans.sub(scaledCenter);
|
||||
// lastMove.set(trans);
|
||||
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
-153
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
Copyright 2008-2011 Gephi
|
||||
Authors : Mathieu Bastian
|
||||
Website : http://www.gephi.org
|
||||
|
||||
This file is part of Gephi.
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Copyright 2011 Gephi Consortium. All rights reserved.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 3 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://gephi.org/about/legal/license-notice/
|
||||
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License files at
|
||||
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 3, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 3] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 3 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 3 code and therefore, elected the GPL
|
||||
Version 3 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Portions Copyrighted 2011 Gephi Consortium.
|
||||
*/
|
||||
package org.gephi.preview;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import org.gephi.preview.api.PreviewController;
|
||||
import org.gephi.preview.api.PreviewModel;
|
||||
import org.gephi.preview.api.PreviewProperty;
|
||||
import org.gephi.preview.api.ProcessingTarget;
|
||||
import org.gephi.preview.api.RenderTarget;
|
||||
import org.gephi.preview.api.Vector;
|
||||
import org.gephi.preview.spi.RenderTargetBuilder;
|
||||
import org.openide.util.Lookup;
|
||||
import org.openide.util.lookup.ServiceProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mathieu Bastian
|
||||
*/
|
||||
@ServiceProvider(service = RenderTargetBuilder.class)
|
||||
public class ProcessingRenderTargetBuilder implements RenderTargetBuilder {
|
||||
|
||||
@Override
|
||||
public RenderTarget buildRenderTarget(PreviewModel previewModel) {
|
||||
Integer width = previewModel.getProperties().getValue("width");
|
||||
Integer height = previewModel.getProperties().getValue("height");
|
||||
if (width != null && height != null) {
|
||||
width = Math.max(1, width);
|
||||
height = Math.max(1, height);
|
||||
return new ProcessingTargetImpl(previewModel, width, height);
|
||||
} else {
|
||||
return new ProcessingTargetImpl(previewModel, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return RenderTarget.PROCESSING_TARGET;
|
||||
}
|
||||
|
||||
public static class ProcessingTargetImpl extends AbstractRenderTarget implements ProcessingTarget {
|
||||
|
||||
private final PreviewController previewController;
|
||||
private final PreviewModel previewModel;
|
||||
private ProcessingGraphics graphics;
|
||||
|
||||
public ProcessingTargetImpl(PreviewModel model, int width, int height) {
|
||||
graphics = new ProcessingGraphics(width, height);
|
||||
previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
previewModel = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
width = Math.max(1, width);
|
||||
height = Math.max(1, height);
|
||||
graphics.getGraphics().dispose();
|
||||
graphics = new ProcessingGraphics(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Graphics2D getGraphics() {
|
||||
return graphics.getGraphics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage() {
|
||||
return graphics.getImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return graphics.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return graphics.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getTranslate() {
|
||||
return graphics.getTranslate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaling() {
|
||||
return graphics.getScaling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaling(float scaling) {
|
||||
graphics.setScaling(scaling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMoving(boolean moving) {
|
||||
previewModel.getProperties().putValue(PreviewProperty.MOVING, moving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
graphics.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if (graphics != null) {
|
||||
graphics.refresh(previewController.getModel(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-31
@@ -45,43 +45,17 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
|
||||
/**
|
||||
* Rendering target to the <a href="http://processing.org">Processing</a>
|
||||
* library.
|
||||
* Rendering target to Java2d.
|
||||
* <p>
|
||||
* Processing is using a <b>Java2D</b> mode so the underlying Processing object
|
||||
* used is a <a
|
||||
* href="http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html?processing/core/PGraphicsJava2D.html">PGraphicsJava2D</a>
|
||||
* object.
|
||||
* <p>
|
||||
* This render target supports two modes: <b>applet</b> or <b>headless</b>. The
|
||||
* applet mode is what is used in Gephi GUI and is backed by a
|
||||
* <code>PApplet</code> with zoom and pan control. The headless mode is tuned to
|
||||
* work without GUI and is typically used in exports. Either way users should
|
||||
* use
|
||||
* <code>getGraphics()</code> method for drawing.
|
||||
* <h4>How to create a headless Processing canvas?</h4>
|
||||
* Before creating a processing target with the
|
||||
* {@link PreviewController#getRenderTarget(java.lang.String)} method users
|
||||
* should define a <b>width</b> and <b>height</b> property in the
|
||||
* {@link PreviewProperties}:
|
||||
* <pre>
|
||||
* PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
|
||||
* PreviewModel model = previewController.getModel();
|
||||
* PreviewProperties props = model.getProperties();
|
||||
* props.putValue("width", 800);
|
||||
* props.putValue("height", 600);
|
||||
* ProcessingTarget target = (ProcessingTarget)previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET);
|
||||
* </pre>
|
||||
* Users should use<code>getGraphics()</code> method for drawing.
|
||||
*
|
||||
* @author Mathieu Bastian
|
||||
*/
|
||||
public interface ProcessingTarget extends RenderTarget {
|
||||
public interface G2DTarget extends RenderTarget {
|
||||
|
||||
/**
|
||||
* Returns the current graphics object. Use this method to draw to
|
||||
* Processing. The
|
||||
* <code>PGRraphics</code> object can be cast to
|
||||
* <code>PGraphicsJava2D</code>.
|
||||
* Returns the current graphics object. Use this method to draw to the
|
||||
* canvas.
|
||||
*
|
||||
* @return the current graphics to draw to
|
||||
*/
|
||||
@@ -1,56 +1,58 @@
|
||||
/*
|
||||
Copyright 2008-2011 Gephi
|
||||
Authors : Yudi Xue <yudi.xue@usask.ca>, Mathieu Bastian
|
||||
Website : http://www.gephi.org
|
||||
Copyright 2008-2011 Gephi
|
||||
Authors : Yudi Xue <yudi.xue@usask.ca>, Mathieu Bastian
|
||||
Website : http://www.gephi.org
|
||||
|
||||
This file is part of Gephi.
|
||||
This file is part of Gephi.
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Copyright 2011 Gephi Consortium. All rights reserved.
|
||||
Copyright 2011 Gephi Consortium. All rights reserved.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 3 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://gephi.org/about/legal/license-notice/
|
||||
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License files at
|
||||
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 3 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://gephi.org/about/legal/license-notice/
|
||||
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License files at
|
||||
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 3, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 3] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 3 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 3 code and therefore, elected the GPL
|
||||
Version 3 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 3, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 3] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 3 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 3 code and therefore, elected the GPL
|
||||
Version 3 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
|
||||
Contributor(s):
|
||||
Contributor(s):
|
||||
|
||||
Portions Copyrighted 2011 Gephi Consortium.
|
||||
Portions Copyrighted 2011 Gephi Consortium.
|
||||
*/
|
||||
package org.gephi.preview.api;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import org.gephi.preview.spi.Renderer;
|
||||
|
||||
/**
|
||||
* RenderTarget is the graphic container the renderers draw into.
|
||||
* <p>
|
||||
* There are three types of targets: <b>Processing</b>, <b>PDF</b> or <b>SVG</b>.
|
||||
* When the target is Processing, renderers obtain the
|
||||
* <a href="http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html?processing/core/PGraphicsJava2D.html">PGraphicsJava2D</a> object.
|
||||
* For the SVG target, renderers obtain Batik's <a href="http://xmlgraphics.apache.org/batik/using/dom-api.html">Document</a> instance.
|
||||
* As the PDF target rely on the iText library renderers obtain the <a href="http://api.itextpdf.com/itext/index.html?com/itextpdf/text/pdf/PdfContentByte.html">PdfContentByte</a>
|
||||
* There are three types of targets: <b>Processing</b>, <b>PDF</b> or
|
||||
* <b>SVG</b>. When the target is G2D, renderers obtain the {@link Graphics2D}
|
||||
* object. For the SVG target, renderers obtain Batik's <a
|
||||
* href="http://xmlgraphics.apache.org/batik/using/dom-api.html">Document</a>
|
||||
* instance. As the PDF target rely on the iText library renderers obtain the <a
|
||||
* href="http://api.itextpdf.com/itext/index.html?com/itextpdf/text/pdf/PdfContentByte.html">PdfContentByte</a>
|
||||
* object.
|
||||
* <p>
|
||||
* Render targets are not drawing anything. They just make accessible the canvas
|
||||
@@ -58,13 +60,13 @@ import org.gephi.preview.spi.Renderer;
|
||||
* <p>
|
||||
* When render targets have specific properties, values should be set in the
|
||||
* {@link PreviewProperties}.
|
||||
*
|
||||
*
|
||||
* @author Yudi Xue, Mathieu Bastian
|
||||
* @see Renderer
|
||||
*/
|
||||
public interface RenderTarget {
|
||||
|
||||
public static final String PROCESSING_TARGET = "processing";
|
||||
public static final String G2D_TARGET = "g2d";
|
||||
public static final String SVG_TARGET = "svg";
|
||||
public static final String PDF_TARGET = "pdf";
|
||||
}
|
||||
|
||||
+2
-2
@@ -139,8 +139,8 @@ public class ArrowRenderer implements Renderer {
|
||||
p3.mult(size * BASE_RATIO);
|
||||
p3.add(p1r);
|
||||
|
||||
if (target instanceof ProcessingTarget) {
|
||||
Graphics2D graphics = ((ProcessingTarget) target).getGraphics();
|
||||
if (target instanceof G2DTarget) {
|
||||
Graphics2D graphics = ((G2DTarget) target).getGraphics();
|
||||
graphics.setColor(color);
|
||||
GeneralPath gpath = new GeneralPath();
|
||||
gpath.moveTo(p1.x, p1.y);
|
||||
|
||||
+3
-3
@@ -202,8 +202,8 @@ public class EdgeLabelRenderer implements Renderer {
|
||||
Color outlineColor = outlineDependantColor.getColor(edgeColor);
|
||||
outlineColor = new Color(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue(), outlineAlpha);
|
||||
|
||||
if (target instanceof ProcessingTarget) {
|
||||
renderProcessing((ProcessingTarget) target, label, x, y, color, outlineSize, outlineColor);
|
||||
if (target instanceof G2DTarget) {
|
||||
renderG2D((G2DTarget) target, label, x, y, color, outlineSize, outlineColor);
|
||||
} else if (target instanceof SVGTarget) {
|
||||
renderSVG((SVGTarget) target, edge, label, x, y, color, outlineSize, outlineColor);
|
||||
} else if (target instanceof PDFTarget) {
|
||||
@@ -211,7 +211,7 @@ public class EdgeLabelRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void renderProcessing(ProcessingTarget target, String label, float x, float y, Color color, float outlineSize, Color outlineColor) {
|
||||
public void renderG2D(G2DTarget target, String label, float x, float y, Color color, float outlineSize, Color outlineColor) {
|
||||
Graphics2D graphics = target.getGraphics();
|
||||
|
||||
graphics.setFont(font);
|
||||
|
||||
+6
-6
@@ -205,8 +205,8 @@ public class EdgeRenderer implements Renderer {
|
||||
Vector v2 = new Vector(x, y);
|
||||
v2.add(size, size);
|
||||
|
||||
if (renderTarget instanceof ProcessingTarget) {
|
||||
Graphics2D graphics = ((ProcessingTarget) renderTarget).getGraphics();
|
||||
if (renderTarget instanceof G2DTarget) {
|
||||
Graphics2D graphics = ((G2DTarget) renderTarget).getGraphics();
|
||||
|
||||
graphics.setStroke(new BasicStroke(thickness));
|
||||
graphics.setColor(color);
|
||||
@@ -279,8 +279,8 @@ public class EdgeRenderer implements Renderer {
|
||||
v2.add(new Vector(x2, y2));
|
||||
v2.add(n);
|
||||
|
||||
if (renderTarget instanceof ProcessingTarget) {
|
||||
Graphics2D graphics = ((ProcessingTarget) renderTarget).getGraphics();
|
||||
if (renderTarget instanceof G2DTarget) {
|
||||
Graphics2D graphics = ((G2DTarget) renderTarget).getGraphics();
|
||||
|
||||
graphics.setStroke(new BasicStroke(thickness));
|
||||
graphics.setColor(color);
|
||||
@@ -355,8 +355,8 @@ public class EdgeRenderer implements Renderer {
|
||||
y1 = direction.y;
|
||||
}
|
||||
|
||||
if (renderTarget instanceof ProcessingTarget) {
|
||||
Graphics2D graphics = ((ProcessingTarget) renderTarget).getGraphics();
|
||||
if (renderTarget instanceof G2DTarget) {
|
||||
Graphics2D graphics = ((G2DTarget) renderTarget).getGraphics();
|
||||
graphics.setStroke(new BasicStroke(thickness, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
|
||||
graphics.setColor(color);
|
||||
Line2D.Float line = new Line2D.Float(x1, y1, x2, y2);
|
||||
|
||||
+3
-3
@@ -176,8 +176,8 @@ public class NodeLabelRenderer implements Renderer {
|
||||
}
|
||||
boxColor = new Color(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue(), boxAlpha);
|
||||
|
||||
if (target instanceof ProcessingTarget) {
|
||||
renderProcessing((ProcessingTarget) target, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
|
||||
if (target instanceof G2DTarget) {
|
||||
renderG2D((G2DTarget) target, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
|
||||
} else if (target instanceof SVGTarget) {
|
||||
renderSVG((SVGTarget) target, node, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
|
||||
} else if (target instanceof PDFTarget) {
|
||||
@@ -185,7 +185,7 @@ public class NodeLabelRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void renderProcessing(ProcessingTarget target, String label, float x, float y, int fontSize, Color color, float outlineSize, Color outlineColor, boolean showBox, Color boxColor) {
|
||||
public void renderG2D(G2DTarget target, String label, float x, float y, int fontSize, Color color, float outlineSize, Color outlineColor, boolean showBox, Color boxColor) {
|
||||
Graphics2D graphics = target.getGraphics();
|
||||
|
||||
Font font = fontCache.get(fontSize);
|
||||
|
||||
+3
-3
@@ -76,8 +76,8 @@ public class NodeRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void render(Item item, RenderTarget target, PreviewProperties properties) {
|
||||
if (target instanceof ProcessingTarget) {
|
||||
renderProcessing(item, (ProcessingTarget) target, properties);
|
||||
if (target instanceof G2DTarget) {
|
||||
renderG2D(item, (G2DTarget) target, properties);
|
||||
} else if (target instanceof SVGTarget) {
|
||||
renderSVG(item, (SVGTarget) target, properties);
|
||||
} else if (target instanceof PDFTarget) {
|
||||
@@ -85,7 +85,7 @@ public class NodeRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void renderProcessing(Item item, ProcessingTarget target, PreviewProperties properties) {
|
||||
public void renderG2D(Item item, G2DTarget target, PreviewProperties properties) {
|
||||
//Params
|
||||
Float x = item.getData(NodeItem.X);
|
||||
Float y = item.getData(NodeItem.Y);
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário