Search in sources :

Example 31 with Graphics2D

use of java.awt.Graphics2D in project ACS by ACS-Community.

the class AlarmDetailTable method setTitleColumnSize.

/**
	 * Calculate the width of the first column to be at least wide 
	 * enough to contain the titles in {@link RowTitles}.
	 * <P>
	 * The width of the column is the greatest between the width needed
	 * to show the title or the passed width
	 * 
	 * @param sz A vector of string (can be <code>null</code>)
	 * @return The width of the first column
	 */
private int setTitleColumnSize(Vector<String> strings) {
    BufferedImage bImg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2D = bImg.createGraphics();
    FontMetrics fm = g2D.getFontMetrics();
    int sz = 0;
    for (RowTitles row : RowTitles.values()) {
        if (sz < fm.stringWidth(row.title)) {
            sz = fm.stringWidth(row.title);
        }
    }
    if (strings != null) {
        for (String str : strings) {
            if (sz < fm.stringWidth(str)) {
                sz = fm.stringWidth(str);
            }
        }
    }
    sz += 20;
    TableColumn col = getColumnModel().getColumn(0);
    col.setPreferredWidth(sz);
    col.setMinWidth(sz);
    col.setMaxWidth(sz);
    col.setWidth(sz);
    col.setResizable(false);
    col = getColumnModel().getColumn(1);
    col.setResizable(true);
    return sz;
}
Also used : FontMetrics(java.awt.FontMetrics) TableColumn(javax.swing.table.TableColumn) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 32 with Graphics2D

use of java.awt.Graphics2D in project ACS by ACS-Community.

the class TransparentGlassPane method paint.

/**
	 * Paint the panel in a light gray.
	 */
public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    g2D.setColor(Color.black);
    g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.05f));
    g2D.fillRect(0, 0, getWidth(), getHeight());
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 33 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by DirtyUnicorns.

the class Bitmap_Delegate method nativeErase.

@LayoutlibDelegate
static /*package*/
void nativeErase(long nativeBitmap, int color) {
    // get the delegate from the native int.
    Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
    if (delegate == null) {
        return;
    }
    BufferedImage image = delegate.mImage;
    Graphics2D g = image.createGraphics();
    try {
        g.setColor(new java.awt.Color(color, true));
        g.fillRect(0, 0, image.getWidth(), image.getHeight());
    } finally {
        g.dispose();
    }
}
Also used : BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 34 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by DirtyUnicorns.

the class Canvas_Delegate method native_drawNinePatch.

@LayoutlibDelegate
public static void native_drawNinePatch(Canvas thisCanvas, long nativeCanvas, long nativeBitmap, long ninePatch, final float dstLeft, final float dstTop, final float dstRight, final float dstBottom, long nativePaintOrZero, final int screenDensity, final int bitmapDensity) {
    // get the delegate from the native int.
    final Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmap);
    if (bitmapDelegate == null) {
        return;
    }
    byte[] c = NinePatch_Delegate.getChunk(ninePatch);
    if (c == null) {
        // not a 9-patch?
        BufferedImage image = bitmapDelegate.getImage();
        drawBitmap(nativeCanvas, bitmapDelegate, nativePaintOrZero, 0, 0, image.getWidth(), image.getHeight(), (int) dstLeft, (int) dstTop, (int) dstRight, (int) dstBottom);
        return;
    }
    final NinePatchChunk chunkObject = NinePatch_Delegate.getChunk(c);
    assert chunkObject != null;
    if (chunkObject == null) {
        return;
    }
    Canvas_Delegate canvasDelegate = Canvas_Delegate.getDelegate(nativeCanvas);
    if (canvasDelegate == null) {
        return;
    }
    // this one can be null
    Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nativePaintOrZero);
    canvasDelegate.getSnapshot().draw(new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            chunkObject.draw(bitmapDelegate.getImage(), graphics, (int) dstLeft, (int) dstTop, (int) (dstRight - dstLeft), (int) (dstBottom - dstTop), screenDensity, bitmapDensity);
        }
    }, paintDelegate, true, false);
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) NinePatchChunk(com.android.ninepatch.NinePatchChunk) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 35 with Graphics2D

use of java.awt.Graphics2D in project opennms by OpenNMS.

the class TimelineRestService method empty.

@GET
@Produces("image/png")
@Transactional
@Path("empty/{start}/{end}/{width}")
public Response empty(@PathParam("start") final long start, @PathParam("end") final long end, @PathParam("width") final int width) throws IOException {
    int delta = (int) end - (int) start;
    BufferedImage bufferedImage = new BufferedImage(width, 20, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();
    graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    graphics2D.setColor(Color.BLACK);
    int numLabels = TimescaleDescriptor.computeNumberOfLabels(graphics2D, delta, width);
    for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
        if (desc.match(delta, numLabels)) {
            desc.drawLine(graphics2D, delta, start, width);
            break;
        }
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);
    byte[] imageData = baos.toByteArray();
    return Response.ok(imageData).build();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Graphics2D (java.awt.Graphics2D)1716 BufferedImage (java.awt.image.BufferedImage)809 Color (java.awt.Color)394 BasicStroke (java.awt.BasicStroke)186 Font (java.awt.Font)161 Point (java.awt.Point)145 AffineTransform (java.awt.geom.AffineTransform)140 Rectangle (java.awt.Rectangle)139 IOException (java.io.IOException)112 Rectangle2D (java.awt.geom.Rectangle2D)100 Dimension (java.awt.Dimension)92 Image (java.awt.Image)91 GradientPaint (java.awt.GradientPaint)90 FontMetrics (java.awt.FontMetrics)87 Paint (java.awt.Paint)82 Graphics (java.awt.Graphics)79 File (java.io.File)65 Point2D (java.awt.geom.Point2D)59 Stroke (java.awt.Stroke)55 ImageIcon (javax.swing.ImageIcon)50