Author: kono
Date: 2010-06-25 14:29:09 -0700 (Fri, 25 Jun 2010)
New Revision: 20664
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsPool.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphics.java
Log:
Default image will be used for broken images.
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsPool.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsPool.java
2010-06-25 21:27:46 UTC (rev 20663)
+++ cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsPool.java
2010-06-25 21:29:09 UTC (rev 20664)
@@ -25,6 +25,7 @@
import cytoscape.Cytoscape;
import cytoscape.CytoscapeInit;
+import cytoscape.logger.CyLogger;
import cytoscape.task.ui.JTaskConfig;
import cytoscape.task.util.TaskManager;
import cytoscape.visual.SubjectBase;
@@ -33,6 +34,8 @@
public class CustomGraphicsPool extends SubjectBase implements
PropertyChangeListener {
+ private static final CyLogger logger = CyLogger.getLogger();
+
private static final int TIMEOUT = 1000;
private static final int NUM_THREADS = 8;
@@ -82,16 +85,12 @@
prop.load(new FileInputStream(new
File(imageHomeDirectory,
METADATA_FILE)));
System.out.println("Image prop loaded!");
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- System.out.println("Image metadata not found!");
+ } catch (Exception e) {
+ logger.warning("Custom Graphics Metadata was not found.
This is normal for the first time.");
+ // Restore process is not necessary.
return;
- } catch (IOException e1) {
- e1.printStackTrace();
- System.out.println("Image metadata not found!");
- return;
}
-
+
if (this.imageHomeDirectory != null &&
imageHomeDirectory.isDirectory()) {
final File[] imageFiles =
imageHomeDirectory.listFiles();
final Map<Future<BufferedImage>, String> fMap = new
HashMap<Future<BufferedImage>, String>();
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphics.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphics.java
2010-06-25 21:27:46 UTC (rev 20663)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphics.java
2010-06-25 21:29:09 UTC (rev 20664)
@@ -6,16 +6,30 @@
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
+import cytoscape.Cytoscape;
+import cytoscape.logger.CyLogger;
import cytoscape.render.stateful.CustomGraphic;
import cytoscape.render.stateful.PaintFactory;
import cytoscape.visual.customgraphic.paint.TexturePaintFactory;
public class URLImageCustomGraphics extends AbstractCyCustomGraphics {
+
+ private static BufferedImage DEF_IMAGE;
+
+ static {
+ try {
+ DEF_IMAGE
=ImageIO.read(Cytoscape.class.getResource("images/ximian/stock_dialog-warning-32.png"));
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
private static final String DEF_TAG = "bitmap image";
// Defining padding
private static final double PAD = 10;
@@ -70,18 +84,23 @@
cgList.add(cg);
}
- private void createImage(String url) throws IOException {
+ private void createImage(String url) throws MalformedURLException {
if (url == null)
throw new IllegalStateException("URL string cannot be
null.");
- final URL imageLocation = new URL(url);
+ URL imageLocation = new URL(url);
+
sourceUrl = imageLocation;
- originalImage = ImageIO.read(imageLocation);
+ try {
+ originalImage = ImageIO.read(imageLocation);
+ } catch (IOException e) {
+ originalImage = DEF_IMAGE;
+ CyLogger.getLogger().warn("Broken Image found. Default
is used instead.");
+ }
- if (originalImage == null)
- throw new IOException(
- "Could not create an image from this
location: "
- +
imageLocation.toString());
+ if (originalImage == null) {
+ originalImage = DEF_IMAGE;
+ }
}
@Override
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.