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

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

源代码1 项目: openjdk-jdk9   文件: PopupMenuLocation.java
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);
        }
    }
}
 
源代码2 项目: openjdk-jdk9   文件: ClusterNode.java
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);
        }
    }
 
源代码3 项目: sis   文件: DefaultIteratorTest.java
/**
 * 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());
    }
}
 
源代码4 项目: openjdk-8   文件: ClusterNode.java
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);
        }
    }
 
源代码5 项目: Ardulink-2   文件: UtilityGeometry.java
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);
	
}
 
源代码6 项目: rapidminer-studio   文件: PortInfoBubble.java
@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);

}
 
源代码7 项目: littleluck   文件: HyperlinkCellRenderer.java
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;
}
 
源代码8 项目: netbeans   文件: ProfilerTable.java
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);
}
 
源代码9 项目: openjdk-jdk9   文件: MutterMaximizeTest.java
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);
}
 
源代码10 项目: APICloud-Studio   文件: CefClient.java
@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;
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: ControlFlowScene.java
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);
    }

}
 
源代码12 项目: netbeans   文件: Outline.java
@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);
}
 
源代码13 项目: SikuliX1   文件: Guide.java
Point convertToRegionLocation(Point point_in_global_coordinate) {
  Point ret = new Point(point_in_global_coordinate);
  ret.translate(-_region.x, -_region.y);
  return ret;
}
 
源代码14 项目: hottub   文件: DiagramConnectionWidget.java
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);
}
 
源代码15 项目: Briss-2.0   文件: MergedPanel.java
@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();
}
 
源代码16 项目: openjdk-jdk9   文件: DNDTextToScaledArea.java
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;
}
 
源代码17 项目: openjdk-jdk8u   文件: DiagramConnectionWidget.java
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);
}
 
源代码18 项目: jdk8u60   文件: SlotWidget.java
public Point getAnchorPosition() {
    Point p = new Point(figureWidget.getFigure().getPosition());
    Point p2 = slot.getRelativePosition();
    p.translate(p2.x, p2.y);
    return p;
}
 
源代码19 项目: triplea   文件: FindTerritoryDialog.java
private Point getInitialLocation() {
  final Point point = mapPanel.getLocation();
  SwingUtilities.convertPointToScreen(point, mapPanel);
  point.translate(20, 20);
  return point;
}
 
源代码20 项目: jdk8u-dev-jdk   文件: MultiScreenLocationTest.java
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!");
}