java.awt.Point Java Examples

The following examples show how to use java.awt.Point. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphPanel.java    From chipster with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: BackgroundIsNotUpdated.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: MapleMap.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #4
Source File: RangeSlider.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example #5
Source File: MetalToolBarUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
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);
    }
}
 
Example #6
Source File: ChartPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: UnitsDrawer.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: WindowUtils.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
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);
}
 
Example #9
Source File: MapMarkerImg.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: Mask.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: X11GraphicsEnvironment.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #12
Source File: BarFilamentFactory.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #13
Source File: ByteBandedRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a Writable subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffers as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width of the subraster.
 * @param height          Height of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {

    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.width + this.minX)) {
        throw new RasterFormatException("(x + width) is outside raster") ;
    }
    if ((y+height < y) || (y+height > this.height + this.minY)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ByteBandedRaster(sm,
                                dataBuffer,
                                new Rectangle(x0,y0,width,height),
                                new Point(sampleModelTranslateX+deltaX,
                                          sampleModelTranslateY+deltaY),
                                this);
}
 
Example #14
Source File: ProgressMonitor.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a point in local coordinates, return the zero-based index
 * of the character under that Point.  If the point is invalid,
 * this method returns -1.
 *
 * @param p the Point in local coordinates
 * @return the zero-based index of the character under Point p; if
 * Point is invalid return -1.
 */
public int getIndexAtPoint(Point p) {
    AccessibleText at = getNoteLabelAccessibleText();
    if (at != null && sameWindowAncestor(pane, noteLabel)) {
        // convert point from the option pane bounds
        // to the note label bounds.
        Point noteLabelPoint = SwingUtilities.convertPoint(pane,
                                                           p,
                                                           noteLabel);
        if (noteLabelPoint != null) {
            return at.getIndexAtPoint(noteLabelPoint);
        }
    }
    return -1;
}
 
Example #15
Source File: JInternalFrameDraggingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Point getInternalFrameLocation() throws Exception {
    final Point[] points = new Point[1];
    SwingUtilities.invokeAndWait(() -> {
        points[0] = internalFrame.getLocationOnScreen();
    });
    return points[0];
}
 
Example #16
Source File: ChartComposite.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Zooms in on a selected region.
 *
 * @param selection  the selected region.
 */
public void zoom(Rectangle selection) {

    // 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(selection.x, selection.y));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle scaledDataArea = getScreenDataArea(
            (selection.x + selection.width / 2),
            (selection.y + selection.height / 2));
    if ((selection.height > 0) && (selection.width > 0)) {

        double hLower = (selection.x - scaledDataArea.x)
            / (double) scaledDataArea.width;
        double hUpper = (selection.x + selection.width - scaledDataArea.x)
            / (double) scaledDataArea.width;
        double vLower = (scaledDataArea.y + scaledDataArea.height
                - selection.y - selection.height)
                / (double) scaledDataArea.height;
        double vUpper = (scaledDataArea.y + scaledDataArea.height
                - selection.y) / (double) scaledDataArea.height;
        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            Zoomable z = (Zoomable) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
            }
            else {
                z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
            }
        }

    }

}
 
Example #17
Source File: ThemeReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example #18
Source File: ReportShowDialog.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #19
Source File: UIUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: AttributionSupport.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #21
Source File: ByteComponentRaster.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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));

}
 
Example #22
Source File: BasicScrollPaneUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example #23
Source File: HeadSpotsBuilder.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #24
Source File: InteractiveGLVisualProcessor.java    From constellation with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #25
Source File: Raster.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #26
Source File: ChartComposite.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example #27
Source File: bug8136998.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example #28
Source File: CheckListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #29
Source File: MouseEvent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #30
Source File: TabbedImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
}