Search in sources :

Example 6 with CyCustomGraphics

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);
            }
        }
    }
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) URLImageCustomGraphics(org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics) URL(java.net.URL) HashSet(java.util.HashSet)

Example 7 with CyCustomGraphics

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;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) TreeSet(java.util.TreeSet) CGComparator(org.cytoscape.ding.customgraphicsmgr.internal.CGComparator)

Example 8 with CyCustomGraphics

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) CyCustomGraphicsFactory(org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 9 with CyCustomGraphics

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);
    }
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)

Example 10 with CyCustomGraphics

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;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) URLImageCustomGraphics(org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics) HashSet(java.util.HashSet)

Aggregations

CyCustomGraphics (org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)14 HashSet (java.util.HashSet)3 Image (java.awt.Image)2 URL (java.net.URL)2 Icon (javax.swing.Icon)2 ImageIcon (javax.swing.ImageIcon)2 URLImageCustomGraphics (org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics)2 CustomGraphicsInfo (org.cytoscape.graph.render.stateful.CustomGraphicsInfo)2 CyCustomGraphicsFactory (org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory)2 PercentLayout (com.l2fprod.common.swing.PercentLayout)1 Color (java.awt.Color)1 Font (java.awt.Font)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URLConnection (java.net.URLConnection)1 TreeSet (java.util.TreeSet)1 JPanel (javax.swing.JPanel)1 DArrowShape (org.cytoscape.ding.DArrowShape)1