📄 choicegroup.java
字号:
private void checkFlag(boolean[] flag) { if (flag == null) { throw new NullPointerException(); } if (flag.length < numOfEls) { throw new IllegalArgumentException(); } } /** * Image to represent an unselected checkbox */ private static final Image CKBX_OFF_IMG; /** * Image to represent a selected checkbox */ private static final Image CKBX_ON_IMG; /** * Width of a checkbox image (both selected and unselected) */ private static final int CKBX_WIDTH = 10; /** * Image to represent an unselected radio button */ private static final Image RD_OFF_IMG; /** * Image to represent a selected radio button */ private static final Image RD_ON_IMG; /** * Width of a radio button image (both selected and unselected) */ private static final int RD_WIDTH = 11; static { /** * Byte array used to create an unselected checkbox */ byte ckbx_off[] = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x02, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x3b, (byte)0x00, (byte)0xf4, (byte)0x8b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x50, (byte)0x4c, (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xbb, (byte)0xbb, (byte)0xbb, (byte)0xc7, (byte)0x4b, (byte)0xdf, (byte)0xf8, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1e, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78, (byte)0xda, (byte)0x63, (byte)0x60, (byte)0x60, (byte)0x60, (byte)0x60, (byte)0x0c, (byte)0x65, (byte)0xf8, (byte)0xcd, (byte)0xe0, (byte)0xc0, (byte)0x20, (byte)0xc0, (byte)0xc4, (byte)0xc0, (byte)0xc0, (byte)0x80, (byte)0x0b, (byte)0x33, (byte)0x86, (byte)0x32, (byte)0xfc, (byte)0x06, (byte)0x00, (byte)0x3f, (byte)0x74, (byte)0x03, (byte)0x01, (byte)0x35, (byte)0x94, (byte)0x27, (byte)0xe6, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82, }; /** * Byte array used to create a selected checkbox */ byte ckbx_on[] = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x02, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x3b, (byte)0x00, (byte)0xf4, (byte)0x8b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0c, (byte)0x50, (byte)0x4c, (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xbb, (byte)0xbb, (byte)0xbb, (byte)0x6a, (byte)0x6a, (byte)0x6a, (byte)0x02, (byte)0x02, (byte)0x02, (byte)0x6a, (byte)0x99, (byte)0x0e, (byte)0xd1, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x35, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78, (byte)0xda, (byte)0x63, (byte)0x60, (byte)0x60, (byte)0x7c, (byte)0xc0, (byte)0xf0, (byte)0xff, (byte)0xb3, (byte)0x03, (byte)0xd3, (byte)0x41, (byte)0x91, (byte)0x0f, (byte)0x4c, (byte)0x0c, (byte)0x6c, (byte)0x0c, (byte)0x4c, (byte)0x0c, (byte)0xfc, (byte)0x0c, (byte)0x4c, (byte)0x0c, (byte)0x12, (byte)0x0c, (byte)0x4c, (byte)0xbc, (byte)0x7f, (byte)0x18, (byte)0x98, (byte)0x7e, (byte)0x2d, (byte)0x60, (byte)0x60, (byte)0xf9, (byte)0xf5, (byte)0x93, (byte)0x81, (byte)0xe9, (byte)0xbf, (byte)0x03, (byte)0x03, (byte)0xe3, (byte)0x7f, (byte)0x86, (byte)0x8f, (byte)0x00, (byte)0x05, (byte)0x25, (byte)0x0c, (byte)0xde, (byte)0x01, (byte)0x9d, (byte)0xad, (byte)0x64, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82, }; /** * Byte array used to create an unselected radio button */ byte rad_off[] = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x02, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xc2, (byte)0x9f, (byte)0xb5, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x50, (byte)0x4c, (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xbb, (byte)0xbb, (byte)0xbb, (byte)0x6a, (byte)0x6a, (byte)0x6a, (byte)0xd4, (byte)0x0d, (byte)0xff, (byte)0xe8, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2a, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78, (byte)0xda, (byte)0x63, (byte)0x60, (byte)0x5a, (byte)0xc5, (byte)0xc0, (byte)0x20, (byte)0xc1, (byte)0x30, (byte)0x81, (byte)0x41, (byte)0x81, (byte)0x41, (byte)0x81, (byte)0x29, (byte)0x81, (byte)0xe1, (byte)0x05, (byte)0x13, (byte)0x03, (byte)0x03, (byte)0x03, (byte)0x32, (byte)0x66, (byte)0x50, (byte)0x60, (byte)0x50, (byte)0x60, (byte)0xfa, (byte)0xc1, (byte)0x50, (byte)0xc0, (byte)0xc0, (byte)0xb4, (byte)0x8a, (byte)0x01, (byte)0x00, (byte)0x71, (byte)0x18, (byte)0x05, (byte)0x3d, (byte)0x49, (byte)0xbc, (byte)0x9c, (byte)0x62, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82, }; /** * Byte array used to create a selected radio button */ byte rad_on[] = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x02, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xc2, (byte)0x9f, (byte)0xb5, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0c, (byte)0x50, (byte)0x4c, (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xbb, (byte)0xbb, (byte)0xbb, (byte)0x6a, (byte)0x6a, (byte)0x6a, (byte)0x02, (byte)0x02, (byte)0x02, (byte)0x6a, (byte)0x99, (byte)0x0e, (byte)0xd1, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78, (byte)0xda, (byte)0x05, (byte)0xc1, (byte)0x41, (byte)0x0d, (byte)0x00, (byte)0x20, (byte)0x0c, (byte)0x04, (byte)0xc1, (byte)0xed, (byte)0xf5, (byte)0x8b, (byte)0x01, (byte)0x12, (byte)0x44, (byte)0x9c, (byte)0x0a, (byte)0x34, (byte)0x13, (byte)0x5e, (byte)0x48, (byte)0x40, (byte)0x11, (byte)0x65, (byte)0x86, (byte)0x2c, (byte)0xd4, (byte)0xe3, (byte)0x62, (byte)0xcc, (byte)0x59, (byte)0x4d, (byte)0x9a, (byte)0x28, (byte)0x02, (byte)0x55, (byte)0xa1, (byte)0xb7, (byte)0xc1, (byte)0x98, (byte)0xc1, (byte)0x25, (byte)0x8b, (byte)0x0f, (byte)0xd8, (byte)0x77, (byte)0x0a, (byte)0x29, (byte)0x4e, (byte)0x1a, (byte)0xb1, (byte)0x3b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82, }; CKBX_OFF_IMG = Image.createImage(ckbx_off, 0, ckbx_off.length); CKBX_ON_IMG = Image.createImage(ckbx_on, 0, ckbx_on.length); RD_OFF_IMG = Image.createImage(rad_off, 0, rad_off.length); RD_ON_IMG = Image.createImage(rad_on, 0, rad_on.length); } /** * This class handles the layout for a choice group item, which consists * of an image (optionally) and a string. When the image is less the half * the display width, the string appears on the same line as the image. * When the image is more than half the display width, the string appears * below the image, indented by 3 white spaces. * * This class extends the StringLayout class to allow the superclass to * handle the string layout. */ class IaSLayout extends StringLayout { /** * Image of the element */ private Image img; /** * Height and width of the image of the element */ private int imgHeight, imgWidth; /** * This is the total height and width of the item. This is different * from the sum of the image and string height and width, because * depending on the width of the image, they could be side-by-side, * or on-top of each other. */ private int layoutedHeight, layoutedWidth; /** * Construct a new IaSLayout * * @param str The string part of the element * @param img The image part of the element * @param font The Font used to render the string of the element * @param offset The offset of the text from the image of the element */ IaSLayout(String str, Image img, Font font, boolean offset) { super(str, font); this.img = img; if (img != null) { imgHeight = img.getHeight(); // pad the image with same spaces before the string imgWidth = img.getWidth() + 2; } setOffset(offset); } /** * Get the image for this element * * @return Image The image to render for this element */ Image getImage() { return img; } /** * Get the width of this element * * @return int The width of this element */ public int getWidth() { return layoutedWidth; } /** * Set the allowable width for this element * * @param w The allowable width for this element * @return int The height required to display this element * given the allowable width */ public int setWidth(int w) { if ((layoutedWidth == w) || (w < 0)) { return layoutedHeight; } layoutedWidth = w; if (imgWidth > (w / 2)) { // height of the item is the sum of the image and // string heights if the image is too wide. layoutedHeight = super.setWidth(w - offsetWidth) + imgHeight; } else { // return the taller of the image or the text int superHeight = super.setWidth(w - imgWidth); layoutedHeight = imgHeight; if (superHeight > layoutedHeight) { layoutedHeight = superHeight; } } return layoutedHeight; } /** * Get the height of this element * * @return int The height of this element */ public int getHeight() { return layoutedHeight; } /** * Paint this element * * @param g The Graphics context to paint to * @param eraseBgrnd A flag to erase the background before painting * @param inverted A flag to signal the element should be painted in * inverted colors */ public void paint(Graphics g, boolean eraseBgrnd, boolean inverted) { // clear the background if (eraseBgrnd) { g.setColor(inverted ? Display.BG_H_COLOR : Display.ERASE_COLOR); g.fillRect(0, 0, layoutedWidth, layoutedHeight); } if (img != null) { // center the image vertically in a line, only // when the image is less than a line height, and there is // only one line of text. if (imgWidth < (Display.WIDTH / 2) && layoutedHeight <= lineHeight) { g.drawImage(img, 0, lineHeight / 2, Graphics.VCENTER | Graphics.LEFT); } else { g.drawImage(img, 0, 0, Graphics.TOP | Graphics.LEFT); } } // depending on the width of the image, the string appears to the // right or below (and indented) of the image. int tx = 0; int ty = 0; if (imgWidth > (Display.WIDTH / 2)) { ty = imgHeight; tx = offsetWidth; } else { tx = imgWidth; } g.translate(tx, ty); super.paint(g, false, inverted); g.translate(-tx, -ty); } } // end of IaStringLayout}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -