1 2 20 21 package javax.microedition.lcdui; 22 23 import com.barteo.emulator.device.DeviceFactory; 24 25 26 public class ImageItem extends Item 27 { 28 29 public static final int LAYOUT_DEFAULT = 0; 30 public static final int LAYOUT_LEFT = 1; 31 public static final int LAYOUT_RIGHT = 2; 32 public static final int LAYOUT_CENTER = 3; 33 public static final int LAYOUT_NEWLINE_BEFORE = 0x100; 34 public static final int LAYOUT_NEWLINE_AFTER = 0x200; 35 36 Image img; 37 int layout; 38 String altText; 39 40 41 public ImageItem(String label, Image img, int layout, String altText) 42 { 43 super(label); 44 45 if (img != null && img.isMutable()) { 46 new IllegalArgumentException(); 47 } 48 49 this.img = img; 50 this.layout = layout; 51 this.altText = altText; 52 } 53 54 55 public String getAltText() 56 { 57 return altText; 58 } 59 60 61 public Image getImage() 62 { 63 return img; 64 } 65 66 67 public int getLayout() 68 { 69 return layout; 70 } 71 72 73 public void setAltText(String text) 74 { 75 altText = text; 76 } 77 78 79 public void setImage(Image img) 80 { 81 this.img = img; 82 } 83 84 85 public void setLabel(String label) 86 { 87 super.setLabel(label); 88 } 89 90 91 public void setLayout(int layout) 92 { 93 this.layout = layout; 94 } 95 96 97 int getHeight() 98 { 99 if (img == null) { 100 return super.getHeight(); 101 } else { 102 return super.getHeight() + img.getHeight(); 103 } 104 } 105 106 107 int paint(Graphics g) 108 { 109 super.paintContent(g); 110 111 if (img != null) { 112 g.translate(0, super.getHeight()); 113 if (layout == LAYOUT_DEFAULT || layout == LAYOUT_LEFT) { 114 g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP); 115 } else if (layout == LAYOUT_RIGHT) { 116 g.drawImage(img, DeviceFactory.getDevice().getDeviceDisplay().getWidth(), 0, 117 Graphics.RIGHT | Graphics.TOP); 118 } else if (layout == LAYOUT_CENTER) { 119 g.drawImage(img, DeviceFactory.getDevice().getDeviceDisplay().getWidth() / 2, 0, 120 Graphics.HCENTER | Graphics.TOP); 121 } else { 122 g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP); 123 } 124 g.translate(0, -super.getHeight()); 125 } 126 127 return getHeight(); 128 } 129 130 131 int traverse(int gameKeyCode, int top, int bottom, boolean action) 132 { 133 Font f = Font.getDefaultFont(); 134 135 if (gameKeyCode == Canvas.UP) { 136 if (top > 0) { 137 if ((top % f.getHeight()) == 0) { 138 return -f.getHeight(); 139 } else { 140 return -(top % f.getHeight()); 141 } 142 } else { 143 return Item.OUTOFITEM; 144 } 145 } 146 if (gameKeyCode == Canvas.DOWN) { 147 if (bottom < getHeight()) { 148 if (getHeight() - bottom < f.getHeight()) { 149 return getHeight() - bottom; 150 } else { 151 return f.getHeight(); 152 } 153 } else { 154 return Item.OUTOFITEM; 155 } 156 } 157 158 return 0; 159 } 160 161 } 162 | Popular Tags |