Package net.alteiar.beans.map

Examples of net.alteiar.beans.map.MapBean


    return createMap(name, new ImageBean(background));
  }

  public static MapBean createMap(String name, ImageBean background)
      throws IOException {
    MapBean map = new MapBean(name);

    CampaignClient.getInstance().addBean(background);

    Image backgroundImage = background.getImage().restoreImage();
    map.setWidth(backgroundImage.getWidth(null));
    map.setHeight(backgroundImage.getHeight(null));

    // ManualMapFilter filter = new ManualMapFilter(map.getId());
    CharacterMapFilter filter = new CharacterMapFilter(map);
    CampaignClient.getInstance().addBean(filter);

    map.setFilter(filter.getId());
    map.setBackground(background.getId());

    return map;
  }
View Full Code Here


        createTransfertImage("./test/ressources/guerrier.jpg"));
  }

  public static UniqueID createBattle(String battleName, File image)
      throws IOException {
    MapBean battleBean = MapFactory.createMap(battleName, image);
    CampaignClient.getInstance().addBean(battleBean);
    return battleBean.getId();
  }
View Full Code Here

  }

  @Test(timeout = 10000)
  public void testBattleWithMapElement() {
    Long waitingTime = 1000L;
    MapBean emptyBattle = new MapBean("");
    assertEquals("verify emptyBattle", emptyBattle, emptyBattle);

    UniqueID battleId = null;
    try {
      battleId = createBattle("test battle 10", getDefaultImage());
    } catch (IOException e) {
      fail("fail to create battle");
    }
    assertNotNull("the battle id must'nt be null", battleId);
    MapBean battle = CampaignClient.getInstance().getBean(battleId,
        waitingTime);
    assertNotNull("the battle should not be null", battle);

    PropertyChangeListener listener = new PropertyChangeListener() {
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        innerClassCall();
      }
    };
    battle.addPropertyChangeListener(listener);

    Point position = new Point(5, 5);
    Color color = Color.GREEN;
    MapElementSize width = new MapElementSizeMeter(6.0);
    MapElementSize height = new MapElementSizePixel(42.0);

    RectangleElement rectangle = new RectangleElement(position, color,
        width, height);

    Collection<UniqueID> elementsOnMap = battle.getElements();
    assertTrue("The map shouldn't have any element",
        elementsOnMap.isEmpty());

    MapElementFactory.buildMapElement(rectangle, battle);

    // wait for the element to be in the element list
    while (elementsOnMap.isEmpty()) {
      sleep(10);
      elementsOnMap = battle.getElements();
    }

    assertEquals("The map should have 1 element", 1, elementsOnMap.size());
    assertEquals("The rectangle id should be the same", rectangle.getId(),
        elementsOnMap.iterator().next());

    assertEquals(
        "The map should have at least 1 element at the position (6,6)",
        1, battle.getElementsAt(new Point(6, 6)).size());
    assertEquals(
        "The map should'nt have any element at the position (4,4)", 0,
        battle.getElementsAt(new Point(4, 4)).size());

    battle.removeElement(elementsOnMap.iterator().next());
    while (!elementsOnMap.isEmpty()) {
      sleep(10);
      elementsOnMap = battle.getElements();
    }

    assertTrue("The map should'nt have any element",
        elementsOnMap.isEmpty());

    battle.setScale(new Scale(25, 1.5));
    battle.setFilter(new UniqueID());

    sleep();
    // Should have 4 call
    // (add element, remove element, scale change, filter change)
    verifyInnerClassCall(4);

    battle.removePropertyChangeListener(listener);
  }
View Full Code Here

        scale.hashCode() != scale3.hashCode());
  }

  @Test(timeout = 10000)
  public void testMap() {
    MapBean emptyMap = new MapBean("");
    assertEquals("verify emptyMap", emptyMap, emptyMap);

    String targetName = "test battle";

    MapBean map = null;
    try {
      map = MapFactory.createMap(targetName, getDefaultImage());
    } catch (IOException e) {
      fail("exception should'nt occur");
    }

    assertNotNull("Map should'nt be null", map);

    BeanDocument doc = new BeanDocument(CampaignClient.getInstance()
        .getRootDirectory(), targetName, "document-type", map);

    doc = addBean(doc);
    map = doc.getBean();

    Scale newScale = new Scale(map.getScale().getPixels() + 5, map
        .getScale().getMeter());
    map.setScale(newScale);

    Integer newWidth = map.getWidth() + 5;
    map.setWidth(newWidth);

    Integer newHeight = map.getHeight() + 5;
    map.setHeight(newHeight);

    ImageBean imageBean = createBeanImage();

    CampaignClient.getInstance().addBean(imageBean);
    UniqueID newImage = imageBean.getId();

    map.setBackground(newImage);

    UniqueID newFilter = new UniqueID();
    map.setFilter(newFilter);

    HashSet<UniqueID> set = new HashSet<UniqueID>();
    set.add(new UniqueID());
    set.add(new UniqueID());
    map.setElements(set);

    waitForChange(map, "getScale", newScale);
    waitForChange(map, "getWidth", newWidth);
    waitForChange(map, "getHeight", newHeight);
    waitForChange(map, "getBackground", newImage);
View Full Code Here

    try {
      battleId = createBattle("test battle", getDefaultImage());
    } catch (IOException e) {
      fail("fail to create battle");
    }
    MapBean created = CampaignClient.getInstance().getBean(battleId, 300);

    // Remove the battle
    CampaignClient.getInstance().removeBean(created);
  }
View Full Code Here

      battleId1 = createBattle("new battle1", battleImageFile);
      battleId2 = createBattle("new battle2", battleImageFile);
    } catch (IOException e) {
      fail("fail to create battle");
    }
    MapBean battle1 = CampaignClient.getInstance().getBean(battleId1,
        waitingTime);
    MapBean battle2 = CampaignClient.getInstance().getBean(battleId2,
        waitingTime);

    sleep();
    double compareZoomFactor = 2.5;
    BufferedImage image1 = new BufferedImage(
        (int) (battle1.getWidth() * compareZoomFactor),
        (int) (battle1.getHeight() * compareZoomFactor),
        BufferedImage.TYPE_INT_ARGB);

    BufferedImage image2 = new BufferedImage(
        (int) (battle2.getWidth() * compareZoomFactor),
        (int) (battle2.getHeight() * compareZoomFactor),
        BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) image1.getGraphics();
    battle1.drawBackground(g);
    battle1.drawFilter(g, true);
    battle1.drawGrid(g);
    g.dispose();

    g = (Graphics2D) image2.getGraphics();
    battle2.drawBackground(g);
    battle2.drawFilter(g, true);
    battle2.drawGrid(g);
    g.dispose();

    try {
      assertTrue("Images should be same", compareImage(image1, image2));
    } catch (IOException e) {
View Full Code Here

    try {
      battleId = createBattle("new battle", battleImageFile);
    } catch (IOException e) {
      fail("fail to create battle");
    }
    MapBean mapFiltered = CampaignClient.getInstance().getBean(battleId,
        waitingTime);

    int width = mapFiltered.getWidth();
    int height = mapFiltered.getHeight();

    try {
      BufferedImage targetImages = ImageIO.read(battleImageFile);
      int expectedWidth = targetImages.getWidth();
      int expectedHeight = targetImages.getHeight();
      assertEquals("width should be same", width, expectedWidth);
      assertEquals("height should be same", height, expectedHeight);

      // Test filter
      double compareZoomFactor = 2.75;

      ManualMapFilter filter = new ManualMapFilter(battleId);
      filter.showPolygon(new Polygon(new int[] { 5, 25, 25, 5 },
          new int[] { 5, 5, 25, 25 }, 4));
      filter.hidePolygon(new Polygon(new int[] { 5, 25, 25, 5 },
          new int[] { 5, 5, 25, 25 }, 4));

      CampaignClient.getInstance().addBean(filter);
      UniqueID filterId = filter.getId();

      mapFiltered.setFilter(filterId);
      filter = CampaignClient.getInstance()
          .getBean(filterId, waitingTime);

      BufferedImage filteredImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * compareZoomFactor),
          (int) (mapFiltered.getHeight() * compareZoomFactor),
          BufferedImage.TYPE_INT_ARGB);

      BufferedImage targetFilteredImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * 2.75),
          (int) (mapFiltered.getHeight() * 2.75),
          BufferedImage.TYPE_INT_ARGB);

      ManualMapFilter targetFilter = new ManualMapFilter(battleId);

      Graphics2D g = (Graphics2D) filteredImage.getGraphics();
      mapFiltered.drawBackground(g);
      mapFiltered.drawFilter(g, true);
      g.dispose();

      g = (Graphics2D) targetFilteredImage.getGraphics();
      AffineTransform transform = new AffineTransform();
      transform.scale(2.75, 2.75);
      g.drawImage(targetImages, transform, null);
      targetFilter.draw(g, 2.75, true);
      g.dispose();

      assertTrue("Images filter should be same",
          compareImage(filteredImage, targetFilteredImage));

      // Change filter
      Polygon showPolygon = new Polygon(new int[] { 15, 50, 50, 15 },
          new int[] { 15, 15, 50, 50 }, 4);
      filter.showPolygon(showPolygon);
      targetFilter.showPolygon(showPolygon);
      sleep();

      BufferedImage filteredShowImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * 0.75),
          (int) (mapFiltered.getHeight() * 0.75),
          BufferedImage.TYPE_INT_ARGB);

      BufferedImage targetFilteredShowImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * 0.75),
          (int) (mapFiltered.getHeight() * 0.75),
          BufferedImage.TYPE_INT_ARGB);

      g = (Graphics2D) filteredShowImage.getGraphics();
      mapFiltered.drawBackground(g);
      mapFiltered.drawFilter(g, true);
      g.dispose();

      g = (Graphics2D) targetFilteredShowImage.getGraphics();
      transform = new AffineTransform();
      transform.scale(0.75, 0.75);
      g.drawImage(targetImages, transform, null);
      targetFilter.draw(g, 0.75, true);
      g.dispose();

      assertTrue("Images filter should be same",
          compareImage(filteredShowImage, targetFilteredShowImage));

      // Compare with previous filter, should have changed
      filteredShowImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * compareZoomFactor),
          (int) (mapFiltered.getHeight() * compareZoomFactor),
          BufferedImage.TYPE_INT_ARGB);

      g = (Graphics2D) filteredShowImage.getGraphics();
      mapFiltered.drawBackground(g);
      mapFiltered.drawFilter(g, true);
      g.dispose();

      assertTrue("Images filter should not be same",
          !compareImage(filteredShowImage, filteredImage));

      // Change filter
      Polygon hidePolygon = new Polygon(new int[] { 15, 20, 20, 15 },
          new int[] { 15, 15, 20, 20 }, 4);
      filter.hidePolygon(hidePolygon);
      targetFilter.hidePolygon(hidePolygon);
      sleep();

      BufferedImage filteredShowHideImage = new BufferedImage(
          mapFiltered.getWidth() * 1, mapFiltered.getHeight() * 1,
          BufferedImage.TYPE_INT_ARGB);

      BufferedImage targetFilteredShowHideImage = new BufferedImage(
          mapFiltered.getWidth() * 1, mapFiltered.getHeight() * 1,
          BufferedImage.TYPE_INT_ARGB);

      g = (Graphics2D) filteredShowHideImage.getGraphics();
      mapFiltered.drawBackground(g);
      mapFiltered.drawFilter(g, true);
      g.dispose();

      g = (Graphics2D) targetFilteredShowHideImage.getGraphics();
      transform = new AffineTransform();
      transform.scale(1, 1);
      g.drawImage(targetImages, transform, null);
      targetFilter.draw(g, 1, true);
      g.dispose();

      assertTrue(
          "Images filter should be same",
          compareImage(filteredShowHideImage,
              targetFilteredShowHideImage));

      // Compare with previous filter, should have changed
      filteredShowImage = new BufferedImage(
          (int) (mapFiltered.getWidth() * compareZoomFactor),
          (int) (mapFiltered.getHeight() * compareZoomFactor),
          BufferedImage.TYPE_INT_ARGB);
      g = (Graphics2D) filteredShowImage.getGraphics();
      mapFiltered.drawBackground(g);
      mapFiltered.drawFilter(g, true);
      filter.draw(g, compareZoomFactor, true);
      g.dispose();
      assertTrue("Images filter should not be same",
          !compareImage(filteredShowHideImage, filteredShowImage));
    } catch (IOException e) {
View Full Code Here

    save();
    assertEquals(1, countObjectFile(ImageBean.class));

    CampaignClient.getInstance().removeBean(battleId);

    MapBean b = CampaignClient.getInstance().getBean(battleId);
    while (b != null) {
      b = CampaignClient.getInstance().getBean(battleId);
    }
    save();
    assertEquals(0, countObjectFile(ImageBean.class));
View Full Code Here

        rectangle.getPosition());
  }

  @Test(timeout = 5000)
  public void testRectangleSelection() {
    MapBean battle = getBattle();

    MapElementSize width = new MapElementSizePixel(20.0);
    MapElementSize height = new MapElementSizePixel(20.0);
    Point position = new Point(5, 5);
View Full Code Here

    }
  }

  @Test(timeout = 5000)
  public void testRectangle() {
    MapBean battle = getBattle();

    MapElementSize width = new MapElementSizePixel(20.0);
    MapElementSize height = new MapElementSizePixel(20.0);
    Point position = new Point(5, 5);

    RectangleElement targetRectangle = new RectangleElement(position,
        Color.RED, width, height);
    MapElementFactory.buildMapElement(targetRectangle, battle);

    RectangleElement rectangle = CampaignClient.getInstance().getBean(
        targetRectangle.getId(), 300L);

    assertEquals("The position should be equals", position,
        rectangle.getPosition());
    assertEquals("The color should be equals", Color.RED,
        rectangle.getColor());
    assertEquals("The angle should be equals", Double.valueOf(0),
        rectangle.getAngle());
    assertEquals("The width should be equals", width.getPixels(battle
        .getScale()), rectangle.getWidth().getPixels(battle.getScale()));
    assertEquals("The height should be equals", height.getPixels(battle
        .getScale()), rectangle.getHeight()
        .getPixels(battle.getScale()));

    MapElementSize newWidth = new MapElementSizeSquare(2.0);
    MapElementSize newHeight = new MapElementSizeSquare(3.0);
    rectangle.setWidth(newWidth);
    rectangle.setHeight(newHeight);
    sleep();
    assertEquals("The width should be equals", newWidth.getPixels(battle
        .getScale()), rectangle.getWidth().getPixels(battle.getScale()));
    assertEquals("The height should be equals", newHeight.getPixels(battle
        .getScale()), rectangle.getHeight()
        .getPixels(battle.getScale()));

    BufferedImage realImg = new BufferedImage(200, 200,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = realImg.createGraphics();
    rectangle.draw(g2, 1.0, true);
View Full Code Here

TOP

Related Classes of net.alteiar.beans.map.MapBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.