/** * 修正矩形框位置,如果{@link Img#setPositionFromCentre(boolean)} 设为{@code true},则坐标修正为基于图形中心,否则基于左上角 * * @param rectangle 矩形 * @param baseWidth 参考宽 * @param baseHeight 参考高 * @return 修正后的{@link Rectangle} * @since 4.1.15 */ private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) { if (this.positionBaseCentre) { // 修正图片位置从背景的中心计算 rectangle.setLocation(// rectangle.x + (int) (Math.abs(baseWidth - rectangle.width) / 2), // rectangle.y + (int) (Math.abs(baseHeight - rectangle.height) / 2)// ); } return rectangle; }
/** * 修正矩形框位置,如果{@link Img#setPositionFromCentre(boolean)} 设为{@code true},则坐标修正为基于图形中心,否则基于左上角 * * @param rectangle 矩形 * @param baseWidth 参考宽 * @param baseHeight 参考高 * @return 修正后的{@link Rectangle} * @since 4.1.15 */ private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) { if (this.positionBaseCentre) { // 修正图片位置从背景的中心计算 rectangle.setLocation(// rectangle.x + (int) (Math.abs(baseWidth - rectangle.width) / 2), // rectangle.y + (int) (Math.abs(baseHeight - rectangle.height) / 2)// ); } return rectangle; }
outsideStroke.setLocation(rectangle.x, rectangle.y); outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET / 2); graphics.setColor(outsideStrokeColor); insideStroke.setLocation(rectangle.x + BORDER_OFFSET / 2, rectangle.y + BORDER_OFFSET / 2); insideStroke.setSize(rectangle.width - BORDER_OFFSET - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET - BORDER_OFFSET / 2);
@Override public Rectangle getBounds() { final Rectangle bounds = super.getBounds(); final Rectangle parent = getParentBounds(client.getWidget(widgetInfo)); if (parent.isEmpty()) { return bounds; } int x = bounds.x; int y = bounds.y; x = Math.max(parent.x, x); y = Math.max(parent.y, y); x = Math.min((int)parent.getMaxX() - bounds.width, x); y = Math.min((int)parent.getMaxY() - bounds.height, y); bounds.setLocation(x, y); return bounds; }
private void positionPanel() { if (parent == null) return; Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, parent); int height = (int)getPreferredSize().getHeight(); if (scroll != null) { Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), oldGlass); bounds.setLocation(pos); setBounds(bounds); repaint(); } }
@Override public Dimension render(Graphics2D graphics) { final Widget widget = client.getWidget(widgetInfo); final Rectangle bounds = super.getBounds(); final Rectangle parent = getParentBounds(widget); if (parent.isEmpty()) { return null; } int x = bounds.x; int y = bounds.y; x = Math.max(parent.x, x); y = Math.max(parent.y, y); x = Math.min((int)parent.getMaxX() - bounds.width, x); y = Math.min((int)parent.getMaxY() - bounds.height, y); bounds.setLocation(x, y); widget.setOriginalX(0); widget.setOriginalY(0); widget.setRelativeX(bounds.x - parent.x); widget.setRelativeY(bounds.y - parent.y); return new Dimension(widget.getWidth(), widget.getHeight()); }
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return; } JViewport viewport = (JViewport)table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x-pt.x, rect.y-pt.y); table.scrollRectToVisible(rect); // Scroll the area into view //viewport.scrollRectToVisible(rect); }
final Insets windowInsets = window.getInsets(); pos.translate(windowInsets.left, windowInsets.top); bounds.setLocation(pos); setBounds(bounds);
final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET); final Rectangle bounds = new Rectangle(getBounds()); bounds.setLocation(mousePosition);
private void positionPanel() { final JComponent contentComponent = myEditor.getContentComponent(); Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent); setSize(scroll.getSize()); myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight(); int count = countLines(myText.getText()); int visLines = getSize().height / myLineHeight - 1; int lines = Math.min(count, visLines); setSize(getSize().width, lines * myLineHeight + myLabel.getPreferredSize().height + getBorder().getBorderInsets(this).top * 2); int height = getSize().height; Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), SwingUtilities.getRootPane(contentComponent).getGlassPane()); bounds.setLocation(pos); setBounds(bounds); myScrollPane.getVerticalScrollBar().setValue(0); if (!Options.getInstance().isSet("more")) { // FIX scrollOffset(100000); } else { scrollOffset(0); } }
final Rectangle canvasBounds = client.getCanvas().getBounds(); canvasBounds.setLocation(0, 0); final Area canvasViewArea = getWorldMapClipArea(canvasBounds); Area currentClip = null;
bounds.setLocation(MARGIN, TAB_HEIGHT + MARGIN);
/** * Reads the rectangle location and size from an 8-byte rectangle stream. * * @param pStream the stream to read from * @param pDestRect the rectangle to read into * * @throws NullPointerException if {@code pDestRect} is {@code null} * @throws IOException if an I/O error occurs while reading the image. */ private void readRectangle(DataInput pStream, Rectangle pDestRect) throws IOException { int y = pStream.readUnsignedShort(); int x = pStream.readUnsignedShort(); int h = pStream.readUnsignedShort(); int w = pStream.readUnsignedShort(); pDestRect.setLocation(getXPtCoord(x), getYPtCoord(y)); pDestRect.setSize(getXPtCoord(w - x), getYPtCoord(h - y)); }
public void setActualLocation(int x, int y) { int paintX = x; int paintY = y; actualBounds.setLocation(x, y); if (hasShadow()) { paintX -= (shadowSize - shadowOffset); paintY -= (shadowSize - shadowOffset); } super.setLocation(paintX, paintY); updateAllFollowers(); }
public int showTokens() { jLayeredPane.removeAll(); List<Token> tokens = getTokens(currentPage, currentSet); if (tokens != null && tokens.size() > 0) { int size = tokens.size(); Rectangle rectangle = new Rectangle(); rectangle.translate(OFFSET_X, OFFSET_Y); for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) { Token token = tokens.get(i); addToken(token, bigCard, null, rectangle); rectangle = CardPosition.translatePosition(i, rectangle, conf); } // calculate the x offset of the second (right) page int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH) - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X; rectangle.setLocation(second_page_x, OFFSET_Y); for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) { Token token = tokens.get(i); addToken(token, bigCard, null, rectangle); rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf); } jLayeredPane.repaint(); return tokens.size(); } return 0; }
public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else { r.setLocation(parent.getLocation()); r.setSize(parent.getSize()); } // Determine the new location of the alert int x = r.x + (r.width - w.getWidth()) / 2; int y = r.y + (r.height - w.getHeight()) / 2; // Move the alert w.setLocation(x, y); }
/** * Compute the bounds in which the user can move the mouse without the * tip window disappearing. */ private void computeTipVisibleBounds() { // Compute area that the mouse can move in without hiding the // tip window. Note that Java 1.4 can only detect mouse events // in Java windows, not globally. Rectangle r = tipWindow.getBounds(); Point p = r.getLocation(); SwingUtilities.convertPointFromScreen(p, textArea); r.setLocation(p); tipVisibleBounds.setBounds(r.x,r.y-15, r.width,r.height+15*2); }
public void showCards() { jLayeredPane.removeAll(); // stats info updateCardStats(currentSet, true); List<CardInfo> cards = getCards(currentPage, currentSet); int size = cards.size(); Rectangle rectangle = new Rectangle(); rectangle.translate(OFFSET_X, OFFSET_Y); for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) { Card card = cards.get(i).getMockCard(); addCard(new CardView(card), bigCard, null, rectangle); rectangle = CardPosition.translatePosition(i, rectangle, conf); } // calculate the x offset of the second (right) page int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH) - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X; rectangle.setLocation(second_page_x, OFFSET_Y); for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) { Card card = cards.get(i).getMockCard(); addCard(new CardView(card), bigCard, null, rectangle); rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf); } jLayeredPane.repaint(); }
rectangleBaseCard.setLocation(point);
sourceRegion.setLocation( (int) Math.round((IMAGE_DIMENSION_PNG.width - sourceRegion.getWidth()) / 2.0), (int) Math.round((IMAGE_DIMENSION_PNG.height - sourceRegion.getHeight()) / 2.0)