testitemlfimplldointernallayout.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 693 行 · 第 1/3 页

JAVA
693
字号
/* *    * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import com.sun.midp.i3test.*;/** * This test is designed to test Chameleon's ItemLFImpl.lDoInternalLayout() * routine only. It does not test label size or content size calculations. * It tests label location and content location calculations. *  * Internal layout for all items is handled in ItemLFImpl. * lDoInternalLayout() is given label and content sizes and available * width, height, it should place label and content in correct place. * Here is what to expect: * If label and content are empty, both bounds are set to 0. * If label is empty, content is given as much space as it needs but *   not more than available. * If content is empty, label is given as much space as it needs but *   not more than available. * If label is a single line label (its height <= label font height) then *   there is an attempt to fit label, content and 3 pixel padding between *   them on the same line. * Otherwise content is placed under label with 2 pixel horizontal padding  *   in between. *   * Furthermore, if label and content are on the same line than *   shorter part (label or content) is vertically centered  *   against the taller one (content or label). *  * Then if there is extra space (item can fit in smaller size than * it is given) then the space is distributed based on the layout * primitives set. * * ItemLFImpl and Item area abstract in javax.microedition.lcdui. * We extend them to test lDoInternalLayout(). */public class TestItemLFImplLDoInternalLayout extends TestCase {    public void runTests() {        // no extra space, null label, null content        declare("test1");        checkLayout(new TestItemLFImpl(0, 0,  // labelSize                                       0, 0,  // contentSize                                       0, 0,  // itemSize                                       10),   // label font height                    0, 0,  // checked label location                    0, 0); // checked content location        // no extra space, null label, non null content        declare("test2");        checkLayout(new TestItemLFImpl(0, 0,      // labelSize                                       100, 100,  // contentSize                                       100, 100,  // itemSize                                       10),   // label font height                    0, 0,  // checked label location                    0, 0); // checked content location        // no extra space, non null label, null content        declare("test3");        checkLayout(new TestItemLFImpl(100, 100,  // labelSize                                       0, 0,      // contentSize                                       100, 100,  // itemSize                                       10),   // label font height                    0, 0,  // checked label location                    0, 0); // checked content location        // no extra space, non null label, non null content;        // label and content are on the same line;        // label height > content height        declare("test4");        checkLayout(new TestItemLFImpl(50, 20,  // labelSize                                       50, 10,  // contentSize                                       103, 20, // itemSize                                       20),     // labelHeight to be single ln                     0, 0,  // checked label location                    53, 5); // checked content location        // no extra space, non null label, non null content        // label and content are on the same line        // label height < content height        declare("test5");        checkLayout(new TestItemLFImpl(50, 10,  // labelSize                                       50, 20,  // contentSize                                       103, 20, // itemSize                                       10),     // labelHeight to be single ln                     0, 5,  // checked label location                    53, 0); // checked content location        // no extra space, non null label, non null content        // label and content are on different lines (due to width)        // label width < content width        declare("test6");        checkLayout(new TestItemLFImpl(30, 10,  // labelSize                                       50, 20,  // contentSize                                       50, 32, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 12); // checked content location        // no extra space, non null label, non null content        // label and content are on different lines (due to multiline label)        // label width < content width        declare("test7");        checkLayout(new TestItemLFImpl(30, 20,  // labelSize                                       50, 30,  // contentSize                                       50, 52, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 22); // checked content location        // no extra space, non null label, non null content        // label and content are on different lines (due to width)        // label width > content width        declare("test8");        checkLayout(new TestItemLFImpl(50, 10,  // labelSize                                       30, 20,  // contentSize                                       50, 32, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 12); // checked content location        // no extra space, non null label, non null content        // label and content are on different lines (due to mulitline label)        // label width > content width        declare("test9");        checkLayout(new TestItemLFImpl(50, 20,  // labelSize                                       30, 30,  // contentSize                                       50, 52, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 22); // checked content location        // ************ more space HORIZONTALLY  **************************        // ****************************************************************        // there IS extra space horizontally,         // LAYOUT_CENTER and LAYOUT_RIGHT are NOT set        // null label, non null content        declare("test10");        checkLayout(new TestItemLFImpl(0, 0,    // labelSize                                       50, 50,  // contentSize                                       100, 50, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 0); // checked content location                // there IS extra space horizontally,         // LAYOUT_CENTER and LAYOUT_RIGHT are NOT set        // non null label, null content        declare("test11");        checkLayout(new TestItemLFImpl(50, 50,   // labelSize                                       0, 0,     // contentSize                                       100, 50, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 0); // checked content location        // there IS extra space horizontally,         // LAYOUT_CENTER and LAYOUT_RIGHT are NOT set        // non null label, non null content        // label and content on the same line;        // label height > content height        declare("test11");        checkLayout(new TestItemLFImpl(47, 20,    // labelSize                                       50, 10,  // contentSize                                       200, 20, // itemSize                                       20),     // labelHeight to be single ln                     0, 0,  // checked label location                    50, 5); // checked content location        // there IS extra space horizontally,         // LAYOUT_CENTER and LAYOUT_RIGHT are NOT set        // non null label, non null content        // label and content on the same line        // label height < content height        declare("test12");        checkLayout(new TestItemLFImpl(47, 10,    // labelSize                                       50, 20,  // contentSize                                       200, 20, // itemSize                                       10),    // labelHeight to be single ln                     0, 5,  // checked label location                    50, 0); // checked content location        // there IS extra space horizontally,         // LAYOUT_CENTER and LAYOUT_RIGHT are NOT set        // non null label, non null content        // label and content on different lines        // label width < content width        declare("test13");        checkLayout(new TestItemLFImpl(30, 20,  // labelSize                                       50, 20,  // contentSize                                       100, 32, // itemSize                                       10),     // labelHeight to be single ln                     0, 0,  // checked label location                    0, 22); // checked content location        // there IS extra space horizontally, 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?