Example usage for com.google.common.collect ImmutableList reverse

List of usage examples for com.google.common.collect ImmutableList reverse

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList reverse.

Prototype

public ImmutableList<E> reverse() 

Source Link

Usage

From source file:org.eclipse.elk.core.util.nodespacing.LabelAndNodeSizeProcessor.java

/**
 * Places the labels of the given port on the outside of the port's node. We suppose that the
 * first label has label side information. Those are then used for all labels. We don't support
 * having some labels above and others below incident edges.
 *
 * @param port/*ww  w.j av a 2 s .  c  o  m*/
 *            the port whose label to place.
 * @param labelSpacing
 *            spacing between labels and other objects.
 */
private void placePortLabelsOutside(final PortAdapter<?> port, final double labelSpacing) {
    ImmutableList<LabelAdapter<?>> labels = ImmutableList.copyOf(port.getLabels());
    if (labels.isEmpty()) {
        return;
    }

    // Retrieve the first label's side
    LabelSide labelSide = labels.get(0).getSide();
    // Default is BELOW.
    labelSide = labelSide == LabelSide.UNKNOWN ? LabelSide.BELOW : labelSide;

    // The initial y position we'll be starting from depends on port and label sides
    double y = 0;
    switch (port.getSide()) {
    case WEST:
    case EAST:
        if (labelSide == LabelSide.BELOW) {
            y = port.getSize().y;
        }
        break;

    case SOUTH:
        y = port.getSize().y;
        break;
    }

    // If labels are below incident edges, we simply start at a given y position and place the
    // labels downwards. Of they are placed above or if we have a northern port, however, we
    // actually need to start with the last label and place them upwards. We thus first add all
    // labels to a list that we may need to reverse
    if (port.getSide() == PortSide.NORTH || labelSide == LabelSide.ABOVE) {
        labels = labels.reverse();
    }

    for (final LabelAdapter<?> label : labels) {
        final KVector position = new KVector(label.getPosition());
        if (labelSide == LabelSide.ABOVE) {
            // Place label "above" edges
            switch (port.getSide()) {
            case WEST:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case EAST:
                position.x = port.getSize().x + labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case NORTH:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case SOUTH:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            }
        } else {
            // Place label "below" edges
            switch (port.getSide()) {
            case WEST:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            case EAST:
                position.x = port.getSize().x + labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            case NORTH:
                position.x = port.getSize().x + labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case SOUTH:
                position.x = port.getSize().x + labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            }
        }
        label.setPosition(position);
    }
}

From source file:de.cau.cs.kieler.kiml.util.nodespacing.LabelAndNodeSizeProcessor.java

/**
 * Places the labels of the given port on the inside of the port's node.
 *
 * @param port/*from w  ww.ja v a 2 s .c  om*/
 *            the port whose labels to place.
 * @param compoundNodeMode
 *            {@code true} if the node contains further nodes in the
 *            original graph. In this case, port labels are not placed next
 *            to ports, but a little down as well to avoid
 *            edge-label-crossings if the port has edges connected to the
 *            node's insides.
 * @param labelSpacing
 *            spacing between labels and other objects.
 */
private void placePortLabelsInside(final PortAdapter<?> port, final boolean compoundNodeMode,
        final double labelSpacing) {

    ImmutableList<LabelAdapter<?>> labels = ImmutableList.copyOf(port.getLabels());
    if (labels.isEmpty()) {
        return;
    }

    // The initial y position we'll be starting from depends on the port
    // side
    double y = 0;
    switch (port.getSide()) {
    case WEST:
    case EAST:
        // We need the first label's size here and we know that there is
        // at least one label
        y = compoundNodeMode && port.hasCompoundConnections() ? port.getSize().y
                : ((port.getSize().y - labels.get(0).getSize().y) / 2.0) - labelSpacing;
        break;
    case NORTH:
        y = port.getSize().y;
        break;
    case SOUTH:
        y = 0.0;
        break;
    }

    // In the usual case, we simply start at a given y position and place
    // the labels downwards.
    // For southern ports, however, we actually need to start with the last
    // label and place them
    // upwards. We thus first add all labels to a list that we may need to
    // reverse
    if (port.getSide() == PortSide.SOUTH) {
        labels = labels.reverse();
    }

    // Place da labels!
    for (final LabelAdapter<?> label : port.getLabels()) {
        final KVector position = new KVector(port.getPosition());
        switch (port.getSide()) {
        case WEST:
            position.x = port.getSize().x + labelSpacing;
            position.y = y + labelSpacing;

            y += labelSpacing + label.getSize().y;
            break;
        case EAST:
            position.x = -label.getSize().x - labelSpacing;
            position.y = y + labelSpacing;

            y += labelSpacing + label.getSize().y;
            break;
        case NORTH:
            position.x = (port.getSize().x - label.getSize().x) / 2;
            position.y = y + labelSpacing;

            y += labelSpacing + label.getSize().y;
            break;
        case SOUTH:
            position.x = (port.getSize().x - label.getSize().x) / 2;
            position.y = y - labelSpacing - label.getSize().y;

            y -= labelSpacing + label.getSize().y;
            break;
        }
        label.setPosition(position);
    }
}

From source file:de.cau.cs.kieler.kiml.util.nodespacing.LabelAndNodeSizeProcessor.java

/**
 * Places the labels of the given port on the outside of the port's node. We
 * suppose that the first label has label side information. Those are then
 * used for all labels. We don't support having some labels above and others
 * below incident edges.//w  w w .  j  a  v a  2 s.  co m
 *
 * @param port
 *            the port whose label to place.
 * @param labelSpacing
 *            spacing between labels and other objects.
 */
private void placePortLabelsOutside(final PortAdapter<?> port, final double labelSpacing) {
    ImmutableList<LabelAdapter<?>> labels = ImmutableList.copyOf(port.getLabels());
    if (labels.isEmpty()) {
        return;
    }

    // Retrieve the first label's side
    LabelSide labelSide = labels.get(0).getSide();
    // Default is BELOW.
    labelSide = labelSide == LabelSide.UNKNOWN ? LabelSide.BELOW : labelSide;

    // The initial y position we'll be starting from depends on port and
    // label sides
    double y = 0;
    switch (port.getSide()) {
    case WEST:
    case EAST:
        if (labelSide == LabelSide.BELOW) {
            y = port.getSize().y;
        }
        break;

    case SOUTH:
        y = port.getSize().y;
        break;
    }

    // If labels are below incident edges, we simply start at a given y
    // position and place the
    // labels downwards. Of they are placed above or if we have a northern
    // port, however, we
    // actually need to start with the last label and place them upwards. We
    // thus first add all
    // labels to a list that we may need to reverse
    if ((port.getSide() == PortSide.NORTH) || (labelSide == LabelSide.ABOVE)) {
        labels = labels.reverse();
    }

    for (final LabelAdapter<?> label : labels) {
        final KVector position = new KVector(label.getPosition());
        if (labelSide == LabelSide.ABOVE) {
            // Place label "above" edges
            switch (port.getSide()) {
            case WEST:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case EAST:
                position.x = port.getSize().x + labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case NORTH:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case SOUTH:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            }
        } else {
            // Place label "below" edges
            switch (port.getSide()) {
            case WEST:
                position.x = -label.getSize().x - labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            case EAST:
                position.x = port.getSize().x + labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            case NORTH:
                position.x = port.getSize().x + labelSpacing;
                position.y = y - labelSpacing - label.getSize().y;

                y -= labelSpacing + label.getSize().y;
                break;
            case SOUTH:
                position.x = port.getSize().x + labelSpacing;
                position.y = y + labelSpacing;

                y += labelSpacing + label.getSize().y;
                break;
            }
        }
        label.setPosition(position);
    }
}