// Draws a line that connects the building to each other
 private void drawLine(Graphics2D g2, Rectangle r1, Rectangle r2, String type) {
   int x1 = (int) r1.getCenterX();
   int y1 = (int) r1.getCenterY();
   int x2 = (int) r2.getCenterX();
   int y2 = (int) r2.getCenterY();
   if (type.equals("DownToUp")) {
     g2.drawLine(x1, r1.y + r1.height, r2.x, y2);
   } else if (type.equals("UpToDown")) {
     g2.drawLine((int) r1.getMaxX(), y1, x2, (int) r2.getMaxY());
   } else if (type.equals("SideToSide")) {
     g2.drawLine((int) r1.getMaxX(), y1 + 20, r2.x, y2 + 20);
   }
 }
Exemplo n.º 2
0
  /**
   * Calculate the affine transforms used to convert between world and pixel coordinates. The
   * calculations here are very basic and assume a cartesian reference system.
   *
   * <p>Tne transform is calculated such that {@code envelope} will be centred in the display
   *
   * @param envelope the current map extent (world coordinates)
   * @param paintArea the current map pane extent (screen units)
   */
  private void setTransforms(final Envelope envelope, final Rectangle paintArea) {
    ReferencedEnvelope refEnv = null;
    if (envelope != null) {
      refEnv = new ReferencedEnvelope(envelope);
    } else {
      refEnv = worldEnvelope();
      // FIXME content.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
    }

    java.awt.Rectangle awtPaintArea = Utils.toAwtRectangle(paintArea);
    double xscale = awtPaintArea.getWidth() / refEnv.getWidth();
    double yscale = awtPaintArea.getHeight() / refEnv.getHeight();

    double scale = Math.min(xscale, yscale);

    double xoff = refEnv.getMedian(0) * scale - awtPaintArea.getCenterX();
    double yoff = refEnv.getMedian(1) * scale + awtPaintArea.getCenterY();

    worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff);
    try {
      screenToWorld = worldToScreen.createInverse();

    } catch (NoninvertibleTransformException ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 3
0
  private void computeWorkersSizes(Dimension panelDimensions) {

    // check when the column of of workers start
    double startWorkerColumn = 8d * panelDimensions.getWidth() / 9d;

    double workerColumnWidth = panelDimensions.getWidth() - startWorkerColumn;
    workerXStart = startWorkerColumn + workerColumnWidth / 5d;
    workerXEnd = panelDimensions.getWidth() - workerColumnWidth / 5d;
    workerFirstY = panelDimensions.getHeight() / 9d;
    workerLastY = 8d * panelDimensions.getHeight() / 9d;
    workerHeight = (workerLastY - workerFirstY) / new Double(Market.numberOfWorkers);
    assert workerXStart > 0;
    assert workerXEnd > 0;
    assert workerFirstY > 0;
    assert workerLastY > 0;
    assert workerHeight > 0;

    int index = 0;
    for (Consumer x : SleepStoneTest.market.getLabor().workers) {
      Rectangle rectangle =
          new Rectangle(
              (int) workerXStart,
              (int) (workerFirstY + index * workerHeight),
              (int) (workerXEnd - workerXStart),
              (int) workerHeight);
      tradersPlace.put(x, new Point((int) rectangle.getCenterX(), (int) rectangle.getCenterY()));
      consumerPlace.put(x, rectangle);
      index++;
    }
  }
Exemplo n.º 4
0
  private void computeFirmSizes(Dimension panelDimensions) {

    ArrayList<Firm> firms = SleepStoneTest.firms;

    double rowMaxLenght = 8d * panelDimensions.getWidth() / 9d;

    // check when the column of of workers start
    double halfheight = panelDimensions.getHeight() / 2d;
    firmYStart = halfheight / 3d;
    firmYEnd = 2d * halfheight / 3d;

    firmFirstX = rowMaxLenght / 11d;
    firmLastX = 10d * rowMaxLenght / 11d;
    double rowRealLenght = firmLastX - firmFirstX;
    firmLenght = (rowRealLenght * 3d) / (4d * new Double(firms.size()));
    firmSpacing = firmLenght / 3d;

    // compute the rectangles
    for (int i = 0; i < firms.size(); i++) {

      Rectangle location =
          new Rectangle(
              (int) Math.round(firmFirstX + i * (firmLenght + firmSpacing)),
              (int) Math.round(firmYStart),
              (int) Math.round(firmLenght),
              (int) Math.round(firmYEnd - firmYStart));
      System.out.println(location);
      firmsPlace.put(firms.get(i), location);
      tradersPlace.put(
          firms.get(i), new Point((int) location.getCenterX(), (int) location.getCenterY()));
    }
  }
Exemplo n.º 5
0
 private static void setCenter(final Rectangle rectangle, final Point center) {
   final int diffX = center.x - (int) rectangle.getCenterX();
   final int diffY = center.y - (int) rectangle.getCenterY();
   final int x = ((int) rectangle.getX()) + diffX;
   final int y = (int) (rectangle.getY() + diffY);
   rectangle.setLocation(x, y);
 }
Exemplo n.º 6
0
 /**
  * Scales the view about the center of the canvas.
  *
  * @param scale the amount to scale
  */
 private void scaleViewAboutPoint(double scale) {
   Rectangle canvasBounds = graph.getCanvas().getBounds();
   graph
       .getCanvas()
       .getCamera()
       .scaleViewAboutPoint(scale, canvasBounds.getCenterX(), canvasBounds.getCenterY());
 }
Exemplo n.º 7
0
 /** Centers the window on the screen. */
 private void centerWindow() {
   Rectangle screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
   Point center = new Point((int) screen.getCenterX(), (int) screen.getCenterY());
   Point newLocation = new Point(center.x - this.getWidth() / 2, center.y - this.getHeight() / 2);
   if (screen.contains(newLocation.x, newLocation.y, this.getWidth(), this.getHeight())) {
     this.setLocation(newLocation);
   }
 }
Exemplo n.º 8
0
  @Override
  public void mouseMoved(MouseEvent e) {

    if (this.selecting) {
      this.disable();
      if (e.getX() > selected.getMaxX() - 5
          && e.getX() < selected.getMaxX() + 5
          && e.getY() > selected.getMaxY() - 5
          && e.getY() < selected.getMaxY() + 5) {
        e.getComponent().setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));
        curDir = DIR_SE;

      } else if (e.getX() == selected.getMinX()
          && (e.getY() < selected.getMaxY() && e.getY() > selected.getMinY())) {
        e.getComponent().setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
        curDir = DIR_W;
      } else if (e.getX() == selected.getMaxX()
          && (e.getY() < selected.getMaxY() && e.getY() > selected.getMinY())) {
        e.getComponent().setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
        curDir = DIR_E;
      } else if (e.getY() < selected.getMaxY() + 5
          && e.getY() > selected.getMaxY() - 5
          && (e.getX() < selected.getMaxX() && e.getX() > selected.getMinX())) {
        e.getComponent().setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
        curDir = DIR_S;
      } else if (e.getY() == selected.getMinY()
          && (e.getX() < selected.getMaxX() && e.getX() > selected.getMinX())) {
        curDir = DIR_N;
        e.getComponent().setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
      } else if (e.getY() < selected.getCenterY() + 10
          && e.getY() > selected.getCenterY() - 10
          && (e.getX() < (selected.getCenterX() + 10) && e.getX() > selected.getCenterX() - 10)) {
        e.getComponent().setCursor(new Cursor(Cursor.MOVE_CURSOR));
        this.enable();

        curDir = NOP;
      } else {
        e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        curDir = NOP;
      }
    } else {
      e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      curDir = NOP;
    }
  }
 /**
  * Drags an item to the specified inventory slot, which must be in the range of 0 and 27.
  *
  * @param item the inventory item
  * @param invSlot the inventory slot
  * @return <tt>true</tt> if dragged; otherwise <tt>false</tt>
  */
 public static boolean drag(Item item, int invSlot) {
   if (item != null) {
     if (invSlot >= 0 && invSlot <= 27) {
       Component slot = getComponent().getComponents()[invSlot];
       if (slot != null) {
         Rectangle slotRectangle = slot.getBoundingRect();
         Rectangle itemRectangle = item.getComponent().getContentRect();
         if (slotRectangle.contains(itemRectangle)) {
           return true;
         }
         Mouse.move((int) itemRectangle.getCenterX(), (int) itemRectangle.getCenterY(), 5, 5);
         Mouse.drag((int) slotRectangle.getCenterX(), (int) slotRectangle.getCenterY());
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 10
0
  public void paint(Graphics g) {
    // repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
      repaint();
    }
    // clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
      Graphics2D g2 = (Graphics2D) g.create();
      Insets insets = getInsets();
      Rectangle bounds = getBounds();

      // don't forget about insets
      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= insets.left + insets.right;
      bounds.height -= insets.top + insets.bottom;
      double centerX1 = bounds.getCenterX();
      double centerY1 = bounds.getCenterY();

      Rectangle tb = getTransformedSize();
      double centerX2 = tb.getCenterX();
      double centerY2 = tb.getCenterY();

      // set antialiasing by default
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (renderingHints != null) {
        g2.addRenderingHints(renderingHints);
      }
      // translate it to the center of the view component again
      double tx = centerX1 - centerX2 - getX();
      double ty = centerY1 - centerY2 - getY();
      g2.translate((int) tx, (int) ty);
      g2.transform(at);
      view.paint(g2);
      g2.dispose();
    }
    // paint the border
    paintBorder(g);
  }
Exemplo n.º 11
0
 private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) {
   final GeneralPath pixelPath =
       ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding());
   final Rectangle viewRect = viewport.getViewRect();
   final Rectangle pathBounds = pixelPath.getBounds();
   setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY()));
   final Dimension bounds =
       new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
   ensureRectIsInBounds(viewRect, bounds);
   viewport.scrollRectToVisible(viewRect);
 }
Exemplo n.º 12
0
 /**
  * Scrolls to a component then left clicks on it.
  *
  * @param o component to be clicked
  */
 protected void scrollToAndClickComponent(SGuiObject o) {
   scrollToComponent(o);
   Rectangle compRect = getComponentBounds(o);
   try {
     robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
     robot.mousePress(KeyEvent.BUTTON1_MASK);
     robot.mouseRelease(KeyEvent.BUTTON1_MASK);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   } catch (NullPointerException npe) {
     Log.debug("IGNORING Selenium NPE for scrollToAndClick '" + o.getWindowId() + "':", npe);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   }
 }
Exemplo n.º 13
0
  public void drawCollapsedMarker(int x, int y, int width, int height) {
    // rectangle
    int rectangleWidth = MARKER_WIDTH;
    int rectangleHeight = MARKER_WIDTH;
    Rectangle rect =
        new Rectangle(
            x + (width - rectangleWidth) / 2,
            y + height - rectangleHeight - 3,
            rectangleWidth,
            rectangleHeight);
    g.draw(rect);

    // plus inside rectangle
    Line2D.Double line =
        new Line2D.Double(
            rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2);
    g.draw(line);
    line =
        new Line2D.Double(
            rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY());
    g.draw(line);
  }
Exemplo n.º 14
0
  public static void paintButtonGroupLines(
      RadRootContainer rootContainer, RadButtonGroup group, Graphics g) {
    List<RadComponent> components = rootContainer.getGroupContents(group);
    if (components.size() < 2) return;
    Rectangle[] allBounds = new Rectangle[components.size()];
    int lastTop = -1;
    int minLeft = Integer.MAX_VALUE;
    for (int i = 0; i < components.size(); i++) {
      final Rectangle rc =
          SwingUtilities.convertRectangle(
              components.get(i).getParent().getDelegee(),
              components.get(i).getBounds(),
              rootContainer.getDelegee());
      allBounds[i] = rc;

      minLeft = Math.min(minLeft, rc.x);
      if (i == 0) {
        lastTop = rc.y;
      } else if (lastTop != rc.y) {
        lastTop = Integer.MIN_VALUE;
      }
    }

    Graphics2D g2d = (Graphics2D) g;
    Stroke oldStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(new Color(104, 107, 130));
    if (lastTop != Integer.MIN_VALUE) {
      // all items in group have same Y
      int left = Integer.MAX_VALUE;
      int right = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midX = (int) rc.getCenterX();
        left = Math.min(left, midX);
        right = Math.max(right, midX);
        g2d.drawLine(midX, lastTop - 8, midX, lastTop);
      }
      g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
    } else {
      int top = Integer.MAX_VALUE;
      int bottom = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midY = (int) rc.getCenterY();
        top = Math.min(top, midY);
        bottom = Math.max(bottom, midY);
        g2d.drawLine(minLeft - 8, midY, rc.x, midY);
      }
      g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
    }
    g2d.setStroke(oldStroke);
  }
Exemplo n.º 15
0
  public void routeEdge(Graphics2D g2d, VisualEdge vEdge) {

    Rectangle fromvertexBounds;
    Rectangle tovertexBounds;
    GeneralPath drawPath;
    VisualVertex visualVertexA = vEdge.getVisualVertexA();
    VisualVertex visualVertexB = vEdge.getVisualVertexB();

    drawPath = new GeneralPath();
    ;

    fromvertexBounds = visualVertexA.getBounds();
    tovertexBounds = visualVertexB.getBounds();

    // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous
    // path will be redrawn as well.
    drawPath.reset();

    // Start the line from the center of the vEdgertex
    drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY());
    drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY());
    vEdge.setShape(new VisualGraphComponentPath(drawPath));
  }
  /** Paints the <tt>visualEdge</tt>. No arrowhead is drawn. */
  public void paint(VisualGraphComponent component, Graphics2D g2d) {
    VisualEdge vEdge = (VisualEdge) component;
    Rectangle fromvertexBounds;
    Rectangle tovertexBounds;
    GeneralPath drawPath;
    VisualVertex visualVertexA = vEdge.getVisualVertexA();
    VisualVertex visualVertexB = vEdge.getVisualVertexB();
    GraphLayoutManager layoutmanager = vEdge.getVisualGraph().getGraphLayoutManager();

    drawPath = vEdge.getGeneralPath();

    // If there is no layoutmanager or there is one but the layout has not
    // been initialised, by default, let us route edges as straight lines.
    if (layoutmanager == null || (layoutmanager != null && !layoutmanager.isInitialized())) {

      fromvertexBounds = visualVertexA.getBounds();
      tovertexBounds = visualVertexB.getBounds();

      // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous
      // path will be redrawn as well.
      drawPath.reset();

      // Start the line from the center of the vEdgertex
      drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY());
      drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY());
    } else {
      // Let the layout manager determine how the edge will be routed.
      layoutmanager.routeEdge(g2d, vEdge);
    }

    // Draw the line
    g2d.setColor(vEdge.getOutlinecolor());
    g2d.draw(drawPath);

    // Draw the edge label
    this.paintText(vEdge, g2d);
  }
Exemplo n.º 17
0
  public NeuralRobot(float x, float y, Arena arena) {
    this(x, y);
    diameter = 12;
    boundingCircleRadius = (float) Math.sqrt(2 * diameter * diameter) / 2;
    myNumber = getNumber();
    this.arena = arena;
    this.world = arena.getWorld();
    body = new Body("Robot", new Box(diameter, diameter), 50f);
    body.setPosition((float) x, (float) y);
    body.setRotation(0);
    body.setDamping(baseDamping);
    body.setRotDamping(ROT_DAMPING_MUTIPLYING_CONST * baseDamping);
    setShape(new Rectangle2D.Double(0, 0, diameter, diameter));
    Rectangle r = getShape().getBounds();
    centerX = (float) r.getCenterX();
    centerY = (float) r.getCenterY();

    setSensors(NUM_SENSORS / 2, -Math.PI / 2, Math.PI / 2, 30, 30);
  }
Exemplo n.º 18
0
  @Override
  public void draw(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform at = g2.getTransform();
    heading = Math.atan2(direction.x, -direction.y);
    g2.rotate(heading, rectangle.getCenterX(), rectangle.getCenterY());
    if (boosting) {
      g2.drawImage(boostingImage, (int) pos.x, (int) pos.y, null);
    } else {
      g2.drawImage(image, (int) pos.x, (int) pos.y, null);
    }

    g2.setTransform(at);

    if (target != null) {
      if (target.isDead()) {
        target = null;
        return;
      }
      if (target instanceof Enemy) {
        g2.setColor(Color.RED);
        g2.draw(((Enemy) target).getRectangle());
      } else {
        g2.setColor(Color.CYAN);
        g2.draw(((Item) target).getRectangle());
      }
    }

    if (wasHit) {
      g2.setColor(new Color(0, shields >> 1, shields));
      g2.drawOval((int) pos.x, (int) pos.y, rectangle.width, rectangle.height);
      wasHit = false;
    }

    //        if(weapon instanceof Solaris) {
    //            g2.setColor(Color.DARK_GRAY);
    //            java.awt.Point p = getCenterPoint().getPoint();
    //            g2.drawLine(p.x, p.y, p.x + (int)(600*direction.x), p.y + (int)(600*direction.y));
    //        }
  }
Exemplo n.º 19
0
 public final Point2D getCenterPoint() {
   return new Point2D(rectangle.getCenterX(), rectangle.getCenterY());
 }
Exemplo n.º 20
0
  /**
   * <br>
   * <em>Purpose:</em> componentClick
   */
  protected void componentClick() throws SAFSException {
    if (compObject == null) {
      throw new SAFSException("Component SGuiObject is null.");
    }
    String locator = compObject.getLocator();
    Log.debug("component's locator=" + locator);

    setFocusToWindow();

    try {
      if (action.equalsIgnoreCase(CLICK) || action.equalsIgnoreCase(COMPONENTCLICK)) {
        selenium.click(locator);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(CTRLCLICK)) {
        selenium.controlKeyDown();
        selenium.click(locator);
        selenium.controlKeyUp();
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(DOUBLECLICK)) {
        selenium.doubleClick(locator);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(RIGHTCLICK)) {
        selenium.mouseDownRight(locator);
        selenium.mouseUpRight(locator);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(CTRLRIGHTCLICK)) {
        selenium.controlKeyDown();
        selenium.mouseDownRight(locator);
        selenium.mouseUpRight(locator);
        selenium.controlKeyUp();
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(SHIFTCLICK)) {
        selenium.shiftKeyDown();
        selenium.click(locator);
        selenium.shiftKeyUp();
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      }
    } catch (Exception e) {
      // Try SFAS robot to do the work.
      scrollToComponent(compObject);
      Rectangle compRect = getComponentBounds(compObject);

      if (compRect == null) {
        Log.error("component rectangle is null.");
        throw new SAFSException("component rectangle is null.");
      }

      // Log.info("Selenium mouseMove to: "
      // +(int)compRect.getCenterX()+":"+(int)compRect.getCenterY());
      if (action.equalsIgnoreCase(CLICK) || action.equalsIgnoreCase(COMPONENTCLICK)) {
        robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(CTRLCLICK)) {
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(DOUBLECLICK)) {
        robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(RIGHTCLICK)) {
        robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
        robot.mousePress(KeyEvent.BUTTON3_MASK);
        robot.mouseRelease(KeyEvent.BUTTON3_MASK);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(CTRLRIGHTCLICK)) {
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
        robot.mousePress(KeyEvent.BUTTON3_MASK);
        robot.mouseRelease(KeyEvent.BUTTON3_MASK);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      } else if (action.equalsIgnoreCase(SHIFTCLICK)) {
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
      }
    }

    // log success message and status
    if (testRecordData.getStatusCode() == StatusCodes.NO_SCRIPT_FAILURE) {
      String msg =
          genericText.convert(
              "success3",
              windowName + ":" + compName + " " + action + " successful.",
              windowName,
              compName,
              action);
      log.logMessage(testRecordData.getFac(), msg, PASSED_MESSAGE);
      return;
      // just in case. (normally any failure should have issued an Exception)
    } else {
      log.logMessage(
          testRecordData.getFac(),
          action
              + "\n"
              + testRecordData.getFilename()
              + " at Line "
              + testRecordData.getLineNumber()
              + ", "
              + testRecordData.getFac(),
          FAILED_MESSAGE);
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
    }
  }
Exemplo n.º 21
0
  public void drawInsideRectangle(
      Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintRequestAttributeSet properties)
      throws SymbolDrawingException {
    markerFillProperties.setSampleSymbol(markerSymbol);
    switch (markerFillProperties.getFillStyle()) {
      case SINGLE_CENTERED_SYMBOL:
        FPoint2D p = new FPoint2D(r.getCenterX(), r.getCenterY());
        markerSymbol.draw(g, null, p, null);
        break;
      case GRID_FILL:
        {
          g.setClip(r);
          int size = (int) markerSymbol.getSize();
          if (size <= 0) size = 1;
          Rectangle rProv = new Rectangle();
          rProv.setFrame(0, 0, size, size);
          Paint resulPatternFill = null;

          BufferedImage sample = null;
          sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
          Graphics2D gAux = sample.createGraphics();

          double xSeparation = markerFillProperties.getXSeparation(); // TODO
          // apply
          // CartographicSupport
          double ySeparation = markerFillProperties.getYSeparation(); // TODO
          // apply
          // CartographicSupport
          double xOffset = markerFillProperties.getXOffset();
          double yOffset = markerFillProperties.getYOffset();

          markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv, properties);

          rProv.setRect(0, 0, rProv.getWidth() + xSeparation, rProv.getHeight() + ySeparation);

          BufferedImage bi =
              new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
          gAux = bi.createGraphics();
          gAux.drawImage(sample, null, (int) (xSeparation * 0.5), (int) (ySeparation * 0.5));

          resulPatternFill = new TexturePaint(bi, rProv);
          g.setColor(null);
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

          // g.translate(xOffset, rProv.getHeight()-yOffset);
          g.translate(xOffset, -yOffset);
          g.setPaint(resulPatternFill);
          g.fill(r);
          // g.translate(-xOffset, -rProv.getHeight()+yOffset);
          g.translate(-xOffset, yOffset);
          g.setClip(null);
        }
        break;
      case RANDOM_FILL:
        g.setClip(r);
        int x = r.x;
        int y = r.y;
        int width = r.width;
        int height = r.height;
        g.setBackground(null);

        markerSymbol.draw(g, null, new FPoint2D((x + width * 0.2), (y + height * 0.8)), null);
        markerSymbol.draw(g, null, new FPoint2D((x + width * 0.634), (y + height * 0.3)), null);
        markerSymbol.draw(g, null, new FPoint2D((x + width * 0.26), (y + height * 0.35)), null);
        markerSymbol.draw(g, null, new FPoint2D((x + width * 0.45), (y + height * 0.98)), null);
        markerSymbol.draw(g, null, new FPoint2D((x + width * 0.9), (y + height * 0.54)), null);
        markerSymbol.draw(g, null, new FPoint2D((x + width * 1.1), (y + height * 0.7)), null);
        g.setClip(null);
        break;
    }
    if (getOutline() != null && hasOutline()) {
      if (properties == null)
        getOutline().draw(g, scaleInstance, new FPolyline2D(new GeneralPathX(r)), null);
      else getOutline().print(g, scaleInstance, new FPolyline2D(new GeneralPathX(r)), properties);
    }
  }
Exemplo n.º 22
0
  public Point2D.Double checkIntersectsCircle(Point2D.Double newLocation, HittableComponent h) {
    double dx, dy, dr, D, r, x1, x2, y1, y2, xa, xb, ya, yb, discriminant, centreX, centreY;
    double newX, newY;
    newX = newLocation.getX();
    newY = newLocation.getY();

    Rectangle hitableCircle = h.getHittableBounds(radius);

    centreX = hitableCircle.getCenterX();
    centreY = hitableCircle.getCenterY();

    // change newLocation so that the centre of the circle (centreX, centreY) would be at (0;0)
    x1 = x - centreX; // (x1;y1) is the point from where the bunny starts moving
    y1 = y - centreY;
    x2 = newX - centreX; // (x2;y2) is the predicted newLocation of the bunny
    y2 = newY - centreY;
    r = hitableCircle.getHeight() / 2;

    dx = x2 - x1;
    dy = y2 - y1;
    dr = Math.sqrt(dx * dx + dy * dy);
    D = (x1 * y2) - (x2 * y1);
    discriminant = r * r * dr * dr - D * D;

    // distance between the new newLocation and the centre of the circle smaller than radius
    if (Point.distance(x2, y2, 0, 0) < r) {

      // break the component
      breakComponent(h.getComponent());

      if (discriminant > 0) {
        int thisDirection;
        thisDirection = adjustThisDirection();

        xa = (D * dy + sgn(dy) * dx * Math.sqrt(discriminant)) / (dr * dr);
        xb = (D * dy - sgn(dy) * dx * Math.sqrt(discriminant)) / (dr * dr);
        ya = (-D * dx + modulus(dy) * Math.sqrt(discriminant)) / (dr * dr);
        yb = (-D * dx - modulus(dy) * Math.sqrt(discriminant)) / (dr * dr);

        if ((thisDirection > 90) && (thisDirection < 270)) {
          x2 = Math.max(xa, xb);
        } else {
          x2 = Math.min(xa, xb);
        }

        if (thisDirection > 180) {
          y2 = Math.max(ya, yb);
        } else {
          y2 = Math.min(ya, yb);
        }

        // switch back to the proper coordinate system
        newX = x2 + centreX;
        newY = y2 + centreY;

        // get the perpendicular angle to the hitpoint
        perpendicularAngle = calculateAngle(newX, newY, centreX, centreY, centreX + 1, centreY);
        newLocation = adjustBunnyWhenHit(perpendicularAngle, newX, newY);
      }
      orientation = fixOrientation(tempOrientation);
    }
    return newLocation;
  }
Exemplo n.º 23
0
  public Point2D.Double checkIntersectsSquare(Point2D.Double newLocation, RecCircle h) {
    double centreX, centreY, halfHeight, halfWidth, newX, newY;
    int thisDirection;
    Rectangle hitBounds = h.getRectangle().getHittableBounds(radius);
    Circle circle1 = h.getCircle1();
    Circle circle2 = h.getCircle2();

    newX = newLocation.getX();
    newY = newLocation.getY();
    centreX = hitBounds.getCenterX();
    centreY = hitBounds.getCenterY();
    halfHeight = hitBounds.getHeight() / 2;
    halfWidth = hitBounds.getWidth() / 2;

    if (hit(newX, newY, centreY, centreX, halfHeight, halfWidth)) {

      thisDirection = adjustThisDirection();

      if (hitFromBelowOrAbove(x, centreX, y, centreY, halfHeight, halfWidth, thisDirection)) {

        if (thisDirection > 180) {
          if (circle2 != null) {
            newLocation = checkIntersectsCircle(newLocation, circle2);
            newX = newLocation.getX();
            newY = newLocation.getY();

          } else {
            breakComponent(h.getComponent());
            perpendicularAngle = 270;
            newY = handleHitWall(centreY, halfHeight, perpendicularAngle);
            newX = adjustX(newY, thisDirection);
            newX = adjustBunnyWhenHit(perpendicularAngle, newX, newY).getX();
          }

        } else {
          if (circle1 != null) {
            newLocation = checkIntersectsCircle(newLocation, circle1);
            newX = newLocation.getX();
            newY = newLocation.getY();

          } else {
            breakComponent(h.getComponent());
            perpendicularAngle = 90;
            newY = handleHitWall(centreY, halfHeight, perpendicularAngle);
            newX = adjustX(newY, thisDirection);
            newX = adjustBunnyWhenHit(perpendicularAngle, newX, newY).getX();
          }
        }

      } else {
        if ((thisDirection < 270) && (thisDirection > 90)) {
          perpendicularAngle = 180;
        } else {
          perpendicularAngle = 0;
        }
        breakComponent(h.getComponent());
        newX = handleHitWall(centreX, halfWidth, perpendicularAngle);
        newY = adjustY(newX, sgn(179 - perpendicularAngle), thisDirection);
        newY = adjustBunnyWhenHit(perpendicularAngle, newX, newY).getY();
      }

      orientation = fixOrientation(tempOrientation);
    } else {
      if (circle1 != null) {
        newLocation = checkIntersectsCircle(newLocation, circle1);
        newX = newLocation.getX();
        newY = newLocation.getY();
      }
      if (circle2 != null) {
        newLocation = checkIntersectsCircle(newLocation, circle2);
        newX = newLocation.getX();
        newY = newLocation.getY();
      }
    }

    newLocation.setLocation(newX, newY);
    return newLocation;
  }
 public Point2D getViewCenter() {
   double viewCenterX = viewBounds.getCenterX();
   double viewCenterY = viewBounds.getCenterY();
   return new Point2D.Float((float) viewCenterX, (float) viewCenterY);
 }