use of org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsDetailPanel method resetButtonActionPerformed.
private void resetButtonActionPerformed(ActionEvent evt) {
if (cg == null || cg.getRenderedImage() == null)
return;
if (cg instanceof URLImageCustomGraphics) {
final Image image = ((URLImageCustomGraphics) cg).resetImage();
imageViewPanel.setImage(image);
final int w = image.getWidth(null);
final int h = image.getHeight(null);
widthTextField.setText(Integer.toString(w));
heightTextField.setText(Integer.toString(h));
cg.setWidth(w);
cg.setHeight(h);
appManager.getCurrentNetworkView().updateView();
}
}
use of org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics in project cytoscape-impl by cytoscape.
the class RestoreImageTask method restoreSampleImages.
private void restoreSampleImages() throws IOException {
// Filter by display name
final Collection<CyCustomGraphics> allGraphics = manager.getAllCustomGraphics();
final Set<String> names = new HashSet<>();
for (CyCustomGraphics<?> cg : allGraphics) names.add(cg.getDisplayName());
for (final URL imageURL : defaultImageURLs) {
final String[] parts = imageURL.getFile().split("/");
final String dispNameString = parts[parts.length - 1];
if (this.manager.getCustomGraphicsBySourceURL(imageURL) == null && !names.contains(dispNameString)) {
final CyCustomGraphics<?> cg = new URLImageCustomGraphics<>(manager.getNextAvailableID(), imageURL.toString());
if (cg != null) {
manager.addCustomGraphics(cg, imageURL);
cg.setDisplayName(dispNameString);
}
}
}
}
use of org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsManagerDialog method processFiles.
private void processFiles(final File[] files) {
for (final File file : files) {
BufferedImage img = null;
if (file.isFile()) {
try {
img = ImageIO.read(file);
} catch (IOException e) {
logger.error("Could not read file: " + file.toString(), e);
continue;
}
}
if (img != null) {
final CyCustomGraphics<?> cg = new URLImageCustomGraphics<>(manager.getNextAvailableID(), file.toString(), img);
try {
manager.addCustomGraphics(cg, file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
continue;
}
((CustomGraphicsListModel) browser.getModel()).addElement(cg);
}
}
}
use of org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics in project cytoscape-impl by cytoscape.
the class RestoreImageTask method restoreImages.
private void restoreImages() {
final CompletionService<BufferedImage> cs = new ExecutorCompletionService<BufferedImage>(imageLoaderService);
imageHomeDirectory.mkdir();
long startTime = System.currentTimeMillis();
// Load metadata first.
final Properties prop = new Properties();
try {
prop.load(new FileInputStream(new File(imageHomeDirectory, METADATA_FILE)));
logger.info("Custom Graphics Image property file loaded from: " + imageHomeDirectory);
} catch (Exception e) {
logger.info("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<>();
final Map<Future<BufferedImage>, Long> fIdMap = new HashMap<>();
final Map<Future<BufferedImage>, Set<String>> metatagMap = new HashMap<>();
final Set<File> validFiles = new HashSet<>();
try {
for (File file : imageFiles) {
if (file.toString().endsWith(IMAGE_EXT) == false)
continue;
final String fileName = file.getName();
final String key = fileName.split("\\.")[0];
final String value = prop.getProperty(key);
// Filter unnecessary files.
if (value == null || value.contains("URLImageCustomGraphics") == false)
continue;
final String[] imageProps = value.split(",");
if (imageProps == null || imageProps.length < 2)
continue;
String name = imageProps[2];
if (name.contains("___"))
name = name.replace("___", ",");
Future<BufferedImage> f = cs.submit(new LoadImageTask(file.toURI().toURL()));
validFiles.add(file);
fMap.put(f, name);
fIdMap.put(f, Long.parseLong(imageProps[1]));
String tagStr = null;
if (imageProps.length > 3) {
tagStr = imageProps[3];
final Set<String> tags = new TreeSet<>();
String[] tagParts = tagStr.split("\\" + AbstractDCustomGraphics.LIST_DELIMITER);
for (String tag : tagParts) tags.add(tag.trim());
metatagMap.put(f, tags);
}
}
for (File file : validFiles) {
if (file.toString().endsWith(IMAGE_EXT) == false)
continue;
final Future<BufferedImage> f = cs.take();
final BufferedImage image = f.get();
if (image == null)
continue;
final CyCustomGraphics<?> cg = new URLImageCustomGraphics<>(fIdMap.get(f), fMap.get(f), image);
if (cg instanceof Taggable && metatagMap.get(f) != null)
((Taggable) cg).getTags().addAll(metatagMap.get(f));
try {
final URL source = new URL(fMap.get(f));
if (source != null)
manager.addCustomGraphics(cg, source);
} catch (MalformedURLException me) {
manager.addCustomGraphics(cg, null);
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
try {
imageLoaderService.shutdown();
imageLoaderService.awaitTermination(TIMEOUT, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
double sec = (endTime - startTime) / (1000.0);
logger.info("Image loading process finished in " + sec + " sec.");
logger.info("Currently, " + (manager.getAllCustomGraphics().size() - 1) + " images are available.");
}
use of org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsManagerImpl method getAllPersistantCustomGraphics.
/* (non-Javadoc)
* @see org.cytoscape.ding.customgraphicsmgr.internal.CGM#getAllPersistantCustomGraphics()
*/
@Override
public Collection<CyCustomGraphics> getAllPersistantCustomGraphics() {
Set<CyCustomGraphics> cgSet = new HashSet<>();
for (CyCustomGraphics cg : getAllCustomGraphics()) {
// Currently, we only export URLImageCustomGraphics to the session file. This may change in the future...
if (cg instanceof URLImageCustomGraphics) {
URLImageCustomGraphics<?> urlCG = (URLImageCustomGraphics<?>) cg;
// Don't serialize bundle-generated graphics
if (urlCG.getSourceURL() != null && urlCG.getSourceURL().toString().startsWith("bundle:"))
continue;
cgSet.add(cg);
}
}
return cgSet;
}
Aggregations