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);
}
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;
}
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];
}
}
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;
}
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();
}
Aggregations