Skip to content

Image preview plugin to 0.9.X #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: image-preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gephi-plugin-image-preview
Submodule gephi-plugin-image-preview deleted from e355bc
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,45 @@

<dependencies>

<dependency>
<groupId>org.gephi</groupId>
<artifactId>preview-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>core-library-wrapper</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>preview-api</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>${netbeans.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.processing/core -->
<dependency>
<groupId>org.processing</groupId>
<artifactId>core</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>preview-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>core-library-wrapper</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>preview-api</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-settings</artifactId>
<version>${netbeans.version}</version>
</dependency>
</dependencies>

Expand All @@ -77,11 +65,10 @@
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<author>Yitzchak Lockerman (Yale Computer Graphics Group)</author>
<sourceCodeUrl>$sourcecode_url</sourceCodeUrl>
<sourceCodeUrl>https://github.com/totetmatt/gephi-plugins/tree/image-preview</sourceCodeUrl>
<licenseName>Apache 2.0</licenseName>
<publicPackages>

<publicPackage>org.yale.cs.graphics.gephi.imagepreview</publicPackage>
<publicPackage>org.yale.cs.graphics.gephi.imagepreview</publicPackage>
</publicPackages>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,23 @@
package org.yale.cs.graphics.gephi.imagepreview;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.gephi.preview.api.G2DTarget;
import org.gephi.preview.plugin.items.AbstractItem;
import processing.core.PConstants;
import processing.core.PImage;
import org.gephi.preview.plugin.items.NodeItem;

/**
* A Item that represents a image within the file system.
* <p>
* Each instance of <code>ImageItem</code> represents a single image file. When
* the file is loaded (using one of the methods) the image data is cached in
* memory, allowing for faster rendering in the future.
* Each instance of <code>ImageItem</code> represents a single image file. When the file is loaded (using one of the methods) the image data is cached in memory, allowing for faster rendering in the
* future.
* <p>
* In addition to the cached images, the item contains all the properties of
* {@link NodeItem}.
* In addition to the cached images, the item contains all the properties of {@link NodeItem}.
*
* @author Yitzchak Lockerman
*/
Expand All @@ -58,16 +53,16 @@ public class ImageItem extends AbstractItem {
public static final String IMAGE = "Image";

/**
* The data key for accessing the Processing image file within the cache.
* The data key for accessing the image file within the cache.
*/
public static final String PROCESSING_DATA = "Processing_Data";
public static final String IMAGE_DATA = "Image_Data";

/**
* The data key for accessing the iText PDF image file within the cache.
*/
public static final String PDF_DATA = "PDF_Data";

private static final Logger logger = Logger.getLogger(ImageItem.class.getName());
private static final Logger LOG = Logger.getLogger(ImageItem.class.getName());

/**
*
Expand All @@ -78,85 +73,70 @@ public ImageItem(String source) {
}

/**
* Prepares this ImageItem to be rendered by the Processing target. Loading
* from the cache, if available. If the method is forced to load a image
* from the hard drive, it store it in the cache.
* Prepares this ImageItem to be rendered by the grapchis target. Loading from the cache, if available. If the method is forced to load a image from the hard drive, it store it in the cache.
*
* @param location_name The name of the folder to load images from.
* @param target The properties of the current rendering.
* @return A Processing image corresponding to this item.
* @param directory The name of the folder to load images from.
* @return A image corresponding to this item.
*/
public PImage renderProcessing(File location_name, G2DTarget target) {
PImage image = (PImage) data.get(PROCESSING_DATA);
public BufferedImage loadImage(File directory) {
BufferedImage image = (BufferedImage) data.get(IMAGE_DATA);
if (image == null) {
if (source instanceof String) {
File full_file = new File(location_name, (String) source);
try {
//if(target.getApplet() != null)
// image = target.getApplet().loadImage(full_file.getCanonicalPath());
// else
//based on http://processing.org/discourse/beta/num_1234546778.html
//http://forum.processing.org/topic/converting-bufferedimage-to-pimage
BufferedImage im_plane;

im_plane = ImageIO.read(full_file);
image = new PImage(im_plane.getWidth(), im_plane.getHeight(), PConstants.ARGB);
im_plane.getRGB(0, 0, image.width, image.height, image.pixels, 0, image.width);
image.updatePixels();
final File file = new File(directory, (String) source);

try {
image = ImageIO.read(file);
} catch (java.io.IOException e) {
logger.log(Level.SEVERE, "Unable to load image: " + full_file, e);
LOG.log(Level.SEVERE, "Unable to load image: " + file, e);
}
}

//If we can't render the image
if (image == null) {
logger.log(Level.WARNING, "Unable to load image: {0}", source);
LOG.log(Level.WARNING, "Unable to load image: {0}", source);
return null;
}

data.put(PROCESSING_DATA, image);
data.put(IMAGE_DATA, image);
}

return image;
}

/**
* @param location_name The name of the folder to load images from.
* @return The attribute to be added to the SVG file to represent this
* image.
* @param directory The name of the folder to load images from.
* @return The attribute to be added to the SVG file to represent this image.
*/
public String renderSVG(File location_name) {
return new File(location_name, (String) source).getAbsolutePath();
public String renderSVG(File directory) {
return new File(directory, (String) source).getAbsolutePath();
}

/**
* Prepares this ImageItem to be rendered by the PDF target. Loading from
* the cache, if available. If the method is forced to load a image from the
* hard drive, it stores it in the cache.
* Prepares this ImageItem to be rendered by the PDF target. Loading from the cache, if available. If the method is forced to load a image from the hard drive, it stores it in the cache.
*
* @param location_name The name of the folder to load images from.
* @param directory The name of the folder to load images from.
* @return A iText PDF Image corresponding to this item.
*/
public com.itextpdf.text.Image renderPDF(File location_name) {
public com.itextpdf.text.Image renderPDF(File directory) {
com.itextpdf.text.Image image = (com.itextpdf.text.Image) data.get(PDF_DATA);
if (image == null) {
if (source instanceof String) {
File full_file = new File(location_name,(String) source);
final File file = new File(directory, (String) source);

try {
image = Image.getInstance(full_file.getCanonicalPath());
image = com.itextpdf.text.Image.getInstance(file.getCanonicalPath());
} catch (BadElementException ex) {
logger.log(Level.SEVERE, "Unable to load image: " + full_file, ex);
LOG.log(Level.SEVERE, "Unable to load image: " + file, ex);
} catch (MalformedURLException ex) {
logger.log(Level.SEVERE, "Unable to load image: " + full_file, ex);
LOG.log(Level.SEVERE, "Unable to load image: " + file, ex);
} catch (IOException ex) {
logger.log(Level.SEVERE, "Unable to load image: " + full_file, ex);
LOG.log(Level.SEVERE, "Unable to load image: " + file, ex);
}

}
//If we can't render the image, fallback to the defult render
if (image == null) {
logger.log(Level.WARNING, "Unable to load image: {0}", source);
LOG.log(Level.WARNING, "Unable to load image: {0}", source);
return null;
}

Expand Down
Loading