List of usage examples for java.awt Rectangle setBounds
public void setBounds(int x, int y, int width, int height)
From source file:Main.java
/** * Returns the screen bounds for a component location (or screen location if component null). */// w w w .j av a 2 s . c o m public static Rectangle getScreenBounds(Component aComp, int anX, int aY, boolean doInset) { GraphicsConfiguration gc = getGraphicsConfiguration(aComp, anX, aY); Rectangle rect = gc != null ? gc.getBounds() : new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Insets ins = doInset && gc != null ? Toolkit.getDefaultToolkit().getScreenInsets(gc) : null; if (ins != null) { int lt = ins.left, rt = ins.right, tp = ins.top, bt = ins.bottom; rect.setBounds(rect.x + lt, rect.y + tp, rect.width - lt - rt, rect.height - tp - bt); } return rect; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(10, 10, 50, 40); r.setBounds(20, 20, 40, 40); g2.fill(r);/*from w w w .j a v a2 s . co m*/ }
From source file:com.comcast.cats.image.OCRRegionInfo.java
/** * Returns a Rectangle object comprising of the x,y,width and height values from this region info. * If there invalid x, y, widht, or height values, null is returned. * //from ww w. j a v a 2 s . c o m * @return The Rectangle object representing this region info or null if there are invalid values. */ public Rectangle getJavaRect() { Rectangle rectangle = new Rectangle(); if (x >= 0 && y >= 0 && width > 0 && height > 0) { rectangle.setBounds(x, y, width, height); } else { rectangle = null; } return rectangle; }
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
@Override public final Layer transform(final Layer layer, final ValueMap properties) { if (properties == null || properties.isEmpty()) { log.warn("Transform [ {} ] requires parameters.", TYPE); return layer; }/* w w w. j a v a 2 s . c o m*/ log.debug("Transforming with [ {} ]", TYPE); final boolean smartBounding = properties.get(KEY_SMART_BOUNDING, true); final String[] bounds = StringUtils.split(properties.get(KEY_BOUNDS, ""), ","); if (bounds.length == NUM_BOUNDS_PARAMS) { int x = parseLength(bounds[PARAM_INDEX_X], layer.getWidth()); int y = parseLength(bounds[PARAM_INDEX_Y], layer.getHeight()); int width = parseLength(bounds[PARAM_INDEX_WIDTH], layer.getWidth()); int height = parseLength(bounds[PARAM_INDEX_HEIGHT], layer.getHeight()); Rectangle rectangle = new Rectangle(); if (smartBounding) { rectangle = this.getSmartBounds(x, y, width, height, layer.getWidth(), layer.getHeight()); } else { rectangle.setBounds(x, y, width, height); } layer.crop(rectangle); if (smartBounding && layer.getWidth() != width || layer.getHeight() != height) { log.debug("SmartBounding resulted in an image of an incorrect size (based on crop params). " + "resizing to: [ width: {}, height: {} ]", width, height); layer.resize(width, height); } } return layer; }
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
private Rectangle constrainByWidth(final int x, final int y, final int width, final int height, final int layerWidth, final int x2) { final Rectangle rectangle = new Rectangle(); // Compute amount of overflow for x (that requires clipping) int deltaX = x2 - layerWidth; // Compute amount to clip height (Y) constrained by the % of total width that was removed for deltaX // (Amount clipped from Y should be proportionately equals to amount clipped from X) int deltaY = Math.round(((float) deltaX / width) * height); // Set the bounds to be the new clipped width/height rectangle.setBounds(x, y, width - deltaX, height - deltaY); return rectangle; }
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
private Rectangle constrainByHeight(final int x, final int y, final int width, final int height, final int layerHeight, final int y2) { final Rectangle rectangle = new Rectangle(); // Compute amount of overflow for y (that requires clipping) final int deltaY = y2 - layerHeight; // Compute amount to clip width (X) constrained by the % of total width that was removed for deltaY // (Amount clipped from Y should be proportionately equals to amount clipped from Y) int deltaX = Math.round(((float) deltaY / height) * width); // Set the bounds to be the new clipped width/height rectangle.setBounds(x, y, width - deltaX, height - deltaY); return rectangle; }
From source file:edu.ku.brc.specify.BackupAndRestoreApp.java
/** * Bring up the PPApp demo by showing the frame (only applicable if coming up * as an application, not an applet);//from w w w .j a v a 2 s .co m */ public void showApp() { topFrame.pack(); topFrame.setTitle(getTitle()); topFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doExit(true); } }); UIHelper.centerWindow(topFrame); /*Rectangle r = f.getBounds(); int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x); int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y); int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width); int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height); UIHelper.positionAndFitToScreen(f, x, y, w, h); */ //HelpMgr.setHelpID(topFrame, mainPanel.getHelpContext()); Rectangle r = topFrame.getBounds(); r.setBounds(1, 1, 600, 275); topFrame.setBounds(r); UIHelper.centerWindow(topFrame); topFrame.setVisible(true); }
From source file:main.java.whiteSocket.Bloop.java
public static float[] setUnitTextbox(int[] corners) { /*/* w w w .j ava2s . c o m*/ returns Rectangle to -> x,y,width,height */ Rectangle rect = new Rectangle(); int x = corners[0]; int y = corners[1]; // corner order UL, UR, LL, LR in x,y sequence int width = 0; int height = 0; if (corners[2] >= corners[6]) { width = corners[6] - x; } else { width = corners[2] - x; } if (corners[5] > corners[7]) { height = corners[7] - y; } else { height = corners[5] - y; } // scales to display output double x2 = (double) x / (double) sketch.getWidth() * (double) blooprint.getWidth(); double y2 = (double) y / (double) sketch.getHeight() * (double) blooprint.getHeight(); double width2 = (double) width / (double) sketch.getWidth() * (double) blooprint.getWidth(); double height2 = (double) height / (double) sketch.getHeight() * (double) blooprint.getHeight(); int aa = (int) Math.round(x2); int bb = (int) Math.round(y2); int cc = (int) Math.round(width2); int dd = (int) Math.round(height2); rect.setBounds(aa, bb, cc, dd); /* Unit boc in order to scale to any client side browser screen dimensions. Must be re-scaled to web application DOM element textarea location */ float[] unit = new float[4]; unit[0] = (float) aa / (float) blooprint.getWidth(); unit[1] = (float) bb / (float) blooprint.getHeight(); unit[2] = (float) cc / (float) blooprint.getWidth(); unit[3] = (float) dd / (float) blooprint.getHeight(); return unit; }
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
@SuppressWarnings("squid:S2589") private Rectangle getSmartBounds(int x, int y, int width, int height, int layerWidth, int layerHeight) { final Rectangle rectangle = new Rectangle(); final int x2 = x + width; final int y2 = y + height; if (x2 >= layerWidth && y2 >= layerHeight) { // Both exceed, pick the dimension to use as the "master" clip final float clipPercentX = ((float) (x2 - layerWidth) / width); final float clipPercentY = ((float) (y2 - layerHeight) / height); if (clipPercentX >= clipPercentY) { // The proportional amount to clip is greatest on the x-axis, so trim both dimensions by the same % return constrainByWidth(x, y, width, height, layerWidth, x2); } else {// ww w .j a v a 2 s .c om // The proportional amount to clip is greatest on the y-axis, so trim both dimensions by the same % return constrainByHeight(x, y, width, height, layerHeight, y2); } } else if (x2 >= layerWidth && y2 < layerHeight) { return constrainByWidth(x, y, width, height, layerWidth, x2); } else if (x2 < layerWidth && y2 >= layerHeight) { return constrainByHeight(x, y, width, height, layerHeight, y2); } // Crop within layer size rectangle.setBounds(x, y, width, height); return rectangle; }
From source file:TileLayout.java
private void align(Dimension cont, Object cons[], Component comp) { int align = 0; Insets insets = null;/* w ww . ja v a 2 s . c om*/ Rectangle tile = null, fixd = null; if (cons != null) { for (int i = 0; i < cons.length; i++) { // gather constraints if (cons[i] != null) { if (cons[i] instanceof Rectangle) fixd = (Rectangle) cons[i]; else if (cons[i] instanceof Insets) insets = (Insets) cons[i]; else if (cons[i] instanceof Integer) align = ((Integer) cons[i]).intValue(); else if (cons[i] instanceof Component) tile = ((Component) cons[i]).getBounds(); } } } if (tile == null) tile = new Rectangle(cont); Rectangle pref = new Rectangle(tile.getLocation(), comp.getPreferredSize()); // perform component positioning: if ((align & 0x004000) != 0) pref.width = fixd.width; else if ((align & 0x008000) != 0) pref.width = (tile.width * fixd.width + 500) / 1000; else if ((align & 0x010000) != 0) pref.width = tile.width; if ((align & 0x080000) != 0) pref.height = fixd.height; else if ((align & 0x100000) != 0) pref.height = (tile.height * fixd.height + 500) / 1000; else if ((align & 0x200000) != 0) pref.height = tile.height; if ((align & 0x000001) != 0) pref.x -= pref.width; else if ((align & 0x000002) != 0) pref.x += (tile.width - pref.width >> 1); else if ((align & 0x000004) != 0) pref.x += tile.width - pref.width; else if ((align & 0x000008) != 0) pref.x += tile.width; else if ((align & 0x000010) != 0) pref.x += fixd.x; else if ((align & 0x000020) != 0) pref.x += (tile.width * fixd.x + 500) / 1000; if ((align & 0x000040) != 0) pref.y -= pref.height; else if ((align & 0x000080) != 0) pref.y += (tile.height - pref.height >> 1); else if ((align & 0x000100) != 0) pref.y += tile.height - pref.height; else if ((align & 0x000200) != 0) pref.y += tile.height; else if ((align & 0x000400) != 0) pref.y += fixd.y; else if ((align & 0x000800) != 0) pref.y += (tile.height * fixd.y + 500) / 1000; if ((align & 0x001000) != 0) pref.setBounds(0, pref.y, pref.x + pref.width, pref.height); else if ((align & 0x002000) != 0) pref.width = cont.width - pref.x; if ((align & 0x020000) != 0) pref.setBounds(pref.x, 0, pref.width, pref.y + pref.height); else if ((align & 0x040000) != 0) pref.height = cont.height - pref.y; if (insets != null) { // apply insets, if any: pref.x += insets.left; pref.y += insets.top; pref.width -= insets.left + insets.right; pref.height -= insets.top + insets.bottom; } // Note: this can cause surprising results, so use it, if you dare. :-) // Honour component minimum size: Dimension d = comp.getMinimumSize(); if (pref.width < d.width) pref.width = d.width; if (pref.height < d.height) pref.height = d.height; comp.setBounds(pref); // now the tile is set! }