Search in sources :

Example 6 with Toolkit

use of java.awt.Toolkit in project adempiere by adempiere.

the class Env method getImage.

//  getParent
/**************************************************************************
	 *  Get Image with File name
	 *
	 *  @param fileNameInImageDir full file name in imgaes folder (e.g. Bean16.gif)
	 *  @return image
	 */
public static Image getImage(String fileNameInImageDir) {
    URL url = Adempiere.class.getResource("images/" + fileNameInImageDir);
    if (url == null) {
        s_log.log(Level.SEVERE, "Not found: " + fileNameInImageDir);
        return null;
    }
    Toolkit tk = Toolkit.getDefaultToolkit();
    return tk.getImage(url);
}
Also used : Toolkit(java.awt.Toolkit) URL(java.net.URL)

Example 7 with Toolkit

use of java.awt.Toolkit in project adempiere by adempiere.

the class MPrintTableFormat method getImage.

//	get
/**
	 * 	Get the Image
	 *	@return image
	 */
public Image getImage() {
    if (m_image != null) {
        return m_image;
    }
    //
    if (isImageIsAttached()) {
        MAttachment attachment = MAttachment.get(getCtx(), Table_ID, get_ID());
        if (attachment == null) {
            log.log(Level.WARNING, "No Attachment - ID=" + get_ID());
            return null;
        }
        if (attachment.getEntryCount() != 1) {
            log.log(Level.WARNING, "Need just 1 Attachment Entry = " + attachment.getEntryCount());
            return null;
        }
        byte[] imageData = attachment.getEntryData(0);
        if (imageData != null) {
            m_image = Toolkit.getDefaultToolkit().createImage(imageData);
        }
        if (m_image != null) {
            log.fine(attachment.getEntryName(0) + " - Size=" + imageData.length);
        } else {
            log.log(Level.WARNING, attachment.getEntryName(0) + " - not loaded (must be gif or jpg) - ID=" + get_ID());
        }
    } else if (getImageURL() != null) {
        URL url;
        try {
            url = new URL(getImageURL());
            Toolkit tk = Toolkit.getDefaultToolkit();
            m_image = tk.getImage(url);
        } catch (MalformedURLException e) {
            log.log(Level.WARNING, "Malformed URL - " + getImageURL(), e);
        }
    }
    return m_image;
}
Also used : MAttachment(org.compiere.model.MAttachment) MalformedURLException(java.net.MalformedURLException) Toolkit(java.awt.Toolkit) URL(java.net.URL)

Example 8 with Toolkit

use of java.awt.Toolkit in project adempiere by adempiere.

the class Adempiere method getImageLogoSmall.

//  getImage16
/**
	 *  Get 28*15 Logo Image.
	 *  @param hr high resolution
	 *  @return Image Icon
	 */
public static Image getImageLogoSmall(boolean hr) {
    if (s_image48x15 == null) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        URL url = null;
        if (hr)
            url = org.compiere.Adempiere.class.getResource(s_file48x15HR);
        else
            url = org.compiere.Adempiere.class.getResource(s_file48x15);
        //	System.out.println(url);
        if (url == null)
            return null;
        s_image48x15 = tk.getImage(url);
    }
    return s_image48x15;
}
Also used : Toolkit(java.awt.Toolkit) URL(java.net.URL)

Example 9 with Toolkit

use of java.awt.Toolkit in project adempiere by adempiere.

the class PrintElement method waitForLoad.

//	imageUpdate
/**
	 * 	Wait until Image is loaded.
	 * 	@param image image
	 * 	@return true if loaded
	 */
public boolean waitForLoad(Image image) {
    long start = System.currentTimeMillis();
    Thread.yield();
    int count = 0;
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        while (//	ImageObserver calls imageUpdate
        !toolkit.prepareImage(image, -1, -1, this)) {
            //	Timeout
            if (//	about 20+ sec overall
            count > 1000) {
                log.severe(this + " - Timeout - " + (System.currentTimeMillis() - start) + "ms - #" + count);
                return false;
            }
            try {
                if (count < 10)
                    Thread.sleep(10);
                else if (count < 100)
                    Thread.sleep(15);
                else
                    Thread.sleep(20);
            } catch (InterruptedException ex) {
                log.log(Level.SEVERE, "", ex);
                break;
            }
            count++;
        }
    } catch (//	java.lang.SecurityException
    Exception e) {
        log.log(Level.SEVERE, "", e);
        return false;
    }
    if (count > 0)
        log.fine((System.currentTimeMillis() - start) + "ms - #" + count);
    return true;
}
Also used : Toolkit(java.awt.Toolkit) Point(java.awt.Point)

Example 10 with Toolkit

use of java.awt.Toolkit in project bigbluebutton by bigbluebutton.

the class WindowlessFrame method centerOnScreen.

public final void centerOnScreen() {
    Toolkit kit = mLeftBorder.getToolkit();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    Insets in = kit.getScreenInsets(gs[0].getDefaultConfiguration());
    Dimension d = kit.getScreenSize();
    int maxWidth = (d.width - in.left - in.right);
    int maxHeight = (d.height - in.top - in.bottom);
    setLocation((int) (maxWidth - mOverallSize.width) / 2, (int) (maxHeight - mOverallSize.height) / 2);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GradientPaint(java.awt.GradientPaint)

Aggregations

Toolkit (java.awt.Toolkit)93 Dimension (java.awt.Dimension)27 Point (java.awt.Point)20 Image (java.awt.Image)19 BufferedImage (java.awt.image.BufferedImage)14 URL (java.net.URL)14 GraphicsDevice (java.awt.GraphicsDevice)8 GraphicsEnvironment (java.awt.GraphicsEnvironment)7 Insets (java.awt.Insets)7 Rectangle (java.awt.Rectangle)6 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 MediaTracker (java.awt.MediaTracker)5 ImageIcon (javax.swing.ImageIcon)5 Frame (java.awt.Frame)4 Clipboard (java.awt.datatransfer.Clipboard)4 Font (java.awt.Font)3 Graphics (java.awt.Graphics)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)3 Method (java.lang.reflect.Method)3