📄 fakecustomitem.java
字号:
} } //////////////////////////// DEFAULT IMPLEMENTATION OF ABSTRACT CUSTOM ITEM METHODS /////////////// /** * Default implementation of javax.microedition.lcdui.CustomItem method. * * @return the minimum content width in pixels */ protected final int getMinContentWidth() { return this.contentWidth; } /** * Default implementation of javax.microedition.lcdui.CustomItem method. * * @return the minimum content height in pixels */ protected final int getMinContentHeight() { return this.contentHeight; } /** * Default implementation of javax.microedition.lcdui.CustomItem method. * * @param height the tentative content height in pixels, or -1 if a tentative height has not been computed. * J2ME Polish will always specify -1 as the height. * @return the preferred content width in pixels */ protected final int getPrefContentWidth(int height) { return this.contentWidth; } /** * Default implementation of javax.microedition.lcdui.CustomItem method. * * @param width the tentative content width in pixels, or -1 if a tentative width has not been computed * @return the preferred content height in pixels */ protected final int getPrefContentHeight(int width) { return this.contentWidth; } /** * Default implementation of javax.microedition.lcdui.CustomItem method. * * @param g the Graphics object to be used for rendering the item * @param w current width of the item in pixels * @param h current height of the item in pixels */ protected final void paint( Graphics g, int w, int h) { // ignore } ////////////// END DEFAULT IMPLEMENTATION OF CUSTOM ITEM METHODS ///////////////////////////// /** * Sets the label of the <code>Item</code>. If <code>label</code> * is <code>null</code>, specifies that this item has no label. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param label - the label string * @throws IllegalStateException - if this Item is contained within an Alert * @see #getLabel() */ public void setLabel( String label) { if (this.label == null) { this.label = new StringItem( null, label, this.labelStyle ); this.label.parent = this.parent; } else { this.label.setText( label ); } if (this.isInitialised) { this.isInitialised = false; repaint(); } } /** * Gets the label of this <code>Item</code> object. * * @return the label string * @see #setLabel(java.lang.String) */ public String getLabel() { if (this.label == null) { return null; } else { return this.label.getText(); } } /** * Retrieves the label item that is used by this item. * * @return the item or null when no item is used. */ public Item getLabelItem() { return this.label; } /** * Gets the layout directives used for placing the item. * * @return a combination of layout directive values * @see #setLayout(int) * @since MIDP 2.0 */ public int getLayout() { return this.layout; } /** * Sets the layout directives for this item. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param layout - a combination of layout directive values for this item * @throws IllegalArgumentException - if the value of layout is not a bit-wise OR combination of layout directives * @throws IllegalStateException - if this Item is contained within an Alert * @see #getLayout() * @since MIDP 2.0 */ public void setLayout(int layout) { this.layout = layout; } /** * Returns the appearance mode of this <code>Item</code>. * See <a href="Item.html#appearance">Appearance Modes</a>. * * @return the appearance mode value, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON * @since MIDP 2.0 */ public int getAppearanceMode() { return this.appearanceMode; } /** * Sets the appearance mode of this item. * * @param appearanceMode the mode value, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON */ public void setAppearanceMode( int appearanceMode ) { this.appearanceMode = appearanceMode; } /** * Retrieves the style of this item. * * @return the style of this item. */ public Style getStyle() { return this.style; } /** * Sets the style of this item. * * @param style the new style for this item. * @throws NullPointerException when style is null */ public void setStyle( Style style ) { //#debug System.out.println("setting style - with background: " + (style.background != null)); this.isInitialised = false; this.isStyleInitialised = true; this.style = style; if (style != StyleSheet.defaultStyle) { this.layout = style.layout; } // horizontal styles: center -> right -> left if ( ( this.layout & LAYOUT_CENTER ) == LAYOUT_CENTER ) { this.isLayoutCenter = true; this.isLayoutRight = false; } else { this.isLayoutCenter = false; if ( ( this.layout & LAYOUT_RIGHT ) == LAYOUT_RIGHT ) { this.isLayoutRight = true; } else { this.isLayoutRight = false; } } //System.out.println(" style [" + style.name + "]: right: " + this.isLayoutRight + " center: " + this.isLayoutCenter); // vertical styles: vcenter -> bottom -> top // expanding layouts: if ( ( this.layout & LAYOUT_EXPAND ) == LAYOUT_EXPAND ) { this.isLayoutExpand = true; } else { this.isLayoutExpand = false; } this.background = style.background; this.border = style.border; if (this.border != null) { this.borderWidth = this.border.borderWidth; } else if (this.background != null){ this.borderWidth = this.background.borderWidth; } else { this.borderWidth = 0; } this.paddingLeft = style.paddingLeft; this.paddingRight = style.paddingRight; this.paddingTop = style.paddingTop; this.paddingBottom = style.paddingBottom; this.paddingVertical = style.paddingVertical; this.paddingHorizontal = style.paddingHorizontal; this.marginLeft = style.marginLeft; this.marginRight = style.marginRight; this.marginTop = style.marginTop; this.marginBottom = style.marginBottom; //#ifdef polish.css.label-style Style labStyle = (Style) style.getObjectProperty("label-style"); if (labStyle != null) { this.labelStyle = labStyle; } else { this.labelStyle = StyleSheet.labelStyle; } //#else this.labelStyle = StyleSheet.labelStyle; //#endif if (this.label != null) { this.label.setStyle( this.labelStyle ); } //#ifdef polish.css.min-width Integer minWidthInt = style.getIntProperty("min-width"); if (minWidthInt != null) { this.minimumWidth = minWidthInt.intValue(); } //#endif //#ifdef polish.css.max-width Integer maxWidthInt = style.getIntProperty("max-width"); if (maxWidthInt != null) { this.maximumWidth = maxWidthInt.intValue(); } //#endif //#ifdef polish.css.min-height Integer minHeightInt = style.getIntProperty("min-height"); if (minHeightInt != null) { this.minimumHeight = minHeightInt.intValue(); } //#endif //#ifdef polish.css.max-height Integer maxHeightInt = style.getIntProperty("max-height"); if (maxHeightInt != null) { this.maximumHeight = maxHeightInt.intValue(); } //#endif //#ifdef polish.css.focused-style //Object object = style.getObjectProperty("focused-style"); //if (object != null) { // System.out.println("focused-type: " + object.getClass().getName()); //} Style focused = (Style) style.getObjectProperty("focused-style"); if (focused != null) { this.focusedStyle = focused;// if (this instanceof ChoiceGroup) {// System.out.println("Setting focused style for choicegroup!");// } } //#endif //#if polish.css.colspan Integer colSpanInt = style.getIntProperty("colspan"); if ( colSpanInt != null ) { this.colSpan = colSpanInt.intValue(); } //#endif //#if polish.css.include-label Boolean includeLabelBool = style.getBooleanProperty("include-label"); if (includeLabelBool != null) { this.includeLabel = includeLabelBool.booleanValue(); } //#endif } /** * Retrieves the complete width of this item. * Note that the width can dynamically change, * e.g. when a StringItem gets a new text. * * @param firstLineWidth the maximum width of the first line * @param lineWidth the maximum width of any following lines * @return the complete width of this item. */ public int getItemWidth( int firstLineWidth, int lineWidth ) { if (!this.isInitialised || this.itemWidth > lineWidth) { init( firstLineWidth, lineWidth ); } return this.itemWidth; } /** * Retrieves the complete height of this item. * Note that the width can dynamically change, * e.g. when a new style is set. * * @param firstLineWidth the maximum width of the first line * @param lineWidth the maximum width of any following lines * @return the complete heigth of this item. */ public int getItemHeight( int firstLineWidth, int lineWidth ) { if (!this.isInitialised || this.itemWidth > lineWidth) { init( firstLineWidth, lineWidth ); } return this.itemHeight; } /** * Adds a context sensitive <code>Command</code> to the item. * The semantic type of * <code>Command</code> should be <code>ITEM</code>. The implementation * will present the command * only when the item is active, for example, highlighted. * <p> * If the added command is already in the item (tested by comparing the * object references), the method has no effect. If the item is * actually visible on the display, and this call affects the set of * visible commands, the implementation should update the display as soon * as it is feasible to do so. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param cmd the command to be added * @throws IllegalStateException if this Item is contained within an Alert * @throws NullPointerException if cmd is null * @since MIDP 2.0 */ public void addCommand( Command cmd) { if (this.commands == null) { this.commands = new ArrayList(); } if (!this.commands.contains( cmd )) { this.commands.add(cmd); if (this.appearanceMode == PLAIN) { this.appearanceMode = HYPERLINK; } if (this.isFocused) { Screen scr = getScreen(); if (scr != null) { scr.addCommand( cmd ); } } if (this.isInitialised) { repaint(); } } } // not needed for signature, since CustomItem also defines this method.// /**// * Repaints the screen to which this item belongs to.// * Subclasses can call this method whenever their contents// * have changed and they need an immediate refresh. // */// protected void repaint() {// //System.out.println("repaint called by class " + getClass().getName() );// if (this.parent instanceof Container) {// ((Container) this.parent).isInitialised = false;// }// Screen scr = getScreen();// if (scr != null && scr == StyleSheet.currentScreen) {// scr.repaint();// }// } /** * Requests that this item and all its parents are to be re-initialised at the next repainting. * All parents of this item are notified, too. * This method should be called when an item changes its size more than * usual. * When the item already has been initialised, a repaint() is requested, too. */ protected void requestInit() { //System.out.println("requestInit called by class " + getClass().getName() + " - screen.class=" + getScreen().getClass().getName() ); Item p = this.parent; while ( p != null) { p.isInitialised = false; p = p.parent; } if (this.isInitialised) { this.isInitialised = false; repaint(); } } /** * Retrieves the screen to which this item belongs to. * * @return either the corresponding screen or null when no screen could be found */ public Screen getScreen() { if (this.screen != null) { return this.screen; } else if (this.parent != null) { Item p = this.parent; while (p.parent != null) { p = p.parent; } return p.screen; } else { return null; } } /** * Removes the context sensitive command from item. If the command is not * in the <code>Item</code> (tested by comparing the object references), * the method has * no effect. If the <code>Item</code> is actually visible on the display, * and this call * affects the set of visible commands, the implementation should update * the display as soon as it is feasible to do so. * * * If the command to be removed happens to be the default command, * the command is removed and the default command on this Item is * set to <code>null</code>. * * The following code: * <CODE> <pre> * // Command c is the default command on Item item * item.removeCommand(c); * </pre> </CODE> * is equivalent to the following code: * <CODE> <pre> * // Command c is the default command on Item item * item.setDefaultCommand(null); * item.removeCommand(c); * </pre> </CODE> *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -