Search in sources :

Example 1 with CyCustomGraphics

use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.

the class DNodeView method setCustomGraphicsPosition.

@SuppressWarnings("rawtypes")
private void setCustomGraphicsPosition(final VisualProperty<?> vp, final ObjectPosition position) {
    // No need to modify
    if (position == null)
        return;
    final VisualProperty<CyCustomGraphics> parent = getParentCustomGraphicsProperty(vp);
    if (parent == null)
        return;
    synchronized (CG_LOCK) {
        final CustomGraphicsInfo info = getCustomGraphicsInfo(parent);
        info.setPosition(position);
    }
}
Also used : CustomGraphicsInfo(org.cytoscape.graph.render.stateful.CustomGraphicsInfo) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)

Example 2 with CyCustomGraphics

use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.

the class DNodeView method getParentCustomGraphicsProperty.

@SuppressWarnings({ "rawtypes", "unchecked" })
private VisualProperty<CyCustomGraphics> getParentCustomGraphicsProperty(final VisualProperty<?> vp) {
    VisualProperty<CyCustomGraphics> parent = null;
    // Use the visual property tree to retrieve its parent.
    final VisualLexiconNode lexNode = lexicon.getVisualLexiconNode(vp);
    final Collection<VisualLexiconNode> leavs = lexNode.getParent().getChildren();
    for (VisualLexiconNode vlNode : leavs) {
        if (vlNode.getVisualProperty().getRange().getType().equals(CyCustomGraphics.class)) {
            parent = (VisualProperty<CyCustomGraphics>) vlNode.getVisualProperty();
            break;
        }
    }
    if (parent == null)
        logger.error("Associated CustomGraphics VisualProperty is missing for " + vp.getDisplayName());
    return parent;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode)

Example 3 with CyCustomGraphics

use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics 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();
}
Also used : CyCustomGraphics2ManagerImpl(org.cytoscape.ding.customgraphics.CyCustomGraphics2ManagerImpl) CyCustomGraphicsFactory(org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) CustomGraphicsManager(org.cytoscape.ding.customgraphics.CustomGraphicsManager)

Example 4 with CyCustomGraphics

use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.

the class CyCustomGraphicsCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
    } else {
        setBackground(table.getBackground());
        setForeground(table.getForeground());
    }
    if (value instanceof CyCustomGraphics) {
        final CyCustomGraphics<?> cg = (CyCustomGraphics<?>) value;
        final Image img = cg.getRenderedImage();
        setIcon(img != null ? IconUtil.resizeIcon(new ImageIcon(img), 20, 20) : null);
        setText(cg.getDisplayName());
        setHorizontalTextPosition(SwingConstants.RIGHT);
        setVerticalTextPosition(SwingConstants.CENTER);
        setIconTextGap(10);
    } else {
        setIcon(null);
        setText(null);
    }
    return this;
}
Also used : ImageIcon(javax.swing.ImageIcon) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) Image(java.awt.Image)

Example 5 with CyCustomGraphics

use of org.cytoscape.view.presentation.customgraphics.CyCustomGraphics in project cytoscape-impl by cytoscape.

the class CustomGraphicsManagerImpl method reloadMissingImageCustomGraphics.

@Override
public Collection<MissingImageCustomGraphics> reloadMissingImageCustomGraphics() {
    final Set<MissingImageCustomGraphics> reloadedSet = new HashSet<>();
    for (final MissingImageCustomGraphics mcg : missingImageCustomGraphicsSet) {
        final CyCustomGraphics cg = mcg.reloadImage();
        if (cg != null)
            reloadedSet.add(mcg);
    }
    missingImageCustomGraphicsSet.removeAll(reloadedSet);
    return reloadedSet;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) MissingImageCustomGraphics(org.cytoscape.ding.customgraphics.bitmap.MissingImageCustomGraphics) 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