use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class JFIFMarkerSegment method expandGrayThumb.
/**
* Return an RGB image that is the expansion of the given grayscale
* image.
*/
private static BufferedImage expandGrayThumb(BufferedImage thumb) {
BufferedImage ret = new BufferedImage(thumb.getWidth(), thumb.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = ret.getGraphics();
g.drawImage(thumb, 0, 0, null);
return ret;
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class PrintJob2D method getGraphics.
/**
* Gets a Graphics object that will draw to the next page.
* The page is sent to the printer when the graphics
* object is disposed. This graphics object will also implement
* the PrintGraphics interface.
* @see PrintGraphics
*/
public Graphics getGraphics() {
Graphics printGraphics = null;
synchronized (this) {
++pageIndex;
// has been closed.
if (pageIndex == 0 && !graphicsToBeDrawn.isClosed()) {
/* We start a thread on which the PrinterJob will run.
* The PrinterJob will ask for pages on that thread
* and will use a message queue to fulfill the application's
* requests for a Graphics on the application's
* thread.
*/
startPrinterJobThread();
}
notify();
}
/* If the application has already been handed back
* a graphics then we need to put that graphics into
* the drawn queue so that the PrinterJob thread can
* return to the print system.
*/
if (currentGraphics != null) {
graphicsDrawn.append(currentGraphics);
currentGraphics = null;
}
/* We'll block here until a new graphics becomes
* available.
*/
currentGraphics = graphicsToBeDrawn.pop();
if (currentGraphics instanceof PeekGraphics) {
((PeekGraphics) currentGraphics).setAWTDrawingOnly();
graphicsDrawn.append(currentGraphics);
currentGraphics = graphicsToBeDrawn.pop();
}
if (currentGraphics != null) {
/* In the PrintJob API, the origin is at the upper-
* left of the imageable area when using the new "printable"
* origin attribute, otherwise its the physical origin (for
* backwards compatibility. We emulate this by createing
* a PageFormat which matches and then performing the
* translate to the origin. This is a no-op if physical
* origin is specified.
*/
currentGraphics.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
/* Scale to accommodate AWT's notion of printer resolution */
double awtScale = 72.0 / getPageResolutionInternal();
currentGraphics.scale(awtScale, awtScale);
/* The caller wants a Graphics instance but we do
* not want them to make 2D calls. We can't hand
* back a Graphics2D. The returned Graphics also
* needs to implement PrintGraphics, so we wrap
* the Graphics2D instance. The PrintJob API has
* the application dispose of the Graphics so
* we create a copy of the one returned by PrinterJob.
*/
printGraphics = new ProxyPrintGraphics(currentGraphics.create(), this);
}
return printGraphics;
}
use of java.awt.Graphics in project JMRI by JMRI.
the class PositionablePropertiesUtil method getColourIcon.
ImageIcon getColourIcon(Color color) {
int ICON_DIMENSION = 10;
BufferedImage image = new BufferedImage(ICON_DIMENSION, ICON_DIMENSION, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
// set completely transparent
g.setColor(color);
g.fillRect(0, 0, ICON_DIMENSION, ICON_DIMENSION);
ImageIcon icon = new ImageIcon(image);
return icon;
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class TitledBorder method paintBorder.
/**
* Paints the border for the specified component with the
* specified position and size.
* @param c the component for which this border is being painted
* @param g the paint graphics
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Border border = getBorder();
String title = getTitle();
if ((title != null) && !title.isEmpty()) {
int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
JLabel label = getLabel(c);
Dimension size = label.getPreferredSize();
Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0));
int borderX = x + edge;
int borderY = y + edge;
int borderW = width - edge - edge;
int borderH = height - edge - edge;
int labelY = y;
int labelH = size.height;
int position = getPosition();
switch(position) {
case ABOVE_TOP:
insets.left = 0;
insets.right = 0;
borderY += labelH - edge;
borderH -= labelH - edge;
break;
case TOP:
insets.top = edge + insets.top / 2 - labelH / 2;
if (insets.top < edge) {
borderY -= insets.top;
borderH += insets.top;
} else {
labelY += insets.top;
}
break;
case BELOW_TOP:
labelY += insets.top + edge;
break;
case ABOVE_BOTTOM:
labelY += height - labelH - insets.bottom - edge;
break;
case BOTTOM:
labelY += height - labelH;
insets.bottom = edge + (insets.bottom - labelH) / 2;
if (insets.bottom < edge) {
borderH += insets.bottom;
} else {
labelY -= insets.bottom;
}
break;
case BELOW_BOTTOM:
insets.left = 0;
insets.right = 0;
labelY += height - labelH;
borderH -= labelH - edge;
break;
}
insets.left += edge + TEXT_INSET_H;
insets.right += edge + TEXT_INSET_H;
int labelX = x;
int labelW = width - insets.left - insets.right;
if (labelW > size.width) {
labelW = size.width;
}
switch(getJustification(c)) {
case LEFT:
labelX += insets.left;
break;
case RIGHT:
labelX += width - insets.right - labelW;
break;
case CENTER:
labelX += (width - labelW) / 2;
break;
}
if (border != null) {
if ((position != TOP) && (position != BOTTOM)) {
border.paintBorder(c, g, borderX, borderY, borderW, borderH);
} else {
Graphics g2 = g.create();
if (g2 instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g2;
Path2D path = new Path2D.Float();
path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
g2d.clip(path);
}
border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
g2.dispose();
}
}
g.translate(labelX, labelY);
label.setSize(labelW, labelH);
label.paint(g);
g.translate(-labelX, -labelY);
} else if (border != null) {
border.paintBorder(c, g, x, y, width, height);
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class RepaintArea method paint.
/**
* Invokes paint and update on target Component with optimal
* rectangular clip region.
* If PAINT bounding rectangle is less than
* MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
* painted separately. Otherwise the entire bounding rectangle is painted.
*
* @param target Component to <code>paint</code> or <code>update</code>
* @since 1.4
*/
public void paint(Object target, boolean shouldClearRectBeforePaint) {
Component comp = (Component) target;
if (isEmpty()) {
return;
}
if (!comp.isVisible()) {
return;
}
RepaintArea ra = this.cloneAndReset();
if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
}
if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
int square = paintRect.width * paintRect.height;
int benefit = square - ra.paintRects[HORIZONTAL].width * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width * ra.paintRects[VERTICAL].height;
// if benefit is comparable with bounding box
if (MAX_BENEFIT_RATIO * benefit < square) {
ra.paintRects[HORIZONTAL] = paintRect;
ra.paintRects[VERTICAL] = null;
}
}
for (int i = 0; i < paintRects.length; i++) {
if (ra.paintRects[i] != null && !ra.paintRects[i].isEmpty()) {
// Should use separate Graphics for each paint() call,
// since paint() can change Graphics state for next call.
Graphics g = comp.getGraphics();
if (g != null) {
try {
g.setClip(ra.paintRects[i]);
if (i == UPDATE) {
updateComponent(comp, g);
} else {
if (shouldClearRectBeforePaint) {
g.clearRect(ra.paintRects[i].x, ra.paintRects[i].y, ra.paintRects[i].width, ra.paintRects[i].height);
}
paintComponent(comp, g);
}
} finally {
g.dispose();
}
}
}
}
}
Aggregations