Package se.sics.cooja.interfaces

Examples of se.sics.cooja.interfaces.Position


    double realClickedX = clickedPoint.x / currentZoomX - currentPanX;
    double realClickedY = clickedPoint.y / currentZoomY - currentPanY;

    for (int i=0; i < currentRadioMedium.getRegisteredRadioCount(); i++) {
      Radio testRadio = currentRadioMedium.getRegisteredRadio(i);
      Position testPosition = testRadio.getPosition();

      if (realClickedX > testPosition.getXCoordinate() - realIconHalfWidth &&
          realClickedX < testPosition.getXCoordinate() + realIconHalfWidth &&
          realClickedY > testPosition.getYCoordinate() - realIconHalfHeight &&
          realClickedY < testPosition.getYCoordinate() + realIconHalfHeight) {
        hitRadios.add(testRadio);
      }
    }

    if (hitRadios.size() == 0) {
View Full Code Here


    for (Mote mote: motes) {
      String msg = getMoteString(mote);
      if (msg == null) {
        continue;
      }
      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);
      int msgWidth = fm.stringWidth(msg);
      g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
    }
  }
View Full Code Here

        repaint();
      }
    };
    simulation.getEventCentral().addMoteCountListener(newMotesListener = new MoteCountListener() {
      public void moteWasAdded(Mote mote) {
        Position pos = mote.getInterfaces().getPosition();
        if (pos != null) {
          pos.addObserver(posObserver);
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              resetViewport = 1;
              repaint();
            }
          });
        }
      }
      public void moteWasRemoved(Mote mote) {
        Position pos = mote.getInterfaces().getPosition();
        if (pos != null) {
          pos.deleteObserver(posObserver);
          repaint();
        }
      }
    });
    for (Mote mote: simulation.getMotes()) {
      Position pos = mote.getInterfaces().getPosition();
      if (pos != null) {
        pos.addObserver(posObserver);
      }
    }

    /* Observe mote highlights */
    gui.addMoteHighlightObserver(moteHighligtObserver = new Observer() {
View Full Code Here

  private double zoomFactor() {
    return viewportTransform.getScaleX();
  }

  private void zoomToFactor(double newZoom) {
    Position center = transformPixelToPosition(
        new Point(canvas.getWidth()/2, canvas.getHeight()/2)
    );
    viewportTransform.setToScale(
        newZoom,
        newZoom
    );
    Position newCenter = transformPixelToPosition(
        new Point(canvas.getWidth()/2, canvas.getHeight()/2)
    );
    viewportTransform.translate(
        newCenter.getXCoordinate() - center.getXCoordinate(),
        newCenter.getYCoordinate() - center.getYCoordinate()
    );
    repaint();
  }
View Full Code Here

        panning = false;
        return;
      }

      /* The current mouse position should correspond to where panning started */
      Position moved = transformPixelToPosition(x,y);
      viewportTransform.translate(
          moved.getXCoordinate() - panningPosition.getXCoordinate(),
          moved.getYCoordinate() - panningPosition.getYCoordinate()
      );
      repaint();
      return;
    }

    /* Zooming */
    if (zooming) {
      if (zoomingPosition == null || zoomingPixel == null || stop) {
        zooming = false;
        return;
      }

      /* The zooming start pixel should correspond to the zooming center position */
      /* The current mouse position should correspond to where panning started */
      double zoomFactor = 1.0 + Math.abs((double) zoomingPixel.y - y)/100.0;
      double newZoom = (zoomingPixel.y - y)>0?zoomStart*zoomFactor: zoomStart/zoomFactor;
      if (newZoom < 0.00001) {
        newZoom = 0.00001;
      }
      viewportTransform.setToScale(
          newZoom,
          newZoom
      );
      Position moved = transformPixelToPosition(zoomingPixel);
      viewportTransform.translate(
          moved.getXCoordinate() - zoomingPosition.getXCoordinate(),
          moved.getYCoordinate() - zoomingPosition.getYCoordinate()
      );
      repaint();
      return;
    }

    /* Moving */
    if (moving) {
      Position newPos = transformPixelToPosition(x, y);

      if (!stop) {
        canvas.setCursor(moveCursor);
        movedMote.getInterfaces().getPosition().setCoordinates(
            newPos.getXCoordinate(),
            newPos.getYCoordinate(),
            movedMote.getInterfaces().getPosition().getZCoordinate()
        );
        repaint();
        return;
      }
      /* Restore cursor */
      canvas.setCursor(Cursor.getDefaultCursor());


      /* Move mote */
      if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) {
        if (moveConfirm) {
          String options[] = {"Yes", "Cancel"};
          int returnValue = JOptionPane.showOptionDialog(Visualizer.this,
              "Move mote to" +
              "\nX=" + newPos.getXCoordinate() +
              "\nY=" + newPos.getYCoordinate() +
              "\nZ=" + movedMote.getInterfaces().getPosition().getZCoordinate(),
              "Move mote?",
              JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
              null, options, options[0]);
          moving = returnValue == JOptionPane.YES_OPTION;
        }
        if (moving) {
          movedMote.getInterfaces().getPosition().setCoordinates(
              newPos.getXCoordinate(),
              newPos.getYCoordinate(),
              movedMote.getInterfaces().getPosition().getZCoordinate()
          );
          repaint();
        }
      }
View Full Code Here

    - transformToPositionX(0);
    double paintedMoteHeight = transformToPositionY(MOTE_RADIUS)
    - transformToPositionY(0);

    for (int i = 0; i < simulation.getMotesCount(); i++) {
      Position pos = simulation.getMote(i).getInterfaces().getPosition();

      // Transform to unit circle before checking if mouse hit this mote
      double distanceX = Math.abs(xCoord - pos.getXCoordinate())
      / paintedMoteWidth;
      double distanceY = Math.abs(yCoord - pos.getYCoordinate())
      / paintedMoteHeight;

      if (distanceX * distanceX + distanceY * distanceY <= 1) {
        motes.add(simulation.getMote(i));
      }
View Full Code Here

    Mote[] allMotes = simulation.getMotes();

    /* Paint mote relations */
    MoteRelation[] relations = simulation.getGUI().getMoteRelations();
    for (MoteRelation r: relations) {
      Position sourcePos = r.source.getInterfaces().getPosition();
      Position destPos = r.dest.getInterfaces().getPosition();

      Point sourcePoint = transformPositionToPixel(sourcePos);
      Point destPoint = transformPositionToPixel(destPos);

      g.setColor(r.color == null ? Color.black : r.color);
      drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, MOTE_RADIUS + 1);
    }

    for (Mote mote: allMotes) {

      /* Use the first skin's non-null mote colors */
      Color moteColors[] = null;
      for (VisualizerSkin skin: currentSkins) {
        moteColors = skin.getColorOf(mote);
        if (moteColors != null) {
          break;
        }
      }
      if (moteColors == null) {
        moteColors = DEFAULT_MOTE_COLORS;
      }

      Position motePos = mote.getInterfaces().getPosition();

      Point pixelCoord = transformPositionToPixel(motePos);
      int x = pixelCoord.x;
      int y = pixelCoord.y;

View Full Code Here

    final double BORDER_SCALE_FACTOR = 1.1;
    double smallX, bigX, smallY, bigY, scaleX, scaleY;

    /* Init values */
    {
      Position pos = motes[0].getInterfaces().getPosition();
      smallX = bigX = pos.getXCoordinate();
      smallY = bigY = pos.getYCoordinate();
    }

    /* Extremes */
    for (Mote mote: motes) {
      Position pos = mote.getInterfaces().getPosition();
      smallX = Math.min(smallX, pos.getXCoordinate());
      bigX = Math.max(bigX, pos.getXCoordinate());
      smallY = Math.min(smallY, pos.getYCoordinate());
      bigY = Math.max(bigY, pos.getYCoordinate());
    }

    /* Scale viewport */
    if (smallX == bigX) {
      scaleX = 1;
    } else {
      scaleX = (bigX - smallX) / (canvas.getWidth());
    }
    if (smallY == bigY) {
      scaleY = 1;
    } else {
      scaleY = (bigY - smallY) / (canvas.getHeight());
    }

    viewportTransform.setToIdentity();
    double newZoom = (1.0/(BORDER_SCALE_FACTOR*Math.max(scaleX, scaleY)));
    viewportTransform.setToScale(
        newZoom,
        newZoom
    );

    /* Center visible motes */
    final double smallXfinal = smallX, bigXfinal = bigX, smallYfinal = smallY, bigYfinal = bigY;
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        Position viewMid =
          transformPixelToPosition(canvas.getWidth()/2, canvas.getHeight()/2);
        double motesMidX = (smallXfinal + bigXfinal) / 2.0;
        double motesMidY = (smallYfinal + bigYfinal) / 2.0;

        viewportTransform.translate(
            viewMid.getXCoordinate() - motesMidX,
            viewMid.getYCoordinate() - motesMidY);
        canvas.repaint();
      }
    });
  }
View Full Code Here

   */
  public Position transformPixelToPosition(Point pixelPos) {
    return transformPixelToPosition(pixelPos.x, pixelPos.y);
  }
  public Position transformPixelToPosition(int x, int y) {
    Position position = new Position(null);
    position.setCoordinates(
        transformToPositionX(x),
        transformToPositionY(y),
        0.0
    );
    return position;
View Full Code Here

      gui.deleteMoteRelationsObserver(moteRelationsObserver);
    }

    simulation.getEventCentral().removeMoteCountListener(newMotesListener);
    for (Mote mote: simulation.getMotes()) {
      Position pos = mote.getInterfaces().getPosition();
      if (pos != null) {
        pos.deleteObserver(posObserver);
      }
    }
  }
View Full Code Here

TOP

Related Classes of se.sics.cooja.interfaces.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.