java.awt.Point#getX ( )源码实例Demo

下面列出了java.awt.Point#getX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans-mmd-plugin   文件: MindMapPanel.java
private int calcDropPosition(@Nonnull final AbstractElement destination, @Nonnull final Point dropPoint) {
  final int result;
  if (destination.getClass() == ElementRoot.class) {
    result = dropPoint.getX() < destination.getBounds().getCenterX() ? DRAG_POSITION_LEFT : DRAG_POSITION_RIGHT;
  } else {
    final boolean destinationIsLeft = destination.isLeftDirection();
    final Rectangle2D bounds = destination.getBounds();

    final double edgeOffset = bounds.getWidth() * 0.2d;
    if (dropPoint.getX() >= (bounds.getX() + edgeOffset) && dropPoint.getX() <= (bounds.getMaxX() - edgeOffset)) {
      result = dropPoint.getY() < bounds.getCenterY() ? DRAG_POSITION_TOP : DRAG_POSITION_BOTTOM;
    } else if (destinationIsLeft) {
      result = dropPoint.getX() < bounds.getCenterX() ? DRAG_POSITION_LEFT : DRAG_POSITION_UNKNOWN;
    } else {
      result = dropPoint.getX() > bounds.getCenterX() ? DRAG_POSITION_RIGHT : DRAG_POSITION_UNKNOWN;
    }
  }
  return result;
}
 
源代码2 项目: chipster   文件: GraphPanel.java
/**
 * Zooms out.
 */
private void zoomOutToolUsed() {
	if (this.setGraphScale(graph.getScale() / this.ZOOM_FACTOR)) {
		JViewport view = this.getScroller().getViewport();
		Point viewPos = view.getViewPosition();
		center = new Point((int) (viewPos.getX() + view.getWidth() / 2), (int) (viewPos.getY() + view.getHeight() / 2));

		center.x = (int) (center.getX() / this.ZOOM_FACTOR);
		center.y = (int) (center.getY() / this.ZOOM_FACTOR);

		updateGridSize();

		this.pointToCenter(center);
	}

	this.repaint();
	this.getScroller().repaint();
	graph.repaint();
}
 
源代码3 项目: netbeans-mmd-plugin   文件: AbstractElement.java
@Nonnull
public ElementPart findPartForPoint(@Nonnull final Point point) {
  ElementPart result = ElementPart.NONE;
  if (this.bounds.contains(point)) {
    final double offX = point.getX() - this.bounds.getX();
    final double offY = point.getY() - this.bounds.getY();

    result = ElementPart.AREA;
    if (this.visualAttributeImageBlock.getBounds().contains(offX, offY)) {
      result = ElementPart.VISUAL_ATTRIBUTES;
    } else {
      if (this.textBlock.getBounds().contains(offX, offY)) {
        result = ElementPart.TEXT;
      } else if (this.extrasIconBlock.getBounds().contains(offX, offY)) {
        result = ElementPart.ICONS;
      }
    }
  }
  return result;
}
 
源代码4 项目: netcdf-java   文件: PopupManager.java
public void show(String text, Point p, Component owner, Object forWho) {
  if (isShowing && (showing == forWho)) {
    return;
  }
  if (isShowing) {
    popup.hide();
  }

  isShowing = true;
  showing = forWho;

  sbuff.setLength(0);
  sbuff.append("<html><body>");

  String textSubbed = CharMatcher.is('\n').replaceFrom(text, "<br>");
  sbuff.append(textSubbed);
  sbuff.append("</body></html>");
  info.setText(sbuff.toString());

  SwingUtilities.convertPointToScreen(p, owner);
  int x = (int) (p.getX());
  int y = (int) (p.getY());

  popup = factory.getPopup(owner, main, x + 5, y + 5); // LOOK 1.4
  if (popup != null) {
    popup.show();
  }
}
 
源代码5 项目: audiveris   文件: WedgesBuilder.java
/**
 * Wedges look like "hair pins", composed of two converging lines.
 * <p>
 * The pair of lines of a wedge are of similar length (short or long) and rather horizontal.
 * By comparison, ending lines are isolated, long and strictly horizontal.
 */
public void buildWedges ()
{
    // Use an area on left end of a segment and look for compatible segments
    // Do the same on right end of segments
    List<SegmentInter> segments = curves.getSegments();

    for (final boolean rev : new boolean[]{true, false}) {
        Collections.sort(segments, rev ? Inters.byAbscissa : Inters.byRightAbscissa);

        for (int index = 0; index < segments.size(); index++) {
            SegmentInter s1 = segments.get(index);

            // Define the lookup area
            Rectangle area = getArea(s1.getInfo(), rev);
            double xMax = area.getMaxX();

            for (SegmentInter s2 : segments.subList(index + 1, segments.size())) {
                Point sEnd = s2.getInfo().getEnd(rev);

                if (area.contains(sEnd)) {
                    // Check compatibility
                    GradeImpacts impacts = computeImpacts(s1, s2, rev);

                    if ((impacts != null) && (impacts.getGrade() >= WedgeInter.getMinGrade())) {
                        createWedgeInter(s1, s2, rev, impacts);
                        segments.remove(s1);
                        segments.remove(s2);
                        index--;

                        break;
                    }
                } else if (sEnd.getX() > xMax) {
                    break; // Since list is sorted by abscissa
                }
            }
        }
    }
}
 
源代码6 项目: rapidminer-studio   文件: AbstractChartPanel.java
/**
 * Translates a panel (component) location to a Java2D point.
 * 
 * @param screenPoint
 *            the screen location (<code>null</code> not permitted).
 * 
 * @return The Java2D coordinates.
 */

@Override
public Point2D translateScreenToJava2D(Point screenPoint) {
	Insets insets = getInsets();
	double x = (screenPoint.getX() - insets.left) / this.scaleX;
	double y = (screenPoint.getY() - insets.top) / this.scaleY;
	return new Point2D.Double(x, y);
}
 
源代码7 项目: marathonv5   文件: JavaElementPropertyAccessor.java
public String getPrecedingLabel() {
    Container container = component.getParent();
    if (container == null) {
        return null;
    }
    List<Component> allComponents = findAllComponents();
    // Find labels in the same row (LTR)
    // In the same row: labelx < componentx, labely >= componenty
    Point locComponent = component.getLocationOnScreen();
    List<Component> rowLeft = new ArrayList<Component>();
    for (Component label : allComponents) {
        Point locLabel = label.getLocationOnScreen();
        if (!(label instanceof JPanel) && locLabel.getX() < locComponent.getX() && locLabel.getY() >= locComponent.getY()
                && locLabel.getY() <= locComponent.getY() + component.getHeight() && !(label instanceof Filler)) {
            rowLeft.add(label);
        }
    }
    Collections.sort(rowLeft, new Comparator<Component>() {
        @Override
        public int compare(Component o1, Component o2) {
            Point locO1 = o1.getLocationOnScreen();
            Point locO2 = o2.getLocationOnScreen();
            return (int) (locO1.getX() - locO2.getX());
        }
    });
    if (rowLeft.size() > 0 && rowLeft.get(rowLeft.size() - 1) instanceof JLabel) {
        return stripLastColon(((JLabel) rowLeft.get(rowLeft.size() - 1)).getText().trim());
    }
    return null;
}
 
源代码8 项目: FastCopy   文件: FastCopyMainForm.java
public void init() {
	frame = new JFrame("MHISoft FastCopy " + UI.version);
	frame.setContentPane(layoutPanel1);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	//progressBar1.setVisible(false);
	progressBar1.setMaximum(100);
	progressBar1.setMinimum(0);

	progressPanel.setVisible(false);
	//frame.setPreferredSize(new Dimension(1200, 800));
	frame.setPreferredSize(new Dimension(UserPreference.getInstance().getDimensionX(), UserPreference.getInstance().getDimensionY()));

	frame.pack();

	/*position it*/
	//frame.setLocationRelativeTo(null);  // *** this will center your app ***
	PointerInfo a = MouseInfo.getPointerInfo();
	Point b = a.getLocation();
	int x = (int) b.getX();
	int y = (int) b.getY();
	frame.setLocation(x + 100, y);

	btnHelp.setBorder(null);

	frame.setVisible(true);


	componentsList = ViewHelper.getAllComponents(frame);
	setupFontSpinner();
	ViewHelper.setFontSize(componentsList, UserPreference.getInstance().getFontSize());



}
 
源代码9 项目: netbeans   文件: FruchtermanReingoldLayout.java
private void relayoutNonFixed(NodeWidget w) {
    Point masterPoint = new Point();
    masterPoint.setLocation(w.locX, w.locY);
    double r;
    double theta;
    double thetaStep = Math.PI / 5;
    r = 30;
    theta = 0;
    w.setFixed(false);
    while (true) {
        AffineTransform tr = AffineTransform.getRotateInstance(theta);
        Point2D d2point = tr.transform(new Point2D.Double(0, r), null);
        Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y);
        w.locX = point.getX();
        w.locY = point.getY();
        if (isThereFreeSpaceNonFixedSpace(w)) {
            w.setFixed(true);
            return;
        }
        theta = theta + thetaStep;
        if (theta > (Math.PI * 2 - Math.PI / 10)) {
            r = r + 30;
            theta = theta - Math.PI * 2;
            thetaStep = thetaStep * 3 / 4; 
        }
    }
    
}
 
源代码10 项目: rapidminer-studio   文件: OperatorInfoBubble.java
@Override
protected Point getObjectLocation() {
	// get all necessary parameters
	if (!getDockable().getComponent().isShowing()) {
		return new Point(0, 0);
	}

	Point rendererLoc = renderer.getVisibleRect().getLocation();
	Rectangle2D targetRect = renderer.getModel().getOperatorRect(operator);
	if (targetRect == null) {
		return rendererLoc;
	}
	Point loc = new Point((int) targetRect.getX(), (int) targetRect.getY());
	loc.x = (int) (loc.x * renderer.getModel().getZoomFactor());
	loc.y = (int) (loc.y * renderer.getModel().getZoomFactor());
	loc = ProcessDrawUtils.convertToAbsoluteProcessPoint(loc,
			renderer.getModel().getProcessIndex(operator.getExecutionUnit()), renderer.getModel());
	if (loc == null) {
		return rendererLoc;
	}

	if (!viewport.isShowing()) {
		return new Point(0, 0);
	}
	// calculate actual on screen loc of the operator and return it
	Point absoluteLoc = new Point((int) (viewport.getLocationOnScreen().x + (loc.getX() - rendererLoc.getX())),
			(int) (viewport.getLocationOnScreen().y + (loc.getY() - rendererLoc.getY())));

	// return validated Point
	return this.validatePointForBubbleInViewport(absoluteLoc);

}
 
源代码11 项目: PIPE   文件: SelectionManagerTest.java
@Test
public void selectsUsingLocationOnMousePress() {
    MouseEvent e = mock(MouseEvent.class);
    when(e.getButton()).thenReturn(MouseEvent.BUTTON1);
    when(e.isControlDown()).thenReturn(false);

    Point clickPoint = new Point(50, 50);
    when(e.getPoint()).thenReturn(clickPoint);
    manager.mousePressed(e);

    int x = (int) clickPoint.getX();
    int y = (int) clickPoint.getY();
    Rectangle rect = new Rectangle(x, y, 0, 0);
    verify(mockController).select(rect);
}
 
源代码12 项目: MikuMikuStudio   文件: MapModel2D.java
/**
 * Converts a pixel position into a mercator position
 * @param p {@Point} object that you wish to convert into
 *        longitude / latiude
 * @return the converted {@code Position} object
 * @since 1.0
 */
public Position toPosition(Point p) {
    double lat, lon;
    Position pos = null;
    try {
        Point pixelCentre = toPixel(new Position(0, 0));

        // Get the distance between position and the centre
        double xDistance = distance(xCentre, p.getX());
        double yDistance = distance(pixelCentre.getY(), p.getY());
        double lonDistanceInDegrees = (xDistance * minutesPerPixel) / 60;
        double mp = (yDistance * minutesPerPixel);
        // If we are zoomed in past a certain point, then use linear search.
        // Otherwise use binary search
        if (getMinutesPerPixel() < 0.05) {
            lat = findLat(mp, getCentre().getLatitude());
            if (lat == -1000) {
                System.out.println("lat: " + lat);
            }
        } else {
            lat = findLat(mp, 0.0, 85.0);
        }
        lon = (p.getX() < xCentre ? centre.getLongitude() - lonDistanceInDegrees
                : centre.getLongitude() + lonDistanceInDegrees);

        if (p.getY() > pixelCentre.getY()) {
            lat = -1 * lat;
        }
        if (lat == -1000 || lon == -1000) {
            return pos;
        }
        pos = new Position(lat, lon);
    } catch (InvalidPositionException ipe) {
        ipe.printStackTrace();
    }
    return pos;
}
 
源代码13 项目: PIPE   文件: AnnotationAction.java
/**
 * Creates a new annotation.
 *
 * @param point top left x,y location of the annotation
 * @param petriNetController controller for the Petri net this annotation is being added to.
 * @return newly created action at the specified point
 */
private Annotation getAnnotation(Point point, PetriNetController petriNetController) {

    int x = (int) point.getX();
    int y = (int) point.getY();
    Annotation annotation = new AnnotationImpl(x, y, "Enter text here", WIDTH, HEIGHT, true);

    PetriNet petriNet = petriNetController.getPetriNet();
    petriNet.addAnnotation(annotation);
    return annotation;
}
 
源代码14 项目: pumpernickel   文件: JColorPickerPanel.java
/**
 * Returns the color at the indicated point in HSB values.
 * 
 * @param p
 *            a point relative to this panel.
 * @return the HSB values at the point provided.
 */
public float[] getHSB(Point p) {
	if (mode == JColorPicker.RED || mode == JColorPicker.GREEN
			|| mode == JColorPicker.BLUE) {
		int[] rgb = getRGB(p);
		float[] hsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], null);
		return hsb;
	}

	int size = Math.min(MAX_SIZE, Math.min(getWidth() - imagePadding.left
			- imagePadding.right, getHeight() - imagePadding.top
			- imagePadding.bottom));
	p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2));
	if (mode == JColorPicker.BRI || mode == JColorPicker.SAT) {
		// the two circular views:
		double radius = (size) / 2.0;
		double x = p.getX() - size / 2.0;
		double y = p.getY() - size / 2.0;
		double r = Math.sqrt(x * x + y * y) / radius;
		double theta = Math.atan2(y, x) / (Math.PI * 2.0);

		if (r > 1)
			r = 1;

		if (mode == JColorPicker.BRI) {
			return new float[] { (float) (theta + .25f), (float) (r), bri };
		} else {
			return new float[] { (float) (theta + .25f), sat, (float) (r) };
		}
	} else {
		float s = ((float) p.x) / ((float) size);
		float b = ((float) p.y) / ((float) size);
		if (s < 0)
			s = 0;
		if (s > 1)
			s = 1;
		if (b < 0)
			b = 0;
		if (b > 1)
			b = 1;
		return new float[] { hue, s, b };
	}
}
 
源代码15 项目: mars-sim   文件: ConstructionWizard.java
@SuppressWarnings("restriction")
public synchronized void confirmSiteLocation(ConstructionSite site, ConstructionManager constructionManager,
		boolean isAtPreDefinedLocation, ConstructionStageInfo stageInfo, int constructionSkill) {
	//System.out.println("ConstructionWizard : entering confirmSiteLocation()");

       // Determine location and facing for the new building.
	double xLoc = site.getXLocation();
	double yLoc = site.getYLocation();
	double scale = mapPanel.getScale();

	Settlement currentS = settlementWindow.getMapPanel().getSettlement();
	if (currentS != constructionManager.getSettlement()) {

		if (mainScene != null) {
			mainScene.setSettlement(constructionManager.getSettlement());
		}
		else {
   			//desktop.openToolWindow(SettlementWindow.NAME);
			settlementWindow.getMapPanel().getSettlementTransparentPanel().getSettlementListBox()
				.setSelectedItem(constructionManager.getSettlement());
		}
	}
 		// set up the Settlement Map Tool to display the suggested location of the building
	mapPanel.reCenter();
	mapPanel.moveCenter(xLoc*scale, yLoc*scale);
	//mapPanel.setShowConstructionLabels(true);
	//mapPanel.getSettlementTransparentPanel().getConstructionLabelMenuItem().setSelected(true);

	String header = null;
	String title = null;
	String message = "(1) Will default to \"Yes\" in 90 secs unless timer is cancelled."
   			+ " (2) To manually place a site, click on \"Use Mouse\" button.";
	StringProperty msg = new SimpleStringProperty(message);
	String name = null;

	if (stageInfo != null) {
		name = stageInfo.getName();
		title = "A New " + Conversion.capitalize(stageInfo.getName()).replace(" X ", " x ") + " at " + constructionManager.getSettlement();
        // stageInfo.getType() is less descriptive than stageInfo.getName()
	}
	else {
		name = site.getName();
		title = "A New " + Conversion.capitalize(site.getName()).replace(" X ", " x ") + " at " + constructionManager.getSettlement();
	}

	if (isAtPreDefinedLocation) {
		header = "Would you like to place the " +  name + " at its default position? ";
	}
	else {
		header = "Would you like to place the " + name + " at this position? ";
	}


       if (mainScene != null) {
       	alertDialog(title, header, msg, constructionManager, site, true, stageInfo, constructionSkill);

	} else {

        desktop.openAnnouncementWindow("Pause for Construction Wizard");
        AnnouncementWindow aw = desktop.getAnnouncementWindow();
        Point location = MouseInfo.getPointerInfo().getLocation();
        double Xloc = location.getX() - aw.getWidth() * 2;
		double Yloc = location.getY() - aw.getHeight() * 2;
		aw.setLocation((int)Xloc, (int)Yloc);

		int reply = JOptionPane.showConfirmDialog(aw, header, TITLE, JOptionPane.YES_NO_OPTION);
		//repaint();

		if (reply == JOptionPane.YES_OPTION) {
            logger.info("The construction site is set");
		}
		else {
			//constructionManager.removeConstructionSite(site);
			//site = new ConstructionSite();
			site = positionNewSite(site);//, constructionSkill);
			confirmSiteLocation(site, constructionManager, false, stageInfo, constructionSkill);
		}

		desktop.disposeAnnouncementWindow();
	}

}
 
/**
 * Updates the currently hovered element
 *
 * @param e
 */
private void updateHoveringState(final MouseEvent e) {
	int hoveringProcessIndex = model.getHoveringProcessIndex();
	if (hoveringProcessIndex != -1) {
		ExecutionUnit hoveringProcess = model.getProcess(hoveringProcessIndex);
		Point relativeMousePosition = model.getMousePositionRelativeToProcess();
		int relativeX = (int) relativeMousePosition.getX();
		int relativeY = (int) relativeMousePosition.getY();

		OutputPort connectionSourceUnderMouse = controller.getPortForConnectorNear(relativeMousePosition, hoveringProcess);
		if (connectionSourceUnderMouse != model.getHoveringConnectionSource()) {
			model.setHoveringConnectionSource(connectionSourceUnderMouse);
			model.fireMiscChanged();
			e.consume();
		}

		// find inner sinks/sources under mouse
		if (controller.checkPortUnder(hoveringProcess.getInnerSinks(), relativeX, relativeY)
				|| controller.checkPortUnder(hoveringProcess.getInnerSources(), relativeX, relativeY)) {
			e.consume();
			return;
		}

		// find operator under mouse
		List<Operator> operators = hoveringProcess.getOperators();
		List<Operator> selectedOperators = model.getSelectedOperators();
		// if there are selected operators, they take precedence
		if (!operators.isEmpty() && !selectedOperators.isEmpty()) {
			operators = new ArrayList<>(operators);
			operators.sort((o1, o2) -> {
				int index1 = selectedOperators.indexOf(o1);
				int index2 = selectedOperators.indexOf(o2);
				if (index1 == index2) {
					return 0;
				}
				if (index1 == -1) {
					return -1;
				}
				if (index2 == -1) {
					return 1;
				}
				return index2 - index1;
			});
		}

		ListIterator<Operator> iterator = operators.listIterator(operators.size());
		while (iterator.hasPrevious()) {
			Operator op = iterator.previous();
			// first, check whether we are over a port
			if (controller.checkPortUnder(op.getInputPorts(), relativeX, relativeY)
					|| controller.checkPortUnder(op.getOutputPorts(), relativeX, relativeY)) {
				e.consume();
				return;
			}
			// If not, check operator.
			Rectangle2D rect = model.getOperatorRect(op);
			if (rect == null) {
				continue;
			}
			if (rect.contains(relativeMousePosition)) {
				if (model.getHoveringOperator() != op) {
					model.setHoveringPort(null);
					view.setHoveringOperator(op);
					if (model.getConnectingPortSource() == null) {
						if (model.getHoveringOperator() instanceof OperatorChain) {
							controller.showStatus(I18N.getGUILabel("processRenderer.displayChain.hover"));
						} else {
							controller.showStatus(I18N.getGUILabel("processRenderer.operator.hover"));
						}
					} else {
						controller.showStatus(I18N.getGUILabel("processRenderer.connection.hover_cancel"));
					}
				}
				view.updateCursor();
				e.consume();
				return;
			}
		}
	}
	if (model.getHoveringOperator() != null) {
		view.setHoveringOperator(null);
	}
	if (model.getHoveringPort() != null) {
		model.setHoveringPort(null);
		view.updateCursor();
		model.fireMiscChanged();
	}
	if (model.getHoveringConnectionSource() != null && model.getConnectingPortSource() == null) {
		controller.showStatus(I18N.getGUILabel("processRenderer.connection.hover"));
	} else if (model.getConnectingPortSource() != null) {
		controller.showStatus(I18N.getGUILabel("processRenderer.connection.hover_cancel"));
	} else {
		controller.clearStatus();
	}
}
 
源代码17 项目: procamtracker   文件: VirtualBall.java
public void setInitialVelocity(Point initialVelocity) {
    this.initialVelocity = new double[] { initialVelocity.getX(), initialVelocity.getY() };
}
 
源代码18 项目: rapidminer-studio   文件: ProcessRendererView.java
/**
 * Converts a {@link Point view point} to a point relative to the specified process.
 *
 * @param p
 *            the original point
 * @param processIndex
 *            the index of the process
 * @return the relative point or {@code null} if no process exists for the specified index
 * @see ProcessRendererView#fromProcessSpace(Point, int)
 */
public Point toProcessSpace(final Point p, final int processIndex) {
	if (processIndex == -1 || processIndex >= model.getProcesses().size()) {
		return null;
	}
	int xOffset = getXOffset(processIndex);
	double zoomFactor = model.getZoomFactor();
	return new Point((int) ((p.getX() - xOffset) * (1 / zoomFactor)), (int) (p.getY() * (1 / zoomFactor)));
}
 
源代码19 项目: SIMVA-SoS   文件: ChartPanel.java
/**
 * Translates a panel (component) location to a Java2D point.
 *
 * @param screenPoint  the screen location (<code>null</code> not
 *                     permitted).
 *
 * @return The Java2D coordinates.
 */
public Point2D translateScreenToJava2D(Point screenPoint) {
    Insets insets = getInsets();
    double x = (screenPoint.getX() - insets.left) / this.scaleX;
    double y = (screenPoint.getY() - insets.top) / this.scaleY;
    return new Point2D.Double(x, y);
}
 
源代码20 项目: PIPE   文件: SplitArcAction.java
/**
 *
 * @param arcController arc controller
 * @param mousePoint point at which to split the arc
 */
public SplitArcAction(ArcController<? extends Connectable, ? extends Connectable> arcController, Point mousePoint) {
    this.arcController = arcController;
    point = new Point2D.Double(mousePoint.getX(), mousePoint.getY());
}