⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logcanvas.java

📁 MoMELog是J2ME的日志框架。它是非常简单的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
          try          {            this.executorLock.wait();          } catch (InterruptedException ie)          {}        }      }      if (this.runner == null && res != null)      {        this.cmds.insertElementAt(res, 0);        res = null;      }      this.executorLock.notify();    }    return res;  }  /**   * Starts the execution thread.   *    * @since 1.0   */  protected void start()  {    synchronized (this.executorLock)    {      (this.runner = new Thread(this)).start();      this.executorLock.notify();    }  }  /**   * Stops the execution thread.   *    * @since 1.0   */  protected void stop()  {    synchronized (this.executorLock)    {      if (this.runner != null)        this.runner = null;      this.executorLock.notifyAll();    }  }  /*   * (non-Javadoc)   *    * @see javax.microedition.lcdui.Canvas#hideNotify()   */  protected void hideNotify()  {    stop();  }  /*   * (non-Javadoc)   *    * @see javax.microedition.lcdui.Canvas#showNotify()   */  protected void showNotify()  {    start();  }  private boolean parseBoolean(char[] lines, int start, int length)  {    String value = String.valueOf(lines, start, length - start);    return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("on")        || value.equalsIgnoreCase("yes");  }  private Font parseFont(char[] lines, int start, int end)  {    Font res = null;    int face = 0;    int style = 0;    int size = 0;    int partStart = start;    int pos = start;    for (; pos < end && lines[pos] != ','; pos++);    if (pos < end)    {      String str = String.valueOf(lines, partStart, pos - partStart);      if (str.equalsIgnoreCase("PROPORTIONAL"))        face = Font.FACE_PROPORTIONAL;      else if (str.equalsIgnoreCase("MONOSPACE"))        face = Font.FACE_MONOSPACE;      else if (str.equalsIgnoreCase("SYSTEM"))        face = Font.FACE_SYSTEM;      else throw new IllegalArgumentException("invalid font's face: \"" + str          + '"');      for (partStart = ++pos; pos < end && lines[pos] != ','; pos++);      if (pos < end)      {        int stylePartPos = partStart;        do        {          for (; stylePartPos < pos && lines[stylePartPos] != ';'; stylePartPos++);          str = String.valueOf(lines, partStart, stylePartPos - partStart);          if (str.equalsIgnoreCase("BOLD"))            style |= Font.STYLE_BOLD;          else if (str.equalsIgnoreCase("ITALIC"))            style |= Font.STYLE_ITALIC;          else if (str.equalsIgnoreCase("PLAIN"))            style |= Font.STYLE_PLAIN;          else if (str.equalsIgnoreCase("UNDERLINED"))            style |= Font.STYLE_UNDERLINED;          else throw new IllegalArgumentException("invalid font's style: \""              + str + '"');          partStart = ++stylePartPos;        } while (stylePartPos < pos);        str = String.valueOf(lines, ++pos, end - pos);        if (str.equalsIgnoreCase("LARGE"))          size = Font.SIZE_LARGE;        else if (str.equalsIgnoreCase("MEDIUM"))          size = Font.SIZE_MEDIUM;        else if (str.equalsIgnoreCase("SMALL"))          size = Font.SIZE_SMALL;        else throw new IllegalArgumentException("invalid font size: \"" + str            + '"');        res = Font.getFont(face, style, size);      }    }    if (res == null)      throw new RuntimeException("Invalid format of font specifier \""          + String.valueOf(lines, start, end - start) + '"');    return res;  }  /**   * Configures {@link LogCanvas} instance from the specified character   * sequence. Character sequence should consist of lines separated by   * {@code new-line} character ({@code '\n'}). Each line should contain   * name-value pair separated by equal sign ({@code =}). White spaces around   * names and values are allowed and ignored. If some property is specified   * more than one time, the last occurrence prevails.   * </p>   * <p>   * {@link LogCanvas} supports following properties. <table width="100%"   * border="1" cellpadding="2" cellspacing="0"> <col width="15%"> <col   * width="*"> <col width="15%">   * <tr valign="top">   * <td>   * <p>   * <strong>Property Name</strong>   * </p>   * </td>   * <td>   * <p>   * <strong>Description</strong>   * </p>   * </td>   * <td>   * <p>   * <strong>Default Value</strong>   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;bgcolor&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies background color of text.   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code 002F00} (<em>dark green</em>)   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;fgcolor&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies foreground color of text.   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code FFFFFF} (<em>white</em>)   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;font&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies font to use for rendering text. The format of this property is<br>   * <strong>&lt;Face&gt;,&lt;Style&gt;,&lt;Size&gt;</strong>   * </p>   * <p CLASS="text-body-indent">   * <strong>Face</strong> = <strong>PROPRTIONAL|MONOSPACE|SYSTEM</strong>   * </p>   * <p CLASS="text-body-indent">   * <strong>Style</strong> = (<strong>PLAIN|BOLD|ITALIC|UNDERLINED)(;(PLAIN|BOLD|ITALIC|UNDERLINED))*</strong>   * </p>   * <p style="margin-left: 4.99mm">   * <strong>Size</strong> = <strong>LARGE|MEDIUM|SMALL</strong>   * </p>   * <p>   * <B>Note</B> No spaces are allowed. Keywords are case insensitive.   * </p>   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code proportional,plain,small}   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;rungconreset&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies whether garbage collector is running after buffer reset. if   * {@code true}, {@code on} or {@code yes} garbage collector is running, not   * otherwise.   * </p>   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code true} (is run)   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;scrollbarcolor&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies color of scrollbar.   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code 00BF00} (<em>green</em>)   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;scrollbarcursorcolor&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies color of scrollbar's cursor at the middle positions.   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code FFFFFF} (<em>white</em>)   * </p>   * </td>   * </tr>   * <tr>   * <td>   * <p align="left">   * <strong>&quot;scrollbarcursoredgecolor&quot;</strong>   * </p>   * </td>   * <td>   * <p align="left">   * Specifies color of scrollbar's cursor at the edge (top or bottom)   * positions.   * <p>   * <em>Since version 1.0</em>   * </p>   * </td>   * <td>   * <p align="center">   * {@code EF1F00} (<em>dark red</em>)   * </p>   * </td>   * </tr>   * </table>   * <p>   * For example following initialization file snippet configures   * {@link LogCanvas} to not run garbage collector on buffer reset, sets font   * to proportional, bold, italic and small, background color to white,   * foreground - black, scrollbar - gray, scrollbar cursor at middle positions -   * yellow and scrollbar cursor at edge positions to white.   * </p>   *    * <pre>   *  #sets LogCanvas as logListener   *  listener = momelog.listener.LogCanvas   *       *  #don't run gc   *  listener.rungconreset = off   *       *  #view setting   *  listener.font = proportional,bold;italic,small   *  listener.bgcolor = FFFFFF   *  listener.fgcolor = 0   *  listener.scrollbarcolor = BFBFBF   *  listener.scrollbarcursorcolor = EFEF00   *  listener.scrollbarcursoredgecolor = FFFFFF   * </pre>   *    * <p>   * See <a href="../../../logcanvas-guide.html#config_decl">LogCanvas Guide</a> for   * details.   * </p>   */  public void configure(char[] lines, int offset, int length)  {    if (length < 0)      throw new IllegalArgumentException("length: " + length + " < 0");    if (offset < 0 || offset > lines.length)      throw new ArrayIndexOutOfBoundsException("offset: "          + Integer.toString(offset));    if ((length += offset) > lines.length)      length = lines.length;    if (length > offset)    {      for (int lineEnd = offset; lineEnd < length; offset = ++lineEnd)      {        for (; offset < length            && (lines[offset] == ' ' || lines[offset] == '\t'); offset++);        for (lineEnd = offset; lineEnd < length && lines[lineEnd] != '\n'; lineEnd++);        int nameEnd = offset;        boolean notValid = true;        for (; nameEnd < lineEnd && (notValid = (lines[nameEnd] != '=')); nameEnd++);        if (!notValid)        {          int vStart = (nameEnd--) + 1;          int vEnd = lineEnd;          for (; nameEnd >= offset              && (lines[nameEnd] == ' ' || lines[nameEnd] == '\t'); nameEnd--);          String name = String.valueOf(lines, offset, ++nameEnd - offset);          for (; vStart < length              && (lines[vStart] == ' ' || lines[vStart] == '\t'); vStart++);          for (int pos = vEnd - 1; vStart <= pos              && (lines[pos] == ' ' || lines[pos] == '\t'); vEnd = pos--);          try          {            if (name.equals("bgcolor"))              setBgColor(Integer.parseInt(String.valueOf(lines, vStart, vEnd                  - vStart), 16));            else if (name.equals("fgcolor"))              setFgColor(Integer.parseInt(String.valueOf(lines, vStart, vEnd                  - vStart), 16));            else if (name.equals("scrollbarcolor"))              setScrollbarColor(Integer.parseInt(String.valueOf(lines, vStart,                  vEnd - vStart), 16));            else if (name.equals("scrollbarcursorcolor"))              setScrollbarCursorColor(Integer.parseInt(String.valueOf(lines,                  vStart, vEnd - vStart), 16));            else if (name.equals("scrollbarcursoredgecolor"))              setScrollbarCursorEdgeColor(Integer.parseInt(String.valueOf(                  lines, vStart, vEnd - vStart), 16));            else if (name.equals("rungconreset"))              setRunGCOnReset(parseBoolean(lines, vStart, vEnd));            else if (name.equals("font"))              setFont(parseFont(lines, vStart, vEnd));            else System.err.println("ERROR: Unknown property " + name + " of "                + LogCanvas.class.getName() + ". Ignored.");          } catch (Throwable e)          {            String message = e.getMessage();            if (message != null && message.length() > 0)              message = ": " + message;            System.err.println("ERROR: Invalid value \""                + String.valueOf(lines, vStart, vEnd - vStart)                + "\" of property " + name + " of " + LogCanvas.class.getName()                + message + ". Ignored.");          }        } else System.err.println("ERROR: Invalid properties line "            + "\"listener." + String.valueOf(lines, offset, lineEnd - offset)            + "\" of " + LogCanvas.class.getName() + ". Ignored.");      }    }  }  /**   * Processes commands.   */  public void run()  {    try    {      while (this.runner != null)      {        Object cmd = this.popCommand();        if (cmd == NEXT_LINE)          nextLine();        else if (cmd == PREV_LINE)          prevLine();        else if (cmd == NEXT_PAGE)          nextPage();        else if (cmd == PREV_PAGE)          prevPage();        else if (cmd == BOTTOM_LINE)          bottomLine();        else if (cmd == TOP_LINE)          topLine();        else if (cmd == RESET)          resetLogging();        else if (cmd == TOGGLE_FULLSCREEN)          toggleFullScreenMode();        else if (cmd == APPEND_LOG)        {          if (grabNextLines())          {            if (!this.needScrollBar                && (this.vStart > 0 || this.lines > this.lpp))            {              this.needScrollBar = true;              this.textWidthView -= 3;              this.shift = this.lines = 0;              grabNextLines();            }            show();            if (this.needScrollBar)              showScrollBar();          } else showScrollBar();          flushGraphics();          repaint();        }      }    } catch (Throwable e)    {      e.printStackTrace();    }  }}

⌨️ 快捷键说明

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