Example usage for java.awt Rectangle setFrame

List of usage examples for java.awt Rectangle setFrame

Introduction

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

Prototype

public void setFrame(double x, double y, double w, double h) 

Source Link

Document

Sets the location and size of the outer bounds of this Rectangle2D to the specified rectangular values.

Usage

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

public boolean editCellAt(int row, int column, EventObject e) {
    boolean b = super.editCellAt(row, column, e);
    if (b && editorComp != null) {
        //          System.out.println("editing cell at " + row + " " + column);
        Component comp;//from  w w  w.  jav a  2s.  c o  m
        boolean nameCell = false;
        if (editorComp instanceof NameCellComponent) {
            nameCell = true;
            NameCellComponent nameCellComp = (NameCellComponent) editorComp;
            comp = nameCellComp.getTextComponent();
        } else
            comp = editorComp;

        if (comp instanceof KeyboardFocusable)
            ((KeyboardFocusable) comp).selectAll(e == null);

        else if (comp instanceof ChangeAwareTextField) {
            ChangeAwareTextField text = ((ChangeAwareTextField) comp);
            if (e == null) {
                text.selectAll();
            } else if (e instanceof MouseEvent) {
                if (nameCell) {
                    MouseEvent me = (MouseEvent) e;
                    Rectangle bounds = text.getBounds(null);
                    Rectangle cell = getCellRect(row, column, false);
                    bounds.setFrame(cell.getX() + bounds.getX(), cell.getY() + bounds.getY(), bounds.getWidth(),
                            bounds.getHeight());
                    if (bounds.contains(me.getPoint())) {
                        text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
                    } else { //because if it's outside there's no caret update
                        text.requestFocus();
                        text.selectAll();
                    }
                } else
                    text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
            }
            text.resetChange();
        }
    }
    return b;
}

From source file:org.uva.itast.blended.omr.scanners.BarcodeScanner.java

/**
 * Generates an expanded boundingbox in milimeters
 * /* ww w.ja v  a 2  s .  c om*/
 * @see {@link #BARCODE_AREA_PERCENT}
 * @see {@value #BARCODE_AREA_PERCENT}
 * @param rect
 * @return milimeteres
 */
protected Rectangle2D getExpandedArea(Rectangle2D rect, double percent) {
    Rectangle expandedRect = new Rectangle();
    expandedRect.setFrame((rect.getX() - rect.getWidth() * (percent) / 2),
            (rect.getY() - rect.getHeight() * (percent) / 2), (rect.getWidth() * (1 + percent)),
            (rect.getHeight() * (1 + percent)));
    return expandedRect;
}