| 33 | import Client.Config; |
| 34 | |
| 35 | abstract public class IconTextElement implements VirtualElement { |
| 36 | public Config cf = Config.getInstance(); |
| 37 | |
| 38 | int itemHeight; |
| 39 | int imageYOfs; |
| 40 | protected int fontYOfs; |
| 41 | |
| 42 | protected ImageList il; |
| 43 | private int ilImageSize=0; |
| 44 | |
| 45 | public IconTextElement(ImageList il) { |
| 46 | super(); |
| 47 | this.il=il; |
| 48 | if (il!=null) ilImageSize=il.getHeight(); |
| 49 | } |
| 50 | |
| 51 | private boolean selectable=true; |
| 52 | public boolean isSelectable() { return selectable; } |
| 53 | |
| 54 | public boolean handleEvent(int keyCode) { return false; } |
| 55 | |
| 56 | public int getImageIndex() { return -1; }; |
| 57 | |
| 58 | public String getImgAlt() { return ""; }; // if image not loaded |
| 59 | |
| 60 | public int getFontIndex() { return 0; } |
| 61 | |
| 62 | public Font getFont() { |
| 63 | return FontCache.getFont((getFontIndex()==0)?false:true, FontCache.roster); |
| 64 | } |
| 65 | |
| 66 | public void drawItem(Graphics g, int ofs, boolean sel) { |
| 67 | g.setFont(getFont()); |
| 68 | |
| 69 | String str = toString(); |
| 70 | int offset = 4; |
| 71 | |
| 72 | if (il != null) { |
| 73 | if (getImageIndex() != -1) { |
| 74 | offset += ilImageSize; |
| 75 | il.drawImage(g, getImageIndex(), 2, imageYOfs); |
| 76 | } |
| 77 | if (!il.isLoaded) { |
| 78 | str = getImgAlt() + toString(); |
| 79 | } |
| 80 | } |
| 81 | g.clipRect(offset, 0, g.getClipWidth(), itemHeight); |
| 82 | |
| 83 | if (str != null) { |
| 84 | FontCache.drawString(g, str, offset - ofs, fontYOfs, Graphics.TOP | Graphics.LEFT); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | public int getVWidth(){ |
| 89 | return getFont().stringWidth(toString())+ilImageSize+4; |
| 90 | } |
| 91 | |
| 92 | public int getVHeight() { |
nothing calls this directly
no test coverage detected