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