Java Code Examples for java.awt.Point#translate()

The following examples show how to use java.awt.Point#translate() . 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: UtilityGeometry.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
public static void setAlignmentCentered(Component component, Component referredComponent) {
	if(referredComponent == null) {
		referredComponent = SwingUtilities.getRoot(component);
	}
	Point rootLocation = referredComponent.getLocation();
	Dimension rootDimension = referredComponent.getSize();
	Dimension componentDimension = component.getSize();
	
	Point componentLocation = new Point(rootLocation);
	int dx = (rootDimension.width - componentDimension.width) / 2;
	int dy = (rootDimension.height - componentDimension.height) / 2;
	componentLocation.translate(dx, dy);
	
	component.setLocation(componentLocation);
	
}
 
Example 2
Source File: PopupMenuLocation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] sds = ge.getScreenDevices();
    for (GraphicsDevice sd : sds) {
        GraphicsConfiguration gc = sd.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        Point point = new Point(bounds.x, bounds.y);
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        while (point.y < bounds.y + bounds.height - insets.bottom - SIZE) {
            while (point.x
                    < bounds.x + bounds.width - insets.right - SIZE) {
                test(point);
                point.translate(bounds.width / 5, 0);
            }
            point.setLocation(bounds.x, point.y + bounds.height / 5);
        }
    }
}
 
Example 3
Source File: ClusterNode.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setPosition(Point pos) {

        this.position = pos;
        for (Vertex n : subNodes) {
            Point cur = new Point(n.getPosition());
            cur.translate(pos.x + BORDER, pos.y + BORDER);
            n.setPosition(cur);
        }

        for (Link e : subEdges) {
            List<Point> arr = e.getControlPoints();
            ArrayList<Point> newArr = new ArrayList<Point>(arr.size());
            for (Point p : arr) {
                if (p != null) {
                    Point p2 = new Point(p);
                    p2.translate(pos.x + BORDER, pos.y + BORDER);
                    newArr.add(p2);
                } else {
                    newArr.add(null);
                }
            }

            e.setControlPoints(newArr);
        }
    }
 
Example 4
Source File: DefaultIteratorTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies {@link PixelIterator#createWindow(TransferType)}.
 * This method assumes that the iterator traverses the full image (no sub-area).
 *
 * @see #verifyIteration(boolean)
 * @see #verifyIterationAfterMove(int, int)
 */
private void verifyWindow(final Dimension window) {
    final PixelIterator.Window<FloatBuffer> w = iterator.createWindow(TransferType.FLOAT);
    final FloatBuffer values = w.values;
    final float[] windowValues = new float[window.width * window.height * numBands];
    while (iterator.next()) {
        final Point pos = iterator.getPosition();
        pos.translate(-xmin, -ymin);
        w.update();
        getExpectedWindowValues(new Rectangle(pos, window), windowValues);
        int indexOfExpected = 0;
        for (int y=0; y<window.height; y++) {
            for (int x=0; x<window.width; x++) {
                for (int b=0; b<numBands; b++) {
                    final float a = values.get();
                    final float e = windowValues[indexOfExpected++];
                    if (Float.floatToRawIntBits(a) != Float.floatToRawIntBits(e)) {
                        fail("Index (" + x + ", " + y + ") in window starting at index ("
                                + pos.x + ", " + pos.y + "), band " + b + ": expected " + e + " but got " + a);
                    }
                }
            }
        }
        assertEquals("buffer.remaining()", 0, values.remaining());
    }
}
 
Example 5
Source File: ClusterNode.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void setPosition(Point pos) {

        this.position = pos;
        for (Vertex n : subNodes) {
            Point cur = new Point(n.getPosition());
            cur.translate(pos.x + BORDER, pos.y + BORDER);
            n.setPosition(cur);
        }

        for (Link e : subEdges) {
            List<Point> arr = e.getControlPoints();
            ArrayList<Point> newArr = new ArrayList<Point>();
            for (Point p : arr) {
                if (p != null) {
                    Point p2 = new Point(p);
                    p2.translate(pos.x + BORDER, pos.y + BORDER);
                    newArr.add(p2);
                } else {
                    newArr.add(null);
                }
            }

            e.setControlPoints(newArr);
        }
    }
 
Example 6
Source File: PortInfoBubble.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Point getObjectLocation() {
	if (!viewport.isShowing()) {
		return new Point(0, 0);
	}
	// get all necessary parameters
	if (!getDockable().getComponent().isShowing()) {
		return new Point(0, 0);
	}

	Point portLoc = ProcessDrawUtils.createPortLocation(port, renderer.getModel());
	if (portLoc == null) {
		return new Point(0, 0);
	}
	portLoc.x = (int) (portLoc.x * renderer.getModel().getZoomFactor());
	portLoc.y = (int) (portLoc.y * renderer.getModel().getZoomFactor());
	portLoc = ProcessDrawUtils.convertToAbsoluteProcessPoint(portLoc,
			renderer.getModel().getProcessIndex(port.getPorts().getOwner().getConnectionContext()), renderer.getModel());
	if (portLoc == null) {
		return new Point(0, 0);
	}
	portLoc.translate(-getObjectWidth() / 2, -getObjectHeight() / 2);

	// calculate actual on screen loc of the port loc and return it
	Point rendererLoc = renderer.getVisibleRect().getLocation();
	Point absoluteLoc = new Point((int) (viewport.getLocationOnScreen().x + (portLoc.getX() - rendererLoc.getX())),
			(int) (viewport.getLocationOnScreen().y + (portLoc.getY() - rendererLoc.getY())));

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

}
 
Example 7
Source File: HyperlinkCellRenderer.java    From littleluck with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfPointInsideHyperlink(Point p) {
    hitColumnIndex = table.columnAtPoint(p);
    hitRowIndex = table.rowAtPoint(p);

    if (hitColumnIndex != -1 && hitRowIndex != -1 &&
            columnModelIndeces.contains(table.getColumnModel().
                    getColumn(hitColumnIndex).getModelIndex())) {
        // We know point is within a hyperlink column, however we do further hit testing
        // to see if point is within the text bounds on the hyperlink
        TableCellRenderer renderer = table.getCellRenderer(hitRowIndex, hitColumnIndex);
        JHyperlink hyperlink = (JHyperlink) table.prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

        // Convert the event to the renderer's coordinate system
        cellRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
        hyperlink.setSize(cellRect.width, cellRect.height);
        p.translate(-cellRect.x, -cellRect.y);
        cellRect.x = cellRect.y = 0;
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        SwingUtilities.layoutCompoundLabel(
                hyperlink.getFontMetrics(hyperlink.getFont()),
                hyperlink.getText(), hyperlink.getIcon(),
                hyperlink.getVerticalAlignment(),
                hyperlink.getHorizontalAlignment(),
                hyperlink.getVerticalTextPosition(),
                hyperlink.getHorizontalTextPosition(),
                cellRect, iconRect, textRect, hyperlink.getIconTextGap());

        if (textRect.contains(p)) {
            // point is within hyperlink text bounds
            return true;
        }
    }
    // point is not within a hyperlink's text bounds
    hitRowIndex = -1;
    hitColumnIndex = -1;
    return false;
}
 
Example 8
Source File: ProfilerTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void updateColumnPreferredWidth(int column) {
    Rectangle visible = getVisibleRect();
    if (visible.isEmpty()) return;
    
    Point visibleP = visible.getLocation();
    int first = rowAtPoint(visible.getLocation());
    visibleP.translate(0, visible.height - 1);
    int last = rowAtPoint(visibleP);
    
    int _column = convertColumnIndexToView(column);
    
    int width = computeColumnPreferredWidth(column, _column, first, last);
    _getColumnModel().setColumnPreferredWidth(column, width);
}
 
Example 9
Source File: MutterMaximizeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void dragWindow(Window w, int dx, int dy, Robot robot) {
    Point p = Util.getTitlePoint(w);
    rmove(robot, p);
    rdown(robot);
    p.translate(dx, dy);
    rmove(robot, p);
    rup(robot);
}
 
Example 10
Source File: CefClient.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Point getScreenPoint(CefBrowser browser, Point viewPoint) {
   if (browser == null)
		return new Point(0, 0);

	CefRenderHandler realHandler = browser.getRenderHandler();
	if (realHandler != null)
		return realHandler.getScreenPoint(browser, viewPoint);
	Point screenPoint = browser.getUIComponent().getLocationOnScreen();
	screenPoint.translate(viewPoint.x, viewPoint.y);
	return screenPoint;
}
 
Example 11
Source File: ControlFlowScene.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setNewLocation(Widget widget, Point location) {
    Point originalLocation = getOriginalLocation(widget);
    int xOffset = location.x - originalLocation.x;
    int yOffset = location.y - originalLocation.y;
    for (Widget w : this.selection) {
        Point p = new Point(w.getPreferredLocation());
        p.translate(xOffset, yOffset);
        w.setPreferredLocation(p);
    }

}
 
Example 12
Source File: MultiScreenLocationTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 13
Source File: FindTerritoryDialog.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private Point getInitialLocation() {
  final Point point = mapPanel.getLocation();
  SwingUtilities.convertPointToScreen(point, mapPanel);
  point.translate(20, 20);
  return point;
}
 
Example 14
Source File: SlotWidget.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Point getAnchorPosition() {
    Point p = new Point(figureWidget.getFigure().getPosition());
    Point p2 = slot.getRelativePosition();
    p.translate(p2.x, p2.y);
    return p;
}
 
Example 15
Source File: DiagramConnectionWidget.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void updateControlPoints() {
    List<Point> newControlPoints = connection.getControlPoints();
    Connection c = connection;
    Figure f = c.getInputSlot().getFigure();
    Point p = new Point(f.getPosition());
    p.translate(c.getInputSlot().getRelativePosition().x, f.getSize().height / 2);
    Point p4 = new Point(f.getPosition());
    p4.translate(c.getInputSlot().getRelativePosition().x, c.getInputSlot().getRelativePosition().y);

    Figure f2 = c.getOutputSlot().getFigure();
    Point p2 = new Point(f2.getPosition());
    p2.translate(c.getOutputSlot().getRelativePosition().x, f2.getSize().height / 2);
    Point p3 = new Point(f2.getPosition());
    p3.translate(c.getOutputSlot().getRelativePosition().x, c.getOutputSlot().getRelativePosition().y);

    /*if(controlPoints.size() >= 2) {
    String className = Preferences.userNodeForPackage(PreferenceConstants.class).get(PreferenceConstants.KEY_LINE_GENERATOR, PreferenceConstants.DEFAULT_LINE_GENERATOR);
    try {
    LineGenerator lg = (LineGenerator)Class.forName(className).newInstance();
    controlPoints = lg.createLine(controlPoints, p2, p);
    } catch (InstantiationException ex) {
    } catch (IllegalAccessException ex) {
    } catch (ClassNotFoundException ex) {
    }
    }*/

    this.controlPoints = newControlPoints;
    pointCount = newControlPoints.size();
    xPoints = new int[pointCount];
    yPoints = new int[pointCount];
    int minX = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxY = Integer.MIN_VALUE;
    split = false;
    for (int i = 0; i < pointCount; i++) {
        if (newControlPoints.get(i) == null) {
            split = true;
        } else {
            int curX = newControlPoints.get(i).x;
            int curY = newControlPoints.get(i).y;
            this.xPoints[i] = curX;
            this.yPoints[i] = curY;
            minX = Math.min(minX, curX);
            maxX = Math.max(maxX, curX);
            minY = Math.min(minY, curY);
            maxY = Math.max(maxY, curY);
        }
    }

    this.clientArea = new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
 
Example 16
Source File: DNDTextToScaledArea.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static Point getPoint(Component component, double scale) {
    Point point = component.getLocationOnScreen();
    Dimension bounds = component.getSize();
    point.translate((int) (bounds.width * scale), (int) (bounds.height * scale));
    return point;
}
 
Example 17
Source File: MergedPanel.java    From Briss-2.0 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent mE) {
    Point curPoint = mE.getPoint();

    switch (actionState) {
        case DRAWING_NEW_CROP:
            if (cropStartPoint == null) {
                cropStartPoint = curPoint;
            }
            curCrop.x = (curPoint.x < cropStartPoint.x) ? curPoint.x : cropStartPoint.x;
            curCrop.width = Math.abs(curPoint.x - cropStartPoint.x);
            curCrop.y = (curPoint.y < cropStartPoint.y) ? curPoint.y : cropStartPoint.y;
            curCrop.height = Math.abs(curPoint.y - cropStartPoint.y);
            break;
        case MOVE_CROP:
            if (lastDragPoint == null) {
                lastDragPoint = curPoint;
            }
            if (mE.isShiftDown()) {
                briss.moveSelectedRects(curPoint.x - lastDragPoint.x, curPoint.y - lastDragPoint.y);
            } else {
                curCrop.translate(curPoint.x - lastDragPoint.x, curPoint.y - lastDragPoint.y);
            }
            lastDragPoint = curPoint;
            break;
        case RESIZING_HOTCORNER_LR:
            if (lastDragPoint == null) {
                lastDragPoint = curPoint;
            }
            if (mE.isShiftDown()) {
                briss.resizeSelRects(curPoint.x - lastDragPoint.x, curPoint.y - lastDragPoint.y);
            } else {
                curPoint.translate(relativeHotCornerGrabDistance.x, relativeHotCornerGrabDistance.y);
                curCrop.setNewHotCornerLR(curPoint);
            }
            lastDragPoint = curPoint;
            break;
        case RESIZING_HOTCORNER_UL:
            if (lastDragPoint == null) {
                lastDragPoint = curPoint;
            }
            if (mE.isShiftDown()) {
                briss.resizeSelRects(lastDragPoint.x - curPoint.x, lastDragPoint.y - curPoint.y);
                briss.moveSelectedRects(curPoint.x - lastDragPoint.x, curPoint.y - lastDragPoint.y);
            } else {
                curPoint.translate(relativeHotCornerGrabDistance.x, relativeHotCornerGrabDistance.y);
                curCrop.setNewHotCornerUL(curPoint);
            }
            lastDragPoint = curPoint;
            break;
    }
    repaint();
}
 
Example 18
Source File: DiagramConnectionWidget.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void updateControlPoints() {
    List<Point> newControlPoints = connection.getControlPoints();
    Connection c = connection;
    Figure f = c.getInputSlot().getFigure();
    Point p = new Point(f.getPosition());
    p.translate(c.getInputSlot().getRelativePosition().x, f.getSize().height / 2);
    Point p4 = new Point(f.getPosition());
    p4.translate(c.getInputSlot().getRelativePosition().x, c.getInputSlot().getRelativePosition().y);

    Figure f2 = c.getOutputSlot().getFigure();
    Point p2 = new Point(f2.getPosition());
    p2.translate(c.getOutputSlot().getRelativePosition().x, f2.getSize().height / 2);
    Point p3 = new Point(f2.getPosition());
    p3.translate(c.getOutputSlot().getRelativePosition().x, c.getOutputSlot().getRelativePosition().y);

    /*if(controlPoints.size() >= 2) {
    String className = Preferences.userNodeForPackage(PreferenceConstants.class).get(PreferenceConstants.KEY_LINE_GENERATOR, PreferenceConstants.DEFAULT_LINE_GENERATOR);
    try {
    LineGenerator lg = (LineGenerator)Class.forName(className).newInstance();
    controlPoints = lg.createLine(controlPoints, p2, p);
    } catch (InstantiationException ex) {
    } catch (IllegalAccessException ex) {
    } catch (ClassNotFoundException ex) {
    }
    }*/

    this.controlPoints = newControlPoints;
    pointCount = newControlPoints.size();
    xPoints = new int[pointCount];
    yPoints = new int[pointCount];
    int minX = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxY = Integer.MIN_VALUE;
    split = false;
    for (int i = 0; i < pointCount; i++) {
        if (newControlPoints.get(i) == null) {
            split = true;
        } else {
            int curX = newControlPoints.get(i).x;
            int curY = newControlPoints.get(i).y;
            this.xPoints[i] = curX;
            this.yPoints[i] = curY;
            minX = Math.min(minX, curX);
            maxX = Math.max(maxX, curX);
            minY = Math.min(minY, curY);
            maxY = Math.max(maxY, curY);
        }
    }

    this.clientArea = new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
 
Example 19
Source File: Guide.java    From SikuliX1 with MIT License 4 votes vote down vote up
Point convertToRegionLocation(Point point_in_global_coordinate) {
  Point ret = new Point(point_in_global_coordinate);
  ret.translate(-_region.x, -_region.y);
  return ret;
}
 
Example 20
Source File: Outline.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String getToolTipText(MouseEvent event) {
    try {
        // Required to really get the tooltip text:
        putClientProperty("ComputingTooltip", Boolean.TRUE);

        toolTip = null;
        String tipText = null;
        Point p = event.getPoint();

        // Locate the renderer under the event location
        int hitColumnIndex = columnAtPoint(p);
        int hitRowIndex = rowAtPoint(p);

        if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
            //Outline tbl = (Outline) table;
            if (convertColumnIndexToModel(hitColumnIndex) == 0) {   // tree column index
                // For tree column get the tooltip directly from the renderer data provider
                RenderDataProvider rendata = getRenderDataProvider();
                if (rendata != null) {
                    Object value = getValueAt(hitRowIndex, hitColumnIndex);
                    if (value != null) {
                        String toolT = rendata.getTooltipText(value);
                        if (toolT != null && (toolT = toolT.trim ()).length () > 0) {
                            tipText = toolT;
                        }
                    }
                }
            }

            TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
            Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

            // Now have to see if the component is a JComponent before
            // getting the tip
            if (component instanceof JComponent) {
                // Convert the event to the renderer's coordinate system
                Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
                p.translate(-cellRect.x, -cellRect.y);
                MouseEvent newEvent = new MouseEvent(component, event.getID(),
                                          event.getWhen(), event.getModifiers(),
                                          p.x, p.y,
                                          event.getXOnScreen(),
                                          event.getYOnScreen(),
                                          event.getClickCount(),
                                          event.isPopupTrigger(),
                                          MouseEvent.NOBUTTON);

                if (tipText == null) {
                    tipText = ((JComponent)component).getToolTipText(newEvent);
                }
                toolTip = ((JComponent)component).createToolTip();
            }
        }

        // No tip from the renderer get our own tip
        if (tipText == null)
            tipText = getToolTipText();

        if (tipText != null) {
            tipText = tipText.trim();
            if (tipText.length() > MAX_TOOLTIP_LENGTH &&
                !tipText.regionMatches(false, 0, "<html>", 0, 6)) {   // Do not cut HTML tooltips

                tipText = tipText.substring(0, MAX_TOOLTIP_LENGTH) + "...";
            }
        }
        return tipText;
    } finally {
        putClientProperty("ComputingTooltip", Boolean.FALSE);
    }
    //return super.getToolTipText(event);
}