Java Code Examples for java.awt.Rectangle#setBounds()
The following examples show how to use
java.awt.Rectangle#setBounds() .
These examples are extracted from open source projects.
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 Project: TrakEM2 File: AreaList.java License: GNU General Public License v3.0 | 6 votes |
/** Returns the bounds of this object as it shows in the given layer. */ @Override public Rectangle getBounds(final Rectangle r, final Layer layer) { if (null == layer) return super.getBounds(r, null); final Area area = (Area)ht_areas.get(layer.getId()); if (null == area) { if (null == r) return new Rectangle(); r.x = 0; r.y = 0; r.width = 0; r.height = 0; return r; } final Rectangle b = area.createTransformedArea(this.at).getBounds(); if (null == r) return b; r.setBounds(b.x, b.y, b.width, b.height); return r; }
Example 2
Source Project: openjdk-jdk9 File: SunGraphics2D.java License: GNU General Public License v2.0 | 6 votes |
public Rectangle getClipBounds(Rectangle r) { if (clipState != CLIP_DEVICE) { if (transformState <= TRANSFORM_INT_TRANSLATE) { if (usrClip instanceof Rectangle) { r.setBounds((Rectangle) usrClip); } else { r.setFrame(usrClip.getBounds2D()); } r.translate(-transX, -transY); } else { r.setFrame(getClip().getBounds2D()); } } else if (r == null) { throw new NullPointerException("null rectangle parameter"); } return r; }
Example 3
Source Project: openjdk-jdk9 File: MetalToolBarUI.java License: GNU General Public License v2.0 | 6 votes |
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 4
Source Project: basicv2 File: BlockCaret.java License: The Unlicense | 6 votes |
public void paint(Graphics g) { if (isVisible()) { try { JTextComponent component = getComponent(); Rectangle r = component.getUI().modelToView(component, getDot()); Color c = g.getColor(); g.setColor(component.getBackground()); g.setXORMode(component.getCaretColor()); r.setBounds(r.x, r.y, g.getFontMetrics().charWidth('w'), g.getFontMetrics().getHeight()); g.fillRect(r.x, r.y, r.width, r.height); g.setPaintMode(); g.setColor(c); } catch (BadLocationException e) { e.printStackTrace(); } } }
Example 5
Source Project: openjdk-8 File: SunGraphics2D.java License: GNU General Public License v2.0 | 6 votes |
public Rectangle getClipBounds(Rectangle r) { if (clipState != CLIP_DEVICE) { if (transformState <= TRANSFORM_INT_TRANSLATE) { if (usrClip instanceof Rectangle) { r.setBounds((Rectangle) usrClip); } else { r.setFrame(usrClip.getBounds2D()); } r.translate(-transX, -transY); } else { r.setFrame(getClip().getBounds2D()); } } else if (r == null) { throw new NullPointerException("null rectangle parameter"); } return r; }
Example 6
Source Project: astor File: LegendGraphicTests.java License: GNU General Public License v2.0 | 6 votes |
/** * Confirm that cloning works. */ public void testCloning() { Rectangle r = new Rectangle(1, 2, 3, 4); LegendGraphic g1 = new LegendGraphic(r, Color.black); LegendGraphic g2 = null; try { g2 = (LegendGraphic) g1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(g1 != g2); assertTrue(g1.getClass() == g2.getClass()); assertTrue(g1.equals(g2)); // check independence r.setBounds(4, 3, 2, 1); assertFalse(g1.equals(g2)); }
Example 7
Source Project: tn5250j File: GuiGraphicBuffer.java License: GNU General Public License v2.0 | 6 votes |
/** * Fills the passed Rectangle with the starting row and column and width and * height of the selected area. * * 1 BASED so column 1 row one is returned 1,1 * * If there is no area bounded then the full screen area is returned. * * @param bounds */ public void getBoundingArea(Rectangle bounds) { // check to see if there is an area selected. If not then return all // screen area. if (!gui.rubberband.isAreaSelected()) { bounds.setBounds(1, 1, screen.getColumns(), screen.getRows()); } else { // lets get the bounding area using a rectangle that we have already // allocated gui.rubberband.getBoundingArea(workR); // get starting row and column int sPos = getRowColFromPoint(workR.x, workR.y); // get the width and height int ePos = getRowColFromPoint(workR.width, workR.height); int row = screen.getRow(sPos) + 1; int col = screen.getCol(sPos) + 1; bounds.setBounds(row, col, screen.getCol(ePos) + 1, screen.getRow(ePos) + 1); } }
Example 8
Source Project: JDKSourceCode1.8 File: MetalToolBarUI.java License: MIT License | 6 votes |
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 9
Source Project: jclic File: JDomUtility.java License: GNU General Public License v2.0 | 6 votes |
public static Rectangle getRectangle(org.jdom.Element e, String id, Rectangle defaultValue) { if (id != null) { e = getChildWithId(e, RECTANGLE, id); } else if (e != null && !e.getName().equals(RECTANGLE)) { e = e.getChild(RECTANGLE); } if (e == null) { return defaultValue; } Rectangle r = (defaultValue == null ? new Rectangle() : new Rectangle(defaultValue)); r.setBounds( getIntAttr(e, LEFT, r.x), getIntAttr(e, TOP, r.y), getIntAttr(e, WIDTH, r.width), getIntAttr(e, HEIGHT, r.height)); return r; }
Example 10
Source Project: ECG-Viewer File: XYAreaRenderer2Test.java License: GNU General Public License v2.0 | 5 votes |
/** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XYAreaRenderer2 r1 = new XYAreaRenderer2(); Rectangle rect = new Rectangle(1, 2, 3, 4); r1.setLegendArea(rect); XYAreaRenderer2 r2 = (XYAreaRenderer2) r1.clone(); assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); // check independence rect.setBounds(99, 99, 99, 99); assertFalse(r1.equals(r2)); }
Example 11
Source Project: hifive-pitalium File: ImagePair.java License: Apache License 2.0 | 5 votes |
/** * Expand the splitRectangle, if it borders on subRectangle, as much as border removed * * @param subRectangle Rectangle for checking expansion * @param splitRectangle Rectangle which is expanded * @param sub_margin how much border removed */ private void expand(Rectangle subRectangle, Rectangle splitRectangle, int sub_margin) { int subX = (int) subRectangle.getX(), subY = (int) subRectangle.getY(); int subWidth = (int) subRectangle.getWidth(), subHeight = (int) subRectangle.getHeight(); int splitX = (int) splitRectangle.getX(), splitY = (int) splitRectangle.getY(); int splitWidth = (int) splitRectangle.getWidth(), splitHeight = (int) splitRectangle.getHeight(); // Left-directional expansion if (splitX <= subX) { splitX = subX - sub_margin; splitWidth = splitWidth + sub_margin; } // Top-directional expansion if (splitY <= subY) { splitY = subY - sub_margin; splitHeight = splitHeight + sub_margin; } // Right-directional expansion if (splitX + splitWidth >= subX + subWidth) { splitWidth = subX + subWidth + sub_margin - splitX; } // Down-directional expansion if (splitY + splitHeight >= subY + subHeight) { splitHeight = subY + subHeight + sub_margin - splitY; } splitRectangle.setBounds(splitX, splitY, splitWidth, splitHeight); }
Example 12
Source Project: jclic File: ActiveMediaPlayer.java License: GNU General Public License v2.0 | 5 votes |
public void checkVisualComponentBounds(ActiveBox bxi) { if (visualComponent == null) return; Rectangle enclosingRect = new Rectangle(); if (!mc.free) enclosingRect.setBounds(bxi.getBounds()); else enclosingRect.setBounds(ps.getComponent().getBounds()); Point offset = new Point(); Dimension dim = new Dimension(visualComponent.getPreferredSize()); if (mc.absLocation != null) { offset.setLocation(mc.absLocation); if (offset.x + dim.width > enclosingRect.width) offset.x = enclosingRect.width - dim.width; if (offset.y + dim.height > enclosingRect.height) offset.y = enclosingRect.height - dim.height; } if (mc.stretch) { int extraW = enclosingRect.width - offset.x - dim.width; if (extraW < 0) { dim.width = enclosingRect.width - offset.x; extraW = 0; } int extraH = enclosingRect.height - offset.y - dim.height; if (extraH < 0) { dim.height = enclosingRect.height - offset.y; extraH = 0; } if (mc.absLocation == null) { offset.x += extraW / 2; offset.y += extraH / 2; } } Rectangle vRect = new Rectangle(enclosingRect.x + offset.x, enclosingRect.y + offset.y, dim.width, dim.height); visualComponent.setSize(dim); visualComponent.setLocation(vRect.getLocation()); visualComponent.setBounds(vRect); }
Example 13
Source Project: openjdk-8-source File: GIFImageWriter.java License: GNU General Public License v2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }
Example 14
Source Project: openjdk-jdk8u-backup File: GIFImageWriter.java License: GNU General Public License v2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }
Example 15
Source Project: netbeans File: TransformableCanvasComponent.java License: Apache License 2.0 | 4 votes |
private void shift(Graphics g, int idx, int idy, int width, int height) { Rectangle areaToRepaint = new Rectangle(); if (idx == 0) { // Vertical shift if (idy > 0) { // --- Shift down -------------------------------------- g.copyArea(0, 0, width, height - idy, 0, idy); areaToRepaint.setBounds(0, 0, width, idy); } else { // --- Shift up ---------------------------------------- g.copyArea(0, -idy, width, height + idy, 0, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); } } else if (idy == 0) { // Horizontal shift if (idx > 0) { // --- Shift right ------------------------------------- g.copyArea(0, 0, width - idx, height, idx, 0); areaToRepaint.setBounds(0, 0, idx, height); } else { // --- Shift left -------------------------------------- g.copyArea(-idx, 0, width + idx, height, idx, 0); areaToRepaint.setBounds(width + idx, 0, -idx, height); } } else { // Diagonal shift if (idx > 0) { // Shift right if (idy > 0) { // --- Shift right down ------------------------ g.copyArea(0, 0, width - idx, height - idy, idx, idy); areaToRepaint.setBounds(0, 0, width, idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(0, idy, idx, height - idy); } else { // --- Shift right up -------------------------- g.copyArea(0, -idy, width - idx, height + idy, idx, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(0, 0, idx, height + idy); } } else { // Shift left if (idy > 0) { // --- Shift left down ------------------------- g.copyArea(-idx, 0, width + idx, height - idy, idx, idy); areaToRepaint.setBounds(0, 0, width, idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(width + idx, idy, -idx, height - idy); } else { // --- Shift left up --------------------------- g.copyArea(-idx, -idy, width + idx, height + idy, idx, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(width + idx, 0, -idx, height + idy); } } } paintContents(g, areaToRepaint); }
Example 16
Source Project: visualvm File: TransformableCanvasComponent.java License: GNU General Public License v2.0 | 4 votes |
private void shift(Graphics g, int idx, int idy, int width, int height) { Rectangle areaToRepaint = new Rectangle(); if (idx == 0) { // Vertical shift if (idy > 0) { // --- Shift down -------------------------------------- g.copyArea(0, 0, width, height - idy, 0, idy); areaToRepaint.setBounds(0, 0, width, idy); } else { // --- Shift up ---------------------------------------- g.copyArea(0, -idy, width, height + idy, 0, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); } } else if (idy == 0) { // Horizontal shift if (idx > 0) { // --- Shift right ------------------------------------- g.copyArea(0, 0, width - idx, height, idx, 0); areaToRepaint.setBounds(0, 0, idx, height); } else { // --- Shift left -------------------------------------- g.copyArea(-idx, 0, width + idx, height, idx, 0); areaToRepaint.setBounds(width + idx, 0, -idx, height); } } else { // Diagonal shift if (idx > 0) { // Shift right if (idy > 0) { // --- Shift right down ------------------------ g.copyArea(0, 0, width - idx, height - idy, idx, idy); areaToRepaint.setBounds(0, 0, width, idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(0, idy, idx, height - idy); } else { // --- Shift right up -------------------------- g.copyArea(0, -idy, width - idx, height + idy, idx, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(0, 0, idx, height + idy); } } else { // Shift left if (idy > 0) { // --- Shift left down ------------------------- g.copyArea(-idx, 0, width + idx, height - idy, idx, idy); areaToRepaint.setBounds(0, 0, width, idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(width + idx, idy, -idx, height - idy); } else { // --- Shift left up --------------------------- g.copyArea(-idx, -idy, width + idx, height + idy, idx, idy); areaToRepaint.setBounds(0, height + idy, width, -idy); paintContents(g, areaToRepaint); areaToRepaint.setBounds(width + idx, 0, -idx, height + idy); } } } paintContents(g, areaToRepaint); }
Example 17
Source Project: openjdk-8 File: GIFImageWriter.java License: GNU General Public License v2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }
Example 18
Source Project: openjdk-jdk8u File: GIFImageWriter.java License: GNU General Public License v2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }
Example 19
Source Project: Bytecoder File: GIFImageWriter.java License: Apache License 2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }
Example 20
Source Project: openjdk-jdk9 File: GIFImageWriter.java License: GNU General Public License v2.0 | 4 votes |
/** * Compute the source region and destination dimensions taking any * parameter settings into account. */ private static void computeRegions(Rectangle sourceBounds, Dimension destSize, ImageWriteParam p) { ImageWriteParam param; int periodX = 1; int periodY = 1; if (p != null) { int[] sourceBands = p.getSourceBands(); if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) { throw new IllegalArgumentException("Cannot sub-band image!"); } // Get source region and subsampling factors Rectangle sourceRegion = p.getSourceRegion(); if (sourceRegion != null) { // Clip to actual image bounds sourceRegion = sourceRegion.intersection(sourceBounds); sourceBounds.setBounds(sourceRegion); } // Adjust for subsampling offsets int gridX = p.getSubsamplingXOffset(); int gridY = p.getSubsamplingYOffset(); sourceBounds.x += gridX; sourceBounds.y += gridY; sourceBounds.width -= gridX; sourceBounds.height -= gridY; // Get subsampling factors periodX = p.getSourceXSubsampling(); periodY = p.getSourceYSubsampling(); } // Compute output dimensions destSize.setSize((sourceBounds.width + periodX - 1)/periodX, (sourceBounds.height + periodY - 1)/periodY); if (destSize.width <= 0 || destSize.height <= 0) { throw new IllegalArgumentException("Empty source region!"); } }