Example usage for java.awt Component Component

List of usage examples for java.awt Component Component

Introduction

In this page you can find the example usage for java.awt Component Component.

Prototype

protected Component() 

Source Link

Document

Constructs a new component.

Usage

From source file:Main.java

public static Insets getBorderInsetsForNoComponent(Border border) {
    // in java 7 calling getBorderInsets on TitleBorder with a null component throws NPE,
    // so let call that with a dummy component
    if (border instanceof TitledBorder) {
        return border.getBorderInsets(new Component() {
        });/*from  ww w. ja v  a 2 s . c  o  m*/
    }

    return border.getBorderInsets(null);
}

From source file:com.tomtom.speedtools.json.ImageSerializer.java

@Nonnull
private static BufferedImage convertToBufferedImage(@Nonnull final Image image) throws IOException {
    assert image != null;

    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }//from   www  .j  av a2  s .  c o  m

    /**
     * Load the image in the background and wait
     * until is is downloaded.
     */
    final MediaTracker tracker = new MediaTracker(new Component() {
        // Empty.
    });
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (final InterruptedException e) {
        throw new IOException(e.getMessage(), e);
    }

    /**
     * Create a buffered image with the right dimensions.
     */
    final BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    /**
     * Draw the image in the buffer and return it as base64 data.
     */
    final Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}

From source file:J3dSwingFrame.java

/**
 * Set the texture on our goemetry/*ww w  . ja va 2 s  . co m*/
 * <P>
 * Always specified as a URL so that we may fetch it from anywhere.
 * 
 * @param url
 *            The url to the image.
 */
public void setTexture(URL url) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image src_img = tk.createImage(url);
    BufferedImage buf_img = null;

    if (!(src_img instanceof BufferedImage)) {
        // create a component anonymous inner class to give us the image
        // observer we need to get the width and height of the source image.
        Component obs = new Component() {
        };

        int width = src_img.getWidth(obs);
        int height = src_img.getHeight(obs);

        // construct the buffered image from the source data.
        buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics g = buf_img.getGraphics();
        g.drawImage(src_img, 0, 0, null);
        g.dispose();
    } else
        buf_img = (BufferedImage) src_img;

    src_img.flush();

    ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img);

    texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight());

    appearance.setTexture(texture);

    buf_img.flush();
}