| Home >> All >> com >> flexstor >> common >> [ awt Javadoc ] |
Source code: com/flexstor/common/awt/LogoCanvas.java
1 /* 2 * LogoCanvas.java 3 * 4 * Copyright $Date: 2003/08/11 02:22:32 $ FLEXSTOR.net Inc. 5 * 6 * This work is licensed for use and distribution under license terms found at 7 * http://www.flexstor.org/license.html 8 * 9 */ 10 11 package com.flexstor.common.awt; 12 13 import java.awt.Canvas; 14 import java.awt.Graphics; 15 import java.awt.Image; 16 import java.awt.MediaTracker; 17 import java.io.FileNotFoundException; 18 import java.net.MalformedURLException; 19 import java.net.URL; 20 21 public class LogoCanvas 22 extends Canvas 23 { 24 private Image imgLogo = null; 25 26 public LogoCanvas ( String sPath ) 27 throws FileNotFoundException 28 { 29 try 30 { 31 imgLogo = getToolkit().getImage ( new URL(sPath) ); 32 33 if (imgLogo == null) 34 return; 35 36 MediaTracker tracker = new MediaTracker(this); 37 tracker.addImage(imgLogo, 0); 38 39 try 40 { 41 tracker.waitForID(0); 42 } 43 catch(InterruptedException e) { } 44 45 if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) 46 throw new FileNotFoundException ( "Error loading " + sPath ); 47 else 48 setSize(imgLogo.getWidth(null), imgLogo.getHeight(null)); 49 } 50 catch ( MalformedURLException m ) 51 { 52 throw new FileNotFoundException ( "Error loading " + sPath ); 53 } 54 } 55 56 public void paint(Graphics g) 57 { 58 if (imgLogo != null) 59 { 60 g.drawImage(imgLogo, 61 Math.max(0, (getSize().width - imgLogo.getWidth(null)) / 2), 62 Math.max(0, (getSize().height - imgLogo.getHeight(null)) / 2), 63 this); 64 } 65 } 66 }