1 /*
2 * Created on Oct 23, 2003
3 */
4 package portaview.model;
5
6 import java.net.InetAddress;
7 import java.util.Observable;
8 import java.util.Observer;
9
10 import portaview.Registry;
11 import portaview.RemoteUpdateController;
12
13 /***
14 * Represents a PortaView. This main contains two parts. One is the SlideSettings,
15 * which controls the settings. The other is the image associated with the PortaView.
16 * @author William Lee
17 */
18 public class PortaViewModel extends NameModel implements Observer
19 {
20 public static final String IMAGE_CHANGED = "image_changed";
21 public static final String SETTINGS_CHANGED = "settings_changed";
22
23 private InetAddress inetAddress = null;
24 private AlbumModel album = null;
25 private SlideSettings slideSettings = null;
26 private PortaViewImageModel imageModel = null;
27 private RemoteUpdateController remoteController = null;
28
29 public PortaViewModel(String name, InetAddress address, AlbumModel album)
30 {
31 super(name);
32 this.inetAddress = address;
33 this.album = album;
34 this.slideSettings = new SlideSettings();
35 this.imageModel = new PortaViewImageModel(this);
36 // attach a controller so we can update the remove PortaView.
37 remoteController = new RemoteUpdateController(this);
38 }
39
40 /***
41 * Moves to the next slide.
42 *
43 */
44 public void nextSlide()
45 {
46 slideSettings.setIndex(
47 (slideSettings.getIndex() + 1) % slideSettings.getTotal());
48 setSlideSettings(slideSettings);
49 }
50
51 /***
52 * Moves to the previous slide.
53 *
54 */
55 public void prevSlide()
56 {
57 if (slideSettings.getIndex() == 0)
58 {
59 slideSettings.setIndex(slideSettings.getTotal() - 1);
60 }
61 else
62 {
63 slideSettings.setIndex((slideSettings.getIndex() - 1) % slideSettings.getTotal());
64 }
65 // we need to do this in order to notify the change.
66 setSlideSettings(slideSettings);
67 }
68
69 /***
70 * Sets the PortaView pause play.
71 *
72 */
73 public void play()
74 {
75 slideSettings.setPlayState(SlideSettings.PLAY);
76 setSlideSettings(slideSettings);
77 }
78
79 /***
80 * Sets the PortaView to pause.
81 */
82 public void pause()
83 {
84 slideSettings.setPlayState(SlideSettings.PAUSE);
85 setSlideSettings(slideSettings);
86 }
87
88 /***
89 * @return the internet address for a given PortaView
90 */
91 public InetAddress getInetAddress()
92 {
93 return inetAddress;
94 }
95
96 /***
97 * Sets the Ip for the PortaView.
98 * @param address the internet address for the PortaView
99 */
100 public void setInetAddress(InetAddress address)
101 {
102 inetAddress = address;
103 }
104
105 /***
106 * @return the AlbumModel that thie PortaView is showing.
107 */
108 public AlbumModel getAlbum()
109 {
110 return album;
111 }
112
113 /***
114 * @param model the album model.
115 */
116 public void setAlbum(AlbumModel model)
117 {
118 album = model;
119 }
120 /***
121 * @return the slide settings, which contain most internal state for a PortaView.
122 */
123 public SlideSettings getSlideSettings()
124 {
125 return slideSettings;
126 }
127
128 /***
129 * Sets the slide settings and notify all the observers about the change.
130 * @param slideSettings slide settings to set.
131 */
132 public void setSlideSettings(SlideSettings slideSettings)
133 {
134 this.slideSettings = slideSettings;
135 // Notify the observers for changes.
136 setChanged();
137 notifyObservers(SETTINGS_CHANGED);
138 }
139
140 /***
141 * @return the image model
142 */
143 public PortaViewImageModel getImageModel()
144 {
145 return imageModel;
146 }
147
148 /***
149 * Sets the image model.
150 * @param imageModel model to set.
151 */
152 public void setImageModel(PortaViewImageModel imageModel)
153 {
154 this.imageModel = imageModel;
155 }
156
157 /***
158 * Underlying models have changed. Notify the observers to this displayer model.
159 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
160 */
161 public void update(Observable arg0, Object arg1)
162 {
163 setChanged();
164 notifyObservers(arg1);
165 }
166
167 /***
168 * Update this portaview model with the remote portaview's state.
169 *
170 */
171 public void updateRemote()
172 {
173 Registry.getClient().updatePortaViewModel(this);
174 }
175 }
This page was automatically generated by Maven