Пример #1
0
 private Rectangle getItemBounds(int pos) {
   Dimension itemSize = getItemSize();
   Point p = new Point(BORDER_SIZE, pos * itemSize.height + BORDER_SIZE);
   Rectangle itemRect = new Rectangle(p, itemSize);
   itemRect.translate(scrollLocation.x, scrollLocation.y);
   return itemRect;
 }
Пример #2
0
  public static void main(String[] args) {
    // square
    Square square = new Square(5.6);
    System.out.println("area: " + square.getArea());
    System.out.println("perimeter: " + square.getPerimeter());

    // rectangle
    Rectangle rectangle = new Rectangle(1.2, 3.4);
    System.out.println("area: " + rectangle.getArea());
    System.out.println("perimeter: " + rectangle.getPerimeter());

    // circle
    Circle circle = new Circle(1.2);
    System.out.println("area: " + circle.getArea());
    System.out.println("perimeter: " + circle.getPerimeter());

    // triangle
    Triangle triangle = new Triangle(1.2, 1.2, 1.2);
    System.out.println("area: " + triangle.getArea());
    System.out.println("perimeter: " + triangle.getPerimeter());

    // shape
    Shape shape = new Circle(1);
    System.out.println("area: " + shape.getArea());
    System.out.println("perimeter: " + shape.getPerimeter());
  }
Пример #3
0
  private static void getRectangleSidesWithSquareAndPerimeter(
      Rectangle rectangle, double perimeter, double square) {
    double x;
    double y;
    double discriminant;

    double halfPerimeter = perimeter / 2;

    discriminant = (Math.pow(halfPerimeter, 2)) - (4 * 1 * square);

    if (discriminant > 0) {

      x = (halfPerimeter - Math.sqrt(discriminant)) / 2;
      rectangle.sideA = x;

      y = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideB = y;

    } else if (discriminant == 0) {

      x = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideA = x;

      y = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideB = y;

    } else {

      System.out.println("Maybe wrong data entered!");
    }
  }
Пример #4
0
  private Group createButtonArea(final Scene scene) {
    // create button area
    final Group buttonGroup = new Group();
    // rounded rect
    Rectangle buttonArea =
        RectangleBuilder.create()
            .arcWidth(15)
            .arcHeight(20)
            .fill(new Color(0, 0, 0, .55))
            .x(0)
            .y(0)
            .width(60)
            .height(30)
            .stroke(Color.rgb(255, 255, 255, .70))
            .build();
    buttonGroup.getChildren().add(buttonArea);

    // move button group when scene is resized
    buttonGroup
        .translateXProperty()
        .bind(scene.widthProperty().subtract(buttonArea.getWidth() + 6));
    buttonGroup
        .translateYProperty()
        .bind(scene.heightProperty().subtract(buttonArea.getHeight() + 6));
    return buttonGroup;
  }
Пример #5
0
  public static Segment[] slice(Rectangle r) {
    Segment[] retval = new Segment[r.getLines()];
    for (int i = 0; i < retval.length; ++i)
      retval[i] = new Segment(r.getPosition().vertical(i), r.getCols());

    return retval;
  }
Пример #6
0
 /** Este metodo ubica los componentes del SlotMachine en sus ubicaciones por defecto */
 private void presentacion() {
   marco.changeColor("black");
   marco.changeSize(50, 50 * casillas);
   marco.moveHorizontal(5);
   marco.moveVertical(5);
   /*ganador.moveVertical(10);
   ganador.moveHorizontal(10);
   ganador.moveHorizontal(50*(casillas/2));
   ganador.moveVertical(50);*/
   for (int i = 0; i < casillas; i++) {
     cubiculo[i] = new Rectangle();
     opcion[i] = new Circle();
   }
   for (int i = 0; i < casillas; i++) {
     cubiculo[i].changeSize(40, 40);
     cubiculo[i].changeColor("white");
     cubiculo[i].moveHorizontal(10);
     cubiculo[i].moveVertical(10);
     cubiculo[i].moveHorizontal(50 * i);
     opcion[i].changeSize(40);
     opcion[i].moveHorizontal(10);
     opcion[i].moveVertical(10);
     opcion[i].moveHorizontal(50 * i);
     opcion[i].changeColor(colores[dados[i]]);
   }
 }
Пример #7
0
 LRESULT WM_MOUSEMOVE(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_MOUSEMOVE(wParam, lParam);
   if (OS.COMCTL32_MAJOR < 6) {
     int x = OS.GET_X_LPARAM(lParam);
     int y = OS.GET_Y_LPARAM(lParam);
     if (OS.GetKeyState(OS.VK_LBUTTON) < 0) {
       int oldSelection = selection.y;
       selection.y = layout.getOffset(x, y, null);
       if (selection.y != oldSelection) {
         int newSelection = selection.y;
         if (oldSelection > newSelection) {
           int temp = oldSelection;
           oldSelection = newSelection;
           newSelection = temp;
         }
         Rectangle rect = layout.getBounds(oldSelection, newSelection);
         redraw(rect.x, rect.y, rect.width, rect.height, false);
       }
     } else {
       for (int j = 0; j < offsets.length; j++) {
         Rectangle[] rects = getRectangles(j);
         for (int i = 0; i < rects.length; i++) {
           Rectangle rect = rects[i];
           if (rect.contains(x, y)) {
             setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
             return result;
           }
         }
       }
       setCursor(null);
     }
   }
   return result;
 }
Пример #8
0
  public void positionWindow(boolean resetToDefault) {
    String mapWindow;

    mapShellBounds = mapShell.getBounds();
    mapWindow = prefs.get(RadarConsts.PREF_KEY_MAP_WINDOW, "");

    if (mapWindow.equals("") || resetToDefault) {
      Rectangle dispBounds, tableBounds;

      dispBounds = ((Display.getCurrent()).getPrimaryMonitor()).getClientArea();
      tableBounds = display.getShells()[1].getBounds();

      mapShellBounds.width = dispBounds.width - tableBounds.width;
      mapShellBounds.height = dispBounds.height;
      mapShellBounds.x = dispBounds.x + tableBounds.width;
      mapShellBounds.y = dispBounds.y;
    } else {
      String[] tokens = mapWindow.split(",");

      mapShellBounds =
          new Rectangle(
              new Integer(tokens[0]), // X value
              new Integer(tokens[1]), // Y value
              new Integer(tokens[2]), // Width
              new Integer(tokens[3]) // Height
              );
    }
    mapShell.setBounds(mapShellBounds);
  }
  @Test
  public void twentyFor4x5RectangleFromSquare() throws Exception {
    final Rectangle rectangle = new Rectangle();
    rectangle.setWidth(5);
    rectangle.setHeight(4);

    final Square square = new Square();
    square.setSideLength(3);

    List<Shape> shapes =
        new ArrayList<Shape>() {
          {
            add(rectangle);
            add(square);
          }
        };

    List<Integer> areas = new ArrayList<Integer>();
    for (Shape shape : shapes) {
      areas.add(shape.area());
    }

    assertEquals(20, areas.get(0).intValue());
    assertEquals(9, areas.get(1).intValue());
  }
Пример #10
0
  public static void main(String[] args) {
    // Figure f = new Figure(10, 10);
    Rectangle r = new Rectangle(9, 5);
    Triangle t = new Triangle(10, 8);

    System.out.println("Pole: " + r.area());
    System.out.println("Pole: " + t.area());
  }
Пример #11
0
  public static void main(String[] args) {

    Cicl c = new Cicl(2);
    Rectangle r = new Rectangle(3, 4);

    System.out.println(c.getS());
    System.out.println(r.getS());
  }
  @Test
  public void sixFor2x3Rectangle() throws Exception {
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(2);
    rectangle.setWidth(3);

    assertEquals(6, rectangle.area());
  }
Пример #13
0
 public static void main(String[] args) {
   Rectangle rectangle = new Rectangle(1, 2, 3, 4);
   // System.out.println(getHeight(rectangle));
   // System.out.println(getWidth(rectangle));
   ///////////////////// expected//////////////////
   System.out.println(getHeight(rectangle.castToHasHeight()));
   System.out.println(getWidth(rectangle.castToHasWidth()));
 }
Пример #14
0
  public Rectangle combineRectangles(Rectangle rect) {
    int x1, y1, x2, y2;

    x1 = Math.min(this.x1, rect.getX1());
    y1 = Math.min(this.y1, rect.getY1());
    x2 = Math.max(this.x2, rect.getX2());
    y2 = Math.max(this.y2, rect.getY2());
    return new Rectangle(x1, y1, x2, y2);
  };
Пример #15
0
  public static void main(String arags[]) {
    //        Rectangle myRect;
    //        myRect = new Rectangle();
    //        myRect.width = 40;
    //        myRect.height = 50;

    Rectangle myRect = new Rectangle(40, 50);
    System.out.println("myRect's area is " + myRect.area());
  }
Пример #16
0
 protected Point randomPointIn(Rectangle r) {
   double x = r.getMinX() + randomDouble() * r.getWidth();
   double y = r.getMinY() + randomDouble() * r.getHeight();
   x = normX(x);
   y = normY(y);
   Point p = ctx.makePoint(x, y);
   assertEquals(CONTAINS, r.relate(p));
   return p;
 }
Пример #17
0
  private Rectangle getDrawBounds(TableCellSWT cell) {
    Rectangle bounds = cell.getBounds();
    bounds.height -= 12;
    bounds.y += 6;
    bounds.x += 4;
    bounds.width -= 4;

    return bounds;
  }
Пример #18
0
  public Buttons(Screen screen, AbstractColor buttonClr, int width, int height, int offset) {
    this.buttonClr = buttonClr;

    leftButton = new Rectangle(0, 0, width, height);
    leftButton.translate(offset, screen.height() - height - offset);
    rightButton = new Rectangle(0, 0, width, height);
    rightButton.translate(screen.width() - width - offset, screen.height() - height - offset);
    fireButton = new Rectangle(0, 0, width, height);
    fireButton.translate(offset, screen.height() - height * 2 - offset * 2);
  }
Пример #19
0
 protected Point randomPointIn(Shape shape) {
   if (!shape.hasArea()) // or try the center?
   throw new UnsupportedOperationException("Need area to define shape!");
   Rectangle bbox = shape.getBoundingBox();
   Point p;
   do {
     p = randomPointIn(bbox);
   } while (!bbox.relate(p).intersects());
   return p;
 }
  public TicTacToeView(int x, int y, int w, int h, TicTacToeModel model) {
    // constructor method

    container = new Rectangle(x, y, w, h);
    container.setBackground(Color.black);
    container.setBounds(x, y, w, h);
    getSmallBox(x, y, w, h);
    modelChanged();
    this.model = model;
  }
Пример #21
0
 public static int getColumnAtPos(TreeItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
Пример #22
0
 public static void packColumns(@NotNull Tree tree, boolean fit, @Nullable float[] ratios) {
   tree.setRedraw(false);
   try {
     // Check for disposed items
     // TODO: it looks like SWT error. Sometimes tree items are disposed and NPE is thrown from
     // column.pack
     for (TreeItem item : tree.getItems()) {
       if (item.isDisposed()) {
         return;
       }
     }
     int totalWidth = 0;
     final TreeColumn[] columns = tree.getColumns();
     for (TreeColumn column : columns) {
       column.pack();
       totalWidth += column.getWidth();
     }
     Rectangle clientArea = tree.getClientArea();
     if (clientArea.isEmpty()) {
       return;
     }
     if (fit) {
       int areaWidth = clientArea.width;
       if (tree.getVerticalBar() != null) {
         areaWidth -= tree.getVerticalBar().getSize().x;
       }
       if (totalWidth > areaWidth) {
         int extraSpace = totalWidth - areaWidth;
         for (TreeColumn tc : columns) {
           double ratio = (double) tc.getWidth() / totalWidth;
           tc.setWidth((int) (tc.getWidth() - extraSpace * ratio));
         }
       } else if (totalWidth < areaWidth) {
         float extraSpace = areaWidth - totalWidth;
         if (columns.length > 0) {
           if (ratios == null || ratios.length < columns.length) {
             extraSpace /= columns.length;
             extraSpace--;
             for (TreeColumn tc : columns) {
               tc.setWidth((int) (tc.getWidth() + extraSpace));
             }
           } else {
             for (int i = 0; i < columns.length; i++) {
               TreeColumn tc = columns[i];
               tc.setWidth((int) (tc.getWidth() + extraSpace * ratios[i]));
             }
           }
         }
       }
     }
   } finally {
     tree.setRedraw(true);
   }
 }
Пример #23
0
 /**
  * ComplexAlgebraicNumber signum.
  *
  * @see edu.jas.structure.RingElem#signum()
  * @return signum(this).
  */
 public int signum() {
   try {
     Rectangle<C> v = ring.engine.invariantRectangle(ring.root, ring.algebraic.modul, number.val);
     ring.setRoot(v);
     Complex<C> c = v.getCenter();
     return c.signum();
   } catch (InvalidBoundaryException e) { // should not happen
     e.printStackTrace();
     throw new RuntimeException(e);
   }
 }
Пример #24
0
  public Rectangle intersectionOfREctangles(Rectangle rect) {
    int x1, y1, x2, y2;

    x1 = Math.max(this.x1, rect.getX1());
    y1 = Math.max(this.y1, rect.getY1());
    x2 = Math.min(this.x2, rect.getX2());
    y2 = Math.min(this.y2, rect.getY2());

    if ((x1 > x2) || (y1 > y2)) return new Rectangle(0, 0, 0, 0);
    return new Rectangle(x1, y1, x2, y2);
  };
Пример #25
0
 private Rectangle getMinRect(int idx1, int idx2) {
   if (!isDisplayable()) {
     return null;
   }
   Rectangle r1 = getItemBounds(idx1);
   Rectangle r2 = getItemBounds(idx2);
   Rectangle minRect = r1.union(r2);
   minRect.width = getClient().width - minRect.x + 1;
   minRect.grow(1, 1);
   return minRect;
 }
Пример #26
0
 /**
  * Returns true if the given object is logically equivalent to this; otherwise returns false.
  *
  * @return this.dimensions = dim.dimensions
  */
 public boolean equals(Object o) {
   if (o instanceof Rectangle) {
     final Rectangle r = (Rectangle) o;
     if (dimensions.length != r.dimensions.length || capacity() != r.capacity()) return false;
     for (int i = 0; i < dimensions.length; i++) {
       if (dimensions[i] != r.dimensions[i]) return false;
     }
     return true;
   }
   return false;
 }
Пример #27
0
 @Test
 public void getBoundedRectangleTest() {
   Point point1 = new Point(5.0, 5.0);
   Point point2 = new Point(0.0, 0.0);
   Circle circle = new Circle(point1, 5.0);
   Rectangle bound = new Rectangle(point2, 10.0, 10.0);
   assertEquals(
       "failure - bounded rectangle does not match",
       true,
       bound.equals(circle.getBoundedRectangle()));
 }
Пример #28
0
  /**
   * Initializes a new hierarchy of partial discs according to a tree of cluster nodes and other
   * parameters.
   *
   * @param <E> Concrete Type of IHierarchyData
   * @param tree Tree of hierarchy data objects which is used to build the partial disc tree.
   * @param idType IDType of the hierarchy data objects.
   * @param dataEventManager Concrete DataEventManager that is responsible for handling and
   *     triggering data specific events.
   * @param alColorModes List of drawing strategies that shall be used as color modes.
   */
  public <E extends AHierarchyElement<E>> void initHierarchy(
      Tree<E> tree,
      E heRoot,
      ADataEventManager dataEventManager,
      ArrayList<EPDDrawingStrategyType> alColorModes) {

    hashPartialDiscs.clear();
    selectionManager = new SelectionManager(tree.getNodeIDType());
    partialDiscTree = new Tree<PartialDisc>();
    navigationHistory.reset();
    drawingController.setDrawingState(EDrawingStateType.DRAWING_STATE_FULL_HIERARCHY);
    LabelManager.get().clearLabels();
    drawingStrategyManager.init(pickingManager, uniqueID, alColorModes);

    PartialDisc pdRoot =
        new PartialDisc(
            partialDiscTree, heRoot, drawingStrategyManager.getDefaultDrawingStrategy());
    partialDiscTree.setRootNode(pdRoot);
    partialDiscTree.setLeafIDType(tree.getLeaveIDType());
    partialDiscTree.setNodeIDType(tree.getNodeIDType());
    hashPartialDiscs.put(heRoot.getID(), pdRoot);
    // selectionManager.initialAdd(heRoot.getID());
    buildTree(tree, heRoot, pdRoot);
    pdRoot.calculateLargestChildren();
    iMaxDisplayedHierarchyDepth = DISP_HIER_DEPTH_DEFAULT;

    this.dataEventManager = dataEventManager;
    this.dataEventManager.registerEventListeners();

    pdCurrentRootElement = pdRoot;
    pdCurrentSelectedElement = pdRoot;
    pdRealRootElement = pdRoot;

    navigationHistory.addNewHistoryEntry(
        drawingController.getCurrentDrawingState(),
        pdCurrentRootElement,
        pdCurrentSelectedElement,
        iMaxDisplayedHierarchyDepth);

    selectionManager.addToType(SelectionType.SELECTION, pdCurrentRootElement.getElementID());

    controlBox = new Rectangle(0, 0, 0.3f, 0.2f);
    upwardNavigationSlider =
        new OneWaySlider(
            new Vec2f(controlBox.getMinX() + 0.1f, controlBox.getMinY() + 0.1f),
            0.2f,
            1f,
            pdRealRootElement.getHierarchyLevel(),
            1,
            0,
            pdRealRootElement.getDepth() - 1);
    upwardNavigationSlider.setMinSize(80);
  }
Пример #29
0
  @Override
  public boolean equals(Object obj) {
    if (obj == null || this.getClass() != obj.getClass()) {
      return false;
    }

    Rectangle other = (Rectangle) obj;
    if (getHeight() == other.getHeight() && getWidth() == other.getWidth()) {
      return true;
    }
    return false;
  }
Пример #30
0
  public static void main(String[] args) {
    Square square = new Square(4);
    Triangle triangle = new Triangle(3, 2, 3, 7.2, 5, 4.5);
    Rectangle rectangle = new Rectangle(6, 4);
    Circle circle = new Circle(8.5);

    System.out.println(square.getArea());
    System.out.println(triangle.getArea());
    System.out.println(triangle.getWidth());
    System.out.println(triangle.getHeight());
    System.out.println(rectangle.getArea());
    System.out.println(circle.getArea());
  }