Search in sources :

Example 91 with Rectangle

use of java.awt.Rectangle in project pcgen by PCGen.

the class Utility method centerComponent.

/**
	 * Centers a {@code Component} to the screen.
	 *
	 * @param dialog JDialog dialog to center
	 */
public static void centerComponent(Component dialog) {
    // since the Toolkit.getScreenSize() method is broken in the Linux implementation
    // of Java 5  (it returns double the screen size under xinerama), this method is
    // encapsulated to accomodate this with a hack.
    // TODO: remove the hack, once Java fixed this.
    // final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
    final Dimension dialogSize = dialog.getSize();
    if (dialogSize.height > screenSize.height) {
        dialogSize.height = screenSize.height;
    }
    if (dialogSize.width > screenSize.width) {
        dialogSize.width = screenSize.width;
    }
    dialog.setSize(dialogSize);
    dialog.setLocation(screenSize.x + ((screenSize.width - dialogSize.width) / 2), screenSize.y + ((screenSize.height - dialogSize.height) / 2));
}
Also used : Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension)

Example 92 with Rectangle

use of java.awt.Rectangle in project pcgen by PCGen.

the class Utility method resizeComponentToScreen.

/**
	 * Update the size of the dialog to ensure it will fit on the screen.
	 *
	 * @param dialog The dialog to be resized.
	 */
public static void resizeComponentToScreen(Component dialog) {
    // Get the maximum window size to account for taskbars etc
    Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    final Dimension dialogSize = dialog.getSize();
    if (dialogSize.height > screenBounds.height) {
        dialogSize.height = screenBounds.height;
    }
    if (dialogSize.width > screenBounds.width) {
        dialogSize.width = screenBounds.width;
    }
    dialog.setSize(dialogSize);
}
Also used : Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension)

Example 93 with Rectangle

use of java.awt.Rectangle in project android_frameworks_base by ResurrectionRemix.

the class GcSnapshot method drawInLayer.

private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint, boolean compositeOnly, int forceMode) {
    Graphics2D originalGraphics = layer.getGraphics();
    if (paint == null) {
        drawOnGraphics((Graphics2D) originalGraphics.create(), drawable, null, /*paint*/
        layer);
    } else {
        ColorFilter_Delegate filter = paint.getColorFilter();
        if (filter == null || !filter.isSupported()) {
            // get a Graphics2D object configured with the drawing parameters.
            Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, compositeOnly, forceMode);
            drawOnGraphics(configuredGraphics, drawable, paint, layer);
            return;
        }
        int x = 0;
        int y = 0;
        int width;
        int height;
        Rectangle clipBounds = originalGraphics.getClipBounds();
        if (clipBounds != null) {
            if (clipBounds.width == 0 || clipBounds.height == 0) {
                // Clip is 0 so no need to paint anything.
                return;
            }
            // If we have clipBounds available, use them as they will always be
            // smaller than the full layer size.
            x = clipBounds.x;
            y = clipBounds.y;
            width = clipBounds.width;
            height = clipBounds.height;
        } else {
            width = layer.getImage().getWidth();
            height = layer.getImage().getHeight();
        }
        // Create a temporary image to which the color filter will be applied.
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D imageBaseGraphics = (Graphics2D) image.getGraphics();
        // Configure the Graphics2D object with drawing parameters and shader.
        Graphics2D imageGraphics = createCustomGraphics(imageBaseGraphics, paint, compositeOnly, AlphaComposite.SRC_OVER);
        // get a Graphics2D object configured with the drawing parameters, but no shader.
        Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, true, /*compositeOnly*/
        forceMode);
        try {
            // The main draw operation.
            // We translate the operation to take into account that the rendering does not
            // know about the clipping area.
            imageGraphics.translate(-x, -y);
            drawable.draw(imageGraphics, paint);
            // Apply the color filter.
            // Restore the original coordinates system and apply the filter only to the
            // clipped area.
            imageGraphics.translate(x, y);
            filter.applyFilter(imageGraphics, width, height);
            // Draw the tinted image on the main layer using as start point the clipping
            // upper left coordinates.
            configuredGraphics.drawImage(image, x, y, null);
            layer.change();
        } finally {
            // dispose Graphics2D objects
            imageGraphics.dispose();
            imageBaseGraphics.dispose();
            configuredGraphics.dispose();
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) ColorFilter_Delegate(android.graphics.ColorFilter_Delegate) Paint(android.graphics.Paint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 94 with Rectangle

use of java.awt.Rectangle in project android_frameworks_base by ResurrectionRemix.

the class Region_Delegate method nativeGetBounds.

@LayoutlibDelegate
static /*package*/
boolean nativeGetBounds(long native_region, Rect rect) {
    Region_Delegate region = sManager.getDelegate(native_region);
    if (region == null) {
        return true;
    }
    Rectangle bounds = region.mArea.getBounds();
    if (bounds.isEmpty()) {
        rect.left = rect.top = rect.right = rect.bottom = 0;
        return false;
    }
    rect.left = bounds.x;
    rect.top = bounds.y;
    rect.right = bounds.x + bounds.width;
    rect.bottom = bounds.y + bounds.height;
    return true;
}
Also used : Rectangle(java.awt.Rectangle) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 95 with Rectangle

use of java.awt.Rectangle in project yyl_example by Relucent.

the class Mover method hitBorder.

protected boolean hitBorder(int _x, int _y) {
    //
    GameMatrix matrix = GameMatrix.getInstance();
    Rectangle bounds = matrix.getBounds();
    return !bounds.contains(_x, _y, width, height);
}
Also used : GameMatrix(yyl.example.exercise.awt.tank.GameMatrix) Rectangle(java.awt.Rectangle)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18