Author: kono
Date: 2010-07-09 13:35:32 -0700 (Fri, 09 Jul 2010)
New Revision: 20873
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsManager.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/CyCustomGraphicsParser.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/VectorCustomGraphics.java
Log:
Vector graphics saving problem fixed.
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsManager.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsManager.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/CustomGraphicsManager.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -39,44 +39,45 @@
PropertyChangeListener {
private static final CyLogger logger = CyLogger.getLogger();
-
+
private static final int TIMEOUT = 1000;
private static final int NUM_THREADS = 8;
-
+
private static final String IMAGE_DIR_NAME = "images";
-
+
// For image I/O, PNG is used as bitmap image format.
private static final String IMAGE_EXT = "png";
private final ExecutorService imageLoaderService;
private final Map<Long, CyCustomGraphics> graphicsMap = new
ConcurrentHashMap<Long, CyCustomGraphics>();
-
- // URL to hash code map. For images associated with URL.
+
+ // URL to hash code map. For images associated with URL.
private final Map<URL, Long> sourceMap = new ConcurrentHashMap<URL,
Long>();
// Null Object
- private static final CyCustomGraphics NULL =
NullCustomGraphics.getNullObject();
-
- // Sample dynamic graphics
- private static final CyCustomGraphics ROUND_RECT_GR = new
GradientRoundRectangleLayer();
- private static final CyCustomGraphics OVAL_GR = new GradientOvalLayer();
+ private static final CyCustomGraphics NULL = NullCustomGraphics
+ .getNullObject();
+ // Default vectors
+ private static final Class<?>[] DEF_VECTORS = {
+ GradientRoundRectangleLayer.class,
GradientOvalLayer.class };
+
public static final String METADATA_FILE = "image_metadata.props";
private File imageHomeDirectory;
-
/**
- * Creates an image pool object and restore existing images from user
resource
- * directory.
+ * Creates an image pool object and restore existing images from user
+ * resource directory.
*/
public CustomGraphicsManager() {
-
+
// For loading images in parallel.
this.imageLoaderService =
Executors.newFixedThreadPool(NUM_THREADS);
graphicsMap.put(NULL.getIdentifier(), NULL);
+ restoreDefaultVectorImageObjects();
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(
Cytoscape.CYTOSCAPE_EXIT, this);
@@ -84,7 +85,6 @@
restoreImages();
}
-
/**
* Restore images from .cytoscape/images dir.
*/
@@ -105,13 +105,14 @@
try {
prop.load(new FileInputStream(new
File(imageHomeDirectory,
METADATA_FILE)));
- logger.info("Custom Graphics Image property file loaded
from: " + imageHomeDirectory );
+ logger.info("Custom Graphics Image property file loaded
from: "
+ + imageHomeDirectory);
} catch (Exception e) {
logger.warning("Custom Graphics Metadata was not found.
This is normal for the first time.");
// Restore process is not necessary.
return;
}
-
+
if (this.imageHomeDirectory != null &&
imageHomeDirectory.isDirectory()) {
final File[] imageFiles =
imageHomeDirectory.listFiles();
final Map<Future<BufferedImage>, String> fMap = new
HashMap<Future<BufferedImage>, String>();
@@ -130,9 +131,9 @@
continue;
String name = imageProps[2];
- if(name.contains("___"))
+ if (name.contains("___"))
name = name.replace("___", ",");
-
+
Future<BufferedImage> f = cs.submit(new
LoadImageTask(file
.toURI().toURL()));
fMap.put(f, name);
@@ -163,10 +164,10 @@
((Taggable)
cg).getTags().addAll(metatagMap.get(f));
graphicsMap.put(cg.getIdentifier(), cg);
-
+
try {
final URL source = new
URL(fMap.get(f));
- if(source != null)
+ if (source != null)
sourceMap.put(source,
cg.getIdentifier());
} catch (MalformedURLException me) {
continue;
@@ -189,54 +190,72 @@
e.printStackTrace();
}
- // Add vector image samples
- graphicsMap.put(ROUND_RECT_GR.getIdentifier(), ROUND_RECT_GR);
- graphicsMap.put(OVAL_GR.getIdentifier(), OVAL_GR);
-
long endTime = System.currentTimeMillis();
double sec = (endTime - startTime) / (1000.0);
logger.info("Image loading process finished in " + sec + "
sec.");
- logger.info("Currently, " + (graphicsMap.size()-1) + " images
are available.");
+ logger.info("Currently, " + (graphicsMap.size() - 1)
+ + " images are available.");
}
-
+ private void restoreDefaultVectorImageObjects() {
+
+ for (Class<?> cls : DEF_VECTORS) {
+
+ try {
+ Object obj = cls.newInstance();
+ if (obj instanceof CyCustomGraphics) {
+ graphicsMap.put( ((CyCustomGraphics)
obj).getIdentifier(), (CyCustomGraphics) obj);
+ }
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }
+
/**
* Add a custom graphics to current session.
*
- * @param hash: Hasn code of image object
- * @param graphics: Actual custom graphics object
- * @param source: Source URL of graphics (if exists. Can be null)
+ * @param hash
+ * : Hasn code of image object
+ * @param graphics
+ * : Actual custom graphics object
+ * @param source
+ * : Source URL of graphics (if exists. Can be null)
*/
- public void addGraphics(final CyCustomGraphics graphics,
- final URL source) {
- if(graphics == null)
- throw new IllegalArgumentException("Custom Graphics and
its ID should not be null.");
-
+ public void addGraphics(final CyCustomGraphics graphics, final URL
source) {
+ if (graphics == null)
+ throw new IllegalArgumentException(
+ "Custom Graphics and its ID should not
be null.");
+
// Souce URL is an optional field.
- if(source != null)
+ if (source != null)
sourceMap.put(source, graphics.getIdentifier());
-
+
graphicsMap.put(graphics.getIdentifier(), graphics);
}
/**
* Remove graphics from current session (memory).
*
- * @param id: ID of graphics (hash code)
+ * @param id
+ * : ID of graphics (hash code)
*/
public void removeGraphics(final Long id) {
final CyCustomGraphics cg = graphicsMap.get(id);
- if(cg != null && cg != NULL)
+ if (cg != null && cg != NULL)
graphicsMap.remove(id);
}
-
/**
* Get a Custom Graphics by integer ID.
*
- * @param hash Hash code of Custom Graphics object
+ * @param hash
+ * Hash code of Custom Graphics object
*
- * @return Custom Graphics if exists. Otherwise, null.
+ * @return Custom Graphics if exists. Otherwise, null.
*
*/
public CyCustomGraphics getByID(Long id) {
@@ -244,8 +263,8 @@
}
/**
- * Get Custom Graphics by source URL.
- * Images without source cannot be retreved by this method.
+ * Get Custom Graphics by source URL. Images without source cannot be
+ * retreved by this method.
*
* @param sourceURL
* @return
@@ -260,27 +279,23 @@
/**
* Get a collection of all Custom Graphics in current session.
- *
+ *
* @return
*/
public Collection<CyCustomGraphics> getAll() {
return graphicsMap.values();
}
-
/**
* Remove all custom graphics from memory.
*/
public void removeAll() {
this.graphicsMap.clear();
this.sourceMap.clear();
-
+
// Null Graphics should not be removed.
this.graphicsMap.put(NULL.getIdentifier(), NULL);
-
- // Add vector image samples
- graphicsMap.put(ROUND_RECT_GR.getIdentifier(), ROUND_RECT_GR);
- graphicsMap.put(OVAL_GR.getIdentifier(), OVAL_GR);
+
}
/**
@@ -291,17 +306,18 @@
public Properties getMetadata() {
// Null graphics object should not be in this property.
graphicsMap.remove(NULL.getIdentifier());
-
+
final Properties props = new Properties();
- // Use hash code as the key, and value will be a string
returned by toString() method.
- // This means all CyCustomGraphics implementations should have
a special toString method.
+ // Use hash code as the key, and value will be a string
returned by
+ // toString() method.
+ // This means all CyCustomGraphics implementations should have
a special
+ // toString method.
for (final CyCustomGraphics graphics : graphicsMap.values())
- props.setProperty(graphics.getIdentifier().toString(),
graphics
- .toString());
+ props.setProperty(graphics.getIdentifier().toString(),
+ graphics.toString());
graphicsMap.put(NULL.getIdentifier(), NULL);
return props;
}
-
/**
* Save images to local disk when exiting from Cytoscape.
@@ -327,7 +343,6 @@
logger.info("Image saving process finished.");
}
-
public SortedSet<Long> getIDSet() {
return new TreeSet<Long>(graphicsMap.keySet());
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/CyCustomGraphicsParser.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/CyCustomGraphicsParser.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/CyCustomGraphicsParser.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -3,7 +3,5 @@
public interface CyCustomGraphicsParser {
public CyCustomGraphics getInstance(final String entry);
- public String getVizMapPropsString(final CyCustomGraphics
customGraphics);
-
public Class<? extends CyCustomGraphics> getTargetClass();
}
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -15,51 +15,45 @@
String[] parts = entry.split(",");
if (parts == null || parts.length < 3)
return null;
-
+
final String className = parts[0];
final Long id = Long.parseLong(parts[1]);
final String name = parts[2];
-// CyCustomGraphics cg = Cytoscape.getVisualMappingManager()
-// .getCustomGraphicsManager().getByID(id);
-
-
CyCustomGraphics cg = null;
- if(cg == null) {
- // Create new one by reflection
- try {
- final Class<?> cls = Class.forName(className);
- final Constructor<?> ct =
cls.getConstructor(Long.class, String.class);
- cg = (CyCustomGraphics) ct.newInstance(id,
name);
- cg.setDisplayName(parts[2]);
- Cytoscape.getVisualMappingManager()
- .getCustomGraphicsManager().addGraphics(cg,
null);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+
+ // Create new one by reflection
+ try {
+ final Class<?> cls = Class.forName(className);
+ final Constructor<?> ct = cls.getConstructor(Long.class,
+ String.class);
+ cg = (CyCustomGraphics) ct.newInstance(id, name);
+ cg.setDisplayName(parts[2]);
+
Cytoscape.getVisualMappingManager().getCustomGraphicsManager()
+ .addGraphics(cg, null);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ return null;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ return null;
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ return null;
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ return null;
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ return null;
}
-
+
return cg;
}
@@ -67,9 +61,4 @@
return null;
}
- public String getVizMapPropsString(CyCustomGraphics customGraphics) {
- // TODO Auto-generated method stub
- return null;
- }
-
}
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -55,12 +55,6 @@
return true;
}
-
- public String getVizMapPropsString(CyCustomGraphics customGraphics) {
-
- return customGraphics.toString();
- }
-
public Class<? extends CyCustomGraphics> getTargetClass() {
return TARGET_CLASS;
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -61,6 +61,9 @@
this.props.put(COLOR2, c2);
this.tags.add("vector image, gradient");
this.fitRatio = FIT;
+
+ // Render it for static icons.
+ getRenderedImage();
}
Modified:
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/VectorCustomGraphics.java
===================================================================
---
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/VectorCustomGraphics.java
2010-07-09 19:22:55 UTC (rev 20872)
+++
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/VectorCustomGraphics.java
2010-07-09 20:35:32 UTC (rev 20873)
@@ -5,4 +5,5 @@
public interface VectorCustomGraphics {
public Map<String, CustomGraphicsProperty<?>> getGraphicsProps();
+
}
--
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.