// 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);
   }
 }
  // Draws the ShopMenu
  private void renderShopMenu(Graphics g, Graphics2D g2) {
    renderMenuUI(g, g2, "Shop");

    // Draws gridpane
    int centerX = (int) menuUI.getCenterX();
    int maxX = (int) menuUI.getMaxX();
    int maxY = (int) menuUI.getMaxY();
    int startY = menuUI.y + menuUI.height / 5;
    g2.drawLine(centerX, startY, centerX, maxY);
    g2.drawLine(menuUI.x, startY, maxX, startY);

    // 6*4
    for (int i = 0; i < 6; i++) {
      for (int k = 0; k < 4; k++) {
        g2.drawRect(
            menuUI.x + (menuGrid.width * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
        drawItems(
            g2,
            menuUI.x + (menuGrid.width * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
      }
    }

    // display cash
    g.setFont(fntSmall);
    g.drawString("Cash: 1005$", maxX - 2 * menuGrid.width, maxY - menuGrid.height / 3);
  }
Example #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++;
    }
  }
Example #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()));
    }
  }
Example #5
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();
    }
  }
Example #6
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);
 }
Example #7
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());
 }
Example #8
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);
   }
 }
  @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;
 }
  // Draws the CharacterOverview
  private void renderCharMenu(Graphics g, Graphics2D g2) {
    renderMenuUI(g, g2, "Character");

    // Draws gridpane
    int maxX = (int) menuUI.getMaxX();
    int maxY = (int) menuUI.getMaxY();
    int startY = menuUI.y + menuUI.height / 5;
    g2.drawLine(menuUI.x, startY, maxX, startY);
    g2.drawRect(menuUI.x + menuGrid.width, startY, 4 * menuGrid.width, 4 * menuGrid.height);

    // 2*4
    for (int i = 0; i < 2; i++) {
      for (int k = 0; k < 4; k++) {
        g2.drawRect(
            menuUI.x + ((menuUI.width - menuGrid.width) * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
        drawItems(
            g2,
            menuUI.x + ((menuUI.width - menuGrid.width)),
            startY + (menuGrid.height),
            menuGrid.width,
            menuGrid.height);
      }
    }

    // draws the character inside the big middle grid
    movingCharRight.renderAnimation(
        g,
        menuUI.x + 2 * menuGrid.width,
        startY + menuGrid.height,
        2 * menuGrid.width,
        2 * menuGrid.height);

    // charactar stats
    g.setFont(fntSmall);
    g.drawString("HP: 100/100", menuUI.x + menuGrid.width, maxY - menuGrid.height / 2);
    g.drawString("STR: 100", menuUI.x + menuGrid.width, maxY - menuGrid.height / 4);
    g.drawString("Lvl: 5", (int) menuUI.getCenterX() + menuGrid.width, maxY - menuGrid.height / 2);
    g.drawString(
        "XP: 7/100", (int) menuUI.getCenterX() + menuGrid.width, maxY - menuGrid.height / 4);
  }
  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);
  }
Example #13
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);
 }
Example #14
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);
   }
 }
  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);
  }
  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);
  }
Example #17
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);
  }
Example #19
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);
  }
Example #20
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));
    //        }
  }
Example #21
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);
    }
  }
Example #22
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;
  }
  // <editor-fold defaultstate="collapsed" desc="Visualization">
  @Override
  protected void paintComponent(Graphics g) {
    final Graphics2D G2 = (Graphics2D) g.create();

    MAIN_CENTER.setLocation(INNER_BOUNDS.getCenterX(), INNER_BOUNDS.getCenterX());
    SMALL_CENTER.setLocation(INNER_BOUNDS.getCenterX(), INNER_BOUNDS.width * 0.3130841121);

    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // Translate the coordinate system related to the insets
    G2.translate(getFramelessOffset().getX(), getFramelessOffset().getY());

    final AffineTransform OLD_TRANSFORM = G2.getTransform();

    // Draw combined background image
    G2.drawImage(bImage, 0, 0, null);

    G2.drawImage(
        smallTickmarkImage,
        ((INNER_BOUNDS.width - smallTickmarkImage.getWidth()) / 2),
        (int) (SMALL_CENTER.getY() - smallTickmarkImage.getHeight() / 2.0),
        null);

    // Draw the small pointer
    G2.rotate(
        Math.toRadians(minutePointerAngle + (2 * Math.sin(Math.toRadians(minutePointerAngle)))),
        SMALL_CENTER.getX(),
        SMALL_CENTER.getY());
    G2.drawImage(smallPointerShadowImage, 0, 0, null);
    G2.setTransform(OLD_TRANSFORM);
    G2.rotate(Math.toRadians(minutePointerAngle), SMALL_CENTER.getX(), SMALL_CENTER.getY());
    G2.drawImage(smallPointerImage, 0, 0, null);
    G2.setTransform(OLD_TRANSFORM);

    // Draw the main pointer
    G2.rotate(
        Math.toRadians(secondPointerAngle + (2 * Math.sin(Math.toRadians(secondPointerAngle)))),
        MAIN_CENTER.getX(),
        MAIN_CENTER.getY());
    G2.drawImage(mainPointerShadowImage, 0, 0, null);
    G2.setTransform(OLD_TRANSFORM);
    G2.rotate(Math.toRadians(secondPointerAngle), MAIN_CENTER.getX(), MAIN_CENTER.getY());
    G2.drawImage(mainPointerImage, 0, 0, null);
    G2.setTransform(OLD_TRANSFORM);

    // Draw combined foreground image
    G2.drawImage(fImage, 0, 0, null);

    if (!isEnabled()) {
      G2.drawImage(disabledImage, 0, 0, null);
    }

    // Translate the coordinate system back to original
    G2.translate(-getInnerBounds().x, -getInnerBounds().y);

    G2.dispose();
  }
  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);
    }
  }
 // Draws the building with a label on top
 private void drawBuilding(Graphics2D g2, Rectangle r, String Name, int type) {
   g2.drawString(Name, (int) r.getCenterX() - 5 * Name.length(), r.y);
   buildings[type].renderAnimation(g2, r.x, r.y, r.width, r.height);
 }
Example #26
0
  /**
   * if the edge is reflexive its painted as a cyclic edge if there are 2 controlpoints the
   * connection is painted as a straight line from the source to the targetanchor if there are more
   * as 2 controlpoints the connection path between 2 control points is painted as bezier curve
   */
  @Override
  protected void paintWidget() {

    List<Point> contrPoints = this.getControlPoints();
    int listSize = contrPoints.size();

    Graphics2D gr = getGraphics();

    if (listSize <= 2) {
      if (isReflexive()) { // special case for reflexive connection widgets
        Widget related = this.getTargetAnchor().getRelatedWidget();
        int position = this.edgeBalance(related);
        Rectangle bounds = related.convertLocalToScene(related.getBounds());
        gr.setColor(getLineColor());
        Point first = new Point();
        Point last = new Point();
        double centerX = bounds.getCenterX();
        first.x = (int) (centerX + bounds.width / 4);
        first.y = bounds.y + bounds.height;
        last.x = first.x;
        last.y = bounds.y;

        gr.setStroke(this.getStroke());

        double cutDistance = this.getTargetAnchorShape().getCutDistance();
        double anchorAngle = Math.PI / -3.0;
        double cutX = Math.abs(Math.cos(anchorAngle) * cutDistance);
        double cutY = Math.abs(Math.sin(anchorAngle) * cutDistance);
        int ydiff = first.y - last.y;
        int endy = -ydiff;
        double height = bounds.getHeight();
        double cy = height / 4.0;
        double cx = bounds.getWidth() / 5.0;
        double dcx = cx * 2;
        GeneralPath gp = new GeneralPath();
        gp.moveTo(0, 0);
        gp.quadTo(0, cy, cx, cy);
        gp.quadTo(dcx, cy, dcx, -height / 2.0);
        gp.quadTo(dcx, endy - cy, cy, -(cy + ydiff));
        gp.quadTo(cutX * 1.5, endy - cy, cutX, endy - cutY);

        AffineTransform af = new AffineTransform();
        AnchorShape anchorShape = this.getTargetAnchorShape();

        if (position < 0) {
          first.x = (int) (centerX - bounds.width / 4);
          af.translate(first.x, first.y);
          af.scale(-1.0, 1.0);
          last.x = first.x;
        } else {
          af.translate(first.x, first.y);
        }
        Shape s = gp.createTransformedShape(af);
        gr.draw(s);

        if (last != null) {
          AffineTransform previousTransform = gr.getTransform();
          gr.translate(last.x, last.y);

          if (position < 0) gr.rotate(Math.PI - anchorAngle);
          else gr.rotate(anchorAngle);

          anchorShape.paint(gr, false);
          gr.setTransform(previousTransform);
        }

      } else {
        super.paintWidget();
      }
      return;
    }

    // bezier curve...
    GeneralPath curvePath = new GeneralPath();
    Point lastControlPoint = null;
    double lastControlPointRotation = 0.0;

    Point prev = null;
    for (int i = 0; i < listSize - 1; i++) {
      Point cur = contrPoints.get(i);
      Point next = contrPoints.get(i + 1);
      Point nextnext = null;
      if (i < listSize - 2) {
        nextnext = contrPoints.get(i + 2);
      }

      double len = cur.distance(next);
      double scale = len * BEZIER_SCALE;
      Point bezierFrom = null; // first ControlPoint
      Point bezierTo = null; // second ControlPoint

      if (prev == null) {
        // first point
        curvePath.moveTo(cur.x, cur.y); // startpoint
        bezierFrom = cur;
      } else {
        bezierFrom = new Point(next.x - prev.x, next.y - prev.y);
        bezierFrom = scaleVector(bezierFrom, scale);
        bezierFrom.translate(cur.x, cur.y);
      }

      if (nextnext == null) { // next== last point (curve to)
        lastControlPoint = next;
        bezierTo = next; // set 2nd intermediate point to endpoint
        GeneralPath lastseg = this.subdivide(cur, bezierFrom, bezierTo, next);
        if (lastseg != null) curvePath.append(lastseg, true);
        break;
      } else {
        bezierTo = new Point(cur.x - nextnext.x, cur.y - nextnext.y);
        bezierTo = scaleVector(bezierTo, scale);
        bezierTo.translate(next.x, next.y);
      }

      curvePath.curveTo(
          bezierFrom.x, bezierFrom.y, // controlPoint1
          bezierTo.x, bezierTo.y, // controlPoint2
          next.x, next.y);
      prev = cur;
    }
    Point2D cur = curvePath.getCurrentPoint();
    Point next = lastControlPoint;

    lastControlPointRotation = // anchor anchorAngle
        Math.atan2(cur.getY() - next.y, cur.getX() - next.x);

    Color previousColor = gr.getColor();
    gr.setColor(getLineColor());
    Stroke s = this.getStroke();
    gr.setStroke(s);
    gr.setColor(this.getLineColor());
    gr.draw(curvePath);

    AffineTransform previousTransform = gr.getTransform();
    gr.translate(lastControlPoint.x, lastControlPoint.y);
    gr.rotate(lastControlPointRotation);
    AnchorShape targetAnchorShape = this.getTargetAnchorShape();
    targetAnchorShape.paint(gr, false);
    gr.setTransform(previousTransform);

    // paint ControlPoints if enabled
    if (isPaintControlPoints()) {
      int last = listSize - 1;
      for (int index = 0; index <= last; index++) {
        Point point = contrPoints.get(index);
        previousTransform = gr.getTransform();
        gr.translate(point.x, point.y);
        if (index == 0 || index == last) getEndPointShape().paint(gr);
        else getControlPointShape().paint(gr);
        gr.setTransform(previousTransform);
      }
    }
    gr.setColor(previousColor);
  }
 public Point2D getViewCenter() {
   double viewCenterX = viewBounds.getCenterX();
   double viewCenterY = viewBounds.getCenterY();
   return new Point2D.Float((float) viewCenterX, (float) viewCenterY);
 }
Example #28
0
 public final Point2D getCenterPoint() {
   return new Point2D(rectangle.getCenterX(), rectangle.getCenterY());
 }
Example #29
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;
  }