use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory in project cytoscape-impl by cytoscape.
the class CustomGraphicsVisualProperty method parseSerializableString.
// Parse the string associated with our visual property. Note that we depend on the first
// part of the string being the class name that was registered with the CyCustomGraphicsManager
@Override
@SuppressWarnings("unchecked")
public CyCustomGraphics<CustomGraphicLayer> parseSerializableString(String value) {
CyCustomGraphics<CustomGraphicLayer> cg = null;
if (value != null && !NullCustomGraphics.getNullObject().toString().equals(value) && !value.contains("NullCustomGraphics")) {
String[] parts = value.split(":");
// Skip over the chart/gradient factory id
int offset = value.indexOf(":");
// First check if it's a CyCustomGraphics2
// ------------------------------
// This is hack, but we've got no other way to get our hands on the
// CyCustomGraphics2Manager this way, because the DVisualLexicon is created statically
final CyCustomGraphics2ManagerImpl cfMgr = CyCustomGraphics2ManagerImpl.getInstance();
final CyCustomGraphics2Factory<? extends CustomGraphicLayer> chartFactory = cfMgr.getCyCustomGraphics2Factory(parts[0]);
if (chartFactory != null) {
cg = (CyCustomGraphics<CustomGraphicLayer>) chartFactory.getInstance(value.substring(offset + 1));
} else {
// Then check if it's a CyCustomGraphics2
// -------------------------------
final CyCustomGraphics2ManagerImpl cgMgr = CyCustomGraphics2ManagerImpl.getInstance();
final CyCustomGraphics2Factory<? extends CustomGraphicLayer> gradFactory = cgMgr.getCyCustomGraphics2Factory(parts[0]);
if (gradFactory != null)
cg = (CyCustomGraphics<CustomGraphicLayer>) gradFactory.getInstance(value.substring(offset + 1));
}
if (cg == null) {
// Try to parse it as a regular custom graphics then
// -------------------------------------------------
// This is hack, but we've got no other way to get our hands on the
// CyCustomGraphicsManager since the DVisualLexicon is created statically
final CustomGraphicsManager cgMgr = CustomGraphicsManagerImpl.getInstance();
parts = value.split(",");
final CyCustomGraphicsFactory factory = cgMgr.getCustomGraphicsFactory(parts[0]);
if (factory != null) {
// Skip over the class name
offset = value.indexOf(",");
cg = factory.parseSerializableString(value.substring(offset + 1));
}
}
}
return cg != null ? cg : NullCustomGraphics.getNullObject();
}
use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory 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;
}
Aggregations