Search in sources :

Example 11 with CyCustomGraphics

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

the class DNodeView method setCustomGraphicsSize.

@SuppressWarnings("rawtypes")
private void setCustomGraphicsSize(final VisualProperty<Double> vp, final Double size) {
    if (size == null)
        return;
    final VisualProperty<CyCustomGraphics> parent = DVisualLexicon.getAssociatedCustomGraphicsVP(vp);
    if (parent == null)
        return;
    synchronized (CG_LOCK) {
        final CustomGraphicsInfo info = getCustomGraphicsInfo(parent);
        info.setSize(size);
    }
}
Also used : CustomGraphicsInfo(org.cytoscape.graph.render.stateful.CustomGraphicsInfo) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)

Example 12 with CyCustomGraphics

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

the class VisualPropertyIconFactory method createIcon.

public static <V> Icon createIcon(V value, int w, int h) {
    if (value == null)
        return null;
    Icon icon = null;
    if (value instanceof Color) {
        icon = new ColorIcon((Color) value, w, h, value.toString());
    } else if (value instanceof NodeShape) {
        final DNodeShape dShape;
        if (NodeShapeVisualProperty.isDefaultShape((NodeShape) value))
            dShape = DNodeShape.getDShape((NodeShape) value);
        else
            dShape = (DNodeShape) value;
        icon = new NodeIcon(dShape.getShape(), w, h, dShape.getDisplayName());
    } else if (value instanceof LineType) {
        icon = new StrokeIcon(DLineType.getDLineType((LineType) value).getStroke(2f), w, h, value.toString());
    } else if (value instanceof CyCustomGraphics) {
        final String name = ((CyCustomGraphics) value).getDisplayName();
        if (name != null)
            icon = new CustomGraphicsIcon(((CyCustomGraphics) value), w, h, name);
    } else if (value instanceof ObjectPosition) {
        icon = new ObjectPositionIcon((ObjectPosition) value, w, h, "Label");
    } else if (value instanceof Font) {
        icon = new FontFaceIcon((Font) value, w, h, "");
    } else if (value instanceof ArrowShape) {
        final ArrowShape arrowShape = (ArrowShape) value;
        final DArrowShape dShape;
        if (ArrowShapeVisualProperty.isDefaultShape(arrowShape))
            dShape = DArrowShape.getArrowShape(arrowShape);
        else
            dShape = DArrowShape.NONE;
        if (dShape.getShape() == null)
            // No arrow
            icon = new TextIcon(value, w, h, "");
        else
            icon = new ArrowIcon(dShape.getShape(), w, h, dShape.getDisplayName());
    } else if (value instanceof Bend) {
        icon = new EdgeBendIcon((Bend) value, w, h, value.toString());
    } else {
        // If not found, use return value of toString() as icon.
        icon = new TextIcon(value, w, h, value.toString());
    }
    return icon;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) Bend(org.cytoscape.view.presentation.property.values.Bend) Color(java.awt.Color) Font(java.awt.Font) ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) DNodeShape(org.cytoscape.ding.DNodeShape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) DNodeShape(org.cytoscape.ding.DNodeShape) Icon(javax.swing.Icon) LineType(org.cytoscape.view.presentation.property.values.LineType) DLineType(org.cytoscape.ding.impl.DLineType)

Example 13 with CyCustomGraphics

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

the class CyCustomGraphicsPropertyEditor method getCustomEditor.

@Override
public Component getCustomEditor() {
    System.out.println(">>>>>>>>>> " + super.getCustomEditor());
    if (editor == null) {
        editor = new JPanel(new PercentLayout(PercentLayout.HORIZONTAL, 0));
        ((JPanel) editor).setOpaque(false);
        ((JPanel) editor).add("*", label = new CyCustomGraphicsCellRenderer());
        label.setOpaque(false);
        final IconManager iconManager = serviceRegistrar.getService(IconManager.class);
        // TODO just use double-click to open editor--remove buttons!!!
        ((JPanel) editor).add(button = ComponentFactory.Helper.getFactory().createMiniButton());
        button.setText(IconManager.ICON_ELLIPSIS_H);
        button.setFont(iconManager.getIconFont(13.0f));
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                editChart();
            }
        });
        ((JPanel) editor).add(button = ComponentFactory.Helper.getFactory().createMiniButton());
        button.setText(IconManager.ICON_REMOVE);
        button.setFont(iconManager.getIconFont(13.0f));
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                CyCustomGraphics<?> old = customGraphics;
                label.setValue(null);
                customGraphics = null;
                firePropertyChange(old, null);
            }
        });
    }
    return super.getCustomEditor();
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) PercentLayout(com.l2fprod.common.swing.PercentLayout) ActionEvent(java.awt.event.ActionEvent) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) IconManager(org.cytoscape.util.swing.IconManager)

Example 14 with CyCustomGraphics

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

the class DiscreteValueList method renderIcons.

/**
 * Use current renderer to create icons.
 * @param values
 */
@SuppressWarnings("rawtypes")
private void renderIcons(final Set<T> values) {
    if (type == Font.class)
        return;
    iconMap.clear();
    final RenderingEngine<CyNetwork> engine = defViewPanel != null ? defViewPanel.getRenderingEngine() : null;
    // Current engine is not ready yet.
    if (engine != null) {
        synchronized (values) {
            for (T value : values) {
                Icon icon = null;
                if (value instanceof CyCustomGraphics) {
                    final Image img = ((CyCustomGraphics) value).getRenderedImage();
                    if (img != null)
                        icon = IconUtil.resizeIcon(new ImageIcon(img), getIconWidth(), getIconHeight());
                } else if (vp != null) {
                    icon = engine.createIcon(vp, value, getIconWidth(), getIconHeight());
                }
                if (icon != null)
                    iconMap.put(value, icon);
            }
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) CyNetwork(org.cytoscape.model.CyNetwork) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) Image(java.awt.Image)

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