/** Creates a new instance of SmilePicker */
  public SmilePicker(Display display, MessageEdit me, int caretPos) {
    super(display);
    this.me = me;
    this.caretPos = caretPos;

    il = SmilesIcons.getInstance();
    // #ifdef SMILES
    // #         smileTable=MessageParser.getInstance().getSmileTable();
    // #endif
    imgCnt = smileTable.size();
    // il.getCount();

    imgWidth = il.getWidth() + 2 * CURSOR_HOFFSET;
    lineHeight = il.getHeight() + 2 * CURSOR_VOFFSET;

    xCnt = getWidth() / imgWidth;

    lines = imgCnt / xCnt;
    xLastCnt = imgCnt - lines * xCnt;
    if (xLastCnt > 0) lines++;
    else xLastCnt = xCnt;

    addCommand(cmdOK);
    addCommand(cmdBack);
    setCommandListener(this);
  }
Exemplo n.º 2
0
 public static ImageList createImageList(String resName) {
   ImageList images = (ImageList) files.get(resName);
   if (null != images) {
     return images;
   }
   ImageList icons = new ImageList();
   try {
     icons.load(resName, -1, -1);
   } catch (Exception ignored) {
   }
   files.put(resName, icons);
   return icons;
 }
Exemplo n.º 3
0
  public void load(String resName, int width, int height) throws IOException {
    Image resImage = ImageList.loadImage(resName);
    if (null == resImage) {
      return;
    }
    int imgHeight = resImage.getHeight();
    int imgWidth = resImage.getWidth();

    if (width == -1) {
      width = Math.min(imgHeight, imgWidth);
    }
    if (height == -1) {
      height = imgHeight;
    }

    this.width = width;
    this.height = height;

    Vector<Icon> tmpIcons = new Vector<Icon>();
    for (int y = 0; y < imgHeight; y += height) {
      for (int x = 0; x < imgWidth; x += width) {
        Icon icon = new Icon(resImage, x, y, width, height);
        tmpIcons.addElement(icon);
      }
    }
    icons = new Icon[tmpIcons.size()];
    tmpIcons.copyInto(icons);
  }
 public int getVHeight() {
   if (height != 0) return height;
   for (int i = 0; i < elementCount; i++) {
     int h = 0;
     Object o = elementData[i];
     if (o == null) continue;
     if (o instanceof String) {
       h = font.getHeight();
     } else if (o instanceof Integer) {
       int a = ((Integer) o).intValue();
       if ((a & 0xff000000) == 0) {
         h = imageList.getWidth();
       }
     } else if (o instanceof VirtualElement) {
       h = ((VirtualElement) o).getVHeight();
     }
     if (h > height) height = h;
   }
   return height;
 }
  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }
 private int imgWidth() {
   return (imageList == null) ? 0 : imageList.getWidth();
 }
 private int imgHeight() {
   return (imageList == null) ? 0 : imageList.getHeight();
 }
 public void drawItem(Graphics g, int ofs, boolean selected, boolean drawsec) {
   int max = (lineIndex == lines - 1) ? xLastCnt : xCnt;
   for (int i = 0; i < max; i++) {
     il.drawImage(g, lineIndex * xCnt + i, i * imgWidth + CURSOR_HOFFSET, CURSOR_VOFFSET);
   }
 };