コード例 #1
0
    @Override
    public GridBoundsChange performAction(GridManager gridManager, DesignerContext context) {
      GridInfoProvider info = gridManager.getGridInfo();
      int oldColumns = info.getColumnCount();
      int oldRows = info.getRowCount();
      GridUtils.removePaddingComponents(gridManager);

      // Undo/redo itself
      delegate.actionPerformed(null);
      gridManager.updateLayout(true);

      // Remove deleted components from selection
      Set<Component> newSelection = new HashSet<Component>();
      for (Component comp : context.getSelectedComponents()) {
        if (comp.getParent() != null) {
          newSelection.add(comp);
        }
      }
      context.setSelectedComponents(newSelection);

      GridUtils.revalidateGrid(gridManager);
      gridManager.updateGaps(false);
      int newColumns = info.getColumnCount();
      int newRows = info.getRowCount();
      int columns = Math.max(oldColumns, newColumns);
      int rows = Math.max(oldRows, newRows);
      GridUtils.addPaddingComponents(gridManager, columns, rows);
      GridUtils.revalidateGrid(gridManager);
      return null;
    }
コード例 #2
0
 private static void checkGridExtras(String gridUrl, RemoteWebDriver driver) {
   String gridExtras = GridUtils.getNodeExtras(gridUrl, driver);
   if (gridExtras == null) {
     log.info("No grid extras foud");
   } else {
     log.info("Grid extras available at {}", gridExtras);
   }
 }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    GridUtils.writeUuid(out, nodeId);

    CU.writeVersion(out, ver);

    out.writeLong(timeout);
    out.writeLong(threadId);
    out.writeLong(id);
    out.writeShort(flags());
  }
コード例 #4
0
ファイル: GridStage.java プロジェクト: kotucz/blocks-game
  protected void draw(Matrix4 combined) {
    batch.setProjectionMatrix(combined);

    batch.begin();

    for (LinPos p : grid.getLinGrid()) {
      final Square square = grid.get(p.i);

      final int neighHash =
          GridUtils.getNeighHash(
              p,
              new Predicate<Pos>() {
                @Override
                public boolean evaluate(Pos pos) {
                  final Square nsquare = grid.get(pos);
                  if (nsquare == null) {
                    return false;
                  }
                  //                    return (pos.x + pos.y) % 2 == 0;
                  return nsquare.count > 0;
                }
              });

      if (square.count > 0) {

        final Sprite sprite = T.blockSprites[neighHash];

        sprite.setPosition(p.x, p.y);

        sprite.draw(batch);
      } else {
        int image = neighHash / 4;

        //            batch.draw(blockTextureRegion.get(square.image), p.x, p.y, 0.5f, 0.5f, 1, 1,
        // 1, 1, MathUtils.random(8)* 45);
        //            batch.draw(blockTextureRegion.get(square.image), p.x, p.y, 0.5f, 0.5f, 1, 1,
        // 1, 1, 45);
        batch.draw(T.blockTextureRegion.get(image), p.x, p.y, 1, 1);
      }
    }

    for (Block block : blocks) {
      block.draw(batch);
    }
    batch.end();
  }
コード例 #5
0
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    nodeId = GridUtils.readUuid(in);

    ver = CU.readVersion(in);

    timeout = in.readLong();
    threadId = in.readLong();
    id = in.readLong();

    short flags = in.readShort();

    mask(OWNER, OWNER.get(flags));
    mask(USED, USED.get(flags));
    mask(TX, TX.get(flags));

    ts = U.currentTimeMillis();
  }
コード例 #6
0
  private DefaultFeatureCollection createFeaturesFromSpacing(
      final MapfishMapContext mapContext,
      final SimpleFeatureBuilder featureBuilder,
      final GridParam layerData,
      final LabelPositionCollector labels) {
    GeometryFactory geometryFactory = new GeometryFactory();
    ReferencedEnvelope bounds = mapContext.toReferencedEnvelope();

    CoordinateReferenceSystem mapCrs = bounds.getCoordinateReferenceSystem();
    String unit = layerData.calculateLabelUnit(mapCrs);
    MathTransform labelTransform = layerData.calculateLabelTransform(mapCrs);

    final double incrementX = layerData.spacing[0];
    final double incrementY = layerData.spacing[1];
    double minX = GridUtils.calculateFirstLine(bounds, layerData, 0);
    double minY = GridUtils.calculateFirstLine(bounds, layerData, 1);

    MapfishMapContext rootContext = mapContext.getRootContext();
    Polygon rotatedBounds = GridUtils.calculateBounds(rootContext);
    AffineTransform worldToScreenTransform = GridUtils.getWorldToScreenTransform(mapContext);

    DefaultFeatureCollection features = new DefaultFeatureCollection();
    int i = 0;
    int j;

    boolean addBorderFeatures = true;
    for (double x = minX; x < bounds.getMaxX(); x += incrementX) {
      i++;
      j = 0;

      if (!onRightBorder(bounds, x)) { // don't add the border features twice.
        GridUtils.bottomBorderLabel(
            labels,
            geometryFactory,
            rotatedBounds,
            unit,
            x,
            worldToScreenTransform,
            labelTransform,
            layerData.getGridLabelFormat());
        GridUtils.topBorderLabel(
            labels,
            geometryFactory,
            rotatedBounds,
            unit,
            x,
            worldToScreenTransform,
            labelTransform,
            layerData.getGridLabelFormat());
      }
      for (double y = minY; y < bounds.getMaxY(); y += incrementY) {
        j++;

        if (addBorderFeatures && !onRightBorder(bounds, x) && !onTopBorder(bounds, y)) {
          GridUtils.leftBorderLabel(
              labels,
              geometryFactory,
              rotatedBounds,
              unit,
              y,
              worldToScreenTransform,
              labelTransform,
              layerData.getGridLabelFormat());
          GridUtils.rightBorderLabel(
              labels,
              geometryFactory,
              rotatedBounds,
              unit,
              y,
              worldToScreenTransform,
              labelTransform,
              layerData.getGridLabelFormat());
        }
        if (!onTopBorder(bounds, y)
            && !onBottomBorder(bounds, y)
            && !onLeftBorder(bounds, x)
            && !onRightBorder(bounds, x)) { // don't add the border features twice.
          featureBuilder.reset();
          Point geom = geometryFactory.createPoint(new Coordinate(x, y));
          featureBuilder.set(Grid.ATT_GEOM, geom);
          features.add(featureBuilder.buildFeature("grid." + i + "." + j));
        }
      }
      addBorderFeatures = false;
    }
    return features;
  }
コード例 #7
0
  private DefaultFeatureCollection createFeaturesFromNumberOfLines(
      final MapfishMapContext mapContext,
      final SimpleFeatureBuilder featureBuilder,
      final GridParam layerData,
      final LabelPositionCollector labels) {
    GeometryFactory geometryFactory = new GeometryFactory();
    ReferencedEnvelope bounds = mapContext.toReferencedEnvelope();

    MapfishMapContext rootContext = mapContext.getRootContext();
    Polygon rotatedBounds = GridUtils.calculateBounds(rootContext);
    AffineTransform worldToScreenTransform = GridUtils.getWorldToScreenTransform(mapContext);

    CoordinateReferenceSystem mapCrs = bounds.getCoordinateReferenceSystem();
    String unit = layerData.calculateLabelUnit(mapCrs);
    MathTransform labelTransform = layerData.calculateLabelTransform(mapCrs);

    double incrementX = bounds.getWidth() / (layerData.numberOfLines[0] + 1);
    double incrementY = bounds.getHeight() / (layerData.numberOfLines[1] + 1);

    double x = bounds.getMinX();
    DefaultFeatureCollection features = new DefaultFeatureCollection();
    for (int i = 0; i < layerData.numberOfLines[0] + 2; i++) {
      double y = bounds.getMinY();
      for (int j = 0; j < layerData.numberOfLines[1] + 2; j++) {
        String fid = "grid." + i + "." + j;
        if ((i != 0 || j != 0)
            && (i != layerData.numberOfLines[0] + 1 || j != layerData.numberOfLines[1] + 1)
            && (i != 0 || j != layerData.numberOfLines[1] + 1)
            && (i != layerData.numberOfLines[0] + 1 || j != 0)) {

          if (i == 0) {
            GridUtils.leftBorderLabel(
                labels,
                geometryFactory,
                rotatedBounds,
                unit,
                y,
                worldToScreenTransform,
                labelTransform,
                layerData.getGridLabelFormat());
          } else if (i == layerData.numberOfLines[0] + 1) {
            GridUtils.rightBorderLabel(
                labels,
                geometryFactory,
                rotatedBounds,
                unit,
                y,
                worldToScreenTransform,
                labelTransform,
                layerData.getGridLabelFormat());
          } else if (j == 0) {
            GridUtils.bottomBorderLabel(
                labels,
                geometryFactory,
                rotatedBounds,
                unit,
                x,
                worldToScreenTransform,
                labelTransform,
                layerData.getGridLabelFormat());
          } else if (j == layerData.numberOfLines[1] + 1) {
            GridUtils.topBorderLabel(
                labels,
                geometryFactory,
                rotatedBounds,
                unit,
                x,
                worldToScreenTransform,
                labelTransform,
                layerData.getGridLabelFormat());
          } else {
            featureBuilder.reset();
            Point geom = geometryFactory.createPoint(new Coordinate(x, y));
            featureBuilder.set(Grid.ATT_GEOM, geom);
            features.add(featureBuilder.buildFeature(fid));
          }
        }
        y += incrementY;
      }
      x += incrementX;
    }
    return features;
  }
コード例 #8
0
  private static WebDriver createRemoteDriver() {
    if (ConfigLoader.config().containsKey("noui")) {
      return new HtmlUnitDriver(true);
    }
    log.info("Creating browser for {}", browser.get());
    try {
      if (Strings.isNullOrEmpty(GRID_URL) || !isGridAvailable(GRID_URL)) {
        log.info("Grid not detected");
        String name = browser.get().toLowerCase();
        if (name.equalsIgnoreCase("ie")
            || name.equals("internet_explorer")
            || name.equals("internet explorer")) {
          return new InternetExplorerDriver(getCapabilities(BrowserType.IE));
        }
        String browserName = StringUtils.capitalize(name + "Driver");
        WebDriver res = null;
        try {
          res =
              (WebDriver)
                  Class.forName("org.openqa.selenium." + name + "." + browserName)
                      .getConstructor(Capabilities.class)
                      .newInstance(getCapabilities(name));
        } catch (Exception e) {
          throw new IllegalStateException(
              String.format("Browser for name %s failed to start", name), e);
        }
        return res;
      } else {
        log.info("Using Selenium grid at {}", GRID_URL);
        String browserType = browser.get();
        URL gridUrl = new URL(GRID_URL);
        RemoteWebDriver result = new RemoteWebDriver(gridUrl, getCapabilities(browserType));
        log.info("Driver instance created {}", result);
        log.debug("Test session id {}", result.getSessionId());
        log.info("Executing on node {}", GridUtils.getNode(GRID_URL, result));
        String videoLink =
            String.format(
                "%s/download_video/%s.mp4",
                GridUtils.getNodeExtras(gridUrl.toString(), result),
                result.getSessionId().toString());
        ConfigLoader.config().addProperty("webdriver.video", videoLink);
        List<Object> videos =
            ConfigLoader.config().getList("webdriver.videos", new ArrayList<Map<String, String>>());

        String story = null;
        try {
          if (!Strings.isNullOrEmpty(GenericAllureStoryReporter.storyName())) {
            story = GenericAllureStoryReporter.storyName();
          } else if (!Strings.isNullOrEmpty(AllureStoryReporter.storyName())) {
            story = AllureStoryReporter.storyName();
          }
        } catch (Throwable t) {

        }
        if (Strings.isNullOrEmpty(story)) {
          story = "recording " + result.getSessionId();
        }
        String title = "video_" + story;

        log.info("Session for story {}", title);
        videos.add(Collections.singletonMap(title, videoLink));
        ConfigLoader.config().setProperty("webdriver.videos", videos);
        checkGridExtras(GRID_URL, result);
        return result;
      }
    } catch (MalformedURLException e) {
      throw new RuntimeException("Cannot connect to grid", e);
    }
  }