uitest.he

来自「维信SDK文档。源码要求为至少5个C或Java源码」· HE 代码 · 共 1,117 行 · 第 1/3 页

HE
1,117
字号
    boolean myKeyHandler(Component source, int op, int code)    {      int w, int h = getScreenSize();      Flow flow = new Flow(getStyle("sliding.bg"));      Picture pic = new Picture(getStyle("sliding.text"), getImage("bubble_genie.png"));      pic.setPreferredSize(-100, -100);      flow.add(pic);      Shell view = getViewShell(flow);            if (op != KEY_RELEASED) {        if (code >= '1' && code <= '9') {          //push new view on the screen          pushShell(view);                    //and then slide it out using selected transformation          switch (code) {            case '1':            slideOut(w, h, w, h, view);            break;                          case '2':            slideOut(0, h, w, h, view);            break;            case '3':            slideOut(w*-1, h, w, h, view);            break;              case '4':            slideOut(w, 0, w, h, view);            break;                        case '5':            //just push it, no sliding            break;            case '6':            slideOut(w*-1, 0, w, h, view);            break;                        case '7':            slideOut(w, h*-1, w, h, view);            break;            case '8':            slideOut(0, h*-1, w, h, view);            break;              case '9':            slideOut(w*-1, h*-1, w, h, view);            break;          }          //we consume this key-event          return true;        }      }      return false;    }        return shell;  }    //-----  Shell createStyles()  {    Style style = getStyle("form.choice.item");    Flow content = new Flow(getStyle("default"));    content.setPreferredSize(-100, -100);        content.add(createHeaderText("List of Label components with different styles"));        addLabel("styles.1", "Style label 1");    addLabel("styles.2", "Style label 2");    addLabel("styles.3", "Style label 3");    addLabel("styles.4", "Style label 4");    addLabel("styles.5", "Style label 5");    addLabel("styles.6", "Style label 6");    addLabel("styles.7", "Style label 7");    addLabel("styles.8", "Style label 8");        Flow addLabel(String style, String text)    {      Label label = new Label(getStyle(style), text);      label.setPreferredWidth(-100);      //label.setFlags(VISIBLE|FOCUSABLE);            Flow flow = new Flow(getStyle("styles.container"));      flow.setPreferredWidth(-100);      flow.setFlags(VISIBLE|LINEFEED|FOCUSABLE);      flow.add(label);      content.add(flow);      return flow;    }        return getViewShell(content);  }    //-----    Shell createTable()  {    //get length of letter "m" to be used as measure for cell-widths    final int FONT_LENGTH = getStyle("table.cell").font(0).stringWidth("m");    final int CELL_WIDTH = FONT_LENGTH*6;    final int MARGIN_WIDTH = FONT_LENGTH*3;    final int MAX_COLS = int('Z')-int('A');    final int COLS = 10;    final int ROWS = 10;        List cells = new List();        Flow content = new Flow(getStyle("default"));    content.setPreferredSize(-100, -100);        content.add(createHeaderText("Spreadsheet Table"));        //create headers    addHeader("", MARGIN_WIDTH, false);    for (int x=0; x<COLS; x++) {      String name = char(int('A') + (x % MAX_COLS)); //A, B, C, ...      addHeader(name, CELL_WIDTH, x+1 == COLS);    }    //Cells could be easily accessed from a Map, but using    //cell name as key wouldn't work because 2-char long    //alphanumeric hashes do collide        //create cells    for (int y=0; y<ROWS; y++) {      addHeader(String(y+1), MARGIN_WIDTH, false);      for (int x=0; x<COLS; x++) {        Input c = addCell("", CELL_WIDTH, x+1 == COLS);        cells.add(c);      }    }        //generate some content    getCell("A3").setText("Foo");    getCell("B3").setText("Bar");    getCell("J10").setText("=)");        void addHeader(String text, int width, boolean linefeed)    {      Label l = new Label(getStyle("table.header"), text);      l.setPreferredWidth(width);      //when adding components to flow, if there is no LINEFEED or      //WRAP flag set, they will be all on same line      l.setFlags(linefeed? VISIBLE|LINEFEED : VISIBLE);      content.add(l);    }    Input addCell(String text, int width, boolean linefeed)    {      Input l = new Input(getStyle("table.cell"), text, ANY);      l.setPreferredWidth(width);      l.setFlags(linefeed? VISIBLE|LINEFEED|FOCUSABLE : VISIBLE|FOCUSABLE);      content.add(l);      return l;    }        Input getCell(String name)    {      int col = int(name.charAt(0))-int('A');      int row = int(name.substring(1, name.length()))-1;      int offset = row*COLS+col;            return (offset <= cells.size())? cells[offset] : null;    }    return getViewShell(content);  }  //-----      Shell createTicker()  {    Flow content = new Flow(getStyle("default"));    content.setPreferredSize(-100, -100);        content.add(createHeaderText("Scrollin' Tickers"));        add(new Ticker(getStyle("ticker.loop.blurred"), "Looping Ticker text (while not focused)"));    add(new Ticker(getStyle("ticker.loop.focused"), "Looping Ticker text (while focused)"));    add(new Label(getStyle("ticker.normal"), "Non-scrolling Label text that hopefully is too long to fit on line"));    add(new Ticker(getStyle("ticker.bounce.blurred"), "Bouncing Ticker text (while not focused) [There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain...]"));    add(new Ticker(getStyle("ticker.bounce.focused"), "Bouncing Ticker text (while focused) [There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain...]"));        void add(Component c)    {      c.setPreferredWidth(-100);      c.setFlags(VISIBLE|FOCUSABLE|LINEFEED);      content.add(c);    }    return getViewShell(content);  }    //------------------------------------------------------------------------  //------------------------------------------------------------------------  //------------------------------------------------------------------------    //Shared functions    Shell getViewShell(Component content)  {    final Shell shell = new Shell(content);    shell.setStyle(getStyle("maxi"));    shell.setSoftKeyHandler(defaultSoftKeyHandler);    shell.setActionHandler(defaultActionHandler);    return shell;  }      MenuItem defaultSoftKeyHandler(final Shell shell, final Component focused, final int key)   {    if (key == SOFTKEY_BACK) {      return BACK;    }    return null;  }  void defaultActionHandler(final Shell shell, final Component source, final int action)   {    if (action == CMD_BACK) {      popShell(shell);    }  }      Text createHeaderText(String name)  {    Text text = new Text(getStyle("header"), name);    text.setPreferredWidth(-100);    text.setFlags(VISIBLE|LINEFEED);    return text;  }      Label createMainLabel(String name, Viewable viewable)  {    Label label = new Label(getStyle("mainLabel"), name);    label.setPreferredWidth(-100);    label.setFlags(VISIBLE|FOCUSABLE|LINEFEED);    label.setData(viewable);    label.setAction(CMD_SELECT);    return label;  }    // Widget stuff  Component createElement(String viewName,                          String elementName,                          Style style,                          Object context)  {    if (elementName.equals("maxi")) {      return new Scrollable(style, createMain());    }    return null;  }    Flow createMain()  {    Flow content = new Flow(getStyle("default"));    content.setPreferredSize(-100, -100);    String header = "UI Examples";        content.add(createHeaderText(header));        //function references to example implementing function    //that implements Viewable -type, passed as parameter    content.add(createMainLabel("Bubble", createBubble));    content.add(createMainLabel("Camera", createCamera));    content.add(createMainLabel("Canvas", createCanvas));    content.add(createMainLabel("Form", createForm));    content.add(createMainLabel("Input", createInput));    content.add(createMainLabel("List", createList));    content.add(createMainLabel("Menu", createMenu));    content.add(createMainLabel("Picture", createPicture));    content.add(createMainLabel("Progress", createProgress));    content.add(createMainLabel("Prompt", createPrompt));    content.add(createMainLabel("Sliding", createSliding));    content.add(createMainLabel("Styles", createStyles));    content.add(createMainLabel("Table", createTable));    content.add(createMainLabel("Ticker", createTicker));    return content;  }      void startWidget()  {    setMinimizedView(createMinimizedView("viewMini", getStyle("white")));  }  Shell openWidget()  {    Flow view = createMaximizedView("viewMaxi", getStyle("maxi"));    Shell shell = new Shell(view);    return shell;  }    //Soft key callback, normally would handle all soft key-calls,  //in this case it handles only Shells which don't have  //soft key callback set, and that is the main list created above    MenuItem getSoftKey(Shell shell, Component focused, int key)  {    if (key == SOFTKEY_OK) {      return null;          } else if (key == SOFTKEY_BACK) {      return BACK;    }    return null;  }      //Widget's generic event-callback, normally all  //events occured on Shells on this widget would   //come here, but they are captured on each example  //using inner callback-functions    void actionPerformed(Shell shell, Component source, int action)  {    switch(action)    {      case CMD_SELECT:      {        //Label from main menu was clicked, take        //function-reference and invoke it.        Object data = source.getData();        if (data != null) {          final Shell s = Viewable(data)->();          //If it returned a shell, push that shell          //to view stack.          if (s != null) {            pushShell(s);          }        }      }      break;            case CMD_BACK:      {        popShell(shell);      }      break;    }  }  }

⌨️ 快捷键说明

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