Example usage for java.awt Rectangle getLocation

List of usage examples for java.awt Rectangle getLocation

Introduction

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

Prototype

public Point getLocation() 

Source Link

Document

Returns the location of this Rectangle .

Usage

From source file:com.osparking.attendant.AttListForm.java

private boolean rowHidden(JTable usersTable, int i) {
    Rectangle vr = usersTable.getVisibleRect();
    int first = usersTable.rowAtPoint(vr.getLocation());
    vr.translate(0, vr.height);//from   w  ww  .j  a  va2s  .c om
    int visibleRows = usersTable.rowAtPoint(vr.getLocation()) - first;
    if (i < visibleRows) {
        return false;
    } else {
        return true;
    }
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

protected void record() {
    try {//from   ww  w  .j av a  2s  .c o  m
        Thread.sleep(200); // For Ubuntu.
    } catch (InterruptedException ie) {
        // Ignore
    }

    int borderWidth = 1;
    JFrame[] borderFrames = new JFrame[4];

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    Rectangle rr = captureConfig.getRecordingRectangle();
    Color borderColor = Color.RED;
    if (rr.x >= borderWidth) {
        // West border
        borderFrames[0] = new JFrame();
        borderFrames[0].setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        borderFrames[0].setSize(borderWidth, rr.height + borderWidth * 2);
        borderFrames[0].setLocation(rr.x - borderWidth, rr.y - borderWidth);
        borderFrames[0].setUndecorated(true);
        borderFrames[0].setAlwaysOnTop(true);
        borderFrames[0].setFocusableWindowState(false);
        borderFrames[0].getContentPane().setBackground(borderColor);
    }
    if (rr.x + rr.width < dim.width - borderWidth) {
        // East border
        borderFrames[1] = new JFrame();
        borderFrames[1].setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        borderFrames[1].setSize(borderWidth, rr.height + borderWidth * 2);
        borderFrames[1].setLocation(rr.x + rr.width, rr.y - borderWidth);
        borderFrames[1].setUndecorated(true);
        borderFrames[1].setAlwaysOnTop(true);
        borderFrames[1].setFocusableWindowState(false);
        borderFrames[1].getContentPane().setBackground(borderColor);
    }
    if (rr.y >= borderWidth) {
        // North border
        borderFrames[2] = new JFrame();
        borderFrames[2].setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        borderFrames[2].setSize(rr.width, borderWidth);
        borderFrames[2].setLocation(rr.x, rr.y - borderWidth);
        borderFrames[2].setUndecorated(true);
        borderFrames[2].setAlwaysOnTop(true);
        borderFrames[2].setFocusableWindowState(false);
        borderFrames[2].getContentPane().setBackground(borderColor);
    }
    if (rr.y + rr.height < dim.height - borderWidth) {
        // South border
        borderFrames[3] = new JFrame();
        borderFrames[3].setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        borderFrames[3].setSize(rr.width, borderWidth);
        borderFrames[3].setLocation(rr.x, rr.y + rr.height);
        borderFrames[3].setUndecorated(true);
        borderFrames[3].setAlwaysOnTop(true);
        borderFrames[3].setFocusableWindowState(false);
        borderFrames[3].getContentPane().setBackground(borderColor);
    }

    RecordingControlsFrame inst = new RecordingControlsFrame(this, borderFrames);
    int x = getLocation().x + getWidth() - inst.getWidth();
    if (x + inst.getWidth() > dim.getWidth()) {
        x = dim.width - inst.getWidth();
    } else if (x < 0) {
        x = 0;
    }

    int y = rr.getLocation().y + getHeight() + 1;
    if (y + inst.getHeight() > dim.height) {
        y = rr.getLocation().y - inst.getHeight();
        if (y < 0) {
            y = dim.height - inst.getHeight();
        }
    }
    inst.setLocation(x, y);
    inst.setVisible(true);
}

From source file:org.apache.jmeter.config.gui.ArgumentsPanel.java

/**
 * @param table {@link JTable}/*from   ww  w  . ja  va2s .co m*/
 * @return number of visible rows
 */
private static int getNumberOfVisibleRows(JTable table) {
    Rectangle vr = table.getVisibleRect();
    int first = table.rowAtPoint(vr.getLocation());
    vr.translate(0, vr.height);
    return table.rowAtPoint(vr.getLocation()) - first;
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private Rectangle positionPlot(Dimension size, int x, int y, int bottom, int right) {
    //insets.setValue(top, left, bottom, right);
    //Rectangle r = insets.shrinkRect(size);
    final Rectangle r = new Rectangle(x, y, (int) size.getWidth() - x - right,
            (int) size.getHeight() - y - bottom);
    origin = r.getLocation();
    graphSize.setSize(r.width, r.height);
    return r;/*w w w  . ja v  a2  s  .  co  m*/
}

From source file:org.nuclos.client.customcomp.resplan.ResPlanPanel.java

public void setViewRect(Rectangle rect) {
    scrollPane.getViewport().setViewPosition(rect.getLocation());
}

From source file:org.pmedv.blackboard.commands.ConvertToSymbolCommand.java

@Override
public void execute(ActionEvent e) {

    // which editor do we have?

    final BoardEditor editor = EditorUtils.getCurrentActiveEditor();

    final List<Item> items = editor.getSelectedItems();
    final List<Item> preserveItems = new ArrayList<Item>();

    for (Item item : items) {
        if (item instanceof Symbol || item instanceof Resistor || item instanceof Diode) {
            ErrorUtils//w ww  .  j a v  a 2 s.co m
                    .showErrorDialog(new IllegalStateException(resources.getResourceByKey("error.onlyshapes")));
            return;
        }
    }

    // first we need to check all items and determine min_x, min_y, max_x, max_y as well as height and width

    int min_x = Integer.MAX_VALUE;
    int min_y = Integer.MAX_VALUE;
    int max_x = Integer.MIN_VALUE;
    int max_y = Integer.MIN_VALUE;

    for (Item item : items) {

        if (item instanceof Line) {

            final Line line = (Line) item;
            final Rectangle boundingBox = line.getBoundingBox();

            int x1 = (int) boundingBox.getLocation().getX();
            int y1 = (int) boundingBox.getLocation().getY();
            int x2 = x1 + (int) boundingBox.getWidth();
            int y2 = y1 + (int) boundingBox.getHeight();

            if (x1 < min_x)
                min_x = x1;
            if (y1 < min_y)
                min_y = y1;
            if (x2 > max_x)
                max_x = x2;
            if (y2 > max_y)
                max_y = y2;
        } else {
            if (item.getXLoc() + item.getWidth() > max_x)
                max_x = item.getXLoc() + item.getWidth();
            if (item.getYLoc() + item.getHeight() > max_y)
                max_y = item.getYLoc() + item.getHeight();
            if (item.getXLoc() < min_x)
                min_x = item.getXLoc();
            if (item.getYLoc() < min_y)
                min_y = item.getYLoc();
        }

    }

    int width = max_x - min_x;
    int height = max_y - min_y;

    final Symbol symbol = new Symbol();
    symbol.setWidth(width);
    symbol.setHeight(height);

    // sort items by z-index
    Collections.sort(items);

    symbol.setLayer(items.get(0).getLayer());

    for (final Item item : items) {

        // preserve old position and set new position and render, since we need to convert the coordinates
        // of the item to the newly calculated drawing area

        if (item instanceof Line) {

            final Line line = (Line) item;

            line.getOldstart().setLocation(line.getStart().getX(), line.getStart().getY());
            line.getOldEnd().setLocation(line.getEnd().getX(), line.getEnd().getY());

            line.getStart().setLocation(line.getStart().getX() - min_x, line.getStart().getY() - min_y);
            line.getEnd().setLocation(line.getEnd().getX() - min_x, line.getEnd().getY() - min_y);
        } else {

            item.setOldXLoc(item.getXLoc());
            item.setOldYLoc(item.getYLoc());

            item.setXLoc(item.getXLoc() - min_x);
            item.setYLoc(item.getYLoc() - min_y);
        }

        item.setOpacity(item.getOpacity());

        // restore position
        if (item instanceof Line) {

            final Line line = (Line) item;

            line.getStart().setLocation(line.getOldstart().getX(), line.getOldstart().getY());
            line.getEnd().setLocation(line.getOldEnd().getX(), line.getOldEnd().getY());
        } else {
            item.setXLoc(item.getOldXLoc());
            item.setYLoc(item.getOldYLoc());
        }

        symbol.getItems().add(item);

    }

    // now get a new index      
    int max = 0;

    for (final Layer layer : editor.getModel().getLayers()) {
        for (Item item : layer.getItems()) {
            if (item.getIndex() > max)
                max = item.getIndex();
        }
    }

    max++;
    symbol.setIndex(max);

    // remove original items and replace with created symbol 

    if (editor.getSelectedItems().size() > 1) {
        editor.clearSelectionBorder();

        preserveItems.addAll(editor.getSelectedItems());

        for (Item item : editor.getSelectedItems()) {
            for (Layer layer : editor.getModel().getLayers())
                layer.getItems().remove(item);
        }

        editor.getSelectedItems().clear();

        symbol.setXLoc(min_x);
        symbol.setYLoc(min_y);

        editor.getModel().getCurrentLayer().getItems().add(symbol);
        editor.setSelectedItem(symbol);

        UndoManager undoManager = editor.getUndoManager();
        if (!undoManager.addEdit(new ConvertToSymbolEdit(preserveItems, symbol))) {
            log.info("Could not add edit " + this.getClass());
        }
        editor.setFileState(FileState.DIRTY);

        AppContext.getContext().getBean(RedoCommand.class).setEnabled(undoManager.canRedo());
        AppContext.getContext().getBean(UndoCommand.class).setEnabled(undoManager.canUndo());

        editor.refresh();
    }

}

From source file:storybook.toolkit.swing.SwingUtil.java

public static void expandRectangle(Rectangle rect) {
    Point p = rect.getLocation();
    p.translate(-5, -5);//from   w w  w .j  av  a  2 s.  c o  m
    rect.setLocation(p);
    rect.grow(10, 10);
}