Example usage for java.awt Point translate

List of usage examples for java.awt Point translate

Introduction

In this page you can find the example usage for java.awt Point translate.

Prototype

public void translate(int dx, int dy) 

Source Link

Document

Translates this point, at location (x,y) , by dx along the x axis and dy along the y axis so that it now represents the point (x+dx,y+dy) .

Usage

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * @param index The hex index in row major order starting with the upper-left-hand corner (0-based).
 * @return <code>Point</code> corresponding to the centre of that hex.
 *///from   www . j a  v a  2s . com
Point indexToCenterPosition(int index) {
    // get upper-left-hand corner of the hex
    Point p = indexToPosition(index);
    if (p == null)
        return p;
    // shift to the centre
    p.translate(getLayout().getDeltaX() / 2, getLayout().getDeltaY() / 2);
    return p;
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Write out place name information as non-stackable pieces which can be searched via
 * the piece inventory./*from   www  .  j  ava2 s  .  co  m*/
 *
 * @param module - Game module to write to.
 */
protected void writePlaceNames(GameModule module) {
    // write prototype
    PrototypesContainer container = module.getAllDescendantComponentsOf(PrototypesContainer.class).iterator()
            .next();
    PrototypeDefinition def = new PrototypeDefinition();
    insertComponent(def, container);
    def.setConfigureName(PLACE_NAMES);

    GamePiece gp = new BasicPiece();
    SequenceEncoder se = new SequenceEncoder(',');
    se.append(ADC2Utils.TYPE);
    gp = new Marker(Marker.ID + se.getValue(), gp);
    gp.setProperty(ADC2Utils.TYPE, PLACE_NAME);
    gp = new Immobilized(gp, Immobilized.ID + "n;V");
    def.setPiece(gp);

    // write place names as pieces with no image.
    getMainMap();
    final Point offset = getCenterOffset();
    final HashSet<String> set = new HashSet<String>();
    final Board board = getBoard();

    for (PlaceName pn : placeNames) {
        String name = pn.getText();
        Point p = pn.getPosition();
        if (p == null)
            continue;
        if (set.contains(name))
            continue;
        set.add(name);
        SetupStack stack = new SetupStack();
        insertComponent(stack, getMainMap());
        p.translate(offset.x, offset.y);
        String location = getMainMap().locationName(p);
        stack.setAttribute(SetupStack.NAME, name);
        stack.setAttribute(SetupStack.OWNING_BOARD, board.getConfigureName());

        MapGrid mg = board.getGrid();
        Zone z = null;
        if (mg instanceof ZonedGrid)
            z = ((ZonedGrid) mg).findZone(p);
        stack.setAttribute(SetupStack.X_POSITION, Integer.toString(p.x));
        stack.setAttribute(SetupStack.Y_POSITION, Integer.toString(p.y));
        if (z != null) {
            try {
                if (mg.getLocation(location) != null) {
                    assert (mg.locationName(mg.getLocation(location)).equals(location));
                    stack.setAttribute(SetupStack.USE_GRID_LOCATION, true);
                    stack.setAttribute(SetupStack.LOCATION, location);
                }
            } catch (BadCoords e) {
            }
        }

        BasicPiece bp = new BasicPiece();
        se = new SequenceEncoder(BasicPiece.ID, ';');
        se.append("").append("").append("").append(name);
        bp.mySetType(se.getValue());

        se = new SequenceEncoder(UsePrototype.ID.replaceAll(";", ""), ';');
        se.append(PLACE_NAMES);
        gp = new UsePrototype(se.getValue(), bp);

        PieceSlot ps = new PieceSlot(gp);
        insertComponent(ps, stack);
    }
}