类java.awt.Point源码实例Demo

下面列出了怎么用java.awt.Point的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Course_Generator   文件: MapMarkerImg.java
public void paint(Graphics g, Point position, int radio) {
	// int size_h = radio;
	// int size = img. size_h * 2;

	if (g instanceof Graphics2D && getBackColor() != null) {
		Graphics2D g2 = (Graphics2D) g;
		Composite oldComposite = g2.getComposite();
		g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
		g2.setPaint(getBackColor());
		g.drawImage(img, position.x - img.getWidth(null) / 2, position.y - img.getHeight(null) / 2, null);
		// g.fillOval(position.x - size_h, position.y - size_h, size, size);
		g2.setComposite(oldComposite);
	}
	g.setColor(getColor());
	g.drawImage(img, position.x - img.getWidth(null) / 2, position.y - img.getHeight(null) / 2, null);
	// g.drawOval(position.x - size_h, position.y - size_h, size, size);

	if (getLayer() == null || getLayer().isVisibleTexts())
		paintText(g, position);
}
 
源代码2 项目: openjdk-8   文件: RangeSlider.java
public void mousePressed(MouseEvent e) {
    if (model == null) {
        return;
    }

    Point p = e.getPoint();
    if (isOverFirstPosition(p)) {
        state = State.DragFirstPosition;
    } else if (isOverSecondPosition(p)) {
        state = State.DragSecondPosition;
    } else if (isOverSelection(p)) {
        state = State.DragBar;
    } else {
        return;
    }

    startPoint = e.getPoint();
    tempModel = model.copy();
}
 
源代码3 项目: triplea   文件: UnitsDrawer.java
public UnitsDrawer(
    final int count,
    final String unitType,
    final String playerName,
    final Point placementPoint,
    final int damaged,
    final int bombingUnitDamage,
    final boolean disabled,
    final boolean overflow,
    final String territoryName,
    final UiContext uiContext) {
  this.count = count;
  this.unitType = unitType;
  this.playerName = playerName;
  this.placementPoint = placementPoint;
  this.damaged = damaged;
  this.bombingUnitDamage = bombingUnitDamage;
  this.disabled = disabled;
  this.overflow = overflow;
  this.territoryName = territoryName;
  this.uiContext = uiContext;
}
 
源代码4 项目: jdk8u-dev-jdk   文件: BackgroundIsNotUpdated.java
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    sleep();
    window.setBackground(Color.GREEN);
    sleep();
    final Robot robot = new Robot();
    robot.setAutoDelay(200);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
源代码5 项目: JDKSourceCode1.8   文件: MetalToolBarUI.java
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
源代码6 项目: gcs   文件: WindowUtils.java
public static void packAndCenterWindowOn(Window window, Component centeredOn) {
    window.pack();
    Dimension prefSize = window.getPreferredSize();
    Dimension minSize  = window.getMinimumSize();
    int       width    = Math.max(prefSize.width, minSize.width);
    int       height   = Math.max(prefSize.height, minSize.height);
    int       x;
    int       y;
    if (centeredOn != null) {
        Point     where = centeredOn.getLocationOnScreen();
        Dimension size  = centeredOn.getSize();
        x = where.x + (size.width - width) / 2;
        y = where.y + (size.height - height) / 2;
    } else {
        Rectangle bounds = getMaximumWindowBounds(window);
        x = bounds.x + (bounds.width - width) / 2;
        y = bounds.y + (bounds.height - height) / 2;
    }
    window.setLocation(x, y);
    forceOnScreen(window);
}
 
源代码7 项目: opensim-gui   文件: ChartPanel.java
/**
 * Returns the data area (the area inside the axes) for the plot or subplot,
 * with the current scaling applied.
 *
 * @param x  the x-coordinate (for subplot selection).
 * @param y  the y-coordinate (for subplot selection).
 * 
 * @return The scaled data area.
 */
public Rectangle2D getScreenDataArea(int x, int y) {
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D result;
    if (plotInfo.getSubplotCount() == 0) {
        result = getScreenDataArea();
    } 
    else {
        // get the origin of the zoom selection in the Java2D space used for
        // drawing the chart (that is, before any scaling to fit the panel)
        Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
        int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
        if (subplotIndex == -1) {
            return null;
        }
        result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
    }
    return result;
}
 
源代码8 项目: mapleLemon   文件: MapleMap.java
public void broadcastMessage(MapleCharacter source, byte[] packet, double rangeSq, Point rangedFrom) {
    this.charactersLock.readLock().lock();
    try {
        for (MapleCharacter chr : characters) {
            if (chr != source) {
                if (rangeSq < Double.POSITIVE_INFINITY) {
                    if (rangedFrom.distance(chr.getTruePosition()) <= rangeSq) {
                        chr.getClient().getSession().write(packet);
                    }
                } else {
                    chr.getClient().getSession().write(packet);
                }
            }
        }
    } finally {
        this.charactersLock.readLock().unlock();
    }
}
 
源代码9 项目: audiveris   文件: Mask.java
private Table.UnsignedByte computeRelevantPoints (Area area)
{
    Table.UnsignedByte table = new Table.UnsignedByte(rect.width, rect.height);
    Point loc = rect.getLocation();
    table.fill(PixelFilter.BACKGROUND);

    for (int y = 0; y < rect.height; y++) {
        int ay = y + loc.y; // Absolute ordinate

        for (int x = 0; x < rect.width; x++) {
            int ax = x + loc.x; // Absolute abscissa

            if (area.contains(ax, ay)) {
                table.setValue(x, y, 0);
                pointCount++;
            }
        }
    }

    return table;
}
 
源代码10 项目: 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();
}
 
源代码11 项目: FCMFrame   文件: CCSystem.java
private GradientPaint translateGradientPaint(GradientPaint gp) {
    Point p1 = translate(gp.getPoint1());
    Point p2 = translate(gp.getPoint2());

    Color c1 = gp.getColor1();
    Color c2 = gp.getColor2();

    return new GradientPaint(p1, c1, p2, c2);
}
 
源代码12 项目: hottub   文件: DiagramScene.java
private Point calcCenter(Rectangle r) {

        Point center = new Point((int) r.getCenterX(), (int) r.getCenterY());
        center.x -= getScrollPane().getViewport().getViewRect().width / 2;
        center.y -= getScrollPane().getViewport().getViewRect().height / 2;

        // Ensure to be within area
        center.x = Math.max(0, center.x);
        center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x);
        center.y = Math.max(0, center.y);
        center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y);

        return center;
    }
 
源代码13 项目: snap-desktop   文件: UIUtils.java
/**
 * Ensures that the popup menue is allways inside the application frame
 */
public static void showPopup(JPopupMenu popup, MouseEvent event) {
    if (popup == null) {
        return;
    }
    final Component component = event.getComponent();
    final Point point = event.getPoint();
    popup.show(component, point.x, point.y);
}
 
源代码14 项目: jdk8u-jdk   文件: X11GraphicsEnvironment.java
/**
 * Override for Xinerama case: call new Solaris API for getting the correct
 * centering point from the windowing system.
 */
public Point getCenterPoint() {
    if (runningXinerama()) {
        Point p = getXineramaCenterPoint();
        if (p != null) {
            return p;
        }
    }
    return super.getCenterPoint();
}
 
源代码15 项目: audiveris   文件: BarFilamentFactory.java
/**
 * Use the long source sections to stick to the provided skeleton and return
 * the resulting filament.
 * <p>
 * Strategy: We use only the long sections that intersect core length (height) and are close
 * enough to the core mid line.
 *
 * @param source the input sections
 * @param core   the oriented core rectangle
 */
private Filament populateCore (Collection<Section> source,
                               Rectangle core)
{
    final Filament fil = new CurvedFilament(scale.getInterline(), params.segmentLength);

    for (Section section : source) {
        Rectangle sectRect = VERTICAL.oriented(section.getBounds());

        // Section with significant length, intersecting core and centroid in core alignment?
        if (sectRect.width >= params.minCoreSectionLength) {
            if (sectRect.intersects(core)) {
                Point oCentroid = VERTICAL.oriented(section.getCentroid());

                if (GeoUtil.yEmbraces(core, oCentroid.y)) {
                    fil.addSection(section);
                }
            }
        }
    }

    if (!fil.getMembers().isEmpty()) {
        return fil;
    } else {
        return null;
    }
}
 
源代码16 项目: RipplePower   文件: LGraphicsMath.java
public final static int getBoundingShape(int xPoints[], int yPoints[], int startAngle, int arcAngle, int centerX,
		int centerY, int boundingX, int boundingY, int boundingWidth, int boundingHeight) {
	xPoints[0] = centerX;
	yPoints[0] = centerY;
	Point startPoint = getBoundingPointAtAngle(boundingX, boundingY, boundingWidth, boundingHeight, startAngle);
	xPoints[1] = startPoint.x;
	yPoints[1] = startPoint.y;
	int i = 2;
	for (int angle = 0; angle < arcAngle; i++, angle += 90) {
		if (angle + 90 > arcAngle
				&& ((startAngle + angle - 45) % 360) / 90 == ((startAngle + arcAngle + 45) % 360) / 90) {
			break;
		}
		int modAngle = (startAngle + angle) % 360;
		if (modAngle > 315 || modAngle <= 45) {
			xPoints[i] = boundingX + boundingWidth;
			yPoints[i] = boundingY;
		} else if (modAngle > 135 && modAngle <= 225) {
			xPoints[i] = boundingX;
			yPoints[i] = boundingY + boundingHeight;
		} else if (modAngle > 45 && modAngle <= 135) {
			xPoints[i] = boundingX;
			yPoints[i] = boundingY;
		} else {
			xPoints[i] = boundingX + boundingWidth;
			yPoints[i] = boundingY + boundingHeight;
		}
	}
	Point endPoint = getBoundingPointAtAngle(boundingX, boundingY, boundingWidth, boundingHeight,
			(startAngle + arcAngle) % 360);
	if (xPoints[i - 1] != endPoint.x || yPoints[i - 1] != endPoint.y) {
		xPoints[i] = endPoint.x;
		yPoints[i++] = endPoint.y;
	}
	return i;
}
 
源代码17 项目: dsworkbench   文件: ReportShowDialog.java
private void fireTitleDraggedEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireTitleDraggedEvent
    Point pos = evt.getLocationOnScreen();
    if (pos == null) {
        return;
    }
    pos.translate(-dndDelta.x, -dndDelta.y);
    setLocation(pos);
}
 
源代码18 项目: Course_Generator   文件: AttributionSupport.java
public boolean handleAttributionCursor(Point p) {
	if (attrTextBounds != null && attrTextBounds.contains(p)) {
		return true;
	} else if (attrImageBounds != null && attrImageBounds.contains(p)) {
		return true;
	} else if (attrToUBounds != null && attrToUBounds.contains(p)) {
		return true;
	}
	return false;
}
 
@Override
public Vector3f convertTranslationToDrag(final Camera camera, final Vector3f nodeLocation, final Point from, final Point to) {

    // Calculate the vector representing the drag (in window coordinates)
    final int dx = to.x - from.x;
    final int dy = to.y - from.y;
    final Vector3f movement = new Vector3f(dx, dy, 0);

    // Calculate and return the vector representing the drag in graph coordinates.
    final Vector3f newposition = new Vector3f();
    Graphics3DUtilities.moveByProjection(nodeLocation, getCameraModelViewProjectionMatrix(camera), getViewport(), movement, newposition);
    return newposition;
}
 
源代码20 项目: openjdk-8-source   文件: Raster.java
/**
 * Create a compatible WritableRaster with the specified size, a new
 * SampleModel, and a new initialized DataBuffer.
 * @param w the specified width of the new <code>WritableRaster</code>
 * @param h the specified height of the new <code>WritableRaster</code>
 * @return a compatible <code>WritableRaster</code> with the specified
 *         size and a new sample model and data buffer.
 * @exception RasterFormatException if the width or height is less than
 *                               or equal to zero.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative " +
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new SunWritableRaster(sm, new Point(0,0));
}
 
源代码21 项目: buffer_bci   文件: ChartComposite.java
/**
 * Restores the auto-range calculation on the range axis.
 */
public void restoreAutoRangeBounds() {
    Plot p = this.chart.getPlot();
    if (p instanceof ValueAxisPlot) {
        Zoomable z = (Zoomable) p;
        // we need to guard against this.zoomPoint being null
        org.eclipse.swt.graphics.Point zp =
                (this.zoomPoint != null ? this.zoomPoint
                : new org.eclipse.swt.graphics.Point(0, 0));
        z.zoomRangeAxes(0.0, this.info.getPlotInfo(),
                SWTUtils.toAwtPoint(zp));
    }
}
 
源代码22 项目: netbeans   文件: CheckListener.java
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
源代码23 项目: openjdk-8-source   文件: MouseEvent.java
/**
 * Returns the x,y position of the event relative to the source component.
 *
 * @return a <code>Point</code> object containing the x and y coordinates
 *         relative to the source component
 *
 */
public Point getPoint() {
    int x;
    int y;
    synchronized (this) {
        x = this.x;
        y = this.y;
    }
    return new Point(x, y);
}
 
源代码24 项目: netbeans   文件: TabbedImpl.java
@Override
protected Shape getDropIndication( TopComponent draggedTC, Point location ) {
    location = SwingUtilities.convertPoint( getComponent(), location, getTabDisplayer() );
    Path2D res = new Path2D.Double();
    Rectangle tabRect = getTabDisplayer().dropIndication( draggedTC, location );
    if( null != tabRect ) {
        tabRect = SwingUtilities.convertRectangle( getTabDisplayer(), tabRect, container );
        res.append( tabRect, false );
    }
    res.append( container.getContentArea(), false );
    return res;
}
 
源代码25 项目: jdk8u-jdk   文件: ThemeReader.java
public static Point getPoint(String widget, int part, int state, int property) {
    readLock.lock();
    try {
        return getPoint(getTheme(widget), part, state, property);
    } finally {
        readLock.unlock();
    }
}
 
源代码26 项目: openjdk-jdk9   文件: bug8136998.java
public void runTest() throws Exception {
    try {
        SwingUtilities.invokeAndWait(this::setupUI);

        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() ->
            scrollPane.getViewport().scrollRectToVisible(comboBox.getBounds())
        );
        robot.waitForIdle();

        // Move mouse pointer to the center of the combo box
        Point p = comboBox.getLocationOnScreen();
        Dimension d = comboBox.getSize();
        robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);

        // The currently visible rectangle in scrollPane
        Rectangle viewRect0 = Util.invokeOnEDT(scrollPane.getViewport()::getViewRect);

        // Scroll the scrollPane with mouse wheel
        robot.mouseWheel(1);
        robot.waitForIdle();

        // The updated rectangle
        Rectangle viewRect1 = Util.invokeOnEDT(scrollPane.getViewport()::getViewRect);

        if (viewRect0.y == viewRect1.y) {
            throw new RuntimeException("Mouse wheel should have scrolled the JScrollPane");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }

    System.out.println("Test passed");
}
 
源代码27 项目: audiveris   文件: HeadSpotsBuilder.java
/**
 * Retrieve the glyphs out of buffer runs.
 *
 * @return the map of spot glyphs per system
 */
public Map<SystemInfo, List<Glyph>> getSpots ()
{
    RunTable headRuns = sheet.getPicture().getTable(Picture.TableKey.HEAD_SPOTS);
    List<Glyph> spots = GlyphFactory.buildGlyphs(
            headRuns,
            new Point(0, 0),
            GlyphGroup.HEAD_SPOT);

    // Dispose the runTable
    sheet.getPicture().removeTable(Picture.TableKey.HEAD_SPOTS);

    // Dispatch spots per system(s)
    return dispatchSheetSpots(spots);
}
 
源代码28 项目: jdk8u_jdk   文件: BasicScrollPaneUI.java
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
源代码29 项目: Bytecoder   文件: ByteComponentRaster.java
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);

    return new ByteComponentRaster(sm , new Point(0,0));

}
 
源代码30 项目: netbeans   文件: KeyboardDnd.java
Point getDropLocation( TopComponentDroppable droppable, int dropMargin ) {
    Dimension size = droppable.getDropComponent().getSize();
    Point res = new Point();
    switch( side ) {
        case center:
            res.x = size.width/2;
            res.y = size.height/2;
            break;
        case top:
            res.x = size.width/2;
            res.y = dropMargin;
            break;
        case bottom:
            res.x = size.width/2;
            res.y = size.height-dropMargin;
            break;
        case left:
            res.x = dropMargin;
            res.y = size.height/2;
            break;
        case right:
            res.x = size.width-dropMargin;
            res.y = size.height/2;
            break;
    }
    return res;
}
 
 类所在包
 同包方法