1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.tapfx.components.machobar;
17
18 import org.apache.tapestry.IRequestCycle;
19 import org.apache.tapestry.Tapestry;
20 import org.apache.tapestry.IAsset;
21
22 import net.sf.tapfx.components.TapFXBaseComponent;
23
24 /***
25 * @author Andreas Andreou
26 */
27 public abstract class MachoItem extends TapFXBaseComponent
28 {
29 private int index;
30 private int size;
31 private String prefix;
32
33 public int getIndex()
34 {
35 return index;
36 }
37
38 public String getPrefix()
39 {
40 return prefix;
41 }
42
43 public int getSize()
44 {
45 return size;
46 }
47
48 public abstract IAsset getIcon();
49 public abstract IAsset getLargeIcon();
50
51 protected void setupComponent(IRequestCycle cycle)
52 {
53 MachoBar bar = MachoBar.getMachoBar(cycle);
54 if (null == bar)
55 {
56 throw Tapestry.createRequiredParameterException(this,
57 "You need to provide a @MachoBar around this component!");
58 }
59 prefix = bar.getPrefix();
60 size = bar.getItemSize();
61
62 String imageURL = getIcon().buildURL(cycle);
63 bar.addAssetUrl(imageURL);
64 if (getLargeIcon() != null)
65 {
66 imageURL = getLargeIcon().buildURL(cycle);
67 }
68 bar.addLargeAssetUrl(imageURL);
69
70 index = bar.getItemsCount();
71 }
72 }