Search in sources :

Example 6 with ObjectPosition

use of org.cytoscape.view.presentation.property.values.ObjectPosition in project cytoscape-impl by cytoscape.

the class CustomGraphicsPositionCalculator method transform.

/**
 * Creates new custom graphics in new location
 */
public static CustomGraphicLayer transform(final ObjectPosition p, final double width, final double height, final CustomGraphicLayer layer) {
    final Position anc = p.getAnchor();
    final Position ancN = p.getTargetAnchor();
    final double cgW = layer.getBounds2D().getWidth();
    final double cgH = layer.getBounds2D().getHeight();
    final Float[] disp1 = DISPLACEMENT_MAP.get(anc);
    final Float[] disp2 = DISPLACEMENT_MAP.get(ancN);
    // 1. Displacement for graphics
    final double dispX = -disp1[0] * width;
    final double dispY = -disp1[1] * height;
    final double dispNX = disp2[0] * cgW;
    final double dispNY = disp2[1] * cgH;
    // calc total and apply transform
    double totalDispX = dispX + dispNX + p.getOffsetX();
    double totalDispY = dispY + dispNY + p.getOffsetY();
    final AffineTransform tf = AffineTransform.getTranslateInstance(totalDispX, totalDispY);
    return layer.transform(tf);
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) Position(org.cytoscape.view.presentation.property.values.Position) AffineTransform(java.awt.geom.AffineTransform)

Example 7 with ObjectPosition

use of org.cytoscape.view.presentation.property.values.ObjectPosition in project cytoscape-impl by cytoscape.

the class CustomGraphicsInfo method createLayers.

public List<CustomGraphicLayer> createLayers(final CyNetworkView netView, final View<CyNode> nodeView, final NodeDetails details, final Set<VisualPropertyDependency<?>> dependencies) {
    final List<CustomGraphicLayer> transformedLayers = new ArrayList<>();
    if (customGraphics == null)
        return transformedLayers;
    final List<? extends CustomGraphicLayer> originalLayers = customGraphics.getLayers(netView, nodeView);
    if (originalLayers == null || originalLayers.isEmpty())
        return transformedLayers;
    final CyNode node = nodeView.getModel();
    final float fitRatio = customGraphics.getFitRatio();
    // Check dependency. Sync size or not.
    boolean sync = syncToNode(dependencies);
    Double cgSize = size;
    ObjectPosition cgPos = position;
    final double nw = details.getWidth(node);
    final double nh = details.getHeight(node);
    for (CustomGraphicLayer layer : originalLayers) {
        // Assume it's a Ding layer
        CustomGraphicLayer finalLayer = layer;
        // Resize the layer
        double cgw = 0.0;
        double cgh = 0.0;
        if (sync) {
            // Size is locked to node size.
            final float bw = details.getBorderWidth(node);
            cgw = nw - bw;
            cgh = nh - bw;
        } else {
            // Width and height should be set to custom size
            if (cgSize == null) {
                final VisualProperty<Double> sizeVP = DVisualLexicon.getAssociatedCustomGraphicsSizeVP(visualProperty);
                cgSize = nodeView.getVisualProperty(sizeVP);
            }
            if (cgSize != null)
                cgw = cgh = cgSize;
        }
        if (cgw > 0.0 && cgh > 0.0)
            finalLayer = syncSize(layer, cgw, cgh, fitRatio);
        // Move the layer to the correct position
        if (cgPos == null)
            cgPos = ObjectPosition.DEFAULT_POSITION;
        finalLayer = moveLayer(finalLayer, cgPos, nw, nh);
        transformedLayers.add(finalLayer);
    }
    return transformedLayers;
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) ImageCustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode)

Example 8 with ObjectPosition

use of org.cytoscape.view.presentation.property.values.ObjectPosition in project cytoscape-impl by cytoscape.

the class ObjectPlacerGraphic method applyPosition.

/**
 * Applies the new ObjectPosition to the graphic.
 */
public void applyPosition() {
    xOffset = (int) (p.getOffsetX() * offsetRatio);
    yOffset = (int) (p.getOffsetY() * offsetRatio);
    justify = p.getJustify();
    final Position nodeAnchor = p.getTargetAnchor();
    if (nodeAnchor != NONE) {
        bestNodeX = nodeAnchor.ordinal() % 3;
        bestNodeY = nodeAnchor.ordinal() / 3;
    }
    final Position labelAnchor = p.getAnchor();
    if (labelAnchor != NONE) {
        bestLabelX = labelAnchor.ordinal() % 3;
        bestLabelY = labelAnchor.ordinal() / 3;
    }
    if ((nodeAnchor != NONE || labelAnchor != NONE) && npoints != null && lxpoints != null && lypoints != null) {
        if (npoints.length > bestNodeX && lxpoints.length > bestLabelX)
            xPos = npoints[bestNodeX] - lxpoints[bestLabelX];
        if (npoints.length > bestNodeY && lypoints.length > bestLabelY)
            yPos = npoints[bestNodeY] - lypoints[bestLabelY];
    }
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) Position(org.cytoscape.view.presentation.property.values.Position)

Example 9 with ObjectPosition

use of org.cytoscape.view.presentation.property.values.ObjectPosition in project cytoscape-impl by cytoscape.

the class ObjectPositionCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    final JLabel label = new JLabel();
    if (isSelected) {
        label.setBackground(table.getSelectionBackground());
        label.setForeground(table.getSelectionForeground());
    } else {
        label.setBackground(table.getBackground());
        label.setForeground(table.getForeground());
    }
    if ((value != null) && value instanceof ObjectPosition) {
        final ObjectPosition lp = (ObjectPosition) value;
        label.setIcon(VisualPropertyIconFactory.createIcon(lp, ICON_WIDTH, ICON_HEIGHT));
        label.setVerticalAlignment(SwingConstants.CENTER);
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }
    return label;
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) JLabel(javax.swing.JLabel)

Example 10 with ObjectPosition

use of org.cytoscape.view.presentation.property.values.ObjectPosition in project cytoscape-impl by cytoscape.

the class DNodeDetails method getLabelOffsetVectorX.

@Override
public float getLabelOffsetVectorX(final CyNode node, final int labelInx) {
    // Check bypass
    final DNodeView dnv = dGraphView.getDNodeView(node);
    if (dnv.isValueLocked(NODE_LABEL_POSITION)) {
        final ObjectPosition lp = dnv.getVisualProperty(NODE_LABEL_POSITION);
        return (float) lp.getOffsetX();
    }
    final Object o = m_labelOffsetXs.get(node);
    if (o == null)
        if (m_labelOffsetVectorXDefault == null)
            return super.getLabelOffsetVectorX(node, labelInx);
        else
            return m_labelOffsetVectorXDefault.floatValue();
    return ((Double) o).floatValue();
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition)

Aggregations

ObjectPosition (org.cytoscape.view.presentation.property.values.ObjectPosition)13 Position (org.cytoscape.view.presentation.property.values.Position)4 Color (java.awt.Color)2 Font (java.awt.Font)2 CustomGraphicLayer (org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer)2 NodeShape (org.cytoscape.view.presentation.property.values.NodeShape)2 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 AffineTransform (java.awt.geom.AffineTransform)1 ArrayList (java.util.ArrayList)1 Icon (javax.swing.Icon)1 JLabel (javax.swing.JLabel)1 DArrowShape (org.cytoscape.ding.DArrowShape)1 DNodeShape (org.cytoscape.ding.DNodeShape)1 DLineType (org.cytoscape.ding.impl.DLineType)1 CustomGraphicsVisualProperty (org.cytoscape.ding.impl.visualproperty.CustomGraphicsVisualProperty)1 ObjectPositionVisualProperty (org.cytoscape.ding.impl.visualproperty.ObjectPositionVisualProperty)1 CyNode (org.cytoscape.model.CyNode)1 CyCustomGraphics (org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)1 ImageCustomGraphicLayer (org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer)1