View Javadoc

1   /*
2    * Copyright 2004-2005 Andreas Andreou
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.tapfx.components.machobar;
17  
18  import org.apache.hivemind.ApplicationRuntimeException;
19  import org.apache.tapestry.IRequestCycle;
20  import org.apache.tapestry.IAsset;
21  
22  import net.sf.tapfx.components.TapFXBaseComponent;
23  
24  /***
25   * @author Andreas Andreou
26   * @version $Id: MachoItem.java,v 1.3 2005/11/07 03:27:15 andyhot Exp $
27   */
28  public abstract class MachoItem extends TapFXBaseComponent
29  {
30      private int index;
31      private int size;
32      private String prefix;
33  
34      public int getIndex()
35      {
36          return index;
37      }
38  
39      public String getPrefix()
40      {
41          return prefix;
42      }
43  
44      public int getSize()
45      {
46          return size;
47      }
48  
49      public abstract IAsset getIcon();
50      public abstract IAsset getLargeIcon();
51  
52      protected void setupComponent(IRequestCycle cycle)
53      {
54          MachoBar bar = MachoBar.getMachoBar(cycle);
55          if (null == bar)
56          {
57              throw new ApplicationRuntimeException("You need to provide a @MachoBar around this component!");
58          }
59          prefix = bar.getIdPrefix();
60          size = bar.getSize();
61  
62          String imageURL = getIcon().buildURL(cycle);
63          bar.addAssetUrl(imageURL);
64          // if a large icon was specified, use it,
65          // otherwise use the normal icon
66          if (getLargeIcon() != null)
67          {
68              imageURL = getLargeIcon().buildURL(cycle);
69          }        
70          bar.addLargeAssetUrl(imageURL);
71          // get the index of the item (after having added the images url)
72          index = bar.getItemsCount();
73      }
74  }