Exemplo n.º 1
0
 /** @param e */
 @Override
 public void mouseExited(MouseEvent e) {
   exit.setLocation(e.getX(), e.getY());
   position.setLocation(e.getX(), e.getY());
   checkButton(e);
   fireEvent(e);
 }
Exemplo n.º 2
0
  public static String validMove(int pos) {
    Point tempPos = new Point(numbPos[pos].x, numbPos[pos].y);
    // point to left.
    tempPos.setLocation(numbPos[pos].x - 1, numbPos[pos].y);
    if (blank.equals(tempPos)) {
      return "left";
    }

    // point to right
    tempPos.setLocation(numbPos[pos].x + 1, numbPos[pos].y);
    if (blank.equals(tempPos)) {
      return "right";
    }

    // point at down
    tempPos.setLocation(numbPos[pos].x, numbPos[pos].y - 1);
    if (blank.equals(tempPos)) {
      return "down";
    }

    // point at up
    tempPos.setLocation(numbPos[pos].x, numbPos[pos].y + 1);
    if (blank.equals(tempPos)) {
      return "up";
    }
    return "none";
  }
Exemplo n.º 3
0
  /**
   * Compute the closest point on given segment defined by the given start and end points to the
   * given point.
   *
   * @param pt the point to get the closest point on the given segment
   * @param start the start point of the segment
   * @param stop the stop point of the segment
   * @param destPoint the closest point on the given segment to the given point
   * @return the closest distance from the given point to the given segment
   */
  static double getClosestPoint(Point pt, Point start, Point stop, Point destPoint) {

    double factor = projectionFactor(pt, start, stop);

    // the closest point is interior to the segment
    if (factor > 0 && factor < 1) {
      double x = start.x + factor * (stop.x - start.x);
      double y = start.y + factor * (stop.y - start.y);

      destPoint.setLocation(x, y);
      return destPoint.distance(pt);
    }

    double dist1 = start.distance(pt);
    double dist2 = stop.distance(pt);

    // the closest point is the start point of the segment
    if (dist1 < dist2) {
      destPoint.setLocation(start);
      return dist1;
    }

    // the closest point is the end point of the segment
    destPoint.setLocation(stop);
    return dist2;
  }
Exemplo n.º 4
0
 /** @param e */
 @Override
 public void mouseReleased(MouseEvent e) {
   mousedown = false;
   release.setLocation(e.getX(), e.getY());
   position.setLocation(e.getX(), e.getY());
   checkButton(e);
   fireEvent(e);
 }
Exemplo n.º 5
0
 /** @param e */
 @Override
 public void mousePressed(MouseEvent e) {
   mousedown = true;
   press.setLocation(e.getX(), e.getY());
   position.setLocation(e.getX(), e.getY());
   checkButton(e);
   fireEvent(e);
 }
Exemplo n.º 6
0
 /** @param e */
 @Override
 public void mouseDragged(MouseEvent e) {
   mousedrag = true;
   drag.setLocation(e.getX(), e.getY());
   position.setLocation(e.getX(), e.getY());
   checkButton(e);
   fireEvent(e);
 }
Exemplo n.º 7
0
 public void moveAnchor(int type, int deltaX, int deltaY) {
   if (type == TYPE_HEAD) {
     pointHead.setLocation(pointHead.x + deltaX, pointHead.y + deltaY);
   } else if (type == TYPE_TAIL) {
     pointTail.setLocation(pointTail.x + deltaX, pointTail.y + deltaY);
   }
   redraw();
 }
Exemplo n.º 8
0
 public void moveAnchor(long guuid, int deltaX, int deltaY) {
   if (anchorHeadUUID == guuid) {
     pointHead.setLocation(pointHead.x + deltaX, pointHead.y + deltaY);
   }
   if (anchorTailUUID == guuid) {
     pointTail.setLocation(pointTail.x + deltaX, pointTail.y + deltaY);
   }
   redraw();
 }
Exemplo n.º 9
0
  public static void main(String[] args) {
    System.out.println("Enter three points to calculate the area: ");
    Scanner reader = new Scanner(System.in);
    Point pointA = new Point();
    pointA.setLocation(reader.nextInt(), reader.nextInt());
    Point pointB = new Point();
    pointB.setLocation(reader.nextInt(), reader.nextInt());
    Point pointC = new Point();
    pointC.setLocation(reader.nextInt(), reader.nextInt());

    Double area = calculatingArea(pointA, pointB, pointC);
    System.out.println(area);
  }
Exemplo n.º 10
0
  public void render(Graphics g) {
    // points used for render culling
    // long starter = System.currentTimeMillis();

    Point origin =
        Globals.findTile(
            (int) player.getX() - Camera.width / 2, (int) player.getY() - Camera.height);
    Point bottomRight =
        Globals.findTile((int) player.getX() + Camera.width, (int) player.getY() + Camera.height);

    if (origin.x < 0) origin.setLocation(0, origin.y);
    if (origin.y < 0) origin.setLocation(origin.x, 0);

    if (bottomRight.x >= xLength) bottomRight.setLocation(xLength - 1, bottomRight.y);
    if (bottomRight.y >= yHeight) bottomRight.setLocation(bottomRight.x, yHeight - 1);

    ArrayList<Entity> sortList = new ArrayList<Entity>();

    for (Entity e : mobList) {
      sortList.add(e);
    }

    // render loop
    for (int x = origin.x; x < bottomRight.x; x++) {
      for (int y = bottomRight.y; y >= origin.y; y--) {
        try {
          if (tileMap[x][y] != null) {
            //	renderct++;
            tileMap[x][y].render(g);
          }
          if (walls[x][y] != null) sortList.add(walls[x][y]);
        } catch (Exception e) {
          System.out.println("EXCEPTION IN WORLD RENDER LOOP");
          e.printStackTrace();
        }
        ;
      }
    }

    Collections.sort(sortList, spriteSorter);
    if (player.target != null)
      player.selection.render(
          g,
          (int) ((Mob) player.target).getAttbox().getX() - 10,
          (int) ((Mob) player.target).getAttbox().getY() + 130);
    for (Entity e : sortList) {
      //	renderct++;
      e.render(g);
    }
  }
Exemplo n.º 11
0
 public void mouseDragged(MouseEvent e) {
   Point newPos = e.getPoint();
   SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
   int xDelta = newPos.x - origPos.x;
   int yDelta = newPos.y - origPos.y;
   Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
   if (wind != null) { // Should always be true
     if (getComponentOrientation().isLeftToRight()) {
       int w = wind.getWidth();
       if (newPos.x >= wind.getX()) {
         w += xDelta;
       }
       int h = wind.getHeight();
       if (newPos.y >= wind.getY()) {
         h += yDelta;
       }
       wind.setSize(w, h);
     } else { // RTL
       int newW = Math.max(1, wind.getWidth() - xDelta);
       int newH = Math.max(1, wind.getHeight() + yDelta);
       wind.setBounds(newPos.x, wind.getY(), newW, newH);
     }
     // invalidate()/validate() needed pre-1.6.
     wind.invalidate();
     wind.validate();
   }
   origPos.setLocation(newPos);
 }
Exemplo n.º 12
0
 /** @param e */
 @Override
 public void mouseMoved(MouseEvent e) {
   mousedrag = false;
   position.setLocation(e.getX(), e.getY());
   checkButton(e);
   fireEvent(e);
 }
Exemplo n.º 13
0
  /**
   * Calculates the position of a frame to be in the center of an other frame.
   *
   * @param parentFrame
   * @param frame
   * @return
   */
  public static Point getCenter(final Component parentFrame, final Window frame) {
    final Point point = new Point();
    int x = 0, y = 0;

    if (parentFrame == null || frame == null) {
      point.setLocation(x, y);
      return point;
    }

    x = parentFrame.getLocation().x + parentFrame.getSize().width / 2 - frame.getSize().width / 2;
    y = parentFrame.getLocation().y + parentFrame.getSize().height / 2 - frame.getSize().height / 2;

    point.setLocation(x, y);

    return point;
  }
Exemplo n.º 14
0
  private void showSliderMenu() {
    Point location = new Point(getX(), getY() + getHeight());

    SwingUtilities.convertPointToScreen(location, InputVolumeControlButton.this.getParent());

    if (isFullScreen()) {
      location.setLocation(
          location.getX(),
          location.getY() - sliderMenu.getPreferredSize().getHeight() - getHeight());
    }

    sliderMenu.setLocation(location);

    sliderMenu.addPopupMenuListener(
        new PopupMenuListener() {
          public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = true;
          }

          public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = false;
          }

          public void popupMenuCanceled(PopupMenuEvent ev) {}
        });

    sliderMenu.setVisible(!sliderMenu.isVisible());
  }
Exemplo n.º 15
0
 public void mousePressed(
     java.awt.event.MouseEvent ev,
     edu.cmu.cs.stage3.alice.core.Transformable pickedTransformable,
     edu.cmu.cs.stage3.alice.scenegraph.renderer.PickInfo pickInfo) {
   camera = (edu.cmu.cs.stage3.alice.core.Camera) pickInfo.getSource().getBonus();
   pressPoint.setLocation(ev.getPoint());
 }
Exemplo n.º 16
0
 @Override
 public void mouseClicked(MouseEvent e) {
   if (SwingUtilities.isRightMouseButton(e) && noteData.getSelectedNote() != null) {
     final String url =
         OsmApi.getOsmApi().getBaseUrl() + "notes/" + noteData.getSelectedNote().getId();
     ClipboardUtils.copyString(url);
     return;
   } else if (!SwingUtilities.isLeftMouseButton(e)) {
     return;
   }
   Point clickPoint = e.getPoint();
   double snapDistance = 10;
   double minDistance = Double.MAX_VALUE;
   final int iconHeight = ImageProvider.ImageSizes.SMALLICON.getAdjustedHeight();
   Note closestNote = null;
   for (Note note : noteData.getNotes()) {
     Point notePoint = Main.map.mapView.getPoint(note.getLatLon());
     // move the note point to the center of the icon where users are most likely to click when
     // selecting
     notePoint.setLocation(notePoint.getX(), notePoint.getY() - iconHeight / 2);
     double dist = clickPoint.distanceSq(notePoint);
     if (minDistance > dist && clickPoint.distance(notePoint) < snapDistance) {
       minDistance = dist;
       closestNote = note;
     }
   }
   noteData.setSelectedNote(closestNote);
 }
Exemplo n.º 17
0
 public Point getJoistick() {
   double xAng = Math.sin(nunchukJoistickAngle * Math.PI / 180.0) * nunchukJoistickMagnithude;
   double yAng = Math.cos(nunchukJoistickAngle * Math.PI / 180.0) * nunchukJoistickMagnithude;
   Point p = new Point();
   p.setLocation(xAng * 1000, yAng * 1000);
   return p;
 }
Exemplo n.º 18
0
 /**
  * Rotates a two-dimensional vector by the angle alpha.
  *
  * @param p Point
  * @param alpha double
  * @return q Point
  */
 public static Point rotate(Point p, double alpha) {
   double sina = Math.sin(alpha);
   double cosa = Math.cos(alpha);
   Point q = new Point();
   q.setLocation(p.getX() * cosa - p.getY() * sina, p.getX() * sina + p.getY() * cosa);
   return q;
 }
 public void selected(
     edu.cmu.cs.stage3.alice.core.Transformable pickedTransformable,
     edu.cmu.cs.stage3.alice.scenegraph.renderer.PickInfo pickInfo,
     Point p) {
   camera = (edu.cmu.cs.stage3.alice.core.Camera) pickInfo.getSource().getBonus();
   pressPoint.setLocation(p);
 }
Exemplo n.º 20
0
  public boolean startDragging(MouseEvent mouseEvent) {

    // Get the mouse position and the component of the mouse event.
    Component mouseComponent = (Component) mouseEvent.getSource();
    int x = mouseEvent.getX();
    int y = mouseEvent.getY();

    // Reset the fields.
    reset();

    // Initialize the fields for docking.

    // Get the origin dock.
    originDock = (LeafDock) SwingUtilities.getAncestorOfClass(LeafDock.class, mouseComponent);
    if (originDock != null) {
      // Control that the dragged dockable belongs to this dock.
      if (originDock.containsDockable(draggedDockable)) {
        // Calculate the dockable offset.
        dockableOffset.setLocation(x, y);
        dockableOffset =
            SwingUtilities.convertPoint(
                mouseComponent, dockableOffset, draggedDockable.getContent());

        // We could find a dockable for dragging.
        return true;
      }
    }

    // We could not find a dockable for dragging.
    return false;
  }
Exemplo n.º 21
0
  /** Sets the location for predicted pentomino */
  public void predictDrop() {

    predictedLocation = (Point) pentominoLocation.clone();
    while (nextDropLegal(activePentomino, gameBoard.getBoard(), predictedLocation)) {
      predictedLocation.setLocation(predictedLocation.getX(), predictedLocation.getY() + 1);
    }
  }
Exemplo n.º 22
0
  /**
   * Mouse dragged, initiates page panning if the tool is selected.
   *
   * @param e awt mouse event
   */
  public void mouseDragged(MouseEvent e) {
    if (documentViewController != null
        && documentViewController.getDocumentViewModel().getViewToolMode()
            == DocumentViewModel.DISPLAY_TOOL_PAN) {

      // Get data about the current view port position
      Adjustable verticalScrollbar = documentViewController.getVerticalScrollBar();
      Adjustable horizontalScrollbar = documentViewController.getHorizontalScrollBar();

      if (verticalScrollbar != null && horizontalScrollbar != null) {
        // calculate how much the view port should be moved
        Point p =
            new Point(
                (int) e.getPoint().getX() - horizontalScrollbar.getValue(),
                (int) e.getPoint().getY() - verticalScrollbar.getValue());
        int x = (int) (horizontalScrollbar.getValue() - (p.getX() - lastMousePosition.getX()));
        int y = (int) (verticalScrollbar.getValue() - (p.getY() - lastMousePosition.getY()));

        // apply the pan
        horizontalScrollbar.setValue(x);
        verticalScrollbar.setValue(y);

        // update last position holder
        lastMousePosition.setLocation(p);
      }
    }
  }
Exemplo n.º 23
0
 private void parseFlow() {
   for (InstanciaComponente component : componentList) {
     component.setEditable(false);
     for (FlowStateHistoryTO flowState : flowStateHistory) {
       if (component.ID == flowState.getState()) {
         touchedBlocks.add(component);
         if (StringUtils.isNotBlank(flowState.getExitPort())) {
           int index = component.C_B.nomes_saidas.indexOf(flowState.getExitPort());
           if (index > -1 && component.C_B.Pontos_Saida.length > index) {
             for (List<Conector> conectorList : component.lista_estado_saidas) {
               for (Conector conector : conectorList) {
                 if (conector.Comp instanceof Linha) {
                   Point point = new Point(component.C_B.Pontos_Saida[index]);
                   point.setLocation(component.Posicao_X + point.x, component.Posicao_Y + point.y);
                   Point p1 = ((Linha) conector.Comp).p1;
                   Point p2 = ((Linha) conector.Comp).p2;
                   if (p1.equals(point) || p2.equals(point)) {
                     touchedLines.add((Linha) conector.Comp);
                   }
                 }
               }
             }
           }
         }
         break;
       }
     }
   }
 }
Exemplo n.º 24
0
  public static Point CenterPoint(Dimension size) {
    Point loc_p = new Point();

    loc_p.setLocation(size.getWidth() / 2, size.getHeight() / 2);

    return loc_p;
  }
Exemplo n.º 25
0
 /**
  * Deletes a row.
  *
  * @param row the number of the row to delete
  * @return boolean <CODE>true</CODE> if the row was deleted; <CODE>false</CODE> if not
  */
 public boolean deleteRow(int row) {
   if (row < 0 || row >= rows.size()) {
     return false;
   }
   rows.remove(row);
   curPosition.setLocation(curPosition.x - 1, curPosition.y);
   return true;
 }
Exemplo n.º 26
0
  /**
   * ************************************************************************ * * Name:
   * getJumpPoint() * * Description: Finds the next possible directional movement on a HiQ board * *
   * Parameters * * INPUT: * pos * A Point instance containing a board coordinate * dir * A String
   * containing the direction to go * * OUTPUT: * A new Point instance *
   * ************************************************************************
   */
  public Point getJumpPoint(Point pos, String dir) {
    int column = (int) pos.getX();
    int row = (int) pos.getY();
    Point p = new Point(0, 0);

    if (dir == "left") {
      p.setLocation(column, row - 1);
    } else if (dir == "right") {
      p.setLocation(column, row + 1);
    } else if (dir == "up") {
      p.setLocation(column - 1, row);
    } else if (dir == "down") {
      p.setLocation(column + 1, row);
    }

    return p;
  }
Exemplo n.º 27
0
 private void zentriere(java.awt.Frame hf) {
   java.awt.Point OL = hf.getLocationOnScreen();
   OL.translate(hf.getWidth() / 2, hf.getHeight() / 2);
   OL.translate(-this.getWidth() / 2, -this.getHeight() / 2);
   if (OL.getX() < 0) OL.setLocation(0, OL.getY());
   if (OL.getY() < 0) OL.setLocation(OL.getX(), 0);
   this.setLocation(OL);
 }
Exemplo n.º 28
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      //            Component result = super.getTableCellRendererComponent(table, value, isSelected,
      // hasFocus, row, column);
      setValue(value);

      highlight.setLocation(-1, -1);
      hasSeparatorLine = column > 1 && column % 4 == 1;
      // ASCII dump
      if (column == table.getColumnCount() - 1) {
        long selStart = getSmallestSelectionIndex();
        long selEnd = getLargestSelectionIndex();

        final int hexColumns = model.getNumberOfHexColumns();
        int b1 = row * hexColumns;
        int b2 = b1 + hexColumns - 1;
        if (selStart <= b2 && selEnd >= b1) {
          long start = Math.max(selStart, b1) - b1;
          long end = Math.min(selEnd, b2) - b1;
          highlight.setLocation(start, end);
        }
        boolean alternateColor = alternateRowBackground && (row & 1) > 0;
        setBackground(alternateColor ? alternateCellColor : table.getBackground());
        setForeground(asciiDumpColor);
        hasSeparatorLine = false;
      } else {
        if (!isSelected) {
          if ((alternateRowBackground && (row & 1) > 0)
              ^ (alternateColumnBackground && (column & 1) > 0)) {
            setBackground(alternateCellColor);
          } else {
            setBackground(table.getBackground());
          }
        } else {
          setBackground(table.getSelectionBackground());
        }
        // Offset column
        if (column == 0) {
          setForeground(offsetColor);
        } else {
          setForeground(table.getForeground());
        }
      }

      return this;
    }
Exemplo n.º 29
0
  public static Point CenterPoint(Dimension parentSize, Dimension windowSize) {
    Point loc_p = new Point();

    loc_p.setLocation(
        (parentSize.getWidth() / 2) - (windowSize.getWidth() / 2),
        (parentSize.getHeight() / 2) - (windowSize.getHeight() / 2));

    return loc_p;
  }
Exemplo n.º 30
0
 public void drawSelection(Graphics g, String lastSubstring) {
   g.setXORMode(Color.black);
   if (activeStart != -1) {
     offset2Point(activeStart, false, activePoint);
     g.setColor(Color.magenta);
     int line = activePoint.x - 1;
     g.fillRect(line, activePoint.y, 1, lineHeight);
   }
   if (selection.isCaret()) {
     offset2Point(selection.caret, selection.clickAfter, caretPoint);
   } else {
     if (focus) g.setColor(Color.blue);
     else g.setColor(Color.yellow);
     offset2Point(selection.getStart(), true, startPoint);
     offset2Point(selection.getEnd(), false, endPoint);
     if (selection.getStart() == selection.caret) caretPoint.setLocation(startPoint);
     else caretPoint.setLocation(endPoint);
     if (startPoint.y == endPoint.y) {
       paintRect(
           g, startPoint.x, startPoint.y, Math.max(1, endPoint.x - startPoint.x), lineHeight);
     } else {
       paintRect(
           g, startPoint.x, startPoint.y, (mySize.width - xInset) - startPoint.x, lineHeight);
       if (startPoint.y + lineHeight < endPoint.y)
         paintRect(
             g,
             xInset,
             startPoint.y + lineHeight,
             (mySize.width - xInset) - xInset,
             endPoint.y - startPoint.y - lineHeight);
       paintRect(g, xInset, endPoint.y, endPoint.x - xInset, lineHeight);
     }
   }
   if (focus || selection.isCaret()) {
     if (focus) g.setColor(Color.green);
     else g.setColor(Color.red);
     int line = caretPoint.x - (selection.clickAfter ? 0 : 1);
     g.fillRect(line, caretPoint.y, 1, lineHeight);
     int w = lineHeight / 12 + 1;
     int braces = line - (selection.clickAfter ? -1 : w);
     g.fillRect(braces, caretPoint.y, w, 1);
     g.fillRect(braces, caretPoint.y + lineHeight - 1, w, 1);
   }
 }