本文整理汇总了Java中javax.swing.Icon.paintIcon方法的典型用法代码示例。如果您正苦于以下问题:Java Icon.paintIcon方法的具体用法?Java Icon.paintIcon怎么用?Java Icon.paintIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.Icon
的用法示例。
在下文中一共展示了Icon.paintIcon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintIconForVertex
import javax.swing.Icon; //导入方法依赖的package包/类
public void paintIconForVertex(Graphics g, Vertex v, int x, int y) {
boolean outlineImages = false;
if(vertexIconFunction instanceof DemoVertexImageShapeFunction) {
outlineImages = ((DemoVertexImageShapeFunction)vertexIconFunction).isOutlineImages();
}
Icon icon = vertexIconFunction.getIcon(v);
if(icon == null || outlineImages) {
Shape s = AffineTransform.getTranslateInstance(x,y).
createTransformedShape(getVertexShapeFunction().getShape(v));
paintShapeForVertex((Graphics2D)g, v, s);
}
if(icon != null) {
int xLoc = x - icon.getIconWidth()/2;
int yLoc = y - icon.getIconHeight()/2;
icon.paintIcon(screenDevice, g, xLoc, yLoc);
}
}
示例2: drawIcon
import javax.swing.Icon; //导入方法依赖的package包/类
/** Draw the icon if it is valid for the given type.
* Here the initial drawing assignments are also done.
*/
protected void drawIcon(Graphics g, Icon icon) {
Insets i = getInsets();
if (i != null) {
drawX = i.left;
drawY = i.top;
} else {
drawX = 0;
drawY = 0;
}
if (icon != null) {
if (g != null) {
icon.paintIcon(this, g, drawX, drawY);
}
drawHeight = Math.max(fontHeight, icon.getIconHeight());
} else {
drawHeight = fontHeight;
}
drawX += ICON_WIDTH + ICON_TEXT_GAP;
if (i != null) {
drawHeight += i.bottom;
}
drawHeight += drawY;
drawY += ascent;
}
示例3: paintIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public void paintIcon(InstancePainter painter) {
Graphics g = painter.getGraphics();
Icon icon = isInverter ? ICON_INVERTER : ICON_BUFFER;
if (icon != null) {
icon.paintIcon(painter.getDestination(), g, 2, 2);
} else {
int x = isInverter ? 0 : 2;
g.setColor(Color.BLACK);
int[] xp = new int[] { x + 15, x + 1, x + 1, x + 15 };
int[] yp = new int[] { 10, 3, 17, 10 };
g.drawPolyline(xp, yp, 4);
if (isInverter)
g.drawOval(x + 13, 8, 4, 4);
g.setColor(Value.FALSE_COLOR);
g.drawLine(x + 8, 14, x + 8, 18);
}
}
示例4: test
import javax.swing.Icon; //导入方法依赖的package包/类
private void test() {
MyGraphics mg = new MyGraphics();
Icon icon = bumps;
icon.paintIcon(mg.component, mg, 0, 0);
if (mg.image != null) {
boolean failed = true;
int value = mg.image.getRGB(0, 0);
for (int x = 0; x < mg.image.getWidth(); x++) {
for (int y = 0; y < mg.image.getHeight(); y++) {
int current = mg.image.getRGB(x, y);
if (current != value) {
mg.image.setRGB(x, y, value);
failed = false;
}
}
}
if (failed) {
throw new Error("shared metal bumps");
}
}
}
示例5: getIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public Image getIcon(int type) {
Icon icon = data.getIcon();
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
}
}
示例6: createMenuIcon
import javax.swing.Icon; //导入方法依赖的package包/类
private static Icon createMenuIcon(Icon icon, Component decorator) {
int h = menuIconSize();
int w = UIUtils.isAquaLookAndFeel() ? h + 4 : h;
BufferedImage i = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = i.getGraphics();
if (decorator != null) {
decorator.setSize(w, h);
decorator.paint(g);
}
icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
g.dispose();
return new ImageIcon(i);
}
示例7: paintIconAndTextCentered
import javax.swing.Icon; //导入方法依赖的package包/类
private void paintIconAndTextCentered(Graphics g, HtmlRendererImpl r) {
Insets ins = r.getInsets();
Icon ic = r.getIcon();
int w = r.getWidth() - (ins.left + ins.right);
int txtX = ins.left;
int txtY = 0;
if ((ic != null) && (ic.getIconWidth() > 0) && (ic.getIconHeight() > 0)) {
int iconx = (w > ic.getIconWidth()) ? ((w / 2) - (ic.getIconWidth() / 2)) : txtX;
int icony = 0;
ic.paintIcon(r, g, iconx, icony);
txtY += (ic.getIconHeight() + r.getIconTextGap());
}
int txtW = r.getPreferredSize().width;
txtX = (txtW < r.getWidth()) ? ((r.getWidth() / 2) - (txtW / 2)) : 0;
int txtH = r.getHeight() - txtY;
Font f = r.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
txtY += fm.getMaxAscent();
Color background = getBackgroundFor(r);
Color foreground = ensureContrastingColor(getForegroundFor(r), background);
if (r.isHtml()) {
HtmlRenderer._renderHTML(
r.getText(), 0, g, txtX, txtY, txtW, txtH, f, foreground, r.getRenderStyle(), true, background, r.isSelected()
);
} else {
HtmlRenderer.renderString(
r.getText(), g, txtX, txtY, txtW, txtH, r.getFont(), foreground, r.getRenderStyle(), true
);
}
}
示例8: paintIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public void paintIcon(InstancePainter painter) {
Icon icon;
if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
icon = ICON_SHAPED;
} else {
icon = ICON_RECTANGULAR;
}
icon.paintIcon(painter.getDestination(), painter.getGraphics(), 2, 2);
}
示例9: mergeIcons
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Utility method merging 2 icons.
*/
private static Icon mergeIcons(Icon icon1, Icon icon2, int x, int y, Component c) {
int w = 0, h = 0;
if (icon1 != null) {
w = icon1.getIconWidth();
h = icon1.getIconHeight();
}
if (icon2 != null) {
w = icon2.getIconWidth() + x > w ? icon2.getIconWidth() + x : w;
h = icon2.getIconHeight() + y > h ? icon2.getIconHeight() + y : h;
}
if (w < 1) w = 16;
if (h < 1) h = 16;
java.awt.image.ColorModel model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment ().
getDefaultScreenDevice ().getDefaultConfiguration ().
getColorModel (java.awt.Transparency.BITMASK);
java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage (model,
model.createCompatibleWritableRaster (w, h), model.isAlphaPremultiplied (), null);
java.awt.Graphics g = buffImage.createGraphics ();
if (icon1 != null) {
icon1.paintIcon(c, g, 0, 0);
}
if (icon2 != null) {
icon2.paintIcon(c, g, x, y);
}
g.dispose();
return new ImageIcon(buffImage);
}
示例10: checkIfIconOk
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Checks colors on coordinates X,Y of the icon and compares them
* to expectedResult.
*/
private void checkIfIconOk(Icon icon, Component c, int pixelX, int pixelY, int[] expectedResult, String nameOfIcon) {
BufferedImage bufImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
icon.paintIcon(c, bufImg.getGraphics(), 0, 0);
int[] res = bufImg.getData().getPixel(pixelX, pixelY, (int[])null);
log("Icon height is " + icon.getIconHeight());
log("Icon width is " + icon.getIconWidth());
for (int i = 0; i < res.length; i++) {
// Huh, Ugly hack. the sparc returns a fuzzy values +/- 1 unit e.g. 254 for Black instead of 255 as other OSs do
// this hack doesn't broken the functionality which should testing
assertTrue(nameOfIcon + ": Color of the ["+pixelX+","+pixelY+"] pixel is " + res[i] + ", expected was " + expectedResult[i], Math.abs(res[i] - expectedResult[i]) < 10);
}
}
示例11: paintIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public final void paintIcon(InstancePainter painter) {
Graphics g = painter.getGraphics();
g.setColor(Color.black);
if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
Icon iconRect = getIconRectangular();
if (iconRect != null) {
iconRect.paintIcon(painter.getDestination(), g, 2, 2);
} else {
paintIconRectangular(painter);
}
} else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
Icon iconDin = getIconDin40700();
if (iconDin != null) {
iconDin.paintIcon(painter.getDestination(), g, 2, 2);
} else {
paintIconRectangular(painter);
}
} else {
Icon iconShaped = getIconShaped();
if (iconShaped != null) {
iconShaped.paintIcon(painter.getDestination(), g, 2, 2);
} else {
paintIconShaped(painter);
}
}
}
示例12: paintCloseButton
import javax.swing.Icon; //导入方法依赖的package包/类
private void paintCloseButton(Graphics g, JComponent c) {
if (((AbstractTabCellRenderer) c).isShowCloseButton()) {
Rectangle r = new Rectangle(0, 0, c.getWidth(), c.getHeight());
Rectangle cbRect = new Rectangle();
getCloseButtonRectangle((JComponent) c, cbRect, r);
//paint close button
String iconPath = findIconPath( (NimbusEditorTabCellRenderer)c );
Icon icon = TabControlButtonFactory.getIcon( iconPath );
icon.paintIcon(c, g, cbRect.x, cbRect.y);
}
}
示例13: getScaledImageIcon
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Scale the given icon to the given dimensions
*
* @param label
* @return
*/
public ImageIcon getScaledImageIcon(Icon icon, int width, int height) {
if (icon != null) {
BufferedImage buf = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics graphics = buf.createGraphics();
icon.paintIcon(null, graphics, 0, 0);
graphics.dispose();
Image dimg = buf.getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(dimg);
}
return null;
}
示例14: writeIcon
import javax.swing.Icon; //导入方法依赖的package包/类
private static void writeIcon(OutputStream target, Project source) throws IOException {
Icon icon = ProjectUtils.getInformation(source).getIcon();
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
icon.paintIcon(new JLabel(), g, 0, 0);
g.dispose();
ImageIO.write(image, "png", target);
}
示例15: paintIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public void paintIcon(InstancePainter painter) {
Object type = painter.getAttributeValue(ATTR_TYPE);
Icon icon = type == TYPE_N ? ICON_N : ICON_P;
icon.paintIcon(painter.getDestination(), painter.getGraphics(), 2, 2);
}