List of usage examples for java.awt Rectangle Rectangle
public Rectangle(int x, int y, int width, int height)
From source file:ca.sqlpower.dao.session.RectangleConverter.java
public Rectangle convertToComplexType(String convertFrom) throws ConversionException { String[] pieces = convertFrom.split(DELIMITER); int x = Integer.valueOf(pieces[0]); int y = Integer.valueOf(pieces[1]); int width = Integer.valueOf(pieces[2]); int height = Integer.valueOf(pieces[3]); return new Rectangle(x, y, width, height); }
From source file:Main.java
private JScrollPane getJScrollPane_descContent() { if (jScrollPane_descContent == null) { jScrollPane_descContent = new JScrollPane(getJTextArea_content()); jScrollPane_descContent.setBounds(new Rectangle(75, 224, 660, 47)); }// w ww . ja va 2s . c o m return jScrollPane_descContent; }
From source file:Main.java
/** * Returns an appropriate location for a component's tool tip that <i>always</i> * lies within the specified frame.//from w ww . ja va 2s .c o m * <p> * Intended be used in custom implementations of {@link JComponent#getToolTipLocation(MouseEvent)}. * * @param e * the event that caused the display of the tool tip * @param c * the parent component of the tool tip * @param frame * a component in which the tool tip has to fit (usually the surrounding window of "c") * @return */ public static Point getAdjustedToolTipLocation(MouseEvent e, JComponent c, Component frame) { JToolTip tip = new JToolTip(); tip.setTipText(c.getToolTipText(e)); Dimension tipSize = tip.getPreferredSize(); // Tool tip will be positioned within the bounds of the specified component (+ 5px inset) Rectangle frameR = frame.getBounds(); if (frame instanceof Container) { Container container = (Container) frame; Insets insets = container.getInsets(); frameR.x += insets.left; frameR.y += insets.top; frameR.width -= (insets.left + insets.right); frameR.height -= (insets.top + insets.bottom); } frameR.x += 5; frameR.y += 5; frameR.width -= 10; frameR.height -= 10; // Initial try for the tool tip's position Rectangle r = new Rectangle(e.getXOnScreen(), c.getLocationOnScreen().y + c.getSize().height + 1, tipSize.width, tipSize.height); // Check if it fits within the frame Rectangle intersection = frameR.intersection(r); if (r.equals(intersection)) { // Tool tip is fully visible within the frame --> use default behaviour // // Note: The implementation of ToolTipManager.showTipWindow() is not always // correct in dual screen mode. The tool tip is _always_ put on that screen, // where the most part of the frame lies upon, even if we return coordinates // that clearly belong to the other screen. Unfortunately we cannot change // that behavior... (bsh 2010-11-24) return null; } // Otherwise, move the tool tip int correction = 0; if (r.height == intersection.height) { // Height is okay, just move left. To make it look better, position the // tip 5px below the component. r = new Rectangle(r.x, c.getLocationOnScreen().y + c.getSize().height + 5, tipSize.width, tipSize.height); correction = -5; // needed to make the ToolTipManager use a lightweight pop-up } else { // The height does not fit. Position the tool tip above the component. r = new Rectangle(c.getLocationOnScreen().x + 10, c.getLocationOnScreen().y - tipSize.height - 1, tipSize.width, tipSize.height); } // Adjust to frame bounds intersection = frameR.intersection(r); intersection.x -= (r.width - intersection.width); intersection.y -= (r.height - intersection.height); // Return value is expected to be relative to the component's position return new Point((-c.getLocationOnScreen().x) + intersection.x + correction, (-c.getLocationOnScreen().y) + intersection.y); }
From source file:com.dianping.imcaptcha.strategy.WaveFilter.java
public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); int type = src.getType(); WritableRaster srcRaster = src.getRaster(); originalSpace = new Rectangle(0, 0, width, height); transformedSpace = new Rectangle(0, 0, width, height); transformSpace(transformedSpace);/*from w w w .jav a 2 s . com*/ if (dst == null) { ColorModel dstCM = src.getColorModel(); dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null); } WritableRaster dstRaster = dst.getRaster(); int[] inPixels = getRGB(src, 0, 0, width, height, null); if (interpolation == NEAREST_NEIGHBOUR) return filterPixelsNN(dst, width, height, inPixels, transformedSpace); int srcWidth = width; int srcHeight = height; int srcWidth1 = width - 1; int srcHeight1 = height - 1; int outWidth = transformedSpace.width; int outHeight = transformedSpace.height; int outX, outY; int index = 0; int[] outPixels = new int[outWidth]; float radius = srcHeight * 1.0f / 2 / (float) Math.PI; outX = transformedSpace.x; outY = transformedSpace.y; float[] out = new float[2]; for (int y = 0; y < outHeight; y++) { for (int x = 0; x < outWidth; x++) { transformInverse(outX + x, outY + y, out, radius); int srcX = (int) Math.floor(out[0]); int srcY = (int) Math.floor(out[1]); float xWeight = out[0] - srcX; float yWeight = out[1] - srcY; int nw, ne, sw, se; if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) { // Easy case, all corners are in the image int i = srcWidth * srcY + srcX; nw = inPixels[i]; ne = inPixels[i + 1]; sw = inPixels[i + srcWidth]; se = inPixels[i + srcWidth + 1]; } else { // Some of the corners are off the image nw = getPixel(inPixels, srcX, srcY, srcWidth, srcHeight); ne = getPixel(inPixels, srcX + 1, srcY, srcWidth, srcHeight); sw = getPixel(inPixels, srcX, srcY + 1, srcWidth, srcHeight); se = getPixel(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight); } outPixels[x] = ImageMath.bilinearInterpolate(xWeight, yWeight, nw, ne, sw, se); } setRGB(dst, 0, y, transformedSpace.width, 1, outPixels); } return dst; }
From source file:Main.java
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. *//*from www. ja va 2 s .c o m*/ public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null || (parent.isVisible() == false)) { positionFrameOnScreen(dialog, horizontalPercent, verticalPercent); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int parentPointX = baseX + (int) (horizontalPercent * p.width); final int parentPointY = baseY + (int) (verticalPercent * p.height); final int dialogPointX = Math.max(0, parentPointX - (int) (horizontalPercent * d.width)); final int dialogPointY = Math.max(0, parentPointY - (int) (verticalPercent * d.height)); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height); final Rectangle intersectedDialogBounds = r.intersection(s); if (intersectedDialogBounds.width < d.width) { r.x = s.width - d.width; r.width = d.width; } if (intersectedDialogBounds.height < d.height) { r.y = s.height - d.height; r.height = d.height; } final Rectangle finalIntersection = r.intersection(s); dialog.setBounds(finalIntersection); }
From source file:TextureWithBufferedImage.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Rectangle2D rec1, rec2, rec3, rec4, rec5; rec1 = new Rectangle2D.Float(25, 25, 75, 150); rec2 = new Rectangle2D.Float(125, 25, 10, 75); rec3 = new Rectangle2D.Float(75, 125, 125, 75); rec4 = new Rectangle2D.Float(25, 15, 12, 75); rec5 = new Rectangle2D.Float(15, 50, 15, 15); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1); g2D.setComposite(ac);/* w w w. ja v a 2 s. co m*/ g2D.setStroke(new BasicStroke(5.0f)); g2D.draw(rec1); GradientPaint gp = new GradientPaint(125f, 25f, Color.yellow, 225f, 100f, Color.blue); g2D.setPaint(gp); g2D.fill(rec2); BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.black); big.drawLine(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); TexturePaint tp = new TexturePaint(bi, r); g2D.setPaint(tp); g2D.fill(rec3); g2D.setColor(Color.green); g2D.fill(rec4); g2D.setColor(Color.red); g2D.fill(rec5); }
From source file:MouseDragActionPanel.java
public void add(int x, int y) { if (squareCount < Max) { squares[squareCount] = new Rectangle(x, y, SquareWidth, SquareWidth); currentSquareIndex = squareCount; squareCount++;/*from w w w. j a va 2s. c om*/ repaint(); } }
From source file:omr.glyph.ui.TextAreaBrowser.java
public static void alignTexts(Sheet sheet) { TextArea area = new TextArea(null, null, sheet.getVerticalLag().createAbsoluteRoi(new Rectangle(0, 0, sheet.getWidth(), sheet.getHeight())), new HorizontalOrientation()); // subdivide// w w w . jav a 2 s .co m area.subdivide(); // Align text glyphs for (SystemInfo info : sheet.getSystems()) { info.retrieveSentences(); } }
From source file:org.encog.workbench.tabs.visualize.scatter.LegendPanel.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; BlockParams p = new BlockParams(); p.setGenerateEntities(true);/*from w w w . j a va 2s. co m*/ Rectangle area = new Rectangle(0, 0, this.getWidth(), this.getHeight()); legend.arrange(g2d); legend.draw(g2d, area, p); }
From source file:layout.GraphPaperTest.java
public GraphPaperTest() { setLayout(new GraphPaperLayout(new Dimension(5, 5))); //Add a 1x1 Rect at (0,0). add(new JButton("1"), new Rectangle(0, 0, 1, 1)); //Add a 2x1 Rect at (2,0). add(new JButton("2"), new Rectangle(2, 0, 2, 1)); //Add a 1x2 Rect at (1,1). add(new JButton("3"), new Rectangle(1, 1, 1, 2)); //Add a 2x2 Rect at (3,2). add(new JButton("4"), new Rectangle(3, 2, 2, 2)); //Add a 1x1 Rect at (0,4). add(new JButton("5"), new Rectangle(0, 4, 1, 1)); //Add a 1x2 Rect at (2,3). add(new JButton("6"), new Rectangle(2, 3, 1, 2)); }