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() 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.

Usage

From source file:Main.java

/**
 * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL}
 *///from   ww  w  .j av a  2  s . com
public static void calculateScreenSizes() {

    Rectangle totalBounds = new Rectangle();
    Rectangle primaryBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int j = 0; j < gs.length; j++) {
        GraphicsDevice gd = gs[j];
        if (gd == ge.getDefaultScreenDevice()) {
            primaryBounds = new Rectangle();
        }
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (int i = 0; i < gc.length; i++) {
            Rectangle bounds = gc[i].getBounds();
            Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]);
            bounds.x += screenInsets.left;
            bounds.y += screenInsets.top;
            bounds.height -= screenInsets.bottom;
            bounds.width -= screenInsets.right;
            totalBounds = totalBounds.union(bounds);
            if (primaryBounds != null) {
                primaryBounds = primaryBounds.union(bounds);
            }
        }
        if (primaryBounds != null) {
            SCREEN_SIZE_PRIMARY = primaryBounds;
            primaryBounds = null;
        }
    }
    SCREEN_SIZE_TOTAL = totalBounds;
}

From source file:SwingUtil.java

/**
 * Verifies if the given point is visible on the screen.
 * //from   w  w  w  .  j  a  v a  2  s .c  o  m
 * @param    location       The given location on the screen.
 * @return                True if the location is on the screen, false otherwise.
 */
public static boolean isLocationInScreenBounds(Point location) {

    // Check if the location is in the bounds of one of the graphics devices.
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
    Rectangle graphicsConfigurationBounds = new Rectangle();

    // Iterate over the graphics devices.
    for (int j = 0; j < graphicsDevices.length; j++) {

        // Get the bounds of the device.
        GraphicsDevice graphicsDevice = graphicsDevices[j];
        graphicsConfigurationBounds.setRect(graphicsDevice.getDefaultConfiguration().getBounds());

        // Is the location in this bounds?
        graphicsConfigurationBounds.setRect(graphicsConfigurationBounds.x, graphicsConfigurationBounds.y,
                graphicsConfigurationBounds.width, graphicsConfigurationBounds.height);
        if (graphicsConfigurationBounds.contains(location.x, location.y)) {

            // The location is in this screengraphics.
            return true;

        }

    }

    // We could not find a device that contains the given point.
    return false;

}

From source file:Main.java

private static Rectangle calculateInnerArea(JComponent comp, int pixels) {
    Rectangle result = new Rectangle();
    Rectangle compRect = comp.getBounds();
    result.x = pixels;/*w  w  w  .j  av a  2  s.co m*/
    result.y = pixels;
    result.height = compRect.height - (pixels * 2);
    result.width = compRect.width - (pixels * 2);
    return result;
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle();

    r.setLocation(10, 10);/*from  w  w  w. j ava  2 s  . co  m*/
    r.setSize(10, 10);

    g2.fill(r);
    System.out.println(r.height);

}

From source file:Main.java

/**
 * Centra una finestra all'interno di un'altra
 *
 * @param f componente target (finestra esterna) - se null centra nello
 * schermo//from www.j  av a  2s. co m
 * @param c componente da centrare (finestra interna)
 */
public static void centerForm(Component f, Component c) {
    Rectangle rf = new Rectangle();
    ;
    if (f == null) {
        rf = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    } else {
        rf = f.getBounds();
    }
    Rectangle rc = c.getBounds();

    int x = (rf.width - rc.width) / 2;
    if (x < 5) {
        x = 5;
    }
    int y = (rf.height - rc.height) / 2;
    if (y < 5) {
        y = 5;
    }

    if (f == null) {
        c.setLocation(x, y);
    } else {
        c.setLocation(x + f.getX(), y + f.getY());
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);// w w  w. j a  v a 2s  . c o  m
    System.out.println(r.height);

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);//from   www  .  j  a va2 s.  co m
    System.out.println(r.isEmpty());

}

From source file:GeneralPathDemo.java

public GeneralPathDemo() {
    oddShape = new GeneralPath();
    firstTime = true;
    area = new Rectangle();
}

From source file:Main.java

private void initUI() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getJTextArea_content().setText(TEXT);
    frame.add(getJScrollPane_descContent());
    frame.pack();/*from  ww w.  j  av  a 2s  .  co m*/
    frame.setVisible(true);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            getJTextArea_content().scrollRectToVisible(new Rectangle());
        }
    });
}

From source file:Main.java

public static Rectangle calculatePaintingArea(JComponent c) {
    Dimension d = c.getSize();/*from   w w  w . j  ava 2 s . c  om*/
    Rectangle result = new Rectangle();
    result.x = 0;
    result.y = 0;
    result.width = d.width;
    result.height = d.height;
    Insets insets = c.getInsets();
    if (insets != null) {
        result.width = d.width - (insets.left + insets.right);
        result.height = d.height - (insets.top + insets.bottom);
        result.x = insets.left;
        result.y = insets.top;
    }
    return result;
}