1 /*
2 * Created on Oct 29, 2003
3 */
4 package portaview.model;
5
6 import java.awt.Image;
7 import java.net.URL;
8
9 import org.apache.xmlrpc.AsyncCallback;
10
11 import portaview.Log;
12 import portaview.util.ImageUtils;
13
14 /***
15 * Abstract implementation of an image model.
16 * @author William Lee
17 */
18 public abstract class ImageModel
19 extends DomainModel
20 implements AsyncCallback
21 {
22 private Image image = null;
23
24 /***
25 * Constructs an ImageModel associated with no image.
26 */
27 public ImageModel()
28 {
29 this(null);
30 }
31
32 /***
33 * Constructs an ImageModel associated with a given image.
34 * @param img Image object.
35 */
36 public ImageModel(Image img)
37 {
38 this.image = img;
39 }
40
41 /***
42 * @return the image
43 */
44 public synchronized Image getImage()
45 {
46 return image;
47 }
48
49 /***
50 * Sets the image
51 * @param image the image to set.
52 */
53 public synchronized void setImage(Image image)
54 {
55 this.image = image;
56 }
57
58 /***
59 * Handles the result for the async call to master when
60 * retrieving the picture.
61 *
62 * @see org.apache.xmlrpc.AsyncCallback#handleResult(java.lang.Object, java.net.URL, java.lang.String)
63 */
64 public synchronized void handleResult(
65 Object result,
66 URL url,
67 String method)
68 {
69 byte[] img = (byte[]) result;
70 this.image = ImageUtils.getImage(img);
71 // Now, if we get the image, go ahead and notify the view changes.
72 setChanged();
73 notifyObservers();
74 }
75
76 /***
77 * Handles the error for the async call to the
78 * master when retrieving the picture.
79 * @see org.apache.xmlrpc.AsyncCallback#handleError(java.lang.Exception, java.net.URL, java.lang.String)
80 */
81 public synchronized void handleError(
82 Exception exception,
83 URL url,
84 String method)
85 {
86 Log.debug(
87 "Error loading image Master url: "
88 + url.toString()
89 + " Exception: "
90 + exception);
91 exception.printStackTrace();
92
93 }
94
95 }
This page was automatically generated by Maven