use of org.cytoscape.ding.customgraphics.Taggable in project cytoscape-impl by cytoscape.
the class CustomGraphicsDetailPanel method valueChanged.
@Override
public void valueChanged(ListSelectionEvent e) {
if (!(e.getSource() instanceof CustomGraphicsBrowser) || e.getValueIsAdjusting())
return;
final CustomGraphicsBrowser browser = (CustomGraphicsBrowser) e.getSource();
cg = (CyCustomGraphics) browser.getSelectedValue();
if (cg == null) {
imageViewPanel.setImage((Image) null);
heightTextField.setText(null);
widthTextField.setText(null);
nameTextField.setText(null);
nameTextField.setToolTipText(null);
tagTextField.setText(null);
return;
}
final Image img = cg.getRenderedImage();
// Set up detail panel
imageViewPanel.setImage(img);
heightTextField.setText(Integer.toString(img.getHeight(null)));
widthTextField.setText(Integer.toString(img.getWidth(null)));
nameTextField.setText(cg.getDisplayName());
nameTextField.setToolTipText(cg.getDisplayName());
if (cg instanceof Taggable) {
final Collection<String> tags = ((Taggable) cg).getTags();
final int tagCount = tags.size();
int counter = 0;
final StringBuilder tagBuilder = new StringBuilder();
for (String tag : tags) {
tagBuilder.append(tag);
counter++;
if (tagCount != counter)
tagBuilder.append(", ");
}
tagTextField.setText(tagBuilder.toString());
tagTextField.setToolTipText(tagBuilder.toString());
}
}
use of org.cytoscape.ding.customgraphics.Taggable 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.");
}
Aggregations