Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

In this page you can find the example usage for java.awt Rectangle Rectangle.

Prototype

public Rectangle(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:de.hstsoft.sdeep.NoteManager.java

public Note getNoteAt(Point2D mapPosition, int size) {
    int x = (int) mapPosition.getX() - size / 2;
    int y = (int) mapPosition.getY() - size / 2;
    Rectangle rectangle = new Rectangle(x, y, size, size);

    for (Note n : notes) {
        if (rectangle.contains(n.getPosition())) {
            return n;
        }/* www .j a v  a2  s . c  o m*/
    }
    return null;
}

From source file:org.esa.beam.visat.toolviews.stat.XYImagePlot.java

public void setImage(BufferedImage image) {
    synchronized (imageLock) {
        this.image = image;
        if (image != null && imageDataBounds == null) {
            setImageDataBounds(new Rectangle(0, 0, image.getWidth(), image.getHeight()));
        }/*ww  w. j  a va2s  .  co m*/
    }
}

From source file:endrov.frameTime.FrameTimeWindow.java

/**
 * Make a new window at default location
 */
public FrameTimeWindow() {
    this(new Rectangle(100, 100, 1000, 600));
}

From source file:de.huxhorn.lilith.swing.AboutDialog.java

public AboutDialog(Frame owner, String title, String appName) {
    super(owner, title, false);
    wasScrolling = true;//from  w  w  w  .j a  v a2 s  . c o  m
    setLayout(new BorderLayout());
    InputStream is = MainFrame.class.getResourceAsStream("/about/aboutText.txt");
    String aboutText = null;
    final Logger logger = LoggerFactory.getLogger(AboutDialog.class);
    if (is != null) {
        try {
            aboutText = IOUtils.toString(is, StandardCharsets.UTF_8);
        } catch (IOException e) {
            if (logger.isErrorEnabled())
                logger.error("Exception while loading aboutText!! *grrr*");
        }
    }
    try {
        aboutPanel = new AboutPanel(MainFrame.class.getResource("/about/lilith_big.jpg"),
                new Rectangle(50, 50, 400, 200), aboutText, MainFrame.class.getResource("/about/lilith.jpg"),
                appName, 20);
        //aboutPanel.setDebug(true);
        add(aboutPanel, BorderLayout.CENTER);
    } catch (IOException e) {
        if (logger.isErrorEnabled())
            logger.error("Exception creating about panel!!");
    }
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        /**
         * Invoked when a window is in the process of being closed.
         * The close operation can be overridden at this point.
         */
        @Override
        public void windowClosing(WindowEvent e) {
            setVisible(false);
        }
    });

}

From source file:RobotTest.java

/**
 * Runs a sample test procedure/*from   w  w w.  jav a2s.c  o m*/
 * 
 * @param robot
 *          the robot attached to the screen device
 */
public static void runTest(Robot robot) {
    // simulate a space bar press
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a tab key followed by a space
    robot.delay(2000);
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a mouse click over the rightmost button
    robot.delay(2000);
    robot.mouseMove(200, 50);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    // capture the screen and show the resulting image
    robot.delay(2000);
    BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 400, 300));

    ImageFrame frame = new ImageFrame(image);
    frame.setVisible(true);
}

From source file:Main.java

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Graphics2D g2 = (Graphics2D) g;

    int bottomLineY = height - thickness - shadowPad;

    RoundRectangle2D.Double bubble = new RoundRectangle2D.Double(0 + strokePad, 0 + strokePad,
            width - thickness - shadowPad, bottomLineY, radius, radius);

    Area area = new Area(bubble);

    g2.setRenderingHints(hints);//from   w w  w .j a v  a  2  s . c o m

    g2.setColor(color);
    g2.setStroke(stroke);
    g2.draw(area);

    Area shadowArea = new Area(new Rectangle(0, 0, width, height));
    shadowArea.subtract(area);
    g.setClip(shadowArea);
    Color shadow = new Color(color.getRed(), color.getGreen(), color.getBlue(), 128);
    g2.setColor(shadow);
    g2.translate(shadowPad, shadowPad);
    g2.draw(area);
}

From source file:ala.soils2sat.DrawingUtils.java

public static Rectangle drawString(Graphics g, Font font, String text, int x, int y, int width, int height,
        int align, boolean wrap) {
    g.setFont(font);//from  w ww  .  j  a va2 s. c om
    FontMetrics fm = g.getFontMetrics(font);

    setPreferredAliasingMode(g);

    Rectangle ret = new Rectangle(0, 0, 0, 0);

    if (text == null) {
        return ret;
    }
    String[] alines = text.split("\\n");
    ArrayList<String> lines = new ArrayList<String>();
    for (String s : alines) {
        if (wrap && fm.stringWidth(s) > width) {
            // need to split this up into multiple lines...
            List<String> splitLines = wrapString(s, fm, width);
            lines.addAll(splitLines);
        } else {
            lines.add(s);
        }
    }
    int numlines = lines.size();
    while (fm.getHeight() * numlines > height) {
        numlines--;
    }
    if (numlines > 0) {
        int maxwidth = 0;
        int minxoffset = y + width;
        int totalheight = (numlines * fm.getHeight());

        int linestart = ((height / 2) - (totalheight / 2));

        if (!wrap) {
            ret.y = y + linestart;
        } else {
            ret.y = y;
            linestart = 0;
        }
        for (int idx = 0; idx < numlines; ++idx) {
            String line = lines.get(idx);
            int stringWidth = fm.stringWidth(line);
            // the width of the label depends on the font :
            // if the width of the label is larger than the item
            if (stringWidth > 0 && width < stringWidth) {
                // We have to truncate the label
                line = clipString(null, fm, line, width);
                stringWidth = fm.stringWidth(line);
            }

            int xoffset = 0;
            int yoffset = linestart + fm.getHeight() - fm.getDescent();
            if (align == TEXT_ALIGN_RIGHT) {
                xoffset = (width - stringWidth);
            } else if (align == TEXT_ALIGN_CENTER) {
                xoffset = (int) Math.round((double) (width - stringWidth) / (double) 2);
            }

            if (xoffset < minxoffset) {
                minxoffset = xoffset;
            }
            g.drawString(line, x + xoffset, y + yoffset);
            if (stringWidth > maxwidth) {
                maxwidth = stringWidth;
            }
            linestart += fm.getHeight();
        }

        ret.width = maxwidth;
        ret.height = totalheight;
        ret.x = x + minxoffset;

        // Debug only...
        if (DEBUG) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setStroke(new BasicStroke(1));
            g.setColor(Color.blue);
            g.drawRect(ret.x, ret.y, ret.width, ret.height);
            g.setColor(Color.green);
            g.drawRect(x, y, width, height);
        }

        return ret;
    }
    return ret;
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Construct a bounding box with the given origin, width and height.
 * /*from w  w w  . j  av a  2 s  .  com*/
 * @param dimensions
 *            int array in the form {x, y, width, height}
 */
public BoundingBox(int[] dimensions) {
    rect = new Rectangle(dimensions[0], dimensions[1], dimensions[2], dimensions[3]);
}

From source file:com.jaeksoft.searchlib.ocr.HocrBox.java

public void addRectangle(List<Rectangle> boxList, float xFactor, float yFactor) {
    int x = (int) (x0 * xFactor);
    int y = (int) (y0 * yFactor);
    int w = (int) ((x1 - x0) * xFactor);
    int h = (int) ((y1 - y0) * yFactor);
    Rectangle r = new Rectangle(x, y, w, h);
    boxList.add(r);/*from  w w  w.ja  va  2 s . c o m*/
}

From source file:eu.esdihumboldt.hale.ui.views.styledmap.tool.InstanceTool.java

/**
 * @see AbstractMapTool#click(MouseEvent, GeoPosition)
 *//*from ww w  . j  ava 2s. co m*/
@Override
public void click(MouseEvent me, GeoPosition pos) {
    if (me.getClickCount() == 2) {
        mapKit.setCenterPosition(pos);
        mapKit.setZoom(mapKit.getMainMap().getZoom() - 1);
    } else if (me.getClickCount() == 1) {
        if (me.isAltDown() && getPositions().size() < 1) {
            // add pos
            addPosition(pos);
        } else if (getPositions().size() == 1) {
            // finish box selection
            // action & reset
            addPosition(pos);

            // action
            try {
                List<Point2D> points = getPoints();
                Rectangle rect = new Rectangle((int) points.get(0).getX(), (int) points.get(0).getY(), 0, 0);
                rect.add(points.get(1));

                updateSelection(rect, me.isControlDown() || me.isMetaDown(), true);
            } catch (IllegalGeoPositionException e) {
                log.error("Error calculating selection box", e); //$NON-NLS-1$
            }

            reset();
        } else {
            // click selection
            reset();

            updateSelection(me.getPoint(), me.isControlDown() || me.isMetaDown(), true);
        }
    }
}