1 /*
2 * Created on Oct 27, 2003
3 */
4 package portaview.view;
5
6 import java.awt.Dimension;
7 import java.awt.Image;
8 import java.awt.dnd.DropTarget;
9 import java.awt.dnd.DropTargetDragEvent;
10 import java.awt.dnd.DropTargetDropEvent;
11 import java.awt.dnd.DropTargetEvent;
12 import java.awt.dnd.DropTargetListener;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.image.BufferedImage;
16 import java.net.URL;
17
18 import javax.swing.TransferHandler;
19
20 import portaview.Log;
21 import portaview.Registry;
22 import portaview.dnd.AlbumTransferHandler;
23 import portaview.model.PortaViewModel;
24 import portaview.model.SlideSettings;
25 import portaview.util.ImageUtils;
26
27 /***
28 * Represents a PortaView icon listed on the left.
29 *
30 * @author William Lee
31 */
32 public class PortaViewView extends IconView implements DropTargetListener
33 {
34 private PortaViewModel portaViewModel = null;
35 public static Image emptyImage = null;
36 private static final int WIDTH = 150;
37 private static final int HEIGHT = 150;
38
39 public PortaViewView(PortaViewModel pview, PortaViewPanel pvp)
40 {
41 super(pvp);
42 this.portaViewModel = pview;
43 this.portaViewModel.addObserver(this);
44 installDnD();
45 installListener();
46 initEmptyImage();
47 setPreferredSize(new Dimension(WIDTH, HEIGHT));
48 }
49
50 /***
51 * Sets the tool tips information
52 */
53 protected void doRefresh()
54 {
55 SlideSettings ss = portaViewModel.getSlideSettings();
56 if (ss.getTotal() == 0)
57 setToolTipText("No album is showing here.");
58 else
59 {
60 String tipText =
61 portaViewModel.getName()
62 + " (Album: "
63 + ss.getSlide()
64 + " "
65 + (ss.getIndex() + 1)
66 + " of "
67 + ss.getTotal()
68 + ")";
69 if (ss.getPlayState() == SlideSettings.PAUSE)
70 {
71 tipText = tipText + " [Paused]";
72 }
73 else
74 {
75 tipText =
76 tipText
77 + " [Playing, refreshing every "
78 + ss.getSpeed()
79 + " seconds ]";
80 }
81 setToolTipText(tipText);
82 }
83 }
84
85 /***
86 * Installs the listener for the button click event.
87 *
88 */
89 protected void installListener()
90 {
91 // if the button is clicked, then we want to change the Previewer
92 // to change its controller.
93 addActionListener(new ActionListener()
94 {
95
96 public void actionPerformed(ActionEvent e)
97 {
98 PortaViewView pvv = (PortaViewView) e.getSource();
99 Registry.getMainApplication().getPreview().setModel(
100 pvv.getPortaViewModel());
101 }
102 });
103 }
104
105 protected void initEmptyImage()
106 {
107 if (emptyImage == null)
108 {
109 URL url =
110 PortaViewView.class.getResource("/portaview/images/empty.jpg");
111 try
112 {
113 Log.debug("Loading empty image: " + url);
114 Image fullSize = ImageUtils.getImage(url);
115 emptyImage =
116 ImageUtils.getBufferedImageInFrame(
117 ImageUtils.getBufferedImage(fullSize, this),
118 DEFAULT_WIDTH,
119 DEFAULT_HEIGHT,
120 this);
121 }
122 catch (Exception e)
123 {
124 e.printStackTrace();
125 }
126 }
127 }
128
129 /***
130 * Adds the drag and drop support for the icon view.
131 *
132 */
133 protected void installDnD()
134 {
135 setDropTarget(new DropTarget(this, this));
136 setTransferHandler(new AlbumTransferHandler());
137 }
138
139 /***
140 * @return the PortaView model
141 */
142 public PortaViewModel getPortaViewModel()
143 {
144 return portaViewModel;
145 }
146
147 /***
148 * Sets the model.
149 * @param model model to set.
150 */
151 public void setPortaViewModel(PortaViewModel model)
152 {
153 portaViewModel = model;
154 }
155
156 /***
157 * Returns the icon image.
158 * @see portaview.view.IconView#getIconImage()
159 */
160 protected Image getIconImage()
161 {
162 Image img = portaViewModel.getImageModel().getImage();
163 if (img == null)
164 return emptyImage;
165 try
166 {
167 return ImageUtils.getBufferedImageInFrame(
168 ImageUtils.getBufferedImage(img, this),
169 DEFAULT_WIDTH,
170 DEFAULT_HEIGHT,
171 this);
172 }
173 catch (Exception e)
174 {
175 e.printStackTrace();
176 }
177 return emptyImage;
178 }
179 /***
180 * Returns the icon label.
181 * @see portaview.view.IconView#getIconLabel()
182 */
183 protected String getIconLabel()
184 {
185 String name = null;
186 /*
187 if (portaViewModel
188 .equals(Registry.getMainApplication().getThisPortaViewModel()))
189 name = "( " + portaViewModel.getName() + " )";
190 else
191 name = portaViewModel.getName();
192 */
193 name = portaViewModel.getName();
194 String aname = null;
195 SlideSettings ss = portaViewModel.getSlideSettings();
196 if (ss.getSlide().equals(""))
197 {
198 aname = "No Album";
199 String[] lbls = { name, aname };
200 return getMultiLineLabel(lbls);
201 }
202 else
203 {
204 aname = "" + ss.getSlide();
205 }
206 String pic = " [" + (ss.getIndex() + 1) + "/" + ss.getTotal() + "]";
207 aname = aname + pic;
208 String state = null;
209 if (ss.getPlayState() == SlideSettings.PAUSE)
210 {
211 state = "- Paused -";
212 }
213 else
214 {
215 state = "- Playing -";
216 }
217 String[] lbls = { name, aname, state };
218 return getMultiLineLabel(lbls);
219 }
220
221 /***
222 * Does nothing.
223 * @see java.awt.dnd.DropTargetListener#dragEnter(java.awt.dnd.DropTargetDragEvent)
224 */
225 public void dragEnter(DropTargetDragEvent dtde)
226 {
227 }
228
229 /***
230 * Does nothing
231 * @see java.awt.dnd.DropTargetListener#dragOver(java.awt.dnd.DropTargetDragEvent)
232 */
233 public void dragOver(DropTargetDragEvent dtde)
234 {
235 }
236
237 /***
238 * Does nothing
239 * @see java.awt.dnd.DropTargetListener#dropActionChanged(java.awt.dnd.DropTargetDragEvent)
240 */
241 public void dropActionChanged(DropTargetDragEvent dtde)
242 {
243
244 }
245
246 /***
247 * Perform the drop by setting the slide settings.
248 * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
249 */
250 public void drop(DropTargetDropEvent dtde)
251 {
252 TransferHandler th = this.getTransferHandler();
253 th.importData(this, dtde.getTransferable());
254 }
255
256 /***
257 * Does nothing
258 * @see java.awt.dnd.DropTargetListener#dragExit(java.awt.dnd.DropTargetEvent)
259 */
260 public void dragExit(DropTargetEvent dte)
261 {
262 }
263
264 /***
265 * Returns true only if the display is not active.
266 * @see portaview.view.IconView#needRefresh()
267 */
268 protected boolean needRefresh()
269 {
270 return (!Registry.getMainApplication().isDisplayActive());
271 }
272
273 /***
274 * Process the image in order to add a border to the icon.
275 *
276 * @author William Lee
277 */
278 protected Image postProcessIcon(Image img)
279 {
280 ImageUtils.drawBorder(portaViewModel, (BufferedImage) img);
281 return img;
282 }
283
284 }
This page was automatically generated by Maven