summaryrefslogtreecommitdiff
path: root/java/ImageProcessing/framework/Icon.java
blob: eed91ed55c7ceac05052dfacf1a571c81a9b5d47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package imaging.framework;

import java.awt.*;
import java.applet.*;
import java.net.*;

public class Icon
{
  protected Image icon_;
  protected Dimension iconSize_;
  
  Icon()
  {
    super();
  }
  
  Icon(String file_name, Component comp)
  {
    this.icon_ = Toolkit.getDefaultToolkit().getImage(file_name);
    this.loadImage(comp);
  }
  
  Icon(Image icon_image, Component comp)
  {
    this.icon_ = icon_image;
    this.loadImage(comp);
  }

  Icon(String url, Applet applet) throws MalformedURLException
  {
    this.icon_ = applet.getImage(new URL(url));
    loadImage(applet);
  }
  
  public void drawIcon(Graphics g, int x, int y, Component comp)
  {
    g.drawImage(this.icon_, x, y, comp);
  }
  
  private void loadImage(Component comp)
  {
    try
      {
	MediaTracker tracker = new MediaTracker(comp);
	tracker.addImage(this.icon_, 0);
        tracker.waitForID(0);

	this.iconSize_ = new Dimension(this.icon_.getWidth(comp), this.icon_.getHeight(comp));
      }
    catch (InterruptedException excp)
      {
        System.err.println("Icon::getIcon image failed to load");
      }
  }

  public Dimension iconSize()
  {
    return this.iconSize_;
  }

  public Image getIconImage()
  {
    return this.icon_;
  }

}