@Override public Point getCenter(int page) { if (!ready) return new Point(0, 0); sPage = startState.getPage(); myPage = sPage; ePage = endState.getPage(); if (sPage == ePage) { if (!stub) { int x = (int) ((endPt.getX() - startPt.getX()) / 2 + startPt.getX()); int y = (int) ((endPt.getY() - startPt.getY()) / 2 + startPt.getY()); return new Point(x, y); } else { return new Point( (int) (startPt.getX() + len * .5 * Math.cos(angle)), (int) (startPt.getY() - len * .5 * Math.sin(angle))); } } else { if (page == sPage) { int x = (int) ((pageS.getX() - startPt.getX()) / 2 + startPt.getX()); int y = (int) ((pageS.getY() - startPt.getY()) / 2 + startPt.getY()); return new Point(x, y); } else { int x = (int) ((pageE.getX() - endPt.getX()) / 2 + endPt.getX()); int y = (int) ((pageE.getY() - endPt.getY()) / 2 + endPt.getY()); return new Point(x, y); } } }
protected void movePolygon(Point previousMousePoint, Point mousePoint) { // Intersect a ray through each mouse point, with a geoid passing through the reference // elevation. // If either ray fails to intersect the geoid, then ignore this event. Use the difference // between the two // intersected positions to move the control point's location. View view = this.wwd.getView(); Globe globe = this.wwd.getModel().getGlobe(); Position refPos = this.polygon.getReferencePosition(); if (refPos == null) return; Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY()); Line previousRay = view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY()); Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray); Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay); if (vec == null || previousVec == null) { return; } Position pos = globe.computePositionFromPoint(vec); Position previousPos = globe.computePositionFromPoint(previousVec); LatLon change = pos.subtract(previousPos); this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.0)); }
/* * (non-Javadoc) * * @see es.axios.udig.ui.georeferencing.internal.ui.MarkPresenter#draw() */ public void draw() { assert this.context != null; if (hide) return; ViewportGraphics graphics = context.getGraphics(); graphics.setColor(createColor(getMarkModel().hashCode())); if (point != null) { final int halfsize = EXTENT_SIZE / 2; this.extent = new Rectangle( (int) (point.getX() - halfsize), (int) (point.getY() - halfsize), EXTENT_SIZE, EXTENT_SIZE); graphics.fillOval(extent.x, extent.y, extent.width, extent.height); Rectangle2D stringBounds = graphics.getStringBounds(String.valueOf(getMarkModel().getID())); graphics.drawString( String.valueOf(getMarkModel().getID()), (int) point.getX(), (int) (point.getY() + stringBounds.getHeight()), ViewportGraphics.ALIGN_MIDDLE, ViewportGraphics.ALIGN_BOTTOM); } }
/** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data * @param closePath if true the path is closed and filled */ protected void render(EMFRenderer renderer, boolean closePath) { // create a GeneralPath containing GeneralPathes GeneralPath path = new GeneralPath(renderer.getWindingRule()); // iterate the polgons Point p; for (int polygon = 0; polygon < numberOfPoints.length; polygon++) { // create a new member of path GeneralPath gp = new GeneralPath(renderer.getWindingRule()); for (int point = 0; point < numberOfPoints[polygon]; point++) { // add a point to gp p = points[polygon][point]; if (point > 0) { gp.lineTo((float) p.getX(), (float) p.getY()); } else { gp.moveTo((float) p.getX(), (float) p.getY()); } } // close the member, add it to path if (closePath) { gp.closePath(); } path.append(gp, false); } // draw the complete path if (closePath) { renderer.fillAndDrawOrAppend(path); } else { renderer.drawOrAppend(path); } }
// ------------------------------ public void scrollToCaret() { // not called - fixed with putting visible scrollbars on JScrollPane // Rectangle rect1 = scroller1.getViewport().getViewRect(); double x1 = rect1.getX(); double y1 = rect1.getY(); double r1height = rect1.getHeight(); double r1width = rect1.getWidth(); Caret caret1 = editor1.getCaret(); Point pt2 = caret1.getMagicCaretPosition(); // the end of the string double x2 = pt2.getX(); double y2 = pt2.getY(); if (((x2 > x1) && (x2 < (x1 + r1width))) && ((y2 > y1) && (y2 < (y1 + r1height)))) { // inview } else { double newheight = r1height / 2; double newwidth = r1width / 2; double x3 = pt2.getX() - newwidth; double y3 = pt2.getY() - newheight; if (x3 < 0) x3 = 0; if (y3 < 0) y3 = 0; Rectangle rect3 = new Rectangle((int) x3, (int) y3, (int) newwidth, (int) newheight); editor1.scrollRectToVisible(rect3); } } // end scrollToCaret
public void mouseDragged(MouseEvent e) { int mods = e.getModifiersEx(); Point dragEnd = e.getPoint(); boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) > 0; boolean ctrl = (mods & MouseEvent.CTRL_DOWN_MASK) > 0; boolean alt = shift & ctrl; ctrl = ctrl & (!alt); shift = shift & (!alt); boolean nomods = !(shift | ctrl | alt); if (dragBegin == null) dragBegin = dragEnd; nodrag = false; if ((mods & InputEvent.BUTTON3_DOWN_MASK) > 0 || true) { double dx = dragEnd.getX() - dragBegin.getX(); double dy = dragEnd.getY() - dragBegin.getY(); synchronized (JImage.this) { t.preConcatenate(AffineTransform.getTranslateInstance(dx, dy)); } dragBegin = dragEnd; repaint(); } }
/** * 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; }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); int[] x = new int[3]; int[] y = new int[3]; double distance = startPoint.distance(endPoint); double halfDistance = distance / 2; double angle = -Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x); System.out.println(angle); x[0] = (int) endPoint.getX(); y[0] = (int) endPoint.getY(); x[1] = (int) ((Math.sin(angle) * halfDistance) + startPoint.getX()); y[1] = (int) ((Math.cos(angle) * halfDistance) + startPoint.getY()); x[2] = (int) (startPoint.getX() - (Math.sin(angle) * halfDistance)); y[2] = (int) (startPoint.getY() - (Math.cos(angle) * halfDistance)); g2d.setColor(Color.RED); g2d.fillPolygon(x, y, 3); g2d.setColor(Color.BLUE); g2d.fillOval(startPoint.x - 5, startPoint.y - 5, 10, 10); g2d.setColor(Color.GREEN); g2d.fillOval(endPoint.x - 5, endPoint.y - 5, 10, 10); g2d.dispose(); }
@Override public boolean Fuite(int refRMI, int refRMIaFuir) throws RemoteException { boolean res = false; VuePersonnage client = personnages.get(refRMI); if (client.isActionExecutee()) { // si une action a deja ete executee logActionDejaExecutee(refRMI); } else { Point pMoi = this.getPosition(refRMI); Point pAFuir = this.getPosition(refRMIaFuir); Point objectif = pMoi; if (pMoi.getX() - pAFuir.getX() > 0) objectif.x++; else objectif.x--; if (pMoi.getY() - pAFuir.getY() > 0) objectif.y++; else objectif.y--; // sinon, on tente de jouer l'interaction new Deplacement(client, getVoisins(refRMI)).seDirigeVers(objectif); client.executeAction(); res = true; } return res; }
public boolean mouseOnButton(MouseEvent event) { Point pt = event.getPoint(); if (pt.getX() >= button.getX() && pt.getX() <= button.getX() + button.getWidth()) { return true; } return false; }
public void mouseMoved(MouseEvent m) { // System.out.println("Mouse move"); double scale = 0.03; Point p = m.getPoint(); if (lastpoint != null) { double xm = scale * (p.getX() - lastpoint.getX()); double ym = scale * -(p.getY() - lastpoint.getY()); if (leftaction) { lhf.x = xm; lhf.y = ym; } else if (rightaction) { rhf.x = xm; rhf.y = ym; } else if (leftfaction) { lff.x = xm; lff.y = ym; } else if (rightfaction) { rff.x = xm; rff.y = ym; } else if (bodyaction) { bf.x = xm; bf.y = ym; } } lastpoint = p; }
/** * 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); } } }
/** Draw the connector on the simulation's canvas */ public void draw(Graphics g) { Color tColor; tColor = g.getColor(); // save exisiting color g.setColor(color); g.drawLine((int) pointA.getX(), (int) pointA.getY(), (int) pointB.getX(), (int) pointB.getY()); g.setColor(tColor); // restore previous color }
/** * Function move moves head of the snake in given direction. Direction and size of of map must be * provided * * @param direct directions of next move * @param mapSize size of game board * @return true-move was made, false-move cannot be made */ public boolean move(Directions direct, int mapSize) { ListIterator<Point> it = this.body.listIterator(); Point tmp = it.next(); switch (direct) { case UP: if (tmp.getY() != 0) { this.moveUp(); return true; } else return false; case DOWN: if (tmp.getY() != mapSize - 1) { moveDown(); return true; } else return false; case RIGHT: if (tmp.getX() != mapSize - 1) { moveRight(); return true; } else return false; case LEFT: if (tmp.getX() != 0) { moveLeft(); return true; } else return false; default: return false; } }
private void setDragTileLocation(Point mouseLocation) { Point frameOffset = parent.getLocation(); draggedTile.setLocation( (int) (mouseLocation.getX() - frameOffset.getX() - offset.getX() - 5), (int) (mouseLocation.getY() - frameOffset.getY() - offset.getY() - 30)); }
public static void main(String[] argv) throws AWTException { final JFrame f = new JFrame("Robot Test"); final JButton b = new JButton("Click me"); final JTextField tf = new JTextField(); final RobotTest t = new RobotTest(); f.add(tf, BorderLayout.NORTH); f.add(t, BorderLayout.CENTER); f.add(b, BorderLayout.SOUTH); f.pack(); f.setLocation(0, 0); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.setVisible(true); final Robot r = new Robot(); r.setAutoDelay(50); r.delay(1000); image = r.createScreenCapture(new Rectangle(0, 0, 200, 200)); t.repaint(); // for(int i = 0; i < 400; i++){ // r.mouseMove(i, i); // } b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { tf.setText("Clicked !"); } }); moveToCenterOfComponent(r, b); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); Point p = f.getLocationOnScreen(); p.translate(f.getWidth() / 2, 5); r.mouseMove((int) p.getX(), (int) p.getY()); r.mousePress(InputEvent.BUTTON1_MASK); for (int i = 0; i < 100; i++) { r.mouseMove((int) p.getX() + i, (int) p.getY() + i); } r.mouseRelease(InputEvent.BUTTON1_MASK); t.addMouseMotionListener( new MouseMotionAdapter() { public void mouseMoved(MouseEvent event) { Point p = event.getPoint(); SwingUtilities.convertPointToScreen(p, t); crtColor = r.getPixelColor(p.x, p.y); // Graphics g = t.getGraphics(); // g.setColor(crtColor); // g.fillRect(25,225, 50,50); t.repaint(); } }); }
void drawCurrentPoint(Graphics g, Point currentPoint) { int xSize = model.getxSize(); int ySize = model.getySize(); int scale = model.getScale(); g.setColor(Color.BLUE); g.drawLine(0, (int) (currentPoint.getY()), (xSize * scale), (int) (currentPoint.getY())); g.drawLine((int) (currentPoint.getX()), 0, (int) (currentPoint.getX()), (ySize * scale)); }
// This determines of the image desired to be drawn is within the visible portion of the area // viewport. private boolean isInRangeOfViewport(Point p) { // Check if the x coordinate is in range if (p.getX() + hexWidth / 2 < 0 || p.getX() - hexWidth / 2 > viewportWidth) { return false; } return !(p.getY() + hexHeight / 2 < 0 || p.getY() - hexHeight / 2 > viewportHeight); }
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); }
public boolean containsRobot(Point p) { if (p.getX() < location.getX()) return false; if (p.getY() < location.getY()) return false; if (p.getX() > (location.getX() + width)) return false; if (p.getY() > (location.getY() + height)) return false; return true; }
private void lineToEnd(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(lineStroke); g2.setColor(getMainFrame().getColorBoxForeground()); line.setLine( start.getX() / scale, start.getY() / scale, end.getX() / scale, end.getY() / scale); g2.draw(line); start = end; }
public boolean contains(Point p) { if (this.topLeft.getX() <= p.getX() && this.topLeft.getY() <= p.getY() && this.bottomRight.getX() >= p.getX() && this.bottomRight.getY() >= p.getY()) { return true; } return false; }
public void drawTo(Point start, Point end) { robot.mouseMove((int) start.getX(), (int) start.getY()); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(100); robot.mouseMove((int) end.getX(), (int) end.getY()); robot.delay(100); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(100); }
@Override public boolean isPointBelongNode(Point p) { if ((p.getX() >= Position.getX()) && (p.getX() <= Position.getX() + ShapeSize.getWidth()) && (p.getY() <= Position.getY()) && (p.getY() >= Position.getY() - ShapeSize.getHeight())) return true; else return false; }
private boolean recalcCheck() { double dx1 = tempStartPt.getX() - tempEndPt.getX(); double dy1 = tempStartPt.getY() - tempEndPt.getY(); double dx2 = startPt.getX() - endPt.getX(); double dy2 = startPt.getY() - endPt.getY(); if ((dx1 >= 0 && dx2 >= -20 || dx1 < 0 && dx2 < 20) && (dy1 >= 0 && dy2 >= -20 || dy1 < 0 && dy2 < 20)) return false; else return true; }
/** * Checks if the falling pentomino can fall further. * * @param pentomino The pentomino piece which is currently falling. * @param board The board in which the pentomino currently is. */ public boolean nextDropLegal(Pentomino pentomino, int[][] board, Point location) { boolean legalMove = true; // Self-explanatory. Just checks the next block to 'fall' to for all blocks of the pentomino for (Point p : pentomino.getLocation()) { int newX = (int) (p.getX() + location.getX()); int newY = (int) (p.getY() + location.getY() + 1); if (newY >= 0 && (newY >= board[0].length || board[newX][newY] != -1)) legalMove = false; } return legalMove; }
public String toString() { return (int) (topLeft.getX()) + " " + (int) (topLeft.getY()) + " " + (int) (bottomRight.getX()) + " " + (int) (bottomRight.getY()) + " "; }
/** * @todo Refactor this. Shouldn't mix localisation logic and relation mutation logic in one method * @todo-javadoc Write javadocs for method parameter * @todo-javadoc Write javadocs for method parameter * @todo-javadoc Write javadocs for return value * @todo-javadoc Write javadocs for method parameter * @param evt Describe what the parameter does * @return Describe the return value */ public boolean selectMaybe(MouseEvent evt) { boolean multiplicity = evt.isControlDown(); boolean cardinality = evt.isShiftDown(); Point point = evt.getPoint(); setSelected(_mainLine.intersects(point.getX() - 5, point.getY() - 5, 10, 10)); if (isSelected()) { double distFromP1 = Point2D.distance(_mainLine.getX1(), _mainLine.getY1(), point.getX(), point.getY()); boolean nearP1 = distFromP1 < _mainLength / 2; boolean leftChosen = (_leftIsWest && nearP1) || (!_leftIsWest && !nearP1); RelationshipRole role = leftChosen ? _rightRole : _leftRole; if (multiplicity) { // toggle multiplicity. Let's prevent the user from doing something stupid. Some // cardinalities // can't be changed. we know best etc. if (role.getRelation().isMany2Many()) { // don't allow to change cardinality of m:n relationships JOptionPane.showMessageDialog( null, "Can't change the cardinality of a many-to-many relationship", "Cardinality", JOptionPane.INFORMATION_MESSAGE); return false; } if (role.isFkPk()) { // don't allow to change cardinality of 1:1 relationships that are 1:1 because fk is also // pk JOptionPane.showMessageDialog( null, "Can't change the cardinality of a one-to-one relationship where the foreign key is also a primary key", "Cardinality", JOptionPane.INFORMATION_MESSAGE); return false; } if (role.isTargetPrimaryKey()) { JOptionPane.showMessageDialog( null, "Can't change the cardinality of a the one-side of a relationship that corresponds to a primary key", "Cardinality", JOptionPane.INFORMATION_MESSAGE); return false; } // All checks passed. Do the toggle role.setTargetMany(!role.isTargetMany()); } if (cardinality) { // toggle between uni/bidirectional role.setEnabled(!role.isEnabled()); } return true; } else { return false; } }
private static Double calculatingArea(Point pointA, Point pointB, Point pointC) { Double area = (pointA.getX() * (pointB.getY() - pointC.getY()) + pointB.getX() * (pointC.getY() - pointA.getY()) + pointC.getX() * (pointA.getY() - pointB.getY())) / 2; if (area < 0) { return -area; } return area; }
private void moveTruckIn() { setCenterLocation( getCenterX() - TRUCK_SPEED, getCenterY()); // changed from -1 to -TRUCK_SPEED by monroe to speed backing up animation up if (getCenterX() < truckOrig.getX()) // changed from > to < by monroe { setCenterLocation(((int) truckOrig.getX()), ((int) truckOrig.getY())); state = TruckState.LOADING; transducer.fireEvent(TChannel.TRUCK, TEvent.TRUCK_GUI_EMPTY_FINISHED, null); } }