use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics 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.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsRange method values.
@Override
public Set<CyCustomGraphics> values() {
Set<CyCustomGraphics> sortedSet = new TreeSet<>(new CGComparator());
sortedSet.addAll(manager.getAllCustomGraphics());
return sortedSet;
}
use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsTranslator method translateURL.
private CyCustomGraphics translateURL(String inputValue) {
try {
final URL url = new URL(inputValue);
String mimeType = mimeTypes.get(inputValue);
if (mimeType == null) {
URLConnection conn = url.openConnection();
if (conn == null)
return null;
mimeType = conn.getContentType();
mimeTypes.put(inputValue, mimeType);
}
for (CyCustomGraphicsFactory factory : cgMgr.getAllCustomGraphicsFactories()) {
if (factory.supportsMime(mimeType)) {
CyCustomGraphics cg = factory.getInstance(url);
if (cg != null)
return cg;
}
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return null;
}
use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.
the class CustomGraphicsManagerImpl method removeCustomGraphics.
@Override
public void removeCustomGraphics(final Long id) {
final CyCustomGraphics cg = graphicsMap.get(id);
if (cg != null && cg != NullCustomGraphics.getNullObject()) {
graphicsMap.remove(id);
this.isUsedCustomGraphics.remove(cg);
}
}
use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics 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