Example usage for java.util Arrays binarySearch

List of usage examples for java.util Arrays binarySearch

Introduction

In this page you can find the example usage for java.util Arrays binarySearch.

Prototype

public static int binarySearch(Object[] a, Object key) 

Source Link

Document

Searches the specified array for the specified object using the binary search algorithm.

Usage

From source file:com.ecyrd.jspwiki.parser.JSPWikiMarkupParser.java

private static final boolean isBlockLevel(String name) {
    return Arrays.binarySearch(BLOCK_ELEMENTS, name) >= 0;
}

From source file:net.sf.jasperreports.swing.JRViewerToolbar.java

void btnZoomInActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnZoomInActionPerformed
{//GEN-HEADEREND:event_btnZoomInActionPerformed
 // Add your handling code here:
    btnActualSize.setSelected(false);//from  ww  w . j a  v a  2s.  c  o m
    btnFitPage.setSelected(false);
    btnFitWidth.setSelected(false);

    int newZoomInt = (int) (100 * getZoomRatio());
    int index = Arrays.binarySearch(zooms, newZoomInt);
    if (index < 0) {
        viewerContext.setZoomRatio(zooms[-index - 1] / 100f);
    } else if (index < cmbZoom.getModel().getSize() - 1) {
        viewerContext.setZoomRatio(zooms[index + 1] / 100f);
    }
}

From source file:net.opentsdb.tools.ConfigArgP.java

/**
 * Determines if the passed key is contained in the non option args
 * @param nonOptionKey The non option key to check for
 * @return true if the passed key is present, false otherwise
 */// w w  w  .java 2 s. c  o m
public boolean hasNonOption(String nonOptionKey) {
    if (nonOptionArgs == null || nonOptionArgs.length == 0 || nonOptionKey == null
            || nonOptionKey.trim().isEmpty())
        return false;
    return Arrays.binarySearch(nonOptionArgs, nonOptionKey) >= 0;
}

From source file:net.countercraft.movecraft.async.translation.TranslationTask.java

@Override
public void excecute() {
    MovecraftLocation[] blocksList = data.getBlockList();

    final int[] fallThroughBlocks = new int[] { 0, 8, 9, 10, 11, 31, 37, 38, 39, 40, 50, 51, 55, 59, 63, 65, 68,
            69, 70, 72, 75, 76, 77, 78, 83, 85, 93, 94, 111, 141, 142, 143, 171 };

    // blockedByWater=false means an ocean-going vessel
    boolean waterCraft = !getCraft().getType().blockedByWater();
    boolean hoverCraft = getCraft().getType().getCanHover();

    boolean airCraft = getCraft().getType().blockedByWater();

    int hoverLimit = getCraft().getType().getHoverLimit();

    Player craftPilot = CraftManager.getInstance().getPlayerFromCraft(getCraft());

    int[][][] hb = getCraft().getHitBox();
    if (hb == null)
        return;//  w w  w.j  a va  2  s . com

    // start by finding the crafts borders
    int minY = 65535;
    int maxY = -65535;
    for (int[][] i1 : hb) {
        for (int[] i2 : i1) {
            if (i2 != null) {
                if (i2[0] < minY) {
                    minY = i2[0];
                }
                if (i2[1] > maxY) {
                    maxY = i2[1];
                }
            }
        }
    }
    int maxX = getCraft().getMinX() + hb.length;
    int maxZ = getCraft().getMinZ() + hb[0].length; // safe because if the first x array doesn't have a z array, then it wouldn't be the first x array
    int minX = getCraft().getMinX();
    int minZ = getCraft().getMinZ();

    // treat sinking crafts specially
    if (getCraft().getSinking()) {
        waterCraft = true;
        hoverCraft = false;
    }

    if (getCraft().getDisabled() && (!getCraft().getSinking())) {
        fail(String.format(I18nSupport.getInternationalisedString("Craft is disabled!")));
    }

    // check the maxheightaboveground limitation, move 1 down if that limit is exceeded
    if (getCraft().getType().getMaxHeightAboveGround() > 0 && data.getDy() >= 0) {
        int x = getCraft().getMaxX() + getCraft().getMinX();
        x = x >> 1;
        int y = getCraft().getMaxY();
        int z = getCraft().getMaxZ() + getCraft().getMinZ();
        z = z >> 1;
        int cy = getCraft().getMinY();
        boolean done = false;
        while (!done) {
            cy = cy - 1;
            if (getCraft().getW().getBlockTypeIdAt(x, cy, z) != 0)
                done = true;
            if (cy <= 1)
                done = true;
        }
        if (y - cy > getCraft().getType().getMaxHeightAboveGround()) {
            data.setDy(-1);
        }
    }

    // Find the waterline from the surrounding terrain or from the static level in the craft type
    int waterLine = 0;
    if (waterCraft) {
        if (getCraft().getType().getStaticWaterLevel() != 0) {
            if (waterLine <= maxY + 1) {
                waterLine = getCraft().getType().getStaticWaterLevel();
            }
        } else {
            // figure out the water level by examining blocks next to the outer boundaries of the craft
            for (int posY = maxY + 1; (posY >= minY - 1) && (waterLine == 0); posY--) {
                int numWater = 0;
                int numAir = 0;
                int posX;
                int posZ;
                posZ = minZ - 1;
                for (posX = minX - 1; (posX <= maxX + 1) && (waterLine == 0); posX++) {
                    int typeID = getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId();
                    if (typeID == 9)
                        numWater++;
                    if (typeID == 0)
                        numAir++;
                }
                posZ = maxZ + 1;
                for (posX = minX - 1; (posX <= maxX + 1) && (waterLine == 0); posX++) {
                    int typeID = getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId();
                    if (typeID == 9)
                        numWater++;
                    if (typeID == 0)
                        numAir++;
                }
                posX = minX - 1;
                for (posZ = minZ; (posZ <= maxZ) && (waterLine == 0); posZ++) {
                    int typeID = getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId();
                    if (typeID == 9)
                        numWater++;
                    if (typeID == 0)
                        numAir++;
                }
                posX = maxX + 1;
                for (posZ = minZ; (posZ <= maxZ) && (waterLine == 0); posZ++) {
                    int typeID = getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId();
                    if (typeID == 9)
                        numWater++;
                    if (typeID == 0)
                        numAir++;
                }
                if (numWater > numAir) {
                    waterLine = posY;
                }
            }
        }

        // now add all the air blocks found within the craft's hitbox immediately above the waterline and below to the craft blocks so they will be translated
        HashSet<MovecraftLocation> newHSBlockList = new HashSet<MovecraftLocation>(Arrays.asList(blocksList));
        int posY = waterLine + 1;
        for (int posX = minX; posX < maxX; posX++) {
            for (int posZ = minZ; posZ < maxZ; posZ++) {
                if (hb[posX - minX] != null) {
                    if (hb[posX - minX][posZ - minZ] != null) {
                        if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 0
                                && posY > hb[posX - minX][posZ - minZ][0]
                                && posY < hb[posX - minX][posZ - minZ][1]) {
                            MovecraftLocation l = new MovecraftLocation(posX, posY, posZ);
                            newHSBlockList.add(l);
                        }
                    }
                }
            }
        }
        // dont check the hitbox for the underwater portion. Otherwise open-hulled ships would flood.
        for (posY = waterLine; posY >= minY; posY--) {
            for (int posX = minX; posX < maxX; posX++) {
                for (int posZ = minZ; posZ < maxZ; posZ++) {
                    if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 0) {
                        MovecraftLocation l = new MovecraftLocation(posX, posY, posZ);
                        newHSBlockList.add(l);
                    }
                }
            }
        }

        blocksList = newHSBlockList.toArray(new MovecraftLocation[newHSBlockList.size()]);
    }

    // check for fuel, burn some from a furnace if needed. Blocks of coal are supported, in addition to coal and charcoal
    double fuelBurnRate = getCraft().getType().getFuelBurnRate();
    // going down doesn't require fuel
    if (data.getDy() == -1 && data.getDx() == 0 && data.getDz() == 0)
        fuelBurnRate = 0.0;

    if (fuelBurnRate != 0.0 && getCraft().getSinking() == false) {
        if (getCraft().getBurningFuel() < fuelBurnRate) {
            Block fuelHolder = null;
            for (MovecraftLocation bTest : blocksList) {
                Block b = getCraft().getW().getBlockAt(bTest.getX(), bTest.getY(), bTest.getZ());
                if (b.getTypeId() == 61) {
                    InventoryHolder inventoryHolder = (InventoryHolder) b.getState();
                    if (inventoryHolder.getInventory().contains(263)
                            || inventoryHolder.getInventory().contains(173)) {
                        fuelHolder = b;
                    }
                }
            }
            if (fuelHolder == null) {
                fail(String.format(
                        I18nSupport.getInternationalisedString("Translation - Failed Craft out of fuel")));
            } else {
                InventoryHolder inventoryHolder = (InventoryHolder) fuelHolder.getState();
                if (inventoryHolder.getInventory().contains(263)) {
                    ItemStack iStack = inventoryHolder.getInventory()
                            .getItem(inventoryHolder.getInventory().first(263));
                    int amount = iStack.getAmount();
                    if (amount == 1) {
                        inventoryHolder.getInventory().remove(iStack);
                    } else {
                        iStack.setAmount(amount - 1);
                    }
                    getCraft().setBurningFuel(getCraft().getBurningFuel() + 7.0);
                } else {
                    ItemStack iStack = inventoryHolder.getInventory()
                            .getItem(inventoryHolder.getInventory().first(173));
                    int amount = iStack.getAmount();
                    if (amount == 1) {
                        inventoryHolder.getInventory().remove(iStack);
                    } else {
                        iStack.setAmount(amount - 1);
                    }
                    getCraft().setBurningFuel(getCraft().getBurningFuel() + 79.0);

                }
            }
        } else {
            getCraft().setBurningFuel(getCraft().getBurningFuel() - fuelBurnRate);
        }
    }

    List<MovecraftLocation> tempBlockList = new ArrayList<MovecraftLocation>();
    HashSet<MovecraftLocation> existingBlockSet = new HashSet<MovecraftLocation>(Arrays.asList(blocksList));
    HashSet<EntityUpdateCommand> entityUpdateSet = new HashSet<EntityUpdateCommand>();
    Set<MapUpdateCommand> updateSet = new HashSet<MapUpdateCommand>();

    data.setCollisionExplosion(false);
    Set<MapUpdateCommand> explosionSet = new HashSet<MapUpdateCommand>();

    List<Material> harvestBlocks = getCraft().getType().getHarvestBlocks();
    List<MovecraftLocation> harvestedBlocks = new ArrayList<MovecraftLocation>();
    List<MovecraftLocation> destroyedBlocks = new ArrayList<MovecraftLocation>();
    List<Material> harvesterBladeBlocks = getCraft().getType().getHarvesterBladeBlocks();

    int hoverOver = data.getDy();
    int craftMinY = 0;
    int craftMaxY = 0;
    boolean clearNewData = false;
    boolean hoverUseGravity = getCraft().getType().getUseGravity();
    boolean checkHover = (data.getDx() != 0 || data.getDz() != 0);// we want to check only horizontal moves
    boolean canHoverOverWater = getCraft().getType().getCanHoverOverWater();
    boolean townyEnabled = Movecraft.getInstance().getTownyPlugin() != null;
    boolean explosionBlockedByTowny = false;
    boolean moveBlockedByTowny = false;
    boolean validateTownyExplosion = false;
    String townName = "";

    Set<TownBlock> townBlockSet = new HashSet<TownBlock>();
    TownyWorld townyWorld = null;
    TownyWorldHeightLimits townyWorldHeightLimits = null;

    if (townyEnabled && Settings.TownyBlockMoveOnSwitchPerm) {
        townyWorld = TownyUtils.getTownyWorld(getCraft().getW());
        if (townyWorld != null) {
            townyEnabled = townyWorld.isUsingTowny();
            if (townyEnabled) {
                townyWorldHeightLimits = TownyUtils.getWorldLimits(getCraft().getW());
                if (getCraft().getType().getCollisionExplosion() != 0.0F) {
                    validateTownyExplosion = true;
                }
            }
        }
    } else {
        townyEnabled = false;
    }

    for (int i = 0; i < blocksList.length; i++) {
        MovecraftLocation oldLoc = blocksList[i];
        MovecraftLocation newLoc = oldLoc.translate(data.getDx(), data.getDy(), data.getDz());

        if (newLoc.getY() > data.getMaxHeight() && newLoc.getY() > oldLoc.getY()) {
            fail(String.format(
                    I18nSupport.getInternationalisedString("Translation - Failed Craft hit height limit")));
            break;
        } else if (newLoc.getY() < data.getMinHeight() && newLoc.getY() < oldLoc.getY()
                && getCraft().getSinking() == false) {
            fail(String.format(I18nSupport
                    .getInternationalisedString("Translation - Failed Craft hit minimum height limit")));
            break;
        }

        boolean blockObstructed = false;
        boolean harvestBlock = false;
        boolean bladeOK = true;
        Material testMaterial;

        Location plugLoc = new Location(getCraft().getW(), newLoc.getX(), newLoc.getY(), newLoc.getZ());
        if (craftPilot != null) {
            // See if they are permitted to build in the area, if WorldGuard integration is turned on
            if (Movecraft.getInstance().getWorldGuardPlugin() != null
                    && Settings.WorldGuardBlockMoveOnBuildPerm) {
                if (Movecraft.getInstance().getWorldGuardPlugin().canBuild(craftPilot, plugLoc) == false) {
                    fail(String.format(I18nSupport.getInternationalisedString(
                            "Translation - Failed Player is not permitted to build in this WorldGuard region")
                            + " @ %d,%d,%d", oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()));
                    break;
                }
            }
        }
        Player p;
        if (craftPilot == null) {
            p = getCraft().getNotificationPlayer();
        } else {
            p = craftPilot;
        }
        if (p != null) {
            if (Movecraft.getInstance().getWorldGuardPlugin() != null
                    && Movecraft.getInstance().getWGCustomFlagsPlugin() != null
                    && Settings.WGCustomFlagsUsePilotFlag) {
                LocalPlayer lp = Movecraft.getInstance().getWorldGuardPlugin().wrapPlayer(p);
                WGCustomFlagsUtils WGCFU = new WGCustomFlagsUtils();
                if (!WGCFU.validateFlag(plugLoc, Movecraft.FLAG_MOVE, lp)) {
                    fail(String
                            .format(I18nSupport.getInternationalisedString("WGCustomFlags - Translation Failed")
                                    + " @ %d,%d,%d", oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()));
                    break;
                }
            }
            if (townyEnabled) {
                TownBlock townBlock = TownyUtils.getTownBlock(plugLoc);
                if (townBlock != null && !townBlockSet.contains(townBlock)) {
                    if (validateTownyExplosion) {
                        if (!explosionBlockedByTowny) {
                            if (!TownyUtils.validateExplosion(townBlock)) {
                                explosionBlockedByTowny = true;
                            }
                        }
                    }
                    if (TownyUtils.validateCraftMoveEvent(p, plugLoc, townyWorld)) {
                        townBlockSet.add(townBlock);
                    } else {
                        int y = plugLoc.getBlockY();
                        boolean oChange = false;
                        if (craftMinY > y) {
                            craftMinY = y;
                            oChange = true;
                        }
                        if (craftMaxY < y) {
                            craftMaxY = y;
                            oChange = true;
                        }
                        if (oChange) {
                            boolean failed = false;
                            Town town = TownyUtils.getTown(townBlock);
                            if (town != null) {
                                Location locSpawn = TownyUtils.getTownSpawn(townBlock);
                                if (locSpawn != null) {
                                    if (!townyWorldHeightLimits.validate(y, locSpawn.getBlockY())) {
                                        failed = true;
                                    }
                                } else {
                                    failed = true;
                                }
                                if (failed) {
                                    if (Movecraft.getInstance().getWorldGuardPlugin() != null
                                            && Movecraft.getInstance().getWGCustomFlagsPlugin() != null
                                            && Settings.WGCustomFlagsUsePilotFlag) {
                                        LocalPlayer lp = Movecraft.getInstance().getWorldGuardPlugin()
                                                .wrapPlayer(p);
                                        ApplicableRegionSet regions = Movecraft.getInstance()
                                                .getWorldGuardPlugin().getRegionManager(plugLoc.getWorld())
                                                .getApplicableRegions(plugLoc);
                                        if (regions.size() != 0) {
                                            WGCustomFlagsUtils WGCFU = new WGCustomFlagsUtils();
                                            if (WGCFU.validateFlag(plugLoc, Movecraft.FLAG_MOVE, lp)) {
                                                failed = false;
                                            }
                                        }
                                    }
                                }
                                if (failed) {
                                    townName = town.getName();
                                    moveBlockedByTowny = true;
                                }
                            }
                        }
                    }
                }
            }
        }

        //check for chests around
        testMaterial = getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getType();
        if (testMaterial.equals(Material.CHEST) || testMaterial.equals(Material.TRAPPED_CHEST)) {
            if (!checkChests(testMaterial, newLoc, existingBlockSet)) {
                //prevent chests collision
                fail(String.format(
                        I18nSupport.getInternationalisedString("Translation - Failed Craft is obstructed")
                                + " @ %d,%d,%d,%s",
                        newLoc.getX(), newLoc.getY(), newLoc.getZ(), getCraft().getW()
                                .getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()).getType().toString()));
                break;
            }
        }

        if (getCraft().getSinking()) {
            int testID = getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()).getTypeId();
            blockObstructed = !(Arrays.binarySearch(fallThroughBlocks, testID) >= 0)
                    && !existingBlockSet.contains(newLoc);
        } else if (!waterCraft) {
            // New block is not air or a piston head and is not part of the existing ship
            testMaterial = getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()).getType();
            blockObstructed = (!testMaterial.equals(Material.AIR)) && !existingBlockSet.contains(newLoc);
        } else {
            // New block is not air or water or a piston head and is not part of the existing ship
            testMaterial = getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()).getType();
            blockObstructed = (!testMaterial.equals(Material.AIR)
                    && !testMaterial.equals(Material.STATIONARY_WATER) && !testMaterial.equals(Material.WATER))
                    && !existingBlockSet.contains(newLoc);
        }

        boolean ignoreBlock = false;
        // air never obstructs anything (changed 4/18/2017 to prevent drilling machines)
        if (getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getType()
                .equals(Material.AIR) && blockObstructed) {
            ignoreBlock = true;
            //                  blockObstructed=false;
        }

        testMaterial = getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()).getType();
        if (blockObstructed) {
            if (hoverCraft || harvestBlocks.size() > 0) {
                // New block is not harvested block
                if (harvestBlocks.contains(testMaterial) && !existingBlockSet.contains(newLoc)) {
                    Material tmpType = getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ())
                            .getType();
                    if (harvesterBladeBlocks.size() > 0) {
                        if (!harvesterBladeBlocks.contains(tmpType)) {
                            bladeOK = false;
                        }
                    }
                    if (bladeOK) {
                        blockObstructed = false;
                        harvestBlock = true;
                        tryPutToDestroyBox(testMaterial, newLoc, harvestedBlocks, destroyedBlocks);
                        harvestedBlocks.add(newLoc);
                    }
                }
            }
        }

        if (blockObstructed || moveBlockedByTowny) {
            if (hoverCraft && checkHover) {
                //we check one up ever, if it is hovercraft and one down if it's using gravity
                if (hoverOver == 0 && newLoc.getY() + 1 <= data.getMaxHeight()) {
                    //first was checked actual level, now check if we can go up
                    hoverOver = 1;
                    data.setDy(1);
                    clearNewData = true;
                } else if (hoverOver >= 1) {
                    //check other options to go up
                    if (hoverOver < hoverLimit + 1 && newLoc.getY() + 1 <= data.getMaxHeight()) {
                        data.setDy(hoverOver + 1);
                        hoverOver += 1;
                        clearNewData = true;
                    } else {
                        if (hoverUseGravity && newLoc.getY() - hoverOver - 1 >= data.getMinHeight()) {
                            //we are on the maximum of top 
                            //if we can't go up so we test bottom side
                            data.setDy(-1);
                            hoverOver = -1;
                        } else {
                            // no way - back to original dY, turn off hovercraft for this move
                            // and get original data again for all explosions
                            data.setDy(0);
                            hoverOver = 0;
                            hoverCraft = false;
                            hoverUseGravity = false;
                        }
                        clearNewData = true;
                    }
                } else if (hoverOver <= -1) {
                    //we cant go down for 1 block, check more to hoverLimit
                    if (hoverOver > -hoverLimit - 1 && newLoc.getY() - 1 >= data.getMinHeight()) {
                        data.setDy(hoverOver - 1);
                        hoverOver -= 1;
                        clearNewData = true;
                    } else {
                        // no way - back to original dY, turn off hovercraft for this move
                        // and get original data again for all explosions
                        data.setDy(0);
                        hoverOver = 0;
                        hoverUseGravity = false;
                        clearNewData = true;
                        hoverCraft = false;
                    }
                } else {
                    // no way - reached MaxHeight during looking new way upstairss 
                    if (hoverUseGravity && newLoc.getY() - 1 >= data.getMinHeight()) {
                        //we are on the maximum of top 
                        //if we can't go up so we test bottom side
                        data.setDy(-1);
                        hoverOver = -1;
                    } else {
                        // - back to original dY, turn off hovercraft for this move
                        // and get original data again for all explosions
                        data.setDy(0);
                        hoverOver = 0;
                        hoverUseGravity = false;
                        hoverCraft = false;
                    }
                    clearNewData = true;
                }
                // End hovercraft stuff
            } else {
                // handle sinking ship collisions
                if (getCraft().getSinking()) {
                    if (getCraft().getType().getExplodeOnCrash() != 0.0F && !explosionBlockedByTowny) {
                        int explosionKey = (int) (0 - (getCraft().getType().getExplodeOnCrash() * 100));
                        if (System.currentTimeMillis() - getCraft().getOrigPilotTime() > 1000)
                            if (!getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ())
                                    .getType().equals(Material.AIR)) {
                                explosionSet
                                        .add(new MapUpdateCommand(oldLoc, explosionKey, (byte) 0, getCraft()));
                                data.setCollisionExplosion(true);
                            }
                    } else {
                        // use the explosion code to clean up the craft, but not with enough force to do anything
                        int explosionKey = 0 - 1;
                        if (!getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getType()
                                .equals(Material.AIR)) {
                            explosionSet.add(new MapUpdateCommand(oldLoc, explosionKey, (byte) 0, getCraft()));
                            data.setCollisionExplosion(true);
                        }
                    }
                } else {
                    // Explode if the craft is set to have a CollisionExplosion. Also keep moving for spectacular ramming collisions
                    if (getCraft().getType().getCollisionExplosion() == 0.0F) {
                        if (moveBlockedByTowny) {
                            fail(String.format(
                                    I18nSupport.getInternationalisedString("Towny - Translation Failed")
                                            + " %s @ %d,%d,%d",
                                    townName, oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()));
                        } else {
                            fail(String.format(
                                    I18nSupport.getInternationalisedString(
                                            "Translation - Failed Craft is obstructed") + " @ %d,%d,%d,%s",
                                    oldLoc.getX(), oldLoc.getY(), oldLoc.getZ(),
                                    getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ())
                                            .getType().toString()));
                            if (getCraft().getNotificationPlayer() != null) {
                                Location location = getCraft().getNotificationPlayer().getLocation();
                            }
                        }
                        break;
                    } else if (explosionBlockedByTowny) {
                        int explosionKey = 0 - 1;
                        if (!getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getType()
                                .equals(Material.AIR)) {
                            explosionSet.add(new MapUpdateCommand(oldLoc, explosionKey, (byte) 0, getCraft()));
                            data.setCollisionExplosion(true);
                        }
                    } else if (System.currentTimeMillis() - getCraft().getOrigPilotTime() > 1000) {
                        int explosionKey;
                        float explosionForce = getCraft().getType().getCollisionExplosion();
                        if (getCraft().getType().getFocusedExplosion() == true) {
                            explosionForce = explosionForce * getCraft().getBlockList().length;
                        }
                        if (oldLoc.getY() < waterLine) { // underwater explosions require more force to do anything
                            explosionForce += 25;
                        }
                        explosionKey = (int) (0 - (explosionForce * 100));
                        if (!getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getType()
                                .equals(Material.AIR)) {
                            explosionSet.add(new MapUpdateCommand(oldLoc, explosionKey, (byte) 0, getCraft()));
                            data.setCollisionExplosion(true);
                        }
                        if (getCraft().getType().getFocusedExplosion() == true) { // don't handle any further collisions if it is set to focusedexplosion
                            break;
                        }
                    }
                }
            }
        } else {
            //block not obstructed
            int oldID = getCraft().getW().getBlockTypeIdAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ());
            byte oldData = getCraft().getW().getBlockAt(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ()).getData();
            int currentID = getCraft().getW().getBlockTypeIdAt(newLoc.getX(), newLoc.getY(), newLoc.getZ());
            byte currentData = getCraft().getW().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ())
                    .getData();
            // remove water from sinking crafts
            if (getCraft().getSinking()) {
                if ((oldID == 8 || oldID == 9) && oldLoc.getY() > waterLine)
                    oldID = 0;
            }

            if (!ignoreBlock) {
                updateSet.add(new MapUpdateCommand(oldLoc, currentID, currentData, newLoc, oldID, oldData,
                        getCraft()));
                tempBlockList.add(newLoc);
            }

            if (i == blocksList.length - 1) {
                if ((hoverCraft && hoverUseGravity)
                        || (hoverUseGravity && newLoc.getY() > data.getMaxHeight() && hoverOver == 0)) {
                    //hovecraft using gravity or something else using gravity and flying over its limit
                    int iFreeSpace = 0;
                    //canHoverOverWater adds 1 to dY for better check water under craft 
                    // best way should be expand selected region to each first blocks under craft
                    if (hoverOver == 0) {
                        //we go directly forward so we check if we can go down
                        for (int ii = -1; ii > -hoverLimit - 2 - (canHoverOverWater ? 0 : 1); ii--) {
                            if (!isFreeSpace(data.getDx(), hoverOver + ii, data.getDz(), blocksList,
                                    existingBlockSet, waterCraft, hoverCraft, harvestBlocks, canHoverOverWater,
                                    checkHover)) {
                                break;
                            }
                            iFreeSpace++;
                        }
                        if (data.failed()) {
                            break;
                        }
                        if (iFreeSpace > hoverLimit - (canHoverOverWater ? 0 : 1)) {
                            data.setDy(-1);
                            hoverOver = -1;
                            clearNewData = true;
                        }
                    } else if (hoverOver == 1 && !airCraft) {
                        //prevent fly heigher than hoverLimit
                        for (int ii = -1; ii > -hoverLimit - 2; ii--) {
                            if (!isFreeSpace(data.getDx(), hoverOver + ii, data.getDz(), blocksList,
                                    existingBlockSet, waterCraft, hoverCraft, harvestBlocks, canHoverOverWater,
                                    checkHover)) {
                                break;
                            }
                            iFreeSpace++;
                        }
                        if (data.failed()) {
                            break;
                        }
                        if (iFreeSpace > hoverLimit) {
                            if (bladeOK) {
                                fail(String.format(I18nSupport.getInternationalisedString(
                                        "Translation - Failed Craft hit height limit")));
                            } else {
                                fail(String.format(
                                        I18nSupport.getInternationalisedString(
                                                "Translation - Failed Craft is obstructed") + " @ %d,%d,%d,%s",
                                        oldLoc.getX(), oldLoc.getY(), oldLoc.getZ(),
                                        getCraft().getW()
                                                .getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ())
                                                .getType().toString()));

                            }
                            break;
                        }
                    } else if (hoverOver > 1) {
                        //prevent jump thru block  
                        for (int ii = 1; ii < hoverOver - 1; ii++) {
                            if (!isFreeSpace(0, ii, 0, blocksList, existingBlockSet, waterCraft, hoverCraft,
                                    harvestBlocks, canHoverOverWater, checkHover)) {
                                break;
                            }
                            iFreeSpace++;
                        }
                        if (data.failed()) {
                            break;
                        }
                        if (iFreeSpace + 2 < hoverOver) {
                            data.setDy(-1);
                            hoverOver = -1;
                            clearNewData = true;
                        }
                    } else if (hoverOver < -1) {
                        //prevent jump thru block  
                        for (int ii = -1; ii > hoverOver + 1; ii--) {
                            if (!isFreeSpace(0, ii, 0, blocksList, existingBlockSet, waterCraft, hoverCraft,
                                    harvestBlocks, canHoverOverWater, checkHover)) {
                                break;
                            }
                            iFreeSpace++;
                        }
                        if (data.failed()) {
                            break;
                        }
                        if (iFreeSpace + 2 < -hoverOver) {
                            data.setDy(0);
                            hoverOver = 0;
                            hoverCraft = false;
                            clearNewData = true;
                        }
                    }
                    if (!canHoverOverWater) {
                        if (hoverOver >= 1) {
                            //others hoverOver values we have checked jet
                            for (int ii = hoverOver - 1; ii > hoverOver - hoverLimit - 2; ii--) {
                                if (!isFreeSpace(0, ii, 0, blocksList, existingBlockSet, waterCraft, hoverCraft,
                                        harvestBlocks, canHoverOverWater, checkHover)) {
                                    break;
                                }
                                iFreeSpace++;
                            }
                            if (data.failed()) {
                                break;
                            }
                        }
                    }
                }
            }
        } //END OF: if (blockObstructed) 

        if (clearNewData) {
            i = -1;
            tempBlockList.clear();
            updateSet.clear();
            harvestedBlocks.clear();
            data.setCollisionExplosion(false);
            explosionSet.clear();
            clearNewData = false;
            townBlockSet.clear();
            craftMinY = 0;
            craftMaxY = 0;
        }

    } //END OF: for ( int i = 0; i < blocksList.length; i++ ) {

    // now move the scheduled block changes along with the ship
    HashMap<MapUpdateCommand, Long> newScheduledBlockChanges = new HashMap<MapUpdateCommand, Long>();
    HashMap<MapUpdateCommand, Long> oldScheduledBlockChanges = getCraft().getScheduledBlockChanges();
    if (oldScheduledBlockChanges != null) {
        for (MapUpdateCommand muc : oldScheduledBlockChanges.keySet()) {
            MovecraftLocation newLoc = muc.getNewBlockLocation().translate(data.getDx(), data.getDy(),
                    data.getDz());
            //           Long newTime=oldScheduledBlockChanges.get(muc);
            Long newTime = System.currentTimeMillis() + 5000;
            MapUpdateCommand newMuc = new MapUpdateCommand(newLoc, muc.getTypeID(), muc.getDataID(),
                    getCraft());
            newScheduledBlockChanges.put(newMuc, newTime);
        }
        data.setScheduledBlockChanges(newScheduledBlockChanges);
    }

    if (data.collisionExplosion()) {
        // mark the craft to check for sinking, remove the exploding blocks from the blocklist, and submit the explosions for map update
        for (MapUpdateCommand m : explosionSet) {

            if (existingBlockSet.contains(m.getNewBlockLocation())) {
                existingBlockSet.remove(m.getNewBlockLocation());
                if (Settings.FadeWrecksAfter > 0) {
                    int typeID = getCraft().getW().getBlockAt(m.getNewBlockLocation().getX(),
                            m.getNewBlockLocation().getY(), m.getNewBlockLocation().getZ()).getTypeId();
                    if (typeID != 0 && typeID != 9) {
                        Movecraft.getInstance().blockFadeTimeMap.put(m.getNewBlockLocation(),
                                System.currentTimeMillis());
                        Movecraft.getInstance().blockFadeTypeMap.put(m.getNewBlockLocation(), typeID);
                        if (m.getNewBlockLocation().getY() <= waterLine) {
                            Movecraft.getInstance().blockFadeWaterMap.put(m.getNewBlockLocation(), true);
                        } else {
                            Movecraft.getInstance().blockFadeWaterMap.put(m.getNewBlockLocation(), false);
                        }
                        Movecraft.getInstance().blockFadeWorldMap.put(m.getNewBlockLocation(),
                                getCraft().getW());
                    }
                }
            }

            // if the craft is sinking, remove all solid blocks above the one that hit the ground from the craft for smoothing sinking
            if (getCraft().getSinking() == true
                    && (getCraft().getType().getExplodeOnCrash() == 0.0 || explosionBlockedByTowny)) {
                int posy = m.getNewBlockLocation().getY() + 1;
                int testID = getCraft().getW()
                        .getBlockAt(m.getNewBlockLocation().getX(), posy, m.getNewBlockLocation().getZ())
                        .getTypeId();

                while (posy <= maxY && !(Arrays.binarySearch(fallThroughBlocks, testID) >= 0)) {
                    MovecraftLocation testLoc = new MovecraftLocation(m.getNewBlockLocation().getX(), posy,
                            m.getNewBlockLocation().getZ());
                    if (existingBlockSet.contains(testLoc)) {
                        existingBlockSet.remove(testLoc);
                        if (Settings.FadeWrecksAfter > 0) {
                            int typeID = getCraft().getW()
                                    .getBlockAt(testLoc.getX(), testLoc.getY(), testLoc.getZ()).getTypeId();
                            if (typeID != 0 && typeID != 9) {
                                Movecraft.getInstance().blockFadeTimeMap.put(testLoc,
                                        System.currentTimeMillis());
                                Movecraft.getInstance().blockFadeTypeMap.put(testLoc, typeID);
                                if (testLoc.getY() <= waterLine) {
                                    Movecraft.getInstance().blockFadeWaterMap.put(testLoc, true);
                                } else {
                                    Movecraft.getInstance().blockFadeWaterMap.put(testLoc, false);
                                }
                                Movecraft.getInstance().blockFadeWorldMap.put(testLoc, getCraft().getW());
                            }
                        }
                    }
                    posy = posy + 1;
                    testID = getCraft().getW()
                            .getBlockAt(m.getNewBlockLocation().getX(), posy, m.getNewBlockLocation().getZ())
                            .getTypeId();
                }
            }
        }

        MovecraftLocation[] newBlockList = (MovecraftLocation[]) existingBlockSet
                .toArray(new MovecraftLocation[0]);
        data.setBlockList(newBlockList);
        data.setUpdates(explosionSet.toArray(new MapUpdateCommand[1]));

        fail(String.format(I18nSupport.getInternationalisedString("Translation - Failed Craft is obstructed")));

        if (getCraft().getSinking() == false) { // FROG changed from ==true, think that was a typo
            if (getCraft().getType().getSinkPercent() != 0.0) {
                getCraft().setLastBlockCheck(0);
            }
            getCraft().setLastCruisUpdate(System.currentTimeMillis() - 30000);
        }
    }

    if (!data.failed()) {
        MovecraftLocation[] newBlockList = (MovecraftLocation[]) tempBlockList
                .toArray(new MovecraftLocation[0]);
        data.setBlockList(newBlockList);

        //prevents torpedo and rocket pilots :)
        if (getCraft().getType().getMoveEntities() && getCraft().getSinking() == false) {
            // Move entities within the craft
            List<Entity> eList = null;
            int numTries = 0;
            while ((eList == null) && (numTries < 100)) {
                try {
                    eList = getCraft().getW().getEntities();
                } catch (java.util.ConcurrentModificationException e) {
                    numTries++;
                }
            }

            Iterator<Entity> i = eList.iterator();
            while (i.hasNext()) {
                Entity pTest = i.next();
                //                                if ( MathUtils.playerIsWithinBoundingPolygon( getCraft().getHitBox(), getCraft().getMinX(), getCraft().getMinZ(), MathUtils.bukkit2MovecraftLoc( pTest.getLocation() ) ) ) {
                if (MathUtils.locIsNearCraftFast(getCraft(),
                        MathUtils.bukkit2MovecraftLoc(pTest.getLocation()))) {
                    if (pTest.getType() == org.bukkit.entity.EntityType.PLAYER) {
                        Player player = (Player) pTest;
                        getCraft().getMovedPlayers().put(player, System.currentTimeMillis());
                        Location tempLoc = pTest.getLocation();

                        //                                        Direct control no longer locks the player in place
                        //                                       if(getCraft().getPilotLocked()==true && pTest==CraftManager.getInstance().getPlayerFromCraft(getCraft())) {
                        //                                            tempLoc.setX(getCraft().getPilotLockedX());
                        //                                            tempLoc.setY(getCraft().getPilotLockedY());
                        //                                            tempLoc.setZ(getCraft().getPilotLockedZ());
                        //                                        } 
                        tempLoc = tempLoc.add(data.getDx(), data.getDy(), data.getDz());
                        Location newPLoc = new Location(getCraft().getW(), tempLoc.getX(), tempLoc.getY(),
                                tempLoc.getZ());
                        newPLoc.setPitch(pTest.getLocation().getPitch());
                        newPLoc.setYaw(pTest.getLocation().getYaw());

                        EntityUpdateCommand eUp = new EntityUpdateCommand(pTest.getLocation().clone(), newPLoc,
                                pTest);
                        entityUpdateSet.add(eUp);
                        //                                        if(getCraft().getPilotLocked()==true && pTest==CraftManager.getInstance().getPlayerFromCraft(getCraft())) {
                        //                                            getCraft().setPilotLockedX(tempLoc.getX());
                        //                                            getCraft().setPilotLockedY(tempLoc.getY());
                        //                                            getCraft().setPilotLockedZ(tempLoc.getZ());
                        //                                        }
                    }
                    if (pTest.getType() == org.bukkit.entity.EntityType.PRIMED_TNT) {
                        Entity ent = (Entity) pTest;
                        Location tempLoc = pTest.getLocation();
                        tempLoc = tempLoc.add(data.getDx(), data.getDy(), data.getDz());
                        EntityUpdateCommand eUp = new EntityUpdateCommand(pTest.getLocation().clone(), tempLoc,
                                pTest);
                        entityUpdateSet.add(eUp);
                    }

                }
            }
        } else {
            //add releaseTask without playermove to manager
            if (getCraft().getType().getCruiseOnPilot() == false && getCraft().getSinking() == false) // not necessary to release cruiseonpilot crafts, because they will already be released
                CraftManager.getInstance().addReleaseTask(getCraft());
        }

        // remove water near sinking crafts
        if (getCraft().getSinking()) {
            int posX;
            int posY = maxY;
            int posZ;
            if (posY > waterLine) {
                for (posX = minX - 1; posX <= maxX + 1; posX++) {
                    for (posZ = minZ - 1; posZ <= maxZ + 1; posZ++) {
                        if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 9
                                || getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 8) {
                            MovecraftLocation loc = new MovecraftLocation(posX, posY, posZ);
                            updateSet.add(new MapUpdateCommand(loc, 0, (byte) 0, getCraft()));
                        }
                    }
                }
            }
            for (posY = maxY + 1; (posY >= minY - 1) && (posY > waterLine); posY--) {
                posZ = minZ - 1;
                for (posX = minX - 1; posX <= maxX + 1; posX++) {
                    if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 9
                            || getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 8) {
                        MovecraftLocation loc = new MovecraftLocation(posX, posY, posZ);
                        updateSet.add(new MapUpdateCommand(loc, 0, (byte) 0, getCraft()));
                    }
                }
                posZ = maxZ + 1;
                for (posX = minX - 1; posX <= maxX + 1; posX++) {
                    if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 9
                            || getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 8) {
                        MovecraftLocation loc = new MovecraftLocation(posX, posY, posZ);
                        updateSet.add(new MapUpdateCommand(loc, 0, (byte) 0, getCraft()));
                    }
                }
                posX = minX - 1;
                for (posZ = minZ - 1; posZ <= maxZ + 1; posZ++) {
                    if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 9
                            || getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 8) {
                        MovecraftLocation loc = new MovecraftLocation(posX, posY, posZ);
                        updateSet.add(new MapUpdateCommand(loc, 0, (byte) 0, getCraft()));
                    }
                }
                posX = maxX + 1;
                for (posZ = minZ - 1; posZ <= maxZ + 1; posZ++) {
                    if (getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 9
                            || getCraft().getW().getBlockAt(posX, posY, posZ).getTypeId() == 8) {
                        MovecraftLocation loc = new MovecraftLocation(posX, posY, posZ);
                        updateSet.add(new MapUpdateCommand(loc, 0, (byte) 0, getCraft()));
                    }
                }
            }
        }

        //Set blocks that are no longer craft to air                        

        //                        /**********************************************************************************************************
        //                        *   I had problems with ListUtils (I tryied commons-collections 3.2.1. and 4.0 without success) 
        //                        *   so I replaced Lists with Sets
        //                        * 
        //                        *   Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/ListUtils
        //                        *   at net.countercraft.movecraft.async.translation.TranslationTask.excecute(TranslationTask.java:716)
        //                        *                                                                                       mwkaicz 24-02-2015
        //                        ***********************************************************************************************************/
        //                        Set<MovecraftLocation> setA = new HashSet(Arrays.asList(blocksList));
        //                        Set<MovecraftLocation> setB = new HashSet(Arrays.asList(newBlockList));
        //                        setA.removeAll(setB);
        //                        MovecraftLocation[] arrA = new MovecraftLocation[0];
        //                        arrA = setA.toArray(arrA);
        //                        List<MovecraftLocation> airLocation = Arrays.asList(arrA);                        
        List<MovecraftLocation> airLocation = ListUtils.subtract(Arrays.asList(blocksList),
                Arrays.asList(newBlockList));

        for (MovecraftLocation l1 : airLocation) {
            // for watercraft, fill blocks below the waterline with water
            if (!waterCraft) {
                if (getCraft().getSinking()) {
                    updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft(),
                            getCraft().getType().getSmokeOnSink()));
                } else {
                    updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft()));
                }
            } else {
                if (l1.getY() <= waterLine) {
                    // if there is air below the ship at the current position, don't fill in with water
                    MovecraftLocation testAir = new MovecraftLocation(l1.getX(), l1.getY() - 1, l1.getZ());
                    while (existingBlockSet.contains(testAir)) {
                        testAir.setY(testAir.getY() - 1);
                    }
                    if (getCraft().getW().getBlockAt(testAir.getX(), testAir.getY(), testAir.getZ())
                            .getTypeId() == 0) {
                        if (getCraft().getSinking()) {
                            updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft(),
                                    getCraft().getType().getSmokeOnSink()));
                        } else {
                            updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft()));
                        }
                    } else {
                        updateSet.add(new MapUpdateCommand(l1, 9, (byte) 0, getCraft()));
                    }
                } else {
                    if (getCraft().getSinking()) {
                        updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft(),
                                getCraft().getType().getSmokeOnSink()));
                    } else {
                        updateSet.add(new MapUpdateCommand(l1, 0, (byte) 0, getCraft()));
                    }
                }
            }
        }

        //add destroyed parts of growed
        for (MovecraftLocation destroyedLocation : destroyedBlocks) {
            updateSet.add(new MapUpdateCommand(destroyedLocation, 0, (byte) 0, getCraft()));
        }
        MapUpdateCommand[] updateArray = updateSet.toArray(new MapUpdateCommand[1]);
        //            MapUpdateManager.getInstance().sortUpdates(updateArray);
        data.setUpdates(updateArray);
        data.setEntityUpdates(entityUpdateSet.toArray(new EntityUpdateCommand[1]));

        if (data.getDy() != 0) {
            data.setHitbox(BoundingBoxUtils.translateBoundingBoxVertically(data.getHitbox(), data.getDy()));
        }

        data.setMinX(data.getMinX() + data.getDx());
        data.setMinZ(data.getMinZ() + data.getDz());
    }

    captureYield(blocksList, harvestedBlocks);
}

From source file:aldenjava.opticalmapping.data.data.DataNode.java

public DataNode remove(long start, long length) {
    if (start < 1)
        throw new IllegalArgumentException("Illegal start: " + start);
    if (start > size)
        throw new IllegalArgumentException("Start " + start + " is larger than data size " + size);
    if (length < 0)
        throw new IllegalArgumentException("Illegal length: " + length);
    if (start + length - 1 > size)
        throw new IllegalArgumentException(
                "The target region " + (start + length - 1) + " is out of range to " + size);

    if (length == 0)
        return new DataNode(name, 0);

    int index = Arrays.binarySearch(refp, start); // refp[index] >= start
    if (index < 0)
        index = (index + 1) * -1;/* w  w w  . ja v a  2s.  c om*/
    else {
        while (index >= 0 && refp[index] == start)
            index--;
        if (index < 0)
            index = 0;
        else
            index++;
    }

    long stop = start + length - 1;
    int index2 = Arrays.binarySearch(refp, stop); // refp[index2] >= stop
    if (index2 < 0)
        index2 = (index2 + 1) * -1;
    else {
        while (index2 >= 0 && refp[index2] == stop)
            index2--;
        if (index2 < 0)
            index2 = 0;
        else
            index2++;
    }

    long[] removedrefp = new long[index2 - index];
    long[] newrefp = new long[refp.length - removedrefp.length];
    System.arraycopy(refp, 0, newrefp, 0, index);
    System.arraycopy(refp, index2, newrefp, index, refp.length - index2);
    for (int i = index; i < newrefp.length; i++)
        newrefp[i] -= length;
    System.arraycopy(refp, index, removedrefp, 0, index2 - index);
    for (int i = 0; i < removedrefp.length; i++)
        removedrefp[i] -= start;
    refp = newrefp;
    size -= length;
    return new DataNode(name, length, removedrefp);
}

From source file:net.sf.jasperreports.swing.JRViewerToolbar.java

void btnZoomOutActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnZoomOutActionPerformed
{//GEN-HEADEREND:event_btnZoomOutActionPerformed
 // Add your handling code here:
    btnActualSize.setSelected(false);//from   ww w  .j a  v  a  2  s  .  c  o  m
    btnFitPage.setSelected(false);
    btnFitWidth.setSelected(false);

    int newZoomInt = (int) (100 * getZoomRatio());
    int index = Arrays.binarySearch(zooms, newZoomInt);
    if (index > 0) {
        viewerContext.setZoomRatio(zooms[index - 1] / 100f);
    } else if (index < -1) {
        viewerContext.setZoomRatio(zooms[-index - 2] / 100f);
    }
}

From source file:com.atolcd.pentaho.di.ui.trans.steps.giscoordinatetransformation.GisCoordinateTransformationDialog.java

public String open() {

    Shell parent = getParent();/*ww  w .j  av  a 2s .c om*/
    Display display = parent.getDisplay();

    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);

    ModifyListener lsMod = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    backupChanged = input.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.Shell.Title"));

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Nom du step
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);

    // Type d'opration
    wlCrsOperation = new Label(shell, SWT.RIGHT);
    wlCrsOperation.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.CrsOperation.Label"));
    props.setLook(wlCrsOperation);
    fdlCrsOperation = new FormData();
    fdlCrsOperation.left = new FormAttachment(0, 0);
    fdlCrsOperation.top = new FormAttachment(wStepname, margin);
    fdlCrsOperation.right = new FormAttachment(middle, -margin);
    wlCrsOperation.setLayoutData(fdlCrsOperation);

    wCrsOperation = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    wCrsOperation
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.CrsOperation.ToolTip"));
    wCrsOperation.setEditable(false);
    props.setLook(wCrsOperation);
    wCrsOperation.addModifyListener(lsMod);
    fdCrsOperation = new FormData();
    fdCrsOperation.left = new FormAttachment(middle, 0);
    fdCrsOperation.right = new FormAttachment(100, 0);
    fdCrsOperation.top = new FormAttachment(wStepname, margin);
    wCrsOperation.setLayoutData(fdCrsOperation);
    wCrsOperation.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            setCrsOperationFlags();
        }
    }

    );

    // Colonne gomtrie
    wlGeometryField = new Label(shell, SWT.RIGHT);
    wlGeometryField.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.GeometryFieldName.Label"));
    props.setLook(wlGeometryField);
    fdlGeometryField = new FormData();
    fdlGeometryField.left = new FormAttachment(0, 0);
    fdlGeometryField.top = new FormAttachment(wCrsOperation, margin);
    fdlGeometryField.right = new FormAttachment(middle, -margin);
    wlGeometryField.setLayoutData(fdlGeometryField);

    wGeometryField = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    wGeometryField.setToolTipText(
            BaseMessages.getString(PKG, "GisCoordinateTransformation.GeometryFieldName.ToolTip"));
    wGeometryField.setEditable(true);
    props.setLook(wGeometryField);
    wGeometryField.addModifyListener(lsMod);
    fdGeometryField = new FormData();
    fdGeometryField.left = new FormAttachment(middle, 0);
    fdGeometryField.right = new FormAttachment(100, 0);
    fdGeometryField.top = new FormAttachment(wCrsOperation, margin);
    wGeometryField.setLayoutData(fdGeometryField);
    wGeometryField.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            loadFields();
        }
    });

    // Colonne gomtrie en sortie
    wlOutputGeometryField = new Label(shell, SWT.RIGHT);
    wlOutputGeometryField
            .setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputGeometryFieldName.Label"));
    props.setLook(wlOutputGeometryField);
    fdlOutputGeometryField = new FormData();
    fdlOutputGeometryField.left = new FormAttachment(0, 0);
    fdlOutputGeometryField.top = new FormAttachment(wGeometryField, margin);
    fdlOutputGeometryField.right = new FormAttachment(middle, -margin);
    wlOutputGeometryField.setLayoutData(fdlOutputGeometryField);

    wOutputGeometryField = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
    wOutputGeometryField.setToolTipText(
            BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputGeometryFieldName.ToolTip"));
    wOutputGeometryField.setEditable(true);
    props.setLook(wOutputGeometryField);
    wOutputGeometryField.addModifyListener(lsMod);
    fdOutputGeometryField = new FormData();
    fdOutputGeometryField.left = new FormAttachment(middle, 0);
    fdOutputGeometryField.right = new FormAttachment(100, 0);
    fdOutputGeometryField.top = new FormAttachment(wGeometryField, margin);
    wOutputGeometryField.setLayoutData(fdOutputGeometryField);

    // ///////////////////////////////////////////////
    // Dbut du groupe : CRS entre
    wInputCRSGroup = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wInputCRSGroup);
    wInputCRSGroup.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSGroup.Label"));

    FormLayout inputCRSGroupLayout = new FormLayout();
    inputCRSGroupLayout.marginWidth = 5;
    inputCRSGroupLayout.marginHeight = 5;
    wInputCRSGroup.setLayout(inputCRSGroupLayout);

    // Dtection du SRID de la gomtrie
    wlCrsFromGeometry = new Label(wInputCRSGroup, SWT.RIGHT);
    wlCrsFromGeometry.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.CrsFromGeometry.Label"));
    props.setLook(wlCrsFromGeometry);
    fdlCrsFromGeometry = new FormData();
    fdlCrsFromGeometry.left = new FormAttachment(0, 0);
    fdlCrsFromGeometry.top = new FormAttachment(0, margin);
    fdlCrsFromGeometry.right = new FormAttachment(middle, -margin);
    wlCrsFromGeometry.setLayoutData(fdlCrsFromGeometry);

    wCrsFromGeometry = new Button(wInputCRSGroup, SWT.CHECK);
    wCrsFromGeometry
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.CrsFromGeometry.ToolTip"));
    props.setLook(wCrsFromGeometry);
    fdCrsFromGeometry = new FormData();
    fdCrsFromGeometry.left = new FormAttachment(middle, 0);
    fdCrsFromGeometry.top = new FormAttachment(0, margin);
    fdCrsFromGeometry.right = new FormAttachment(100, 0);
    wCrsFromGeometry.setLayoutData(fdCrsFromGeometry);
    wCrsFromGeometry.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setCrsReprojectionModeFlags();
        }
    });

    // CRS entre (autorit)
    wlInputCRSAuthority = new Label(wInputCRSGroup, SWT.RIGHT);
    wlInputCRSAuthority
            .setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSAuthority.Label"));
    props.setLook(wlInputCRSAuthority);
    fdlInputCRSAuthority = new FormData();
    fdlInputCRSAuthority.left = new FormAttachment(0, 0);
    fdlInputCRSAuthority.top = new FormAttachment(wCrsFromGeometry, margin);
    fdlInputCRSAuthority.right = new FormAttachment(middle, -margin);
    wlInputCRSAuthority.setLayoutData(fdlInputCRSAuthority);

    wInputCRSAuthority = new CCombo(wInputCRSGroup, SWT.BORDER | SWT.READ_ONLY);
    wInputCRSAuthority.setToolTipText(
            BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSAuthority.ToolTip"));
    wInputCRSAuthority.setEditable(false);
    props.setLook(wInputCRSAuthority);
    wInputCRSAuthority.addModifyListener(lsMod);
    fdInputCRSAuthority = new FormData();
    fdInputCRSAuthority.left = new FormAttachment(middle, 0);
    fdInputCRSAuthority.right = new FormAttachment(100, 0);
    fdInputCRSAuthority.top = new FormAttachment(wCrsFromGeometry, margin);
    wInputCRSAuthority.setLayoutData(fdInputCRSAuthority);
    wInputCRSAuthority.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {

        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            wInputCRSCode.setText("");
        }
    });

    // CRS entre (code)
    wlInputCRSCode = new Label(wInputCRSGroup, SWT.RIGHT);
    wlInputCRSCode.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSCode.Label"));
    props.setLook(wlInputCRSCode);
    fdlInputCRSCode = new FormData();
    fdlInputCRSCode.left = new FormAttachment(0, 0);
    fdlInputCRSCode.top = new FormAttachment(wInputCRSAuthority, margin);
    fdlInputCRSCode.right = new FormAttachment(middle, -margin);
    wlInputCRSCode.setLayoutData(fdlInputCRSCode);

    wbInputCRSCode = new Button(wInputCRSGroup, SWT.PUSH | SWT.CENTER);
    props.setLook(wbInputCRSCode);
    wbInputCRSCode.setText("...");
    wbInputCRSCode
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSCode.ToolTip"));
    fdbInputCRSCode = new FormData();
    fdbInputCRSCode.right = new FormAttachment(100, 0);
    fdbInputCRSCode.top = new FormAttachment(wInputCRSAuthority, margin);
    wbInputCRSCode.setLayoutData(fdbInputCRSCode);

    wInputCRSCode = new TextVar(transMeta, wInputCRSGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wInputCRSCode
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSCode.ToolTip"));
    props.setLook(wInputCRSCode);
    wInputCRSCode.addModifyListener(lsMod);
    fdInputCRSCode = new FormData();
    fdInputCRSCode.left = new FormAttachment(middle, 0);
    fdInputCRSCode.right = new FormAttachment(wbInputCRSCode, -margin);
    fdInputCRSCode.top = new FormAttachment(wInputCRSAuthority, margin);
    wInputCRSCode.setLayoutData(fdInputCRSCode);

    fdInputCRSGroup = new FormData();
    fdInputCRSGroup.left = new FormAttachment(0, margin);
    fdInputCRSGroup.right = new FormAttachment(100, -margin);
    fdInputCRSGroup.top = new FormAttachment(wOutputGeometryField, margin);
    wInputCRSGroup.setLayoutData(fdInputCRSGroup);
    // Fin du groupe : Options de cration de table
    // ///////////////////////////////////////////////

    // ///////////////////////////////////////////////
    // Dbut du groupe : CRS sortie
    wOutputCRSGroup = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wOutputCRSGroup);
    wOutputCRSGroup.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSGroup.Label"));

    FormLayout outputCRSGroupLayout = new FormLayout();
    outputCRSGroupLayout.marginWidth = 5;
    outputCRSGroupLayout.marginHeight = 5;
    wOutputCRSGroup.setLayout(outputCRSGroupLayout);

    // CRS sortie (autorit)
    wlOutputCRSAuthority = new Label(wOutputCRSGroup, SWT.RIGHT);
    wlOutputCRSAuthority
            .setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSAuthority.ToolTip"));
    props.setLook(wlOutputCRSAuthority);
    fdlOutputCRSAuthority = new FormData();
    fdlOutputCRSAuthority.left = new FormAttachment(0, 0);
    fdlOutputCRSAuthority.top = new FormAttachment(0, margin);
    fdlOutputCRSAuthority.right = new FormAttachment(middle, -margin);
    wlOutputCRSAuthority.setLayoutData(fdlOutputCRSAuthority);

    wOutputCRSAuthority = new CCombo(wOutputCRSGroup, SWT.BORDER | SWT.READ_ONLY);
    wOutputCRSAuthority.setToolTipText(
            BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSAuthority.ToolTip"));
    wOutputCRSAuthority.setEditable(false);
    props.setLook(wOutputCRSAuthority);
    wOutputCRSAuthority.addModifyListener(lsMod);
    fdOutputCRSAuthority = new FormData();
    fdOutputCRSAuthority.left = new FormAttachment(middle, 0);
    fdOutputCRSAuthority.right = new FormAttachment(100, 0);
    fdOutputCRSAuthority.top = new FormAttachment(0, margin);
    wOutputCRSAuthority.setLayoutData(fdOutputCRSAuthority);
    wOutputCRSAuthority.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {

        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            wOutputCRSCode.setText("");
        }
    });

    // CRS sortie (code)
    wlOutputCRSCode = new Label(wOutputCRSGroup, SWT.RIGHT);
    wlOutputCRSCode.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSCode.Label"));
    props.setLook(wlOutputCRSCode);
    fdlOutputCRSCode = new FormData();
    fdlOutputCRSCode.left = new FormAttachment(0, 0);
    fdlOutputCRSCode.top = new FormAttachment(wOutputCRSAuthority, margin);
    fdlOutputCRSCode.right = new FormAttachment(middle, -margin);
    wlOutputCRSCode.setLayoutData(fdlOutputCRSCode);

    wbOutputCRSCode = new Button(wOutputCRSGroup, SWT.PUSH | SWT.CENTER);
    props.setLook(wbOutputCRSCode);
    wbOutputCRSCode.setText("...");
    wbOutputCRSCode
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSCode.Label"));
    fdbOutputCRSCode = new FormData();
    fdbOutputCRSCode.right = new FormAttachment(100, 0);
    fdbOutputCRSCode.top = new FormAttachment(wOutputCRSAuthority, margin);
    wbOutputCRSCode.setLayoutData(fdbOutputCRSCode);

    wOutputCRSCode = new TextVar(transMeta, wOutputCRSGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wOutputCRSCode
            .setToolTipText(BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSCode.ToolTip"));
    props.setLook(wOutputCRSCode);
    wOutputCRSCode.addModifyListener(lsMod);
    fdOutputCRSCode = new FormData();
    fdOutputCRSCode.left = new FormAttachment(middle, 0);
    fdOutputCRSCode.right = new FormAttachment(wbOutputCRSCode, -margin);
    fdOutputCRSCode.top = new FormAttachment(wOutputCRSAuthority, margin);
    wOutputCRSCode.setLayoutData(fdOutputCRSCode);

    fdOutputCRSGroup = new FormData();
    fdOutputCRSGroup.left = new FormAttachment(0, margin);
    fdOutputCRSGroup.right = new FormAttachment(100, -margin);
    fdOutputCRSGroup.top = new FormAttachment(wInputCRSGroup, margin);
    wOutputCRSGroup.setLayoutData(fdOutputCRSGroup);
    // Fin du groupe : Options de cration de table
    // ///////////////////////////////////////////////

    // Boutons Ok et Annuler
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    wVerify = new Button(shell, SWT.PUSH);
    wVerify.setText(BaseMessages.getString(PKG, "GisCoordinateTransformation.Button.Check.Label"));
    wVerify.setToolTipText("");

    setButtonPositions(new Button[] { wOK, wCancel, wVerify }, margin, wOutputCRSGroup);
    lsCancel = new Listener() {
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {
        public void handleEvent(Event e) {
            ok();
        }
    };

    // Afficahe de la liste des codes disponibles pour le systeme en entre
    wbInputCRSCode.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            if (wInputCRSAuthority.getText() != null) {

                String descriptions[] = loadRegistryInfo(wInputCRSAuthority.getText());

                EnterSelectionDialog inputCodeDialog = new EnterSelectionDialog(shell, descriptions,
                        BaseMessages.getString(PKG,
                                "GisCoordinateTransformation.InputCRSGroup."
                                        + getCrsOperationKey(wCrsOperation.getText()) + ".Label"),
                        BaseMessages.getString(PKG, "GisCoordinateTransformation.InputCRSGroup."
                                + getCrsOperationKey(wCrsOperation.getText()) + ".Label"));

                inputCodeDialog.setMulti(false);
                inputCodeDialog.setFixed(true);
                inputCodeDialog.setViewOnly();

                if (wInputCRSCode.getText() != null) {

                    Registry registry = registryManager.getRegistry(wInputCRSAuthority.getText());
                    try {
                        Map<String, String> map = registry.getParameters(wInputCRSCode.getText());

                        if (map != null) {

                            Integer index = Arrays.binarySearch(descriptions,
                                    wInputCRSCode.getText().toUpperCase() + " - " + map.get("title"));
                            if (index != null) {
                                int[] selected = new int[1];
                                selected[0] = index;
                                inputCodeDialog.setSelectedNrs(selected);
                            }
                        }

                    } catch (RegistryException e1) {
                    }
                }

                String selection = inputCodeDialog.open();

                if (selection != null) {
                    wInputCRSCode.setText(selection.split(" - ")[0].trim());
                }
            }

        }
    });

    // Afficahe de la liste des codes disponibles pour le systeme en sortie
    wbOutputCRSCode.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (wOutputCRSAuthority.getText() != null) {

                String descriptions[] = loadRegistryInfo(wOutputCRSAuthority.getText());
                EnterSelectionDialog inputCodeDialog = new EnterSelectionDialog(shell, descriptions,
                        BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSGroup.Label"),
                        BaseMessages.getString(PKG, "GisCoordinateTransformation.OutputCRSGroup.Label"));

                /*
                 * inputCodeDialog.setMulti(false);
                 * inputCodeDialog.setFixed(true);
                 * inputCodeDialog.setViewOnly();
                 */

                if (wOutputCRSCode.getText() != null) {

                    Registry registry = registryManager.getRegistry(wOutputCRSAuthority.getText());
                    try {
                        Map<String, String> map = registry.getParameters(wOutputCRSCode.getText());

                        if (map != null) {

                            Integer index = Arrays.binarySearch(descriptions,
                                    wOutputCRSCode.getText().toUpperCase() + " - " + map.get("title"));
                            if (index != null) {
                                int[] selected = new int[1];
                                selected[0] = index;
                                inputCodeDialog.setSelectedNrs(selected);
                            }
                        }

                    } catch (RegistryException e1) {
                    }
                }

                String selection = inputCodeDialog.open();

                if (selection != null) {
                    wOutputCRSCode.setText(selection.split(" - ")[0].trim());
                }
            }

        }
    });

    // Vrification des codes entre et sorties
    wVerify.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            String dialogTitle = wCrsOperation.getText();
            String dialogMessage = null;
            int dialogIcon = SWT.ICON_INFORMATION;

            CoordinateReferenceSystem inputCRS = null;
            String inputSystemName = (wInputCRSAuthority.getText() + ":" + wInputCRSCode.getText())
                    .toUpperCase();

            // Controle Assignement de SRID ou Systme en entre
            try {

                inputCRS = cRSFactory.getCRS(inputSystemName);
                if (inputCRS == null) {

                    dialogIcon = SWT.ICON_ERROR;
                    dialogMessage = String.format(
                            BaseMessages.getString(PKG, "GisCoordinateTransformation.MessageBox.CRSCode.ERROR"),
                            inputSystemName);
                    showMessage(dialogIcon, dialogTitle, dialogMessage);

                } else {

                    if (getCrsOperationKey(wCrsOperation.getText()).equalsIgnoreCase("ASSIGN")) {
                        dialogIcon = SWT.ICON_INFORMATION;
                        dialogMessage = String.format(BaseMessages.getString(PKG,
                                "GisCoordinateTransformation.MessageBox.CRSCode.OK"), inputSystemName);
                        showMessage(dialogIcon, dialogTitle, dialogMessage);
                    }

                }

            } catch (CRSException e1) {

                dialogIcon = SWT.ICON_ERROR;
                dialogMessage = String.format(
                        BaseMessages.getString(PKG, "GisCoordinateTransformation.MessageBox.CRSCode.ERROR"),
                        inputSystemName);
                showMessage(dialogIcon, dialogTitle, dialogMessage);
            }

            // Si Reprojection
            if (getCrsOperationKey(wCrsOperation.getText()).equalsIgnoreCase("REPROJECT")) {

                CoordinateReferenceSystem outputCRS = null;
                String outputSystemName = (wOutputCRSAuthority.getText() + ":" + wOutputCRSCode.getText())
                        .toUpperCase();

                // Systme de sortie
                try {

                    outputCRS = cRSFactory.getCRS(outputSystemName);
                    if (outputCRS == null) {

                        dialogIcon = SWT.ICON_ERROR;
                        dialogMessage = String.format(
                                BaseMessages.getString(PKG,
                                        "GisCoordinateTransformation.MessageBox.CRSCode.ERROR"),
                                outputSystemName);
                        showMessage(dialogIcon, dialogTitle, dialogMessage);
                    }

                } catch (CRSException e1) {

                    dialogIcon = SWT.ICON_ERROR;
                    dialogMessage = String.format(
                            BaseMessages.getString(PKG, "GisCoordinateTransformation.MessageBox.CRSCode.ERROR"),
                            outputSystemName);
                    showMessage(dialogIcon, dialogTitle, dialogMessage);
                }

                // Existence de la transformation
                if (inputCRS != null && outputCRS != null) {

                    List<CoordinateOperation> transformations = CoordinateOperationFactory
                            .createCoordinateOperations((GeodeticCRS) inputCRS, (GeodeticCRS) outputCRS);

                    if (!transformations.isEmpty() && transformations.get(0) != null) {

                        dialogIcon = SWT.ICON_INFORMATION;
                        dialogMessage = String.format(
                                BaseMessages.getString(PKG,
                                        "GisCoordinateTransformation.MessageBox.CRSTransformation.OK"),
                                inputSystemName, outputSystemName);

                    } else {

                        dialogIcon = SWT.ICON_INFORMATION;
                        dialogMessage = String.format(
                                BaseMessages.getString(PKG,
                                        "GisCoordinateTransformation.MessageBox.CRSTransformation.ERROR"),
                                inputSystemName, outputSystemName);

                    }

                    showMessage(dialogIcon, dialogTitle, dialogMessage);

                }

            }

        }
    });

    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    lsDef = new SelectionAdapter() {
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);

    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });

    loadAuthorities();
    loadCrsOperation();
    loadFields();
    loadData();
    setCrsOperationFlags();
    input.setChanged(changed);
    setSize();

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    return stepname;
}

From source file:it.unimi.dsi.util.ImmutableExternalPrefixMap.java

protected MutableString getTerm(final int index, final MutableString s) {
    ensureStream();//  w ww . j a  v a 2  s . c  om
    // We perform a binary search to find the  block to which s could possibly belong.
    int block = Arrays.binarySearch(blockStart, index);
    if (block < 0)
        block = -block - 2;

    try {
        dumpStream.position(blockOffset[block] * blockSize);
        dumpStream.readBits(0);
        iteratorIsUsable = false;
        int suffixLength, prefixLength = -1;

        for (int i = index - blockStart[block] + 1; i-- != 0;) {
            if (prefixLength < 0)
                prefixLength = 0;
            else
                prefixLength = dumpStream.readUnary();
            suffixLength = dumpStream.readUnary();
            s.delete(prefixLength, s.length());
            s.length(prefixLength + suffixLength);
            for (int j = 0; j < suffixLength; j++)
                s.charAt(j + prefixLength, symbol2char[decoder.decode(dumpStream)]);
        }

        return s;
    } catch (IOException rethrow) {
        throw new RuntimeException(rethrow);
    }
}

From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java

/**
 * Switch data type selector to filtered (Spinner) mode and initialize it's value
 *///from   w ww. j a  v a 2  s. c  o m
private void setupFilteredDataTypeFields(boolean mayBeUntyped, boolean mayAutoDetect, Set<String> dataTypes) {
    mDataTypeMayBeNull = mayBeUntyped;

    if (dataTypes.size() == 0) {
        // IntentFilter doesn't accept data type
        mDataTypeHeader.setVisibility(View.GONE);
        mDataTypeText.setVisibility(View.GONE);
        mDataTypeSpinnerWrapper.setVisibility(View.GONE);

        mUseDataType = false;
    } else {
        // We have set of accepted data types, show them in spinner

        // Build array of items
        String[] spinnerItems = dataTypes.toArray(new String[dataTypes.size()]);

        // Sort them
        Arrays.sort(spinnerItems);

        // Find current
        int currentPosition = -1;
        int slashPos = -1;
        if (mEditedIntent.getType() != null) {
            currentPosition = Arrays.binarySearch(spinnerItems, mEditedIntent.getType());
            if (currentPosition < 0) {
                // Try also partial type matching
                slashPos = mEditedIntent.getType().indexOf('/');
                if (slashPos != -1) {
                    currentPosition = Arrays.binarySearch(spinnerItems,
                            mEditedIntent.getType().substring(0, slashPos));
                }
            }
        }

        // If we also accept untyped variant add that option at first position
        mDataTypeMayBeNull = mayBeUntyped || mayAutoDetect;
        if (mDataTypeMayBeNull) {
            String[] shiftedSpinnerItems = new String[spinnerItems.length + 1];
            System.arraycopy(spinnerItems, 0, shiftedSpinnerItems, 1, spinnerItems.length);

            currentPosition++;
            shiftedSpinnerItems[0] = mayBeUntyped ? getActivity().getString(R.string.data_type_unspecified)
                    : getActivity().getString(R.string.data_type_autodetect);

            spinnerItems = shiftedSpinnerItems;
        }

        // Put data in Spinner
        mDataTypeSpinner.setAdapter(
                new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, spinnerItems));
        if (currentPosition < 0) {
            currentPosition = 0;
        }
        mDataTypeSpinner.setSelection(currentPosition);

        // Show the Spinner
        mDataTypeHeader.setVisibility(View.VISIBLE);
        mDataTypeText.setVisibility(View.GONE);
        mDataTypeSpinnerWrapper.setVisibility(View.VISIBLE);

        // Prepare subtype field
        boolean isPartialType = useSpinnerAndTextEditForDataType();
        if (isPartialType && slashPos != -1) {
            mDataSubtypeText.setText(mEditedIntent.getType().substring(slashPos + 1));
        }
        mDataTypeSlash.setVisibility(isPartialType ? View.VISIBLE : View.GONE);
        mDataSubtypeText.setVisibility(isPartialType ? View.VISIBLE : View.GONE);

        // Bind event
        mDataTypeSpinner.setOnItemSelectedListener(mTypeSpinnerListener);

        // Set flags
        mUseDataType = true;
        mUseDataTypeSpinner = true;
    }
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java

protected int getVirtualFingers() {
    int virtualFingers;

    if (mAdapter.getCount() == 0 && (mForceFingersExemptions == null
            || Arrays.binarySearch(mForceFingersExemptions, mMaxFingersDown) < 0)) {
        virtualFingers = mForceFingersWhenEmpty;
    } else {//  w  ww .  j a v a 2  s  . c o  m
        virtualFingers = mMaxFingersDown;
    }

    if (mOnStageClickListeners.get(virtualFingers) == null) {
        return 0;
    }

    return virtualFingers;
}