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));
}
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);
}
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();
}
}
}
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;
}
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);
}
Aggregations