Exemple #1
0
  /**
   * Paint this window. This method should not generally be overridden by subclasses. This method
   * carefully stores the clip, translation, and color before calling into subclasses. The graphics
   * context should be translated such that it is in this window's coordinate space (0,0 is the top
   * left corner of this window).
   *
   * @param g The graphics object to use to paint this window.
   * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted
   *     to the screen
   */
  public void paint(Graphics g, CGraphicsQ refreshQ) {
    // We reset our dirty flag first. Any layers that become
    // dirty in the duration of this method will then cause it
    // to toggle back to true for the subsequent pass.
    // IMPL NOTE: when layers start to do complex animation, there will
    // likely need to be better atomic handling of the dirty state,
    // and layers becoming dirty and getting painted
    this.dirty = false;

    // Store the clip, translate, font, color
    cX = g.getClipX();
    cY = g.getClipY();
    cW = g.getClipWidth();
    cH = g.getClipHeight();

    tranX = g.getTranslateX();
    tranY = g.getTranslateY();

    font = g.getFont();
    color = g.getColor();

    // We set the basic clip to the size of this window
    g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]);

    synchronized (layers) {
      sweepAndMarkLayers();
      copyAndCleanDirtyLayers();
    }
    paintLayers(g, refreshQ);

    // We restore the original clip. The original font, color, etc.
    // have already been restored
    g.setClip(cX, cY, cW, cH);
  }
Exemple #2
0
 /** ********************************************************************** */
 public void paintComponent(Graphics g) {
   for (int i = 0; i < model.size(); i++) {
     int y = i * cell_height;
     if (y + cell_height < g.getClipY()) continue;
     else if (y > g.getClipY() + g.getClipHeight()) break;
     //
     g.translate(0, y);
     IComponent c =
         renderer.getListCellRendererComponent(
             this, model.elementAt(i), i, selection.isSelectedIndex(i), (rollover == i));
     c.setBounds(0, 0, bounds.width, cell_height);
     c.setFont(font);
     c.setEnabled(enabled);
     c.paint(g);
     g.translate(0, -y);
   }
 }
Exemple #3
0
  public void paint(Graphics g) {
    // g.setClip(0, 0, this.ui.xWForm.getWidth(), this.ui.xWForm.getWidth());
    if (inBox) {
      posX = (ui.xmlForm.frm_Width - width) / 2;
      posY = (ui.xmlForm.frm_Height - height) / 2;
    } else {
      posX = x + ui.offsetX;
      posY = y + ui.offsetY;
      /*
      if(focus){
      	if(height<=ui.xWForm.frm_Height-60)
      		if(posY+height+itemHeight-10>ui.xWForm.frm_Height-30){
      			ui.offsetY=ui.offsetY-(ui.xWForm.frm_Height/2);
      			ui.xWForm.repaint();
      		}
      }*/
      if (title != null) {
        //				System.out.println("title==="+title);
        if (posX + smallHeavryFont.stringWidth(title) > ui.xmlForm.frm_Width) {
          x = 0;
          y = posY + smallHeavryFont.getHeight() + 5;
        }
        posY = y + ui.offsetY + smallHeavryFont.getHeight() + 5;
        posX = x + ui.offsetX + 10;
      }
    }
    if (title != null) {

      g.setColor(0);
      g.setFont(smallHeavryFont);
      g.drawString(title + ":", x + ui.offsetX, y + ui.offsetY, 0);
    }
    //		if (focus) {

    /*if(items.size()==0){
    	height=0;
    }
    if(height!=0)*/
    /*int h=0;
    if(richmode){
    	h=title!=null?height-smallFont.getHeight()+5:0;
    }else{
    	h=height+smallFont.getHeight()-10;
    }*/
    ImageDiv.drawJiuGong(
        g,
        UIManager.select_bright,
        posX - 3,
        posY - 3,
        width + 10,
        title != null ? height - smallFont.getHeight() + 5 : height);

    //
    //		}
    //		g.setColor(bgTricolorR, bgTricolorG, bgTricolorB);
    //			g.setColor(125);
    //		g.fillRect(posX, posY, width, height-(title!=null?smallFont.getHeight()-5:0));
    g.setFont(DisplaySetting.TEXT_FONT);
    if ((onShowSelectedItemNum + 2) * itemHeight > height) {
      offsetY = (onShowSelectedItemNum + 2) * itemHeight - height;
    } else {
      offsetY = 0;
    }
    /*if(focus)
    if (onShowSelectedItemNum + 1 >= 0) {
    	ImageDiv.drawJiuGong(g, UIManager.connect_bg, posX, posY
    			+ (onShowSelectedItemNum + 1) * itemHeight - offsetY,
    			width, itemHeight);
    }*/
    int clipx = g.getClipX();
    int clipy = g.getClipY();
    int clipwidth = g.getClipWidth();
    int clipheight = g.getClipHeight();
    g.setClip(posX, posY, width, height);
    //		g.setColor(Attribute.);
    // g.setFont(font);
    g.setFont(smallFont);
    g.setColor(ColorAttribute.label_context);
    int length = items.size();
    for (int i = 0; i < length; i++) {
      g.setClip(posX, posY, width, height);
      if (i == onShowSelectedItemNum + 1 && focus) {
        g.setColor(0, 220, 247);
        if (posY + (onShowSelectedItemNum + 1) * itemHeight - offsetY
            > ui.xmlForm.frm_Height - 40) {
          ui.offsetY -= 20;
          ui.xmlForm.repaint();
          System.out.println("draw it");
        } else if (posY + (onShowSelectedItemNum + 1) * itemHeight - offsetY < 20) {
          ui.offsetY += 20;
          ui.xmlForm.repaint();
          System.out.println("draw it");
        }
        //				System.out.println("draw it");
      } else {
        g.setColor(0);
      }
      if (items.elementAt(i) != null) {
        g.drawString(
            items.elementAt(i).toString(),
            posX + 5 + (UIManager.select_block.getWidth() >> 2) + 2,
            posY + i * itemHeight - offsetY,
            Graphics.LEFT | Graphics.TOP);
      }
      if (!hasNonItem)
        ImageBuilder.drawSmallImage(
            g,
            UIManager.select_block,
            posX + 5,
            posY + i * itemHeight - offsetY + 2,
            (UIManager.select_block.getWidth() >> 2),
            UIManager.select_block.getHeight(),
            selector.elementAt(i).equals(new Integer(1))
                ? (UIManager.select_block.getWidth() >> 2) * 0
                : (UIManager.select_block.getWidth() >> 2) * 1,
            0);
    }
    if (inBox) {
      g.drawImage(
          UIManager.select_bright,
          posX + width - 1,
          posY + (height * (onShowSelectedItemNum + 1) / length),
          Graphics.RIGHT | Graphics.TOP);
    }
    g.setClip(clipx, clipy, clipwidth, clipheight);
    /*if(posY+ (onShowSelectedItemNum + 1)* itemHeight - offsetY>ui.xWForm.frm_Height-40){
    	ui.offsetY-=20;
    	ui.xWForm.repaint();
    }else if(posY+ (onShowSelectedItemNum + 1)* itemHeight - offsetY<20){
    	ui.offsetY+=20;
    }*/

  }
  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
  }
Exemple #5
0
  protected void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    if (_fullRepaintPending) {
      boolean design =
          _state == STATE_CHOOSE_WIDGET
              || _state == STATE_MOVE_WIDGET
              || _state == STATE_RESIZE_WIDGET;
      if (design) g.setColor(0x202060);
      else g.setColor(0);
      g.fillRect(0, 0, w, h);

      // long start = System.currentTimeMillis();
      // paint all widgets
      WidgetInfo.update();
      for (int i = 0; i < _widgets.length; i++) {
        WidgetPosition wp = _widgets[i];
        g.setClip(
            w * wp.col / _ncols,
            h * wp.row / _nrows,
            w * (wp.col + wp.ncols) / _ncols - w * wp.col / _ncols,
            h * (wp.row + wp.nrows) / _nrows - h * wp.row / _nrows);

        if (design) {
          g.setColor(0);
          g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());
        }

        try {
          wp.widget.paint(g, wp.settings);
        } catch (Exception e) {
          Log.error("Widget paint failed! widget=" + wp.widget.getName(), e);
        }
      }
      // Log.info("Widgets repaint: "+(System.currentTimeMillis()-start)+"ms");
      g.setClip(0, 0, getWidth(), getHeight());
      _fullRepaintPending = false;
    }

    if (_state == STATE_WIDGET_MENU
        || _state == STATE_CHOOSE_WIDGET
        || _state == STATE_MOVE_WIDGET
        || _state == STATE_RESIZE_WIDGET) {
      int x1, y1, x2, y2;
      WidgetPosition wp;
      // paint rectangle around all widgets
      for (int i = 0; i < _widgets.length; i++) {
        if (i != _widgetIndex) {
          wp = _widgets[i];
          x1 = wp.col * w / _ncols;
          y1 = wp.row * h / _nrows;
          x2 = (wp.col + wp.ncols) * w / _ncols - 1;
          y2 = (wp.row + wp.nrows) * h / _nrows - 1;
          g.setColor(0x808080);
          g.drawRect(x1, y1, x2 - x1, y2 - y1);
          g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);
        }
      }

      // paint rectangle around selected widget
      wp = _widgets[_widgetIndex];
      x1 = wp.col * w / _ncols;
      y1 = wp.row * h / _nrows;
      x2 = (wp.col + wp.ncols) * w / _ncols - 1;
      y2 = (wp.row + wp.nrows) * h / _nrows - 1;
      g.setColor(0xff0000);
      g.drawRect(x1, y1, x2 - x1, y2 - y1);
      g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);

      // paint move/resize icon
      if (_imageMove != null) {
        if (_state == STATE_MOVE_WIDGET)
          g.drawImage(
              _imageMove, (x1 + x2) / 2, (y1 + y2) / 2, Graphics.HCENTER | Graphics.VCENTER);
        else if (_state == STATE_RESIZE_WIDGET)
          g.drawImage(_imageMove, x2, y2, Graphics.HCENTER | Graphics.VCENTER);
      }
    }

    // paint menu
    if (_state == STATE_MAIN_MENU) {
      _mainMenu.paint(g);
    }

    if (_state == STATE_WIDGET_MENU) {
      _widgetMenu.paint(g);
    }

    if (isSoftkeyVisibleState()) {
      g.drawImage(
          _selectedSoftkey == KEY_LEFT ? _imgSoftkeyLeftSel : _imgSoftkeyLeft,
          _softkeysPanelX + _softkeyW / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_UP ? _imgSoftkeyUpSel : _imgSoftkeyUp,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_FIRE ? _imgSoftkeyFireSel : _imgSoftkeyFire,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_DOWN ? _imgSoftkeyDownSel : _imgSoftkeyDown,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 5 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_RIGHT ? _imgSoftkeyRightSel : _imgSoftkeyRight,
          _softkeysPanelX + _softkeyW * 5 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
    }

    if (_state == STATE_SHOW && _touchHintDisplayTimeout > System.currentTimeMillis()) {
      int s = (w < h ? w : h) / 3;
      g.setColor(0xFF0000);
      g.drawRect(w - s, 0, s - 1, s - 1);
      g.drawRect(w - s + 1, 1, s - 3, s - 3);
      _touchHintMenuPainter.paint(
          g, "MENU", 0, w - s, 0, s, s, Graphics.HCENTER | Graphics.VCENTER);
    }
  }
Exemple #6
0
  protected void paint(Graphics g) {
    int x = g.getClipX();
    int y = g.getClipY();
    int w = g.getClipWidth();
    int h = g.getClipHeight();

    // Draw the frame
    g.setColor(0xffffff);
    g.fillRect(x, y, w, h);

    // Draw each ball
    for (int i = 0; i < numBalls; i++) {
      if (balls[i].inside(x, y, x + w, y + h)) {
        balls[i].paint(g);
      }
    }

    g.setColor(0);
    g.drawRect(0, 0, width - 1, height - 1);

    long now = System.currentTimeMillis();
    String str = null;

    if (times_idx >= NUM_HISTORY) {
      long oldTime = times[times_idx % NUM_HISTORY];

      if (oldTime == now) {
        // in case of divide-by-zero
        oldTime = now - 1;
      }

      long fps = ((long) 1000 * (long) NUM_HISTORY) / (now - oldTime);

      if ((times_idx % 20) == 0) {
        str = numBalls + " Ball(s) " + fps + " fps";
      }
    } else {
      if ((times_idx % 20) == 0) {
        str = numBalls + " Ball(s)";
      }
    }

    if (msg != null) {
      g.setColor(0xffffff);
      g.setClip(0, height - STATUSBAR_HEIGHT, width, height);
      g.fillRect(0, height - STATUSBAR_HEIGHT, width, STATUSBAR_HEIGHT);

      g.setColor(0);
      g.drawString(msg, 5, height - STATUSBAR_HEIGHT - 2, 0);
      g.drawRect(0, 0, width - 1, height - 1);

      // draw a reflection line
      g.drawLine(0, height - STATUSBAR_HEIGHT, w, height - STATUSBAR_HEIGHT);

      msg = null;
    }

    if (str != null) {
      /*
       * Do a complete repaint, so that the message will
       * be shown even in double-buffer mode.
       */
      repaint();
      msg = str;
    }

    times[times_idx % NUM_HISTORY] = now;
    ++times_idx;
  }
Exemple #7
0
  /**
   * Draws one character. It called from drawChar(), drawString() and drawSubstrung().
   *
   * @param g the graphics context
   * @param c the character to be drawn
   * @param x the x coordinate of the anchor point
   * @param y the y coordinate of the anchor point
   * @return the x coordinate for the next character
   */
  public int drawOneChar(Graphics g, char c, int x, int y) {
    // skip if it is a space
    if (c == ' ') {
      return x + this.spaceWidth + xIndent + charWidthIncrement;
    }
    int charIndex = charIndex(c);
    // draw the unknown character as a rectangle
    if (charIndex < 0) {
      int squareWidth = this.spaceWidth + xIndent + charWidthIncrement;
      g.drawRect(x, y, squareWidth - 1, height - 1);
      return x + squareWidth;
    }

    int charX = this.x[charIndex];
    int charY = this.y[charIndex];
    int cw = widthes[charIndex];
    int imageIndex = idx[charIndex];

    y += yIndent / 2;

    Image image = this.currentImages[imageIndex];

    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipWidth = g.getClipWidth();
    int clipHeight = g.getClipHeight();

    int ix = x - charX;
    int iy = y - charY;

    if (!italic && !bold) {
      g.clipRect(x, y, cw, this.height);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else if (italic & bold) {
      int halfHeight = height / 2;
      g.clipRect(x + 1, y, cw, this.height);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x + 2, y, cw, halfHeight);
      g.drawImage(image, ix + 2, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x, y + halfHeight, cw, height - halfHeight);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else if (italic) {
      int halfHeight = height / 2;
      g.clipRect(x + 1, y, cw, halfHeight);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x, y + halfHeight, cw, height - halfHeight);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else { // just a bold
      g.clipRect(x, y, cw, this.height);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x + 1, y, cw, this.height);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
    }
    // restore clipping
    g.setClip(clipX, clipY, clipWidth, clipHeight);
    return x + cw + xIndent + charWidthIncrement;
  }