1 /*
2 * Created on Oct 6, 2003
3 * Copyright (c) 2003. All rights reserved.
4 */
5 package portaview.model;
6
7 import java.awt.Image;
8 import java.util.Observable;
9 import java.util.Observer;
10
11 import portaview.Registry;
12 import portaview.server.PortaViewClient;
13
14 /***
15 * Contains the image information within the PortaViewModel.
16 *
17 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a>
18 * @version $Id: PortaViewImageModel.java,v 1.2 2003/12/10 06:18:57 wlee Exp $
19 */
20 public class PortaViewImageModel extends ImageModel implements Observer
21 {
22 private Image image = null;
23
24 /***
25 * Used for checking whether the image has changed or not.
26 */
27 private String currSlide = null;
28 private int currIndex = 0;
29
30 /***
31 * Constructs the image model within the PortaViewModel.
32 * @param dmodel the PortaViewModel that contains this image model.
33 */
34 public PortaViewImageModel(PortaViewModel dmodel)
35 {
36 dmodel.addObserver(this);
37 addObserver(dmodel);
38 }
39
40 /***
41 * When the slide setting has changed, then it'll call this method to update the current image.
42 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
43 */
44 public void update(Observable arg0, Object arg1)
45 {
46 if (arg1 == null)
47 return;
48 if (arg1.equals(PortaViewModel.SETTINGS_CHANGED))
49 {
50 PortaViewModel dm = (PortaViewModel) arg0;
51 String arg = (String) arg1;
52 String newSlide = dm.getSlideSettings().getSlide();
53 int newIndex = dm.getSlideSettings().getIndex();
54 if (needToRenewImage(newSlide, newIndex))
55 {
56 PortaViewClient client = Registry.getClient();
57 client.getPhotoFromMaster(dm.getSlideSettings(), this);
58 }
59 }
60 }
61
62 /***
63 * Returns true if we need to renew the image.
64 * @param newSlide slide name.
65 * @param newIndex index of the picture you want to check for renewal.
66 * @return true if need renew, false otherwise.
67 */
68 private boolean needToRenewImage(String newSlide, int newIndex)
69 {
70 if (newSlide == null)
71 return false;
72 if (currSlide == null && newSlide != null)
73 return true;
74 return ((currSlide.equals(newSlide) && (newIndex == currIndex)));
75 }
76 }
This page was automatically generated by Maven