1 /*
2 * Created on Oct 29, 2003
3 *
4 * To change the template for this generated file go to
5 * Window>Preferences>Java>Code Generation>Code and Comments
6 */
7 package portaview.view;
8
9 import java.awt.Dimension;
10 import java.awt.Image;
11 import java.awt.event.MouseEvent;
12
13 import javax.swing.TransferHandler;
14 import javax.swing.event.MouseInputAdapter;
15
16 import portaview.Registry;
17 import portaview.dnd.AlbumTransferHandler;
18 import portaview.model.AlbumModel;
19
20 /***
21 * The album icons that represents the album.
22 * @author William Lee
23 */
24 public class AlbumIconView extends IconView
25 {
26 private AlbumModel albumModel = null;
27 private static final int WIDTH = 120;
28 private static final int HEIGHT = 100;
29
30 /***
31 * Constrcts an icon view.
32 * @param amodel the album model associated with this view.
33 * @param apanel the panel that list out the icons of this icon view.
34 */
35 public AlbumIconView(AlbumModel amodel, AlbumPanel apanel)
36 {
37 super(apanel);
38 this.albumModel = amodel;
39 this.albumModel.addObserver(this);
40 installDnD();
41 setPreferredSize(new Dimension(WIDTH, HEIGHT));
42 refresh();
43 }
44
45 /***
46 * Adds the drag and drop support for the icon view.
47 */
48 protected void installDnD()
49 {
50 setTransferHandler(new AlbumTransferHandler());
51 DnDStarter starter = new DnDStarter();
52 addMouseListener(starter);
53 addMouseMotionListener(starter);
54 }
55
56 class DnDStarter extends MouseInputAdapter
57 {
58 public void mousePressed(MouseEvent e)
59 {
60 TransferHandler th = AlbumIconView.this.getTransferHandler();
61 th.exportAsDrag(AlbumIconView.this, e, TransferHandler.COPY);
62 }
63 }
64
65 /***
66 * Returns the icon image.
67 * @see portaview.view.IconView#getIconImage()
68 */
69 public Image getIconImage()
70 {
71 return albumModel.getImage();
72 }
73
74 /***
75 * Returns the icon label.
76 * @see portaview.view.IconView#getIconLabel()
77 */
78 public String getIconLabel()
79 {
80 String[] lbl =
81 {
82 albumModel.getName(),
83 "(" + albumModel.getPhotos().size() + " pictures)" };
84 return (getMultiLineLabel(lbl));
85 }
86 /***
87 * @return the album model
88 */
89 public AlbumModel getAlbumModel()
90 {
91 return albumModel;
92 }
93
94 /***
95 * Sets the album model.
96 * @param model model to set.
97 */
98 public void setAlbumModel(AlbumModel model)
99 {
100 albumModel = model;
101 }
102
103 /***
104 * Returns true if the displayer is not active
105 * @see portaview.view.IconView#needRefresh()
106 */
107 protected boolean needRefresh()
108 {
109 return (!Registry.getMainApplication().isDisplayActive());
110 }
111
112 /***
113 * Sets the tool tips information
114 */
115 protected void doRefresh()
116 {
117 String tipText =
118 "Album "
119 + albumModel.getName()
120 + " has "
121 + albumModel.getPhotos().size()
122 + " photos";
123 setToolTipText(tipText);
124 }
125
126 }
This page was automatically generated by Maven